diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java index ba3c28560d09201e0a18777bfdeb44dd40e01104..e904d46ccbc7ff17a60d70beeb21824d4e68542e 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java @@ -66,6 +66,7 @@ import ch.systemsx.cisd.openbis.generic.shared.translator.SampleTranslator; import ch.systemsx.cisd.openbis.generic.shared.translator.VocabularyTranslator; import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; import ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.IScreeningQuery; +import ch.systemsx.cisd.openbis.plugin.screening.server.logic.FeatureVectorValuesLoader; import ch.systemsx.cisd.openbis.plugin.screening.server.logic.PlateContentLoader; import ch.systemsx.cisd.openbis.plugin.screening.server.logic.ScreeningApiImpl; import ch.systemsx.cisd.openbis.plugin.screening.server.logic.WellContentLoader; @@ -205,9 +206,9 @@ public final class ScreeningServer extends AbstractServer<IScreeningServer> impl public FeatureVectorValues getWellFeatureVectorValues(String sessionToken, String datasetCode, String datastoreCode, WellLocation wellLocation) { - Session session = getSession(sessionToken); - return WellContentLoader.loadFeatureVectorValues(session, businessObjectFactory, - getDAOFactory(), datasetCode, datastoreCode, wellLocation); + getSession(sessionToken); + return FeatureVectorValuesLoader.loadFeatureVectorValues(businessObjectFactory, + datasetCode, datastoreCode, wellLocation); } public LogicalImageInfo getImageDatasetInfo(String sessionToken, String datasetCode, diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/FeatureVectorValuesLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/FeatureVectorValuesLoader.java new file mode 100644 index 0000000000000000000000000000000000000000..79eaa38b29f824724b58b33412d2d8e0b6e0ec67 --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/FeatureVectorValuesLoader.java @@ -0,0 +1,60 @@ +/* + * Copyright 2011 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.plugin.screening.server.logic; + +import java.util.Arrays; +import java.util.List; + +import ch.systemsx.cisd.openbis.plugin.screening.server.IScreeningBusinessObjectFactory; +import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.FeatureVectorValues; +import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.WellFeatureVectorReference; +import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.WellLocation; +import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.FeatureVectorLoader.WellFeatureCollection; +import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.IHCSFeatureVectorLoader; + +/** + * @author Kaloyan Enimanev + */ +public class FeatureVectorValuesLoader +{ + + public static FeatureVectorValues loadFeatureVectorValues( + IScreeningBusinessObjectFactory businessObjectFactory, + String datasetCode, String datastoreCode, WellLocation wellLocation) + { + IHCSFeatureVectorLoader loader = + businessObjectFactory.createHCSFeatureVectorLoader(datastoreCode); + + List<WellFeatureVectorReference> wellReferences = + Arrays.asList(new WellFeatureVectorReference(datasetCode, wellLocation)); + WellFeatureCollection<FeatureVectorValues> featureVectors = + loader.fetchWellFeatureValuesIfPossible(wellReferences); + + List<FeatureVectorValues> features = featureVectors.getFeatures(); + if (features.size() == 0) + { + // Because of the way we are storing the features it can happen only if dataset contains + // no features (NaN are stored in the plate matrix for the wells which have no value + // specified). + return null; + } else + { + return featureVectors.getFeatures().get(0); + } + } + +} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoader.java index b56b6aa5cb848e8a34f8f17ea7830153f5592c44..3c09d44d421baf1e72c26a5c84aa0a082e7b7652 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoader.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoader.java @@ -100,8 +100,11 @@ public class WellContentLoader IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory, TechId geneMaterialId, String experimentPermId) { - return new WellContentLoader(session, businessObjectFactory, daoFactory).loadLocations( - geneMaterialId, experimentPermId); + WellContentLoader loader = + new WellContentLoader(session, businessObjectFactory, daoFactory); + + List<WellContent> contents = loader.loadLocations(geneMaterialId, experimentPermId); + return loader.enrichWithWellProperties(contents); } /** loads wells metadata, but no information about image or image analysis datasets */ @@ -109,8 +112,9 @@ public class WellContentLoader IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory, TechId geneMaterialId) { - return new WellContentLoader(session, businessObjectFactory, daoFactory) - .loadLocations(geneMaterialId); + final WellContentLoader loader = new WellContentLoader(session, businessObjectFactory, daoFactory); + List<WellContent> contents = loader.loadLocations(geneMaterialId); + return loader.enrichWithWellProperties(contents); } /** @@ -122,16 +126,14 @@ public class WellContentLoader IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory, WellSearchCriteria materialCriteria) { - return new WellContentLoader(session, businessObjectFactory, daoFactory) - .loadLocationsAndEnrich(materialCriteria); - } + WellContentLoader loader = + new WellContentLoader(session, businessObjectFactory, daoFactory); - public static FeatureVectorValues loadFeatureVectorValues(Session session, - IScreeningBusinessObjectFactory businessObjectFactory, IDAOFactory daoFactory, - String datasetCode, String datastoreCode, WellLocation wellLocation) - { - return new WellContentLoader(session, businessObjectFactory, daoFactory) - .getFeatureVectorValues(datasetCode, datastoreCode, wellLocation); + List<WellContent> locations = loader.loadLocations(materialCriteria); + List<WellContent> uniqueLocations = loader.filterWellDuplicates(locations); + List<WellContent> withProperties = loader.enrichWithWellProperties(uniqueLocations); + List<WellContent> withPropsAndDataSets = loader.enrichWithDatasets(withProperties); + return loader.enrichWithFeatureVectors(withPropsAndDataSets); } /** @@ -174,39 +176,6 @@ public class WellContentLoader this.daoFactory = daoFactory; } - private FeatureVectorValues getFeatureVectorValues(String dataSetCode, String datastoreCode, - WellLocation wellLocation) - { - IHCSFeatureVectorLoader loader = - businessObjectFactory.createHCSFeatureVectorLoader(datastoreCode); - - List<WellFeatureVectorReference> wellReferences = - Arrays.asList(new WellFeatureVectorReference(dataSetCode, wellLocation)); - WellFeatureCollection<FeatureVectorValues> featureVectors = - loader.fetchWellFeatureValuesIfPossible(wellReferences); - - List<FeatureVectorValues> features = featureVectors.getFeatures(); - if (features.size() == 0) - { - // Because of the way we are storing the features it can happen only if dataset contains - // no features (NaN are stored in the plate matrix for the wells which have no value - // specified). - return null; - } else - { - return featureVectors.getFeatures().get(0); - } - } - - private List<WellContent> loadLocationsAndEnrich(WellSearchCriteria materialCriteria) - { - List<WellContent> locations = loadLocations(materialCriteria); - List<WellContent> uniqueLocations = filterWellDuplicates(locations); - List<WellContent> withProperties = enrichWithWellProperties(uniqueLocations); - List<WellContent> withPropsAndDataSets = enrichWithDatasets(withProperties); - return enrichWithFeatureVectors(withPropsAndDataSets); - } - private List<WellContent> filterWellDuplicates(List<WellContent> wellContents) { Set<String> seenPermIds = new HashSet<String>();