diff --git a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/ChipResultsSummary.java b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/ChipResultsSummary.java new file mode 100644 index 0000000000000000000000000000000000000000..cf07fd33f048cba6d8831455aa7eb92825de3ccf --- /dev/null +++ b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/ChipResultsSummary.java @@ -0,0 +1,74 @@ +/* + * 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.plugins; + +import javax.xml.bind.annotation.XmlElement; + +/** + * <pre> + * <ChipResultsSummary> + * <clusterCountPF>98792458</clusterCountPF> + * <clusterCountRaw>158466917</clusterCountRaw> + * <yield>3556528488</yield> + * </ChipResultsSummary> + * </pre> + * + * @author Manuel Kohler + */ +// @XmlType +public class ChipResultsSummary +{ + private String clusterCountPF; + + private String clusterCountRaw; + + private String yield; + + @XmlElement + public String getClusterCountPF() + { + return clusterCountPF; + } + + public void setClusterCountPF(String clusterCountPF) + { + this.clusterCountPF = clusterCountPF; + } + + @XmlElement + public String getClusterCountRaw() + { + return clusterCountRaw; + } + + public void setClusterCountRaw(String clusterCountRaw) + { + this.clusterCountRaw = clusterCountRaw; + } + + @XmlElement + public String getYield() + { + return yield; + } + + public void setYield(String yield) + { + this.yield = yield; + } + +} diff --git a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/IlluminaSummary.java b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/IlluminaSummary.java new file mode 100644 index 0000000000000000000000000000000000000000..c9e801b7cb0b51fcf8c8c430df5e6b41a2f18963 --- /dev/null +++ b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/IlluminaSummary.java @@ -0,0 +1,53 @@ +/* + * 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.plugins; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * <pre> + * <Summary> + * <ChipResultsSummary> + * <clusterCountPF>98792458</clusterCountPF> + * <clusterCountRaw>158466917</clusterCountRaw> + * <yield>3556528488</yield> + * </ChipResultsSummary> + * ... + * <Summary> + * </pre> + * + * @author Manuel Kohler + */ +@XmlRootElement(name = "Summary") +// @XmlType +public class IlluminaSummary +{ + private ChipResultsSummary chipResultsSummary; + + @XmlElement(name = "ChipResultsSummary") + public ChipResultsSummary getChipResultsSummary() + { + return chipResultsSummary; + } + + public void setChipResultsSummary(ChipResultsSummary chipResultsSummary) + { + this.chipResultsSummary = chipResultsSummary; + } + +} diff --git a/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/IlluminaSummaryXMLLoader.java b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/IlluminaSummaryXMLLoader.java new file mode 100644 index 0000000000000000000000000000000000000000..4128e188937c5f1f3a698f3895f290b9b0821603 --- /dev/null +++ b/deep_sequencing_unit/source/java/ch/ethz/bsse/cisd/dsu/dss/plugins/IlluminaSummaryXMLLoader.java @@ -0,0 +1,94 @@ +/* + * Copyright 2009 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.plugins; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.UnmarshallerHandler; + +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel; +import ch.systemsx.cisd.common.utilities.XMLInfraStructure; + +/** + * Loader of Illumina summary XML file. + * + * @author Manuel Kohler + */ +class IlluminaSummaryXMLLoader +{ + + private final Unmarshaller unmarshaller; + + private final XMLInfraStructure xmlInfraStructure; + + IlluminaSummaryXMLLoader(boolean validating) + { + try + { + JAXBContext context = JAXBContext.newInstance(IlluminaSummary.class); + unmarshaller = context.createUnmarshaller(); + xmlInfraStructure = new XMLInfraStructure(validating); + xmlInfraStructure.setEntityResolver(new EntityResolver() + { + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException + { + String schemaVersion = systemId.substring(systemId.lastIndexOf('/')); + String resource = + "/" + + IlluminaSummaryXMLLoader.class.getPackage().getName() + .replace('.', '/') + schemaVersion; + InputStream inputStream = + IlluminaSummaryXMLLoader.class.getResourceAsStream(resource); + return inputStream == null ? null : new InputSource(inputStream); + } + }); + + } catch (Exception ex) + { + throw CheckedExceptionTunnel.wrapIfNecessary(ex); + } + } + + IlluminaSummary readSummaryXML(File dataSet) + { + try + { + UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler(); + xmlInfraStructure.parse(new FileReader(dataSet), unmarshallerHandler); + Object object = unmarshallerHandler.getResult(); + if (object instanceof IlluminaSummary == false) + { + throw new IllegalArgumentException("Wrong type: " + object); + } + return (IlluminaSummary) object; + } catch (Exception ex) + { + throw CheckedExceptionTunnel.wrapIfNecessary(ex); + } + } + +} diff --git a/deep_sequencing_unit/sourceTest/java/ch/ethz/bsse/cisd/dsu/dss/plugins/IlluminaSummaryXMLLoaderTest.java b/deep_sequencing_unit/sourceTest/java/ch/ethz/bsse/cisd/dsu/dss/plugins/IlluminaSummaryXMLLoaderTest.java new file mode 100644 index 0000000000000000000000000000000000000000..eb8f0494dad880ec468bc46dcf41039c9eb70eef --- /dev/null +++ b/deep_sequencing_unit/sourceTest/java/ch/ethz/bsse/cisd/dsu/dss/plugins/IlluminaSummaryXMLLoaderTest.java @@ -0,0 +1,63 @@ +/* + * Copyright 2009 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.plugins; + +import java.io.File; + +import org.testng.annotations.Test; + +import ch.systemsx.cisd.base.tests.AbstractFileSystemTestCase; +import ch.systemsx.cisd.common.filesystem.FileUtilities; + +/** + * @author Franz-Josef Elmer + */ +public class IlluminaSummaryXMLLoaderTest extends AbstractFileSystemTestCase +{ + @Test + public void test() + { + File file = new File(workingDirectory, "test.xml"); + FileUtilities.writeToFile(file, EXAMPLE); + IlluminaSummary summary = new IlluminaSummaryXMLLoader(false).readSummaryXML(file); + + ChipResultsSummary chipResultsSummary = summary.getChipResultsSummary(); + assertEquals("98792458", chipResultsSummary.getClusterCountPF()); + assertEquals("158466917", chipResultsSummary.getClusterCountRaw()); + assertEquals("3556528488", chipResultsSummary.getYield()); + } + + protected static final String EXAMPLE = "<?xml version='1.0' ?>\n " + + "<?xml-stylesheet type='text/xsl' href='Summary.xsl' ?>\n " + + "<Summary> " + + " <ChipResultsSummary> " + + " <clusterCountPF>98792458</clusterCountPF> " + + " <clusterCountRaw>158466917</clusterCountRaw> " + + " <yield>3556528488</yield> " + + " </ChipResultsSummary> " + + " <ChipSummary> " + + " <ChipID>unknown</ChipID> " + + " <Machine>HWI-EAS264</Machine> " + + " <RunFolder>090916_42R0CAAXX</RunFolder> " + + " </ChipSummary> " + + " <Date>Tue Oct 20 18:15:43 2009</Date> " + + " <ExpandedLaneSummary/> " + + " <LaneParameterSummary/> " + + " <LaneResultsSummary/> " + + " <TileErrorsByLane/> " + + "</Summary>"; +}