GeneCoder Plugins
GeneCoder 4.0 provides a plug-in API to customize and/or add functionality to the software. Writing plugins require some knowledge of java programming, and JDK 1.6 or later. Plugins are as simple writing some code, complling into a class file or jar library, and adding the plugin file(s) to the plug-in directory - GeneCoder will automatically load the Plugins on startup.
Overview
The plugin API allows three different types of extensions:
- View Plugins - Customize how sequences are viewed. These plugins are loaded into the main interface and can be selected using the view type selection.
- Action Plugins - Add functionality to modify, analyze, or create Sequences. These plugins get loaded into the toolbox, and can be run with the click of a button.
- IO Plugins - Add different File format parsers to read as many file formats as you wish.
The Java API
Writing a Plugin requires a java class to implement the appropriate interface for the appropriate functionality. These interfaces can be found in the com.algosome.genecoder.plugin package (ISequenceViewPlugin, ISequenceActionPlugin, and IIOPlugin). Three libraries are required on the classpath to compile a plugin: Apache log4j, Algosome Commons, and the GeneCoder plugin API.
Plugins are given access to Sequence objects through the SequenceData interface. All sequences in GeneCoder are represented by an implementation of the Sequence interface (it is advised plugins do NOT attempt to implement this interface - rather if one needs to create or read Sequences use the SequenceFactoryBridge or GeneCoderIOBridge classes, respectively). Sequences are wrapped within two parent container objects - a SequenceModel wraps a Sequence and provides basic access to underlying data and method models such as the EditorModel, RestrictionSiteModel (for DNA sequences), SelectionModel, etc...Instances of SequenceModel are in turn wrapped by a SequenceManager, which is responsible for containing a List of sequences and provides access to underlying data and method models (such as a SelectionModel defining which sequences are selected).
Example
The following class file demonstrates a simple ISequenceActionPlugin, the meat of the code is within the doAction method, and has code examples for retrieving a selected sequence from a SequenceData object, as well as examples for how to create a Sequence using the GeneCoderIOBridge and SequenceFactoryBridge classes.
import javax.swing.ImageIcon; import javax.swing.KeyStroke; import com.algosome.common.event.IndexSelectionModel; import com.algosome.genecoder.bio.sequence.SequenceData; import com.algosome.genecoder.bio.sequence.SequenceManager; import com.algosome.genecoder.bio.sequence.SequenceModel; import com.algosome.genecoder.bio.sequence.SequenceFactoryBridge; import com.algosome.genecoder.plugin.DefinedTypes; import com.algosome.genecoder.plugin.ISequenceActionPlugin; import com.algosome.genecoder.plugin.PluginListener; import com.algosome.genecoder.plugin.SequenceCount; import com.algosome.genecoder.plugin.DefinedTypes.Option; import com.algosome.genecoder.io.GeneCoderIOBridge; /** * An example implementation of an Action plugin which * @author Greg Cope * */ class ExamplePlugin implements ISequenceActionPlugin{ private SequenceData sequenceData = null; @Override public SequenceCount getRequiredSequenceCount() { return SequenceCount.ONE;//operates on only one sequence } @Override public void setSequenceData(SequenceData seq) { sequenceData = seq; } @Override public void breakDown() { //break down anything necessary - nothing with this Plugin } @Override public void doStart() { //perform any setup here - nothing with this plugin } @Override public String getDescription() { return "An example plugin"; } @Override public String getName() { return "Example Action"; } @Override public Option getType() { return DefinedTypes.Option.DNA; } @Override public void doAction(PluginListener listener) throws Exception { /* * Given this Plugin is defined with SequenceCount.ONE, only one sequence * should be selected and operated on. The following code operates on this assumption * be retrieving the SelectionModels and getting the selected Sequence. */ IndexSelectionModel model = sequenceData.getSequenceManagerContainer().getSelectionModel(); int selection = model.getSelectedIndex(); assert selection != -1 : "The selection should NOT be -1"; SequenceManager sequenceManager = sequenceData.getSequenceManagerContainer().getSequenceManagers().get(selection); IndexSelectionModel smModel = sequenceManager.getSelectionModel(); int selectedSequenceIndex = smModel.getSelectedIndex(); assert selectedSequenceIndex != -1 : "The selection should NOT be -1"; SequenceModel sequenceModel = sequenceManager.getSequences().get(selectedSequenceIndex); System.out.println(sequenceModel.getSequence().getSequenceName()); /* * Do Manipulation here */ System.out.println("Constructing sequence"); Sequence seq = SequenceFactoryBridge.getInstance().constructSequence("AGCTAAAAGGGGACCCTA", Sequence.SEQUENCE_TYPE_DNA);//construct a new DNA sequence System.out.println(seq.getSequence()); /* Listseqs = GeneCoderIOBridge.getGeneCoderIOBridge().readSequence(new File(""));//enter absolute File path to read a File. System.out.println(seqs.get(0).getSequence()); */ System.out.println(GeneCoderIOBridge.getGeneCoderIOBridge().convertToGenbank(seq)) } @Override public ImageIcon getImageIcon() { return null; } @Override public KeyStroke getShortcut() { return null; } @Override public void stopAction() { //do nothing. } }
References
Required API's to compile Plugins- Algosome Commons 1.2: Download | Javadocs
- GeneCoder Plugin API 4.01: Download | Javadocs
- Apache log4j