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