diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/plugin.xml b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/plugin.xml
index 1bd9e2ac96..fbbb3b0dff 100644
--- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/plugin.xml
+++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/plugin.xml
@@ -7,13 +7,27 @@
description="Reads mzData Chromatograms"
exportConverter="org.eclipse.chemclipse.msd.converter.supplier.mzdata.converter.ChromatogramExportConverter"
fileExtension=".mzData"
- filterName="mzData Chromatogram (*.mzData)"
+ filterName="Chromatogram (*.mzData)"
id="org.eclipse.chemclipse.msd.converter.supplier.mzdata"
importConverter="org.eclipse.chemclipse.msd.converter.supplier.mzdata.converter.ChromatogramImportConverter"
- importMagicNumberMatcher="org.eclipse.chemclipse.msd.converter.supplier.mzdata.converter.MagicNumberMatcher"
+ importMagicNumberMatcher="org.eclipse.chemclipse.msd.converter.supplier.mzdata.converter.ChromatogramMagicNumberMatcher"
isExportable="true"
isImportable="true">
+
+
+
+
diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/ChromatogramMagicNumberMatcher.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/ChromatogramMagicNumberMatcher.java
new file mode 100644
index 0000000000..96c154692c
--- /dev/null
+++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/ChromatogramMagicNumberMatcher.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2016, 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
+ * Matthias Mailänder - auto detection for chromatography files
+ *******************************************************************************/
+package org.eclipse.chemclipse.msd.converter.supplier.mzdata.converter;
+
+import java.io.File;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.eclipse.chemclipse.converter.core.AbstractMagicNumberMatcher;
+import org.eclipse.chemclipse.converter.core.IMagicNumberMatcher;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.io.IFormat;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.support.IConstants;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.support.SpecificationValidator;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.v105.model.MzData;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+public class ChromatogramMagicNumberMatcher extends AbstractMagicNumberMatcher implements IMagicNumberMatcher {
+
+ @Override
+ public boolean checkFileFormat(File file) {
+
+ boolean isValidFormat = false;
+ try {
+ file = SpecificationValidator.validateSpecification(file);
+ if(!file.exists()) {
+ return isValidFormat;
+ }
+ if(!checkFileExtension(file, ".mzdata")) {
+ return isValidFormat;
+ }
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+ Document document = documentBuilder.parse(file);
+ NodeList nodeList = document.getElementsByTagName(IConstants.NODE_MZ_DATA);
+ //
+ JAXBContext jaxbContext = JAXBContext.newInstance(IFormat.CONTEXT_PATH_V_105);
+ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+ MzData mzData = (MzData)unmarshaller.unmarshal(nodeList.item(0));
+ if(mzData.getSpectrumList().getCount() > 1)
+ isValidFormat = true;
+ } catch(Exception e) {
+ // Print no exception.
+ }
+ return isValidFormat;
+ }
+}
diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MagicNumberMatcher.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MagicNumberMatcher.java
deleted file mode 100644
index c3ee72fe3f..0000000000
--- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MagicNumberMatcher.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016, 2018 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.mzdata.converter;
-
-import java.io.File;
-
-import org.eclipse.chemclipse.converter.core.AbstractMagicNumberMatcher;
-import org.eclipse.chemclipse.converter.core.IMagicNumberMatcher;
-import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.support.SpecificationValidator;
-
-public class MagicNumberMatcher extends AbstractMagicNumberMatcher implements IMagicNumberMatcher {
-
- @Override
- public boolean checkFileFormat(File file) {
-
- boolean isValidFormat = false;
- try {
- file = SpecificationValidator.validateSpecification(file);
- if(file.exists()) {
- return true;
- }
- } catch(Exception e) {
- // Print no exception.
- }
- return isValidFormat;
- }
-}
diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MassSpectrumExportConverter.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MassSpectrumExportConverter.java
new file mode 100644
index 0000000000..6db42f8523
--- /dev/null
+++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MassSpectrumExportConverter.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 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
+ * Matthias Mailänder - adapted for MALDI
+ *******************************************************************************/
+package org.eclipse.chemclipse.msd.converter.supplier.mzdata.converter;
+
+import java.io.File;
+
+import org.eclipse.chemclipse.msd.converter.massspectrum.AbstractMassSpectrumExportConverter;
+import org.eclipse.chemclipse.msd.model.core.IMassSpectra;
+import org.eclipse.chemclipse.msd.model.core.IScanMSD;
+import org.eclipse.chemclipse.processing.core.IProcessingInfo;
+import org.eclipse.chemclipse.processing.core.ProcessingInfo;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class MassSpectrumExportConverter extends AbstractMassSpectrumExportConverter {
+
+ private static final String DESCRIPTION = "mzXML Mass Spectra Export Converter";
+
+ @Override
+ public IProcessingInfo convert(File file, IScanMSD massSpectrum, boolean append, IProgressMonitor monitor) {
+
+ return getProcessingInfo();
+ }
+
+ @Override
+ public IProcessingInfo convert(File file, IMassSpectra massSpectra, boolean append, IProgressMonitor monitor) {
+
+ return getProcessingInfo();
+ }
+
+ private IProcessingInfo getProcessingInfo() {
+
+ IProcessingInfo processingInfo = new ProcessingInfo();
+ processingInfo.addErrorMessage(DESCRIPTION, "It's not possible to export mass spectrum data as mzXML yet.");
+ return processingInfo;
+ }
+}
diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MassSpectrumImportConverter.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MassSpectrumImportConverter.java
new file mode 100644
index 0000000000..2acbea2ea3
--- /dev/null
+++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MassSpectrumImportConverter.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 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
+ * Christoph Läubrich - add generics
+ * Matthias Mailänder - adapted for MALDI
+ *******************************************************************************/
+package org.eclipse.chemclipse.msd.converter.supplier.mzdata.converter;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.eclipse.chemclipse.converter.exceptions.FileIsEmptyException;
+import org.eclipse.chemclipse.converter.exceptions.FileIsNotReadableException;
+import org.eclipse.chemclipse.logging.core.Logger;
+import org.eclipse.chemclipse.msd.converter.io.IMassSpectraReader;
+import org.eclipse.chemclipse.msd.converter.massspectrum.AbstractMassSpectrumImportConverter;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.support.SpecificationValidator;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.io.MassSpectrumReader;
+import org.eclipse.chemclipse.msd.model.core.IMassSpectra;
+import org.eclipse.chemclipse.processing.core.IProcessingInfo;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class MassSpectrumImportConverter extends AbstractMassSpectrumImportConverter {
+
+ private static final Logger logger = Logger.getLogger(MassSpectrumImportConverter.class);
+ private static final String DESCRIPTION = "mzData Mass Spectrum Import";
+
+ @Override
+ public IProcessingInfo convert(File file, IProgressMonitor monitor) {
+
+ IProcessingInfo processingInfo = super.validate(file);
+ if(!processingInfo.hasErrorMessages()) {
+ try {
+ file = SpecificationValidator.validateSpecification(file);
+ IMassSpectraReader massSpectraReader = new MassSpectrumReader();
+ IMassSpectra massSpectra = massSpectraReader.read(file, monitor);
+ if(massSpectra != null && massSpectra.size() > 0) {
+ processingInfo.setProcessingResult(massSpectra);
+ } else {
+ processingInfo.addErrorMessage(DESCRIPTION, "No mass spectra are stored." + file.getAbsolutePath());
+ }
+ } catch(FileNotFoundException e) {
+ logger.warn(e);
+ processingInfo.addErrorMessage(DESCRIPTION, "The file couldn't be found: " + file.getAbsolutePath());
+ } catch(FileIsNotReadableException e) {
+ logger.warn(e);
+ processingInfo.addErrorMessage(DESCRIPTION, "The file is not readable: " + file.getAbsolutePath());
+ } catch(FileIsEmptyException e) {
+ logger.warn(e);
+ processingInfo.addErrorMessage(DESCRIPTION, "The file is empty: " + file.getAbsolutePath());
+ } catch(IOException e) {
+ logger.warn(e);
+ processingInfo.addErrorMessage(DESCRIPTION, "Something has gone completely wrong: " + file.getAbsolutePath());
+ }
+ }
+ return processingInfo;
+ }
+}
diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MassSpectrumMagicNumberMatcher.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MassSpectrumMagicNumberMatcher.java
new file mode 100644
index 0000000000..26e57e5bce
--- /dev/null
+++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MassSpectrumMagicNumberMatcher.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2016, 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
+ * Matthias Mailänder - auto detection for MALDI files
+ *******************************************************************************/
+package org.eclipse.chemclipse.msd.converter.supplier.mzdata.converter;
+
+import java.io.File;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.eclipse.chemclipse.converter.core.AbstractMagicNumberMatcher;
+import org.eclipse.chemclipse.converter.core.IMagicNumberMatcher;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.io.IFormat;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.support.IConstants;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.support.SpecificationValidator;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.v105.model.MzData;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+public class MassSpectrumMagicNumberMatcher extends AbstractMagicNumberMatcher implements IMagicNumberMatcher {
+
+ @Override
+ public boolean checkFileFormat(File file) {
+
+ boolean isValidFormat = false;
+ try {
+ file = SpecificationValidator.validateSpecification(file);
+ if(!file.exists()) {
+ return isValidFormat;
+ }
+ if(!checkFileExtension(file, ".mzdata")) {
+ return isValidFormat;
+ }
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+ Document document = documentBuilder.parse(file);
+ NodeList nodeList = document.getElementsByTagName(IConstants.NODE_MZ_DATA);
+ //
+ JAXBContext jaxbContext = JAXBContext.newInstance(IFormat.CONTEXT_PATH_V_105);
+ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+ MzData mzData = (MzData)unmarshaller.unmarshal(nodeList.item(0));
+ if(mzData.getSpectrumList().getCount() == 1)
+ isValidFormat = true;
+ } catch(Exception e) {
+ // Print no exception.
+ }
+ return isValidFormat;
+ }
+}
diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/internal/io/ChromatogramReaderVersion105.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/internal/io/ChromatogramReaderVersion105.java
index 562a77e0b6..886b17d007 100644
--- a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/internal/io/ChromatogramReaderVersion105.java
+++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/internal/io/ChromatogramReaderVersion105.java
@@ -14,10 +14,6 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.DoubleBuffer;
-import java.nio.FloatBuffer;
import java.util.List;
import javax.xml.bind.JAXBContext;
@@ -36,7 +32,6 @@
import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.v105.model.CvParamType;
import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.v105.model.MzData;
import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.v105.model.MzData.SpectrumList.Spectrum;
-import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.v105.model.SupDataBinaryType.Data;
import org.eclipse.chemclipse.msd.converter.supplier.mzdata.io.AbstractChromatogramReader;
import org.eclipse.chemclipse.msd.converter.supplier.mzdata.model.IVendorChromatogram;
import org.eclipse.chemclipse.msd.converter.supplier.mzdata.model.IVendorIon;
@@ -97,8 +92,8 @@ public IChromatogramMSD read(File file, IProgressMonitor monitor) throws FileNot
/*
* Get the ions.
*/
- double[] mz = parseData(spectrum.getMzArrayBinary().getData());
- double[] intensities = parseData(spectrum.getIntenArrayBinary().getData());
+ double[] mz = ReaderVersion105.parseData(spectrum.getMzArrayBinary().getData());
+ double[] intensities = ReaderVersion105.parseData(spectrum.getIntenArrayBinary().getData());
int length = Math.min(mz.length, intensities.length);
for(int index = 0; index < length; index++) {
float intensity = (float)intensities[index];
@@ -127,37 +122,4 @@ public IChromatogramMSD read(File file, IProgressMonitor monitor) throws FileNot
chromatogram.setFile(file);
return chromatogram;
}
-
- double[] parseData(Data data) {
-
- double[] values = new double[0];
- ByteBuffer byteBuffer = ByteBuffer.wrap(data.getValue());
- /*
- * Byte Order
- */
- String endian = data.getEndian();
- if(endian != null && endian.equals("big")) {
- byteBuffer.order(ByteOrder.BIG_ENDIAN);
- } else {
- byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
- }
- /*
- * Data Type
- */
- int precision = data.getPrecision();
- if(precision == 64) {
- DoubleBuffer doubleBuffer = byteBuffer.asDoubleBuffer();
- values = new double[doubleBuffer.capacity()];
- for(int index = 0; index < doubleBuffer.capacity(); index++) {
- values[index] = new Double(doubleBuffer.get(index));
- }
- } else if(precision == 32) {
- FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
- values = new double[floatBuffer.capacity()];
- for(int index = 0; index < floatBuffer.capacity(); index++) {
- values[index] = new Double(floatBuffer.get(index));
- }
- }
- return values;
- }
}
diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/internal/io/MassSpectrumReaderVersion105.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/internal/io/MassSpectrumReaderVersion105.java
new file mode 100644
index 0000000000..1f410c92ad
--- /dev/null
+++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/internal/io/MassSpectrumReaderVersion105.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * 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.mzdata.internal.io;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.chemclipse.converter.exceptions.FileIsEmptyException;
+import org.eclipse.chemclipse.converter.exceptions.FileIsNotReadableException;
+import org.eclipse.chemclipse.logging.core.Logger;
+import org.eclipse.chemclipse.model.exceptions.AbundanceLimitExceededException;
+import org.eclipse.chemclipse.msd.converter.io.AbstractMassSpectraReader;
+import org.eclipse.chemclipse.msd.converter.io.IMassSpectraReader;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.support.IConstants;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.v105.model.CvParamType;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.v105.model.MzData;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.v105.model.MzData.SpectrumList.Spectrum;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.v105.model.ParamType;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.model.IVendorIon;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.model.IVendorMassSpectra;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.model.VendorIon;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.model.VendorMassSpectra;
+import org.eclipse.chemclipse.msd.model.core.AbstractIon;
+import org.eclipse.chemclipse.msd.model.core.IMassSpectra;
+import org.eclipse.chemclipse.msd.model.core.IVendorMassSpectrum;
+import org.eclipse.chemclipse.msd.model.exceptions.IonLimitExceededException;
+import org.eclipse.chemclipse.msd.model.implementation.VendorMassSpectrum;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+public class MassSpectrumReaderVersion105 extends AbstractMassSpectraReader implements IMassSpectraReader {
+
+ private static final Logger logger = Logger.getLogger(MassSpectrumReaderVersion105.class);
+ private String contextPath;
+
+ public MassSpectrumReaderVersion105(String contextPath) {
+
+ this.contextPath = contextPath;
+ }
+
+ @Override
+ public IMassSpectra read(File file, IProgressMonitor monitor) throws FileNotFoundException, FileIsNotReadableException, FileIsEmptyException, IOException {
+
+ IVendorMassSpectrum massSpectrum = null;
+ //
+ try {
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+ Document document = documentBuilder.parse(file);
+ NodeList nodeList = document.getElementsByTagName(IConstants.NODE_MZ_DATA);
+ //
+ JAXBContext jaxbContext = JAXBContext.newInstance(contextPath);
+ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+ MzData mzData = (MzData)unmarshaller.unmarshal(nodeList.item(0));
+ //
+ massSpectrum = new VendorMassSpectrum();
+ massSpectrum.setFile(file);
+ massSpectrum.setIdentifier(file.getName());
+ ParamType processingMethod = mzData.getDescription().getDataProcessing().getProcessingMethod();
+ if(processingMethod != null) {
+ for(Object object : processingMethod.getCvParamOrUserParam()) {
+ if(object instanceof CvParamType) {
+ CvParamType cvParamType = (CvParamType)object;
+ if(cvParamType.getName().equals("peakProcessing")) {
+ massSpectrum.setMassSpectrumType((short)(cvParamType.getValue().equals("centroided") ? 0 : 1));
+ }
+ }
+ }
+ }
+ Spectrum spectrum = mzData.getSpectrumList().getSpectrum().get(0);
+ double[] mzs = ReaderVersion105.parseData(spectrum.getMzArrayBinary().getData());
+ double[] intensities = ReaderVersion105.parseData(spectrum.getIntenArrayBinary().getData());
+ int length = Math.min(mzs.length, intensities.length);
+ for(int i = 0; i < length; i++) {
+ double mz = AbstractIon.getIon(mzs[i]);
+ float intensity = (float)intensities[i];
+ try {
+ if(intensity >= VendorIon.MIN_ABUNDANCE && intensity <= VendorIon.MAX_ABUNDANCE) {
+ IVendorIon ion = new VendorIon(mz, intensity);
+ massSpectrum.addIon(ion);
+ }
+ } catch(AbundanceLimitExceededException e) {
+ logger.warn(e);
+ } catch(IonLimitExceededException e) {
+ logger.warn(e);
+ }
+ }
+ } catch(SAXException e) {
+ logger.warn(e);
+ } catch(JAXBException e) {
+ logger.warn(e);
+ } catch(ParserConfigurationException e) {
+ logger.warn(e);
+ }
+ //
+ IVendorMassSpectra massSpectra = new VendorMassSpectra();
+ massSpectra.setName(file.getName());
+ massSpectra.addMassSpectrum(massSpectrum);
+ return massSpectra;
+ }
+}
diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/internal/io/ReaderVersion105.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/internal/io/ReaderVersion105.java
new file mode 100644
index 0000000000..8de0457ae3
--- /dev/null
+++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/internal/io/ReaderVersion105.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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.mzdata.internal.io;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.DoubleBuffer;
+import java.nio.FloatBuffer;
+
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.v105.model.SupDataBinaryType.Data;
+
+public class ReaderVersion105 {
+
+ public static double[] parseData(Data data) {
+
+ double[] values = new double[0];
+ ByteBuffer byteBuffer = ByteBuffer.wrap(data.getValue());
+ /*
+ * Byte Order
+ */
+ String endian = data.getEndian();
+ if(endian != null && endian.equals("big")) {
+ byteBuffer.order(ByteOrder.BIG_ENDIAN);
+ } else {
+ byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
+ }
+ /*
+ * Data Type
+ */
+ int precision = data.getPrecision();
+ if(precision == 64) {
+ DoubleBuffer doubleBuffer = byteBuffer.asDoubleBuffer();
+ values = new double[doubleBuffer.capacity()];
+ for(int index = 0; index < doubleBuffer.capacity(); index++) {
+ values[index] = new Double(doubleBuffer.get(index));
+ }
+ } else if(precision == 32) {
+ FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
+ values = new double[floatBuffer.capacity()];
+ for(int index = 0; index < floatBuffer.capacity(); index++) {
+ values[index] = new Double(floatBuffer.get(index));
+ }
+ }
+ return values;
+ }
+}
diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/io/MassSpectrumReader.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/io/MassSpectrumReader.java
new file mode 100644
index 0000000000..ae4e2c12f4
--- /dev/null
+++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/io/MassSpectrumReader.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 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
+ * Matthias Mailänder - adapted for MALDI
+ *******************************************************************************/
+package org.eclipse.chemclipse.msd.converter.supplier.mzdata.io;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.eclipse.chemclipse.converter.exceptions.FileIsEmptyException;
+import org.eclipse.chemclipse.converter.exceptions.FileIsNotReadableException;
+import org.eclipse.chemclipse.msd.converter.io.AbstractMassSpectraReader;
+import org.eclipse.chemclipse.msd.converter.io.IMassSpectraReader;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.io.IFormat;
+import org.eclipse.chemclipse.msd.converter.supplier.mzdata.internal.io.MassSpectrumReaderVersion105;
+import org.eclipse.chemclipse.msd.model.core.IMassSpectra;
+import org.eclipse.chemclipse.xxd.converter.supplier.io.exception.UnknownVersionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class MassSpectrumReader extends AbstractMassSpectraReader implements IMassSpectraReader {
+
+ @Override
+ public IMassSpectra read(File file, IProgressMonitor monitor) throws FileNotFoundException, FileIsNotReadableException, FileIsEmptyException, IOException {
+
+ final IMassSpectraReader massSpectraReader = getReader(file);
+ if(massSpectraReader != null) {
+ return massSpectraReader.read(file, monitor);
+ } else {
+ return null;
+ }
+ }
+
+ public static IMassSpectraReader getReader(final File file) throws IOException {
+
+ IMassSpectraReader massSpectraReader = null;
+ //
+ final FileReader fileReader = new FileReader(file);
+ final char[] charBuffer = new char[350];
+ fileReader.read(charBuffer);
+ fileReader.close();
+ //
+ final String header = new String(charBuffer);
+ if(header.contains(IFormat.V_105)) {
+ massSpectraReader = new MassSpectrumReaderVersion105(IFormat.CONTEXT_PATH_V_105);
+ } else {
+ throw new UnknownVersionException();
+ }
+ //
+ return massSpectraReader;
+ }
+}
diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/io/MassSpectrumWriter.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/io/MassSpectrumWriter.java
new file mode 100644
index 0000000000..94bd771515
--- /dev/null
+++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/io/MassSpectrumWriter.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 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.mzdata.io;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.eclipse.chemclipse.converter.exceptions.FileIsNotWriteableException;
+import org.eclipse.chemclipse.msd.converter.io.IMassSpectraWriter;
+import org.eclipse.chemclipse.msd.model.core.IMassSpectra;
+import org.eclipse.chemclipse.msd.model.core.IScanMSD;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class MassSpectrumWriter implements IMassSpectraWriter {
+
+ @Override
+ public void write(File file, IScanMSD massSpectrum, boolean append, IProgressMonitor monitor) throws FileNotFoundException, FileIsNotWriteableException, IOException {
+
+ }
+
+ @Override
+ public void write(File file, IMassSpectra massSpectra, boolean append, IProgressMonitor monitor) throws FileNotFoundException, FileIsNotWriteableException, IOException {
+
+ }
+
+ @Override
+ public void writeMassSpectrum(FileWriter fileWriter, IScanMSD massSpectrum, IProgressMonitor monitor) throws IOException {
+
+ }
+}
diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/model/IVendorMassSpectra.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/model/IVendorMassSpectra.java
new file mode 100644
index 0000000000..ec5d3c56a2
--- /dev/null
+++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/model/IVendorMassSpectra.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 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.mzdata.model;
+
+import org.eclipse.chemclipse.msd.model.core.IMassSpectra;
+
+public interface IVendorMassSpectra extends IMassSpectra {
+}
diff --git a/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/model/VendorMassSpectra.java b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/model/VendorMassSpectra.java
new file mode 100644
index 0000000000..a8bb0a5d44
--- /dev/null
+++ b/chemclipse/plugins/org.eclipse.chemclipse.msd.converter.supplier.mzdata/src/org/eclipse/chemclipse/msd/converter/supplier/mzdata/model/VendorMassSpectra.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 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.mzdata.model;
+
+import org.eclipse.chemclipse.msd.model.core.AbstractMassSpectra;
+import org.eclipse.chemclipse.msd.model.core.IScanMSD;
+import org.eclipse.chemclipse.msd.model.core.IVendorMassSpectrum;
+
+public class VendorMassSpectra extends AbstractMassSpectra implements IVendorMassSpectra {
+
+ @Override
+ public String getName() {
+
+ IScanMSD scanMSD = this.getMassSpectrum(1);
+ if(scanMSD instanceof IVendorMassSpectrum) {
+ return ((IVendorMassSpectrum)scanMSD).getName();
+ } else {
+ return super.getName();
+ }
+ }
+}