diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/imsb/HCSImageFileExtractor.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/imsb/HCSImageFileExtractor.java index fd65a1337f09564e4a34960d6c136bf839060971..9810a9d1e5debb1469e2a02f06b1fc16d1c55533 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/imsb/HCSImageFileExtractor.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/imsb/HCSImageFileExtractor.java @@ -82,14 +82,14 @@ public class HCSImageFileExtractor extends AbstractHCSImageFileExtractor impleme * </p> */ @Override - protected final int getChannelWavelength(final String value) + protected final int getChannelWavelength(final String channel) { final String startsWith = "w"; - if (value.startsWith(startsWith)) + if (channel.startsWith(startsWith)) { try { - return Integer.parseInt(value.substring(startsWith.length())); + return Integer.parseInt(channel.substring(startsWith.length())); } catch (final NumberFormatException ex) { // Nothing to do here. Rest of the code can handle this. @@ -111,9 +111,9 @@ public class HCSImageFileExtractor extends AbstractHCSImageFileExtractor impleme * </p> */ @Override - protected final Location tryGetWellLocation(final String value) + protected final Location tryGetWellLocation(final String wellLocation) { - return tryGetZigZagWellLocation(value, wellGeometry); + return tryGetZigZagWellLocation(wellLocation, wellGeometry); } public static Location tryGetZigZagWellLocation(String value, Geometry wellGeometry) diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/AbstractHCSImageFileExtractor.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/AbstractHCSImageFileExtractor.java index 9e23bf7e294759e112964a883985ef4d6d43769f..aec64f58b7d17fc69ffd126987e3a0dc294fdd31 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/AbstractHCSImageFileExtractor.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/plugins/AbstractHCSImageFileExtractor.java @@ -50,20 +50,6 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; */ abstract public class AbstractHCSImageFileExtractor { - /** - * Extracts the channel from given <var>value</var>, following the convention adopted here. - * <p> - * Returns <code>0</code> if the operation fails. - * </p> - */ - abstract protected int getChannelWavelength(final String value); - - /** - * Extracts the well location from given <var>value</var>. Returns <code>null</code> if the - * operation fails. - */ - abstract protected Location tryGetWellLocation(final String value); - private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, AbstractHCSImageFileExtractor.class); @@ -71,7 +57,7 @@ abstract public class AbstractHCSImageFileExtractor "Image file '%s' could not be standardized given following tokens [plateLocation=%s,wellLocation=%s,channel=%s]."; static final String IMAGE_FILE_NOT_ENOUGH_ENTITIES = - "Image file '%s' does not have enough entities."; + "The name of image file '%s' could not be splitted into enough entities."; static final String IMAGE_FILE_BELONGS_TO_WRONG_SAMPLE = "Image file '%s' belongs to the wrong sample [expected=%s,found=%s]."; @@ -111,18 +97,6 @@ abstract public class AbstractHCSImageFileExtractor return geometry; } - /** - * Extracts the plate location from given <var>value</var>, following the convention adopted - * here. - * <p> - * Returns <code>null</code> if the operation fails. - * </p> - */ - protected final static Location tryGetPlateLocation(final String value) - { - return Location.tryCreateLocationFromMatrixCoordinate(value); - } - /** Perform channel wavelength sorting on images. */ protected static class ChannelWavelengthSortingHCSImageFileAccepterDecorator implements IHCSImageFileAccepter @@ -214,8 +188,8 @@ abstract public class AbstractHCSImageFileExtractor operationLog.debug(String.format("Processing image file '%s'", imageFile)); } final String baseName = FilenameUtils.getBaseName(imageFile.getPath()); - final String[] tokens = StringUtils.split(baseName, TOKEN_SEPARATOR); - if (tokens.length < 4) + final String[] tokens = tryToSplitIntoTokens(baseName); + if (tokens == null || tokens.length < 4) { if (operationLog.isDebugEnabled()) { @@ -225,7 +199,7 @@ abstract public class AbstractHCSImageFileExtractor continue; } final String sampleCode = tokens[tokens.length - 4]; - if (sampleCode.equals(dataSetInformation.getSampleCode()) == false) + if (sampleCode != null && sampleCode.equals(dataSetInformation.getSampleCode()) == false) { if (operationLog.isDebugEnabled()) { @@ -264,4 +238,42 @@ abstract public class AbstractHCSImageFileExtractor .size(), Collections.unmodifiableList(invalidFiles), accepterDecorator .getChannels()); } + + /** + * Splits specified image file name into at least four tokens. Only the last four tokens + * will be considered. They are sample code, plate location, well location, and channel. + * Note, that sample code could be <code>null</code>. + * <p> + * Subclasses may override this method. + * + * @return <code>null</code> if the argument could not be splitted into tokens. + */ + protected String[] tryToSplitIntoTokens(final String imageFileName) + { + return StringUtils.split(imageFileName, TOKEN_SEPARATOR); + } + + /** + * Extracts the channel from specified channel string. + * <p> + * Returns <code>0</code> if the operation fails. Otherwise a positive number is returned. + * </p> + */ + abstract protected int getChannelWavelength(final String channel); + + /** + * Extracts the well location from argument. Returns <code>null</code> if the operation fails. + */ + abstract protected Location tryGetWellLocation(final String wellLocation); + + /** + * Extracts the plate location from argument. Returns <code>null</code> if the operation fails. + * <p> + * Subclasses may override this method. + */ + protected Location tryGetPlateLocation(final String plateLocation) + { + return Location.tryCreateLocationFromMatrixCoordinate(plateLocation); + } + }