Post

2 followers Follow
0
Avatar

DocumentOperation behaves differently when deployed

Hi,

somehow I see a pattern here. I have a DocumentOperation which works fine, when started from the IDE, but behaves differently when run as plugin. 

This might be related to: https://support.geneious.com/hc/en-us/community/posts/115001972371-Plugin-works-only-from-IDE-not-in-packaged-form-Why 

package de.mpicbg.gef;

import com.biomatters.geneious.publicapi.components.Dialogs;
import com.biomatters.geneious.publicapi.databaseservice.DatabaseServiceException;
import com.biomatters.geneious.publicapi.documents.AnnotatedPluginDocument;
import com.biomatters.geneious.publicapi.documents.sequence.SequenceAnnotation;
import com.biomatters.geneious.publicapi.documents.sequence.SequenceDocument;
import com.biomatters.geneious.publicapi.plugin.*;
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 GefPrimerOperation extends DocumentOperation {


@Override
public GeneiousActionOptions getActionOptions() {
GeneiousActionOptions actionOptions = new GeneiousActionOptions("Create Primers around Annotation", "Generate Primers around Annotation", null, GeneiousActionOptions.Category.None);
actionOptions.setMainMenuLocation(GeneiousActionOptions.MainMenu.Sequence);
actionOptions.setInMainToolbar(false);

return actionOptions;
}

@Override
public String getHelp() {
return "";
}

@Override
public DocumentSelectionSignature[] getSelectionSignatures() {
DocumentSelectionSignature sequenceSelSig = new DocumentSelectionSignature(SequenceDocument.class, 1, 100);
return new DocumentSelectionSignature[]{sequenceSelSig};
}


@Override
public void performOperation(AnnotatedPluginDocument[] annotatedDocuments, ProgressListener progressListener, Options options, SequenceSelection sequenceSelection, OperationCallback callback) throws DocumentOperationException {

String tagType = options.getValueAsString("tagType");

int i = 0;
for (AnnotatedPluginDocument document : annotatedDocuments) {
i++;
progressListener.setProgress(i, annotatedDocuments.length);
SequenceDocument sequenceDocument = (SequenceDocument) document.getDocument();
//find the tag
SequenceAnnotation tagAnnotation = null;
for (SequenceAnnotation annotation : sequenceDocument.getSequenceAnnotations()) {
if (tagAnnotation == null && annotation.getType().equalsIgnoreCase(tagType))
tagAnnotation = annotation;
else if (annotation.getType().equalsIgnoreCase(tagType))
throw new DocumentOperationException("found more that one tag in: " + document.getName());
}

if (tagAnnotation == null)
throw new DocumentOperationException("found no tag in: " + document.getName());

String fromPosition = String.valueOf(tagAnnotation.getInterval().getMinimumIndex());
String toPosition = String.valueOf(tagAnnotation.getInterval().getMaximumIndex());

DocumentOperation primerOperation = PluginUtilities.getDocumentOperation("Operation_com.biomatters.plugins.primerDesign.DesignAnnotationGenerator");

Options primerOperationOptions = primerOperation.getOptions(document);

// System.out.println(primerOperationOptions.getDescriptionAndState());
// System.out.println("Available Options: " + primerOperationOptions.getNamesAndValues(true));

assert primerOperationOptions.setStringValue("taskOptions.chooser", "designNewOptions");
assert primerOperationOptions.setStringValue("taskOptions.designNewOptions.oligosToPickOptions.forwardOption", "true");
assert primerOperationOptions.setStringValue("taskOptions.designNewOptions.oligosToPickOptions.reverseOption", "true");
assert primerOperationOptions.setStringValue("taskOptions.designNewOptions.oligosToPickOptions.probeOption", "false");

assert primerOperationOptions.setStringValue("panelForRegionType.designRegionTypeOption", "genericOptionValue");
assert primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.enableIncludedRegionOption", "false");

assert primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.enableTargetRegionOption", "true");
assert primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.targetRegionFromOption", fromPosition);
assert primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.targetRegionToOption", toPosition);

assert primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.enableProductSizeOption", "true");
assert primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.productSizeFromOption", options.getValueAsString("productSizeFromOption"));
assert primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.productSizeToOption", options.getValueAsString("productSizeToOption"));

assert primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.enableOptimalProductSizeOption", "false");
assert primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.numPairsOption", "1");


try {
callback.setSubFolder("primed sequences");
} catch (DatabaseServiceException e) {
e.printStackTrace();
}
primerOperation.performOperation(new AnnotatedPluginDocument[]{document}, ProgressListener.EMPTY, primerOperationOptions, sequenceSelection, callback);

}

}


@Override
public Options getOptions(DocumentOperationInput operationInput) throws DocumentOperationException {
Options options = new Options(getClass());
options.addLabel("select annotation type for tag: ");
Options.OptionValue preselectedTag = null;
List<String> tagTypeList = new LinkedList<String>();
for (AnnotatedPluginDocument doc : operationInput.getInputDocumentsList()) {
SequenceDocument sequenceDocument = null;
if (doc.getDocument() instanceof SequenceDocument) {
sequenceDocument = (SequenceDocument) doc.getDocument();
}
if (sequenceDocument == null)
continue;
for (SequenceAnnotation annotation : sequenceDocument.getSequenceAnnotations()) {
String annoType = annotation.getType().toLowerCase();
if (!tagTypeList.contains(annoType) && annoType != null && !annoType.isEmpty())
tagTypeList.add(annoType);
}
}

if (tagTypeList.isEmpty())
throw new DocumentOperationException("no annotations found");

final Options.OptionValue[] optionValues = new Options.OptionValue[tagTypeList.size()];
int i = 0;
for (String tagTypeString : tagTypeList) {
Options.OptionValue value = new Options.OptionValue(tagTypeString, tagTypeString);
optionValues[i] = value;
if (tagTypeString.equalsIgnoreCase("tag"))
preselectedTag = optionValues[i];
i++;
}
options.addComboBoxOption("tagType", "select annotation type for tag", optionValues, preselectedTag);
options.addIntegerOption("productSizeFromOption", "product size from", 1000);
options.addIntegerOption("productSizeToOption", "product size to", 3000);

return options;
}
}


