3 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
4 * Copyright (C) 2014 The Jalview Authors
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/>.
18 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 <title>Groovy Shell</title>
25 <strong>The Groovy Shell</strong>
28 <a href="http://groovy.codehaus.org/">Groovy</a> is an "<em>agile
29 and dynamic language for the Java platform</em>". The groovy
30 scripting language makes it extremely easy to programmatically
31 interact with Java programs, in much the same way that Javascript is
32 used to generate and interact with applets and other objects on the
36 <strong><em>Getting Groovy...</em>
37 </strong><br> Jalview Groovy support is only possible if the core groovy
38 jars which include the GroovyShell are present on the CLASSPATH when
42 The jars are obtained from the <em>embedded</em> directory within the
43 <a href="http://dist.codehaus.org/groovy/distributions">groovy
44 distribution</a>. The easiest way of adding them to the Jalview classpath
45 is to download and build jalview from it's source distribution, and
46 then add the groovy-all-*.jar to the lib directory whose path is given
47 in the java.ext.dirs property.
50 <strong>Opening Jalview's Groovy Console</strong><br>If groovy is
51 available, then the <strong>Tools→Groovy Console...</strong>
52 menu entry will be available from the Jalview Desktop's drop-down
53 menu. Selecting this will open the <a
54 href="http://groovy.codehaus.org/Groovy+Console">Groovy Console</a>
55 which allows you to interactively execute Groovy scripts within the
56 Jalview run-time environment.
59 <strong>Executing groovy scripts on Jalview startup</strong><br>
60 The -groovy <script> option on the <a href="commandline.html" />
61 Jalview command line</a> will execute the contents of <script>.
62 <script> may be a file, a URL, or alternatively if it is
63 "STDIN" then the standard input will be used.<br>
64 <em>Note: The groovy script will be executed <strong>after</strong>
65 any data is loaded, and <strong>before</strong> images or any output
66 files are written. This allows you to perform customised jalview
67 analysis workflows with groovy.</em>
70 <strong>Access to Jalview's functions from Groovy Scripts</strong><br>
71 There is as yet no properly defined scripting interface to Jalview,
72 but all the public methods of the jalview class hierarchy can be
73 called from Groovy scripts. The access point for this is the <strong>Jalview</strong>
74 object defined in the groovy environent which corresponds to the
75 <pre>jalview.gui.Desktop</pre>
76 object which manages all the Jalview windows.
78 Here's an example to get you started:
81 <li>Getting the title, alignment and first sequence from the
82 current alignFrame<br> <pre>
83 def alf = Jalview.getAlignframes();
84 print alf[0].getTitle();
85 def alignment = alf[0].viewport.alignment;
86 def seq = alignment.getSequenceAt(0);
88 <li>When running a groovy script from the command line, the alignment that was just loaded can be referred to like so:<br><pre>
89 print currentAlFrame.getTitle();</pre>