Skip to content

Commit 4d70faa

Browse files
committed
Fixed #2316 - Peak Target - Penalty Calculation Filter
1 parent 4b4953c commit 4d70faa

File tree

14 files changed

+231
-27
lines changed

14 files changed

+231
-27
lines changed

chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/identifier/AbstractIdentifierDeltaPenaltyCalculationSettings.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class AbstractIdentifierDeltaPenaltyCalculationSettings extends AbstractI
2727
private DeltaCalculation deltaCalculation = DeltaCalculation.NONE;
2828
@JsonProperty(value = "Delta Window", defaultValue = "0")
2929
@JsonPropertyDescription(value = "Identify the peak if the unknown is inside of the delta window (delta -/+).")
30-
@FloatSettingsProperty(minValue = IDeltaCalculationSettings.MIN_DELTA_WINDOW, maxValue = IDeltaCalculationSettings.MAX_DELTA_WINDOW)
30+
@FloatSettingsProperty(minValue = MIN_DELTA_WINDOW, maxValue = MAX_DELTA_WINDOW)
3131
private float deltaWindow = 0.0f;
3232
/**
3333
* Penalty Calculation
@@ -37,12 +37,12 @@ public class AbstractIdentifierDeltaPenaltyCalculationSettings extends AbstractI
3737
private PenaltyCalculation penaltyCalculation = PenaltyCalculation.NONE;
3838
@JsonProperty(value = "Penalty Window", defaultValue = "0")
3939
@JsonPropertyDescription(value = "The penalty window. The unit of the selected penalty calculation is used.")
40-
@FloatSettingsProperty(minValue = IPenaltyCalculationSettings.MIN_PENALTY_WINDOW, maxValue = IPenaltyCalculationSettings.MAX_PENALTY_WINDOW)
40+
@FloatSettingsProperty(minValue = MIN_PENALTY_WINDOW, maxValue = MAX_PENALTY_WINDOW)
4141
private float penaltyWindow = 0.0f;
4242
@JsonProperty(value = "Penalty Level Factor", defaultValue = "5.0")
4343
@JsonPropertyDescription(value = "The penalty level factor.")
44-
@FloatSettingsProperty(minValue = IPenaltyCalculationSettings.MIN_PENALTY_LEVEL_FACTOR, maxValue = IPenaltyCalculationSettings.MAX_PENALTY_LEVEL_FACTOR)
45-
private float penaltyLevelFactor = IPenaltyCalculationSettings.DEF_PENALTY_LEVEL_FACTOR;
44+
@FloatSettingsProperty(minValue = MIN_PENALTY_LEVEL_FACTOR, maxValue = MAX_PENALTY_LEVEL_FACTOR)
45+
private float penaltyLevelFactor = DEF_PENALTY_LEVEL_FACTOR;
4646
@JsonProperty(value = "Max Penalty", defaultValue = "20")
4747
@JsonPropertyDescription(value = "The max penalty. Values between 0 (no penalty) and 100 (max penalty) are allowed.")
4848
@FloatSettingsProperty(minValue = MIN_PENALTY_MATCH_FACTOR, maxValue = MAX_PENALTY_MATCH_FACTOR)
@@ -119,4 +119,4 @@ public void setMaxPenalty(float maxPenalty) {
119119

120120
this.maxPenalty = maxPenalty;
121121
}
122-
}
122+
}

chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/identifier/IIdentifierSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ public interface IIdentifierSettings extends IProcessSettings {
3434
* @param limitMatchFactor
3535
*/
3636
void setLimitMatchFactor(float limitMatchFactor);
37-
}
37+
}

chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/identifier/IPenaltyCalculationSettings.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,6 @@ public interface IPenaltyCalculationSettings extends IProcessSettings {
3232
float MIN_PENALTY_MATCH_FACTOR = 0.0f;
3333
float MAX_PENALTY_MATCH_FACTOR = 100.0f;
3434

35-
/**
36-
* Limit Match Factor
37-
*
38-
* @return float
39-
*/
40-
float getLimitMatchFactor();
41-
42-
/**
43-
* Only identify the peak if no target is available with a match factor >= the limit.
44-
*
45-
* @param limitMatchFactor
46-
*/
47-
void setLimitMatchFactor(float limitMatchFactor);
48-
4935
/**
5036
* Retention Time / Index Penalty Calculation
5137
*/
@@ -64,4 +50,4 @@ public interface IPenaltyCalculationSettings extends IProcessSettings {
6450
float getMaxPenalty();
6551

6652
void setMaxPenalty(float maxValue);
67-
}
53+
}

chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/identifier/PenaltyCalculationSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,4 @@ public static double calculatePenalty(double valueUnknown, double valueReference
117117
return (result > maxPenalty) ? maxPenalty : result;
118118
}
119119
}
120-
}
120+
}

chemclipse/plugins/org.eclipse.chemclipse.xxd.filter/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Service-Component: OSGI-INF/org.eclipse.chemclipse.xxd.filter.chromatogram.Inten
5858
OSGI-INF/org.eclipse.chemclipse.xxd.filter.peaks.AreaFilter.xml,
5959
OSGI-INF/org.eclipse.chemclipse.xxd.filter.peaks.AreaPercentFilter.xml,
6060
OSGI-INF/org.eclipse.chemclipse.xxd.filter.peaks.AsymmetryFilter.xml,
61+
OSGI-INF/org.eclipse.chemclipse.xxd.filter.peaks.CalculatePenaltyFilter.xml,
6162
OSGI-INF/org.eclipse.chemclipse.xxd.filter.peaks.ClassifiedPeaksFilter.xml,
6263
OSGI-INF/org.eclipse.chemclipse.xxd.filter.peaks.DeleteIntegrationsFilter.xml,
6364
OSGI-INF/org.eclipse.chemclipse.xxd.filter.peaks.DeletePeaksByModelFilter.xml,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.chemclipse.xxd.filter.peaks.CalculatePenaltyFilter">
3+
<service>
4+
<provide interface="org.eclipse.chemclipse.model.filter.IPeakFilter"/>
5+
<provide interface="org.eclipse.chemclipse.processing.filter.Filter"/>
6+
<provide interface="org.eclipse.chemclipse.processing.Processor"/>
7+
</service>
8+
<implementation class="org.eclipse.chemclipse.xxd.filter.peaks.CalculatePenaltyFilter"/>
9+
</scr:component>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Lablicate GmbH.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Philip Wenig - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.chemclipse.xxd.filter.peaks;
14+
15+
import java.util.Collection;
16+
import java.util.Set;
17+
18+
import org.eclipse.chemclipse.model.core.IPeak;
19+
import org.eclipse.chemclipse.model.core.IPeakModel;
20+
import org.eclipse.chemclipse.model.core.IScan;
21+
import org.eclipse.chemclipse.model.filter.IPeakFilter;
22+
import org.eclipse.chemclipse.model.identifier.IComparisonResult;
23+
import org.eclipse.chemclipse.model.identifier.IIdentificationTarget;
24+
import org.eclipse.chemclipse.model.identifier.ILibraryInformation;
25+
import org.eclipse.chemclipse.model.identifier.PenaltyCalculationSupport;
26+
import org.eclipse.chemclipse.model.selection.IChromatogramSelection;
27+
import org.eclipse.chemclipse.processing.Processor;
28+
import org.eclipse.chemclipse.processing.filter.Filter;
29+
import org.eclipse.chemclipse.processing.supplier.ProcessExecutionContext;
30+
import org.eclipse.chemclipse.xxd.filter.peaks.settings.PenaltyCalculatorFilterSettings;
31+
import org.eclipse.core.runtime.SubMonitor;
32+
import org.osgi.service.component.annotations.Component;
33+
34+
@Component(service = {IPeakFilter.class, Filter.class, Processor.class})
35+
public class CalculatePenaltyFilter extends AbstractPeakFilter<PenaltyCalculatorFilterSettings> {
36+
37+
@Override
38+
public String getName() {
39+
40+
return "Penalty Calculator";
41+
}
42+
43+
@Override
44+
public String getDescription() {
45+
46+
return "Calculate match penalties based on RT or RI deviations of unknown and library hit.";
47+
}
48+
49+
@Override
50+
public Class<PenaltyCalculatorFilterSettings> getConfigClass() {
51+
52+
return PenaltyCalculatorFilterSettings.class;
53+
}
54+
55+
@Override
56+
public void filterPeaks(IChromatogramSelection chromatogramSelection, PenaltyCalculatorFilterSettings configuration, ProcessExecutionContext context) throws IllegalArgumentException {
57+
58+
Collection<IPeak> peaks = getReadOnlyPeaks(chromatogramSelection);
59+
if(configuration == null) {
60+
configuration = createConfiguration(peaks);
61+
}
62+
63+
SubMonitor subMonitor = SubMonitor.convert(context.getProgressMonitor(), peaks.size());
64+
for(IPeak peak : peaks) {
65+
Set<IIdentificationTarget> targets = peak.getTargets();
66+
for(IIdentificationTarget identificationTarget : targets) {
67+
IComparisonResult comparisonResult = identificationTarget.getComparisonResult();
68+
ILibraryInformation libraryInformation = identificationTarget.getLibraryInformation();
69+
IPeakModel peakModel = peak.getPeakModel();
70+
IScan scan = peakModel.getPeakMaximum();
71+
int retentionTimeUnknown = scan.getRetentionTime();
72+
float retentionIndexUnknown = scan.getRetentionIndex();
73+
int retentionTimeReference = libraryInformation.getRetentionTime();
74+
float retentionIndexReference = libraryInformation.getRetentionIndex();
75+
PenaltyCalculationSupport.applyPenalty(retentionTimeUnknown, retentionIndexUnknown, retentionTimeReference, retentionIndexReference, comparisonResult, configuration);
76+
}
77+
subMonitor.worked(1);
78+
}
79+
}
80+
}

