From 864d2fd293fe223fc1748800e54d7813693af2c8 Mon Sep 17 00:00:00 2001 From: kaloyane <kaloyane> Date: Fri, 1 Apr 2011 14:08:23 +0000 Subject: [PATCH] [LMS-2163] refactor feature vector loading out of WellContentLoader, make the implementation of WellContentLoader.loadXXXX a bit more verbose and easy to read SVN: 20625 --- .../screening/server/ScreeningServer.java | 7 ++- .../logic/FeatureVectorValuesLoader.java | 60 ++++++++++++++++++ .../server/logic/WellContentLoader.java | 61 +++++-------------- 3 files changed, 79 insertions(+), 49 deletions(-) create mode 100644 screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/FeatureVectorValuesLoader.java 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 ba3c28560d0..e904d46ccbc 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 00000000000..79eaa38b29f --- /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 b56b6aa5cb8..3c09d44d421 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>(); -- GitLab