Bc rhino

From Bioclipse
Jump to: navigation, search

This page is deprecated and the listed sample scripts will not work in Bioclipse 2

Here you find three javascript sample scripts for the bc_rhino Plug-In

Sample script 1

The basics.

   // the rhino object conatains functions for simplifying scripting...
   rhino.showMessage("Hello", "Bioclipse :)");
   rhino.showMessage("Bioclipse :)");
   BioclipseConsole = Packages.net.bioclipse.util.BioclipseConsole;
   BioclipseConsole.writeToConsole("Hello Bioclipse!");
   i = 0;
   while(i < 10) {
   i = i + 1;

Sample script 2

Do complicated Bioclipse GUI stuff :)

   // shorten identifiers
   EBIWSDbfetchWizard = Packages.net.bioclipse.plugins.bc_webservices.wizards.newwizards.EBIWSDbfetchWizard;
   WizardDialog = Packages.org.eclipse.jface.wizard.WizardDialog;
   PlatformUI = Packages.org.eclipse.ui.PlatformUI;
   // pre-set some variables
   database = "pdb";
   format = "pdb";
   style = "";
   query = "";
   description = "Please enter the pdb identifier.";
   blockcombo = true;
   // and show the wizard dialog with the WSDbfetch wizard
   wizard = new EBIWSDbfetchWizard(database, format, style, query, description, blockcombo);
   dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);

Sample script 3

Request the FASTA sequence for an identifier with the WSDbfetch Web Service, isolate its protein sequence and check its subcellular localization with SubLoc Web Service (client stub available in in the bc_webservices, too).

   // shorten identifiers
   Array = Packages.java.lang.reflect.Array;
   DbfetchServiceServiceLocator = Packages.uk.ac.ebi.www.ws.services.urn.Dbfetch.DbfetchServiceServiceLocator;
   SubLocServiceLocator = Packages.subloc.SOAPServiceLocator;
   // use WSDbfetch Web Service to get protein sequence for later usage (Ccp1 of Aspergillus fumigatus: uniprot:Q4WPF8)
   wsdbfetch = new DbfetchServiceServiceLocator();
   strarray = wsdbfetch.getUrnDbfetch().fetchData("uniprot:Q4WPF8", "fasta", "raw");
   // the answer is FASTA format
   // just remove the first line ;)
   var protein = "";
   for (i = 1; i < Array.getLength(strarray); i++) {
   	if (i != 1)
   		protein = protein + ("\n");
   	protein = protein + strarray[i];
   // show search result
   rhino.showMessage("Search result", "In FASTA format, first line removed:\n" + protein);
   // use SubLoc web service to make a localisation prediction
   subloc = new SubLocServiceLocator();
   sublocAPI = subloc.getAPI();
   psort_result = sublocAPI.psort_predict(protein);
   str = "Localisation: ";
   str = str + psort_result.getPrediction();
   str = str + "\nDetails:\n";
   str = str + psort_result.getDetail();
   // show prediction result
   rhino.showMessage("Result of PSORT", str);

Sample script 4

Run script as an eclipse job (in its own thread).

   	This is a sample script to test multithreaded scripting.
   	Scripts can optionally run as an eclipse job in their own thread.
   	However it is not save to access the main thread from another thread,
   	especially the GUI!
   	In this case it is required to prepare a Runnable object and execute
   	it with syncExec().
   	Note: it is currently not possible to cancel a rhino job; at least
   	the	GUI wont block.
   BioclipseConsole = Packages.net.bioclipse.util.BioclipseConsole;
   Thread = Packages.java.lang.Thread;
   Runnable = Packages.java.lang.Runnable;
   var i = 1;
   var r = new Runnable() {
   	run: function() {
   		// this is a blocking GUI element that will wait for user input!
   		rhino.showMessage("Test ASYNC!", "Hello World!");
   while(i < 4) {

Sample script 5

Download sequence from Genbank via a BioMoby Service, convert to Fasta using Biojava

Requires you to add dependencies in net.bioclipse.rhino to net.bioclipse.biomoby.ui and net.bioclipse.biojava.

   console = Packages.net.bioclipse.util.BioclipseConsole; 
   moby = Packages.net.bioclipse.biomoby.ui.scripts.MobyServiceScripting;
   biojava = Packages.net.bioclipse.biojava.scripts.BioJavaScripting;

Ouput looks like:

   Calling service...
   Read: 1 sequences. Returning first.
   >gi|111076|lcl|D31461.0|D31461 T-cell receptor delta chain BDN7, thymus - mouse (fragment).
   Rhino script done.

Script your own Plug-in

Want to script your own Plug-in? Make sure to export the relevant packages in your plugin (manifest, Runtime tab) so that Rhino can access them. There is no need to add a dependency in the Rhino plugin, because of the following addition to the Manifest.mf:

  DynamicImport-Package: *

I know that took Edrin quite some time to figure out. Good job!

Adding a simple namespace for your plugin

There is now an extension point that allows you to create a namespace and hence easy access to a plugins scripting-classes without the necessary and annoying "Packages.*" part. The example below is for making a class in net.bioclipse.biomoby.ui available from a rhino script.

Add an extension in net.bioclipse.biomoby.ui (plugin.xml):


The class must implement IScriptProvider and namespace is the desired namespace you like to have (see examples below). An example is the class net.bioclipse.biomoby.ui.scripts.MobyServiceScripting:

  public class MobyServiceScripting implements IScriptProvider{
     public void showMessage(String title, String message) {

To test, fire up Bioclipse with the plugins net.bioclipse.rhino and net.bioclipse.moby.ui selected. Create a file (e.g. helloMoby.js) and write the following:

  moby.showMessage("wee", "how");

Try to run it an: Voila! This makes it very easy to add new scripting commands.

--Ola 13:02, 5 November 2007 (CET)

Creating resources and open in editor

Some convenience methods:

  dl=">gi|111076|lcl|D31461.0|D31461 T-cell receptor delta chain BDN7, thymus - mouse (fragment).\nATYFCALMERVSRRGAPDKLVFGQGTQVTVEP";
  //Create a BioResource from the string
  myres=bioresource.create("111076.seq", dl);
  //Open in editor



Still in early stage, but fully working.

Download resources via EBI WSDBfetch Web service

Download PDBs:

  file.create("olala.pdb", mypdb);

Download RefSeq:

  //Seems BioJava cannot read this file in refseq format. Report?
  //myrefseq=ws.downloadRefseq("NM_000579", "refseq");
  file.create("NM_000579.seq", myrefseq);