diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/genedata/HCSImageFileExtractor.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/genedata/HCSImageFileExtractor.java new file mode 100644 index 0000000000000000000000000000000000000000..0b67c6d41eb7634d848df85da3bd81486e3153cc --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/genedata/HCSImageFileExtractor.java @@ -0,0 +1,109 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.dss.genedata; + +import java.util.Properties; + +import ch.rinn.restrictions.Private; +import ch.systemsx.cisd.bds.hcs.Geometry; +import ch.systemsx.cisd.bds.hcs.Location; +import ch.systemsx.cisd.bds.storage.IDirectory; +import ch.systemsx.cisd.etlserver.HCSImageFileExtractionResult; +import ch.systemsx.cisd.etlserver.IHCSImageFileAccepter; +import ch.systemsx.cisd.etlserver.IHCSImageFileExtractor; +import ch.systemsx.cisd.etlserver.plugins.AbstractHCSImageFileExtractor; +import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; + +/** + * + * + * @author Franz-Josef Elmer + */ +public class HCSImageFileExtractor extends AbstractHCSImageFileExtractor implements IHCSImageFileExtractor +{ + public HCSImageFileExtractor(final Properties properties) + { + super(properties); + } + + @Private + HCSImageFileExtractor(Geometry wellGeometry) + { + super(wellGeometry); + } + + + public HCSImageFileExtractionResult process(IDirectory incomingDataSetDirectory, + DataSetInformation dataSetInformation, IHCSImageFileAccepter accepter) + { + assert incomingDataSetDirectory != null; + return process(incomingDataSetDirectory.listFiles(null, false), dataSetInformation, accepter); + } + + @Override + protected String[] tryToSplitIntoTokens(String imageFileName) + { + String[] tokens = new String[4]; + int indexOfChannelSeparator = imageFileName.indexOf('-'); + if (indexOfChannelSeparator < 0) + { + return null; + } + tokens[3] = imageFileName.substring(indexOfChannelSeparator + 1); + String wellAndTileCoordinates = imageFileName.substring(0, indexOfChannelSeparator); + if (wellAndTileCoordinates.length() != 9) + { + return null; + } + tokens[1] = wellAndTileCoordinates.substring(0, 6); + tokens[2] = wellAndTileCoordinates.substring(6); + return tokens; + } + + @Override + protected int getChannelWavelength(String channel) + { + try + { + return Integer.parseInt(channel) + 1; + } catch (NumberFormatException ex) + { + return 0; + } + } + + @Override + protected Location tryGetWellLocation(String wellLocation) + { + return new Location(1, 1); + } + + @Override + protected Location tryGetPlateLocation(String plateLocation) + { + try + { + int row = Integer.parseInt(plateLocation.substring(0, 3)); + int column = Integer.parseInt(plateLocation.substring(3)); + return new Location(row, column); + } catch (NumberFormatException ex) + { + return null; + } + } + +} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/lmc/HCSImageFileExtractor.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/lmc/HCSImageFileExtractor.java index 2cff4ad2557579c5061a0a8009596b77e1d1908e..2a3cea2a142b6fd21655ed95623621837f0f84cb 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/lmc/HCSImageFileExtractor.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/lmc/HCSImageFileExtractor.java @@ -56,14 +56,13 @@ public class HCSImageFileExtractor extends AbstractHCSImageFileExtractor impleme } @Override - protected final int getChannelWavelength(final String value) + protected final int getChannelWavelength(final String channel) { - int channel; - for (channel = 1; channel <= CHANNEL_NAMES.length; channel++) + for (int channelIndex = 1; channelIndex <= CHANNEL_NAMES.length; channelIndex++) { - if (value.equalsIgnoreCase(CHANNEL_NAMES[channel - 1])) + if (channel.equalsIgnoreCase(CHANNEL_NAMES[channelIndex - 1])) { - return channel; + return channelIndex; } } return 0; // unknown channel name @@ -81,11 +80,11 @@ public class HCSImageFileExtractor extends AbstractHCSImageFileExtractor impleme * </p> */ @Override - protected final Location tryGetWellLocation(final String value) + protected final Location tryGetWellLocation(final String wellLocation) { try { - int tileNumber = Integer.parseInt(value); + int tileNumber = Integer.parseInt(wellLocation); Location letterLoc = Location.tryCreateLocationFromPosition(tileNumber, wellGeometry); // transpose rows with columns return new Location(letterLoc.getY(), letterLoc.getX()); diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/genedata/HCSImageFileExtractorTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/genedata/HCSImageFileExtractorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..7a1d9d18fce3267f9150a70be1f24b764a26f9ba --- /dev/null +++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/genedata/HCSImageFileExtractorTest.java @@ -0,0 +1,115 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.dss.genedata; + +import java.io.IOException; +import java.util.Arrays; + +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.testng.AssertJUnit; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import ch.rinn.restrictions.Friend; +import ch.systemsx.cisd.bds.hcs.Location; +import ch.systemsx.cisd.bds.hcs.WellGeometry; +import ch.systemsx.cisd.bds.storage.IDirectory; +import ch.systemsx.cisd.bds.storage.IFile; +import ch.systemsx.cisd.etlserver.HCSImageFileExtractionResult; +import ch.systemsx.cisd.etlserver.IHCSImageFileAccepter; +import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; + +/** + * + * + * @author Franz-Josef Elmer + */ +@Friend(toClasses=HCSImageFileExtractor.class) +public class HCSImageFileExtractorTest extends AssertJUnit +{ + private Mockery context; + + private IHCSImageFileAccepter fileAccepter; + + private HCSImageFileExtractor extractor; + + private IDirectory directory; + + private DataSetInformation dataSetInformation; + + private IFile file1; + + private IFile file2; + + @BeforeMethod + public final void setUp() throws IOException + { + context = new Mockery(); + directory = context.mock(IDirectory.class); + file1 = createImageFileMock("001001000-0.jpeg"); + file2 = createImageFileMock("002005000-1.jpeg"); + fileAccepter = context.mock(IHCSImageFileAccepter.class); + extractor = new HCSImageFileExtractor(new WellGeometry(1, 1)); + dataSetInformation = new DataSetInformation(); + } + + @AfterMethod + public final void tearDown() + { + // To following line of code should also be called at the end of each test method. + // Otherwise one do not known which test failed. + context.assertIsSatisfied(); + } + + @Test + public void test() + { + context.checking(new Expectations() + { + { + one(directory).listFiles(null, false); + will(returnValue(Arrays.asList(file1, file2))); + + one(fileAccepter).accept(1, new Location(1, 1), new Location(1, 1), file1); + one(fileAccepter).accept(2, new Location(2, 5), new Location(1, 1), file2); + } + }); + + HCSImageFileExtractionResult result = extractor.process(directory, dataSetInformation, fileAccepter); + + assertEquals("[channel1[1=1], channel2[2=2]]", result.getChannels().toString()); + assertEquals(2, result.getTotalFiles()); + assertEquals(0, result.getInvalidFiles().size()); + context.assertIsSatisfied(); + } + + private IFile createImageFileMock(final String fileName) + { + final IFile file = context.mock(IFile.class, fileName); + context.checking(new Expectations() + { + { + one(file).getPath(); + will(returnValue(fileName)); + } + }); + return file; + } +} +