Skip to content

Commit

Permalink
Add initial write support for mzXML chromatograms.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Jun 17, 2021
1 parent 94fa019 commit d010a15
Show file tree
Hide file tree
Showing 16 changed files with 370 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.preferencePages">
<page
category="org.eclipse.chemclipse.msd.converter.ui.converterPreferencePage"
class="org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui.preferences.PreferencePage"
id="org.eclipse.chemclipse.msd.converter.supplier.mzxml.ui.preferences.converterPreferencePage"
name="mzXML Converter">
</page>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,13 +19,21 @@
*/
public class Activator extends AbstractUIPlugin {

private static BundleContext context;

public static BundleContext getContext() {

return context;
}

// The shared instance
private static Activator plugin;

/**
* The constructor
*/
public Activator() {

}

/*
Expand All @@ -36,6 +44,7 @@ public Activator() {
*/
public void start(BundleContext context) throws Exception {

Activator.context = context;
super.start(context);
plugin = this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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">
</ChromatogramSupplier>
</extension>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IIon> 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(1)); // TODO
Peaks peaks = new Peaks();
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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -57,6 +58,7 @@ public class ReaderVersion32 extends AbstractReaderVersion implements IChromatog
private String contextPath;

public ReaderVersion32(String contextPath) {

this.contextPath = contextPath;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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> parentFile;
private List<MsInstrument> msInstrument;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down
Loading

0 comments on commit d010a15

Please sign in to comment.