Commit 87c826ed authored by janosch's avatar janosch

factored out DocumentOperation

parent 06d7e141
package de.mpicbg.gef.extractannotationlist;
import com.biomatters.geneious.publicapi.components.Dialogs;
import com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument;
import com.biomatters.geneious.publicapi.documents.sequence.SequenceDocument;
import com.biomatters.geneious.publicapi.plugin.*;
import jebl.util.CompositeProgressListener;
import jebl.util.ProgressListener;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* Created by Stephan Janosch on 17/11/17.
*/
public class GefExtractAnnotationListOperation extends DocumentOperation {
@Override
public GeneiousActionOptions getActionOptions() {
GeneiousActionOptions actionOptions = new GeneiousActionOptions("Extract Features from List", "Extract Features from List", null, GeneiousActionOptions.Category.None);
actionOptions.setMainMenuLocation(GeneiousActionOptions.MainMenu.Sequence);
actionOptions.setInMainToolbar(false);
return actionOptions;
}
@Override
public String getHelp() {
return null;
}
@Override
public DocumentSelectionSignature[] getSelectionSignatures() {
DocumentSelectionSignature sequenceSelSig = new DocumentSelectionSignature(SequenceDocument.class, 1, 100);
return new DocumentSelectionSignature[]{sequenceSelSig};
}
@Override
public List<AnnotatedPluginDocument> performOperation(AnnotatedPluginDocument[] annotatedDocuments, ProgressListener progressListener, Options options) throws DocumentOperationException {
progressListener.setProgress(0d);
String listOfNames = options.getOption("listOfNames").getValueAsString();
List<String> namesWanted = new LinkedList<>();
// final boolean matchPartialNames = ((Options.BooleanOption) options.getOption("matchPartialNames")).getValue();
final String optionType = options.getOption("type").getValueAsString();
for (String name : listOfNames.split(options.getOption("separator").getValueAsString())) {
namesWanted.add(name.trim());
}
List<AnnotatedPluginDocument> results = new ArrayList<AnnotatedPluginDocument>();
List<String> namesFound = new LinkedList<>();
DocumentOperation extractionOperation = PluginUtilities.getDocumentOperation("com.biomatters.plugins.extractAnnotations.ExtractAnnotationsOperation");
CompositeProgressListener compositeProgressListener = new CompositeProgressListener(progressListener, annotatedDocuments.length);
// Dialogs.showMessageDialog(StringUtilities.escapeHtmlCharacters(extractionOptions.getDescriptionAndState()));
//iterate over single documents because of performance reasons
for (AnnotatedPluginDocument doc:annotatedDocuments) {
compositeProgressListener.beginSubtask();
progressListener.setTitle(doc.getName());
Options extractionOptions = extractionOperation.getOptions(doc);
assert extractionOptions.setStringValue("match", "all");
assert extractionOptions.setStringValue("whatToExtract", "annotatedRegion");
assert extractionOptions.setStringValue("intersecting", "includeContained");
assert extractionOptions.setStringValue("concatenate", "false");
assert extractionOptions.setStringValue("includeIntergenicRegionsOption", "false");
assert extractionOptions.setStringValue("dontMatchTruncated", "false");
assert extractionOptions.setStringValue("extractionContextOptions.includeUpstreamBasesOption", "true");
assert extractionOptions.setStringValue("extractionContextOptions.numUpstreamBasesOption", "10000");
assert extractionOptions.setStringValue("extractionContextOptions.includeDownstreamBasesOption", "true");
assert extractionOptions.setStringValue("extractionContextOptions.numDownstreamBasesOption", "10000");
assert extractionOptions.setStringValue("annotation.0.field", "Annotation name");
assert extractionOptions.setStringValue("annotation.0.condition", "contains");
//type
assert extractionOptions.setStringValue("annotation.1.field", "Annotation type");
assert extractionOptions.setStringValue("annotation.1.condition", "is");
assert extractionOptions.setStringValue("annotation.1.value", optionType);
for (String name : namesWanted) {
progressListener.setMessage(name);
compositeProgressListener.setProgress(namesWanted.indexOf(name), namesWanted.size());
assert extractionOptions.setStringValue("annotation.0.value", name);
List<AnnotatedPluginDocument> resultPerOperation = null;
try {
resultPerOperation = extractionOperation.performOperation(new AnnotatedPluginDocument[]{doc}, ProgressListener.EMPTY, extractionOptions);
} catch (Exception e) {
// Dialogs.showMessageDialog(e.toString());
}
if (resultPerOperation != null && !resultPerOperation.isEmpty()) {
results.addAll(resultPerOperation);
namesFound.add(name);
}
}//name
}//doc
for (String name : namesFound) {
namesWanted.remove(name);
}
if (!namesWanted.isEmpty())
Dialogs.showMessageDialog(namesWanted.toString(), "Not found");
return results;
}
@Override
public Options getOptions(DocumentOperationInput operationInput) throws DocumentOperationException {
Options options = new Options(getClass());
options.addMultipleLineStringOption("listOfNames", "Names to Extract:", "", 10, true).setFillHorizontalSpace(true);
options.addStringOption("separator", "Separator:", ",");
options.addStringOption("type","Type:","CDS");
// options.addBooleanOption("matchPartialNames", "Match partial names", false);
return options;
}
}
package de.mpicbg.gef.extractannotationlist;
import com.biomatters.geneious.publicapi.components.Dialogs;
import com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument;
import com.biomatters.geneious.publicapi.documents.sequence.SequenceDocument;
import com.biomatters.geneious.publicapi.plugin.*;
import com.biomatters.geneious.publicapi.utilities.StringUtilities;
import jebl.util.CompositeProgressListener;
import jebl.util.ProgressListener;
import java.util.*;
import com.biomatters.geneious.publicapi.plugin.DocumentOperation;
import com.biomatters.geneious.publicapi.plugin.GeneiousPlugin;
/**
* Created by Stephan Janosch on 31/08/17.
......@@ -52,122 +45,7 @@ public class GefExtractAnnotationListPlugin extends GeneiousPlugin {
@Override
public DocumentOperation[] getDocumentOperations() {
return new DocumentOperation[]{new DocumentOperation() {
@Override
public GeneiousActionOptions getActionOptions() {
GeneiousActionOptions actionOptions = new GeneiousActionOptions("Extract Features from List", "Extract Features from List", null, GeneiousActionOptions.Category.None);
actionOptions.setMainMenuLocation(GeneiousActionOptions.MainMenu.Sequence);
actionOptions.setInMainToolbar(false);
return actionOptions;
}
@Override
public String getHelp() {
return null;
}
@Override
public DocumentSelectionSignature[] getSelectionSignatures() {
DocumentSelectionSignature sequenceSelSig = new DocumentSelectionSignature(SequenceDocument.class, 1, 100);
return new DocumentSelectionSignature[]{sequenceSelSig};
}
@Override
public List<AnnotatedPluginDocument> performOperation(AnnotatedPluginDocument[] annotatedDocuments, ProgressListener progressListener, Options options) throws DocumentOperationException {
progressListener.setProgress(0d);
String listOfNames = options.getOption("listOfNames").getValueAsString();
List<String> namesWanted = new LinkedList<>();
// final boolean matchPartialNames = ((Options.BooleanOption) options.getOption("matchPartialNames")).getValue();
final String optionType = options.getOption("type").getValueAsString();
for (String name : listOfNames.split(options.getOption("separator").getValueAsString())) {
namesWanted.add(name.trim());
}
List<AnnotatedPluginDocument> results = new ArrayList<AnnotatedPluginDocument>();
List<String> namesFound = new LinkedList<>();
DocumentOperation extractionOperation = PluginUtilities.getDocumentOperation("com.biomatters.plugins.extractAnnotations.ExtractAnnotationsOperation");
CompositeProgressListener compositeProgressListener = new CompositeProgressListener(progressListener, annotatedDocuments.length);
// Dialogs.showMessageDialog(StringUtilities.escapeHtmlCharacters(extractionOptions.getDescriptionAndState()));
//iterate over single documents because of performance reasons
for (AnnotatedPluginDocument doc:annotatedDocuments) {
compositeProgressListener.beginSubtask();
progressListener.setTitle(doc.getName());
Options extractionOptions = extractionOperation.getOptions(doc);
assert extractionOptions.setStringValue("match", "all");
assert extractionOptions.setStringValue("whatToExtract", "annotatedRegion");
assert extractionOptions.setStringValue("intersecting", "includeContained");
assert extractionOptions.setStringValue("concatenate", "false");
assert extractionOptions.setStringValue("includeIntergenicRegionsOption", "false");
assert extractionOptions.setStringValue("dontMatchTruncated", "false");
assert extractionOptions.setStringValue("extractionContextOptions.includeUpstreamBasesOption", "true");
assert extractionOptions.setStringValue("extractionContextOptions.numUpstreamBasesOption", "10000");
assert extractionOptions.setStringValue("extractionContextOptions.includeDownstreamBasesOption", "true");
assert extractionOptions.setStringValue("extractionContextOptions.numDownstreamBasesOption", "10000");
assert extractionOptions.setStringValue("annotation.0.field", "Annotation name");
assert extractionOptions.setStringValue("annotation.0.condition", "contains");
//type
assert extractionOptions.setStringValue("annotation.1.field", "Annotation type");
assert extractionOptions.setStringValue("annotation.1.condition", "is");
assert extractionOptions.setStringValue("annotation.1.value", optionType);
for (String name : namesWanted) {
progressListener.setMessage(name);
compositeProgressListener.setProgress(namesWanted.indexOf(name), namesWanted.size());
assert extractionOptions.setStringValue("annotation.0.value", name);
List<AnnotatedPluginDocument> resultPerOperation = null;
try {
resultPerOperation = extractionOperation.performOperation(new AnnotatedPluginDocument[]{doc}, ProgressListener.EMPTY, extractionOptions);
} catch (Exception e) {
// Dialogs.showMessageDialog(e.toString());
}
if (resultPerOperation != null && !resultPerOperation.isEmpty()) {
results.addAll(resultPerOperation);
namesFound.add(name);
}
}//name
}//doc
for (String name : namesFound) {
namesWanted.remove(name);
}
if (!namesWanted.isEmpty())
Dialogs.showMessageDialog(namesWanted.toString(), "Not found");
return results;
}
@Override
public Options getOptions(DocumentOperationInput operationInput) throws DocumentOperationException {
Options options = new Options(getClass());
options.addMultipleLineStringOption("listOfNames", "Names to Extract:", "", 10, true).setFillHorizontalSpace(true);
options.addStringOption("separator", "Separator:", ",");
options.addStringOption("type","Type:","CDS");
// options.addBooleanOption("matchPartialNames", "Match partial names", false);
return options;
}
}};
return new DocumentOperation[]{new GefExtractAnnotationListOperation()};
}
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment