-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #648 from Mailaender/mzdata-maldi
Added support for .mzData MALDI files
- Loading branch information
Showing
13 changed files
with
574 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...se/chemclipse/msd/converter/supplier/mzdata/converter/ChromatogramMagicNumberMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
...rc/org/eclipse/chemclipse/msd/converter/supplier/mzdata/converter/MagicNumberMatcher.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...lipse/chemclipse/msd/converter/supplier/mzdata/converter/MassSpectrumExportConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...lipse/chemclipse/msd/converter/supplier/mzdata/converter/MassSpectrumImportConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...se/chemclipse/msd/converter/supplier/mzdata/converter/MassSpectrumMagicNumberMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.