3 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
4 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
6 * This file is part of Jalview.
8 * Jalview is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 <title>Groovy Shell</title>
24 <strong>The Groovy Shell</strong>
27 <a href="http://groovy.codehaus.org/">Groovy</a> is an "<em>agile
28 and dynamic language for the Java platform</em>". The groovy
29 scripting language makes it extremely easy to programmatically
30 interact with Java programs, in much the same way that Javascript is
31 used to generate and interact with applets and other objects on the
35 <strong><em>Getting Groovy...</em>
36 </strong><br> Jalview Groovy support is only possible if the core groovy
37 jars which include the GroovyShell are present on the CLASSPATH when
41 The jars are obtained from the <em>embedded</em> directory within the
42 <a href="http://dist.codehaus.org/groovy/distributions">groovy
43 distribution</a>. The easiest way of adding them to the Jalview classpath
44 is to download and build jalview from it's source distribution, and
45 then add the groovy-all-*.jar to the lib directory whose path is given
46 in the java.ext.dirs property.
49 <strong>Opening Jalview's Groovy Console</strong><br>If groovy is
50 available, then the <strong>Tools→Groovy Console...</strong>
51 menu entry will be available from the Jalview Desktop's drop-down
52 menu. Selecting this will open the <a
53 href="http://groovy.codehaus.org/Groovy+Console">Groovy Console</a>
54 which allows you to interactively execute Groovy scripts within the
55 Jalview run-time environment.
58 <strong>Executing groovy scripts on Jalview startup</strong><br>
59 The -groovy <script> option on the <a href="commandline.html" />
60 Jalview command line</a> will execute the contents of <script>.
61 <script> may be a file, a URL, or alternatively if it is
62 "STDIN" then the standard input will be used.<br>
63 <em>Note: The groovy script will be executed <strong>after</strong>
64 any data is loaded, and <strong>before</strong> images or any output
65 files are written. This allows you to perform customised jalview
66 analysis workflows with groovy.</em>
69 <strong>Access to Jalview's functions from Groovy Scripts</strong><br>
70 There is as yet no properly defined scripting interface to Jalview,
71 but all the public methods of the jalview class hierarchy can be
72 called from Groovy scripts. The access point for this is the <strong>Jalview</strong>
73 object defined in the groovy environent which corresponds to the
74 <pre>jalview.gui.Desktop</pre>
75 object which manages all the Jalview windows.
77 Here's an example to get you started:
80 <li>Getting the title, alignment and first sequence from the
81 current alignFrame<br> <pre>
82 def alf = Jalview.getAlignframes();
83 print alf[0].getTitle();
84 def alignment = alf[0].viewport.alignment;
85 def seq = alignment.getSequenceAt(0);
87 <li>When running a groovy script from the command line, the alignment that was just loaded can be referred to like so:<br><pre>
88 print currentAlFrame.getTitle();</pre>