diff --git a/bds/source/java/ch/systemsx/cisd/bds/IFormatParameterFactory.java b/bds/source/java/ch/systemsx/cisd/bds/IFormatParameterFactory.java index fd291b6e5d8d9cdc32941fc24f3da54cb1051d87..892a54390ecb8aa2a92721db0a3147dc0a91933b 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/IFormatParameterFactory.java +++ b/bds/source/java/ch/systemsx/cisd/bds/IFormatParameterFactory.java @@ -44,6 +44,11 @@ public interface IFormatParameterFactory } return null; } + + public final FormatParameter createFormatParameter(final String name, final String value) + { + return null; + } }; /** @@ -53,4 +58,15 @@ public interface IFormatParameterFactory * <code>INode</code>. */ public FormatParameter createFormatParameter(final INode node); + + /** + * Creates a <code>FormatParameter</code> from given <var>value</var>. + * + * @param name name of the format parameter. Usually it is one of the values returned by + * {@link Format#getParameterNames()}. + * @param value generic value that should help to construct the <code>FormatParameter</code>. + * @return <code>null</code> if no appropriate <code>FormatParameter</code> could be created from given + * <code>value</code>. + */ + public FormatParameter createFormatParameter(final String name, final String value); } diff --git a/bds/source/java/ch/systemsx/cisd/bds/hcs/FormatParameterFactory.java b/bds/source/java/ch/systemsx/cisd/bds/hcs/FormatParameterFactory.java index 68a780cb445834bdccb233234e8435782cff9e32..f6266bdf0b80bf95bb1e7411d0876947622aa5cc 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/hcs/FormatParameterFactory.java +++ b/bds/source/java/ch/systemsx/cisd/bds/hcs/FormatParameterFactory.java @@ -30,6 +30,23 @@ import ch.systemsx.cisd.bds.storage.INode; public final class FormatParameterFactory implements IFormatParameterFactory { + private static IFormatParameterFactory instance; + + private FormatParameterFactory() + { + // Can not be instantiated. + } + + /** Returns the unique instance of this class. */ + public final synchronized static IFormatParameterFactory getInstance() + { + if (instance == null) + { + instance = new FormatParameterFactory(); + } + return instance; + } + // // IFormatParameterFactory // @@ -58,4 +75,27 @@ public final class FormatParameterFactory implements IFormatParameterFactory } return IFormatParameterFactory.DEFAULT_FORMAT_PARAMETER_FACTORY.createFormatParameter(node); } + + public final FormatParameter createFormatParameter(final String name, final String value) + { + if (name.equals(PlateGeometry.PLATE_GEOMETRY)) + { + final Geometry geometry = Geometry.createFromString(value); + if (geometry != null) + { + return new FormatParameter(name, new PlateGeometry(geometry)); + } + } else if (name.equals(WellGeometry.WELL_GEOMETRY)) + { + final Geometry geometry = Geometry.createFromString(value); + if (geometry != null) + { + return new FormatParameter(name, new WellGeometry(geometry)); + } + } else if (name.equals(ChannelList.NUMBER_OF_CHANNELS)) + { + return new FormatParameter(name, ChannelList.createChannelListFromString(value)); + } + return IFormatParameterFactory.DEFAULT_FORMAT_PARAMETER_FACTORY.createFormatParameter(name, value); + } } diff --git a/bds/source/java/ch/systemsx/cisd/bds/hcs/HCSImageFormattedData.java b/bds/source/java/ch/systemsx/cisd/bds/hcs/HCSImageFormattedData.java index 1b0994e18b8bf8b4ba8972ea93136091e176fe62..f6daf488528f3a59255dd0e79177da31762b0b5e 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/hcs/HCSImageFormattedData.java +++ b/bds/source/java/ch/systemsx/cisd/bds/hcs/HCSImageFormattedData.java @@ -20,6 +20,7 @@ import java.util.HashSet; import java.util.Set; import ch.systemsx.cisd.bds.AbstractFormattedData; +import ch.systemsx.cisd.bds.Constants; import ch.systemsx.cisd.bds.DataStructureV1_0; import ch.systemsx.cisd.bds.Format; import ch.systemsx.cisd.bds.FormattedDataContext; @@ -37,7 +38,7 @@ import ch.systemsx.cisd.bds.storage.INode; * * @author Christian Ribeaud */ -public final class HCSImageFormattedData extends AbstractFormattedData implements IHCSFormattedData +public final class HCSImageFormattedData extends AbstractFormattedData implements IHCSImageFormattedData { /** The <i>column</i> (or <i>x</i>) coordinate. */ @@ -46,14 +47,6 @@ public final class HCSImageFormattedData extends AbstractFormattedData implement /** The <i>row</i> (or <i>y</i>) coordinate. */ public static final String ROW = "row"; - /** - * The mandatory format parameters that must be defined so that this implementation is able to work properly. - */ - final static String[] MANDATORY_FORMAT_PARAMETERS = - new String[] - { PlateGeometry.PLATE_GEOMETRY, WellGeometry.WELL_GEOMETRY, ChannelList.NUMBER_OF_CHANNELS, - HCSImageFormat1_0.CONTAINS_ORIGINAL_DATA, HCSImageFormat1_0.DEVICE_ID }; - public HCSImageFormattedData(final FormattedDataContext context) { super(context); @@ -157,7 +150,7 @@ public final class HCSImageFormattedData extends AbstractFormattedData implement return plateColumnDir.tryGetNode(createWellFileName(wellLocation)); } - public final INode addStandardNode(final String originalFileName, int channel, final Location plateLocation, + public final NodePath addStandardNode(final String originalFilePath, int channel, final Location plateLocation, final Location wellLocation) { // This will check all parameters but originalFileName. @@ -168,18 +161,18 @@ public final class HCSImageFormattedData extends AbstractFormattedData implement "A node already exists at channel %d, plate location '%s' and well location '%s'.", channel, plateLocation, wellLocation)); } - assert originalFileName != null : "Given original file name can not be null."; + assert originalFilePath != null : "Given original file name can not be null."; final IDirectory standardDir = getStandardDataDirectory(); final IDirectory channelDir = Utilities.getOrCreateSubDirectory(standardDir, getChannelName(channel)); final IDirectory plateRowDir = Utilities.getOrCreateSubDirectory(channelDir, getPlateRowDirName(plateLocation)); final IDirectory plateColumnDir = Utilities.getOrCreateSubDirectory(plateRowDir, getPlateColumnDir(plateLocation)); final String wellFileName = createWellFileName(wellLocation); - final INode originalNode = getOriginalDataDirectory().tryGetNode(originalFileName); + final INode originalNode = getOriginalDataDirectory().tryGetNode(originalFilePath); if (originalNode == null) { throw new DataStructureException(String.format("No original node with name '%s' could be found.", - originalFileName)); + originalFilePath)); } if (containsOriginalData()) { @@ -194,9 +187,12 @@ public final class HCSImageFormattedData extends AbstractFormattedData implement String .format( "Original file name '%s' could not be added at channel %d, plate location '%s' and well location '%s'.", - originalFileName, channel, plateLocation, wellLocation)); + originalFilePath, channel, plateLocation, wellLocation)); } - return node; + final char sep = Constants.PATH_SEPARATOR; + final String standardNodePath = channelDir.getName() + sep + plateRowDir.getName() + sep + plateColumnDir + sep + + wellFileName; + return new NodePath(node, standardNodePath); } // @@ -214,7 +210,7 @@ public final class HCSImageFormattedData extends AbstractFormattedData implement super.assertValidFormatAndFormatParameters(); final IFormatParameters formatParameters = getFormatParameters(); final Set<String> notPresent = new HashSet<String>(); - for (final String formatParameterName : MANDATORY_FORMAT_PARAMETERS) + for (final String formatParameterName : format.getParameterNames()) { if (formatParameters.containsParameter(formatParameterName) == false) { diff --git a/bds/source/java/ch/systemsx/cisd/bds/hcs/IHCSFormattedData.java b/bds/source/java/ch/systemsx/cisd/bds/hcs/IHCSImageFormattedData.java similarity index 63% rename from bds/source/java/ch/systemsx/cisd/bds/hcs/IHCSFormattedData.java rename to bds/source/java/ch/systemsx/cisd/bds/hcs/IHCSImageFormattedData.java index a0247918ff4e33d2d328fed09031858d4beee3b3..afe3b7712909b57abaf715971546d0eb4796f45f 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/hcs/IHCSFormattedData.java +++ b/bds/source/java/ch/systemsx/cisd/bds/hcs/IHCSImageFormattedData.java @@ -27,7 +27,7 @@ import ch.systemsx.cisd.bds.storage.INode; * * @author Christian Ribeaud */ -public interface IHCSFormattedData extends IFormattedData +public interface IHCSImageFormattedData extends IFormattedData { /** @@ -40,12 +40,32 @@ public interface IHCSFormattedData extends IFormattedData public INode tryGetStandardNodeAt(final int channel, final Location plateLocation, final Location wellLocation); /** - * Adds a new node at given coordinates and returns it. + * Adds a new node at given coordinates. * - * @return the new <code>INode</code> just added. Never returns <code>null</code>. - * @param originalFileName name of the <code>original</code> directory file that is going to be added in the + * @return the new <code>INode</code> just added (encapsulated in returned <code>NodePath</code>) with its path + * in the <code>standard</code> directory. Never returns <code>null</code>. + * @param originalFilePath name of the <code>original</code> directory file path that is going to be added in the * <code>standard</code> directory. */ - public INode addStandardNode(final String originalFileName, final int channel, final Location plateLocation, + public NodePath addStandardNode(final String originalFilePath, final int channel, final Location plateLocation, final Location wellLocation) throws DataStructureException; + + // + // Helper classes + // + + public final static class NodePath + { + public final INode node; + + public final String path; + + public NodePath(final INode node, final String path) + { + assert node != null : "Given node could not be null."; + assert path != null : "Given path could not be null."; + this.node = node; + this.path = path; + } + } } diff --git a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/HCSDataStructureV1_0Test.java b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/HCSDataStructureV1_0Test.java index bbbd9474cfbefcd40530bef074f4b0d04a0a9cdf..8241204d9381b8b76e89fc9691fff6d1b8db0e1e 100644 --- a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/HCSDataStructureV1_0Test.java +++ b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/HCSDataStructureV1_0Test.java @@ -101,11 +101,11 @@ public final class HCSDataStructureV1_0Test extends AbstractFileSystemTestCase } setFormatAndFormatParameters(); final IFormattedData formattedData = dataStructure.getFormattedData(); - assertTrue(formattedData instanceof IHCSFormattedData); + assertTrue(formattedData instanceof IHCSImageFormattedData); assertEquals(format, formattedData.getFormat()); } - @Test(dependsOnMethods="testGetFormattedData") + @Test(dependsOnMethods = "testGetFormattedData") public final void testHCSImageDataStructure() { // Creating... diff --git a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/HCSImageFormattedDataTest.java b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/HCSImageFormattedDataTest.java index 6a1f4b80bbbfa09cc0655f3d945d63a599c0a39a..6ecb02788eb453a7f995b7f304a78f6e253d5b67 100644 --- a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/HCSImageFormattedDataTest.java +++ b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/HCSImageFormattedDataTest.java @@ -35,8 +35,10 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import ch.systemsx.cisd.bds.DataStructureV1_0; +import ch.systemsx.cisd.bds.Format; import ch.systemsx.cisd.bds.FormattedDataFactory; import ch.systemsx.cisd.bds.IFormatParameters; +import ch.systemsx.cisd.bds.hcs.IHCSImageFormattedData.NodePath; import ch.systemsx.cisd.bds.storage.IDirectory; import ch.systemsx.cisd.bds.storage.IFile; import ch.systemsx.cisd.bds.storage.ILink; @@ -72,10 +74,11 @@ public class HCSImageFormattedDataTest extends AbstractFileSystemTestCase { directory = context.mock(IDirectory.class); formatParameters = context.mock(IFormatParameters.class); + final Format format = HCSImageFormat1_0.HCS_IMAGE_1_0; context.checking(new Expectations() { { - for (final String formatParameterName : HCSImageFormattedData.MANDATORY_FORMAT_PARAMETERS) + for (final String formatParameterName : format.getParameterNames()) { one(formatParameters).containsParameter(formatParameterName); will(returnValue(true)); @@ -83,8 +86,8 @@ public class HCSImageFormattedDataTest extends AbstractFileSystemTestCase } }); formattedData = - (HCSImageFormattedData) FormattedDataFactory.createFormattedData(directory, - HCSImageFormat1_0.HCS_IMAGE_1_0, null, formatParameters); + (HCSImageFormattedData) FormattedDataFactory.createFormattedData(directory, format, null, + formatParameters); } private final void prepareStandardNode() @@ -166,8 +169,8 @@ public class HCSImageFormattedDataTest extends AbstractFileSystemTestCase @Test public final void testAddStandardNodeWithOriginalData() throws IOException { - final String originalFileName = "original.txt"; - FileUtils.writeStringToFile(new File(workingDirectory, originalFileName), "This is my original file..."); + final String originalFilePath = "original.txt"; + FileUtils.writeStringToFile(new File(workingDirectory, originalFilePath), "This is my original file..."); final int channelIndex = 1; final IDirectory originalNode = NodeFactory.createDirectoryNode(workingDirectory); context.checking(new Expectations() @@ -185,25 +188,26 @@ public class HCSImageFormattedDataTest extends AbstractFileSystemTestCase will(returnValue(Boolean.FALSE)); } }); - final INode node = formattedData.addStandardNode(originalFileName, channelIndex, PLATE_LOCATION, WELL_LOCATION); + final NodePath nodePath = + formattedData.addStandardNode(originalFilePath, channelIndex, PLATE_LOCATION, WELL_LOCATION); final String standardFileName = "row2_column1.tiff"; - assertNotNull(node); - assertEquals(standardFileName, node.getName()); + assertNotNull(nodePath); + assertEquals(standardFileName, nodePath.node.getName()); // Look at the standard leaf directory if the node is there as well. final INode standardFile = leafDirectory.tryGetNode(standardFileName); assertNotNull(standardFile); assertTrue(standardFile instanceof IFile); assertEquals(standardFileName, standardFile.getName()); // Node should no longer be in original directory - assertNull(originalNode.tryGetNode(originalFileName)); + assertNull(originalNode.tryGetNode(originalFilePath)); context.assertIsSatisfied(); } @Test public final void testAddStandardNodeWithoutOriginalData() throws IOException { - final String originalFileName = "original.tiff"; - FileUtils.writeStringToFile(new File(workingDirectory, originalFileName), "This is my original file..."); + final String originalFilePath = "original.tiff"; + FileUtils.writeStringToFile(new File(workingDirectory, originalFilePath), "This is my original file..."); final int channelIndex = 1; final IDirectory originalNode = NodeFactory.createDirectoryNode(workingDirectory); context.checking(new Expectations() @@ -221,18 +225,19 @@ public class HCSImageFormattedDataTest extends AbstractFileSystemTestCase will(returnValue(Boolean.TRUE)); } }); - final INode node = formattedData.addStandardNode(originalFileName, channelIndex, PLATE_LOCATION, WELL_LOCATION); + final NodePath nodePath = + formattedData.addStandardNode(originalFilePath, channelIndex, PLATE_LOCATION, WELL_LOCATION); final String standardFileName = "row2_column1.tiff"; - assertNotNull(node); - assertTrue(node instanceof ILink); - assertEquals(standardFileName, node.getName()); + assertNotNull(nodePath); + assertTrue(nodePath.node instanceof ILink); + assertEquals(standardFileName, nodePath.node.getName()); // Look at the standard leaf directory if the node is there as well. final INode standardFile = leafDirectory.tryGetNode(standardFileName); assertNotNull(standardFile); assertTrue(standardFile instanceof IFile); assertEquals(standardFileName, standardFile.getName()); // Node should still be in original directory - assertNotNull(originalNode.tryGetNode(originalFileName)); + assertNotNull(originalNode.tryGetNode(originalFilePath)); context.assertIsSatisfied(); }