From c1600b8517c88a920b650a4845e820c03b1ba48a Mon Sep 17 00:00:00 2001 From: kohleman <kohleman> Date: Tue, 14 Dec 2010 10:52:13 +0000 Subject: [PATCH] adopted the Sample Library Strategy/Selection SVN: 19121 --- .../cisd/dsu/dss/plugins/DataSetToSOFT.java | 112 +++++++++++------- .../dsu/dss/plugins/DataSetToSOFTTest.java | 78 ++++++------ 2 files changed, 110 insertions(+), 80 deletions(-) diff --git a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/DataSetToSOFT.java b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/DataSetToSOFT.java index 4071b8c4239..f080ae98f77 100644 --- a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/DataSetToSOFT.java +++ b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/DataSetToSOFT.java @@ -54,12 +54,13 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFa /** * Processing plugin for exporting meta data of a flow lane as a SOFT file. - * + * * @author Franz-Josef Elmer */ public class DataSetToSOFT implements IProcessingPluginTask { - @Private static final String EXTERNAL_SAMPLE_NAME_PROPERTY = "EXTERNAL_SAMPLE_NAME"; + @Private + static final String EXTERNAL_SAMPLE_NAME_PROPERTY = "EXTERNAL_SAMPLE_NAME"; private static final String EMPTY = "<<<NEED_TO_BE_FILLED>>>"; @@ -79,34 +80,35 @@ public class DataSetToSOFT implements IProcessingPluginTask private static final class SOFTBuilder { private final StringBuilder builder = new StringBuilder(); - + void addSample(Sample sample, String propertyTypeCode) { addLine('^', "SAMPLE", getProperty(sample, propertyTypeCode)); } - - void addSampleProperty(String key, Sample sample, String propertyTypeCode, Map<String, String> translation) + + void addSampleProperty(String key, Sample sample, String propertyTypeCode, + Map<String, String> translation) { String property = getProperty(sample, propertyTypeCode); String translatedProperty = translation.get(property); addProperty(key, translatedProperty == null ? property : translatedProperty); } - + void addSampleProperty(String key, Sample sample, String propertyTypeCode) { addProperty(key, getProperty(sample, propertyTypeCode)); } - + void addProperty(String key, String property) { addLine('!', "Sample_" + key, property); } - + private void addLine(char prefix, String key, String value) { builder.append(prefix).append(key).append(" = ").append(value).append('\n'); } - + private String getProperty(Sample sample, String propertyTypeCode) { String property = tryToGetProperty(sample, propertyTypeCode); @@ -119,7 +121,7 @@ public class DataSetToSOFT implements IProcessingPluginTask return builder.toString(); } } - + private static final String tryToGetProperty(Sample sample, String propertyTypeCode) { List<IEntityProperty> properties = sample.getProperties(); @@ -132,12 +134,12 @@ public class DataSetToSOFT implements IProcessingPluginTask } return null; } - - private static final Logger operationLog = - LogFactory.getLogger(LogCategory.OPERATION, DataSetToSOFT.class); + + private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, + DataSetToSOFT.class); private static final long serialVersionUID = 1L; - + private final File storeRoot; private final Map<String, String> translation; @@ -148,7 +150,7 @@ public class DataSetToSOFT implements IProcessingPluginTask { this(properties, storeRoot, null); } - + DataSetToSOFT(Properties properties, File storeRoot, IEncapsulatedOpenBISService service) { this.storeRoot = storeRoot; @@ -166,7 +168,7 @@ public class DataSetToSOFT implements IProcessingPluginTask translation.put("MRNA", "other"); translation.put("PROCESSED_DNA_LIBRARY", EMPTY); } - + public ProcessingStatus process(List<DatasetDescription> datasets, DataSetProcessingContext context) { @@ -193,26 +195,37 @@ public class DataSetToSOFT implements IProcessingPluginTask continue; } String checkSum = calculateCheckSum(srfFile); - + SOFTBuilder softBuilder = new SOFTBuilder(); softBuilder.addSample(sequencingSample, EXTERNAL_SAMPLE_NAME_PROPERTY); softBuilder.addProperty("type", "SRA"); - softBuilder.addSampleProperty("title", sequencingSample, EXTERNAL_SAMPLE_NAME_PROPERTY); - softBuilder.addSampleProperty("source_name", sequencingSample, "SAMPLE_SOURCE_NAME"); - softBuilder.addSampleProperty("organism", sequencingSample, "NCBI_ORGANISM_TAXONOMY"); - softBuilder.addSampleProperty("characteristics", sequencingSample, "SAMPLE_CHARACTERISTICS"); - softBuilder.addSampleProperty("biomaterial_provider", sequencingSample, "CONTACT_PERSON_NAME"); - softBuilder.addSampleProperty("molecule", sequencingSample, "SEQUENCING_APPLICATION"); - softBuilder.addSampleProperty("extract_protocol", sequencingSample, "SAMPLE_EXTRACT_PROTOCOL"); - softBuilder.addSampleProperty("data_processing", sequencingSample, "SAMPLE_DATA_PROCESSING"); - softBuilder.addSampleProperty("library_strategy", sequencingSample, "SEQUENCING_APPLICATION"); - softBuilder.addSampleProperty("library_source", sequencingSample, "SAMPLE_KIND", translation); - softBuilder.addSampleProperty("library_selection", sequencingSample, "SAMPLE_KIND"); - softBuilder.addSampleProperty("instrument_model", flowCellSample, "GENOME_ANALYZER"); + softBuilder.addSampleProperty("title", sequencingSample, + EXTERNAL_SAMPLE_NAME_PROPERTY); + softBuilder + .addSampleProperty("source_name", sequencingSample, "SAMPLE_SOURCE_NAME"); + softBuilder.addSampleProperty("organism", sequencingSample, + "NCBI_ORGANISM_TAXONOMY"); + softBuilder.addSampleProperty("characteristics", sequencingSample, + "SAMPLE_CHARACTERISTICS"); + softBuilder.addSampleProperty("biomaterial_provider", sequencingSample, + "CONTACT_PERSON_NAME"); + softBuilder.addSampleProperty("molecule", sequencingSample, "SAMPLE_MOLECULE"); + softBuilder.addSampleProperty("extract_protocol", sequencingSample, + "SAMPLE_EXTRACT_PROTOCOL"); + softBuilder.addSampleProperty("data_processing", sequencingSample, + "SAMPLE_DATA_PROCESSING"); + softBuilder.addSampleProperty("library_strategy", sequencingSample, + "SAMPLE_LIBRARY_STRATEGY"); + softBuilder.addSampleProperty("library_source", sequencingSample, "SAMPLE_KIND", + translation); + softBuilder.addSampleProperty("library_selection", sequencingSample, + "SAMPLE_LIBRARY_SELECTION"); + softBuilder + .addSampleProperty("instrument_model", flowCellSample, "GENOME_ANALYZER"); softBuilder.addProperty("raw_file_1", srfFile.getName()); softBuilder.addProperty("raw_file_type_1", "srf"); softBuilder.addProperty("file_checksum_1", checkSum); - + String subject = createSubject(sequencingSample); String content = createContent(sequencingSample, flowLaneSample, srfDataSet); String fileName = createSoftFileName(sequencingSample, flowLaneSample); @@ -222,13 +235,14 @@ public class DataSetToSOFT implements IProcessingPluginTask status.addDatasetStatus(datasetDescription, Status.OK); } catch (Exception ex) { - status.addDatasetStatus(datasetDescription, Status.createError("Exception occured: " + ex)); + status.addDatasetStatus(datasetDescription, + Status.createError("Exception occured: " + ex)); operationLog.error("Exception occured while processing " + datasetDescription, ex); } } return status; } - + private String createSubject(Sample sequencingSample) { Template template = E_MAIL_SUBJECT_TEMPLATE.createFreshCopy(); @@ -236,7 +250,8 @@ public class DataSetToSOFT implements IProcessingPluginTask return template.createText(); } - private String createContent(Sample sequencingSample, Sample flowLaneSample, ExternalData dataSet) + private String createContent(Sample sequencingSample, Sample flowLaneSample, + ExternalData dataSet) { Template template = E_MAIL_CONTENT_TEMPLATE.createFreshCopy(); bindExternalSampleName(template, sequencingSample); @@ -244,22 +259,24 @@ public class DataSetToSOFT implements IProcessingPluginTask template.bind("data-set", dataSet.getCode()); return template.createText(); } - + private String createSoftFileName(Sample sequencingSample, Sample flowLaneSample) { Template template = SOFT_FILE_NAME_TEMPLATE.createFreshCopy(); - String externalSampleName = tryToGetProperty(sequencingSample, EXTERNAL_SAMPLE_NAME_PROPERTY); + String externalSampleName = + tryToGetProperty(sequencingSample, EXTERNAL_SAMPLE_NAME_PROPERTY); template.bind("external-sample-name", externalSampleName.replace(' ', '_')); template.bind("flow-lane", flowLaneSample.getCode().replace(':', '-')); return template.createText(); } - + private void bindExternalSampleName(Template template, Sample sequencingSample) { - String externalSampleName = tryToGetProperty(sequencingSample, EXTERNAL_SAMPLE_NAME_PROPERTY); + String externalSampleName = + tryToGetProperty(sequencingSample, EXTERNAL_SAMPLE_NAME_PROPERTY); template.bind("external-sample-name", externalSampleName); } - + private String calculateCheckSum(File srfFile) { String checkSum; @@ -272,13 +289,13 @@ public class DataSetToSOFT implements IProcessingPluginTask } return checkSum; } - + private File tryToFindSrfFile(DatasetDescription datasetDescription) { File root = new File(storeRoot, datasetDescription.getDataSetLocation()); return tryToFindSrfFile(root); } - + private File tryToFindSrfFile(File file) { if (file.isFile() && file.getName().endsWith(".srf")) @@ -299,22 +316,25 @@ public class DataSetToSOFT implements IProcessingPluginTask } return null; } - + private Sample getFlowLaneSample(ExternalData dataSet) { SampleIdentifier identifier = SampleIdentifierFactory.parse(dataSet.getSampleIdentifier()); return getService().tryGetSampleWithExperiment(identifier); } - + private Sample getFlowCellSample(Sample flowLaneSample) { - SampleIdentifier identifier = SampleIdentifierFactory.parse(flowLaneSample.getContainer().getIdentifier()); + SampleIdentifier identifier = + SampleIdentifierFactory.parse(flowLaneSample.getContainer().getIdentifier()); return getService().tryGetSampleWithExperiment(identifier); } - + private Sample getSequencingSample(Sample flowLaneSample) { - List<Sample> parents = getService().listSamples(ListSampleCriteria.createForChild(new TechId(flowLaneSample.getId()))); + List<Sample> parents = + getService().listSamples( + ListSampleCriteria.createForChild(new TechId(flowLaneSample.getId()))); return parents.get(0); } @@ -328,7 +348,7 @@ public class DataSetToSOFT implements IProcessingPluginTask throw CheckedExceptionTunnel.wrapIfNecessary(ex); } } - + private IEncapsulatedOpenBISService getService() { if (service == null) diff --git a/deep_sequencing_unit/sourceTest/java/ch/ethz/bsse/cisd/dsu/dss/plugins/DataSetToSOFTTest.java b/deep_sequencing_unit/sourceTest/java/ch/ethz/bsse/cisd/dsu/dss/plugins/DataSetToSOFTTest.java index 0233f85afb1..7092a28b1aa 100644 --- a/deep_sequencing_unit/sourceTest/java/ch/ethz/bsse/cisd/dsu/dss/plugins/DataSetToSOFTTest.java +++ b/deep_sequencing_unit/sourceTest/java/ch/ethz/bsse/cisd/dsu/dss/plugins/DataSetToSOFTTest.java @@ -58,24 +58,31 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.DatasetDescription; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory; /** - * - * * @author Franz-Josef Elmer */ -@Friend(toClasses=DataSetToSOFT.class) +@Friend(toClasses = DataSetToSOFT.class) public class DataSetToSOFTTest extends AbstractFileSystemTestCase { private static final String USER_EMAIL = "user@ho.me"; + private static final String SRF_FILE_NAME = "sample.srf"; + private static final String SRF_FILE_CONTENT = "hello world!"; + private static final String DATASET_CODE = "ds-1"; + private static final String FLOW_LANE_SAMPLE_CODE = "flow-lane:1"; - + private BufferedAppender logRecorder; + private Mockery context; + private IEncapsulatedOpenBISService service; + private IMailClient mailClient; + private DataSetProcessingContext dataSetProcessingContext; + private IProcessingPluginTask processingPlugin; @BeforeMethod @@ -120,65 +127,68 @@ public class DataSetToSOFTTest extends AbstractFileSystemTestCase addProperty(sequencingSample, "SAMPLE_SOURCE_NAME", "source"); addProperty(sequencingSample, "NCBI_ORGANISM_TAXONOMY", "organism"); addProperty(sequencingSample, "CONTACT_PERSON_NAME", "person"); + addProperty(sequencingSample, "SAMPLE_MOLECULE", "total_rna"); addProperty(sequencingSample, "SEQUENCING_APPLICATION", "application"); addProperty(sequencingSample, "SAMPLE_EXTRACT_PROTOCOL", "protocol"); addProperty(sequencingSample, "SAMPLE_DATA_PROCESSING", "processing"); + addProperty(sequencingSample, "SAMPLE_LIBRARY_SELECTION", "cDNA"); + addProperty(sequencingSample, "SAMPLE_LIBRARY_STRATEGY", "RNA-Seq"); addProperty(sequencingSample, "SAMPLE_KIND", "CHIP"); flowLaneSample.setContainer(flowCellSample); prepareGetSample(flowLaneSample); prepareGetSample(flowCellSample); - final RecordingMatcher<ListSampleCriteria> listSampleCriteriaMatcher = new RecordingMatcher<ListSampleCriteria>(); + final RecordingMatcher<ListSampleCriteria> listSampleCriteriaMatcher = + new RecordingMatcher<ListSampleCriteria>(); final RecordingMatcher<String> subjectMatcher = new RecordingMatcher<String>(); final RecordingMatcher<String> contentMatcher = new RecordingMatcher<String>(); final RecordingMatcher<String> fileNameMatcher = new RecordingMatcher<String>(); final RecordingMatcher<DataHandler> attachmentMatcher = new RecordingMatcher<DataHandler>(); - final RecordingMatcher<EMailAddress[]> addressesMatcher = new RecordingMatcher<EMailAddress[]>(); + final RecordingMatcher<EMailAddress[]> addressesMatcher = + new RecordingMatcher<EMailAddress[]>(); context.checking(new Expectations() { { one(service).listSamples(with(listSampleCriteriaMatcher)); will(returnValue(Arrays.asList(sequencingSample))); - + one(mailClient).sendEmailMessageWithAttachment(with(subjectMatcher), with(contentMatcher), with(fileNameMatcher), with(attachmentMatcher), with(new IsNull<EMailAddress>()), with(new IsNull<EMailAddress>()), with(addressesMatcher)); } }); - + ProcessingStatus status = processingPlugin.process(dataSets, dataSetProcessingContext); assertEquals(0, status.getErrorStatuses().size()); - assertEquals(flowLaneSample.getId(), listSampleCriteriaMatcher.getRecordedObjects().get(0).getChildSampleId().getId()); + assertEquals(flowLaneSample.getId(), listSampleCriteriaMatcher.getRecordedObjects().get(0) + .getChildSampleId().getId()); Template template = initTemplate(DataSetToSOFT.E_MAIL_SUBJECT_TEMPLATE); - assertEquals("[" + template.createText() + "]", subjectMatcher.getRecordedObjects().toString()); + assertEquals("[" + template.createText() + "]", subjectMatcher.getRecordedObjects() + .toString()); Template content = initTemplate(DataSetToSOFT.E_MAIL_CONTENT_TEMPLATE); content.bind("flow-lane", flowLaneSample.getCode()); content.bind("data-set", DATASET_CODE); - assertEquals("[" + content.createText() + "]", contentMatcher.getRecordedObjects().toString()); + assertEquals("[" + content.createText() + "]", contentMatcher.getRecordedObjects() + .toString()); Template fileNameTemplate = DataSetToSOFT.SOFT_FILE_NAME_TEMPLATE.createFreshCopy(); fileNameTemplate.bind("external-sample-name", "my_sample"); fileNameTemplate.bind("flow-lane", flowLaneSample.getCode().replace(':', '-')); - assertEquals("[" + fileNameTemplate.createText() + "]", fileNameMatcher.getRecordedObjects().toString()); + assertEquals("[" + fileNameTemplate.createText() + "]", fileNameMatcher + .getRecordedObjects().toString()); List<EMailAddress[]> emailAddresses = addressesMatcher.getRecordedObjects(); assertEquals(USER_EMAIL, emailAddresses.get(0)[0].tryGetEmailAddress()); DataSource dataSource = attachmentMatcher.getRecordedObjects().get(0).getDataSource(); String attachmentContent = getContent(dataSource); - assertEquals("^SAMPLE = my sample\n" - + "!Sample_type = SRA\n" - + "!Sample_title = my sample\n" - + "!Sample_source_name = source\n" + assertEquals("^SAMPLE = my sample\n" + "!Sample_type = SRA\n" + + "!Sample_title = my sample\n" + "!Sample_source_name = source\n" + "!Sample_organism = organism\n" + "!Sample_characteristics = <<<NEED_TO_BE_FILLED>>>\n" - + "!Sample_biomaterial_provider = person\n" - + "!Sample_molecule = application\n" + + "!Sample_biomaterial_provider = person\n" + "!Sample_molecule = total_rna\n" + "!Sample_extract_protocol = protocol\n" - + "!Sample_data_processing = processing\n" - + "!Sample_library_strategy = application\n" - + "!Sample_library_source = genomic\n" - + "!Sample_library_selection = CHIP\n" - + "!Sample_instrument_model = my-analyzer\n" - + "!Sample_raw_file_1 = sample.srf\n" + + "!Sample_data_processing = processing\n" + "!Sample_library_strategy = RNA-Seq\n" + + "!Sample_library_source = genomic\n" + "!Sample_library_selection = cDNA\n" + + "!Sample_instrument_model = my-analyzer\n" + "!Sample_raw_file_1 = sample.srf\n" + "!Sample_raw_file_type_1 = srf\n" + "!Sample_file_checksum_1 = fc3ff98e8c6a0d3087d515c0473f8677\n", attachmentContent); context.assertIsSatisfied(); @@ -202,7 +212,7 @@ public class DataSetToSOFTTest extends AbstractFileSystemTestCase template.bind("external-sample-name", "my sample"); return template; } - + private void prepareGetDataSet(final String dataSetCode, final Sample flowLaneSample) { context.checking(new Expectations() @@ -216,18 +226,19 @@ public class DataSetToSOFTTest extends AbstractFileSystemTestCase } }); } - + private void prepareGetSample(final Sample sample) { context.checking(new Expectations() - { { - one(service).tryGetSampleWithExperiment(SampleIdentifierFactory.parse(sample.getIdentifier())); - will(returnValue(sample)); - } - }); + { + one(service).tryGetSampleWithExperiment( + SampleIdentifierFactory.parse(sample.getIdentifier())); + will(returnValue(sample)); + } + }); } - + private void addProperty(Sample sample, String propertyTypeCode, String value) { List<IEntityProperty> properties = sample.getProperties(); @@ -243,7 +254,7 @@ public class DataSetToSOFTTest extends AbstractFileSystemTestCase property.setValue(value); properties.add(property); } - + private Sample sample(long id, String identifier) { Sample sample = new Sample(); @@ -252,4 +263,3 @@ public class DataSetToSOFTTest extends AbstractFileSystemTestCase return sample; } } - -- GitLab