I checked my project settings and they fit with the setup guide.

Just for completeness I post my build file as well:


<?xml version="1.0" ?>

<project name="GefPrimerPlugin" default="distribute" basedir=".">

<property file="plugin.properties"/>
<property name="build" location="build"/>
<property name="classes" location="classes"/>
<property name="src" location="src"/>

<path id="classpath">
<fileset dir="../../geneiousPlugins/geneious-10.2.3-devkit/examples/GeneiousFiles/lib">
<include name="GeneiousPublicAPI.jar"/>
<include name="jdom.jar"/>
<include name="jebl.jar"/>
</fileset>
</path>

<target name= "distribute" depends="build">
<copy file="${build}/${short-plugin-name}.jar" tofile="${build}/${short-plugin-name}.gplugin"/>
<echo message="Created ${build}/${short-plugin-name}.gplugin"/>

<!--If your plugin consists of a folder you should build it into
a zip file with extension gplugin. See commented example below.
Remove above line and uncomment these to use-->
<!--
<zip zipfile="${build}/${short-plugin-name}.gplugin">
<fileset dir="${build}/${plugin-name}"/>
</zip>
-->
</target>

<target name="build" depends="compile">
<jar jarfile="${build}/${short-plugin-name}.jar">
<fileset dir="${classes}"/>
<fileset dir="">
<include name="plugin.properties"/>
</fileset>
</jar>

<!--build example for folder type plugin. Remove above
lines and uncomment these to use-->
<!--
<jar jarfile="${build}/${short-plugin-name}.jar">
<fileset dir="${classes}"/>
</jar>
<mkdir dir="${build}/${plugin-name}"/>
<copy todir="${build}/${plugin-name}">
<fileset dir="${build}">
<include name="ExtraFiles"/>
<include name="ExtraFiles/*"/>
<include name="${short-plugin-name}.jar"/>
</fileset>
<fileset dir="docs">
<include name="readme.txt"/>
</fileset>
</copy>
-->
</target>

<target name="compile" depends="prepare">
<javac target="1.8" source="1.8" destdir="${classes}" debug="true">
<classpath refid="classpath"/>
<src path="${src}"/>
</javac>
</target>

<target name="prepare">
<mkdir dir="${build}"/>
<mkdir dir="${classes}"/>
</target>

<target name="clean">
<delete dir="${build}"/>
<delete dir="${classes}"/>
</target>
</project>

Clueless,
Stephan

 

 

Stephan Janosch

Please sign in to leave a comment.

2 comments

0
Avatar

Hah! I found the culprit! In plugin form, Geneious does not set the options properly. Check out the screen shot!

The same code on the produces different results. Then I tried something. REMOVING the ASSERTIONS. 

Now it looks like that:

primerOperationOptions.setStringValue("taskOptions.chooser", "designNewOptions");
primerOperationOptions.setStringValue("taskOptions.designNewOptions.oligosToPickOptions.forwardOption", "true");
primerOperationOptions.setStringValue("taskOptions.designNewOptions.oligosToPickOptions.reverseOption", "true");
primerOperationOptions.setStringValue("taskOptions.designNewOptions.oligosToPickOptions.probeOption", "false");

primerOperationOptions.setStringValue("panelForRegionType.designRegionTypeOption", "genericOptionValue");
primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.enableIncludedRegionOption", "false");

primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.enableTargetRegionOption", "true");
primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.targetRegionFromOption", fromPosition);
primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.targetRegionToOption", toPosition);

primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.enableProductSizeOption", "true");
primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.productSizeFromOption", options.getValueAsString("productSizeFromOption"));
primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.productSizeToOption", options.getValueAsString("productSizeToOption"));

primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.enableOptimalProductSizeOption", "false");
primerOperationOptions.setStringValue("panelForRegionType.genericRegionOptions.numPairsOption", "1");

And voila, it works! 

Case is closed. I will check my other plugin now ASAP!

*happy*
Stephan

BTW> I don't understand right now, why the assert keyword makes a difference there. I am not a java expert to understand the difference with and without _assert_.

 

 

Stephan Janosch 0 votes
Comment actions Permalink
0
Avatar

Oh! That explains it.  Sorry I should have caught that when looking at your other plugin.

You've got actual production code in your assertions.  Assertions in Java only run when you give the JVM the flag -ea i.e. enable assertions.  So those assert lines weren't being run at all.

We do this in the IDE projects we provide with the development kit because that's how we set up the project internally ourselves too.  But we don't enable assertions for distributions to avoid causing crashes for our users in case the assertions are wrong.  We treat them as a tool for use during development.

Hope that explains things.

Cheers,
Matthew

Matthew Cheung 0 votes
Comment actions Permalink