From 75e01f8b77bf818ac1a7725621f95d6f55f49525 Mon Sep 17 00:00:00 2001 From: kaloyane <kaloyane> Date: Mon, 25 Jul 2011 11:28:50 +0000 Subject: [PATCH] [LMS-2401] parse analysis procedures from GE XML file SVN: 22256 --- .../dropbox-all-in-one-with-library.py | 5 +- .../dss/test/SanofiDropboxJythonTest.java | 10 ++++ .../GEExplorerImageAnalysisResultParser.java | 54 +++++++++++++++++-- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/sanofi/dist/etc/sanofi-dropbox/dropbox-all-in-one-with-library.py b/sanofi/dist/etc/sanofi-dropbox/dropbox-all-in-one-with-library.py index 44c9ffed466..fac13fc4504 100644 --- a/sanofi/dist/etc/sanofi-dropbox/dropbox-all-in-one-with-library.py +++ b/sanofi/dist/etc/sanofi-dropbox/dropbox-all-in-one-with-library.py @@ -373,7 +373,8 @@ if incoming.isDirectory(): analysisFile = util.findFileByExt(incoming, "xml") if analysisFile is not None: analysisCSVFile = File(analysisFile.getPath() + ".csv") - GEExplorerImageAnalysisResultParser(analysisFile.getPath()).writeCSV(analysisCSVFile) + geXmlParser = GEExplorerImageAnalysisResultParser(analysisFile.getPath()) + geXmlParser.writeCSV(analysisCSVFile) featureProps = Properties() featureProps.setProperty("separator", ",") @@ -381,7 +382,7 @@ if incoming.isDirectory(): featureProps.setProperty("well-name-col", "Well") analysisDataSetDetails = factory.createFeatureVectorRegistrationDetails(analysisCSVFile.getPath(), featureProps) - analysisProcedureCode = util.extractFileBasename(analysisFile.getName()) + analysisProcedureCode = geXmlParser.getAnalysisProcedureName() analysisDataSetDetails.getDataSetInformation().setAnalysisProcedure(analysisProcedureCode) analysisDataSet = transaction.createNewDataSet(analysisDataSetDetails) analysisDataSet.setSample(imageDataSet.getSample()) diff --git a/sanofi/sourceTest/java/ch/systemsx/cisd/sanofi/dss/test/SanofiDropboxJythonTest.java b/sanofi/sourceTest/java/ch/systemsx/cisd/sanofi/dss/test/SanofiDropboxJythonTest.java index 359fc3062d3..3819f3ba6bb 100644 --- a/sanofi/sourceTest/java/ch/systemsx/cisd/sanofi/dss/test/SanofiDropboxJythonTest.java +++ b/sanofi/sourceTest/java/ch/systemsx/cisd/sanofi/dss/test/SanofiDropboxJythonTest.java @@ -404,6 +404,8 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest NewExternalData analysisDataSet = dataSetsRegistered.get(2); assertEquals(ANALYSIS_DATA_SET_CODE, analysisDataSet.getCode()); assertEquals(ANALYSIS_DATA_SET_TYPE, analysisDataSet.getDataSetType()); + assertEquals("NRF2ProdAnalysis_1.1_MatlabGeneral_1.1", + extractAnalysisProcedureCode(analysisDataSet)); AssertionUtil @@ -414,6 +416,14 @@ public class SanofiDropboxJythonTest extends AbstractJythonDataSetHandlerTest context.assertIsSatisfied(); } + private String extractAnalysisProcedureCode(NewExternalData analysisDataSet) + { + NewProperty property = + EntityHelper.tryFindProperty(analysisDataSet.getDataSetProperties(), + ScreeningConstants.ANALYSIS_PROCEDURE); + return (property != null) ? property.getValue() : null; + } + @Test public void testFatalErrorSentToAdmin() throws IOException { diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/custom/geexplorer/GEExplorerImageAnalysisResultParser.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/custom/geexplorer/GEExplorerImageAnalysisResultParser.java index 9ca6e88fff7..f5f715e640c 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/custom/geexplorer/GEExplorerImageAnalysisResultParser.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/etl/custom/geexplorer/GEExplorerImageAnalysisResultParser.java @@ -31,6 +31,7 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.apache.commons.lang.StringUtils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -49,17 +50,23 @@ public class GEExplorerImageAnalysisResultParser extends DefaultHandler private static final String WELL_TAG = "Well"; - private static final String TABLE_TAG = "Table"; - private static final String DATA_TAG = "Data"; + private static final String ANALYSIS_TAG = "AutoLeadAnalysisProtocol"; + + private static final String ASSAY_TAG = "AutoLeadAssay"; + private enum State { - INIT, DATA, TABLE, WELL, FINISHED + INIT, ANALYSIS, DATA, TABLE, WELL, FINISHED } private State state = State.INIT; + private String analysisProtocolWithVersion = StringUtils.EMPTY; + + private String assayWithVersion = StringUtils.EMPTY; + private String currentWellId; private HashSet<String> wells = new HashSet<String>(); @@ -99,8 +106,16 @@ public class GEExplorerImageAnalysisResultParser extends DefaultHandler } break; case DATA: - if (TABLE_TAG.equals(qName) && "Wells Summary".equals(attributes.getValue("title"))) + if (ANALYSIS_TAG.equals(qName)) + { + analysisProtocolWithVersion = parseNameAndVersion(attributes); + state = State.ANALYSIS; + } + break; + case ANALYSIS: + if (ASSAY_TAG.equals(qName)) { + assayWithVersion = parseNameAndVersion(attributes); state = State.TABLE; } break; @@ -224,4 +239,35 @@ public class GEExplorerImageAnalysisResultParser extends DefaultHandler out.close(); } + public String getAnalysisProcedureName() + { + if (StringUtils.isEmpty(assayWithVersion)) + { + return analysisProtocolWithVersion; + } else + { + return analysisProtocolWithVersion + "_" + assayWithVersion; + } + } + + private String parseNameAndVersion(Attributes attributes) + { + String name = parseAttribute("name", attributes); + String version = parseAttribute("version", attributes); + if (StringUtils.isEmpty(version)) + { + return name; + } else + { + return name + "_" + version; + } + } + + private String parseAttribute(String attrName, Attributes attributes) + { + String attrValue = attributes.getValue(attrName); + return StringUtils.trimToEmpty(attrValue); + } + + } -- GitLab