Download Scripting Bioclipse

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Scripting Bioclipse
Johannes Wagener
Outline
1.
Introduction
2.
Tutorial Session
1.
2.
3.
4.
5.
6.
3.
The Basics (if, for, while, int, String, “Hello World”…)
Accessing and controlling Java, Bioclipse and Plug-In API
Exploiting Eclipse’s API to modify Bioclipse GUI
Run scripts in separate threads
Loading and using external .jar(s)
Writing a realistic workflow test case
Discussion
Introduction
bc_jmol
Plug-In
bc_biojava
Plug-In
bc_cdk
Plug-In
bc_*
Plug-In
Bioclipse
bc_rhino
Plug-In
Introduction
bc_jmol
Plug-In
bc_biojava
Plug-In
bc_cdk
Plug-In
bc_*
Plug-In
Bioclipse
bc_rhino
Plug-In
Mozilla Rhino
JavaScript for
Java
Introduction
bc_jmol
Plug-In
bc_biojava
Plug-In
bc_cdk
Plug-In
bc_*
Plug-In
Bioclipse
bc_rhino
Plug-In
Mozilla Rhino
JavaScript for
Java
• OS License: MPL or GPL
• Powerful scripting engine
• Actively developed
since ~10 years
• Used in many other
projects
http://www.mozilla.org/rhino/
Introduction
bc_jmol
Plug-In
bc_biojava
Plug-In
bc_cdk
Plug-In
bc_*
Plug-In
Bioclipse
bc_rhino
Plug-In
Mozilla Rhino
JavaScript for
Java
• OS License: MPL or GPL
• Powerful scripting engine
• Actively developed
since ~10 years
• Used in many other
projects
http://www.mozilla.org/rhino/
Introduction
bc_jmol
Plug-In
bc_biojava
Plug-In
bc_cdk
Plug-In
External
.jar(s)
bc_*
Plug-In
Bioclipse
bc_rhino
Plug-In
Mozilla Rhino
JavaScript for
Java
• OS License: MPL or GPL
• Powerful scripting engine
• Actively developed
since ~10 years
• Used in many other
projects
http://www.mozilla.org/rhino/
The bc_rhino Plug-In offers…
• access to all Packages, Classes and Interfaces
in the Classpath:
–
–
–
–
–
Java Runtime
Eclipse (parts)
Bioclipse
Bioclipse Plug-Ins
Other Libraries (dynamic loading)
• “quick and dirty” solutions
Introduction
JavaScript != Java
• an implementation of the ECMAScript standard
• the syntax is just similar to Java
Tutorials
1.
The Basics (if, for, while, int, String, “Hello World”…)
2.
Accessing and controlling Java, Bioclipse and Plug-In API
3.
Exploiting Eclipse’s API to modify Bioclipse GUI
4.
Run scripts in separate threads
5.
Loading and using external .jar(s)
6.
Writing a realistic workflow test case
The Basics
• In the Bioclipse Resource Navigator create a new file called “helloworld.js”
• Double-click the file (an editor pops up)
Task: Write a program that prints “Hello Bioclipse” to the Bioclipse Console
Suggested Objects, Classes and Functions:
The rhino Object and two of its Functions:
rhino.showMessage(title, text);
rhino.showMessage(text);
A (static) Function within a Bioclipse Package/Class:
net.bioclipse.util.BioclipseConsole.writeToConsole(text);
To access such Classes in the Classpath add “Package.” in front !!
The Basics
// the rhino object contains 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) {
BioclipseConsole.writeToConsole("Hello Bioclipse!");
i++;
}
i = i + 1;
Tutorials
1.
The Basics (if, for, while, int, String, “Hello World”…)
2.
Accessing and controlling Java, Bioclipse and Plug-In API
3.
Exploiting Eclipse’s API to modify Bioclipse GUI
4.
Run scripts in separate threads
5.
Loading and using external .jar(s)
6.
Writing a realistic workflow test case
Accessing and controlling Java, Bioclipse
and Plug-In API
• In the Bioclipse Resource Navigator create a new file called
“ControlBioclipseGUI.js”
Task: Write a program that shows the WSDbfetch wizard dialog
Accessing and controlling Java, Bioclipse
and Plug-In API
Task: Write a program that shows the WSDbfetch wizard dialog
Some tips:
1. Required Packages/Classes:
net.bioclipse.plugins.bc_webservices.wizards.newwizards.
EBIWSDbfetchWizard;
org.eclipse.jface.wizard.WizardDialog;
rhino.getShell();
2. You must create Objects of the Classes:
myObject = new TheClass(parameter1, parameter2, ...);
3. Don’t forget to put the “Package.” in front of the Classpath Packages
Accessing and controlling Java, Bioclipse
and Plug-In API
// to have short identifiers
EBIWSDbfetchWizard =
Packages.net.bioclipse.plugins.bc_webservices.wizards.newwizards.EBI
WSDbfetchWizard;
WizardDialog = Packages.org.eclipse.jface.wizard.WizardDialog;
// 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(rhino.getShell(), wizard);
dialog.open();
Tutorials
1.
The Basics (if, for, while, int, String, “Hello World”…)
2.
Accessing and controlling Java, Bioclipse and Plug-In API
3.
Exploiting Eclipse’s API to modify Bioclipse GUI
4.
Run scripts in separate threads
5.
Loading and using external .jar(s)
6.
Writing a realistic workflow test case
Exploiting Eclipse’s API to modify Bioclipse
GUI
• In the Bioclipse Resource Navigator create a new file called
“AddActionToGUI.js”
Task: Write a program that adds an additional menu entry to the Bioclipse
Menubar. On selection the entry should show a “hello world” message.
Exploiting Eclipse’s API to modify Bioclipse
GUI
SWT = Packages.org.eclipse.swt.SWT;
MenuItem = Packages.org.eclipse.swt.widgets.MenuItem;
Listener = Packages.org.eclipse.swt.widgets.Listener;
var shell = rhino.getShell();
shell.getMenuBar();
// ... To be continued...
Exploiting Eclipse’s API to modify Bioclipse
GUI
SWT = Packages.org.eclipse.swt.SWT;
MenuItem = Packages.org.eclipse.swt.widgets.MenuItem;
Listener = Packages.org.eclipse.swt.widgets.Listener;
var
var
var
var
shell = rhino.getShell();
menubar = shell.getMenuBar();
menubaritem = menubar.getItem(2);
menu = menubaritem.getMenu();
var action = new Listener() {
handleEvent: function(e) {
rhino.showMessage("Bioclipse", "Hello Action :)");
}
}
item = new MenuItem(menu, SWT.PUSH);
item.addListener(SWT.Selection, action);
item.setText("Rhino Test");
Tutorials
1.
The Basics (if, for, while, int, String, “Hello World”…)
2.
Accessing and controlling Java, Bioclipse and Plug-In API
3.
Exploiting Eclipse’s API to modify Bioclipse GUI
4.
Run scripts in separate threads
5.
Loading and using external .jar(s)
6.
Writing a realistic workflow test case
Run scripts in separate threads
Task:
1) Learn how to run scripts in a separate thread.
2) Learn how to cancel such long lasting scripts.
3) Learn how to access the main thread from the separate thread.
Run scripts in separate threads
1. Learn how to run scripts in a separate thread.
BioclipseConsole = Packages.net.bioclipse.util.BioclipseConsole;
// sleep for 5 seconds
rhino.sleep(5000);
BioclipseConsole.writeToConsole("done!");
Run scripts in separate threads
1. Learn how to run scripts in a separate thread.
BioclipseConsole = Packages.net.bioclipse.util.BioclipseConsole;
// sleep for 5 seconds
rhino.sleep(5000);
BioclipseConsole.writeToConsole("done!");
Run scripts in separate threads
1. Learn how to run scripts in a separate thread.
BioclipseConsole = Packages.net.bioclipse.util.BioclipseConsole;
// sleep for 5 seconds
rhino.sleep(5000);
BioclipseConsole.writeToConsole("done!");
Run scripts in separate threads
2) Learn how to cancel such long lasting scripts.
...
if (rhino.isCanceled() == true) {
// abort the script
}
Run scripts in separate threads
2) Learn how to cancel such long lasting scripts.
BioclipseConsole = Packages.net.bioclipse.util.BioclipseConsole;
var i = 1;
var output = ":)";
while(i < 10) {
// check if script was canceled by the user
if (rhino.isCanceled() == true) {
BioclipseConsole.writeToConsole("The job was canceled!");
break;// exit the loop.
}
rhino.sleep(1000);
i++;
BioclipseConsole.writeToConsole(output);
output = " " + output;
}
Run scripts in separate threads
3) Learn how to access the main thread from the separate thread.
BioclipseConsole = Packages.net.bioclipse.util.BioclipseConsole;
Runnable = Packages.java.lang.Runnable;
BioclipseConsole.writeToConsole("Thread starts ... ");
var r = new Runnable() {
run: function() {
// this is a blocking GUI element: waits for user input!
BioclipseConsole.writeToConsole("Thread waits for user...");
rhino.showMessage("Test ASYNC!", "Hello World!");
}
};
rhino.syncExec(r);
BioclipseConsole.writeToConsole("Thread continues... and finishes");
Tutorials
1.
The Basics (if, for, while, int, String, “Hello World”…)
2.
Accessing and controlling Java, Bioclipse and Plug-In API
3.
Exploiting Eclipse’s API to modify Bioclipse GUI
4.
Run scripts in separate threads
5.
Loading and using external .jar(s)
6.
Writing a realistic workflow test case
Loading and using external .jar(s)
Task:
Load the “aacode.jar” and use two of its functions to convert the
amino acid sequence “MAAQSKLLPP" from one letter code to three
letter code and back:
rhino.load(library);
Details about “aacode.jar”:
aacode.AAConverter
public String toThreeLetterCode(String input)
public String toOneLetterCode(String input)
Loading and using external .jar(s)
// load the AAConverter jar
rhino.load("c:\\aacode.jar");
AAConverter = Packages.aacode.AAConverter;
var protein = "maaqskllpp";
var three_code = AAConverter.toThreeLetterCode(protein);
rhino.showMessage("Three letter code:\n" + three_code);
var one_code = AAConverter.toOneLetterCode(three_code);
rhino.showMessage("Back to one letter code:\n" + one_code);
Tutorials
1.
The Basics (if, for, while, int, String, “Hello World”…)
2.
Accessing and controlling Java, Bioclipse and Plug-In API
3.
Exploiting Eclipse’s API to modify Bioclipse GUI
4.
Run scripts in separate threads
5.
Loading and using external .jar(s)
6.
Writing a realistic workflow test case
Writing a realistic workflow test case
var inputfile = "c:/FASTA/export1.txt";
var outputfile = "c:/FASTA/export1-subloc-result.txt";
(...)
contents = LoadFASTAFile(inputfile);
// use SubLoc web service to make a localisation prediction
subloc = new SubLocServiceLocator();
sublocAPI = subloc.getAPI();
z = 0;
while(contents[z] != null && rhino.isCanceled() != true) {
// show currently analysed data
BioclipseConsole.writeToConsole(contents[z] + ": " + contents[z+1]);
// do the analysation
psort_result = sublocAPI.psort_predict(contents[z+1]);
result = psort_result.getPrediction();
details = psort_result.getDetail();
WriteResultFile(outputfile, contents[z], result, details);
z = z+2;
// and sleep for a second to not spam the webservice
rhino.sleep(1000);
}
BioclipseConsole.writeToConsole("Analysation of " + inputfile + " done!");
Discussion
Questions?