Skip to content

Commit

Permalink
Add basic metadata for MALDI-TOF MS spectra
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Feb 22, 2022
1 parent 82a5d7f commit 3d00709
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

Expand All @@ -35,8 +38,9 @@
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.core.IVendorStandaloneMassSpectrum;
import org.eclipse.chemclipse.msd.model.exceptions.IonLimitExceededException;
import org.eclipse.chemclipse.msd.model.implementation.VendorMassSpectrum;
import org.eclipse.chemclipse.msd.model.implementation.VendorStandaloneMassSpectrum;
import org.eclipse.core.runtime.IProgressMonitor;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
Expand All @@ -53,11 +57,11 @@ public class MassSpectrumReaderVersion22 extends AbstractMassSpectraReader imple
@Override
public IMassSpectra read(File file, IProgressMonitor monitor) throws IOException {

IVendorMassSpectrum massSpectrum = null;
IVendorStandaloneMassSpectrum massSpectrum = null;
//
try {
//
massSpectrum = new VendorMassSpectrum();
massSpectrum = new VendorStandaloneMassSpectrum();
massSpectrum.setFile(file);
massSpectrum.setIdentifier(file.getName());
massSpectrum.setMassSpectrumType((short)1); // profile
Expand Down Expand Up @@ -96,20 +100,26 @@ private NodeList getTopNode(File file) throws SAXException, IOException, ParserC
return document.getElementsByTagName("mSD");
}

private void readDescription(Element element, IVendorMassSpectrum massSpectrum) {
private void readDescription(Element element, IVendorStandaloneMassSpectrum massSpectrum) {

NodeList descriptionList = element.getElementsByTagName("description");
for(int i = 0; i < descriptionList.getLength(); i++) {
Node node = descriptionList.item(i);
Element description = (Element)node;
massSpectrum.setIdentifier(description.getElementsByTagName("title").item(0).getTextContent());
// TODO store and display
description.getElementsByTagName("date").item(0).getAttributes().getNamedItem("value").getTextContent();
description.getElementsByTagName("operator").item(0).getAttributes().getNamedItem("value").getTextContent();
description.getElementsByTagName("contact").item(0).getAttributes().getNamedItem("value").getTextContent();
description.getElementsByTagName("institution").item(0).getAttributes().getNamedItem("value").getTextContent();
description.getElementsByTagName("instrument").item(0).getAttributes().getNamedItem("value").getTextContent();
description.getElementsByTagName("notes").item(0).getTextContent();
massSpectrum.setSampleName(description.getElementsByTagName("title").item(0).getTextContent());
try {
String date = description.getElementsByTagName("date").item(0).getAttributes().getNamedItem("value").getTextContent();
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.ENGLISH);
massSpectrum.setDate(dateFormat.parse(date));
} catch(ParseException e) {
logger.warn(e);
}
String operator = description.getElementsByTagName("operator").item(0).getAttributes().getNamedItem("value").getTextContent();
String contact = description.getElementsByTagName("contact").item(0).getAttributes().getNamedItem("value").getTextContent();
String institution = description.getElementsByTagName("institution").item(0).getAttributes().getNamedItem("value").getTextContent();
massSpectrum.setOperator(operator + " " + contact + " " + institution);
massSpectrum.setInstrument(description.getElementsByTagName("instrument").item(0).getAttributes().getNamedItem("value").getTextContent());
massSpectrum.setDescription(description.getElementsByTagName("notes").item(0).getTextContent());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*******************************************************************************
* Copyright (c) 2022 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.model.core;

import java.util.Date;

public abstract class AbstractVendorStandaloneMassSpectrum extends AbstractVendorMassSpectrum implements IVendorStandaloneMassSpectrum {

/**
* Renew the serialVersionUID any time you have changed some fields or
* methods.
*/
private static final long serialVersionUID = 7180911179209208597L;
//
private String sample;
private String description;
private String operator;
private Date acquisitionDate;
private String instrument;

@Override
public String getSampleName() {

return sample;
}

@Override
public void setSampleName(String name) {

this.sample = name;
}

@Override
public String getOperator() {

return operator;
}

@Override
public void setOperator(String operator) {

this.operator = operator;
}

@Override
public Date getDate() {

return acquisitionDate;
}

@Override
public void setDate(Date acquisitionDate) {

this.acquisitionDate = acquisitionDate;
}

@Override
public String getInstrument() {

return instrument;
}

@Override
public void setInstrument(String instrument) {

this.instrument = instrument;
}

@Override
public String getDescription() {

return description;
}

@Override
public void setDescription(String description) {

this.description = description;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2022 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.model.core;

import java.util.Date;

/**
* An interface for single MALDI-TOF MS spectra which contain additional metadata.
*
* @author Matthias Mailänder
*/
public interface IVendorStandaloneMassSpectrum extends IVendorMassSpectrum {

String getSampleName();

void setSampleName(String name);

String getDescription();

void setDescription(String description);

String getOperator();

void setOperator(String operator);

Date getDate();

void setDate(Date date);

String getInstrument();

void setInstrument(String instrument);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*******************************************************************************
* Copyright (c) 2008, 2022 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.model.implementation;

import org.eclipse.chemclipse.logging.core.Logger;
import org.eclipse.chemclipse.model.exceptions.AbundanceLimitExceededException;
import org.eclipse.chemclipse.msd.model.core.AbstractVendorStandaloneMassSpectrum;
import org.eclipse.chemclipse.msd.model.core.IIon;
import org.eclipse.chemclipse.msd.model.core.IScanIon;
import org.eclipse.chemclipse.msd.model.core.IVendorMassSpectrum;
import org.eclipse.chemclipse.msd.model.core.IVendorStandaloneMassSpectrum;
import org.eclipse.chemclipse.msd.model.exceptions.IonLimitExceededException;

public class VendorStandaloneMassSpectrum extends AbstractVendorStandaloneMassSpectrum implements IVendorStandaloneMassSpectrum {

/**
* Renew the serialVersionUID any time you have changed some fields or
* methods.
*/
private static final long serialVersionUID = 7540947309609765366L;
private static final Logger logger = Logger.getLogger(VendorStandaloneMassSpectrum.class);
public static final int MAX_IONS = Integer.MAX_VALUE;

@Override
public int getMaxPossibleIons() {

return MAX_IONS;
}

@Override
public int getMaxPossibleRetentionTime() {

return 0; // TODO: this should move away
}

@Override
public int getMinPossibleRetentionTime() {

return 0; // TODO: this should move away
}

/**
* Keep in mind, it is a covariant return.<br/>
* IMassSpectrum is needed. ISupplierMassSpectrum is a subtype of
* IMassSpectrum.
*/
@Override
public IVendorMassSpectrum makeDeepCopy() throws CloneNotSupportedException {

/*
* The method super.clone() is not used here to avoid removing the mass
* fragments from the mass spectrum and to add freshly created ones
* again.
*/
IVendorMassSpectrum massSpectrum = (IVendorMassSpectrum)super.clone();
IScanIon defaultIon;
/*
* The instance variables have been copied by super.clone();.<br/> The
* ions in the ion list need not to be removed via
* removeAllIons as the method super.clone() has created a new
* list.<br/> It is necessary to fill the list again, as the abstract
* super class does not know each available type of ion.<br/>
* Make a deep copy of all ions.
*/
for(IIon ion : getIons()) {
try {
defaultIon = new ScanIon(ion.getIon(), ion.getAbundance());
massSpectrum.addIon(defaultIon);
} catch(AbundanceLimitExceededException e) {
logger.warn(e);
} catch(IonLimitExceededException e) {
logger.warn(e);
}
}
return massSpectrum;
}

@Override
protected Object clone() throws CloneNotSupportedException {

return makeDeepCopy();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 Lablicate GmbH.
* Copyright (c) 2020, 2022 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 @@ -12,6 +12,8 @@
package org.eclipse.chemclipse.ux.extension.xxd.ui;

import org.eclipse.chemclipse.msd.model.core.IVendorMassSpectrum;
import org.eclipse.chemclipse.msd.model.core.IVendorStandaloneMassSpectrum;
import org.eclipse.chemclipse.support.text.ValueFormat;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
Expand All @@ -32,10 +34,19 @@ public void updateMassSpectrum(IVendorMassSpectrum massSpectrum) {
StringBuilder builder = new StringBuilder();
if(massSpectrum != null) {
addHeaderLine(builder, "Name", massSpectrum.getName());
addHeaderLine(builder, "Type Description", massSpectrum.getMassSpectrumTypeDescription());
addHeaderLine(builder, "Data", massSpectrum.getMassSpectrumTypeDescription());
addHeaderLine(builder, "File", massSpectrum.getFile().getName());
addHeaderLine(builder, "Mass Spectrometer", "MS" + massSpectrum.getMassSpectrometer());
addHeaderLine(builder, "Technique", "MS" + massSpectrum.getMassSpectrometer());
addHeaderLine(builder, "Ions", Integer.toString(massSpectrum.getNumberOfIons()));
if(massSpectrum instanceof IVendorStandaloneMassSpectrum) {
IVendorStandaloneMassSpectrum standaloneMassSpectrum = (IVendorStandaloneMassSpectrum)massSpectrum;
addHeaderLine(builder, "Sample", standaloneMassSpectrum.getSampleName());
addHeaderLine(builder, "Instrument", standaloneMassSpectrum.getInstrument());
addHeaderLine(builder, "Operator", standaloneMassSpectrum.getOperator());
if(standaloneMassSpectrum.getDate() != null) {
addHeaderLine(builder, "Date", ValueFormat.getDateFormatEnglish().format(standaloneMassSpectrum.getDate()));
}
}
}
//
text.setText(builder.toString());
Expand Down

0 comments on commit 3d00709

Please sign in to comment.