chemclipse/plugins/org.eclipse.chemclipse.xxd.filter/src/org/eclipse/chemclipse/xxd/filter/peaks/DeleteTargetsFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.eclipse.chemclipse.processing.Processor;
2121
import org.eclipse.chemclipse.processing.filter.Filter;
2222
import org.eclipse.chemclipse.processing.supplier.ProcessExecutionContext;
23-
import org.eclipse.chemclipse.xxd.filter.settings.DeleteTargetsFilterSettings;
23+
import org.eclipse.chemclipse.xxd.filter.peaks.settings.DeleteTargetsFilterSettings;
2424
import org.eclipse.chemclipse.xxd.filter.targets.TargetsFilter;
2525
import org.eclipse.core.runtime.SubMonitor;
2626
import org.osgi.service.component.annotations.Component;

chemclipse/plugins/org.eclipse.chemclipse.xxd.filter/src/org/eclipse/chemclipse/xxd/filter/settings/DeleteTargetsFilterSettings.java renamed to chemclipse/plugins/org.eclipse.chemclipse.xxd.filter/src/org/eclipse/chemclipse/xxd/filter/peaks/settings/DeleteTargetsFilterSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Contributors:
1111
* Philip Wenig - initial API and implementation
1212
*******************************************************************************/
13-
package org.eclipse.chemclipse.xxd.filter.settings;
13+
package org.eclipse.chemclipse.xxd.filter.peaks.settings;
1414

