3 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
4 * Copyright (C) $$Year-Rel$$ 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
11 * of the License, or (at your option) any later version.
13 * Jalview is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 <title>Groovy Shell</title>
27 <strong>The Groovy Shell</strong>
30 Groovy (<a href="http://www.groovy-lang.org/">www.groovy-lang.org</a>)
31 is an "<em>agile and dynamic language for the Java
32 platform</em>". The groovy scripting language makes it extremely
33 easy to programmatically interact with Java programs, in much the
34 same way that Javascript is used to generate and interact with
35 applets and other objects on the page.
38 <em>Getting Groovy...</em><br> Jalview comes with an embedded
39 installation of Groovy. Just select <strong>Tools→Groovy
40 Console...</strong> from the Jalview Desktop's drop-down menu. After a
41 short pause, you should then see the <a
42 href="https://groovy-lang.org/groovyconsole.html">Groovy
43 Console</a> appear. This allows you to interactively execute Groovy
44 scripts whilst Jalview is running. We've also provided a <strong>Calculations→Execute
45 Groovy Script</strong> button so you can execute the currently loaded
46 groovy script whilst viewing an alignment.
49 <strong>Executing groovy scripts on Jalview startup</strong><br>
50 The --groovy <script> option on the <a href="commandline.html">
51 Jalview command line</a> will execute the contents of <script>.
52 <script> may be a file, a URL, or alternatively if it is
53 "STDIN" then the standard input will be used.<br> <em>Note:
54 The groovy script will be executed <strong>after</strong> any data
55 is loaded, and <strong>before</strong> images or any output files
56 are written. This allows you to perform customised Jalview
57 analysis workflows with groovy.
61 <strong>Access to Jalview's functions from Groovy Scripts</strong><br>
62 The scripting interface to Jalview is still a work in progress, so
63 we recommend you also take a look at Jalview's source, since all the
64 public methods of the jalview class hierarchy can be called from
65 Groovy scripts. In addition, the following objects are also defined:
70 <li><strong>Jalview</strong> - this is bound to <code>jalview.bin.Jalview</code>.<br />Useful
73 <li>Jalview.getAlignFrames() - returns a list of
74 jalview.gui.AlignFrame objects</li>
75 <li>Jalview.getCurrentAlignFrame() - returns the alignment
76 window which is currently being looked at by the user</li>
78 <li><strong>currentAlFrame</strong> - this is only defined when
79 running a Groovy script via the --groovy command line argument. It
80 returns the first alignment window created after acting on the
81 other arguments passed on the command line.</li>
84 <em>A simple script</em><br />
86 <li>Getting the title, alignment and first sequence from the
87 current alignFrame<br> <pre>
88 def alf = Jalview.getAlignFrames();
89 print alf[0].getTitle();
90 def alignment = alf[0].viewport.alignment;
91 def seq = alignment.getSequenceAt(0);
94 <li>If you wanted to do the same thing from the command line,
95 you can refer to alignment that was just loaded with
96 currentAlFrame:<br> <pre>
97 print currentAlFrame.getTitle();</pre>
100 <em>Example scripts</em><br />If you have downloaded the
101 InstallAnywhere version of Jalview, you can find additional groovy
102 scripts in the examples/groovy subfolder of the installation
103 directory. The examples are also available at <a
104 href="https://www.jalview.org/examples/groovy">https://www.jalview.org/examples/groovy</a>.
107 <em>Using Groovy to add new Alignment Calculations</em><br />We've
108 simplified the alignment analysis programming interface in Jalview
109 2.10 to make it easy for you to add your own dynamic annotation
110 tracks with Groovy. Have a look at the <a
111 href="../groovy/featuresCounter.html">featuresCounter.groovy</a>
112 example for more information.
114 <p><a name="groovyColours"/>
115 <em>Creating custom colourschemes</em><br/>
116 You can create your own alignment colourschemes with a groovy script. We've provided two examples:<br/>
118 <li><a href="https://www.jalview.org/examples/groovy/colourConserved.groovy">colourConserved.groovy</a> creates an 'Conserved' colourscheme - similar to the classic <a href="http://www.nrbsc.org/old/gfx/genedoc/">GeneDOC</a> shading model.</li>
119 <li><a href="https://www.jalview.org/examples/groovy/colourUnconserved.groovy">colourUnconserved.groovy</a> creates an 'Unconserved' colourscheme, where any unconserved residues are coloured pink.</li>