Skip to content

Commit

Permalink
Replace window size enum with validated integer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Sep 14, 2021
1 parent 514316a commit 13bb6f3
Show file tree
Hide file tree
Showing 43 changed files with 376 additions and 290 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2018 Lablicate GmbH.
* Copyright (c) 2011, 2021 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -30,20 +30,20 @@
import org.eclipse.chemclipse.numeric.core.IPoint;
import org.eclipse.chemclipse.numeric.core.Point;
import org.eclipse.chemclipse.numeric.miscellaneous.Evaluation;
import org.eclipse.chemclipse.numeric.statistics.WindowSize;

// TODO JUnit
public class PeakDetectorSupport {

private static float NORMALIZATION_BASE = 100000.0f;
private static int CONSECUTIVE_SCAN_STEPS = 3;
private static WindowSize MOVING_AVERAGE_WINDOW = WindowSize.WIDTH_5;
private static int MOVING_AVERAGE_WINDOW = 5;
private static double threshold = 0.005d;

/**
* This class has only static methods.
*/
private PeakDetectorSupport() {

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2018 Lablicate GmbH.
* Copyright (c) 2011, 2021 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand All @@ -11,12 +11,11 @@
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.msd.filter.supplier.coda.calculator;

import org.eclipse.chemclipse.logging.core.Logger;
import org.eclipse.chemclipse.msd.model.exceptions.NoExtractedIonSignalStoredException;
import org.eclipse.chemclipse.msd.model.xic.IExtractedIonSignal;
import org.eclipse.chemclipse.msd.model.xic.IExtractedIonSignals;
import org.eclipse.chemclipse.logging.core.Logger;
import org.eclipse.chemclipse.numeric.statistics.Calculations;
import org.eclipse.chemclipse.numeric.statistics.WindowSize;

// TODO JUnit
/**
Expand All @@ -32,6 +31,7 @@ public class CodaCalculator {
* Use it a singleton.
*/
private CodaCalculator() {

}

/**
Expand All @@ -43,7 +43,7 @@ private CodaCalculator() {
* @param ion
* @return float
*/
public static float getMCQValue(IExtractedIonSignals extractedIonSignals, WindowSize windowSize, int ion) {
public static float getMCQValue(IExtractedIonSignals extractedIonSignals, int windowSize, int ion) {

IExtractedIonSignal extractedIonSignal;
int startScan = extractedIonSignals.getStartScan();
Expand Down Expand Up @@ -91,11 +91,10 @@ public static float getMCQValue(IExtractedIonSignals extractedIonSignals, Window
* @param windowSize
* @return float
*/
private static float calculateMCQValue(double[] euclidianLengthValues, double[] standardizedSmoothedValues, WindowSize windowSize) {
private static float calculateMCQValue(double[] euclidianLengthValues, double[] standardizedSmoothedValues, int windowSize) {

assert (windowSize != null) : "The window size must not be null.";
float mcq = 0.0f;
int lastScan = Calculations.getWindowReducedLength(euclidianLengthValues, windowSize.getSize());
int lastScan = Calculations.getWindowReducedLength(euclidianLengthValues, windowSize);
int scans = euclidianLengthValues.length;
double sumSignals = 0.0f;
/*
Expand All @@ -107,7 +106,7 @@ private static float calculateMCQValue(double[] euclidianLengthValues, double[]
for(int i = 0; i < lastScan; i++) {
sumSignals += euclidianLengthValues[i] * standardizedSmoothedValues[i];
}
mcq = (float)((1.0d / Math.sqrt((scans - windowSize.getSize()))) * sumSignals);
mcq = (float)((1.0d / Math.sqrt((scans - windowSize))) * sumSignals);
/*
* Give a warning if something tries to run out of order.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2018 Lablicate GmbH.
* Copyright (c) 2011, 2021 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand All @@ -13,7 +13,6 @@

import org.eclipse.chemclipse.chromatogram.msd.filter.supplier.coda.exceptions.CodaCalculatorException;
import org.eclipse.chemclipse.msd.model.core.selection.IChromatogramSelectionMSD;
import org.eclipse.chemclipse.numeric.statistics.WindowSize;

/**
* @author eselmeister
Expand All @@ -24,6 +23,7 @@ public class MassChromatographicQualityCalculator {
* Use only static methods.
*/
private MassChromatographicQualityCalculator() {

}

/**
Expand All @@ -36,7 +36,7 @@ private MassChromatographicQualityCalculator() {
* @return {@link IMassChromatographicQualityResult}
* @throws CodaCalculatorException
*/
public static IMassChromatographicQualityResult calculate(IChromatogramSelectionMSD chromatogramSelection, float codaThreshold, WindowSize windowSize) throws CodaCalculatorException {
public static IMassChromatographicQualityResult calculate(IChromatogramSelectionMSD chromatogramSelection, float codaThreshold, int windowSize) throws CodaCalculatorException {

IMassChromatographicQualityResult result = new MassChromatographicQualityResult(chromatogramSelection, codaThreshold, windowSize);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.eclipse.chemclipse.msd.model.xic.ExtractedIonSignalExtractor;
import org.eclipse.chemclipse.msd.model.xic.IExtractedIonSignalExtractor;
import org.eclipse.chemclipse.msd.model.xic.IExtractedIonSignals;
import org.eclipse.chemclipse.numeric.statistics.WindowSize;

public class MassChromatographicQualityResult implements IMassChromatographicQualityResult {

Expand All @@ -41,10 +40,9 @@ public class MassChromatographicQualityResult implements IMassChromatographicQua
* @param windowSize
* @throws CodaCalculatorException
*/
public MassChromatographicQualityResult(IChromatogramSelectionMSD chromatogramSelection, float codaThreshold, WindowSize windowSize) throws CodaCalculatorException {
public MassChromatographicQualityResult(IChromatogramSelectionMSD chromatogramSelection, float codaThreshold, int windowSize) throws CodaCalculatorException {

validateChromatogramSelection(chromatogramSelection);
validateWindowSize(windowSize);
/*
* Create a new excluded ions object.
*/
Expand All @@ -71,11 +69,10 @@ public float getDataReductionValue() {
* DataReductionValue<br/>
* ExcludedIons
*/
private void calculateMassChromatographicQuality(IChromatogramSelectionMSD chromatogramSelection, float codaThreshold, WindowSize windowSize, IMarkedIons excludedIons) {
private void calculateMassChromatographicQuality(IChromatogramSelectionMSD chromatogramSelection, float codaThreshold, int windowSize, IMarkedIons excludedIons) {

assert (chromatogramSelection != null) : "The chromatogram selection must not be null.";
assert (chromatogramSelection.getChromatogram() != null) : "The chromatogram must not be null.";
assert (windowSize != null) : "The window size must not be null.";
assert (excludedIons != null) : "The excluded ions must not be null.";
List<Float> mcqs = new ArrayList<Float>();
float mcq;
Expand Down Expand Up @@ -127,19 +124,6 @@ private float calculateDataReductionValue(List<Float> mcqs, float codaThreshold)
return selected / mcqs.size();
}

/**
* Validates the window size.
*
* @param windowSize
* @throws CodaCalculatorException
*/
private void validateWindowSize(WindowSize windowSize) throws CodaCalculatorException {

if(windowSize == null) {
throw new CodaCalculatorException("The window size must not be null.");
}
}

/**
* Validates the chromatogram selection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
import org.eclipse.chemclipse.msd.model.core.IVendorMassSpectrum;
import org.eclipse.chemclipse.msd.model.core.selection.IChromatogramSelectionMSD;
import org.eclipse.chemclipse.msd.model.core.support.IMarkedIons;
import org.eclipse.chemclipse.numeric.statistics.WindowSize;
import org.eclipse.chemclipse.processing.core.IProcessingInfo;
import org.eclipse.chemclipse.processing.core.ProcessingInfo;
import org.eclipse.core.runtime.IProgressMonitor;

public class ChromatogramFilter extends AbstractChromatogramFilterMSD {

private static WindowSize MOVING_AVERAGE_WINDOW = WindowSize.WIDTH_5;
private static int MOVING_AVERAGE_WINDOW = 5;

@Override
public IProcessingInfo<?> applyFilter(IChromatogramSelectionMSD chromatogramSelection, IChromatogramFilterSettings chromatogramFilterSettings, IProgressMonitor monitor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.savitzkygolay.processor.SavitzkyGolayFilter;
import org.eclipse.chemclipse.model.signals.ITotalScanSignals;
import org.eclipse.chemclipse.numeric.statistics.Calculations;
import org.eclipse.chemclipse.numeric.statistics.WindowSize;

/**
* @author eselmeister
* @author Philip Wenig
*/
public class DetectorSlopes implements IDetectorSlopes {

Expand Down Expand Up @@ -65,28 +64,28 @@ public void add(IDetectorSlope detectorSlope) {
}

@Override
public void calculateMovingAverage(WindowSize windowSize) {
public void calculateMovingAverage(int windowSize) {

/*
* Return if the windowSize is null or NONE.
* Return if the windowSize is NONE.
*/
if(windowSize == null || WindowSize.NONE.equals(windowSize)) {
if(windowSize == 0) {
return;
}
/*
* Return if the available number of slopes are lower than the window
* size.
*/
if(slopes.size() < windowSize.getSize()) {
if(slopes.size() < windowSize) {
return;
}
int diff = windowSize.getSize() / 2;
int windowStop = windowSize.getSize() - diff;
int diff = windowSize / 2;
int windowStop = windowSize - diff;
/*
* Moving average calculation.
*/
int size = slopes.size() - diff;
double[] values = new double[windowSize.getSize()];
double[] values = new double[windowSize];
for(int i = diff; i < size; i++) {
for(int j = -diff, k = 0; j < windowStop; j++, k++) {
values[k] = slopes.get(i + j).getSlope();
Expand All @@ -98,11 +97,11 @@ public void calculateMovingAverage(WindowSize windowSize) {
}
}

public void calculateSavitzkyGolaySmooth(WindowSize windowSize) {
public void calculateSavitzkyGolaySmooth(int windowSize) {

int SAVITZKYGOLAY_DERIVATIVE = 0;
int SAVITZKYGOLAY_ORDER = 3;
int filterWidth = windowSize.getSize();
int filterWidth = windowSize;
double[] initialSlopes = new double[slopes.size()];
double[] smoothedSlopes = new double[slopes.size()];
for(int i = 0; i < slopes.size(); i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.peak.detector.support;

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

/**
* @author eselmeister
* @author Philip Wenig
*/
public interface IDetectorSlopes {

Expand All @@ -38,17 +36,17 @@ public interface IDetectorSlopes {
* Calculates for each stored slope value a smoothed moving average value.<br/>
* The window size declares the width of the moving window.
*
* @param windowSize
* @param int
*/
void calculateMovingAverage(WindowSize windowSize);
void calculateMovingAverage(int windowSize);

/**
* Calculates for each stored slope value a Savitzky-Golay smooothed value.<br/>
* The window size declares the filter width of the Savitzky-Golay filter.
*
* @param windowSize
* @param int
*/
void calculateSavitzkyGolaySmooth(WindowSize windowSize);
void calculateSavitzkyGolaySmooth(int windowSize);

/**
* Returns the size of the slope list.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2020 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 Down Expand Up @@ -30,7 +30,6 @@
import org.eclipse.chemclipse.csd.model.core.selection.ChromatogramSelectionCSD;
import org.eclipse.chemclipse.csd.model.core.selection.IChromatogramSelectionCSD;
import org.eclipse.chemclipse.logging.core.Logger;
import org.eclipse.chemclipse.numeric.statistics.WindowSize;
import org.eclipse.chemclipse.processing.core.IProcessingInfo;
import org.eclipse.core.runtime.IProgressMonitor;

Expand Down Expand Up @@ -61,7 +60,7 @@ public IChromatogramCSD parseChromatogram(String chromatogramPath, String pathRe
peakDetectorSettings.setThreshold(Threshold.LOW);
peakDetectorSettings.setIncludeBackground(false);
peakDetectorSettings.setMinimumSignalToNoiseRatio(50.0f);
peakDetectorSettings.setMovingAverageWindowSize(WindowSize.WIDTH_5);
peakDetectorSettings.setMovingAverageWindowSize(5);
peakDetectorCSD.detect(chromatogramSelectionCSD, peakDetectorSettings, monitor);
/*
* Peak integrator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2020 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 Down Expand Up @@ -33,7 +33,6 @@
import org.eclipse.chemclipse.msd.model.core.IChromatogramPeakMSD;
import org.eclipse.chemclipse.msd.model.core.selection.ChromatogramSelectionMSD;
import org.eclipse.chemclipse.msd.model.core.selection.IChromatogramSelectionMSD;
import org.eclipse.chemclipse.numeric.statistics.WindowSize;
import org.eclipse.chemclipse.processing.core.IProcessingInfo;
import org.eclipse.core.runtime.IProgressMonitor;

Expand Down Expand Up @@ -71,7 +70,7 @@ public IChromatogramMSD parseChromatogram(String chromatogramPath, String pathRe
peakDetectorSettings.setThreshold(Threshold.LOW);
peakDetectorSettings.setIncludeBackground(false);
peakDetectorSettings.setMinimumSignalToNoiseRatio(50.0f);
peakDetectorSettings.setMovingAverageWindowSize(WindowSize.WIDTH_5);
peakDetectorSettings.setMovingAverageWindowSize(5);
peakDetectorMSD.detect(chromatogramSelectionMSD, peakDetectorSettings, monitor);
/*
* Peak integrator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2020 Lablicate GmbH.
* Copyright (c) 2013, 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 @@ -13,11 +13,10 @@

import org.eclipse.chemclipse.chromatogram.xxd.edit.supplier.snip.preferences.PreferenceSupplier;
import org.eclipse.chemclipse.chromatogram.xxd.edit.supplier.snip.ui.Activator;
import org.eclipse.chemclipse.numeric.statistics.WindowSize;
import org.eclipse.chemclipse.support.settings.IntSettingsProperty.Validation;
import org.eclipse.chemclipse.support.ui.preferences.fieldeditors.DoubleFieldEditor;
import org.eclipse.jface.preference.ComboFieldEditor;
import org.eclipse.chemclipse.support.ui.preferences.fieldeditors.IntegerFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

Expand All @@ -36,12 +35,13 @@ public PreferencePage() {
* GUI blocks needed to manipulate various types of preferences. Each field
* editor knows how to save and restore itself.
*/
@Override
public void createFieldEditors() {

IntegerFieldEditor iterationsFieldEditor = new IntegerFieldEditor(PreferenceSupplier.P_ITERATIONS, "Iterations", getFieldEditorParent());
iterationsFieldEditor.setValidRange(PreferenceSupplier.MIN_ITERATIONS, PreferenceSupplier.MAX_ITERATIONS);
addField(iterationsFieldEditor);
addField(new ComboFieldEditor(PreferenceSupplier.P_WINDOW_SIZE, "Window size (Detector)", WindowSize.getElements(), getFieldEditorParent()));
addField(new IntegerFieldEditor(PreferenceSupplier.P_WINDOW_SIZE, "Window Size (Detector)", PreferenceSupplier.MIN_WINDOW_SIZE, PreferenceSupplier.MAX_WINDOW_SIZE, Validation.ODD_NUMBER, getFieldEditorParent()));
addField(new DoubleFieldEditor(PreferenceSupplier.P_MAGNIFICATION_FACTOR, "Magnification factor (Filter)", PreferenceSupplier.MIN_MAGNIFICATION_FACTOR, PreferenceSupplier.MAX_MAGNIFICATION_FACTOR, getFieldEditorParent()));
IntegerFieldEditor transitionsFieldEditor = new IntegerFieldEditor(PreferenceSupplier.P_TRANSITIONS, "Transitions (Filter)", getFieldEditorParent());
transitionsFieldEditor.setValidRange(PreferenceSupplier.MIN_TRANSITIONS, PreferenceSupplier.MAX_TRANSITIONS);
Expand All @@ -53,6 +53,7 @@ public void createFieldEditors() {
* @see
* org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
*/
@Override
public void init(IWorkbench workbench) {

}
Expand Down
Loading

0 comments on commit 13bb6f3

Please sign in to comment.