Skip to content

Commit

Permalink
Fixed #683 - Add a peak filter to add a distinct classification
Browse files Browse the repository at this point in the history
  • Loading branch information
eselmeister committed Jul 12, 2021
1 parent d2b8106 commit 7ff4d30
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ Service-Component: OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.Asymme
OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.LowPassPeaksFilter.xml,
OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.DeletePeaksByTargetFilter.xml,
OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierAssignFilter.xml,
OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierRemoveFilter.xml
OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierRemoveFilter.xml,
OSGI-INF/org.eclipse.chemclipse.xxd.model.filter.peaks.ClassifierAddFilter.xml
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>
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);
}
}
}
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;
}
}

0 comments on commit 7ff4d30

Please sign in to comment.