Skip to content

Commit

Permalink
Merge pull request #648 from Mailaender/mzdata-maldi
Browse files Browse the repository at this point in the history
Added support for .mzData MALDI files
  • Loading branch information
eselmeister authored Jun 22, 2021
2 parents 0fec756 + c7ac6d7 commit 172f804
Show file tree
Hide file tree
Showing 13 changed files with 574 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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">
</ChromatogramSupplier>
</extension>
<extension
point="org.eclipse.chemclipse.msd.converter.massSpectrumSupplier">
<MassSpectrumSupplier
description="Reads mzData Spectra"
exportConverter="org.eclipse.chemclipse.msd.converter.supplier.mzdata.converter.MassSpectrumExportConverter"
fileExtension=".mzData"
filterName="Mass Spectrum (*.mzData)"
id="org.eclipse.chemclipse.msd.converter.supplier.mzdata.MassSpectrumSupplier"
importConverter="org.eclipse.chemclipse.msd.converter.supplier.mzdata.converter.MassSpectrumImportConverter"
importMagicNumberMatcher="org.eclipse.chemclipse.msd.converter.supplier.mzdata.converter.MassSpectrumMagicNumberMatcher"
isExportable="false"
isImportable="true">
</MassSpectrumSupplier>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<IMassSpectra> convert(File file, IScanMSD massSpectrum, boolean append, IProgressMonitor monitor) {

return getProcessingInfo();
}

@Override
public IProcessingInfo<IMassSpectra> convert(File file, IMassSpectra massSpectra, boolean append, IProgressMonitor monitor) {

return getProcessingInfo();
}

private IProcessingInfo<IMassSpectra> getProcessingInfo() {

IProcessingInfo<IMassSpectra> processingInfo = new ProcessingInfo<IMassSpectra>();
processingInfo.addErrorMessage(DESCRIPTION, "It's not possible to export mass spectrum data as mzXML yet.");
return processingInfo;
}
}
Original file line number Diff line number Diff line change
@@ -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<IMassSpectra> convert(File file, IProgressMonitor monitor) {

IProcessingInfo<IMassSpectra> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
}
Loading

0 comments on commit 172f804

Please sign in to comment.