Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ion transitions to mz5 and fix MSn display #564

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ private void readScanProxies(IHDF5SimpleReader reader, CVReference[] cvReference
int[] retentionTimes = new int[spectrumIndex.length];
String[] spectrumTitles = new String[spectrumIndex.length];
short[] msLevels = new short[spectrumIndex.length];
double[] selectedIon = new double[spectrumIndex.length];
int p = 0;
for(CVParam cvParam : cvParams) {
if(cvParam.cvRefID == getScanStartTimeReference(cvReferences)) {
Expand All @@ -136,11 +137,15 @@ private void readScanProxies(IHDF5SimpleReader reader, CVReference[] cvReference
if(cvParam.cvRefID == getMassSpectrumLevelReference(cvReferences)) {
msLevels[p] = Short.parseShort(cvParam.value);
}
if(cvParam.cvRefID == getSelectedIonReference(cvReferences)) {
selectedIon[p] = Double.parseDouble(cvParam.value);
}
}
try {
double[] mzs = reader.readDoubleArray(Mz5.SPECTRUM_MZ);
float[] spectrumIntensity = reader.readFloatArray(Mz5.SPECTRUM_INTENSITY);
int start = 0;
int cycleNumber = isMultiStageMassSpectrum(cvParams, cvReferences) ? 1 : 0;
for(int i = 0; i < spectrumIndex.length; i++) {
int offset = spectrumIndex[i];
IScanMarker scanMarker = new ScanMarker(start, offset);
Expand All @@ -149,6 +154,14 @@ private void readScanProxies(IHDF5SimpleReader reader, CVReference[] cvReference
scanProxy.setIdentifier(spectrumTitles[i]);
scanProxy.setRetentionTime(retentionTimes[i]);
scanProxy.setMassSpectrometer(msLevels[i]);
if(scanProxy.getMassSpectrometer() < 2) {
cycleNumber++;
} else {
scanProxy.setPrecursorIon(selectedIon[i]);
}
if(cycleNumber >= 1) {
scanProxy.setCycleNumber(cycleNumber);
}
float totalSignal = 0;
for(int o = start; o < offset; o++) {
totalSignal = totalSignal + spectrumIntensity[o];
Expand Down Expand Up @@ -229,4 +242,27 @@ private int getTimeMultiplicator(CVReference unit) {
}
return multiplicator;
}

private boolean isMultiStageMassSpectrum(CVParam[] cvParams, CVReference[] cvReferences) {

for(CVParam cvParam : cvParams) {
if(cvParam.cvRefID == getMassSpectrumLevelReference(cvReferences)) {
if(Short.parseShort(cvParam.value) > 1) {
return true;
}
}
}
return false;
}

private int getSelectedIonReference(CVReference[] cvReferences) {

int selectedIonRef = 0;
for(int c = 0; c < cvReferences.length; c++) {
if(cvReferences[c].accession == 1000744 && cvReferences[c].name.equals("selected ion m/z")) {
selectedIonRef = c;
}
}
return selectedIonRef;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.io.IOException;

import org.eclipse.chemclipse.logging.core.Logger;
import org.eclipse.chemclipse.msd.model.core.IIonTransition;
import org.eclipse.chemclipse.msd.model.implementation.IonTransition;
import org.eclipse.core.runtime.IProgressMonitor;

import net.openchrom.msd.converter.supplier.mz5.io.support.IScanMarker;
Expand All @@ -36,7 +38,13 @@ public void readMassSpectrum(double[] mzs, float[] spectrumIntensity, IScanMarke
for(int o = start; o < offset; o++) {
float intensity = spectrumIntensity[o];
mz += mzs[o]; // first m/z value and then deltas
IVendorIon ion = new VendorIon(mz, intensity);
IVendorIon ion = null;
if(massSpectrum.getPrecursorIon() != 0) {
IIonTransition ionTransition = new IonTransition(massSpectrum.getPrecursorIon(), mz, 0, 1, 1, 0);
ion = new VendorIon(mz, intensity, ionTransition);
} else {
ion = new VendorIon(mz, intensity);
}
massSpectrum.addIon(ion);
}
} catch(OutOfMemoryError e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public IVendorScan makeDeepCopy() throws CloneNotSupportedException {
* Make a deep copy of all ions.
*/
for(IIon ion : getIons()) {
IVendorIon vendorIon = new VendorIon(ion.getIon(), ion.getAbundance());
IVendorIon vendorIon = new VendorIon(ion.getIon(), ion.getAbundance(), ion.getIonTransition());
massSpectrum.addIon(vendorIon);
}
return massSpectrum;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Lablicate GmbH.
* Copyright (c) 2022, 2024 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 @@ -14,13 +14,16 @@
import java.io.File;

import org.eclipse.chemclipse.msd.model.core.IChromatogramMSD;
import org.eclipse.chemclipse.msd.model.core.IIon;
import org.eclipse.chemclipse.msd.model.core.IRegularMassSpectrum;
import org.eclipse.chemclipse.processing.core.IProcessingInfo;
import org.eclipse.core.runtime.NullProgressMonitor;

import junit.framework.TestCase;
import net.openchrom.msd.converter.supplier.mz5.PathResolver;
import net.openchrom.msd.converter.supplier.mz5.converter.ChromatogramImportConverter;

import junit.framework.TestCase;

public class ChromatogramImportConverter_ITest extends TestCase {

private IChromatogramMSD chromatogram;
Expand Down Expand Up @@ -49,8 +52,17 @@ public void testLoading() {

public void testScans() {

assertEquals(chromatogram.getNumberOfScans(), 26);
assertEquals(chromatogram.getScan(10).getTotalSignal(), 105525.87f);
assertEquals(chromatogram.getScan(26).getRetentionTime(), 16639);
assertEquals(26, chromatogram.getNumberOfScans());
assertEquals(105525.87f, chromatogram.getScan(10).getTotalSignal());
assertEquals(16639, chromatogram.getScan(26).getRetentionTime());
}

public void testIonTransitions() {

IRegularMassSpectrum massSpectrum = (IRegularMassSpectrum)chromatogram.getScan(3);
assertEquals(367.201873779297, massSpectrum.getPrecursorIon());
IIon ion = massSpectrum.getIons().get(0);
assertEquals(367, ion.getIonTransition().getQ1Ion());
assertEquals(112.1d, ion.getIonTransition().getQ3Ion());
}
}