note about ensuring callers of loadAlignment(..) save the new alignment
[jalview.git] / examples / jalviewLiteJs.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><!-- InstanceBegin template="/Templates/jtemplate.dwt" codeOutsideHTMLIsLocked="false" -->
3 <head>
4 <!-- InstanceBeginEditable name="doctitle" -->
5 <TITLE>JalviewLite API documentation</TITLE>
6 <!-- InstanceEndEditable --> 
7 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta http-equiv="keywords" content="jalview,multiple,sequence,alignment,editor,viewer,java,download,barton group,protein,dna,das,distributed annotation system">
8 <!-- InstanceBeginEditable name="head" -->
9 <!-- InstanceEndEditable --> 
10 <style type="text/css">
11 <!--
12 td {
13         font-family: Geneva, Arial, Helvetica, sans-serif;
14         font-size: 12px;
15 }
16 .plain {
17         font-family: Verdana, Arial, Helvetica, sans-serif;
18         font-size: 14px;
19         text-decoration: none;
20 }
21 .plain:hover{
22         background-color:#000000; color: #F2F2FF;
23 }
24  
25 -->
26 </style>
27 <script language="JavaScript">
28 function genHref()
29 {
30 var s1 = "ml:ljvwr", s2 = "athpai.g", s3 = "ioe@leo ", href="";
31 for(i=0; i<8; i++)
32 {href = href + s1.charAt(i) + s2.charAt(i) + s3.charAt(i);      }
33 window.location=href;
34 }
35 function getEventTarget(e)
36 {
37 if(!e)
38 e = window.event;
39 if(e.target)
40 return e.target;
41 return e.srcElement;
42 }
43 </script>
44 </head>
45 <body alink="#000000" vlink="#000000" link="#000000">
46 <script type="text/javascript">
47 var gaJsHost = (("https:" == document.location.protocol) ? 
48 "https://ssl." : "http://www.");
49 document.write(unescape("%3Cscript src='" + gaJsHost + 
50 "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
51 </script>
52 <script type="text/javascript">
53 try{
54 var pageTracker = _gat._getTracker("UA-9060947-1");
55 pageTracker._trackPageview();
56 } catch(err) {}
57 </script>
58 <div align="left"> 
59   <table width="805" height="100" cellpadding="5">
60     <tr>
61       <td background="../jalview.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.compbio.dundee.ac.uk" target="NEW"><img src="../uodc_r1_c1.gif" width="143" height="101" border="1"></a></td>
62     </tr>
63   </table>
64   <table width="805" border="0" cellpadding="5" cellspacing="5">
65     <tr> 
66       <td width="183" valign="top" bgcolor="#F2F2FF" border="5"> 
67           
68           <div align="center">
69           <table width="182" height="386" border="0" cellpadding="0" cellspacing="0">
70             <tr> 
71               <td align="left" valign="middle"><a href="../index.html" class="plain">Home</a></td>
72             </tr>
73             <tr> 
74               <td align="left" valign="middle"><a href="../overview.html" class="plain">Overview</a></td>
75             </tr>
76             <tr> 
77               <td align="left" valign="middle"><a href="../download.html" class="plain">Download</a></td>
78             </tr>
79             <tr> 
80               <td align="left" valign="middle"><a href="applets.html" class="plain">Applet 
81                 Version</a></td>
82             </tr>
83             <tr> 
84               <td align="left" valign="middle"><a href="examples.html" class="plain">Screenshots</a></td>
85             </tr>
86             <tr> 
87               <td align="left" valign="middle"><a href="../faq.html" class="plain">FAQ</a></td>
88             </tr>
89             <tr> 
90               <td align="left" valign="middle"><a href="../documentList.html" class="plain">Documentation</a></td>
91             </tr>
92             <tr>
93               <td align="left" valign="middle" ><a href="../releaseHistory.html" class="plain">Release 
94                 history</a></td>
95             </tr>
96             <tr> 
97               <td align="left" valign="middle"><a href="../source/source.html" class="plain">Source 
98                 Code</a></td>
99             </tr>
100                         <tr> 
101               <td align="left" valign="middle"><a href="../versions.html" class="plain">Development Version</a></td>
102             </tr>
103                         <tr> 
104               <td align="left" valign="middle"><a href="../links.html" class="plain">Links</a></td>
105             </tr>
106             <tr> 
107               <td align="left" valign="middle"><a href="http://www.jalview.org/mailman/listinfo/jalview-announce" class="plain" target="NEW">News 
108                 Mailing List</a></td>
109             </tr>
110             <tr>
111               <td align="left" valign="middle"><a
112             href="http://www.jalview.org/mailman/listinfo/jalview-discuss"
113             class="plain" target="NEW">Discussion Mailing List</a><br><br><em>Please send problems<br>and
114             bug reports to the discussion list.</em></td>
115             </tr>
116             <tr></tr>
117             <tr>
118               <!--<td align="left" valign="middle"><br>
119                 Please send problems<br>and
120             bug reports to:<br><a href="#" onClick="javascript:genHref();"><img src="../help.gif" width="123" height="19" border="0"></a></td>-->
121             </tr>
122           </table>
123         </div>
124         <div align="center"> <a href="http://www.bbsrc.ac.uk/" target="NEW"><br>
125           <img src="../bbsrc-new.gif" width="179" height="64" border="1"></a> 
126         </div>
127         </td>
128       <td valign="top" width="587" bgcolor="#F2F2FF"><!-- InstanceBeginEditable name="Contents" -->
129                 <p>&nbsp;</p>
130                 <strong>JalviewLite Javascript API<br></strong>
131                 <p>The jalviewLite applet's application programming interface (API) includes two components. A <a href="javascript/jalview.js">JalviewLite Javascript Library</a> and the <a href="#api">public methods on the JalviewLite applet</a>.
132                 <p>The best way to learn how to use the API is to see it in action on the demonstration pages below:</p>
133                 <ul>
134           <li><a href="formComplete.html">use Javascript to control and get data from JalviewLite</a></li>
135           <li><a href="linkedapplets_ng.html">use Javascript to make two jalviewLite instances talk to each other.</a></li>
136           <li><a href="embeddedWJmol.html">configure JalviewLite to talk to a Jmol applet on the page (EXPERIMENTAL! please provide feedback!).</a></li>
137           <li><a href="javascriptLaunch.html">launch JalviewLite from a javascript button</a></li>
138           
139                 </ul>
140                 <h4>Notes</h4>
141                 <ul>
142                 <li>Unfortunately Javascript - Java communication is not possible
143                 using Internet Explorer or Opera on Macs. Please use Safari or
144                 Firefox.</li>
145                 <li>If more than one Jalview window is open, Jalview returns the
146                 alignment in the active window, unless you provide an AlignFrame
147                 object reference.</li>
148                 <li>The alignment output format can be either Fasta, PFAM, Clustal,
149                 MSF, PIR, or BLC.</li>
150                 <li>When referring to the Jalview applet in javascript, you must
151                 either give Jalview a name in the applet tag or use the document.applets index.</li>
152                 <li>When creating javascript functions that are called by jalviewLite (e.g. the <em>oninit</em> parameter, or any mouseOver, selection or structureListener handlers), ensure they complete very quickly, and do not access any jalview API methods that might result in more javascript calls (this which will cause your browser to hang). If you need to do this, we suggest that jalviewLite callbacks are used to add new javascript events to a queue (e.g. using a Jquery timer callback) to avoid any concurrency issues.
153                 </li>
154                 </ul>
155                 <a name="api">
156                 <h4>JalviewLite's Java API</h4></a>
157                 <p>The following public methods on the jalviewLite applet are available to be called from javascript:</p>
158                 <pre>//get list of IDs of selected sequences
159 public String getSelectedSequences()
160
161 // list of IDs of selected sequences terminated by sep or, if sep is null, '&#172;' (&amp;#172;)
162 public String getSelectedSequences(sep)
163
164 // get list of selected sequences from specific alignFrame. (2.7)
165 public String getSelectedSequencesFrom(AlignFrame alf)
166 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
167
168 // highlight a position in a specific sequence or a column in an alignment containing it
169 // provide ID sequence to highlight, integer (range highlighting will be supported in future versions)
170 // and flag indicating if position is an alignment column or given according to sequence numbering (2.7)
171 public void highlight(String sequenceId, String position, String alignedPosition)
172 public void highlightIn(AlignFrame alf, String sequenceId, String position, String alignedPosition)
173
174
175 // select regions of the currrent alignment frame using a list of sequence ids and a list of 
176 // column numbers and ranges (with minus sign indicating start-end) (separated by default separator) (2.7) 
177 public void select(String sequenceIds, String columns)
178 public void select(String sequenceIds, String columns, String sep)
179 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
180 public void selectIn(AlignFrame alf, String sequenceIds, String columns, String sep)
181
182
183 // get selected sequences as alignment as format with or without start-end suffix
184 public String getSelectedSequencesAsAlignment(String format, boolean suffix)
185
186 // get selected sequences as alignment from given view as format with or without start-end suffix
187 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf, String format, boolean suffix)
188
189 // get a separator separated list of sequence IDs reflecting the order of the current alignment (2.7)
190 public String getAlignmentOrder();
191 public String getAlignmentOrderFrom(AlignFrame alf);
192 public String getAlignmentOrderFrom(AlignFrame alf, String sep);
193
194 // re-order the current alignment using the given list of sequence IDs separated by sep
195 // undoName - is string to use when referring to ordering action in undo buffer
196 // returns 'true' if alignment was actually reordered. empty string if alignment did not contain sequences.
197 // (v2.7)
198 public String orderBy(String order, String undoName)
199 public String orderBy(String order, String undoName, String sep)
200 String orderAlignmentBy(AlignFrame alf, String order, String undoName, String sep)
201
202
203 // get alignment as format
204 public String getAlignment(String format)
205
206 // get alignment as format with jalview 
207 // start-end sequence suffix appended
208 public String getAlignment(String format, String suffix)
209
210 // get alignment displayed in alf as format
211 public String getAlignmentFrom(AlignFrame alf, String format)
212
213 // get alignment displayed in alf as format 
214 // with jalview start-end sequence suffix appended
215 public String getAlignmentFrom(AlignFrame alf, String format, String suffix)
216
217 // add the given features or annotation to the current alignment
218 public void loadAnnotation(String annotation)
219
220 // add the given features or annotation to the given alignment view
221 public void loadAnnotationFrom(AlignFrame alf, String annotation)
222
223 // get the sequence features in the given format (Jalview or GFF)
224 public String getFeatures(String format)
225
226 // get the sequence features in alf in the given format (Jalview or GFF)
227 public String getFeaturesFrom(AlignFrame alf, String format)
228
229 // get current alignment's annotation as an annotation file
230 public String getAnnotation()
231
232 // get alignment view alf's annotation as an annotation file
233 public String getAnnotationFrom(AlignFrame alf)
234
235 // create a new view and return the alignFrame instance
236 public AlignFrame newView()
237
238 // create a new view named name and return the alignFrame instance
239 public AlignFrame newView(String name)
240
241 // create a new view on alf and return the alignFrame instance
242 public AlignFrame newViewFrom(AlignFrame alf)
243
244 // create a new view named name on alf 
245 // and return the alignFrame instance
246 public AlignFrame newViewFrom(AlignFrame alf, String name)
247
248 // load a new alignment 
249 // remember to store the AlignFrame object reference 
250 // if you want to manipulate the new alignment view.
251 public AlignFrame loadAlignment(String text, String title)
252
253
254 // register a javascript function to handle any alignment mouseover events
255 // listener is name of javascript function  which will be called
256 // with arguments [jalview.appletgui.AlignFrame,String(sequence id),
257 // String(column in alignment), String(position in sequence)]
258 // (v2.7)
259 public void setMouseoverListener(String listener)
260
261 // register a javascript function to handle mouseover events for specific alignframe
262 // (v2.7)
263 public void setMouseoverListener(AlignFrame af, String listener)
264
265 // register a javascript function to handle alignment selection events. 
266 // Events are generated when the user completes a selection event, or when
267 // the user deselects all selected regions.
268 // listener is name of javascript function  that will be called with arguments
269 //  [jalview.appletgui.AlignFrame, String(sequence set id), 
270 //   String(separator separated list of sequences which were selected), 
271 //   String(separator separated list of column ranges)]
272 // (v2.7)
273 public void setSelectionListener(String listener)
274
275 // register a selection listener for a specific alignment frame
276 // (v2.7)
277 public void setSelectionListener(AlignFrame af, String listener)
278
279 // register a javascript function to handle events normally routed 
280 // to a Jmol structure viewer.
281 // listener is a javascript function called with several different types 
282 // of arguments, dependent on the type of structure callback event. 
283 // See jalview.javascript.MouseOverStructureListener for full details or
284 // the embedded Jmol example.
285 // modelSet - is a separator separated list of PDB file URIs that this viewer is handling (where position in list equals model number in Jmol).
286 // (v2.7)
287 public void setStructureListener(String listener, String modelSet)
288
289 // remove any callback using the given listener function and associated with
290 // the given alignFrame (or null for all callbacks) (v2.7)
291 public void removeJavascriptListener(AlignFrame af, String listener)
292
293 // send a mouseover message to all the alignment windows associated with the
294 // given residue in the pdbfile (v2.7)
295 public void mouseOverStructure(String pdbResNum, String chain, String pdbfile)
296
297 // bind a pdb file to a sequence in the given alignFrame - this will be searched
298 // for sequences matching sequenceId. The PDB file in pdbFile is either the contents
299 // of a PDB file or a URI that can be used to retrieve the file, and the pdbEntryString
300 // is the user friendly name (or PDBID) shown in jalview's user interface.
301 // returns true if binding was as success (v2.7)
302 public boolean addPdbFile(AlignFrame alFrame, 
303     String sequenceId, String pdbEntryString, String pdbFile)
304
305 // adjust horizontal/vertical scroll in alf to the make 
306 // the given location the top left hand corner for given current view (v2.7)
307 public void scrollViewToIn(AlignFrame alf, String topRow, String leftHandColumn)
308
309 // adjust horizontal scroll in alf to the make 
310 // the given location the left hand corner for given current view (v2.7)
311 public void scrollViewToColumnIn(AlignFrame alf, String leftHandColumn)
312
313 // adjust horizontal/vertical scroll in alf to the make 
314 // the given location the top row for given current view (v2.7)
315 public void scrollViewToRowIn(AlignFrame alf, String topRow)
316
317
318 // return separator separated list of feature groups 
319 // on the current alignment
320 public String getFeatureGroups()
321
322 // return separator separated list of feature groups on alf
323 public String getFeatureGroupsOn(AlignFrame alf)
324
325 // return separator separated list of feature groups 
326 // either visible or hidden
327 public String getFeatureGroupsOfState(boolean state)
328
329 // return separator separated list of feature groups 
330 // either visible or hidden on alf
331 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean state)
332
333 // set the separator separated list of feature groups as 
334 // visible or hidden on the current alignment
335 public void setFeatureGroupState(String groupList, boolean state)
336
337 // set the separator separated list of feature groups 
338 // as visible or hidden on alf
339 public void setFeatureGroupStateOn(AlignFrame alf, String groupList, boolean state)
340
341 // helper functions
342
343 // Asynchronously retrieve next chunk of a large packet of data made available 
344 // for a JalviewLite event handler, or the empty string if no more data is available.
345 // messageclass and viewId are keys used to retrieve a specific message related
346 // to an event.  
347 // Use this in a javascript timer or GUI update thread to retrieve data without 
348 // blocking the JalviewLite applet. DO NOT USE IN THE CALLBACK THAT HANDLED THE EVENT
349 // (v2.7)
350 public String getJsMessage(String messageclass, String viewId)
351
352
353 // convert list to a separator separated array
354 public String arrayToSeparatorList(String[] list) 
355
356 // get a string array from a list
357 public String[] separatorListToArray(String list)
358
359 // get the current separator
360 public String getSeparator()
361
362 // set the current separator
363 public void setSeparator(String)
364
365 //// JalviewLite global state methods and fields
366
367 // return the build date as a string
368 public static String getBuildDate() 
369
370 // return the JalviewLite version as a string
371 public static String getVersion()
372
373 // debug flag - controls output to standard out
374 public static boolean debug
375
376 </pre> <!-- InstanceEndEditable --></td>
377     </tr>
378   </table>
379 </div>
380 </body>
381 <!-- InstanceEnd --></html>