Skip to content

Commit

Permalink
Fixed #174 - Template Peak Detector UI - chromatogram trace validation
Browse files Browse the repository at this point in the history
  • Loading branch information
eselmeister committed Dec 3, 2021
1 parent 79a2c77 commit 95801f1
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
import net.openchrom.xxd.process.supplier.templates.settings.PeakDetectorSettings;
import net.openchrom.xxd.process.supplier.templates.ui.wizards.PeakDetectorSupport;
import net.openchrom.xxd.process.supplier.templates.ui.wizards.ProcessDetectorSettings;
import net.openchrom.xxd.process.supplier.templates.util.ChromatogramValidator;

public class PeakDetectorDirectMSD<P extends IPeak, C extends IChromatogram<P>, R> extends AbstractPeakDetectorMSD<P, C, R> implements IPeakDetectorDirect, ITemplateExport {

private static final String DESCRIPTION = "PeakDetectorDirectMSD";

@Override
public IProcessingInfo<R> detect(IChromatogramSelectionMSD chromatogramSelection, IPeakDetectorSettingsMSD peakDetectorSettings, IProgressMonitor monitor) {

Expand All @@ -52,81 +55,89 @@ public IProcessingInfo<R> detect(IChromatogramSelectionMSD chromatogramSelection
IChromatogram<? extends IPeak> chromatogram = chromatogramSelection.getChromatogram();
List<DetectorSetting> detectorSettings = new ArrayList<>();
/*
* Peak(s)
* First of all, check that the chromatogram contains the listed traces.
*/
if(settingsDirect.isUseExistingPeaks()) {
for(IPeak peak : chromatogram.getPeaks(chromatogramSelection)) {
String tracesSetting = settingsDirect.getTraces();
if(!ChromatogramValidator.chromatogramContainsTraces(chromatogram, tracesSetting)) {
processingInfo.addWarnMessage(DESCRIPTION, "The chromatogram doesn't contain the given traces: " + tracesSetting);
} else {
/*
* Peak(s)
*/
if(settingsDirect.isUseExistingPeaks()) {
for(IPeak peak : chromatogram.getPeaks(chromatogramSelection)) {
/*
* Retention Time
*/
IPeakModel peakModel = peak.getPeakModel();
int startRetentionTime = peakModel.getStartRetentionTime() - offset;
int stopRetentionTime = peakModel.getStopRetentionTime() + offset;
//
DetectorSetting detectorSetting = new DetectorSetting();
detectorSetting.setStartRetentionTime(startRetentionTime);
detectorSetting.setStopRetentionTime(stopRetentionTime);
detectorSetting.setDetectorType(DetectorType.translate(settingsDirect.getDetectorType()));
detectorSetting.setTraces(getTraces(peak));
detectorSetting.setOptimizeRange(settingsDirect.isOptimizeRange());
detectorSettings.add(detectorSetting);
}
}
/*
* Detector Selected Range
*/
if(settingsDirect.isUseSelectedRange()) {
/*
* Retention Time
*/
IPeakModel peakModel = peak.getPeakModel();
int startRetentionTime = peakModel.getStartRetentionTime() - offset;
int stopRetentionTime = peakModel.getStopRetentionTime() + offset;
int startRetentionTime = getStartRetentionTime(chromatogramSelection, offset);
int stopRetentionTime = getStopRetentionTime(chromatogramSelection, offset);
//
DetectorSetting detectorSetting = new DetectorSetting();
detectorSetting.setStartRetentionTime(startRetentionTime);
detectorSetting.setStopRetentionTime(stopRetentionTime);
detectorSetting.setDetectorType(DetectorType.translate(settingsDirect.getDetectorType()));
detectorSetting.setTraces(getTraces(peak));
detectorSetting.setTraces(settingsDirect.getTraces());
detectorSetting.setOptimizeRange(settingsDirect.isOptimizeRange());
detectorSettings.add(detectorSetting);
}
}
/*
* Detector Selected Range
*/
if(settingsDirect.isUseSelectedRange()) {
/*
* Retention Time
*/
int startRetentionTime = getStartRetentionTime(chromatogramSelection, offset);
int stopRetentionTime = getStopRetentionTime(chromatogramSelection, offset);
//
DetectorSetting detectorSetting = new DetectorSetting();
detectorSetting.setStartRetentionTime(startRetentionTime);
detectorSetting.setStopRetentionTime(stopRetentionTime);
detectorSetting.setDetectorType(DetectorType.translate(settingsDirect.getDetectorType()));
detectorSetting.setTraces(settingsDirect.getTraces());
detectorSetting.setOptimizeRange(settingsDirect.isOptimizeRange());
detectorSettings.add(detectorSetting);
}
/*
* Default: Complete Range
*/
if(detectorSettings.size() == 0) {
/*
* Retention Time
* Default: Complete Range
*/
int startRetentionTime = chromatogram.getStartRetentionTime() + 2000;
int stopRetentionTime = chromatogram.getStopRetentionTime() - 2000;
if(detectorSettings.size() == 0) {
/*
* Retention Time
*/
int startRetentionTime = chromatogram.getStartRetentionTime() + 2000;
int stopRetentionTime = chromatogram.getStopRetentionTime() - 2000;
//
DetectorSetting detectorSetting = new DetectorSetting();
detectorSetting.setStartRetentionTime(startRetentionTime);
detectorSetting.setStopRetentionTime(stopRetentionTime);
detectorSetting.setDetectorType(DetectorType.translate(settingsDirect.getDetectorType()));
detectorSetting.setTraces(settingsDirect.getTraces());
detectorSetting.setOptimizeRange(settingsDirect.isOptimizeRange());
detectorSettings.add(detectorSetting);
}
//
DetectorSetting detectorSetting = new DetectorSetting();
detectorSetting.setStartRetentionTime(startRetentionTime);
detectorSetting.setStopRetentionTime(stopRetentionTime);
detectorSetting.setDetectorType(DetectorType.translate(settingsDirect.getDetectorType()));
detectorSetting.setTraces(settingsDirect.getTraces());
detectorSetting.setOptimizeRange(settingsDirect.isOptimizeRange());
detectorSettings.add(detectorSetting);
}
//
PeakDetectorSettings settings = new PeakDetectorSettings();
settings.setDetectorSettings(detectorSettings);
ProcessDetectorSettings processSettings = new ProcessDetectorSettings(processingInfo, chromatogram, settings);
try {
DisplayUtils.executeInUserInterfaceThread(new Runnable() {
PeakDetectorSettings settings = new PeakDetectorSettings();
settings.setDetectorSettings(detectorSettings);
ProcessDetectorSettings processSettings = new ProcessDetectorSettings(processingInfo, chromatogram, settings);
try {
DisplayUtils.executeInUserInterfaceThread(new Runnable() {

@Override
public void run() {
@Override
public void run() {

Shell shell = DisplayUtils.getShell();
PeakDetectorSupport peakDetectorSupport = new PeakDetectorSupport();
peakDetectorSupport.addPeaks(shell, processSettings);
}
});
} catch(InterruptedException e) {
Thread.currentThread().interrupt();
} catch(ExecutionException e) {
processingInfo.addErrorMessage("PeakDetectorDirectMSD", "Execution failed", e);
Shell shell = DisplayUtils.getShell();
PeakDetectorSupport peakDetectorSupport = new PeakDetectorSupport();
peakDetectorSupport.addPeaks(shell, processSettings);
}
});
} catch(InterruptedException e) {
Thread.currentThread().interrupt();
} catch(ExecutionException e) {
processingInfo.addErrorMessage(DESCRIPTION, "Sorry, somehow the execution failed.", e);
}
}
}
return processingInfo;
Expand All @@ -138,4 +149,4 @@ public IProcessingInfo<R> detect(IChromatogramSelectionMSD chromatogramSelection
PeakDetectorDirectSettings settings = PreferenceSupplier.getPeakDetectorSettingsDirectMSD();
return detect(chromatogramSelection, settings, monitor);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
import net.openchrom.xxd.process.supplier.templates.settings.PeakDetectorSettings;
import net.openchrom.xxd.process.supplier.templates.ui.wizards.PeakDetectorSupport;
import net.openchrom.xxd.process.supplier.templates.ui.wizards.ProcessDetectorSettings;
import net.openchrom.xxd.process.supplier.templates.util.ChromatogramValidator;

public class PeakDetectorDirectWSD<P extends IPeak, C extends IChromatogram<P>, R> extends AbstractPeakDetectorWSD<P, C, R> implements IPeakDetectorDirect, ITemplateExport {

private static final String DESCRIPTION = "PeakDetectorDirectWSD";

@Override
public IProcessingInfo<R> detect(IChromatogramSelectionWSD chromatogramSelection, IPeakDetectorSettingsWSD peakDetectorSettings, IProgressMonitor monitor) {

Expand All @@ -52,81 +55,89 @@ public IProcessingInfo<R> detect(IChromatogramSelectionWSD chromatogramSelection
IChromatogram<? extends IPeak> chromatogram = chromatogramSelection.getChromatogram();
List<DetectorSetting> detectorSettings = new ArrayList<>();
/*
* Peak(s)
* First of all, check that the chromatogram contains the listed traces.
*/
if(settingsDirect.isUseExistingPeaks()) {
for(IPeak peak : chromatogram.getPeaks(chromatogramSelection)) {
String tracesSetting = settingsDirect.getTraces();
if(!ChromatogramValidator.chromatogramContainsTraces(chromatogram, tracesSetting)) {
processingInfo.addWarnMessage(DESCRIPTION, "The chromatogram doesn't contain the given traces: " + tracesSetting);
} else {
/*
* Peak(s)
*/
if(settingsDirect.isUseExistingPeaks()) {
for(IPeak peak : chromatogram.getPeaks(chromatogramSelection)) {
/*
* Retention Time
*/
IPeakModel peakModel = peak.getPeakModel();
int startRetentionTime = peakModel.getStartRetentionTime() - offset;
int stopRetentionTime = peakModel.getStopRetentionTime() + offset;
//
DetectorSetting detectorSetting = new DetectorSetting();
detectorSetting.setStartRetentionTime(startRetentionTime);
detectorSetting.setStopRetentionTime(stopRetentionTime);
detectorSetting.setDetectorType(DetectorType.translate(settingsDirect.getDetectorType()));
detectorSetting.setTraces(getTraces(peak));
detectorSetting.setOptimizeRange(settingsDirect.isOptimizeRange());
detectorSettings.add(detectorSetting);
}
}
/*
* Detector Selected Range
*/
if(settingsDirect.isUseSelectedRange()) {
/*
* Retention Time
*/
IPeakModel peakModel = peak.getPeakModel();
int startRetentionTime = peakModel.getStartRetentionTime() - offset;
int stopRetentionTime = peakModel.getStopRetentionTime() + offset;
int startRetentionTime = getStartRetentionTime(chromatogramSelection, offset);
int stopRetentionTime = getStopRetentionTime(chromatogramSelection, offset);
//
DetectorSetting detectorSetting = new DetectorSetting();
detectorSetting.setStartRetentionTime(startRetentionTime);
detectorSetting.setStopRetentionTime(stopRetentionTime);
detectorSetting.setDetectorType(DetectorType.translate(settingsDirect.getDetectorType()));
detectorSetting.setTraces(getTraces(peak));
detectorSetting.setTraces(settingsDirect.getTraces());
detectorSetting.setOptimizeRange(settingsDirect.isOptimizeRange());
detectorSettings.add(detectorSetting);
}
}
/*
* Detector Selected Range
*/
if(settingsDirect.isUseSelectedRange()) {
/*
* Retention Time
*/
int startRetentionTime = getStartRetentionTime(chromatogramSelection, offset);
int stopRetentionTime = getStopRetentionTime(chromatogramSelection, offset);
//
DetectorSetting detectorSetting = new DetectorSetting();
detectorSetting.setStartRetentionTime(startRetentionTime);
detectorSetting.setStopRetentionTime(stopRetentionTime);
detectorSetting.setDetectorType(DetectorType.translate(settingsDirect.getDetectorType()));
detectorSetting.setTraces(settingsDirect.getTraces());
detectorSetting.setOptimizeRange(settingsDirect.isOptimizeRange());
detectorSettings.add(detectorSetting);
}
/*
* Default: Complete Range
*/
if(detectorSettings.size() == 0) {
/*
* Retention Time
* Default: Complete Range
*/
int startRetentionTime = chromatogram.getStartRetentionTime() + 2000;
int stopRetentionTime = chromatogram.getStopRetentionTime() - 2000;
if(detectorSettings.size() == 0) {
/*
* Retention Time
*/
int startRetentionTime = chromatogram.getStartRetentionTime() + 2000;
int stopRetentionTime = chromatogram.getStopRetentionTime() - 2000;
//
DetectorSetting detectorSetting = new DetectorSetting();
detectorSetting.setStartRetentionTime(startRetentionTime);
detectorSetting.setStopRetentionTime(stopRetentionTime);
detectorSetting.setDetectorType(DetectorType.translate(settingsDirect.getDetectorType()));
detectorSetting.setTraces(settingsDirect.getTraces());
detectorSetting.setOptimizeRange(settingsDirect.isOptimizeRange());
detectorSettings.add(detectorSetting);
}
//
DetectorSetting detectorSetting = new DetectorSetting();
detectorSetting.setStartRetentionTime(startRetentionTime);
detectorSetting.setStopRetentionTime(stopRetentionTime);
detectorSetting.setDetectorType(DetectorType.translate(settingsDirect.getDetectorType()));
detectorSetting.setTraces(settingsDirect.getTraces());
detectorSetting.setOptimizeRange(settingsDirect.isOptimizeRange());
detectorSettings.add(detectorSetting);
}
//
PeakDetectorSettings settings = new PeakDetectorSettings();
settings.setDetectorSettings(detectorSettings);
ProcessDetectorSettings processSettings = new ProcessDetectorSettings(processingInfo, chromatogram, settings);
try {
DisplayUtils.executeInUserInterfaceThread(new Runnable() {
PeakDetectorSettings settings = new PeakDetectorSettings();
settings.setDetectorSettings(detectorSettings);
ProcessDetectorSettings processSettings = new ProcessDetectorSettings(processingInfo, chromatogram, settings);
try {
DisplayUtils.executeInUserInterfaceThread(new Runnable() {

@Override
public void run() {
@Override
public void run() {

Shell shell = DisplayUtils.getShell();
PeakDetectorSupport peakDetectorSupport = new PeakDetectorSupport();
peakDetectorSupport.addPeaks(shell, processSettings);
}
});
} catch(InterruptedException e) {
Thread.currentThread().interrupt();
} catch(ExecutionException e) {
processingInfo.addErrorMessage("PeakDetectorDirectWSD", "Execution failed", e);
Shell shell = DisplayUtils.getShell();
PeakDetectorSupport peakDetectorSupport = new PeakDetectorSupport();
peakDetectorSupport.addPeaks(shell, processSettings);
}
});
} catch(InterruptedException e) {
Thread.currentThread().interrupt();
} catch(ExecutionException e) {
processingInfo.addErrorMessage(DESCRIPTION, "Sorry, somehow the execution failed.", e);
}
}
}
return processingInfo;
Expand All @@ -138,4 +149,4 @@ public IProcessingInfo<R> detect(IChromatogramSelectionWSD chromatogramSelection
PeakDetectorDirectSettings settings = PreferenceSupplier.getPeakDetectorSettingsDirectWSD();
return detect(chromatogramSelection, settings, monitor);
}
}
}
Loading

0 comments on commit 95801f1

Please sign in to comment.