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

fix #677 channel wise subtraction #678

Merged
Merged
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
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Lablicate GmbH.
* Copyright (c) 2019, 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
Expand All @@ -8,15 +8,26 @@
*
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Lorenz Gerber - channel wise subtraction for WSD / MSD
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.baselinesubtract.core;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.chemclipse.model.core.IChromatogram;
import org.eclipse.chemclipse.model.core.IScan;
import org.eclipse.chemclipse.model.exceptions.AbundanceLimitExceededException;
import org.eclipse.chemclipse.msd.model.core.IIon;
import org.eclipse.chemclipse.msd.model.core.IScanMSD;
import org.eclipse.chemclipse.msd.model.exceptions.IonLimitExceededException;
import org.eclipse.chemclipse.wsd.model.core.IScanSignalWSD;
import org.eclipse.chemclipse.wsd.model.core.IScanWSD;

public class ChromatogramSubtractor {

private final static boolean CHANNEL_WISE_SUBTRACTION = true;

public void perform(IChromatogram<?> chromatogramMaster, IChromatogram<?> chromatogramSubtract) {

if(chromatogramMaster != null && chromatogramSubtract != null) {
Expand All @@ -34,7 +45,13 @@ public void perform(IChromatogram<?> chromatogramMaster, IChromatogram<?> chroma
//
for(int i = startScan; i <= stopScan; i++) {
IScan scanMaster = chromatogramMaster.getScan(i);
if(scanMaster != null) {
if(scanMaster instanceof IScanMSD && CHANNEL_WISE_SUBTRACTION) {
IScanMSD scanMasterMSD = (IScanMSD)scanMaster;
subtractMSD(scanMasterMSD, chromatogramSubtract);
} else if(scanMaster instanceof IScanWSD && CHANNEL_WISE_SUBTRACTION) {
IScanWSD scanMasterWSD = (IScanWSD)scanMaster;
subtractWSD(scanMasterWSD, chromatogramSubtract);
} else if(scanMaster != null) {
int scanNumberSubtract = chromatogramSubtract.getScanNumber(scanMaster.getRetentionTime());
IScan scanSubtract = chromatogramSubtract.getScan(scanNumberSubtract);
if(scanSubtract != null) {
Expand All @@ -60,4 +77,55 @@ public void perform(IChromatogram<?> chromatogramMaster, IChromatogram<?> chroma
}
}
}

private void subtractWSD(IScanWSD scanMasterWSD, IChromatogram<?> chromatogramSubtract) {

if(scanMasterWSD != null) {
int scanNumberSubtract = chromatogramSubtract.getScanNumber(scanMasterWSD.getRetentionTime());
IScanWSD scanSubtract = (IScanWSD)chromatogramSubtract.getScan(scanNumberSubtract);
if(scanSubtract != null) {
List<IScanSignalWSD> signals = scanMasterWSD.getScanSignals();
for(IScanSignalWSD signal : signals) {
double wavelength = signal.getWavelength();
IScanSignalWSD subtract = scanSubtract.getScanSignal(wavelength).orElse(null);
if(subtract != null) {
float abundance = signal.getAbundance() - subtract.getAbundance();
signal.setAbundance(abundance);
}
}
}
}
}

private void subtractMSD(IScanMSD scanMasterMSD, IChromatogram<?> chromatogramSubtract) {

if(scanMasterMSD != null) {
int scanNumberSubtract = chromatogramSubtract.getScanNumber(scanMasterMSD.getRetentionTime());
IScanMSD scanSubtract = (IScanMSD)chromatogramSubtract.getScan(scanNumberSubtract);
if(scanSubtract != null) {
List<IIon> ions = scanMasterMSD.getIons();
List<IIon> zeroAbundanceIons = new ArrayList<>();
for(IIon ion : ions) {
double mass = ion.getIon();
IIon subtract;
try {
subtract = scanSubtract.getIon(mass);
if(subtract != null) {
float abundance = ion.getAbundance() - subtract.getAbundance();
if(abundance <= 0.0) {
zeroAbundanceIons.add(ion);
} else {
ion.setAbundance(abundance);
}
}
} catch(AbundanceLimitExceededException e1) {
System.out.println(e1);
} catch(IonLimitExceededException e1) {
System.out.println(e1);
}
}
zeroAbundanceIons.stream().forEach(x -> scanMasterMSD.removeIon(x));
}
}
}
}