JAL-1432 updated copyright notices
[jalview.git] / help / html / features / groovy.html
1 <html>
2 <!--
3  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
4  * Copyright (C) 2014 The Jalview Authors
5  * 
6  * This file is part of Jalview.
7  * 
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.
11  *  
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.
16  * 
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.
19 -->
20 <head>
21 <title>Groovy Shell</title>
22 </head>
23 <body>
24         <p>
25                 <strong>The Groovy Shell</strong>
26         </p>
27         <p>
28                 <a href="http://groovy.codehaus.org/">Groovy</a> is an &quot;<em>agile
29                         and dynamic language for the Java platform</em>&quot;. 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
33                 page.
34         </p>
35         <p>
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
39                 Jalview is started.
40         </p>
41         <p>
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.
48         </p>
49         <p>
50                 <strong>Opening Jalview's Groovy Console</strong><br>If groovy is
51                 available, then the <strong>Tools&#8594;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.
57         </p>
58         <p>
59                 <strong>Executing groovy scripts on Jalview startup</strong><br>
60                 The -groovy &lt;script&gt; option on the <a href="commandline.html" />
61                 Jalview command line</a> will execute the contents of &lt;script&gt;.
62                 &lt;script&gt; may be a file, a URL, or alternatively if it is
63                 &quot;STDIN&quot; 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>
68         </p>
69         <p>
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.
77         </p>
78         Here's an example to get you started:
79         <br>
80         <ul>
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);
87 </pre></li>
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>
90         </ul>
91         </p>
92
93         <p>&nbsp;</p>
94 </body>
95 </html>