1515
import org.eclipse.chemclipse.support.settings.StringSettingsProperty;
1616
import org.eclipse.chemclipse.xxd.filter.support.TargetsDeleteOption;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Lablicate GmbH.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Philip Wenig - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.chemclipse.xxd.filter.peaks.settings;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
import org.eclipse.chemclipse.logging.core.Logger;
19+
import org.eclipse.chemclipse.model.identifier.IPenaltyCalculationSettings;
20+
import org.eclipse.chemclipse.model.identifier.PenaltyCalculation;
21+
import org.eclipse.chemclipse.support.literature.LiteratureReference;
22+
import org.eclipse.chemclipse.support.settings.FloatSettingsProperty;
23+
24+
import com.fasterxml.jackson.annotation.JsonProperty;
25+
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
26+
27+
public class PenaltyCalculatorFilterSettings implements IPenaltyCalculationSettings {
28+
29+
private static final Logger logger = Logger.getLogger(PenaltyCalculatorFilterSettings.class);
30+
31+
@JsonProperty(value = "Penalty Calculation", defaultValue = "NONE")
32+
@JsonPropertyDescription(value = "Select the strategy, how penalties are calculated.")
33+
private PenaltyCalculation penaltyCalculation = PenaltyCalculation.NONE;
34+
@JsonProperty(value = "Penalty Window", defaultValue = "0")
35+
@JsonPropertyDescription(value = "The penalty window. The unit of the selected penalty calculation is used.")
36+
@FloatSettingsProperty(minValue = IPenaltyCalculationSettings.MIN_PENALTY_WINDOW, maxValue = IPenaltyCalculationSettings.MAX_PENALTY_WINDOW)
37+
private float penaltyWindow = 0.0f;
38+
@JsonProperty(value = "Penalty Level Factor", defaultValue = "5.0")
39+
@JsonPropertyDescription(value = "The penalty level factor.")
40+
@FloatSettingsProperty(minValue = IPenaltyCalculationSettings.MIN_PENALTY_LEVEL_FACTOR, maxValue = IPenaltyCalculationSettings.MAX_PENALTY_LEVEL_FACTOR)
41+
private float penaltyLevelFactor = IPenaltyCalculationSettings.DEF_PENALTY_LEVEL_FACTOR;
42+
@JsonProperty(value = "Max Penalty", defaultValue = "20")
43+
@JsonPropertyDescription(value = "The max penalty. Values between 0 (no penalty) and 100 (max penalty) are allowed.")
44+
@FloatSettingsProperty(minValue = IPenaltyCalculationSettings.MIN_PENALTY_MATCH_FACTOR, maxValue = IPenaltyCalculationSettings.MAX_PENALTY_MATCH_FACTOR)
45+
private float maxPenalty = IPenaltyCalculationSettings.DEF_PENALTY_MATCH_FACTOR;
46+
47+
@Override
48+
public PenaltyCalculation getPenaltyCalculation() {
49+
50+
return penaltyCalculation;
51+
}
52+
53+
@Override
54+
public void setPenaltyCalculation(PenaltyCalculation penaltyCalculation) {
55+
56+
this.penaltyCalculation = penaltyCalculation;
57+
}
58+
59+
@Override
60+
public float getPenaltyWindow() {
61+
62+
return penaltyWindow;
63+
}
64+
65+
@Override
66+
public void setPenaltyWindow(float penaltyWindow) {
67+
68+
this.penaltyWindow = penaltyWindow;
69+
}
70+
71+
@Override
72+
public float getPenaltyLevelFactor() {
73+
74+
return penaltyLevelFactor;
75+
}
76+
77+
@Override
78+
public void setPenaltyLevelFactor(float penaltyLevelFactor) {
79+
80+
this.penaltyLevelFactor = penaltyLevelFactor;
81+
}
82+
83+
@Override
84+
public float getMaxPenalty() {
85+
86+
return maxPenalty;
87+
}
88+
89+
@Override
90+
public void setMaxPenalty(float maxPenalty) {
91+
92+
this.maxPenalty = maxPenalty;
93+
}
94+
95+
@Override
96+
public List<LiteratureReference> getLiteratureReferences() {
97+
98+
List<LiteratureReference> literatureReferences = new ArrayList<>();
99+
literatureReferences.add(createLiteratureReference("S1044030599000471.ris", "10.1016/S1044-0305(99)00047-1"));
100+
//
101+
return literatureReferences;
102+
}
103+
104+
private static LiteratureReference createLiteratureReference(String file, String doi) {
105+
106+
try {
107+
return new LiteratureReference(new String(PenaltyCalculatorFilterSettings.class.getResourceAsStream(file).readAllBytes()));
108+
} catch(Exception e) {
109+
logger.warn(e);
110+
return new LiteratureReference(doi);
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)