JAL-970 JAL-1052 (comment about JAL-1140)
[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 // if features are loaded, feature display is automatically enabled
219 public void loadAnnotation(String annotation)
220
221 // add the given features or annotation to the given alignment view
222 // if features are loaded, feature display is automatically enabled
223 public void loadAnnotationFrom(AlignFrame alf, String annotation)
224
225 // parse the given string as a jalview or GFF features file and optionally enable feature display on the current alignment
226 // (v2.7.1)
227 public abstract void loadFeatures(String features, boolean autoenabledisplay)
228
229 // parse the given string as a jalview or GFF features file and optionally enable feature display on the given alignment
230 // (v2.7.1)
231 public abstract void loadFeaturesFrom(AlignFrame alf, String features, boolean autoenabledisplay)
232
233 // get the sequence features in the given format (Jalview or GFF)
234 public String getFeatures(String format)
235
236 // get the sequence features in alf in the given format (Jalview or GFF)
237 public String getFeaturesFrom(AlignFrame alf, String format)
238
239 // get current alignment's annotation as an annotation file
240 public String getAnnotation()
241
242 // get alignment view alf's annotation as an annotation file
243 public String getAnnotationFrom(AlignFrame alf)
244
245 // create a new view and return the alignFrame instance
246 public AlignFrame newView()
247
248 // create a new view named name and return the alignFrame instance
249 public AlignFrame newView(String name)
250
251 // create a new view on alf and return the alignFrame instance
252 public AlignFrame newViewFrom(AlignFrame alf)
253
254 // create a new view named name on alf 
255 // and return the alignFrame instance
256 public AlignFrame newViewFrom(AlignFrame alf, String name)
257
258 // load a new alignment 
259 // remember to store the AlignFrame object reference 
260 // if you want to manipulate the new alignment view.
261 public AlignFrame loadAlignment(String text, String title)
262
263
264 // register a javascript function to handle any alignment mouseover events
265 // listener is name of javascript function  which will be called
266 // with arguments [jalview.appletgui.AlignFrame,String(sequence id),
267 // String(column in alignment), String(position in sequence)]
268 // (v2.7)
269 public void setMouseoverListener(String listener)
270
271 // register a javascript function to handle mouseover events for specific alignframe
272 // (v2.7)
273 public void setMouseoverListener(AlignFrame af, String listener)
274
275 // register a javascript function to handle alignment selection events. 
276 // Events are generated when the user completes a selection event, or when
277 // the user deselects all selected regions.
278 // listener is name of javascript function  that will be called with arguments
279 //  [jalview.appletgui.AlignFrame, String(sequence set id), 
280 //   String(separator separated list of sequences which were selected), 
281 //   String(separator separated list of column ranges)]
282 // (v2.7)
283 public void setSelectionListener(String listener)
284
285 // register a selection listener for a specific alignment frame
286 // (v2.7)
287 public void setSelectionListener(AlignFrame af, String listener)
288
289 // register a javascript function to handle events normally routed 
290 // to a Jmol structure viewer.
291 // listener is a javascript function called with several different types 
292 // of arguments, dependent on the type of structure callback event. 
293 // See jalview.javascript.MouseOverStructureListener for full details or
294 // the embedded Jmol example.
295 // modelSet - is a separator separated list of PDB file URIs that this viewer is handling (where position in list equals model number in Jmol).
296 // (v2.7)
297 public void setStructureListener(String listener, String modelSet)
298
299 // remove any callback using the given listener function and associated with
300 // the given alignFrame (or null for all callbacks) (v2.7)
301 public void removeJavascriptListener(AlignFrame af, String listener)
302
303 // send a mouseover message to all the alignment windows associated with the
304 // given residue in the pdbfile (v2.7)
305 public void mouseOverStructure(String pdbResNum, String chain, String pdbfile)
306
307 // bind a pdb file to a sequence in the given alignFrame - this will be searched
308 // for sequences matching sequenceId. The PDB file in pdbFile is either the contents
309 // of a PDB file or a URI that can be used to retrieve the file, and the pdbEntryString
310 // is the user friendly name (or PDBID) shown in jalview's user interface.
311 // returns true if binding was as success (v2.7)
312 public boolean addPdbFile(AlignFrame alFrame, 
313     String sequenceId, String pdbEntryString, String pdbFile)
314
315 // adjust horizontal/vertical scroll in alf to the make 
316 // the given location the top left hand corner for given current view (v2.7)
317 public void scrollViewToIn(AlignFrame alf, String topRow, String leftHandColumn)
318
319 // adjust horizontal scroll in alf to the make 
320 // the given location the left hand corner for given current view (v2.7)
321 public void scrollViewToColumnIn(AlignFrame alf, String leftHandColumn)
322
323 // adjust horizontal/vertical scroll in alf to the make 
324 // the given location the top row for given current view (v2.7)
325 public void scrollViewToRowIn(AlignFrame alf, String topRow)
326
327
328 // return separator separated list of feature groups 
329 // on the current alignment
330 public String getFeatureGroups()
331
332 // return separator separated list of feature groups on alf
333 public String getFeatureGroupsOn(AlignFrame alf)
334
335 // return separator separated list of feature groups 
336 // either visible or hidden
337 public String getFeatureGroupsOfState(boolean state)
338
339 // return separator separated list of feature groups 
340 // either visible or hidden on alf
341 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean state)
342
343 // set the separator separated list of feature groups as 
344 // visible or hidden on the current alignment
345 public void setFeatureGroupState(String groupList, boolean state)
346
347 // set the separator separated list of feature groups 
348 // as visible or hidden on alf
349 public void setFeatureGroupStateOn(AlignFrame alf, String groupList, boolean state)
350
351 // helper functions
352
353 // Asynchronously retrieve next chunk of a large packet of data made available 
354 // for a JalviewLite event handler, or the empty string if no more data is available.
355 // messageclass and viewId are keys used to retrieve a specific message related
356 // to an event.  
357 // Use this in a javascript timer or GUI update thread to retrieve data without 
358 // blocking the JalviewLite applet. DO NOT USE IN THE CALLBACK THAT HANDLED THE EVENT
359 // (v2.7)
360 public String getJsMessage(String messageclass, String viewId)
361
362
363 // convert list to a separator separated array
364 public String arrayToSeparatorList(String[] list) 
365
366 // get a string array from a list
367 public String[] separatorListToArray(String list)
368
369 // get the current separator
370 public String getSeparator()
371
372 // set the current separator
373 public void setSeparator(String)
374
375 //// JalviewLite global state methods and fields
376
377 // return the build date as a string
378 public static String getBuildDate() 
379
380 // return the JalviewLite version as a string
381 public static String getVersion()
382
383 // debug flag - controls output to standard out
384 public static boolean debug
385
386 </pre> <!-- InstanceEndEditable --></td>
387     </tr>
388   </table>
389 </div>
390 </body>
391 <!-- InstanceEnd --></html>