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 = 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);
   dialog.open();

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;
   
   //rhino.sleep(1000);
   Thread.sleep(1000);
   
   var r = new Runnable() {
   	run: function() {
   		// this is a blocking GUI element that will wait for user input!
   		rhino.showMessage("Test ASYNC!", "Hello World!");
   	}
   };
   
   rhino.syncExec(r);
   
   while(i < 4) {
   	Thread.sleep(1000);
   	i++;
   	BioclipseConsole.writeToConsole(":)");
   }


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;
   
   prot=moby.downloadGenbank("NCBI_GI","111076");
   seq=biojava.parseString(prot);
   fasta=biojava.toFasta(seq);
   
   console.writeToConsole(fasta);

Ouput looks like:

   Calling service...
   Done.
   Read: 1 sequences. Returning first.
   >gi|111076|lcl|D31461.0|D31461 T-cell receptor delta chain BDN7, thymus - mouse (fragment).
   ATYFCALMERVSRRGAPDKLVFGQGTQVTVEP
   
   undefined
   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):

<extension
     point="net.bioclipse.rhino.scripting">
  <ScriptContribution
        class="net.bioclipse.biomoby.ui.scripts.MobyServiceScripting"
        id="net.bioclipse.biomoby.ui.scripts.MobyServiceScripting"
        namespace="moby">
  </ScriptContribution>
</extension>

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) {
        MessageDialog.openInformation(
           getShell(),
           title,
           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:

  rhino.showMessage("wee");
  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
  editor.open(myres);

and:

  editor.open("1ale.pdb");

Still in early stage, but fully working.


Download resources via EBI WSDBfetch Web service

Download PDBs:

  mypdb=ws.downloadPDB("1ale");
  file.create("olala.pdb", mypdb);
  editor.open("olala.pdb");

Download RefSeq:

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