Skip to content

Commit

Permalink
Fixed #915 - Chromatogram Filter - Select Scan
Browse files Browse the repository at this point in the history
  • Loading branch information
eselmeister committed Feb 22, 2022
1 parent 82a5d7f commit 5984048
Show file tree
Hide file tree
Showing 14 changed files with 323 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,9 +11,8 @@
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.filter.result;

/**
* @author eselmeister
*/
public enum ResultStatus {
OK, UNDEFINED, EXCEPTION;
}
OK, //
UNDEFINED, //
EXCEPTION;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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">
</page>
</extension>
</plugin>
</plugin>
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,20 +11,26 @@
*******************************************************************************/
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;

public class FilterPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

public FilterPreferencePage() {

super(GRID);
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setDescription("Scan Remover");
setTitle("Chromatogram Scan Filter");
setDescription("");
}

@Override
Expand All @@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,36 @@
<ChromatogramFilterSupplier
description="This filter enables to remove a series of scans."
filter="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.core.FilterRemover"
filterName="Scan Remover Filter"
filterName="Scan Remover"
filterSettings="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings.FilterSettingsRemover"
id="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover">
</ChromatogramFilterSupplier>
<ChromatogramFilterSupplier
description="This filters removes empty scans."
filter="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.core.FilterCleaner"
filterName="Remove Empty Scans Filter"
filterName="Scan Cleaner (Remove Empty)"
filterSettings="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings.FilterSettingsCleaner"
id="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.removeemptyscans">
</ChromatogramFilterSupplier>
<ChromatogramFilterSupplier
description="This filters deletes scan identification(s)."
filter="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.core.FilterDeleteIdentifier"
filterName="Delete Scan Target(s)"
filterName="Scan Targets (Delete)"
filterSettings="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings.FilterSettingsDeleteIdentifier"
id="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.removescanidentifications">
</ChromatogramFilterSupplier>
</ChromatogramFilterSupplier>
<ChromatogramFilterSupplier
description="This filters selects a scan in the chromatogram."
filter="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.core.FilterScanSelector"
filterName="Scan Selector"
filterSettings="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.settings.FilterSettingsScanSelector"
id="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanselector">
</ChromatogramFilterSupplier>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="org.eclipse.chemclipse.chromatogram.xxd.filter.supplier.scanremover.preferences.PreferenceInitializer">
</initializer>
</extension>
</plugin>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -59,6 +69,8 @@ public Map<String, String> getDefaultValues() {

Map<String, String> defaultValues = new HashMap<String, String>();
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;
}

Expand Down Expand Up @@ -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.
*
Expand All @@ -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);
}
}
Loading

0 comments on commit 5984048

Please sign in to comment.