Skip to content
Snippets Groups Projects
Commit e05c823e authored by tpylak's avatar tpylak
Browse files

LMS-1939 improve specific DSS uploading plugin

SVN: 19194
parent aaca0793
No related branches found
No related tags found
No related merge requests found
...@@ -20,8 +20,10 @@ import java.io.File; ...@@ -20,8 +20,10 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import javax.sql.DataSource; import javax.sql.DataSource;
...@@ -50,6 +52,7 @@ import ch.systemsx.cisd.etlserver.hdf5.Hdf5Container; ...@@ -50,6 +52,7 @@ import ch.systemsx.cisd.etlserver.hdf5.Hdf5Container;
import ch.systemsx.cisd.etlserver.hdf5.HierarchicalStructureDuplicatorFileToHdf5; import ch.systemsx.cisd.etlserver.hdf5.HierarchicalStructureDuplicatorFileToHdf5;
import ch.systemsx.cisd.openbis.dss.Constants; import ch.systemsx.cisd.openbis.dss.Constants;
import ch.systemsx.cisd.openbis.dss.etl.dataaccess.IImagingQueryDAO; import ch.systemsx.cisd.openbis.dss.etl.dataaccess.IImagingQueryDAO;
import ch.systemsx.cisd.openbis.dss.etl.dto.ImageSeriesPoint;
import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider; import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
import ch.systemsx.cisd.openbis.generic.shared.dto.StorageFormat; import ch.systemsx.cisd.openbis.generic.shared.dto.StorageFormat;
...@@ -711,15 +714,17 @@ abstract class AbstractImageStorageProcessor extends AbstractStorageProcessor ...@@ -711,15 +714,17 @@ abstract class AbstractImageStorageProcessor extends AbstractStorageProcessor
protected static boolean hasImageSeries(List<AcquiredSingleImage> images) protected static boolean hasImageSeries(List<AcquiredSingleImage> images)
{ {
Set<ImageSeriesPoint> points = new HashSet<ImageSeriesPoint>();
for (AcquiredSingleImage image : images) for (AcquiredSingleImage image : images)
{ {
if (image.tryGetTimePoint() != null || image.tryGetDepth() != null if (image.tryGetTimePoint() != null || image.tryGetDepth() != null
|| image.tryGetSeriesNumber() != null) || image.tryGetSeriesNumber() != null)
{ {
return true; points.add(new ImageSeriesPoint(image.tryGetTimePoint(), image.tryGetDepth(), image
.tryGetSeriesNumber()));
} }
} }
return false; return points.size() > 1;
} }
} }
...@@ -25,6 +25,7 @@ import java.util.Set; ...@@ -25,6 +25,7 @@ import java.util.Set;
import ch.systemsx.cisd.bds.hcs.Geometry; import ch.systemsx.cisd.bds.hcs.Geometry;
import ch.systemsx.cisd.common.utilities.AbstractHashable; import ch.systemsx.cisd.common.utilities.AbstractHashable;
import ch.systemsx.cisd.openbis.dss.etl.dto.ImageSeriesPoint;
import ch.systemsx.cisd.openbis.plugin.screening.shared.dto.PlateDimension; import ch.systemsx.cisd.openbis.plugin.screening.shared.dto.PlateDimension;
/** /**
...@@ -119,85 +120,25 @@ public final class HCSImageCheckList ...@@ -119,85 +120,25 @@ public final class HCSImageCheckList
// Helper classes // Helper classes
// //
private static final class CheckDimension
{
private final Float timeOrNull;
private final Float depthOrNull;
private final Integer seriesNumberOrNull;
public CheckDimension(Float timeOrNull, Float depthOrNull, Integer seriesNumberOrNull)
{
this.timeOrNull = timeOrNull;
this.depthOrNull = depthOrNull;
this.seriesNumberOrNull = seriesNumberOrNull;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((depthOrNull == null) ? 0 : depthOrNull.hashCode());
result = prime * result + ((timeOrNull == null) ? 0 : timeOrNull.hashCode());
result =
prime * result
+ ((seriesNumberOrNull == null) ? 0 : seriesNumberOrNull.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CheckDimension other = (CheckDimension) obj;
if (depthOrNull == null)
{
if (other.depthOrNull != null)
return false;
} else if (!depthOrNull.equals(other.depthOrNull))
return false;
if (timeOrNull == null)
{
if (other.timeOrNull != null)
return false;
} else if (!timeOrNull.equals(other.timeOrNull))
return false;
if (seriesNumberOrNull == null)
{
if (other.seriesNumberOrNull != null)
return false;
} else if (!seriesNumberOrNull.equals(other.seriesNumberOrNull))
return false;
return true;
}
}
private static final class Check private static final class Check
{ {
private boolean checkedOff; private boolean checkedOff;
private final Set<CheckDimension> dimensions = new HashSet<CheckDimension>(); private final Set<ImageSeriesPoint> dimensions = new HashSet<ImageSeriesPoint>();
final void checkOff(Float timepointOrNull, Float depthOrNull, Integer seriesNumberOrNull) final void checkOff(Float timepointOrNull, Float depthOrNull, Integer seriesNumberOrNull)
{ {
dimensions.add(new CheckDimension(timepointOrNull, depthOrNull, seriesNumberOrNull)); dimensions.add(new ImageSeriesPoint(timepointOrNull, depthOrNull, seriesNumberOrNull));
checkedOff = true; checkedOff = true;
} }
final boolean isCheckedOff(Float timepointOrNull, Float depthOrNull, final boolean isCheckedOff(Float timepointOrNull, Float depthOrNull,
Integer seriesNumberOrNull) Integer seriesNumberOrNull)
{ {
CheckDimension dim = null; ImageSeriesPoint dim = null;
if (timepointOrNull != null || depthOrNull != null || seriesNumberOrNull != null) if (timepointOrNull != null || depthOrNull != null || seriesNumberOrNull != null)
{ {
dim = new CheckDimension(timepointOrNull, depthOrNull, seriesNumberOrNull); dim = new ImageSeriesPoint(timepointOrNull, depthOrNull, seriesNumberOrNull);
} }
return checkedOff && (dim == null || dimensions.contains(dim)); return checkedOff && (dim == null || dimensions.contains(dim));
} }
......
...@@ -121,7 +121,7 @@ public class UnparsedImageFileInfoLexer ...@@ -121,7 +121,7 @@ public class UnparsedImageFileInfoLexer
return info; return info;
} }
private static Map<Character, String> extractTokensMap(String text) public static Map<Character, String> extractTokensMap(String text)
{ {
Map<Character, String> tokensMap = new HashMap<Character, String>(); Map<Character, String> tokensMap = new HashMap<Character, String>();
String[] tokens = StringUtils.split(text, TOKENS_SEPARATOR); String[] tokens = StringUtils.split(text, TOKENS_SEPARATOR);
......
...@@ -66,17 +66,22 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor ...@@ -66,17 +66,22 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor
static final String PLATE_GEOMETRY = "plate-geometry"; static final String PLATE_GEOMETRY = "plate-geometry";
static final String SEPARATOR = "separator";
private final String spaceCode; private final String spaceCode;
private final String projectCode; private final String projectCode;
private final String defaultPlateGeometryOrNull; private final String defaultPlateGeometryOrNull;
private final String separatorOrNull;
public BZDataSetInfoExtractor(final Properties properties) public BZDataSetInfoExtractor(final Properties properties)
{ {
spaceCode = PropertyUtils.getMandatoryProperty(properties, SPACE_CODE); spaceCode = PropertyUtils.getMandatoryProperty(properties, SPACE_CODE);
projectCode = PropertyUtils.getMandatoryProperty(properties, PROJECT_CODE); projectCode = PropertyUtils.getMandatoryProperty(properties, PROJECT_CODE);
defaultPlateGeometryOrNull = properties.getProperty(PLATE_GEOMETRY); defaultPlateGeometryOrNull = properties.getProperty(PLATE_GEOMETRY);
separatorOrNull = properties.getProperty(SEPARATOR);
} }
public DataSetInformation getDataSetInformation(File incomingDataSetPath, public DataSetInformation getDataSetInformation(File incomingDataSetPath,
...@@ -84,9 +89,16 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor ...@@ -84,9 +89,16 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor
EnvironmentFailureException EnvironmentFailureException
{ {
BZDatasetDirectoryNameTokenizer tokens = String fileBaseName = FilenameUtils.getBaseName(incomingDataSetPath.getPath());
new BZDatasetDirectoryNameTokenizer(FilenameUtils.getBaseName(incomingDataSetPath if (separatorOrNull != null)
.getPath())); {
int separatorIndex = fileBaseName.indexOf(separatorOrNull);
if (separatorIndex != -1)
{
fileBaseName = fileBaseName.substring(0, separatorIndex);
}
}
BZDatasetDirectoryNameTokenizer tokens = new BZDatasetDirectoryNameTokenizer(fileBaseName);
String sampleCode = getSampleCode(tokens); String sampleCode = getSampleCode(tokens);
String experimentCode = getExperiment(tokens); String experimentCode = getExperiment(tokens);
ExperimentIdentifier experimentIdentifier = ExperimentIdentifier experimentIdentifier =
...@@ -155,12 +167,6 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor ...@@ -155,12 +167,6 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor
if (experimentOrNull == null) if (experimentOrNull == null)
{ {
openbisService.registerExperiment(createExperimentSIRNAHCS(experimentIdentifier)); openbisService.registerExperiment(createExperimentSIRNAHCS(experimentIdentifier));
experimentOrNull = openbisService.tryToGetExperiment(experimentIdentifier);
if (experimentOrNull == null)
{
throw new UserFailureException(String.format("Experiment '%s' could not be found",
experimentIdentifier));
}
} }
openbisService.registerSample( openbisService.registerSample(
createPlate(sampleIdentifier, experimentIdentifier, plateGeometry), null); createPlate(sampleIdentifier, experimentIdentifier, plateGeometry), null);
...@@ -173,7 +179,7 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor ...@@ -173,7 +179,7 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor
private static String getSampleCode(BZDatasetDirectoryNameTokenizer tokens) private static String getSampleCode(BZDatasetDirectoryNameTokenizer tokens)
{ {
return "P_" + tokens.getExperimentToken() + "_" + tokens.getTimestampToken(); return "PLATE_" + tokens.getPlateBarcodeToken();
} }
private static IEntityProperty[] createVocabularyProperty(String propertyTypeCode, private static IEntityProperty[] createVocabularyProperty(String propertyTypeCode,
...@@ -231,7 +237,8 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor ...@@ -231,7 +237,8 @@ public class BZDataSetInfoExtractor implements IDataSetInfoExtractor
for (File imageFile : imageFiles) for (File imageFile : imageFiles)
{ {
UnparsedImageFileInfo imageInfo = UnparsedImageFileInfo imageInfo =
UnparsedImageFileInfoLexer.tryExtractHCSImageFileInfo(imageFile, incomingDataSetPath); UnparsedImageFileInfoLexer.tryExtractHCSImageFileInfo(imageFile,
incomingDataSetPath);
if (imageInfo != null) if (imageInfo != null)
{ {
String wellLocationToken = imageInfo.getWellLocationToken(); String wellLocationToken = imageInfo.getWellLocationToken();
......
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
package ch.systemsx.cisd.openbis.dss.etl.biozentrum; package ch.systemsx.cisd.openbis.dss.etl.biozentrum;
import org.apache.commons.lang.StringUtils; import java.util.Map;
import ch.systemsx.cisd.openbis.dss.etl.UnparsedImageFileInfoLexer;
/** /**
* Extracts useful information from dataset directory name specific to iBrain2. * Extracts useful information from dataset directory name specific to iBrain2.
...@@ -25,9 +27,17 @@ import org.apache.commons.lang.StringUtils; ...@@ -25,9 +27,17 @@ import org.apache.commons.lang.StringUtils;
*/ */
public class BZDatasetDirectoryNameTokenizer public class BZDatasetDirectoryNameTokenizer
{ {
private static final char EXPERIMENT_MARKER = 'i';
private static final char MICROSCOPE_MARKER = 'm';
private static final char PLATE_BARCODE_MARKER = 'b';
private static final char UNIQUE_ID_MARKER = 'u';
private final String experimentToken; private final String experimentToken;
private final String plateToken; private final String microscopeToken;
private final String barcodeToken; private final String barcodeToken;
...@@ -35,11 +45,11 @@ public class BZDatasetDirectoryNameTokenizer ...@@ -35,11 +45,11 @@ public class BZDatasetDirectoryNameTokenizer
BZDatasetDirectoryNameTokenizer(String identifier) BZDatasetDirectoryNameTokenizer(String identifier)
{ {
String[] namedParts = StringUtils.split(identifier, "_"); Map<Character, String> tokensMap = UnparsedImageFileInfoLexer.extractTokensMap(identifier);
experimentToken = StringUtils.split(namedParts[0], "-")[1]; experimentToken = tokensMap.get(EXPERIMENT_MARKER);
plateToken = StringUtils.split(namedParts[1], "-")[1]; microscopeToken = tokensMap.get(MICROSCOPE_MARKER);
barcodeToken = StringUtils.split(namedParts[2], "-")[1]; barcodeToken = tokensMap.get(PLATE_BARCODE_MARKER);
timestampToken = StringUtils.split(namedParts[3], "-")[1]; timestampToken = tokensMap.get(UNIQUE_ID_MARKER);
} }
public String getExperimentToken() public String getExperimentToken()
...@@ -47,17 +57,17 @@ public class BZDatasetDirectoryNameTokenizer ...@@ -47,17 +57,17 @@ public class BZDatasetDirectoryNameTokenizer
return experimentToken; return experimentToken;
} }
public String getPlateToken() public String getMicroscopeToken()
{ {
return plateToken; return microscopeToken;
} }
public String getBarcodeToken() public String getPlateBarcodeToken()
{ {
return barcodeToken; return barcodeToken;
} }
public String getTimestampToken() public String getUniqueIdToken()
{ {
return timestampToken; return timestampToken;
} }
......
/*
* 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.dto;
/**
* DTO which stores time, depth and series number (all optional).
*
* @author Tomasz Pylak
*/
public final class ImageSeriesPoint
{
private final Float timeOrNull;
private final Float depthOrNull;
private final Integer seriesNumberOrNull;
public ImageSeriesPoint(Float timeOrNull, Float depthOrNull, Integer seriesNumberOrNull)
{
this.timeOrNull = timeOrNull;
this.depthOrNull = depthOrNull;
this.seriesNumberOrNull = seriesNumberOrNull;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((depthOrNull == null) ? 0 : depthOrNull.hashCode());
result = prime * result + ((timeOrNull == null) ? 0 : timeOrNull.hashCode());
result =
prime * result + ((seriesNumberOrNull == null) ? 0 : seriesNumberOrNull.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ImageSeriesPoint other = (ImageSeriesPoint) obj;
if (depthOrNull == null)
{
if (other.depthOrNull != null)
return false;
} else if (!depthOrNull.equals(other.depthOrNull))
return false;
if (timeOrNull == null)
{
if (other.timeOrNull != null)
return false;
} else if (!timeOrNull.equals(other.timeOrNull))
return false;
if (seriesNumberOrNull == null)
{
if (other.seriesNumberOrNull != null)
return false;
} else if (!seriesNumberOrNull.equals(other.seriesNumberOrNull))
return false;
return true;
}
}
\ No newline at end of file
/*
* 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.testng.AssertJUnit;
import org.testng.annotations.Test;
/**
* @author Tomasz Pylak
*/
public class BZDatasetDirectoryNameTokenizerTest extends AssertJUnit
{
@Test
public void test()
{
BZDatasetDirectoryNameTokenizer tokenizer =
new BZDatasetDirectoryNameTokenizer(
"iBrucellaInfectionWF10_mBS-IX2_bRCB024_u0265626F");
assertEquals("BrucellaInfectionWF10", tokenizer.getExperimentToken());
assertEquals("BS-IX2", tokenizer.getMicroscopeToken());
assertEquals("RCB024", tokenizer.getPlateBarcodeToken());
assertEquals("0265626F", tokenizer.getUniqueIdToken());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment