Using BioJava in STRAP-Plugins

Introduction

BioJava is a versatile API for processing biological data. This page shows how STRAP can serve as a graphical interface for programs written with BioJava and how BioJava can be used to enhance the functionality of STRAP by plugins.

STRAP has a special script command "plugin" to load plugins. The "script"-command has two required parameters which are separated by comma: The class name and the list of jar-files.
    plugin full-Class-name,  list of jar-file-URLs
  
The script line is contained in the Web-variable "script": Another important Web-variable "load" is also used in the examples of this page. The file contains a space separated list of protein entries. For more details see Script commands and Web variables.

Plugin files

Plugins for STRAP are distributed as jar-file[s] which contain the Java-class files and some optional files. To assure that a plugin is registered, such that it can be started in the plugin dialog, the file "classes.txt" is required. It contains the main class name[s] of the plugin followed by menu a name. This file may contain more than one class entry. In the example below the "classes.txt"-file has the following content:
    PairAligner_NeedlemanWunsch_Biojava   BioJava
    ApplyPairAligner_NeedlemanWunsch_Biojava   BioJava
  
"PairAligner_NeedlemanWunsch_Biojava" and "ApplyPairAligner_NeedlemanWunsch_Biojava" are the two main classes and "BioJava" is free text designating the menu name.

When preparing a plugin file, it is a good style to include the java source code and some documentation. The html file with information about the plugin must have the same file path like the ".class" and ".java" files, but should end with ".html".

For the example below the plugin file needlemanWunschBJ.jar contains the following files:
    ApplyPairAligner_NeedlemanWunsch_Biojava.java
    ApplyPairAligner_NeedlemanWunsch_Biojava.class
    PairAligner_NeedlemanWunsch_Biojava.java
    PairAligner_NeedlemanWunsch_Biojava.html
    PairAligner_NeedlemanWunsch_Biojava.class
    author.txt
    classes.txt
    delete.txt
    download.txt
  
Absolutely necessary are only the class files, whereas the "classes.txt"-file allows registration in the plugin dialog.

A plugin can be stored on any Web-server (static or dynamic). STRAP evaluates the "last-modified" HTTP header field to check whether a previously downloaded copy of the Jar-file is still up-to-date. Otherwise STRAP will download the Jar-file from the given Web-address and load the contained Java classes with the an own ClassLoader.

Plugins of type SequenceAligner

     <form  action="ce.php"  method="POST" >
      <input  type="hidden"  name="load"   value="PDB:1ryp_A PDB:1ryp_B PDB:1ryp_C PDB:1ryp_D UNIPROT:PSA2_XENLA "  >
      <input  type="hidden"  name="script" value="
    plugin  PairAligner_NeedlemanWunsch_Biojava, http://www-intern.charite.de/bioinf/strap/plugins/needlemanWunschBJ.jar http://www.biojava.org/download/bj17/bin/biojava.jar
    ">
      <input  type="SUBMIT"  name="SUBMIT" value="Open alignment dialog with Biojava-Needleman-Wunsch" >      
    </form>
    
The class PairAligner_NeedlemanWunsch_Biojava implements the interface SequenceAligner. Therefore the alignment dialog will be started and the class "PairAligner_NeedlemanWunsch_Biojava" will be selected as the alignment method. The user can press the "go"-button of the dialog to start computation. After some seconds the preview with the alignment result will appear.

Plugins of type StrapExtension

In the following example the class "ApplyPairAligner_NeedlemanWunsch_Biojava" is specified in the HTML-form. Otherwise the HTML-form is identical to the previous example. Because this class file is also contained in the same Jar-file which had already been downloaded with the previous example, no download dialog appears. This class implements the interface StrapExtension. On clicking the submit button in the HTML-form, the run()-method of the plugin is started. In this example the selected proteins are aligned using BioJava.
Footnote: Proteins are selected in STRAP by left-clicking the protein labels. Multiple selections require the shift or ctrl key.

What happens when a Plugin is activated?

The role of a plugin is defined by the implemented interfaces. Depending on these interfaces different actions are taken when a plugin is activated:

Plugins that can be controlled by Web-links

Some advanced Viewers for biological data such as Jmol can not only be installed automatically and started from Web-pages but also be controlled by clicking Web-links. This requires some kind of communication of the Web browser with the running viewer.

Also STRAP plugins can be controlled by Web-links. A HTML-form or a Web-link defines a script line in the Web-variable "script". When the link is clicked, the script line is wrapped in a StrapEvent object which is broadcasted to all listeners. All plugins that implement StrapListener receive this event. Each plugin can decide to ignore the script command or to take a specific action. In this example the following command is send.
     *testBiojava_showSelectedProteins
   
The leading asterisk indicates that this command is not evaluated by the STRAP core, but by an external plugin. The plugin code contains the following lines:
     public void handleEvent(StrapEvent ev) {
       if (ev.getType()==StrapEvent.SCRIPT_LINE) {
         for (String scriptLine : (String[])ev.getParameters()) {
           if (scriptLine.startsWith("*testBiojava_showSelectedProteins")) {
     ...
     In this example the selected proteins are listed in a text pane.
     ...
   
This is the HTML-form:
     <form  action="ce.php"  method="POST" >
       <input  type="hidden"  name="script"     value="*testBiojava_showSelectedProteins">
       <input  type="SUBMIT"  name="SUBMIT" value="Send script line" >      
     </form>
   

Getting started

To develop a plugin, start STRAP from the STRAP page.
  1. Download http://www.charite.de/bioinf/strap/strap.jar and include strap.jar in the classpath.
  2. Write and compile a Java file implementing StrapExtension.
  3. Create a Jar-file containing the compiled class-file and a "classes.txt"-file.
  4. Copy the jar file to $HOME/.StrapAlign/plugins/. On DOS-platforms the path is C:\StrapAlign\plugins\.
  5. Open the Standard-plugin-dialog. Your plugin should be listed. Select the plugin and start it.
Whenever the plugin code has been modified the button "Reload class" in the plugin dialog of STRAP needs to be pressed (Or STRAP can be restarted). Also See 16469097. On DOS-platforms reloading of modified classes requires Java-version 1.7 or higher (Reason).