-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #683 - Add a peak filter to add a distinct classification
- Loading branch information
1 parent
d2b8106
commit 7ff4d30
Showing
4 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
....xxd.model/OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierAddFilter.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierAddFilter"> | ||
<service> | ||
<provide interface="org.eclipse.chemclipse.model.filter.IPeakFilter"/> | ||
<provide interface="org.eclipse.chemclipse.processing.filter.Filter"/> | ||
<provide interface="org.eclipse.chemclipse.processing.Processor"/> | ||
</service> | ||
<implementation class="org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierAddFilter"/> | ||
</scr:component> |
84 changes: 84 additions & 0 deletions
84
...ipse.xxd.model/src/org/eclipse/chemclipse/xxd/model/filter/peaks/ClassifierAddFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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 | ||
* 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.xxd.model.filter.peaks; | ||
|
||
import java.util.Collection; | ||
|
||
import org.eclipse.chemclipse.model.core.IPeak; | ||
import org.eclipse.chemclipse.model.core.IPeakModel; | ||
import org.eclipse.chemclipse.model.filter.IPeakFilter; | ||
import org.eclipse.chemclipse.processing.Processor; | ||
import org.eclipse.chemclipse.processing.core.MessageConsumer; | ||
import org.eclipse.chemclipse.processing.filter.CRUDListener; | ||
import org.eclipse.chemclipse.processing.filter.Filter; | ||
import org.eclipse.chemclipse.xxd.model.settings.peaks.ClassifierAddFilterSettings; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.SubMonitor; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
@Component(service = {IPeakFilter.class, Filter.class, Processor.class}) | ||
public class ClassifierAddFilter implements IPeakFilter<ClassifierAddFilterSettings> { | ||
|
||
@Override | ||
public String getName() { | ||
|
||
return "Peak Classifier (Add)"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
|
||
return "Adds the given classifier."; | ||
} | ||
|
||
@Override | ||
public Class<ClassifierAddFilterSettings> getConfigClass() { | ||
|
||
return ClassifierAddFilterSettings.class; | ||
} | ||
|
||
@Override | ||
public boolean acceptsIPeaks(Collection<? extends IPeak> items) { | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public <X extends IPeak> void filterIPeaks(CRUDListener<X, IPeakModel> listener, ClassifierAddFilterSettings configuration, MessageConsumer messageConsumer, IProgressMonitor monitor) throws IllegalArgumentException { | ||
|
||
Collection<X> peaks = listener.read(); | ||
if(configuration == null) { | ||
configuration = createConfiguration(peaks); | ||
} | ||
// | ||
String classification = configuration.getClassification(); | ||
boolean skipClassifiedPeak = configuration.isSkipClassifiedPeak(); | ||
SubMonitor subMonitor = SubMonitor.convert(monitor, peaks.size()); | ||
for(X peak : peaks) { | ||
/* | ||
* Peak Classifier | ||
*/ | ||
boolean classify = true; | ||
if(peak.getClassifier().size() > 0) { | ||
if(skipClassifiedPeak) { | ||
classify = false; | ||
} | ||
} | ||
// | ||
if(classify) { | ||
peak.addClassifier(classification); | ||
} | ||
// | ||
subMonitor.worked(1); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...odel/src/org/eclipse/chemclipse/xxd/model/settings/peaks/ClassifierAddFilterSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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 | ||
* 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.xxd.model.settings.peaks; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyDescription; | ||
|
||
public class ClassifierAddFilterSettings { | ||
|
||
@JsonProperty(value = "Classification", defaultValue = "") | ||
@JsonPropertyDescription(value = "This is the classification that shall be set.") | ||
private String classification = ""; | ||
@JsonProperty(value = "Skip Classified Peaks", defaultValue = "true") | ||
@JsonPropertyDescription(value = "Skip peaks that have been classified already.") | ||
private boolean skipClassifiedPeak = true; | ||
|
||
public String getClassification() { | ||
|
||
return classification; | ||
} | ||
|
||
public void setClassification(String classification) { | ||
|
||
this.classification = classification; | ||
} | ||
|
||
public boolean isSkipClassifiedPeak() { | ||
|
||
return skipClassifiedPeak; | ||
} | ||
|
||
public void setSkipClassifiedPeak(boolean skipClassifiedPeak) { | ||
|
||
this.skipClassifiedPeak = skipClassifiedPeak; | ||
} | ||
} |