From 1b413cae7e90fab6672ce02080f9241298632838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Thu, 17 Jun 2021 22:57:23 +0200 Subject: [PATCH] Add initial write support for mzXML chromatograms. --- .../META-INF/MANIFEST.MF | 7 +- .../plugin.xml | 13 +++ .../supplier/mzxml/ui/Activator.java | 11 ++- .../mzxml/ui/preferences/PreferencePage.java | 40 ++++++++ .../META-INF/MANIFEST.MF | 1 + .../plugin.xml | 2 +- .../internal/io/ChromatogramWriter32.java | 91 +++++++++++++++++++ .../supplier/mzxml/internal/io/IFormat.java | 29 ++++++ .../mzxml/internal/io/ReaderVersion32.java | 8 +- .../mzxml/internal/v32/model/MsRun.java | 6 +- .../mzxml/internal/v32/model/MzXML.java | 40 ++++++++ .../mzxml/internal/v32/model/Scan.java | 3 +- .../supplier/mzxml/io/ChromatogramReader.java | 40 +++----- .../supplier/mzxml/io/ChromatogramWriter.java | 23 ++++- .../preferences/PreferenceInitializer.java | 22 +++++ .../mzxml/preferences/PreferenceSupplier.java | 77 ++++++++++++++++ 16 files changed, 370 insertions(+), 43 deletions(-) create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/plugin.xml create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/ui/preferences/PreferencePage.java create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/io/ChromatogramWriter32.java create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/io/IFormat.java create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/v32/model/MzXML.java create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/preferences/PreferenceInitializer.java create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/preferences/PreferenceSupplier.java diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/META-INF/MANIFEST.MF b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/META-INF/MANIFEST.MF index 3f4c85a2ce..75547da37c 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/META-INF/MANIFEST.MF +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/META-INF/MANIFEST.MF @@ -2,11 +2,14 @@ Manifest-Version: 1.0 Automatic-Module-Name: org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui Bundle-ManifestVersion: 2 Bundle-Name: mzXML UI -Bundle-SymbolicName: org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui +Bundle-SymbolicName: org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui;singleton:=true Bundle-Version: 0.9.0.qualifier Bundle-Activator: org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui.Activator Bundle-Vendor: ChemClipse Require-Bundle: org.eclipse.ui, - org.eclipse.core.runtime + org.eclipse.core.runtime, + org.eclipse.chemclipse.support, + org.eclipse.chemclipse.msd.converter.supplier.mzxml, + org.eclipse.chemclipse.support.ui Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/plugin.xml b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/plugin.xml new file mode 100644 index 0000000000..0e5cd36ac7 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/ui/Activator.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/ui/Activator.java index 8dea23dbab..dc88fa6b5c 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/ui/Activator.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/ui/Activator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2018 Lablicate GmbH. + * Copyright (c) 2008, 2021 Lablicate GmbH. * * All rights reserved. * This program and the accompanying materials are made available under the @@ -19,6 +19,13 @@ */ public class Activator extends AbstractUIPlugin { + private static BundleContext context; + + public static BundleContext getContext() { + + return context; + } + // The shared instance private static Activator plugin; @@ -26,6 +33,7 @@ public class Activator extends AbstractUIPlugin { * The constructor */ public Activator() { + } /* @@ -36,6 +44,7 @@ public Activator() { */ public void start(BundleContext context) throws Exception { + Activator.context = context; super.start(context); plugin = this; } diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/ui/preferences/PreferencePage.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/ui/preferences/PreferencePage.java new file mode 100644 index 0000000000..e4eb423f53 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/ui/preferences/PreferencePage.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2021 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Mailänder - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui.preferences; + +import org.eclipse.chemclipse.msd.converter.supplier.mzxml.preferences.PreferenceSupplier; +import org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui.Activator; +import org.eclipse.chemclipse.support.ui.preferences.fieldeditors.SpacerFieldEditor; +import org.eclipse.jface.preference.ComboFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +public class PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + + public PreferencePage() { + + super(GRID); + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + setDescription("mzXML Converter"); + } + + public void createFieldEditors() { + + addField(new SpacerFieldEditor(getFieldEditorParent())); + addField(new ComboFieldEditor(PreferenceSupplier.P_CHROMATOGRAM_VERSION_SAVE, "Save (*.mzxml) as version:", PreferenceSupplier.getChromatogramVersions(), getFieldEditorParent())); + } + + public void init(IWorkbench workbench) { + + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/META-INF/MANIFEST.MF b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/META-INF/MANIFEST.MF index 14c7dd5726..4bc00f8ea5 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/META-INF/MANIFEST.MF +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/META-INF/MANIFEST.MF @@ -18,3 +18,4 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.chemclipse.xxd.converter.supplier.chemclipse;bundle-version="0.8.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.chemclipse.msd.converter.supplier.mzxml.preferences diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/plugin.xml b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/plugin.xml index ba2dba8264..9ca20ed910 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/plugin.xml +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/plugin.xml @@ -11,7 +11,7 @@ id="org.eclipse.chemclipse.msd.converter.supplier.mzxml.chromatogram" importConverter="org.eclipse.chemclipse.msd.converter.supplier.mzxml.converter.ChromatogramImportConverter" importMagicNumberMatcher="org.eclipse.chemclipse.msd.converter.supplier.mzxml.converter.MagicNumberMatcher" - isExportable="false" + isExportable="true" isImportable="true"> diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/io/ChromatogramWriter32.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/io/ChromatogramWriter32.java new file mode 100644 index 0000000000..a01de2224a --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/io/ChromatogramWriter32.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2021 Lablicate GmbH. + * + * All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Mailänder - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.io; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.DoubleBuffer; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; + +import org.eclipse.chemclipse.converter.exceptions.FileIsNotWriteableException; +import org.eclipse.chemclipse.converter.io.AbstractChromatogramWriter; +import org.eclipse.chemclipse.logging.core.Logger; +import org.eclipse.chemclipse.model.core.IScan; +import org.eclipse.chemclipse.msd.converter.io.IChromatogramMSDWriter; +import org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v32.model.MsRun; +import org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v32.model.MzXML; +import org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v32.model.Peaks; +import org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v32.model.Scan; +import org.eclipse.chemclipse.msd.model.core.IChromatogramMSD; +import org.eclipse.chemclipse.msd.model.core.IIon; +import org.eclipse.chemclipse.msd.model.core.IScanMSD; +import org.eclipse.core.runtime.IProgressMonitor; + +public class ChromatogramWriter32 extends AbstractChromatogramWriter implements IChromatogramMSDWriter { + + private static final Logger logger = Logger.getLogger(ChromatogramWriter32.class); + + @Override + public void writeChromatogram(File file, IChromatogramMSD chromatogram, IProgressMonitor monitor) throws FileNotFoundException, FileIsNotWriteableException, IOException { + + try { + JAXBContext jaxbContext = JAXBContext.newInstance(org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v32.model.MzXML.class); + Marshaller marshaller = jaxbContext.createMarshaller(); + MsRun msRun = new MsRun(); + for(IScan sourceScan : chromatogram.getScans()) { + Scan exportScan = new Scan(); + exportScan.setTotIonCurrent(sourceScan.getTotalSignal()); + exportScan.setRetentionTime(DatatypeFactory.newInstance().newDuration(sourceScan.getRetentionTime())); + IScanMSD scanMSD = (IScanMSD)sourceScan; + List ions = scanMSD.getIons(); + double[] values = new double[ions.size() * 2]; + int i = 0; + for(IIon ion : ions) { + values[i] = ion.getIon(); + values[i + 1] = ion.getAbundance(); + i += 2; + } + exportScan.setMsLevel(BigInteger.valueOf(0)); // TODO + Peaks peaks = new Peaks(); // TODO: pairOrder + DoubleBuffer doubleBuffer = DoubleBuffer.wrap(values); + ByteBuffer byteBuffer = ByteBuffer.allocate(doubleBuffer.capacity() * Double.BYTES); + peaks.setPrecision(BigInteger.valueOf(64)); + peaks.setByteOrder("network"); + byteBuffer.order(ByteOrder.BIG_ENDIAN); // TODO: preferences + // TODO: compression + byteBuffer.asDoubleBuffer().put(doubleBuffer); + peaks.setValue(byteBuffer.array()); + exportScan.getPeaks().add(peaks); + msRun.getScan().add(exportScan); + } + MzXML mzXML = new MzXML(); + mzXML.setMsRun(msRun); + marshaller.marshal(mzXML, file); + } catch(JAXBException e) { + logger.warn(e); + } catch(DatatypeConfigurationException e) { + logger.warn(e); + } catch(Exception e) { + e.printStackTrace(); + } + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/io/IFormat.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/io/IFormat.java new file mode 100644 index 0000000000..b5a21494b7 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/io/IFormat.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2021 Lablicate GmbH. + * + * All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Mailänder + *******************************************************************************/ +package org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.io; + +public interface IFormat { + + String CONTEXT_PATH_V_200 = "org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v20.model"; + String CONTEXT_PATH_V_210 = "org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v21.model"; + String CONTEXT_PATH_V_220 = "org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v22.model"; + String CONTEXT_PATH_V_300 = "org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v30.model"; + String CONTEXT_PATH_V_310 = "org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v31.model"; + String CONTEXT_PATH_V_320 = "org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v32.model"; + String MZXML_V_200 = "mzXML_2.0"; + String MZXML_V_210 = "mzXML_2.1"; + String MZXML_V_220 = "mzXML_2.2"; + String MZXML_V_300 = "mzXML_3.0"; + String MZXML_V_310 = "mzXML_3.1"; + String MZXML_V_320 = "mzXML_3.2"; + String CHROMATOGRAM_VERSION_LATEST = MZXML_V_320; +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/io/ReaderVersion32.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/io/ReaderVersion32.java index e27ec87f0e..027922488f 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/io/ReaderVersion32.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/io/ReaderVersion32.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2019 Lablicate GmbH. + * Copyright (c) 2015, 2021 Lablicate GmbH. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -19,6 +19,7 @@ import java.nio.ByteOrder; import java.nio.DoubleBuffer; import java.nio.FloatBuffer; +import java.util.Date; import java.util.zip.DataFormatException; import java.util.zip.Inflater; @@ -57,6 +58,7 @@ public class ReaderVersion32 extends AbstractReaderVersion implements IChromatog private String contextPath; public ReaderVersion32(String contextPath) { + this.contextPath = contextPath; } @@ -85,7 +87,7 @@ public IChromatogramMSD read(File file, IProgressMonitor monitor) throws FileNot * Get the mass spectra. */ IVendorScan massSpectrum = new VendorScan(); - int retentionTime = scan.getRetentionTime().multiply(1000).getSeconds(); // milliseconds + long retentionTime = scan.getRetentionTime().getTimeInMillis(new Date()); // MS, MS/MS short msLevel = scan.getMsLevel().shortValue(); massSpectrum.setMassSpectrometer(msLevel); @@ -104,7 +106,7 @@ public IChromatogramMSD read(File file, IProgressMonitor monitor) throws FileNot if(cycleNumber >= 1) { massSpectrum.setCycleNumber(cycleNumber); } - massSpectrum.setRetentionTime(retentionTime); + massSpectrum.setRetentionTime((int)retentionTime); /* * Get the ions. */ diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/v32/model/MsRun.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/v32/model/MsRun.java index 94cdbb8677..54f6a053bf 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/v32/model/MsRun.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/v32/model/MsRun.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2018 Lablicate GmbH. + * Copyright (c) 2015, 2021 Lablicate GmbH. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -11,7 +11,6 @@ *******************************************************************************/ package org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v32.model; -import java.io.Serializable; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; @@ -28,9 +27,8 @@ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = {"parentFile", "msInstrument", "dataProcessing", "separation", "spotting", "scan", "sha1"}) @XmlRootElement(name = "msRun") -public class MsRun implements Serializable { +public class MsRun { - private final static long serialVersionUID = 320L; @XmlElement(required = true) private List parentFile; private List msInstrument; diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/v32/model/MzXML.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/v32/model/MzXML.java new file mode 100644 index 0000000000..6c502856c4 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/v32/model/MzXML.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2021 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Mailände - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v32.model; + +import java.io.Serializable; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = {"msRun"}) +@XmlRootElement(name = "mzXML", namespace = "http://sashimi.sourceforge.net/schema_revision/mzXML_3.2") +public class MzXML implements Serializable { + + private final static long serialVersionUID = 320L; + @XmlElement(required = true) + private MsRun msRun; + + public MsRun getMsRun() { + + return msRun; + } + + public void setMsRun(MsRun value) { + + this.msRun = value; + } +} diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/v32/model/Scan.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/v32/model/Scan.java index 129aeebb51..e66bd8f678 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/v32/model/Scan.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/internal/v32/model/Scan.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2018 Lablicate GmbH. + * Copyright (c) 2015, 2021 Lablicate GmbH. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -15,6 +15,7 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.List; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/io/ChromatogramReader.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/io/ChromatogramReader.java index 5ee74eb7e0..da36e3ab55 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/io/ChromatogramReader.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/io/ChromatogramReader.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2018 Lablicate GmbH. + * Copyright (c) 2008, 2021 Lablicate GmbH. * * All rights reserved. * This program and the accompanying materials are made available under the @@ -22,6 +22,7 @@ import org.eclipse.chemclipse.model.core.IChromatogramOverview; import org.eclipse.chemclipse.msd.converter.io.AbstractChromatogramMSDReader; import org.eclipse.chemclipse.msd.converter.io.IChromatogramMSDReader; +import org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.io.IFormat; import org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.io.ReaderVersion20; import org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.io.ReaderVersion21; import org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.io.ReaderVersion30; @@ -33,19 +34,6 @@ public class ChromatogramReader extends AbstractChromatogramMSDReader implements IChromatogramMSDReader { - private static final String CONTEXT_PATH_V_200 = "org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v20.model"; - private static final String CONTEXT_PATH_V_210 = "org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v21.model"; - private static final String CONTEXT_PATH_V_220 = "org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v22.model"; - private static final String CONTEXT_PATH_V_300 = "org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v30.model"; - private static final String CONTEXT_PATH_V_310 = "org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v31.model"; - private static final String CONTEXT_PATH_V_320 = "org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.v32.model"; - private static final String MZXML_V_200 = "mzXML_2.0"; - private static final String MZXML_V_210 = "mzXML_2.1"; - private static final String MZXML_V_220 = "mzXML_2.2"; - private static final String MZXML_V_300 = "mzXML_3.0"; - private static final String MZXML_V_310 = "mzXML_3.1"; - private static final String MZXML_V_320 = "mzXML_3.2"; - public static IChromatogramMSDReader getReader(final File file) throws IOException { IChromatogramMSDReader chromatogramReader = null; @@ -56,18 +44,18 @@ public static IChromatogramMSDReader getReader(final File file) throws IOExcepti fileReader.close(); // final String header = new String(charBuffer); - if(header.contains(MZXML_V_200)) { - chromatogramReader = new ReaderVersion20(CONTEXT_PATH_V_200); - } else if(header.contains(MZXML_V_210)) { - chromatogramReader = new ReaderVersion21(CONTEXT_PATH_V_210); - } else if(header.contains(MZXML_V_220)) { - chromatogramReader = new ReaderVersion21(CONTEXT_PATH_V_220); - } else if(header.contains(MZXML_V_300)) { - chromatogramReader = new ReaderVersion30(CONTEXT_PATH_V_300); - } else if(header.contains(MZXML_V_310)) { - chromatogramReader = new ReaderVersion31(CONTEXT_PATH_V_310); - } else if(header.contains(MZXML_V_320)) { - chromatogramReader = new ReaderVersion32(CONTEXT_PATH_V_320); + if(header.contains(IFormat.MZXML_V_200)) { + chromatogramReader = new ReaderVersion20(IFormat.CONTEXT_PATH_V_200); + } else if(header.contains(IFormat.MZXML_V_210)) { + chromatogramReader = new ReaderVersion21(IFormat.CONTEXT_PATH_V_210); + } else if(header.contains(IFormat.MZXML_V_220)) { + chromatogramReader = new ReaderVersion21(IFormat.CONTEXT_PATH_V_220); + } else if(header.contains(IFormat.MZXML_V_300)) { + chromatogramReader = new ReaderVersion30(IFormat.CONTEXT_PATH_V_300); + } else if(header.contains(IFormat.MZXML_V_310)) { + chromatogramReader = new ReaderVersion31(IFormat.CONTEXT_PATH_V_310); + } else if(header.contains(IFormat.MZXML_V_320)) { + chromatogramReader = new ReaderVersion32(IFormat.CONTEXT_PATH_V_320); } else { throw new UnknownVersionException(); } diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/io/ChromatogramWriter.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/io/ChromatogramWriter.java index d3a6771b2f..bc44ccb47a 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/io/ChromatogramWriter.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/io/ChromatogramWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2018 Lablicate GmbH. + * Copyright (c) 2008, 2021 Lablicate GmbH. * * All rights reserved. * This program and the accompanying materials are made available under the @@ -8,6 +8,7 @@ * * Contributors: * Dr. Philip Wenig - initial API and implementation + * Matthias Mailänder - add support for saving version 3.2 *******************************************************************************/ package org.eclipse.chemclipse.msd.converter.supplier.mzxml.io; @@ -17,18 +18,30 @@ import org.eclipse.chemclipse.converter.exceptions.FileIsNotWriteableException; import org.eclipse.chemclipse.converter.io.AbstractChromatogramWriter; -import org.eclipse.chemclipse.logging.core.Logger; import org.eclipse.chemclipse.msd.converter.io.IChromatogramMSDWriter; +import org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.io.ChromatogramWriter32; +import org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.io.IFormat; +import org.eclipse.chemclipse.msd.converter.supplier.mzxml.preferences.PreferenceSupplier; import org.eclipse.chemclipse.msd.model.core.IChromatogramMSD; import org.eclipse.core.runtime.IProgressMonitor; public class ChromatogramWriter extends AbstractChromatogramWriter implements IChromatogramMSDWriter { - private static final Logger logger = Logger.getLogger(ChromatogramWriter.class); - @Override public void writeChromatogram(File file, IChromatogramMSD chromatogram, IProgressMonitor monitor) throws FileNotFoundException, FileIsNotWriteableException, IOException { - logger.info("The mzXML writer needs to be re-implemented."); + final IChromatogramMSDWriter chromatogramWriter = getChromatogramWriter(); + if(chromatogramWriter != null) { + chromatogramWriter.writeChromatogram(file, chromatogram, monitor); + } + } + + private IChromatogramMSDWriter getChromatogramWriter() { + + String versionSave = PreferenceSupplier.getChromatogramVersionSave(); + if(versionSave.equals(IFormat.MZXML_V_320)) { + return new ChromatogramWriter32(); + } + return null; } } diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/preferences/PreferenceInitializer.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/preferences/PreferenceInitializer.java new file mode 100644 index 0000000000..6969849986 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/preferences/PreferenceInitializer.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2014, 2021 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Dr. Philip Wenig - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.msd.converter.supplier.mzxml.preferences; + +import org.eclipse.chemclipse.support.preferences.AbstractExtendedPreferenceInitializer; + +public class PreferenceInitializer extends AbstractExtendedPreferenceInitializer { + + public PreferenceInitializer() { + + super(PreferenceSupplier.INSTANCE()); + } +} \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/preferences/PreferenceSupplier.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/preferences/PreferenceSupplier.java new file mode 100644 index 0000000000..eefb621281 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzxml/src/org/eclipse/chemclipse/msd/converter/supplier/mzxml/preferences/PreferenceSupplier.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2021 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Mailänder - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.msd.converter.supplier.mzxml.preferences; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.chemclipse.msd.converter.supplier.mzxml.Activator; +import org.eclipse.chemclipse.msd.converter.supplier.mzxml.internal.io.IFormat; +import org.eclipse.chemclipse.support.preferences.IPreferenceSupplier; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; + +public class PreferenceSupplier implements IPreferenceSupplier { + + public static final String P_CHROMATOGRAM_VERSION_SAVE = "chromatogramVersionSave"; + public static final String DEF_CHROMATOGRAM_VERSION_SAVE = IFormat.CHROMATOGRAM_VERSION_LATEST; + private static IPreferenceSupplier preferenceSupplier; + + public static IPreferenceSupplier INSTANCE() { + + if(preferenceSupplier == null) { + preferenceSupplier = new PreferenceSupplier(); + } + return preferenceSupplier; + } + + @Override + public IScopeContext getScopeContext() { + + return InstanceScope.INSTANCE; + } + + @Override + public String getPreferenceNode() { + + return Activator.getContext().getBundle().getSymbolicName(); + } + + @Override + public Map getDefaultValues() { + + Map defaultValues = new HashMap(); + defaultValues.put(P_CHROMATOGRAM_VERSION_SAVE, DEF_CHROMATOGRAM_VERSION_SAVE); + return defaultValues; + } + + @Override + public IEclipsePreferences getPreferences() { + + return getScopeContext().getNode(getPreferenceNode()); + } + + public static String getChromatogramVersionSave() { + + IEclipsePreferences preferences = INSTANCE().getPreferences(); + return preferences.get(P_CHROMATOGRAM_VERSION_SAVE, DEF_CHROMATOGRAM_VERSION_SAVE); + } + + public static String[][] getChromatogramVersions() { + + String[][] elements = new String[1][2]; + elements[0][0] = IFormat.MZXML_V_320.split("_")[1]; + elements[0][1] = IFormat.MZXML_V_320; + return elements; + } +}