Skip to content

Commit

Permalink
Translate the options available in MSD to WSD.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Oct 26, 2021
1 parent 5f07181 commit 750310b
Show file tree
Hide file tree
Showing 11 changed files with 578 additions and 90 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,34 @@
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Matthias Mailänder - remove the window size enum
* Matthias Mailänder - add wavelength filters
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.firstderivative.settings;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.chemclipse.chromatogram.peak.detector.core.FilterMode;
import org.eclipse.chemclipse.chromatogram.peak.detector.model.Threshold;
import org.eclipse.chemclipse.chromatogram.wsd.peak.detector.settings.AbstractPeakDetectorWSDSettings;
import org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.firstderivative.preferences.PreferenceSupplier;
import org.eclipse.chemclipse.support.settings.FloatSettingsProperty;
import org.eclipse.chemclipse.support.settings.IntSettingsProperty;
import org.eclipse.chemclipse.support.settings.IntSettingsProperty.Validation;
import org.eclipse.chemclipse.support.settings.serialization.WindowSizeDeserializer;
import org.eclipse.chemclipse.wsd.model.core.support.IMarkedWavelength;
import org.eclipse.chemclipse.wsd.model.core.support.IMarkedWavelength.WavelengthMarkMode;
import org.eclipse.chemclipse.wsd.model.core.support.IMarkedWavelengths;
import org.eclipse.chemclipse.wsd.model.core.support.MarkedWavelength;
import org.eclipse.chemclipse.wsd.model.core.support.MarkedWavelengths;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand All @@ -39,6 +56,18 @@ public class PeakDetectorSettingsWSD extends AbstractPeakDetectorWSDSettings {
@IntSettingsProperty(minValue = PreferenceSupplier.MIN_WINDOW_SIZE, maxValue = PreferenceSupplier.MAX_WINDOW_SIZE, validation = Validation.ODD_NUMBER_INCLUDING_ZERO)
@JsonDeserialize(using = WindowSizeDeserializer.class)
private int windowSize;
@JsonProperty(value = "Use Noise-Segments", defaultValue = "false")
@JsonPropertyDescription(value = "Whether to use noise segments to decide where peaks should be detected. This can improve the sensitivity of the algorithm.")
private boolean useNoiseSegments = false;
@JsonProperty(value = "Filter Mode", defaultValue = "EXCLUDE")
private FilterMode filterMode = FilterMode.EXCLUDE;
@JsonProperty(value = "Wavelengths to filter", defaultValue = "")
private String filterWavelengths;
@JsonProperty(value = "Use Individual Wavelengths", defaultValue = "false")
@JsonPropertyDescription("Uses each wavelength in the filter-list individualy to detect peaks")
private boolean useIndividualWavelengths = false;
@JsonProperty(value = "Optimize Baseline (VV)", defaultValue = "false")
private boolean optimizeBaseline = false;

public PeakDetectorSettingsWSD() {

Expand Down Expand Up @@ -86,4 +115,91 @@ public void setMovingAverageWindowSize(int windowSize) {

this.windowSize = windowSize;
}

public boolean isUseNoiseSegments() {

return useNoiseSegments;
}

public void setUseNoiseSegments(boolean useNoiseSegments) {

this.useNoiseSegments = useNoiseSegments;
}

public FilterMode getFilterMode() {

return filterMode == null ? FilterMode.EXCLUDE : filterMode;
}

public void setFilterMode(FilterMode filterMode) {

this.filterMode = filterMode;
}

static Collection<Number> parseWavelengths(String input) {

if(StringUtils.isBlank(input)) {
return Collections.emptyList();
}
List<Number> waveLengths = new ArrayList<>();
String[] split = input.trim().split("[\\s.,;]+");
for(String s : split) {
try {
waveLengths.add(new BigDecimal(s));
} catch(NumberFormatException e) {
// invalid or empty string
}
}
return waveLengths;
}

public boolean isIndividualWavelengths() {

return useIndividualWavelengths;
}

public void setUseIndividualTraces(boolean useIndividualWavelengths) {

this.useIndividualWavelengths = useIndividualWavelengths;
}

@JsonIgnore
public Collection<IMarkedWavelengths> getFilterWavelengths() {

WavelengthMarkMode wavelengthMarkMode;
switch(getFilterMode()) {
case EXCLUDE:
wavelengthMarkMode = WavelengthMarkMode.INCLUDE;
break;
case INCLUDE:
wavelengthMarkMode = WavelengthMarkMode.EXCLUDE;
break;
default:
throw new IllegalArgumentException("Unsupported filter mode " + getFilterMode());
}
Set<IMarkedWavelength> parsedWavelengths = parseWavelengths(filterWavelengths).stream().map(e -> new MarkedWavelength(e.doubleValue())).collect(Collectors.toSet());
if(isIndividualWavelengths()) {
List<IMarkedWavelengths> listedWavelengths = new ArrayList<>();
for(IMarkedWavelength wavelength : parsedWavelengths) {
IMarkedWavelengths markedWavelengths = new MarkedWavelengths(wavelengthMarkMode);
markedWavelengths.add(wavelength);
listedWavelengths.add(markedWavelengths);
}
return listedWavelengths;
} else {
IMarkedWavelengths markedWavelengths = new MarkedWavelengths(wavelengthMarkMode);
markedWavelengths.addAll(parsedWavelengths);
return Collections.singleton(markedWavelengths);
}
}

public boolean isOptimizeBaseline() {

return optimizeBaseline;
}

public void setOptimizeBaseline(boolean optimizeBaseline) {

this.optimizeBaseline = optimizeBaseline;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand All @@ -22,6 +23,7 @@
import org.eclipse.chemclipse.wsd.model.comparator.WavelengthCombinedComparator;
import org.eclipse.chemclipse.wsd.model.comparator.WavelengthComparatorMode;
import org.eclipse.chemclipse.wsd.model.core.implementation.ScanSignalWSD;
import org.eclipse.chemclipse.wsd.model.core.support.IMarkedWavelengths;
import org.eclipse.chemclipse.wsd.model.xwc.ExtractedSingleWavelengthSignal;
import org.eclipse.chemclipse.wsd.model.xwc.ExtractedWavelengthSignal;
import org.eclipse.chemclipse.wsd.model.xwc.IExtractedSingleWavelengthSignal;
Expand Down Expand Up @@ -135,6 +137,40 @@ public float getTotalSignal() {
return totalSignal;
}

@Override
public float getTotalSignal(IMarkedWavelengths markedWavelengths) {

float totalSignal = 0;
/*
* If the excluded ions are null, return the total signal.
*/
if(markedWavelengths == null || markedWavelengths.isEmpty()) {
totalSignal = getTotalSignal();
} else {
Iterator<IScanSignalWSD> iterator = scanSignals.iterator();
while(iterator.hasNext()) {
IScanSignalWSD scan = iterator.next();
if(useWavelength(scan, markedWavelengths)) {
totalSignal += scan.getAbundance();
}
}
}
return totalSignal;
}

private static boolean useWavelength(IScanSignalWSD scan, IMarkedWavelengths filterWavelengths) {

Set<Double> wavelengths = filterWavelengths.getWavelengths();
switch(filterWavelengths.getMode()) {
case EXCLUDE:
return wavelengths.contains(scan.getWavelength());
case INCLUDE:
return !wavelengths.contains(scan.getWavelength());
default:
return true;
}
}

@Override
public void adjustTotalSignal(float totalSignal) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Matthias Mailänder - add total signal except excluded
*******************************************************************************/
package org.eclipse.chemclipse.wsd.model.core;

Expand All @@ -16,6 +17,7 @@
import java.util.Set;

import org.eclipse.chemclipse.model.core.IScan;
import org.eclipse.chemclipse.wsd.model.core.support.IMarkedWavelengths;
import org.eclipse.chemclipse.wsd.model.xwc.IExtractedSingleWavelengthSignal;
import org.eclipse.chemclipse.wsd.model.xwc.IExtractedWavelengthSignal;

Expand Down Expand Up @@ -47,11 +49,17 @@ public interface IScanWSD extends IScan {

IExtractedWavelengthSignal getExtractedWavelengthSignal();

IExtractedWavelengthSignal getExtractedWavelengthSignal(double startIon, double stopIon);
IExtractedWavelengthSignal getExtractedWavelengthSignal(double startWavelength, double stopWavelength);

Optional<IExtractedSingleWavelengthSignal> getExtractedSingleWavelengthSignal(double wavelength);

boolean hasScanSignals();

IWavelengthBounds getWavelengthBounds();

/**
*
* @return total intensity count (TIC) excepted excluded wavelengths
*/
float getTotalSignal(IMarkedWavelengths excludedWavelenths);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Iterator;
import java.util.Set;

public class AbstractMarkedWavelengths implements IMarkedWavelengths {
public abstract class AbstractMarkedWavelengths implements IMarkedWavelengths {

private Set<IMarkedWavelength> markedWavelengths;

Expand All @@ -25,6 +25,16 @@ public AbstractMarkedWavelengths() {
markedWavelengths = new HashSet<>();
}

protected AbstractMarkedWavelengths(Collection<? extends Number> wavelengths) {

markedWavelengths = new HashSet<>();
if(wavelengths != null) {
for(Number wavelength : wavelengths) {
markedWavelengths.add(new MarkedWavelength(wavelength.intValue()));
}
}
}

@Override
public boolean add(IMarkedWavelength e) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2018 Lablicate GmbH.
* Copyright (c) 2016, 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 @@ -12,9 +12,40 @@
package org.eclipse.chemclipse.wsd.model.core.support;

import org.eclipse.chemclipse.model.core.IMarkedSignal;
import org.eclipse.chemclipse.support.text.ILabel;

public interface IMarkedWavelength extends IMarkedSignal {

enum WavelengthMarkMode implements ILabel {

/**
* In this mode, all wavelengths in the list are considered as an exclusion, that means apply the given function to all except the given wavelengths
*/
EXCLUDE("Exclude"),
/**
* In this mode, all wavelengths in the list are considered as an inclusion, that means apply the given function to all wavelengths given
*/
INCLUDE("Include");

private String label = "";

private WavelengthMarkMode(String label) {

this.label = label;
}

@Override
public String label() {

return label;
}

public static String[][] getOptions() {

return ILabel.getOptions(values());
}
}

double getWavelength();

void setWavelength(double wavelength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Set;

import org.eclipse.chemclipse.model.core.IMarkedSignals;
import org.eclipse.chemclipse.wsd.model.core.support.IMarkedWavelength.WavelengthMarkMode;

public interface IMarkedWavelengths extends IMarkedSignals<IMarkedWavelength> {

Expand Down Expand Up @@ -43,4 +44,6 @@ public interface IMarkedWavelengths extends IMarkedSignals<IMarkedWavelength> {
*/
@Deprecated
void add(int wavelengthStart, int wavelengthStop);

WavelengthMarkMode getMode();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2018 Lablicate GmbH.
* Copyright (c) 2016, 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,8 +8,36 @@
*
* Contributors:
* Dr. Philip Wenig - initial API and implementation
* Matthias Mailänder - add inclusive/exclusive mode
*******************************************************************************/
package org.eclipse.chemclipse.wsd.model.core.support;

import java.util.Collection;

import org.eclipse.chemclipse.wsd.model.core.support.IMarkedWavelength.WavelengthMarkMode;

public class MarkedWavelengths extends AbstractMarkedWavelengths implements IMarkedWavelengths {

private WavelengthMarkMode mode;

public MarkedWavelengths() {

}

public MarkedWavelengths(WavelengthMarkMode mode) {

this.mode = mode;
}

public MarkedWavelengths(Collection<? extends Number> wavelengths, WavelengthMarkMode mode) {

super(wavelengths);
this.mode = mode;
}

@Override
public WavelengthMarkMode getMode() {

return mode;
}
}
Loading

0 comments on commit 750310b

Please sign in to comment.