From 79436a0c6188e732cb76e19830c86e0695d13afb Mon Sep 17 00:00:00 2001 From: izabel <izabel> Date: Wed, 8 Sep 2010 07:53:26 +0000 Subject: [PATCH] [LMS-1715] small refactoring; unit tests SVN: 17753 --- .../biozentrum/BZDataSetInfoExtractor.java | 173 ++++-------------- .../BZDatasetDirectoryNameTokenizer.java | 65 +++++++ .../etl/biozentrum/HCSImageFileExtractor.java | 22 +-- .../etl/biozentrum/PlateGeometryOracle.java | 6 +- .../openbis/dss/etl/biozentrum/Utils.java | 143 +++++++++++++++ .../biozentrum/PlateGeometryOracleTest.java | 152 +++++++++++++++ ...eFileExtractorTest.java => UtilsTest.java} | 9 +- 7 files changed, 411 insertions(+), 159 deletions(-) create mode 100644 screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/BZDatasetDirectoryNameTokenizer.java create mode 100644 screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/Utils.java create mode 100644 screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/PlateGeometryOracleTest.java rename screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/{HCSImageFileExtractorTest.java => UtilsTest.java} (81%) diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/BZDataSetInfoExtractor.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/BZDataSetInfoExtractor.java index 74e5b065849..404ad8a7e60 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/BZDataSetInfoExtractor.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/BZDataSetInfoExtractor.java @@ -23,28 +23,17 @@ import java.util.List; import java.util.Properties; import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang.StringUtils; import ch.systemsx.cisd.bds.hcs.Location; import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.utilities.PropertyUtils; import ch.systemsx.cisd.etlserver.IDataSetInfoExtractor; -import ch.systemsx.cisd.openbis.dss.etl.ImageFileExtractorUtils; import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataType; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericValueEntityProperty; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTermValueEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier; @@ -52,7 +41,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.ScreeningConstants; /** - * Data set info extractor dealing with BZ data. Creates experiments and plates if needed. + * Data set info extractor dealing with iBrain data. Creates experiments and plates if needed. * * @author Izabela Adamczyk */ @@ -63,23 +52,24 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor static final String PROJECT_CODE = "project-code"; - private final Properties properties; + private final String spaceCode; + + private final String projectCode; public BZDataSetInfoExtractor(final Properties properties) { - this.properties = properties; + spaceCode = PropertyUtils.getMandatoryProperty(properties, SPACE_CODE); + projectCode = PropertyUtils.getMandatoryProperty(properties, PROJECT_CODE); } public DataSetInformation getDataSetInformation(File incomingDataSetPath, IEncapsulatedOpenBISService openbisService) throws UserFailureException, EnvironmentFailureException { - final DataSetInformation dataSetInformation = new DataSetInformation(); - DirectoryDatasetInfoExtractor tokens = - new DirectoryDatasetInfoExtractor(FilenameUtils.getBaseName(incomingDataSetPath + + BZDatasetDirectoryNameTokenizer tokens = + new BZDatasetDirectoryNameTokenizer(FilenameUtils.getBaseName(incomingDataSetPath .getPath())); - String spaceCode = PropertyUtils.getMandatoryProperty(properties, SPACE_CODE); - String projectCode = PropertyUtils.getMandatoryProperty(properties, PROJECT_CODE); String sampleCode = getSampleCode(tokens); String experimentCode = getExperiment(tokens); ExperimentIdentifier experimentIdentifier = @@ -87,26 +77,12 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor SampleIdentifier sampleIdentifier = new SampleIdentifier(new GroupIdentifier(DatabaseInstanceIdentifier.createHome(), spaceCode), sampleCode); + Sample sampleOrNull = openbisService.tryGetSampleWithExperiment(sampleIdentifier); if (sampleOrNull == null) { - Collection<VocabularyTerm> terms = - openbisService.listVocabularyTerms(ScreeningConstants.PLATE_GEOMETRY); - List<String> plateGeometries = new ArrayList<String>(); - for (VocabularyTerm v : terms) - { - plateGeometries.add(v.getCode()); - } - List<File> imageFiles = ImageFileExtractorUtils.listImageFiles(incomingDataSetPath); - List<Location> plateLocations = new ArrayList<Location>(); - for (File imageFile : imageFiles) - { - String baseName = FilenameUtils.getBaseName(imageFile.getPath()); - String plateLocationToken = - HCSImageFileExtractor.extractFileInfo(baseName).getPlateLocationToken(); - plateLocations.add(Location - .tryCreateLocationFromTransposedMatrixCoordinate(plateLocationToken)); - } + List<String> plateGeometries = loadPlateGeometries(openbisService); + List<Location> plateLocations = Utils.extractPlateLocations(incomingDataSetPath); String plateGeometry = PlateGeometryOracle.figureGeometry(plateLocations, plateGeometries); registerSampleWithExperiment(openbisService, sampleIdentifier, experimentIdentifier, @@ -118,6 +94,17 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor sampleIdentifier)); } } + checkSampleExperiment(experimentIdentifier, sampleIdentifier, sampleOrNull); + + final DataSetInformation dataSetInformation = new DataSetInformation(); + dataSetInformation.setSpaceCode(spaceCode); + dataSetInformation.setSampleCode(sampleCode); + return dataSetInformation; + } + + private void checkSampleExperiment(ExperimentIdentifier experimentIdentifier, + SampleIdentifier sampleIdentifier, Sample sampleOrNull) + { if (sampleOrNull.getExperiment() == null || new ExperimentIdentifier(sampleOrNull.getExperiment()) .equals(experimentIdentifier) == false) @@ -126,9 +113,18 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor "Sample '%s' is not part of experiment '%s'", sampleIdentifier, experimentIdentifier)); } - dataSetInformation.setSpaceCode(spaceCode); - dataSetInformation.setSampleCode(sampleCode); - return dataSetInformation; + } + + private List<String> loadPlateGeometries(IEncapsulatedOpenBISService openbisService) + { + Collection<VocabularyTerm> terms = + openbisService.listVocabularyTerms(ScreeningConstants.PLATE_GEOMETRY); + List<String> plateGeometries = new ArrayList<String>(); + for (VocabularyTerm v : terms) + { + plateGeometries.add(v.getCode()); + } + return plateGeometries; } private static void registerSampleWithExperiment(IEncapsulatedOpenBISService openbisService, @@ -138,7 +134,7 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor Experiment experimentOrNull = openbisService.tryToGetExperiment(experimentIdentifier); if (experimentOrNull == null) { - registerExperiment(openbisService, experimentIdentifier); + openbisService.registerExperiment(Utils.createExperimentSIRNAHCS(experimentIdentifier)); experimentOrNull = openbisService.tryToGetExperiment(experimentIdentifier); if (experimentOrNull == null) { @@ -146,107 +142,18 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor experimentIdentifier)); } } - NewSample sample = new NewSample(); - sample.setExperimentIdentifier(experimentIdentifier.toString()); - sample.setIdentifier(sampleIdentifier.toString()); - SampleType sampleType = new SampleType(); - sampleType.setCode(ScreeningConstants.PLATE_PLUGIN_TYPE_CODE); - sample.setSampleType(sampleType); - sample.setProperties(createPlateGeometryProperty(plateGeometry)); - openbisService.registerSample(sample, null); + openbisService.registerSample(Utils.createPlate(sampleIdentifier, experimentIdentifier, + plateGeometry), null); } - private static IEntityProperty[] createPlateGeometryProperty(String plateGeometry) - { - List<IEntityProperty> sampleProperties = new ArrayList<IEntityProperty>(); - VocabularyTermValueEntityProperty property = new VocabularyTermValueEntityProperty(); - VocabularyTerm vocabularyTerm = new VocabularyTerm(); - vocabularyTerm.setCode(plateGeometry); - property.setVocabularyTerm(vocabularyTerm); - PropertyType propertyType = new PropertyType(); - DataType dataType = new DataType(); - dataType.setCode(DataTypeCode.CONTROLLEDVOCABULARY); - propertyType.setDataType(dataType); - propertyType.setCode(ScreeningConstants.PLATE_GEOMETRY); - property.setPropertyType(propertyType); - sampleProperties.add(property); - return sampleProperties.toArray(new IEntityProperty[sampleProperties.size()]); - } - - private static IEntityProperty[] createDescriptionProperty(String description) - { - List<IEntityProperty> properties = new ArrayList<IEntityProperty>(); - GenericValueEntityProperty property = new GenericValueEntityProperty(); - property.setValue(description); - PropertyType propertyType = new PropertyType(); - DataType dataType = new DataType(); - dataType.setCode(DataTypeCode.VARCHAR); - propertyType.setDataType(dataType); - propertyType.setCode(ScreeningConstants.DESCRIPTION); - property.setPropertyType(propertyType); - properties.add(property); - return properties.toArray(new IEntityProperty[properties.size()]); - } - - private static void registerExperiment(IEncapsulatedOpenBISService openbisService, - ExperimentIdentifier experimentIdentifier) - { - NewExperiment experiment = new NewExperiment(); - experiment.setExperimentTypeCode(ScreeningConstants.SIRNA_HCS); - experiment.setIdentifier(experimentIdentifier.toString()); - experiment.setProperties(createDescriptionProperty("-")); - openbisService.registerExperiment(experiment); - } - - private String getExperiment(DirectoryDatasetInfoExtractor tokens) + private static String getExperiment(BZDatasetDirectoryNameTokenizer tokens) { return tokens.getExperimentToken(); } - private String getSampleCode(DirectoryDatasetInfoExtractor tokens) + private static String getSampleCode(BZDatasetDirectoryNameTokenizer tokens) { return "P_" + tokens.getExperimentToken() + "_" + tokens.getTimestampToken(); } - private class DirectoryDatasetInfoExtractor - { - private final String experimentToken; - - private final String plateToken; - - private final String barcodeToken; - - private final String timestampToken; - - DirectoryDatasetInfoExtractor(String identifier) - { - String[] namedParts = StringUtils.split(identifier, "_"); - experimentToken = StringUtils.split(namedParts[0], "-")[1]; - plateToken = StringUtils.split(namedParts[1], "-")[1]; - barcodeToken = StringUtils.split(namedParts[2], "-")[1]; - timestampToken = StringUtils.split(namedParts[3], "-")[1]; - } - - public String getExperimentToken() - { - return experimentToken; - } - - public String getPlateToken() - { - return plateToken; - } - - public String getBarcodeToken() - { - return barcodeToken; - } - - public String getTimestampToken() - { - return timestampToken; - } - - } - } diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/BZDatasetDirectoryNameTokenizer.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/BZDatasetDirectoryNameTokenizer.java new file mode 100644 index 00000000000..30e90f38f78 --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/BZDatasetDirectoryNameTokenizer.java @@ -0,0 +1,65 @@ +/* + * 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.etl.biozentrum; + +import org.apache.commons.lang.StringUtils; + +/** + * Extracts useful information from dataset directory name specific to iBrain2. + * + * @author Izabela Adamczyk + */ +public class BZDatasetDirectoryNameTokenizer +{ + private final String experimentToken; + + private final String plateToken; + + private final String barcodeToken; + + private final String timestampToken; + + BZDatasetDirectoryNameTokenizer(String identifier) + { + String[] namedParts = StringUtils.split(identifier, "_"); + experimentToken = StringUtils.split(namedParts[0], "-")[1]; + plateToken = StringUtils.split(namedParts[1], "-")[1]; + barcodeToken = StringUtils.split(namedParts[2], "-")[1]; + timestampToken = StringUtils.split(namedParts[3], "-")[1]; + } + + public String getExperimentToken() + { + return experimentToken; + } + + public String getPlateToken() + { + return plateToken; + } + + public String getBarcodeToken() + { + return barcodeToken; + } + + public String getTimestampToken() + { + return timestampToken; + } + +} \ No newline at end of file diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/HCSImageFileExtractor.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/HCSImageFileExtractor.java index 27ec8b57480..53b72a38e00 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/HCSImageFileExtractor.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/HCSImageFileExtractor.java @@ -19,13 +19,10 @@ package ch.systemsx.cisd.openbis.dss.etl.biozentrum; import java.io.File; import java.util.Properties; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang.StringUtils; - import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; /** - * A <code>IHCSImageFileExtractor</code> implementation suitable for <i>BioZentrum</i>. + * A <code>IHCSImageFileExtractor</code> implementation suitable for <i>iBrain</i>. * * @author Izabela Adamczyk */ @@ -40,22 +37,7 @@ public class HCSImageFileExtractor extends ch.systemsx.cisd.openbis.dss.etl.HCSI @Override protected final ImageFileInfo tryExtractImageInfo(File imageFile, SampleIdentifier datasetSample) { - return extractFileInfo(FilenameUtils.getBaseName(imageFile.getPath())); - } - - static ImageFileInfo extractFileInfo(String text) - { - String[] namedParts = StringUtils.split(text, "_"); - final String plateLocationToken = StringUtils.split(namedParts[3], "-")[1]; - final String wellLocationToken = StringUtils.split(namedParts[4], "-")[1]; - final String timepointToken = StringUtils.split(namedParts[5], "-")[1]; - final String channelToken = StringUtils.split(namedParts[6], "-")[1]; - ImageFileInfo info = new ImageFileInfo(); - info.setPlateLocationToken(plateLocationToken); - info.setWellLocationToken(wellLocationToken); - info.setChannelToken(channelToken); - info.setTimepointToken(timepointToken); - return info; + return Utils.extractImageFileInfo(imageFile); } } diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/PlateGeometryOracle.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/PlateGeometryOracle.java index 3af0c0fbf01..42eb1502592 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/PlateGeometryOracle.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/PlateGeometryOracle.java @@ -92,6 +92,10 @@ public class PlateGeometryOracle static private boolean isEnough(Geometry geometry, Location location) { - return geometry.getDimX() >= location.getX() && geometry.getDimY() >= location.getY(); + int dimX = geometry.getDimX(); + int x = location.getX(); + int dimY = geometry.getDimY(); + int y = location.getY(); + return dimX >= x && dimY >= y; } } diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/Utils.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/Utils.java new file mode 100644 index 00000000000..e9438319414 --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/Utils.java @@ -0,0 +1,143 @@ +/* + * 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.etl.biozentrum; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang.StringUtils; + +import ch.systemsx.cisd.bds.hcs.Location; +import ch.systemsx.cisd.openbis.dss.etl.ImageFileExtractorUtils; +import ch.systemsx.cisd.openbis.dss.etl.AbstractHCSImageFileExtractor.ImageFileInfo; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericValueEntityProperty; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTermValueEntityProperty; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; +import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.ScreeningConstants; + +/** + * Utility class containing methods useful in iBrain integration. + * + * @author Izabela Adamczyk + */ +public class Utils +{ + static ImageFileInfo extractImageFileInfo(File imageFile) + { + return extractBZImageFileInfo(FilenameUtils.getBaseName(imageFile.getPath())); + } + + /** + * Extracts useful information from dataset image file name specific to iBrain2. + */ + static ImageFileInfo extractBZImageFileInfo(String text) + { + String[] namedParts = StringUtils.split(text, "_"); + final String plateLocationToken = StringUtils.split(namedParts[3], "-")[1]; + final String wellLocationToken = StringUtils.split(namedParts[4], "-")[1]; + final String timepointToken = StringUtils.split(namedParts[5], "-")[1]; + final String channelToken = StringUtils.split(namedParts[6], "-")[1]; + ImageFileInfo info = new ImageFileInfo(); + info.setPlateLocationToken(plateLocationToken); + info.setWellLocationToken(wellLocationToken); + info.setChannelToken(channelToken); + info.setTimepointToken(timepointToken); + return info; + } + + static IEntityProperty[] createVocabularyProperty(String propertyTypeCode, String termCode) + { + List<IEntityProperty> sampleProperties = new ArrayList<IEntityProperty>(); + VocabularyTermValueEntityProperty property = new VocabularyTermValueEntityProperty(); + VocabularyTerm vocabularyTerm = new VocabularyTerm(); + vocabularyTerm.setCode(termCode); + property.setVocabularyTerm(vocabularyTerm); + PropertyType propertyType = new PropertyType(); + DataType dataType = new DataType(); + dataType.setCode(DataTypeCode.CONTROLLEDVOCABULARY); + propertyType.setDataType(dataType); + propertyType.setCode(propertyTypeCode); + property.setPropertyType(propertyType); + sampleProperties.add(property); + return sampleProperties.toArray(new IEntityProperty[sampleProperties.size()]); + } + + static IEntityProperty[] createVarcharProperty(String propertyTypeCode, String description) + { + List<IEntityProperty> properties = new ArrayList<IEntityProperty>(); + GenericValueEntityProperty property = new GenericValueEntityProperty(); + property.setValue(description); + PropertyType propertyType = new PropertyType(); + DataType dataType = new DataType(); + dataType.setCode(DataTypeCode.VARCHAR); + propertyType.setDataType(dataType); + propertyType.setCode(propertyTypeCode); + property.setPropertyType(propertyType); + properties.add(property); + return properties.toArray(new IEntityProperty[properties.size()]); + } + + static NewSample createPlate(SampleIdentifier sampleIdentifier, + ExperimentIdentifier experimentIdentifier, String plateGeometry) + { + NewSample sample = new NewSample(); + sample.setExperimentIdentifier(experimentIdentifier.toString()); + sample.setIdentifier(sampleIdentifier.toString()); + SampleType sampleType = new SampleType(); + sampleType.setCode(ScreeningConstants.PLATE_PLUGIN_TYPE_CODE); + sample.setSampleType(sampleType); + sample.setProperties(createVocabularyProperty(ScreeningConstants.PLATE_GEOMETRY, + plateGeometry)); + return sample; + } + + static List<Location> extractPlateLocations(File incomingDataSetPath) + { + List<File> imageFiles = ImageFileExtractorUtils.listImageFiles(incomingDataSetPath); + List<Location> plateLocations = new ArrayList<Location>(); + for (File imageFile : imageFiles) + { + String baseName = FilenameUtils.getBaseName(imageFile.getPath()); + String plateLocationToken = extractBZImageFileInfo(baseName).getPlateLocationToken(); + plateLocations.add(Location + .tryCreateLocationFromTransposedMatrixCoordinate(plateLocationToken)); + } + return plateLocations; + } + + static NewExperiment createExperimentSIRNAHCS(ExperimentIdentifier experimentIdentifier) + { + NewExperiment experiment = new NewExperiment(); + experiment.setExperimentTypeCode(ScreeningConstants.SIRNA_HCS); + experiment.setIdentifier(experimentIdentifier.toString()); + experiment.setProperties(createVarcharProperty(ScreeningConstants.DESCRIPTION, "-")); + return experiment; + + } + +} diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/PlateGeometryOracleTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/PlateGeometryOracleTest.java new file mode 100644 index 00000000000..59bf015a32d --- /dev/null +++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/PlateGeometryOracleTest.java @@ -0,0 +1,152 @@ +/* + * 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.etl.biozentrum; + +import java.util.Arrays; + +import org.testng.AssertJUnit; +import org.testng.annotations.Test; + +import ch.systemsx.cisd.bds.hcs.Location; +import ch.systemsx.cisd.common.exceptions.UserFailureException; + +/** + * Test cases from {@link PlateGeometryOracle}. + * + * @author Izabela Adamczyk + */ +public class PlateGeometryOracleTest extends AssertJUnit +{ + + private static final String GEOMETRY_3X4 = "12_3X4"; + + private static final String GEOMETRY_12_WELLS_3X4 = "12_WELLS_3X4"; + + private static final String GEOMETRY_12_WELLS_4X3 = "12_WELLS_4X3"; + + private static final String GEOMETRY_16_WELLS_4X4 = "16_WELLS_4X4"; + + private static final String GEOMETRY_1200_WELLS_40X30 = "1200_WELLS_40X30"; + + @Test + public void testTwoSimilarMatchingGeometriesGetFirst() throws Exception + { + assertEquals(GEOMETRY_12_WELLS_3X4, PlateGeometryOracle.figureGeometry(Arrays + .asList(new Location(1, 1)), Arrays.asList(GEOMETRY_12_WELLS_3X4, + GEOMETRY_12_WELLS_4X3))); + assertEquals(GEOMETRY_12_WELLS_4X3, PlateGeometryOracle.figureGeometry(Arrays + .asList(new Location(1, 1)), Arrays.asList(GEOMETRY_12_WELLS_4X3, + GEOMETRY_12_WELLS_3X4))); + } + + @Test + public void testGetSmallerGeometry() throws Exception + { + assertEquals(GEOMETRY_12_WELLS_3X4, PlateGeometryOracle.figureGeometry(Arrays + .asList(new Location(1, 1)), Arrays.asList(GEOMETRY_1200_WELLS_40X30, + GEOMETRY_12_WELLS_3X4))); + } + + @Test + public void testGetSmallestMatchingGeometry() throws Exception + { + assertEquals(GEOMETRY_1200_WELLS_40X30, PlateGeometryOracle.figureGeometry(Arrays + .asList(new Location(3, 4)), Arrays.asList(GEOMETRY_12_WELLS_3X4, + GEOMETRY_1200_WELLS_40X30))); + } + + @Test + public void testGetSmallestMatchingGeometryForManyLocations() throws Exception + { + assertEquals(GEOMETRY_12_WELLS_4X3, PlateGeometryOracle.figureGeometry(Arrays.asList( + new Location(1, 1), new Location(3, 4)), Arrays.asList(GEOMETRY_12_WELLS_3X4, + GEOMETRY_12_WELLS_4X3, GEOMETRY_1200_WELLS_40X30))); + } + + @Test + public void testGetSmallestMatchingGeometryForManyLocationsWithSimilarGeometries() + throws Exception + { + assertEquals(GEOMETRY_1200_WELLS_40X30, PlateGeometryOracle.figureGeometry(Arrays.asList( + new Location(1, 1), new Location(3, 4), new Location(4, 3)), Arrays.asList( + GEOMETRY_12_WELLS_3X4, GEOMETRY_12_WELLS_4X3, GEOMETRY_1200_WELLS_40X30))); + } + + @Test + public void testGetSmallestMatchingGeometryForManyLocationsWithGeometryMatchingMaxLocations() + throws Exception + { + assertEquals(GEOMETRY_16_WELLS_4X4, PlateGeometryOracle.figureGeometry(Arrays.asList( + new Location(1, 1), new Location(3, 4), new Location(4, 3)), Arrays.asList( + GEOMETRY_12_WELLS_3X4, GEOMETRY_12_WELLS_4X3, GEOMETRY_1200_WELLS_40X30, + GEOMETRY_16_WELLS_4X4))); + } + + @Test + public void testSimpleGeometryCode() throws Exception + { + assertEquals(GEOMETRY_3X4, PlateGeometryOracle.figureGeometry(Arrays.asList(new Location(1, + 2)), Arrays.asList(GEOMETRY_3X4))); + + } + + @Test + public void testOneLocationOneGeometryMatching() throws Exception + { + assertEquals(GEOMETRY_12_WELLS_3X4, PlateGeometryOracle.figureGeometry(Arrays + .asList(new Location(1, 2)), Arrays.asList(GEOMETRY_12_WELLS_3X4))); + + } + + @Test + public void testOneLocationOneGeometryMatchingMaxValues() throws Exception + { + assertEquals(GEOMETRY_12_WELLS_3X4, PlateGeometryOracle.figureGeometry(Arrays + .asList(new Location(4, 3)), Arrays.asList(GEOMETRY_12_WELLS_3X4))); + } + + @Test + public void testOneLocationOneGeometryNotMatchingY() throws Exception + { + boolean exceptionThrown = false; + try + { + PlateGeometryOracle.figureGeometry(Arrays.asList(new Location(3, 4)), Arrays + .asList(GEOMETRY_12_WELLS_3X4)); + } catch (UserFailureException ex) + { + exceptionThrown = true; + } + assertTrue(exceptionThrown); + } + + @Test + public void testOneLocationOneGeometryNotMatchingX() throws Exception + { + boolean exceptionThrown = false; + try + { + PlateGeometryOracle.figureGeometry(Arrays.asList(new Location(5, 3)), Arrays + .asList(GEOMETRY_12_WELLS_3X4)); + } catch (UserFailureException ex) + { + exceptionThrown = true; + } + assertTrue(exceptionThrown); + } + +} diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/HCSImageFileExtractorTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/UtilsTest.java similarity index 81% rename from screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/HCSImageFileExtractorTest.java rename to screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/UtilsTest.java index c2dc6e560ed..225cf3fd993 100644 --- a/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/HCSImageFileExtractorTest.java +++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/dss/etl/biozentrum/UtilsTest.java @@ -23,19 +23,18 @@ import ch.rinn.restrictions.Friend; import ch.systemsx.cisd.openbis.dss.etl.AbstractHCSImageFileExtractor.ImageFileInfo; /** - * Test cases for {@link HCSImageFileExtractor}. + * Test cases for {@link Utils}. * * @author Izabela Adamczyk */ -@Friend(toClasses = HCSImageFileExtractor.class) -public class HCSImageFileExtractorTest extends AssertJUnit +@Friend(toClasses = Utils.class) +public class UtilsTest extends AssertJUnit { @Test public void testExtractFileInfoCorrectFileName() throws Exception { ImageFileInfo info = - HCSImageFileExtractor - .extractFileInfo("SM100719invasomes_plt-1_bc-UNK_wp-A01_s-10_t-1_wl-Cy3_001"); + Utils.extractBZImageFileInfo("SM100719invasomes_plt-1_bc-UNK_wp-A01_s-10_t-1_wl-Cy3_001"); assertEquals("plate location token", "A01", info.getPlateLocationToken()); assertEquals("channel token", "Cy3", info.getChannelToken()); assertEquals("time point token", "1", info.getTimepointToken()); -- GitLab