From 5984048999f1e7218ad4ec4e55c75d7c24131014 Mon Sep 17 00:00:00 2001 From: Philip Wenig Date: Tue, 22 Feb 2022 07:11:11 +0100 Subject: [PATCH] Fixed #915 - Chromatogram Filter - Select Scan --- .../filter/result/ResultStatus.java | 11 +- .../plugin.xml | 4 +- .../ui/preferences/FilterPreferencePage.java | 15 ++- .../META-INF/MANIFEST.MF | 3 +- .../plugin.xml | 17 ++- .../scanremover/core/FilterRemover.java | 2 +- .../scanremover/core/FilterScanSelector.java | 109 ++++++++++++++++++ .../ScanRemoverPattern.java | 2 +- .../scanremover/model/ScanSelectorOption.java | 39 +++++++ .../preferences/PreferenceSupplier.java | 39 ++++++- .../settings/FilterSettingsScanSelector.java | 51 ++++++++ .../model/support/RetentionIndexMap.java | 42 +++++++ .../xxd/ui/swt/PenaltyCalculationChart.java | 29 +---- .../support/ScanRemoverPattern_1_Test.java | 12 +- 14 files changed, 323 insertions(+), 52 deletions(-) create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/core/FilterScanSelector.java rename chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/{settings => model}/ScanRemoverPattern.java (99%) create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/model/ScanSelectorOption.java create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/settings/FilterSettingsScanSelector.java create mode 100644 chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/support/RetentionIndexMap.java diff --git a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.filter/src/org/eclipse/chemclipse/chromatogram/filter/result/ResultStatus.java b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.filter/src/org/eclipse/chemclipse/chromatogram/filter/result/ResultStatus.java index 1a56c173d3..fc903fe2db 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.filter/src/org/eclipse/chemclipse/chromatogram/filter/result/ResultStatus.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.filter/src/org/eclipse/chemclipse/chromatogram/filter/result/ResultStatus.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2018 Lablicate GmbH. + * Copyright (c) 2008, 2022 Lablicate GmbH. * * All rights reserved. * This program and the accompanying materials are made available under the @@ -11,9 +11,8 @@ *******************************************************************************/ package org.eclipse.chemclipse.chromatogram.filter.result; -/** - * @author eselmeister - */ public enum ResultStatus { - OK, UNDEFINED, EXCEPTION; -} + OK, // + UNDEFINED, // + EXCEPTION; +} \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.ui/plugin.xml b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.ui/plugin.xml index 1b054b2855..47890f5640 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.ui/plugin.xml +++ b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.ui/plugin.xml @@ -7,7 +7,7 @@ category="org.eclipse.chemclipse.chromatogram.filter.ui.preferences.filterPreferencePage" class="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.ui.preferences.FilterPreferencePage" id="org.eclipse.chemclipse.chromatogram.msd.filter.supplier.scanremover.ui.preferences.scanremoverFilterPreferencePage" - name="Scan Remover"> + name="Chromatogram Scan Filter"> - + \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.ui/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/ui/preferences/FilterPreferencePage.java b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.ui/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/ui/preferences/FilterPreferencePage.java index 4c7fa97020..df27a7aa97 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.ui/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/ui/preferences/FilterPreferencePage.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.ui/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/ui/preferences/FilterPreferencePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2018 Lablicate GmbH. + * Copyright (c) 2011, 2022 Lablicate GmbH. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -11,10 +11,14 @@ *******************************************************************************/ package org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.ui.preferences; +import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.model.ScanSelectorOption; import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.preferences.PreferenceSupplier; import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.ui.Activator; +import org.eclipse.chemclipse.support.ui.preferences.fieldeditors.DoubleFieldEditor; import org.eclipse.chemclipse.support.ui.preferences.fieldeditors.LabelFieldEditor; +import org.eclipse.chemclipse.support.ui.preferences.fieldeditors.SpacerFieldEditor; import org.eclipse.chemclipse.support.ui.preferences.fieldeditors.StringRegexFieldEditor; +import org.eclipse.jface.preference.ComboFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; @@ -22,9 +26,11 @@ public class FilterPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { public FilterPreferencePage() { + super(GRID); setPreferenceStore(Activator.getDefault().getPreferenceStore()); - setDescription("Scan Remover"); + setTitle("Chromatogram Scan Filter"); + setDescription(""); } @Override @@ -39,5 +45,10 @@ protected void createFieldEditors() { StringRegexFieldEditor stringPattern = new StringRegexFieldEditor(PreferenceSupplier.P_REMOVER_PATTERN, "Pattern", getFieldEditorParent()); stringPattern.setRegEx(PreferenceSupplier.CHECK_REMOVER_PATTERM); addField(stringPattern); + // + addField(new SpacerFieldEditor(getFieldEditorParent())); + addField(new LabelFieldEditor("Scan Selector", getFieldEditorParent())); + addField(new ComboFieldEditor(PreferenceSupplier.P_SCAN_SELECTOR_OPTION, "Option", ScanSelectorOption.getOptions(), getFieldEditorParent())); + addField(new DoubleFieldEditor(PreferenceSupplier.P_SCAN_SELECTOR_VALUE, "Value", PreferenceSupplier.MIN_SCAN_SELECTOR_VALUE, PreferenceSupplier.MAX_SCAN_SELECTOR_VALUE, getFieldEditorParent())); } } \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/META-INF/MANIFEST.MF b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/META-INF/MANIFEST.MF index 2e8ad82c23..69694a37fc 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/META-INF/MANIFEST.MF +++ b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/META-INF/MANIFEST.MF @@ -18,5 +18,6 @@ Require-Bundle: org.eclipse.core.runtime, com.fasterxml.jackson.core.jackson-annotations;bundle-version="2.6.2" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy -Export-Package: org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.preferences, +Export-Package: org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.model, + org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.preferences, org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings diff --git a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/plugin.xml b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/plugin.xml index 3008e43f6f..36a80057c2 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/plugin.xml +++ b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/plugin.xml @@ -6,24 +6,31 @@ - + + + @@ -31,4 +38,4 @@ class="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.preferences.PreferenceInitializer"> - + \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/core/FilterRemover.java b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/core/FilterRemover.java index a2625f994f..7539af8500 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/core/FilterRemover.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/core/FilterRemover.java @@ -19,9 +19,9 @@ import org.eclipse.chemclipse.chromatogram.filter.result.ResultStatus; import org.eclipse.chemclipse.chromatogram.filter.settings.IChromatogramFilterSettings; import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.exceptions.FilterException; +import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.model.ScanRemoverPattern; import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.preferences.PreferenceSupplier; import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings.FilterSettingsRemover; -import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings.ScanRemoverPattern; import org.eclipse.chemclipse.model.core.IChromatogram; import org.eclipse.chemclipse.model.core.IScan; import org.eclipse.chemclipse.model.selection.IChromatogramSelection; diff --git a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/core/FilterScanSelector.java b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/core/FilterScanSelector.java new file mode 100644 index 0000000000..00e6458e39 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/core/FilterScanSelector.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2022 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.core; + +import org.eclipse.chemclipse.chromatogram.filter.core.chromatogram.AbstractChromatogramFilter; +import org.eclipse.chemclipse.chromatogram.filter.result.ChromatogramFilterResult; +import org.eclipse.chemclipse.chromatogram.filter.result.ResultStatus; +import org.eclipse.chemclipse.chromatogram.filter.settings.IChromatogramFilterSettings; +import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.exceptions.FilterException; +import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.preferences.PreferenceSupplier; +import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings.FilterSettingsScanSelector; +import org.eclipse.chemclipse.model.core.IChromatogram; +import org.eclipse.chemclipse.model.core.IChromatogramOverview; +import org.eclipse.chemclipse.model.core.IScan; +import org.eclipse.chemclipse.model.selection.IChromatogramSelection; +import org.eclipse.chemclipse.model.support.RetentionIndexMap; +import org.eclipse.chemclipse.processing.core.IProcessingInfo; +import org.eclipse.chemclipse.processing.core.MessageType; +import org.eclipse.chemclipse.processing.core.ProcessingMessage; +import org.eclipse.core.runtime.IProgressMonitor; + +@SuppressWarnings("rawtypes") +public class FilterScanSelector extends AbstractChromatogramFilter { + + @SuppressWarnings("unchecked") + @Override + public IProcessingInfo applyFilter(IChromatogramSelection chromatogramSelection, IChromatogramFilterSettings chromatogramFilterSettings, IProgressMonitor monitor) { + + IProcessingInfo processingInfo = validate(chromatogramSelection, chromatogramFilterSettings); + if(!processingInfo.hasErrorMessages()) { + try { + if(chromatogramFilterSettings instanceof FilterSettingsScanSelector) { + FilterSettingsScanSelector settings = (FilterSettingsScanSelector)chromatogramFilterSettings; + selectScan(chromatogramSelection, settings, monitor); + processingInfo.addMessage(new ProcessingMessage(MessageType.INFO, "Select Scan", "The scan has been selected successfully.")); + processingInfo.setProcessingResult(new ChromatogramFilterResult(ResultStatus.OK, "Scan selection was successful.")); + chromatogramSelection.getChromatogram().setDirty(true); + } + } catch(FilterException e) { + processingInfo.addMessage(new ProcessingMessage(MessageType.WARN, "Select Scan", e.getMessage())); + processingInfo.setProcessingResult(new ChromatogramFilterResult(ResultStatus.EXCEPTION, e.getMessage())); + } + } + return processingInfo; + } + + @Override + public IProcessingInfo applyFilter(IChromatogramSelection chromatogramSelection, IProgressMonitor monitor) { + + FilterSettingsScanSelector filterSettings = PreferenceSupplier.getFilterSettingsScanSelector(); + return applyFilter(chromatogramSelection, filterSettings, monitor); + } + + private void selectScan(IChromatogramSelection chromatogramSelection, FilterSettingsScanSelector filterSettingsScanSelector, IProgressMonitor monitor) throws FilterException { + + IChromatogram chromatogram = chromatogramSelection.getChromatogram(); + int startScan = chromatogram.getScanNumber(chromatogramSelection.getStartRetentionTime()); + int stopScan = chromatogram.getScanNumber(chromatogramSelection.getStopRetentionTime()); + int scanNumber = getScanNumber(chromatogram, filterSettingsScanSelector); + // + if(scanNumber >= startScan && scanNumber <= stopScan) { + IScan scan = chromatogram.getScan(scanNumber); + chromatogramSelection.setSelectedScan(scan); + } else { + throw new FilterException("The scan is outside of the chromatogram selection range."); + } + } + + private int getScanNumber(IChromatogram chromatogram, FilterSettingsScanSelector filterSettingsScanSelector) { + + int scanNumber; + double value = filterSettingsScanSelector.getScanSelectorValue(); + switch(filterSettingsScanSelector.getScanSelectorOption()) { + case SCAN_NUMER: + scanNumber = (int)Math.round(value); + break; + case RETENTION_TIME_MS: + scanNumber = chromatogram.getScanNumber((int)Math.round(value)); + break; + case RETENTION_TIME_MIN: + scanNumber = chromatogram.getScanNumber((int)Math.round(value * IChromatogramOverview.MINUTE_CORRELATION_FACTOR)); + break; + case RETENTION_INDEX: + RetentionIndexMap retentionIndexMap = new RetentionIndexMap(); + retentionIndexMap.updateRetentionIndexMap(chromatogram); + int retentionTime = retentionIndexMap.getRetentionTime((int)Math.round(value)); + if(retentionTime > -1) { + scanNumber = chromatogram.getScanNumber(retentionTime); + } else { + scanNumber = -1; + } + break; + default: + scanNumber = -1; + break; + } + // + return scanNumber; + } +} \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/settings/ScanRemoverPattern.java b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/model/ScanRemoverPattern.java similarity index 99% rename from chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/settings/ScanRemoverPattern.java rename to chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/model/ScanRemoverPattern.java index f77a922a3e..a8a10a7132 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/settings/ScanRemoverPattern.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/model/ScanRemoverPattern.java @@ -9,7 +9,7 @@ * Contributors: * Dr. Philip Wenig - initial API and implementation *******************************************************************************/ -package org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings; +package org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.model; import java.util.ArrayList; import java.util.List; diff --git a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/model/ScanSelectorOption.java b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/model/ScanSelectorOption.java new file mode 100644 index 0000000000..b6af5975d6 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/model/ScanSelectorOption.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2022 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.model; + +import org.eclipse.chemclipse.support.text.ILabel; + +public enum ScanSelectorOption implements ILabel { + SCAN_NUMER("Scan Number"), // + RETENTION_TIME_MS("Retention Time [ms]"), // + RETENTION_TIME_MIN("Retention Time [min]"), // + RETENTION_INDEX("Retention Index"); // + + private String label = ""; + + private ScanSelectorOption(String label) { + + this.label = label; + } + + @Override + public String label() { + + return label; + } + + public static String[][] getOptions() { + + return ILabel.getOptions(values()); + } +} \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/preferences/PreferenceSupplier.java b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/preferences/PreferenceSupplier.java index 6b0845c4ac..fbf2ca1a10 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/preferences/PreferenceSupplier.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/preferences/PreferenceSupplier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2020 Lablicate GmbH. + * Copyright (c) 2011, 2022 Lablicate GmbH. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -15,9 +15,11 @@ import java.util.Map; import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.Activator; +import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.model.ScanSelectorOption; import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings.FilterSettingsCleaner; import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings.FilterSettingsDeleteIdentifier; import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings.FilterSettingsRemover; +import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings.FilterSettingsScanSelector; import org.eclipse.chemclipse.support.preferences.IPreferenceSupplier; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IScopeContext; @@ -28,10 +30,18 @@ public class PreferenceSupplier implements IPreferenceSupplier { public static final Character REMOVE_SIGN = 'X'; public static final Character PRESERVE_SIGN = 'O'; // + public static final double MIN_SCAN_SELECTOR_VALUE = 0.0d; + public static final double MAX_SCAN_SELECTOR_VALUE = Double.MAX_VALUE; + // public static final String P_REMOVER_PATTERN = "removerPattern"; public static final String DEF_REMOVER_PATTERN = "XO"; public static final String CHECK_REMOVER_PATTERM = "^[OX]+"; // + public static final String P_SCAN_SELECTOR_OPTION = "scanSelectorOption"; + public static final String DEF_SCAN_SELECTOR_OPTION = ScanSelectorOption.RETENTION_TIME_MS.name(); + public static final String P_SCAN_SELECTOR_VALUE = "scanSelectorValue"; + public static final double DEF_SCAN_SELECTOR_VALUE = 1000.0d; + // private static IPreferenceSupplier preferenceSupplier; public static IPreferenceSupplier INSTANCE() { @@ -59,6 +69,8 @@ public Map getDefaultValues() { Map defaultValues = new HashMap(); defaultValues.put(P_REMOVER_PATTERN, DEF_REMOVER_PATTERN); + defaultValues.put(P_SCAN_SELECTOR_OPTION, DEF_SCAN_SELECTOR_OPTION); + defaultValues.put(P_SCAN_SELECTOR_VALUE, Double.toString(DEF_SCAN_SELECTOR_VALUE)); return defaultValues; } @@ -86,6 +98,15 @@ public static FilterSettingsDeleteIdentifier getDeleteIdentifierFilterSettings() return new FilterSettingsDeleteIdentifier(); } + public static FilterSettingsScanSelector getFilterSettingsScanSelector() { + + FilterSettingsScanSelector settings = new FilterSettingsScanSelector(); + settings.setScanSelectorOption(getScanSelectorOption()); + settings.setScanSelectorValue(getScanSelectorValue()); + // + return settings; + } + /** * Returns the scan remover pattern. * @@ -96,4 +117,20 @@ public static String getScanRemoverPattern() { IEclipsePreferences preferences = INSTANCE().getPreferences(); return preferences.get(P_REMOVER_PATTERN, DEF_REMOVER_PATTERN); } + + private static ScanSelectorOption getScanSelectorOption() { + + try { + IEclipsePreferences preferences = INSTANCE().getPreferences(); + return ScanSelectorOption.valueOf(preferences.get(P_SCAN_SELECTOR_OPTION, DEF_SCAN_SELECTOR_OPTION)); + } catch(Exception e) { + return ScanSelectorOption.RETENTION_TIME_MS; + } + } + + private static double getScanSelectorValue() { + + IEclipsePreferences preferences = INSTANCE().getPreferences(); + return preferences.getDouble(P_SCAN_SELECTOR_VALUE, DEF_SCAN_SELECTOR_VALUE); + } } diff --git a/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/settings/FilterSettingsScanSelector.java b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/settings/FilterSettingsScanSelector.java new file mode 100644 index 0000000000..56206bd028 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/settings/FilterSettingsScanSelector.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2022 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings; + +import org.eclipse.chemclipse.chromatogram.filter.settings.AbstractChromatogramFilterSettings; +import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.model.ScanSelectorOption; +import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.preferences.PreferenceSupplier; +import org.eclipse.chemclipse.support.settings.DoubleSettingsProperty; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; + +public class FilterSettingsScanSelector extends AbstractChromatogramFilterSettings { + + @JsonProperty(value = "Scan Selector Option", defaultValue = "RETENTION_TIME_MS") + @JsonPropertyDescription(value = "Select the option to select the scan in the chromatogram selection.") + private ScanSelectorOption scanSelectorOption = ScanSelectorOption.RETENTION_TIME_MS; + @JsonProperty(value = "Scan Selector Value", defaultValue = "1000") + @JsonPropertyDescription(value = "Select the scan at the given position.") + @DoubleSettingsProperty(minValue = PreferenceSupplier.MIN_SCAN_SELECTOR_VALUE, maxValue = PreferenceSupplier.MAX_SCAN_SELECTOR_VALUE) + private double scanSelectorValue = 1000.0d; + + public ScanSelectorOption getScanSelectorOption() { + + return scanSelectorOption; + } + + public void setScanSelectorOption(ScanSelectorOption scanSelectorOption) { + + this.scanSelectorOption = scanSelectorOption; + } + + public double getScanSelectorValue() { + + return scanSelectorValue; + } + + public void setScanSelectorValue(double scanSelectorValue) { + + this.scanSelectorValue = scanSelectorValue; + } +} \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/support/RetentionIndexMap.java b/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/support/RetentionIndexMap.java new file mode 100644 index 0000000000..2eb46d3327 --- /dev/null +++ b/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/support/RetentionIndexMap.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2022 Lablicate GmbH. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Philip Wenig - initial API and implementation + *******************************************************************************/ +package org.eclipse.chemclipse.model.support; + +import java.util.Map.Entry; +import java.util.TreeMap; + +import org.eclipse.chemclipse.model.core.IChromatogram; +import org.eclipse.chemclipse.model.core.IScan; + +public class RetentionIndexMap extends TreeMap { + + private static final long serialVersionUID = -4827650901052762574L; + + public void updateRetentionIndexMap(IChromatogram chromatogram) { + + clear(); + if(chromatogram != null) { + for(IScan scan : chromatogram.getScans()) { + float retentionIndex = scan.getRetentionIndex(); + if(retentionIndex > 0) { + put(Math.round(retentionIndex), scan.getRetentionTime()); + } + } + } + } + + public int getRetentionTime(int retentionIndex) { + + Entry floorEntry = floorEntry(retentionIndex); + return floorEntry != null ? floorEntry.getValue().intValue() : -1; + } +} \ No newline at end of file diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/PenaltyCalculationChart.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/PenaltyCalculationChart.java index 5b824d548d..996fc03b73 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/PenaltyCalculationChart.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/PenaltyCalculationChart.java @@ -14,8 +14,6 @@ import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; -import java.util.Map.Entry; -import java.util.TreeMap; import org.eclipse.chemclipse.model.core.IChromatogram; import org.eclipse.chemclipse.model.core.IChromatogramPeak; @@ -24,6 +22,7 @@ import org.eclipse.chemclipse.model.core.IScan; import org.eclipse.chemclipse.model.identifier.PenaltyCalculation; import org.eclipse.chemclipse.model.identifier.PenaltyCalculationSupport; +import org.eclipse.chemclipse.model.support.RetentionIndexMap; import org.eclipse.chemclipse.support.text.ValueFormat; import org.eclipse.chemclipse.swt.ui.support.Colors; import org.eclipse.chemclipse.ux.extension.xxd.ui.Activator; @@ -54,7 +53,7 @@ public class PenaltyCalculationChart extends ChromatogramChart { // private IPeak peak = null; private PenaltyCalculationModel penaltyCalculationModel = null; - private TreeMap retentionIndexMap = new TreeMap<>(); + private RetentionIndexMap retentionIndexMap = new RetentionIndexMap(); public PenaltyCalculationChart() { @@ -77,7 +76,7 @@ public void setInput(PenaltyCalculationModel penaltyCalculationModel) { public void setInput(IPeak peak) { this.peak = peak; - updateRetentionIndexMap(); + retentionIndexMap.updateRetentionIndexMap(getChromatogram()); updateChart(); } @@ -211,7 +210,7 @@ private void displayRetentionIndexPenalty() { unknownListener.setData(retentionTimeUnknown, labelUnknown, "-- %"); // double retentionIndexReference = penaltyCalculationModel.getReferenceValue(); - int retentionTimeReference = getRetentionTime((int)retentionIndexReference); + int retentionTimeReference = retentionIndexMap.getRetentionTime((int)retentionIndexReference); if(retentionTimeReference > -1) { /* * Reference @@ -249,26 +248,6 @@ private double[] adjust(double[] series, double start, double stop) { return seriesAdjusted; } - private void updateRetentionIndexMap() { - - retentionIndexMap.clear(); - IChromatogram chromatogram = getChromatogram(); - if(chromatogram != null) { - for(IScan scan : chromatogram.getScans()) { - float retentionIndex = scan.getRetentionIndex(); - if(retentionIndex > 0) { - retentionIndexMap.put(Math.round(retentionIndex), scan.getRetentionTime()); - } - } - } - } - - private int getRetentionTime(int retentionIndex) { - - Entry floorEntry = retentionIndexMap.floorEntry(retentionIndex); - return floorEntry != null ? floorEntry.getValue().intValue() : -1; - } - private IChromatogram getChromatogram() { IChromatogram chromatogram = null; diff --git a/chemclipse/tests/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.fragment.test/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/internal/support/ScanRemoverPattern_1_Test.java b/chemclipse/tests/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.fragment.test/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/internal/support/ScanRemoverPattern_1_Test.java index 5409497199..cafc97067f 100644 --- a/chemclipse/tests/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.fragment.test/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/internal/support/ScanRemoverPattern_1_Test.java +++ b/chemclipse/tests/org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.fragment.test/src/org/eclipse/chemclipse/chromatogram/xxd/filter/supplier/scanremover/internal/support/ScanRemoverPattern_1_Test.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2018 Lablicate GmbH. + * Copyright (c) 2011, 2022 Lablicate GmbH. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -11,15 +11,11 @@ *******************************************************************************/ package org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.internal.support; -import junit.framework.TestCase; - +import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.model.ScanRemoverPattern; import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.preferences.PreferenceSupplier; -import org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings.ScanRemoverPattern; -/** - * @author Dr. Philip Wenig - * - */ +import junit.framework.TestCase; + public class ScanRemoverPattern_1_Test extends TestCase { private ScanRemoverPattern scanRemoverPattern;