diff --git a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.baselinesubtract/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/baselinesubtract/core/ChromatogramSubtractor.java b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.baselinesubtract/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/baselinesubtract/core/ChromatogramSubtractor.java index 08d2c17f46..386c953aae 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.baselinesubtract/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/baselinesubtract/core/ChromatogramSubtractor.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.baselinesubtract/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/baselinesubtract/core/ChromatogramSubtractor.java @@ -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 @@ -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) { @@ -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) { @@ -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 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 ions = scanMasterMSD.getIons(); + List 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)); + } + } + } }