diff --git a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/FlowLaneDataSetInfoExtractor.java b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/FlowLaneDataSetInfoExtractor.java new file mode 100644 index 0000000000000000000000000000000000000000..95a32df99b5e328970d1620c69d9245c732c103f --- /dev/null +++ b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/FlowLaneDataSetInfoExtractor.java @@ -0,0 +1,59 @@ +/* + * 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.ethz.bsse.cisd.dsu.dss; + +import java.io.File; +import java.util.Properties; + +import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; +import ch.systemsx.cisd.common.exceptions.UserFailureException; +import ch.systemsx.cisd.etlserver.DefaultDataSetInfoExtractor; +import ch.systemsx.cisd.etlserver.IDataSetInfoExtractor; +import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; +import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; + +/** + * @author Franz-Josef Elmer + */ +public class FlowLaneDataSetInfoExtractor implements IDataSetInfoExtractor +{ + static final String FLOW_LANE_NUMBER_SEPARATOR = "."; + + private final IDataSetInfoExtractor dataSetInfoExtractor; + + public FlowLaneDataSetInfoExtractor(Properties properties) + { + dataSetInfoExtractor = new DefaultDataSetInfoExtractor(properties); + } + + public DataSetInformation getDataSetInformation(File incomingDataSetPath, + IEncapsulatedOpenBISService openbisService) throws UserFailureException, + EnvironmentFailureException + { + DataSetInformation dataSetInformation = + dataSetInfoExtractor.getDataSetInformation(incomingDataSetPath, openbisService); + String sampleCode = dataSetInformation.getSampleCode(); + if (sampleCode != null) + { + dataSetInformation.setSampleCode(sampleCode.replace(FLOW_LANE_NUMBER_SEPARATOR, + SampleIdentifier.CONTAINED_SAMPLE_CODE_SEPARARTOR_STRING)); + } + return dataSetInformation; + } + +} diff --git a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/FlowLaneFeeder.java b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/FlowLaneFeeder.java index e7afa3d671a78128ab596f1c3989a65116b259e9..61a4bbf3898696d7e23ba1164d8469bfbff45f68 100644 --- a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/FlowLaneFeeder.java +++ b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/FlowLaneFeeder.java @@ -160,7 +160,7 @@ class FlowLaneFeeder extends AbstractPostRegistrationDataSetHandlerForFileBasedU File dropBox = createDropBoxFile(flowLane); String fileName = flowLaneSample.getGroup().getCode() + entitySepaparator + flowcellID - + SampleIdentifier.CONTAINED_SAMPLE_CODE_SEPARARTOR_STRING + flowLane; + + FlowLaneDataSetInfoExtractor.FLOW_LANE_NUMBER_SEPARATOR + flowLane; File flowLaneDataSet = new File(dropBox, fileName); if (flowLaneDataSet.exists()) { @@ -274,8 +274,10 @@ class FlowLaneFeeder extends AbstractPostRegistrationDataSetHandlerForFileBasedU builder.append(line).append('\n'); } } - String metaFileName = flowLaneSample.getCode() + META_DATA_FILE_TYPE; - metaFileName = asFileName(metaFileName); + String sampleCode = flowLaneSample.getCode(); + String metaFileName = + escapeSampleCode(sampleCode) + + META_DATA_FILE_TYPE; FileUtilities.writeToFile(new File(flowLaneDataSet, metaFileName), builder.toString()); if (dropBox != null) { @@ -289,15 +291,10 @@ class FlowLaneFeeder extends AbstractPostRegistrationDataSetHandlerForFileBasedU } } - // TODO : more generic solution for avoiding escape chars in file names, this is just quick and - // dirty - static String asFileName(String originalFileName) + static String escapeSampleCode(String sampleCode) { - String fileName = originalFileName; - fileName = fileName.replace("/", "_"); - fileName = fileName.replace(":", "_"); - fileName = fileName.replace("\\", "_"); - return fileName; + return sampleCode == null ? null : sampleCode.replace( + SampleIdentifier.CONTAINED_SAMPLE_CODE_SEPARARTOR_STRING, "_"); } private void addLine(StringBuilder builder, String key, String value) diff --git a/deep_sequencing_unit/sourceTest/java/ch/ethz/bsse/cisd/dsu/dss/FlowLaneFeederTest.java b/deep_sequencing_unit/sourceTest/java/ch/ethz/bsse/cisd/dsu/dss/FlowLaneFeederTest.java index 6285c73fa5a1a62317fc17d1f6ede322d5e16852..8671932699fd95b9793f758345fd07575ece88a5 100644 --- a/deep_sequencing_unit/sourceTest/java/ch/ethz/bsse/cisd/dsu/dss/FlowLaneFeederTest.java +++ b/deep_sequencing_unit/sourceTest/java/ch/ethz/bsse/cisd/dsu/dss/FlowLaneFeederTest.java @@ -16,7 +16,7 @@ package ch.ethz.bsse.cisd.dsu.dss; -import static ch.ethz.bsse.cisd.dsu.dss.FlowLaneFeeder.asFileName; +import static ch.ethz.bsse.cisd.dsu.dss.FlowLaneDataSetInfoExtractor.FLOW_LANE_NUMBER_SEPARATOR; import java.io.File; import java.io.FilenameFilter; @@ -263,10 +263,10 @@ public class FlowLaneFeederTest extends AbstractFileSystemTestCase File[] transferedFiles = transferDropBox.listFiles(); assertEquals(1, transferedFiles.length); - String sampleName = SAMPLE_CODE + ":2"; - assertEquals("G2_" + sampleName, transferedFiles[0].getName()); + String sampleName = SAMPLE_CODE + FLOW_LANE_NUMBER_SEPARATOR + "2"; + assertEquals("G2_" + FlowLaneFeeder.escapeSampleCode(sampleName), transferedFiles[0].getName()); File metaFile = getFile(transferedFiles[0], FlowLaneFeeder.META_DATA_FILE_TYPE); - String myFileName = asFileName(sampleName + FlowLaneFeeder.META_DATA_FILE_TYPE); + String myFileName = SAMPLE_CODE + "_2" + FlowLaneFeeder.META_DATA_FILE_TYPE; assertEquals(myFileName, metaFile.getName()); assertHardLinkOnSameFile(originalFlowLane2, getFile(transferedFiles[0], "2.srf")); @@ -303,10 +303,10 @@ public class FlowLaneFeederTest extends AbstractFileSystemTestCase File[] transferedFiles = transferDropBox.listFiles(); assertEquals(1, transferedFiles.length); - String sampleName = SAMPLE_CODE + ":2"; + String sampleName = SAMPLE_CODE + FLOW_LANE_NUMBER_SEPARATOR + "2"; assertEquals("G2_" + sampleName, transferedFiles[0].getName()); File metaFile = getFile(transferedFiles[0], FlowLaneFeeder.META_DATA_FILE_TYPE); - assertEquals(asFileName(sampleName + FlowLaneFeeder.META_DATA_FILE_TYPE), metaFile + assertEquals(SAMPLE_CODE + "_2" + FlowLaneFeeder.META_DATA_FILE_TYPE, metaFile .getName()); List<String> metaData = FileUtilities.loadToStringList(metaFile); String lastLine = metaData.remove(metaData.size() - 1); @@ -352,7 +352,7 @@ public class FlowLaneFeederTest extends AbstractFileSystemTestCase { public boolean accept(File dir, String name) { - return name.endsWith(fileNameExtension); + return FlowLaneFeeder.escapeSampleCode(name).endsWith(FlowLaneFeeder.escapeSampleCode(fileNameExtension)); } }); assertEquals(1, files.length); @@ -443,10 +443,10 @@ public class FlowLaneFeederTest extends AbstractFileSystemTestCase private GenericValueEntityProperty createProperty(String key, String value) { GenericValueEntityProperty p = new GenericValueEntityProperty(); - p.setValue(value); + p.setValue(FlowLaneFeeder.escapeSampleCode(value)); PropertyType propertyType = new PropertyType(); - propertyType.setCode(key); - propertyType.setLabel(key.toLowerCase()); + propertyType.setCode(FlowLaneFeeder.escapeSampleCode(key)); + propertyType.setLabel(FlowLaneFeeder.escapeSampleCode(key).toLowerCase()); p.setPropertyType(propertyType); return p; } @@ -455,11 +455,11 @@ public class FlowLaneFeederTest extends AbstractFileSystemTestCase private void checkFlowLaneDataSet(File originalFlowLane, String flowLaneNumber) { - File dropBox = new File(workingDirectory, DROP_BOX_PREFIX + flowLaneNumber); - String flowLaneSampleCode = SAMPLE_CODE + ":" + flowLaneNumber; + File dropBox = new File(workingDirectory, DROP_BOX_PREFIX + FlowLaneFeeder.escapeSampleCode(flowLaneNumber)); String fileName = - "G" + flowLaneNumber + FlowLaneFeeder.DEFAULT_ENTITY_SEPARATOR + flowLaneSampleCode; - File ds = new File(dropBox, fileName); + "G" + FlowLaneFeeder.escapeSampleCode(flowLaneNumber) + FlowLaneFeeder.DEFAULT_ENTITY_SEPARATOR + SAMPLE_CODE + + FLOW_LANE_NUMBER_SEPARATOR + FlowLaneFeeder.escapeSampleCode(flowLaneNumber); + File ds = new File(dropBox, FlowLaneFeeder.escapeSampleCode(fileName)); assertEquals(true, ds.isDirectory()); File flowLane = new File(ds, originalFlowLane.getName()); @@ -467,10 +467,10 @@ public class FlowLaneFeederTest extends AbstractFileSystemTestCase assertEquals(FileUtilities.loadToString(originalFlowLane), FileUtilities .loadToString(flowLane)); assertHardLinkOnSameFile(originalFlowLane, flowLane); - String metaDataFileName = flowLaneSampleCode + FlowLaneFeeder.META_DATA_FILE_TYPE; - metaDataFileName = asFileName(metaDataFileName); - assertEquals(true, new File(ds, metaDataFileName).exists()); - assertEquals(true, new File(dropBox, Constants.IS_FINISHED_PREFIX + fileName).exists()); + String metaDataFileName = + (SAMPLE_CODE + "_" + FlowLaneFeeder.escapeSampleCode(flowLaneNumber)) + FlowLaneFeeder.META_DATA_FILE_TYPE; + assertEquals(true, new File(ds, FlowLaneFeeder.escapeSampleCode(metaDataFileName)).exists()); + assertEquals(true, new File(dropBox, Constants.IS_FINISHED_PREFIX + FlowLaneFeeder.escapeSampleCode(fileName)).exists()); } private void assertHardLinkOnSameFile(File file1, File file2)