From 6cd595c0e86547259edecf09476dfa39ad7e7d08 Mon Sep 17 00:00:00 2001 From: tpylak <tpylak> Date: Thu, 4 Mar 2010 23:32:38 +0000 Subject: [PATCH] LMS-1397 yeastx: introduce label, mz1 and mz2 columns SVN: 15051 --- .../EICMLChromatogramImagesReporter.java | 61 ++++++++++++++++++- .../EICMLChromatogramImagesReporterTest.java | 46 ++++++++++++++ 2 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 rtd_yeastx/sourceTest/java/ch/systemsx/cisd/yeastx/eicml/EICMLChromatogramImagesReporterTest.java diff --git a/rtd_yeastx/source/java/ch/systemsx/cisd/yeastx/eicml/EICMLChromatogramImagesReporter.java b/rtd_yeastx/source/java/ch/systemsx/cisd/yeastx/eicml/EICMLChromatogramImagesReporter.java index 4652de5cab1..d4164b7c8b8 100644 --- a/rtd_yeastx/source/java/ch/systemsx/cisd/yeastx/eicml/EICMLChromatogramImagesReporter.java +++ b/rtd_yeastx/source/java/ch/systemsx/cisd/yeastx/eicml/EICMLChromatogramImagesReporter.java @@ -26,6 +26,7 @@ import javax.sql.DataSource; import net.lemnik.eodsql.DataIterator; import net.lemnik.eodsql.QueryTool; +import ch.rinn.restrictions.Private; import ch.systemsx.cisd.dbmigration.DatabaseConfigurationContext; import ch.systemsx.cisd.openbis.dss.generic.server.plugins.standard.AbstractDatastorePlugin; import ch.systemsx.cisd.openbis.dss.generic.server.plugins.tasks.IReportingPluginTask; @@ -49,7 +50,7 @@ public class EICMLChromatogramImagesReporter extends AbstractDatastorePlugin imp private static final String CHROMATOGRAM_SERVLET = "chromatogram"; private static final int THUMBNAIL_WIDTH = 150; - + private static final int THUMBNAIL_HEIGHT = 150; private static final int IMAGE_WIDTH = 1066; @@ -61,7 +62,7 @@ public class EICMLChromatogramImagesReporter extends AbstractDatastorePlugin imp private final IEICMSRunDAO query; /** - * An internal helper class for storing the information for the query paramters to the image + * An internal helper class for storing the information for the query parameters to the image * servlet. * * @author Chandrasekhar Ramakrishnan @@ -169,12 +170,68 @@ public class EICMLChromatogramImagesReporter extends AbstractDatastorePlugin imp imageCell.addParameter(EICMLChromatogramGeneratorServlet.CHROMATOGRAM_CODE_PARAM, chromatogram.getId()); + String chromatogramLabel = chromatogram.getLabel(); + row.add(SimpleTableModelBuilder.asText(chromatogramLabel)); + int mz1 = getMz1(chromatogramLabel); + row.add(SimpleTableModelBuilder.asNum(mz1)); + int mz2 = getMz2(chromatogramLabel); + row.add(SimpleTableModelBuilder.asNum(mz2)); row.add(imageCell); return row; } + // All eic_chromatograms.label values have a format [-]EIC mz1[>mz2]. + @Private + static int getMz1(String chromatogramLabel) + { + String textBefore = "EIC "; + int ixEic = chromatogramLabel.indexOf(textBefore); + if (ixEic == -1) + { + return -1; + } + int ixGt = chromatogramLabel.indexOf(">"); + if (ixGt == -1) + { + ixGt = chromatogramLabel.length(); + } + if (ixGt < ixEic) + { + return -1; + } + String text = chromatogramLabel.substring(ixEic + textBefore.length(), ixGt); + return parseNumber(text, -1); + } + + // All eic_chromatograms.label values have a format [-]EIC mz1[>mz2]. + @Private + static int getMz2(String chromatogramLabel) + { + int ixGt = chromatogramLabel.indexOf(">"); + if (ixGt == -1) + { + return -1; + } + String text = chromatogramLabel.substring(ixGt + 1); + return parseNumber(text, -1); + } + + private static int parseNumber(String text, int defaultValue) + { + try + { + return Integer.parseInt(text); + } catch (NumberFormatException ex) + { + return defaultValue; + } + } + private static void addReportHeaders(SimpleTableModelBuilder builder) { + builder.addHeader("Label"); + builder.addHeader("m/z 1"); + builder.addHeader("m/z 2"); builder.addHeader("Chromatogram"); } } diff --git a/rtd_yeastx/sourceTest/java/ch/systemsx/cisd/yeastx/eicml/EICMLChromatogramImagesReporterTest.java b/rtd_yeastx/sourceTest/java/ch/systemsx/cisd/yeastx/eicml/EICMLChromatogramImagesReporterTest.java new file mode 100644 index 00000000000..adc44046d88 --- /dev/null +++ b/rtd_yeastx/sourceTest/java/ch/systemsx/cisd/yeastx/eicml/EICMLChromatogramImagesReporterTest.java @@ -0,0 +1,46 @@ +/* + * 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.systemsx.cisd.yeastx.eicml; + +import static ch.systemsx.cisd.yeastx.eicml.EICMLChromatogramImagesReporter.getMz1; +import static ch.systemsx.cisd.yeastx.eicml.EICMLChromatogramImagesReporter.getMz2; +import static org.testng.AssertJUnit.assertEquals; + +import org.testng.annotations.Test; + +import ch.rinn.restrictions.Friend; + +/** + * Test of {@link EICMLChromatogramImagesReporter} + * + * @author Tomasz Pylak + */ +@Friend(toClasses = EICMLChromatogramImagesReporter.class) +public class EICMLChromatogramImagesReporterTest +{ + @Test + public void testLabelParsing() + { + assertEquals(10, getMz1("-EIC 10>23")); + assertEquals(10, getMz1("EIC 10>23")); + assertEquals(10, getMz1("-EIC 10")); + assertEquals(23, getMz2("-EIC 10>23")); + assertEquals(23, getMz2("EIC 10>23")); + assertEquals(-1, getMz2("-EIC 10")); + + } +} -- GitLab