diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/AbstractSampleHandler.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/AbstractSampleHandler.java index a6ec738733d517dd5151a5fb9d05a842de27aebe..fbc0955110fff79e2e6f5a37aec18bdecae0a093 100644 --- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/AbstractSampleHandler.java +++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/AbstractSampleHandler.java @@ -27,6 +27,7 @@ import ch.systemsx.cisd.openbis.etlserver.proteomics.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.dto.ListSamplesByPropertyCriteria; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SpaceIdentifier; import ch.systemsx.cisd.openbis.plugin.proteomics.shared.basic.CommonConstants; @@ -57,31 +58,49 @@ abstract class AbstractSampleHandler extends AbstractHandler private final Map<String, SampleOrError> samplesOrErrors = new HashMap<String, SampleOrError>(); + private final String delimiter; + + private final boolean restrictedSampleResolving; + AbstractSampleHandler(IEncapsulatedOpenBISService openbisService, IProtDAO dao, - ExperimentIdentifier experimentIdentifier, Experiment experiment) + ExperimentIdentifier experimentIdentifier, Experiment experiment, String delimiter, + boolean restrictedSampleResolving) { super(dao); this.openbisService = openbisService; this.experimentIdentifier = experimentIdentifier; this.experiment = experiment; + this.delimiter = delimiter; + this.restrictedSampleResolving = restrictedSampleResolving; String databaseInstanceCode = experimentIdentifier.getDatabaseInstanceCode(); space = new SpaceIdentifier(databaseInstanceCode, CommonConstants.MS_DATA_SPACE); } - protected SampleOrError getOrCreateSampleOrError(String sampleName) + protected SampleOrError getOrCreateSampleOrError(String sampleNameAndMore) { + int indexOfDelimiter = sampleNameAndMore.indexOf(delimiter); + String sampleName; + if (indexOfDelimiter < 0) + { + sampleName = sampleNameAndMore; + } else + { + sampleName = sampleNameAndMore.substring(0, indexOfDelimiter); + } SampleOrError sampleOrError = samplesOrErrors.get(sampleName); if (sampleOrError == null) { // first we look for a sample in space MS_DATA - SampleIdentifier sampleIdentifier = new SampleIdentifier(space, sampleName); + SampleIdentifier sampleIdentifier = + SampleIdentifierFactory.parse(sampleName, "/" + CommonConstants.MS_DATA_SPACE); + String sampleCode = sampleIdentifier.getSampleCode(); ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample = openbisService.tryGetSampleWithExperiment(sampleIdentifier); sampleOrError = new SampleOrError(); if (sample != null) { sampleOrError.sample = getOrCreateSample(sample.getPermId()); - } else + } else if (restrictedSampleResolving == false) { // second we look for a sample in same space as search experiment with // a property specified by 'sampleName' @@ -102,10 +121,13 @@ abstract class AbstractSampleHandler extends AbstractHandler sample = list.get(0); sampleOrError.sample = getOrCreateSample(sample.getPermId()); } + } else + { + sampleOrError.error = "Couldn't resolve sample: " + sampleIdentifier; } if (sample != null) { - handleSample(sampleName, sample); + handleSample(sampleCode, sample); } samplesOrErrors.put(sampleName, sampleOrError); } diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/AbundanceHandler.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/AbundanceHandler.java index 1a6789b2ffdcc363d38df1a9fc93ece2c8f4def9..392589c0ca2412b6a246e7831ec97a04540ddba9 100644 --- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/AbundanceHandler.java +++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/AbundanceHandler.java @@ -37,9 +37,11 @@ class AbundanceHandler extends AbstractSampleHandler private final SampleType sampleType; AbundanceHandler(IEncapsulatedOpenBISService openbisService, IProtDAO dao, - ExperimentIdentifier experimentIdentifier, Experiment experiment) + ExperimentIdentifier experimentIdentifier, Experiment experiment, String delimiter, + boolean restrictedSampleResolving) { - super(openbisService, dao, experimentIdentifier, experiment); + super(openbisService, dao, experimentIdentifier, experiment, delimiter, + restrictedSampleResolving); sampleType = new SampleType(); sampleType.setCode(Constants.SEARCH_SAMPLE_TYPE); } diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ModificationFractionHandler.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ModificationFractionHandler.java index 537565ff6afde633da0c950898f19ccd4fe74017..fdf2c118531586f1b799421453e64c7c86d8c7f2 100644 --- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ModificationFractionHandler.java +++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ModificationFractionHandler.java @@ -32,9 +32,11 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifi class ModificationFractionHandler extends AbstractSampleHandler { public ModificationFractionHandler(IEncapsulatedOpenBISService openbisService, IProtDAO dao, - ExperimentIdentifier experimentIdentifier, Experiment experiment) + ExperimentIdentifier experimentIdentifier, Experiment experiment, String delimiter, + boolean restrictedSampleResolving) { - super(openbisService, dao, experimentIdentifier, experiment); + super(openbisService, dao, experimentIdentifier, experiment, delimiter, + restrictedSampleResolving); } @Override diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ProtXMLUploader.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ProtXMLUploader.java index 6aaac2c90f209d18876ccfa50a055ea575e30f67..5d169ddbd01fae39056a2b5008807b5bcf150730 100644 --- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ProtXMLUploader.java +++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ProtXMLUploader.java @@ -44,6 +44,10 @@ public class ProtXMLUploader implements IDataSetUploader private static final String VALIDATING_XML = "validating-xml"; private static final String ASSUMING_EXTENDED_PROT_XML = "assuming-extended-prot-xml"; + + private static final String MS_INJECTION_SAMPLE_DELIMITER = "delimiter_for_sample_resolving"; + + private static final String RESTRICTED_SAMPLE_RESOLVING = "restricted_sample_resolving"; private static final String DATABASE_ENGINE = "database.engine"; @@ -80,6 +84,10 @@ public class ProtXMLUploader implements IDataSetUploader private final boolean assumingExtendedProtXML; + private final String msInjectionSampleDelimiter; + + private final boolean restrictedSampleResolving; + private ResultDataSetUploader currentResultDataSetUploader; public ProtXMLUploader(Properties properties, IEncapsulatedOpenBISService openbisService) @@ -87,6 +95,8 @@ public class ProtXMLUploader implements IDataSetUploader dataSource = createDataSource(properties); this.openbisService = openbisService; assumingExtendedProtXML = PropertyUtils.getBoolean(properties, ASSUMING_EXTENDED_PROT_XML, false); + msInjectionSampleDelimiter = properties.getProperty(MS_INJECTION_SAMPLE_DELIMITER, "~"); + restrictedSampleResolving = PropertyUtils.getBoolean(properties, RESTRICTED_SAMPLE_RESOLVING, true); loader = new ProtXMLLoader(PropertyUtils.getBoolean(properties, VALIDATING_XML, false)); } @@ -152,7 +162,8 @@ public class ProtXMLUploader implements IDataSetUploader { throw CheckedExceptionTunnel.wrapIfNecessary(ex); } - return new ResultDataSetUploader(connection, openbisService, assumingExtendedProtXML); + return new ResultDataSetUploader(connection, openbisService, assumingExtendedProtXML, + msInjectionSampleDelimiter, restrictedSampleResolving); } private File getProtXMLFile(File dataSet) diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ResultDataSetUploader.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ResultDataSetUploader.java index 78d2cd6eec011c71462f572c4485a2a5ec32aaec..c12c66e204b8629c182aed92c38626bfb4fd91a8 100644 --- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ResultDataSetUploader.java +++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ResultDataSetUploader.java @@ -75,18 +75,28 @@ class ResultDataSetUploader extends AbstractHandler private final boolean assumingExtendedProtXML; - ResultDataSetUploader(Connection connection, IEncapsulatedOpenBISService openbisService, boolean assumingExtendedProtXML) + private final String delimiter; + + private final boolean restrictedSampleResolving; + + ResultDataSetUploader(Connection connection, IEncapsulatedOpenBISService openbisService, + boolean assumingExtendedProtXML, String delimiter, + boolean restrictedSampleResolving) { - this(QueryTool.getQuery(connection, IProtDAO.class), connection, openbisService, assumingExtendedProtXML); + this(QueryTool.getQuery(connection, IProtDAO.class), connection, openbisService, + assumingExtendedProtXML, delimiter, restrictedSampleResolving); } ResultDataSetUploader(IProtDAO dao, Connection connection, - IEncapsulatedOpenBISService openbisService, boolean assumingExtendedProtXML) + IEncapsulatedOpenBISService openbisService, boolean assumingExtendedProtXML, + String delimiter, boolean restrictedSampleResolving) { super(dao); this.connection = connection; this.openbisService = openbisService; this.assumingExtendedProtXML = assumingExtendedProtXML; + this.delimiter = delimiter; + this.restrictedSampleResolving = restrictedSampleResolving; this.errorMessages = new StringBuffer(); } @@ -207,10 +217,11 @@ class ResultDataSetUploader extends AbstractHandler long dataSetID = dataSet.getId(); Long databaseID = dataSet.getDatabaseID(); AbundanceHandler abundanceHandler = - new AbundanceHandler(openbisService, dao, experimentIdentifier, experiment); + new AbundanceHandler(openbisService, dao, experimentIdentifier, experiment, + delimiter, restrictedSampleResolving); ModificationFractionHandler modificationFractionHandler = new ModificationFractionHandler(openbisService, dao, experimentIdentifier, - experiment); + experiment, delimiter, restrictedSampleResolving); ProbabilityToFDRCalculator calculator = createProbabilityToFDRMapping(dataSetID, summary); List<ProteinGroup> proteinGroups = summary.getProteinGroups(); for (ProteinGroup proteinGroup : proteinGroups) diff --git a/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/etlserver/proteomics/AbundanceHandlerTest.java b/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/etlserver/proteomics/AbundanceHandlerTest.java index 9930301d650ad4cba9c7da0d08ebcdb95f47db64..b9aa45dd89189b6646c2f49611b7530833c9c22d 100644 --- a/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/etlserver/proteomics/AbundanceHandlerTest.java +++ b/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/etlserver/proteomics/AbundanceHandlerTest.java @@ -31,8 +31,6 @@ import org.testng.annotations.Test; import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; -import ch.systemsx.cisd.openbis.etlserver.proteomics.AbundanceHandler; -import ch.systemsx.cisd.openbis.etlserver.proteomics.IProtDAO; import ch.systemsx.cisd.openbis.etlserver.proteomics.dto.Experiment; import ch.systemsx.cisd.openbis.etlserver.proteomics.dto.Parameter; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; @@ -42,6 +40,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifi import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ProjectIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SpaceIdentifier; import ch.systemsx.cisd.openbis.plugin.proteomics.shared.basic.CommonConstants; @@ -107,7 +106,7 @@ public class AbundanceHandlerTest extends AssertJUnit experiment = new Experiment(); experiment.setPermID(EXPERIMENT_PERM_ID); experiment.setId(EXPERIMENT_ID); - handler = new AbundanceHandler(service, dao, EXPERIMENT_IDENTIFIER, experiment); + handler = new AbundanceHandler(service, dao, EXPERIMENT_IDENTIFIER, experiment, "+", false); } @AfterMethod @@ -153,6 +152,27 @@ public class AbundanceHandlerTest extends AssertJUnit context.assertIsSatisfied(); } + + @Test + public void testAddTwoAbundanceValuesForASampleIdentifiedByCodeAndSpace() + { + String sampleIdentifier = "/" + SPACE_CODE + "/" + PARAMETER_NAME; + prepareCreateSampleIdentifiedByIdentifier(sampleIdentifier); + context.checking(new Expectations() + { + { + one(dao).createAbundance(PROTEIN_ID, SAMPLE_ID, ABUNDANCE); + one(dao).createAbundance(PROTEIN_ID, SAMPLE_ID, 1.5); + } + }); + + handler.addAbundancesToDatabase(createParameter(sampleIdentifier, PARAMETER_VALUE), + PROTEIN_ID, PROTEIN_NAME); + handler.addAbundancesToDatabase(createParameter(sampleIdentifier, "1.5"), PROTEIN_ID, + PROTEIN_NAME); + + context.assertIsSatisfied(); + } @Test public void testAddTwoAbundanceValuesForASampleIdentifiedByPropertyButNoSampleFound() @@ -248,25 +268,40 @@ public class AbundanceHandlerTest extends AssertJUnit } }); - handler.addAbundancesToDatabase(createParameter(PARAMETER_VALUE), PROTEIN_ID, PROTEIN_NAME); + handler.addAbundancesToDatabase( + createParameter(PARAMETER_NAME + "+blabla.xml", PARAMETER_VALUE), PROTEIN_ID, + PROTEIN_NAME); context.assertIsSatisfied(); } private Parameter createParameter(String value) + { + return createParameter(PARAMETER_NAME, value); + } + + Parameter createParameter(String parameterName, String value) { Parameter parameter = new Parameter(); - parameter.setName(PARAMETER_NAME); + parameter.setName(parameterName); parameter.setValue(value); return parameter; } private void prepareCreateSampleIdentifiedByCode() + { + prepareCreateSampleIdentifiedByIdentifier(PARAMETER_NAME); + } + + void prepareCreateSampleIdentifiedByIdentifier(final String sampleIdentifier) { Sample sample = new Sample(); sample.setPermId(SAMPLE_PERM_ID); - sample.setIdentifier(PARAMETER_NAME); - prepareGetSample(sample); + sample.setIdentifier(sampleIdentifier); + prepareGetSample( + SampleIdentifierFactory + .parse(sampleIdentifier, "/" + CommonConstants.MS_DATA_SPACE).toString(), + sample); prepareCreateSample(); context.checking(new Expectations() { @@ -283,7 +318,7 @@ public class AbundanceHandlerTest extends AssertJUnit + EXPERIMENT_CODE, newSample.getIdentifier()); assertEquals(EXPERIMENT_IDENTIFIER.toString(), newSample.getExperimentIdentifier()); - assertEquals(PARAMETER_NAME, newSample.getParentIdentifier()); + assertEquals(sampleIdentifier, newSample.getParentIdentifier()); return true; } return false; @@ -314,7 +349,7 @@ public class AbundanceHandlerTest extends AssertJUnit private void prepareCreateSampleIdentifiedByProperty(final List<Sample> samples) { - prepareGetSample(null); + prepareGetSample(SAMPLE_IDENTIFER.toString(), null); context.checking(new Expectations() { { @@ -337,7 +372,7 @@ public class AbundanceHandlerTest extends AssertJUnit }); } - private void prepareGetSample(final Sample sample) + private void prepareGetSample(final String expectedSampleIdentifier, final Sample sample) { context.checking(new Expectations() { @@ -348,12 +383,12 @@ public class AbundanceHandlerTest extends AssertJUnit public boolean matches(Object item) { - return SAMPLE_IDENTIFER.toString().equals(item.toString()); + return expectedSampleIdentifier.equals(item.toString()); } public void describeTo(Description description) { - description.appendValue(SAMPLE_IDENTIFER); + description.appendValue(expectedSampleIdentifier); } })); diff --git a/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ProtXMLUploaderTest.java b/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ProtXMLUploaderTest.java index ae14179b04c7f5499029465271465cf6dde15113..5c4912e98d1a80d73cb770967c2078ab97cd9b44 100644 --- a/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ProtXMLUploaderTest.java +++ b/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ProtXMLUploaderTest.java @@ -55,7 +55,7 @@ public class ProtXMLUploaderTest extends ProtXMLTestCase @Override protected ResultDataSetUploader createUploader() { - return new ResultDataSetUploader(null, null, null, true) + return new ResultDataSetUploader(null, null, null, true, "+", false) { @Override void upload(DataSetInformation dataSetInfo, ProteinSummary summary) diff --git a/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ResultDataSetUploaderTest.java b/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ResultDataSetUploaderTest.java index fe45fe551d8ac9782d3a2e12fb0292f61dd98caf..676dfd9930bd54ad00ac3c8445bba33a330137d1 100644 --- a/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ResultDataSetUploaderTest.java +++ b/rtd_phosphonetx/sourceTest/java/ch/systemsx/cisd/openbis/etlserver/proteomics/ResultDataSetUploaderTest.java @@ -145,7 +145,7 @@ public class ResultDataSetUploaderTest extends AssertJUnit dao = context.mock(IProtDAO.class); service = context.mock(IEncapsulatedOpenBISService.class); - uploader = new ResultDataSetUploader(dao, connection, service, true); + uploader = new ResultDataSetUploader(dao, connection, service, true, "+", false); } @AfterMethod @@ -310,7 +310,7 @@ public class ResultDataSetUploaderTest extends AssertJUnit p1.setName(PROTEIN_NAME1); p1.getParameters().add(createAbundance(CELL_LYSATE1, 2.5)); p1.getParameters().add(new Parameter()); - final GroupIdentifier groupIdentifier = new GroupIdentifier(DB_INSTANCE, CommonConstants.MS_DATA_SPACE); + final GroupIdentifier groupIdentifier = new GroupIdentifier((String) null, CommonConstants.MS_DATA_SPACE); final SampleIdentifier sampleIdentifier = new SampleIdentifier(groupIdentifier, CELL_LYSATE1); final ListSamplesByPropertyCriteria criteria = @@ -533,7 +533,7 @@ public class ResultDataSetUploaderTest extends AssertJUnit { { one(service).tryGetSampleWithExperiment( - new SampleIdentifier(new SpaceIdentifier(DB_INSTANCE, + new SampleIdentifier(new SpaceIdentifier((String) null, CommonConstants.MS_DATA_SPACE), CELL_LYSATE1)); ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample = new ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample();