diff --git a/screening/dist/etc/service.properties b/screening/dist/etc/service.properties index cb5fb7967b15d46046b73ba4d8ead547ccab6fc6..b2400892d2ac5a98da3cf8b417b115fab9c15c75 100644 --- a/screening/dist/etc/service.properties +++ b/screening/dist/etc/service.properties @@ -112,7 +112,7 @@ default-plate-image-analysis.properties-file = plate-image-analysis-graph.label = Image Analysis Graphs plate-image-analysis-graph.dataset-types = HCS_IMAGE_ANALYSIS_DATA, HCS_ANALYSIS_PER_GENE -plate-image-analysis-graph.class = ch.systemsx.cisd.openbis.dss.generic.server.plugins.DatabaseImageAnalysisGraphReportingPlugin +plate-image-analysis-graph.class = ch.systemsx.cisd.openbis.dss.generic.server.plugins.ImageAnalysisGraphReportingPlugin plate-image-analysis-graph.servlet-path = datastore_server_graph/ plate-image-analysis-graph.properties-file = etc/tabular-data-graph.properties @@ -128,7 +128,7 @@ screening-image-download-servlet.class = ch.systemsx.cisd.openbis.dss.generic.se # URL which will be mapped to this servlet screening-image-download-servlet.path = /datastore_server_screening/* -tabular-data-graph-servlet.class = ch.systemsx.cisd.openbis.dss.generic.server.ImagingDataGraphServlet +tabular-data-graph-servlet.class = ch.systemsx.cisd.openbis.dss.generic.server.TabularDataGraphServlet tabular-data-graph-servlet.path = /datastore_server_graph/* tabular-data-graph-servlet.properties-file = etc/tabular-data-graph.properties diff --git a/screening/etc/service.properties b/screening/etc/service.properties index e002a253193edaf568ef8fb6d5e1d673a944aa49..31c0a913abb6169d322979c35d0b3667db69b74e 100644 --- a/screening/etc/service.properties +++ b/screening/etc/service.properties @@ -106,7 +106,7 @@ default-plate-image-analysis.properties-file = plate-image-analysis-graph.label = Image Analysis Graphs plate-image-analysis-graph.dataset-types = HCS_IMAGE_ANALYSIS_DATA, HCS_ANALYSIS_PER_GENE -plate-image-analysis-graph.class = ch.systemsx.cisd.openbis.dss.generic.server.plugins.DatabaseImageAnalysisGraphReportingPlugin +plate-image-analysis-graph.class = ch.systemsx.cisd.openbis.dss.generic.server.plugins.ImageAnalysisGraphReportingPlugin plate-image-analysis-graph.servlet-path = datastore_server_graph/ plate-image-analysis-graph.properties-file = etc/tabular-data-graph.properties @@ -122,7 +122,7 @@ screening-image-download-servlet.class = ch.systemsx.cisd.openbis.dss.generic.se # URL which will be mapped to this servlet screening-image-download-servlet.path = /datastore_server_screening/* -tabular-data-graph-servlet.class = ch.systemsx.cisd.openbis.dss.generic.server.ImagingDataGraphServlet +tabular-data-graph-servlet.class = ch.systemsx.cisd.openbis.dss.generic.server.TabularDataGraphServlet tabular-data-graph-servlet.path = /datastore_server_graph/* tabular-data-graph-servlet.properties-file = etc/tabular-data-graph.properties diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/FileTabularDataGraphServlet.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/FileTabularDataGraphServlet.java new file mode 100644 index 0000000000000000000000000000000000000000..df7ed6ce97e2c3288d1282b4aa8e168bfe8af24a --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/FileTabularDataGraphServlet.java @@ -0,0 +1,47 @@ +/* + * 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.generic.server; + +import java.io.File; +import java.io.IOException; + +import ch.systemsx.cisd.common.exceptions.UserFailureException; +import ch.systemsx.cisd.openbis.dss.generic.server.plugins.tasks.ITabularData; +import ch.systemsx.cisd.utils.CsvFileReaderHelper; + +/** + * @author Chandrasekhar Ramakrishnan + */ +public class FileTabularDataGraphServlet extends AbstractTabularDataGraphServlet +{ + private static final long serialVersionUID = 1L; + + /** + * Return the tabular data from a file as a DatasetFileLines. + */ + @Override + protected ITabularData getDatasetLines(String dataSetCode, String pathOrNull) + throws IOException + { + if (pathOrNull == null) + { + throw new UserFailureException("No value for the parameter " + FILE_PATH_PARAM + + " found in the URL"); + } + return CsvFileReaderHelper.getDatasetFileLines(new File(pathOrNull), configuration); + } +} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ImagingDataGraphServlet.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ImagingDataGraphServlet.java deleted file mode 100644 index 3aa322e29f9344bd78d728e937cc84fc67d20a57..0000000000000000000000000000000000000000 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ImagingDataGraphServlet.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * 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.generic.server; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import ch.systemsx.cisd.openbis.dss.generic.server.plugins.tasks.ITabularData; -import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; -import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider; -import ch.systemsx.cisd.openbis.dss.shared.DssScreeningUtils; -import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.WellPosition; -import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.PlateUtils; -import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.dataaccess.IImagingQueryDAO; - -/** - * Create a graph from the imaging database. - * <p> - * TODO 2010-08-09, CR, LMS-1692, This implementation is inefficient. The better way to implement - * this would be to lazily get feature vectors necessary for generating the graph, not to egerly get - * all feature vectors. - * - * @author Chandrasekhar Ramakrishnan - */ -public class ImagingDataGraphServlet extends AbstractTabularDataGraphServlet -{ - - private static final long serialVersionUID = 1L; - - private IImagingQueryDAO imagingDbDao; - - private IEncapsulatedOpenBISService openBisService; - - /** - * An CSV-file-like interface to feature data from the database. - * - * @author Chandrasekhar Ramakrishnan - */ - private final class ImagingTabularData implements ITabularData - { - private static final String WELL_NAME_COLUMN = "WellName"; - - private static final String WELL_ROW_COLUMN = "Row"; - - private static final String WELL_COLUMN_COLUMN = "Column"; - - private final IImagingQueryDAO dao; - - private final IEncapsulatedOpenBISService service; - - private final String dataSetCode; - - private String[] headerTokens; - - private ArrayList<String[]> lines; - - private ImagingTabularData(IImagingQueryDAO dao, IEncapsulatedOpenBISService service, - String dataSetCode) - { - this.dao = dao; - this.service = service; - this.dataSetCode = dataSetCode; - initialize(); - } - - private void initialize() - { - final FeatureTableBuilder tableBuilder = new FeatureTableBuilder(dao, service); - tableBuilder.addFeatureVectorsOfDataSet(dataSetCode); - - List<String> featureNames = tableBuilder.getFeatureNames(); - int headerTokensLength = featureNames.size() + 3; - headerTokens = new String[headerTokensLength]; - headerTokens[0] = WELL_NAME_COLUMN; - headerTokens[1] = WELL_ROW_COLUMN; - headerTokens[2] = WELL_COLUMN_COLUMN; - - int i = 1; - for (String name : featureNames) - { - headerTokens[i++] = name; - } - - lines = new ArrayList<String[]>(); - - final List<FeatureTableRow> rows = tableBuilder.createFeatureTableRows(); - for (FeatureTableRow row : rows) - { - String[] line = new String[headerTokensLength]; - WellPosition pos = row.getWellPosition(); - String rowLetter = PlateUtils.translateRowNumberIntoLetterCode(pos.getWellRow()); - String columnNumber = Integer.toString(row.getWellPosition().getWellColumn()); - line[0] = rowLetter + columnNumber; - line[1] = rowLetter; - line[2] = columnNumber; - i = 1; - float[] values = row.getFeatureValues(); - for (float value : values) - { - line[i++] = Float.toString(value); - } - lines.add(line); - } - // final ImgDatasetDTO dataSet = dao.tryGetDatasetByPermId(dataSetCode); - // if (dataSet == null) - // { - // throw new UserFailureException("Unkown data set " + dataSetCode); - // } - // - // final List<ImgFeatureDefDTO> featureDefinitions = - // dao.listFeatureDefsByDataSetId(dataSet.getId()); - // - // int headersLength = featureDefinitions.size(); - // headerTokens = new String[headersLength]; - // lines = new ArrayList<String[]>(); - // int featureDefCount = 0; - // for (ImgFeatureDefDTO featureDefinition : featureDefinitions) - // { - // headerTokens[featureDefCount++] = featureDefinition.getName(); - // } - // int numRows = dataSet.getFieldNumberOfRows(); - // int numCols = dataSet.getFieldNumberOfColumns(); - // for (int row = 0; row < numRows; ++row) - // { - // for (int col = 0; col < numCols; ++col) - // { - // for (ImgFeatureDefDTO featureDefinition : featureDefinitions) - // { - // List<ImgFeatureValuesDTO> featureValues = - // dao.getFeatureValues(featureDefinition); - // } - // } - // } - } - - public List<String[]> getDataLines() - { - return lines; - } - - public String[] getHeaderTokens() - { - return headerTokens; - } - - } - - @Override - protected ITabularData getDatasetLines(String dataSetCode, String filePathOrNull) - throws IOException - { - return new ImagingTabularData(getDAO(), getService(), dataSetCode); - } - - private IImagingQueryDAO getDAO() - { - synchronized (this) - { - if (imagingDbDao == null) - { - imagingDbDao = DssScreeningUtils.createQuery(); - } - } - return imagingDbDao; - } - - private IEncapsulatedOpenBISService getService() - { - synchronized (this) - { - if (openBisService == null) - { - openBisService = ServiceProvider.getOpenBISService(); - } - } - return openBisService; - } - -} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/TabularDataGraphServlet.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/TabularDataGraphServlet.java index 7fc440aef448b2eef2d03c66849e968bbece40f8..d988553b942530b6dafdc98c3cabbf205abc08bb 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/TabularDataGraphServlet.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/TabularDataGraphServlet.java @@ -16,32 +16,179 @@ package ch.systemsx.cisd.openbis.dss.generic.server; -import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; -import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.dss.generic.server.plugins.tasks.ITabularData; -import ch.systemsx.cisd.utils.CsvFileReaderHelper; +import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; +import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider; +import ch.systemsx.cisd.openbis.dss.shared.DssScreeningUtils; +import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.WellPosition; +import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.PlateUtils; +import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.dataaccess.IImagingQueryDAO; /** + * Create a graph from the imaging database. + * <p> + * TODO 2010-08-09, CR, LMS-1692, This implementation is inefficient. The better way to implement + * this would be to lazily get feature vectors necessary for generating the graph, not to egerly get + * all feature vectors. + * * @author Chandrasekhar Ramakrishnan */ public class TabularDataGraphServlet extends AbstractTabularDataGraphServlet { + private static final long serialVersionUID = 1L; + private IImagingQueryDAO imagingDbDao; + + private IEncapsulatedOpenBISService openBisService; + /** - * Return the tabular data from a file as a DatasetFileLines. + * An CSV-file-like interface to feature data from the database. + * + * @author Chandrasekhar Ramakrishnan */ + private final class ImagingTabularData implements ITabularData + { + private static final String WELL_NAME_COLUMN = "WellName"; + + private static final String WELL_ROW_COLUMN = "Row"; + + private static final String WELL_COLUMN_COLUMN = "Column"; + + private final IImagingQueryDAO dao; + + private final IEncapsulatedOpenBISService service; + + private final String dataSetCode; + + private String[] headerTokens; + + private ArrayList<String[]> lines; + + private ImagingTabularData(IImagingQueryDAO dao, IEncapsulatedOpenBISService service, + String dataSetCode) + { + this.dao = dao; + this.service = service; + this.dataSetCode = dataSetCode; + initialize(); + } + + private void initialize() + { + final FeatureTableBuilder tableBuilder = new FeatureTableBuilder(dao, service); + tableBuilder.addFeatureVectorsOfDataSet(dataSetCode); + + List<String> featureNames = tableBuilder.getFeatureNames(); + int headerTokensLength = featureNames.size() + 3; + headerTokens = new String[headerTokensLength]; + headerTokens[0] = WELL_NAME_COLUMN; + headerTokens[1] = WELL_ROW_COLUMN; + headerTokens[2] = WELL_COLUMN_COLUMN; + + int i = 1; + for (String name : featureNames) + { + headerTokens[i++] = name; + } + + lines = new ArrayList<String[]>(); + + final List<FeatureTableRow> rows = tableBuilder.createFeatureTableRows(); + for (FeatureTableRow row : rows) + { + String[] line = new String[headerTokensLength]; + WellPosition pos = row.getWellPosition(); + String rowLetter = PlateUtils.translateRowNumberIntoLetterCode(pos.getWellRow()); + String columnNumber = Integer.toString(row.getWellPosition().getWellColumn()); + line[0] = rowLetter + columnNumber; + line[1] = rowLetter; + line[2] = columnNumber; + i = 1; + float[] values = row.getFeatureValues(); + for (float value : values) + { + line[i++] = Float.toString(value); + } + lines.add(line); + } + // final ImgDatasetDTO dataSet = dao.tryGetDatasetByPermId(dataSetCode); + // if (dataSet == null) + // { + // throw new UserFailureException("Unkown data set " + dataSetCode); + // } + // + // final List<ImgFeatureDefDTO> featureDefinitions = + // dao.listFeatureDefsByDataSetId(dataSet.getId()); + // + // int headersLength = featureDefinitions.size(); + // headerTokens = new String[headersLength]; + // lines = new ArrayList<String[]>(); + // int featureDefCount = 0; + // for (ImgFeatureDefDTO featureDefinition : featureDefinitions) + // { + // headerTokens[featureDefCount++] = featureDefinition.getName(); + // } + // int numRows = dataSet.getFieldNumberOfRows(); + // int numCols = dataSet.getFieldNumberOfColumns(); + // for (int row = 0; row < numRows; ++row) + // { + // for (int col = 0; col < numCols; ++col) + // { + // for (ImgFeatureDefDTO featureDefinition : featureDefinitions) + // { + // List<ImgFeatureValuesDTO> featureValues = + // dao.getFeatureValues(featureDefinition); + // } + // } + // } + } + + public List<String[]> getDataLines() + { + return lines; + } + + public String[] getHeaderTokens() + { + return headerTokens; + } + + } + @Override - protected ITabularData getDatasetLines(String dataSetCode, String pathOrNull) + protected ITabularData getDatasetLines(String dataSetCode, String filePathOrNull) throws IOException { - if (pathOrNull == null) + return new ImagingTabularData(getDAO(), getService(), dataSetCode); + } + + private IImagingQueryDAO getDAO() + { + synchronized (this) { - throw new UserFailureException("No value for the parameter " + FILE_PATH_PARAM - + " found in the URL"); + if (imagingDbDao == null) + { + imagingDbDao = DssScreeningUtils.createQuery(); + } } - return CsvFileReaderHelper.getDatasetFileLines(new File(pathOrNull), configuration); + return imagingDbDao; } + + private IEncapsulatedOpenBISService getService() + { + synchronized (this) + { + if (openBisService == null) + { + openBisService = ServiceProvider.getOpenBISService(); + } + } + return openBisService; + } + } diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/FileBasedImageAnalysisGraphReportingPlugin.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/FileBasedImageAnalysisGraphReportingPlugin.java index 1c2d1dc5f67c85dbb76603f098ac04c430860316..14fde7f96d2df93252b2ae323711e9b90acac4c3 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/FileBasedImageAnalysisGraphReportingPlugin.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/FileBasedImageAnalysisGraphReportingPlugin.java @@ -37,7 +37,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription; * Reporting plugin that returns a table in which each column contains a graph. The number and * format of the graphs can be configured in a properties file. * <p> - * This plugin reads data from a file. The {@link DatabaseImageAnalysisGraphReportingPlugin} reads + * This plugin reads data from a file. The {@link ImageAnalysisGraphReportingPlugin} reads * from the imaging db. * * @author Chandrasekhar Ramakrishnan @@ -63,7 +63,7 @@ public class FileBasedImageAnalysisGraphReportingPlugin extends AbstractDataMerg if (propertiesFilePath == null) { throw new EnvironmentFailureException( - "DatabaseImageAnalysisGraphReportingPlugin requires a properties file (specified with the " + "ImageAnalysisGraphReportingPlugin requires a properties file (specified with the " + PROPERTIES_FILE_KEY + "key)."); } diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/DatabaseImageAnalysisGraphReportingPlugin.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/ImageAnalysisGraphReportingPlugin.java similarity index 94% rename from screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/DatabaseImageAnalysisGraphReportingPlugin.java rename to screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/ImageAnalysisGraphReportingPlugin.java index b0b7400e664c99235384cc1ed378714688446bb1..a175ff96145b3262724ab2b1726928ec458aab5b 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/DatabaseImageAnalysisGraphReportingPlugin.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/ImageAnalysisGraphReportingPlugin.java @@ -41,7 +41,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription; * * @author Chandrasekhar Ramakrishnan */ -public class DatabaseImageAnalysisGraphReportingPlugin extends AbstractDataMergingReportingPlugin +public class ImageAnalysisGraphReportingPlugin extends AbstractDataMergingReportingPlugin { private static final long serialVersionUID = 1L; @@ -54,7 +54,7 @@ public class DatabaseImageAnalysisGraphReportingPlugin extends AbstractDataMergi private final static String PROPERTIES_FILE_KEY = "properties-file"; - public DatabaseImageAnalysisGraphReportingPlugin(Properties properties, File storeRoot) + public ImageAnalysisGraphReportingPlugin(Properties properties, File storeRoot) { super(properties, storeRoot, SEMICOLON_SEPARATOR); graphServletPath = properties.getProperty(SERVLET_PATH_PROP, "datastore_server_graph/"); @@ -62,7 +62,7 @@ public class DatabaseImageAnalysisGraphReportingPlugin extends AbstractDataMergi if (propertiesFilePath == null) { throw new EnvironmentFailureException( - "DatabaseImageAnalysisGraphReportingPlugin requires a properties file (specified with the " + "ImageAnalysisGraphReportingPlugin requires a properties file (specified with the " + PROPERTIES_FILE_KEY + "key)."); }