Skip to content

Commit

Permalink
Fix #34, #36, #37 (#35)
Browse files Browse the repository at this point in the history
Fix #34, #36, #37, #35
  • Loading branch information
kerner1000 authored and Christoph Läubrich committed Oct 4, 2019
1 parent 6c45162 commit a16b753
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2018 Lablicate GmbH.
* Copyright (c) 2008, 2019 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand All @@ -8,13 +8,34 @@
*
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Dr. Alexander Kerner - implementation
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.msd.peak.detector.settings;

import java.util.Collection;
import java.util.Collections;

import org.eclipse.chemclipse.numeric.statistics.WindowSize;

/**
* THIS IS A TESTCLASS! ONLY USE IT FOR TEST CASES! IT'S NOT FOR PRODUCTIVE USE!
*
* @author eselmeister
*/
public class PeakDetectorSettings extends AbstractPeakDetectorSettingsMSD {

@Override
public WindowSize getMovingAverageWindowSize() {
return WindowSize.WIDTH_15;
}

@Override
public Collection<Number> getFilterIon() {
return Collections.emptyList();
}

@Override
public FilterMode getFilterMode() {
return FilterMode.EXCLUDE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Export-Package: org.eclipse.chemclipse.chromatogram.msd.peak.detector.core,
org.eclipse.chemclipse.chromatogram.msd.peak.detector.settings
Bundle-Vendor: ChemClipse
Import-Package: org.eclipse.chemclipse.model.types,
org.eclipse.chemclipse.numeric.statistics,
org.eclipse.chemclipse.support.settings.parser,
org.osgi.service.component.annotations;version="1.2.0"
Service-Component: OSGI-INF/org.eclipse.chemclipse.chromatogram.msd.peak.detector.core.PeakDetectorMSDProcessTypeSupplier.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,31 @@

import org.eclipse.chemclipse.chromatogram.peak.detector.settings.AbstractPeakDetectorSettings;

public abstract class AbstractPeakDetectorSettingsMSD extends AbstractPeakDetectorSettings implements IPeakDetectorSettingsMSD {
public abstract class AbstractPeakDetectorSettingsMSD extends AbstractPeakDetectorSettings
implements IPeakDetectorSettingsMSD {

private boolean includeBackground = false;
private float minimumSignalToNoiseRatio = 0;

@Override
public boolean isIncludeBackground() {

return includeBackground;
}

public void setIncludeBackground(boolean includeBackground) {

this.includeBackground = includeBackground;
}

@Override
public float getMinimumSignalToNoiseRatio() {

return minimumSignalToNoiseRatio;
}

public void setMinimumSignalToNoiseRatio(float minimumSignalToNoiseRatio) {

this.minimumSignalToNoiseRatio = minimumSignalToNoiseRatio;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,25 @@
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.msd.peak.detector.settings;

import java.util.Collection;

import org.eclipse.chemclipse.chromatogram.peak.detector.settings.IPeakDetectorSettings;
import org.eclipse.chemclipse.numeric.statistics.WindowSize;

public interface IPeakDetectorSettingsMSD extends IPeakDetectorSettings {

enum FilterMode {
INCLUDE, EXCLUDE
}

float getMinimumSignalToNoiseRatio();

boolean isIncludeBackground();

WindowSize getMovingAverageWindowSize();

Collection<Number> getFilterIon();

FilterMode getFilterMode();

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public <T extends IMeasurement> Map<T, PeakList> detectIMeasurementPeaks(Collect
} else {
configuration = globalConfiguration;
}
slopes = PeakDetectorMSD.getFirstDerivativeSlopes(new ChromatogramSelectionMSD((IChromatogramMSD)measurement), configuration.getMovingAverageWindowSize());
slopes = PeakDetectorMSD.getFirstDerivativeSlopes(new ChromatogramSelectionMSD((IChromatogramMSD)measurement), configuration.getMovingAverageWindowSize(), PeakDetectorMSD.getIonFilter(configuration.getFilterIon(), configuration.getFilterMode()));
} else if(measurement instanceof IChromatogramCSD) {
if(globalConfiguration == null) {
configuration = new FirstDerivativePeakDetectorSettings(DataType.CSD);
Expand Down Expand Up @@ -153,6 +153,7 @@ private static final class SignalSlope implements IFirstDerivativeDetectorSlope
private double slope;

public SignalSlope(ISignal signal, ISignal signalNext) {

IPoint p1 = new Point(signal.getX(), signal.getY());
IPoint p2 = new Point(signalNext.getX(), signalNext.getY());
slope = Equations.calculateSlopeAbs(p1, p2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.firstderivative.core;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.eclipse.chemclipse.chromatogram.msd.peak.detector.core.IPeakDetectorMSD;
import org.eclipse.chemclipse.chromatogram.msd.peak.detector.settings.IPeakDetectorSettingsMSD;
import org.eclipse.chemclipse.chromatogram.msd.peak.detector.settings.IPeakDetectorSettingsMSD.FilterMode;
import org.eclipse.chemclipse.chromatogram.peak.detector.exceptions.ValueMustNotBeNullException;
import org.eclipse.chemclipse.chromatogram.peak.detector.support.IRawPeak;
import org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.firstderivative.preferences.PreferenceSupplier;
Expand All @@ -36,6 +39,9 @@
import org.eclipse.chemclipse.msd.model.core.IChromatogramMSD;
import org.eclipse.chemclipse.msd.model.core.IChromatogramPeakMSD;
import org.eclipse.chemclipse.msd.model.core.selection.IChromatogramSelectionMSD;
import org.eclipse.chemclipse.msd.model.core.support.IMarkedIons;
import org.eclipse.chemclipse.msd.model.core.support.IMarkedIons.IonMarkMode;
import org.eclipse.chemclipse.msd.model.core.support.MarkedIons;
import org.eclipse.chemclipse.msd.model.core.support.PeakBuilderMSD;
import org.eclipse.chemclipse.msd.model.xic.ITotalIonSignalExtractor;
import org.eclipse.chemclipse.msd.model.xic.TotalIonSignalExtractor;
Expand Down Expand Up @@ -99,7 +105,7 @@ public IProcessingInfo detect(IChromatogramSelectionMSD chromatogramSelection, I
*/
private void detectPeaks(IChromatogramSelectionMSD chromatogramSelection, PeakDetectorSettingsMSD peakDetectorSettings, IProgressMonitor monitor) {

IFirstDerivativeDetectorSlopes slopes = getFirstDerivativeSlopes(chromatogramSelection, peakDetectorSettings.getMovingAverageWindowSize());
IFirstDerivativeDetectorSlopes slopes = getFirstDerivativeSlopes(chromatogramSelection, peakDetectorSettings.getMovingAverageWindowSize(), getIonFilter(peakDetectorSettings.getFilterIon(), peakDetectorSettings.getFilterMode()));
List<IRawPeak> rawPeaks = getRawPeaks(slopes, peakDetectorSettings.getThreshold(), monitor);
buildAndStorePeaks(rawPeaks, chromatogramSelection.getChromatogramMSD(), peakDetectorSettings);
}
Expand All @@ -111,7 +117,7 @@ private void detectPeaks(IChromatogramSelectionMSD chromatogramSelection, PeakDe
* @param rawPeaks
* @param chromatogram
*/
private void buildAndStorePeaks(List<IRawPeak> rawPeaks, IChromatogramMSD chromatogram, PeakDetectorSettingsMSD peakDetectorSettings) {
private void buildAndStorePeaks(List<IRawPeak> rawPeaks, IChromatogramMSD chromatogram, IPeakDetectorSettingsMSD peakDetectorSettings) {

IChromatogramPeakMSD peak = null;
IScanRange scanRange = null;
Expand Down Expand Up @@ -159,12 +165,12 @@ private void buildAndStorePeaks(List<IRawPeak> rawPeaks, IChromatogramMSD chroma
* @param windowSize
* @return {@link IFirstDerivativeDetectorSlopes}
*/
public static IFirstDerivativeDetectorSlopes getFirstDerivativeSlopes(IChromatogramSelectionMSD chromatogramSelection, WindowSize windowSize) {
public static IFirstDerivativeDetectorSlopes getFirstDerivativeSlopes(IChromatogramSelectionMSD chromatogramSelection, WindowSize movingAverageWindowSize, IMarkedIons filterIons) {

IChromatogramMSD chromatogram = chromatogramSelection.getChromatogramMSD();
try {
ITotalIonSignalExtractor totalIonSignalExtractor = new TotalIonSignalExtractor(chromatogram);
ITotalScanSignals signals = totalIonSignalExtractor.getTotalIonSignals(chromatogramSelection);
ITotalScanSignals signals = totalIonSignalExtractor.getTotalIonSignals(chromatogramSelection, filterIons);
TotalScanSignalsModifier.normalize(signals, NORMALIZATION_BASE);
/*
* Get the start and stop scan of the chromatogram selection.
Expand All @@ -185,22 +191,50 @@ public static IFirstDerivativeDetectorSlopes getFirstDerivativeSlopes(IChromatog
slopes.add(slope);
}
}
slopes.calculateMovingAverage(windowSize);
slopes.calculateMovingAverage(movingAverageWindowSize);
return slopes;
} catch(ChromatogramIsNullException e) {
logger.warn(e);
logger.warn(e.getLocalizedMessage(), e);
return null;
}
}

static IMarkedIons getIonFilter(Collection<Number> filterIons, FilterMode mode) {

MarkedIons result = new MarkedIons(buildIons(filterIons), buildFilterMode(mode));
return result;
}

private static int[] buildIons(Collection<Number> filterIons) {

int[] result = new int[filterIons.size()];
int cnt = 0;
Iterator<Number> it = filterIons.iterator();
while(it.hasNext()) {
result[cnt++] = it.next().intValue();
}
return result;
}

private static IonMarkMode buildFilterMode(FilterMode mode) {

switch(mode) {
case EXCLUDE:
return IonMarkMode.EXCLUDE;
case INCLUDE:
return IonMarkMode.INCLUDE;
}
throw new IllegalArgumentException("Unknown mode " + mode);
}

/**
* Checks that the peak is not null and that it matches
* the min S/N requirements.
*
* @param peak
* @return boolean
*/
private boolean isValidPeak(IChromatogramPeakMSD peak, PeakDetectorSettingsMSD peakDetectorSettings) {
private boolean isValidPeak(IChromatogramPeakMSD peak, IPeakDetectorSettingsMSD peakDetectorSettings) {

if(peak != null && peak.getSignalToNoiseRatio() >= peakDetectorSettings.getMinimumSignalToNoiseRatio()) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.firstderivative.settings;

import org.eclipse.chemclipse.chromatogram.msd.peak.detector.settings.AbstractPeakDetectorSettingsMSD;
import org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.firstderivative.preferences.PreferenceSupplier;
import org.eclipse.chemclipse.model.types.DataType;
import org.eclipse.chemclipse.numeric.statistics.WindowSize;
Expand All @@ -22,7 +21,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;

public class FirstDerivativePeakDetectorSettings extends AbstractPeakDetectorSettingsMSD {
public class FirstDerivativePeakDetectorSettings extends PeakDetectorSettingsMSD {

@JsonProperty(value = "Threshold", defaultValue = "MEDIUM")
@EnumSelectionRadioButtonsSettingProperty
Expand All @@ -36,52 +35,20 @@ public class FirstDerivativePeakDetectorSettings extends AbstractPeakDetectorSet
@JsonPropertyDescription(value = "Window Size: 3, 5, 7, ..., 45")
@EnumSelectionSettingProperty
private WindowSize windowSize = WindowSize.WIDTH_5;
@JsonProperty(value = "IonFilter", defaultValue = "EXCLUDE")
@EnumSelectionRadioButtonsSettingProperty
FilterMode filterMode = FilterMode.EXCLUDE;
@JsonPropertyDescription(value = "Ions to filter: 16, 18, ...")
@JsonProperty
String filterIonsString;

public FirstDerivativePeakDetectorSettings() {

this(DataType.MSD);
}

public FirstDerivativePeakDetectorSettings(DataType dataType) {
// we could load optimized settings depending on datatype here
}

public Threshold getThreshold() {

return threshold;
}

public void setThreshold(Threshold threshold) {

this.threshold = threshold;
}

public boolean isIncludeBackground() {

return includeBackground;
}

public void setIncludeBackground(boolean includeBackground) {

this.includeBackground = includeBackground;
}

public float getMinimumSignalToNoiseRatio() {

return minimumSignalToNoiseRatio;
}

public void setMinimumSignalToNoiseRatio(float minimumSignalToNoiseRatio) {

this.minimumSignalToNoiseRatio = minimumSignalToNoiseRatio;
}

public WindowSize getMovingAverageWindowSize() {

return windowSize;
}

public void setMovingAverageWindowSize(WindowSize windowSize) {

this.windowSize = windowSize;
// we could load optimized settings depending on datatype here
}
}
Loading

0 comments on commit a16b753

Please sign in to comment.