JAL-1859 JAL-857 house keeping
[jalview.git] / examples / jalviewLiteJs.html
1 <!--
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18 -->
19
20 <!-- content start -->
21 <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>.
22 </p>
23                 <h3>Notes</h3>
24                 <ul>
25                 <li>Unfortunately Javascript - Java communication is not possible
26                 using Internet Explorer or Opera on Macs. Please use Safari or
27                 Firefox.</li>
28                 <li>If more than one Jalview window is open, Jalview returns the
29                 alignment in the active window, unless you provide an AlignFrame
30                 object reference.</li>
31                 <li>The alignment output format can be either Fasta, PFAM, Clustal,
32                 MSF, PIR, or BLC.</li>
33                 <li>When referring to the Jalview applet in javascript, you must
34                 either give Jalview a name in the applet tag or use the document.applets index.</li>
35                 <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.
36                 </li>
37                 </ul>
38                 <a name="api">
39                 <h1>JalviewLite's Javascript API</h1></a>
40                 <p>The following public methods on the jalviewLite applet are available to be called from javascript:</p>
41                 <pre>//get list of IDs of selected sequences
42 public String getSelectedSequences()
43
44 // list of IDs of selected sequences terminated by sep or, if sep is null, '&#172;' (&amp;#172;)
45 public String getSelectedSequences(sep)
46
47 // get list of selected sequences from specific alignFrame. (2.7)
48 public String getSelectedSequencesFrom(AlignFrame alf)
49 public String getSelectedSequencesFrom(AlignFrame alf, String sep)
50
51 // highlight a position in a specific sequence or a column in an alignment containing it
52 // provide ID sequence to highlight, integer (range highlighting will be supported in future versions)
53 // and flag indicating if position is an alignment column or given according to sequence numbering (2.7)
54 public void highlight(String sequenceId, String position, String alignedPosition)
55 public void highlightIn(AlignFrame alf, String sequenceId, String position, String alignedPosition)
56
57
58 // select regions of the currrent alignment frame using a list of sequence ids and a list of 
59 // column numbers and ranges (with minus sign indicating start-end) (separated by default separator) (2.7) 
60 public void select(String sequenceIds, String columns)
61 public void select(String sequenceIds, String columns, String sep)
62 public void selectIn(AlignFrame alf, String sequenceIds, String columns)
63 public void selectIn(AlignFrame alf, String sequenceIds, String columns, String sep)
64
65
66 // get selected sequences as alignment as format with or without start-end suffix
67 public String getSelectedSequencesAsAlignment(String format, boolean suffix)
68
69 // get selected sequences as alignment from given view as format with or without start-end suffix
70 public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf, String format, boolean suffix)
71
72 // get a separator separated list of sequence IDs reflecting the order of the current alignment (2.7)
73 public String getAlignmentOrder();
74 public String getAlignmentOrderFrom(AlignFrame alf);
75 public String getAlignmentOrderFrom(AlignFrame alf, String sep);
76
77 // re-order the current alignment using the given list of sequence IDs separated by sep
78 // undoName - is string to use when referring to ordering action in undo buffer
79 // returns 'true' if alignment was actually reordered. empty string if alignment did not contain sequences.
80 // (v2.7)
81 public String orderBy(String order, String undoName)
82 public String orderBy(String order, String undoName, String sep)
83 String orderAlignmentBy(AlignFrame alf, String order, String undoName, String sep)
84
85
86 // get alignment as format
87 public String getAlignment(String format)
88
89 // get alignment as format with jalview 
90 // start-end sequence suffix appended
91 public String getAlignment(String format, String suffix)
92
93 // get alignment displayed in alf as format
94 public String getAlignmentFrom(AlignFrame alf, String format)
95
96 // get alignment displayed in alf as format 
97 // with jalview start-end sequence suffix appended
98 public String getAlignmentFrom(AlignFrame alf, String format, String suffix)
99
100 // add the given features or annotation to the current alignment
101 // if features are loaded, feature display is automatically enabled
102 public void loadAnnotation(String annotation)
103
104 // add the given features or annotation to the given alignment view
105 // if features are loaded, feature display is automatically enabled
106 public void loadAnnotationFrom(AlignFrame alf, String annotation)
107
108 // parse the given string as a jalview or GFF features file and optionally enable feature display on the current alignment
109 // (v2.8)
110 public abstract void loadFeatures(String features, boolean autoenabledisplay)
111
112 // parse the given string as a jalview or GFF features file and optionally enable feature display on the given alignment
113 // (v2.8)
114 public abstract void loadFeaturesFrom(AlignFrame alf, String features, boolean autoenabledisplay)
115
116 // get the sequence features in the given format (Jalview or GFF)
117 public String getFeatures(String format)
118
119 // get the sequence features in alf in the given format (Jalview or GFF)
120 public String getFeaturesFrom(AlignFrame alf, String format)
121
122 // get current alignment's annotation as an annotation file
123 public String getAnnotation()
124
125 // get alignment view alf's annotation as an annotation file
126 public String getAnnotationFrom(AlignFrame alf)
127
128 // create a new view and return the alignFrame instance
129 public AlignFrame newView()
130
131 // create a new view named name and return the alignFrame instance
132 public AlignFrame newView(String name)
133
134 // create a new view on alf and return the alignFrame instance
135 public AlignFrame newViewFrom(AlignFrame alf)
136
137 // create a new view named name on alf 
138 // and return the alignFrame instance
139 public AlignFrame newViewFrom(AlignFrame alf, String name)
140
141 // load a new alignment 
142 // remember to store the AlignFrame object reference 
143 // if you want to manipulate the new alignment view.
144 public AlignFrame loadAlignment(String text, String title)
145
146
147 // register a javascript function to handle any alignment mouseover events
148 // listener is name of javascript function  which will be called
149 // with arguments [jalview.appletgui.AlignFrame,String(sequence id),
150 // String(column in alignment), String(position in sequence)]
151 // (v2.7)
152 public void setMouseoverListener(String listener)
153
154 // register a javascript function to handle mouseover events for specific alignframe
155 // (v2.7)
156 public void setMouseoverListener(AlignFrame af, String listener)
157
158 // register a javascript function to handle alignment selection events. 
159 // Events are generated when the user completes a selection event, or when
160 // the user deselects all selected regions.
161 // listener is name of javascript function  that will be called with arguments
162 //  [jalview.appletgui.AlignFrame, String(sequence set id), 
163 //   String(separator separated list of sequences which were selected), 
164 //   String(separator separated list of column ranges)]
165 // (v2.7)
166 public void setSelectionListener(String listener)
167
168 // register a selection listener for a specific alignment frame
169 // (v2.7)
170 public void setSelectionListener(AlignFrame af, String listener)
171
172 // register a javascript function to handle events normally routed 
173 // to a Jmol structure viewer.
174 // listener is a javascript function called with several different types 
175 // of arguments, dependent on the type of structure callback event. 
176 // See jalview.javascript.MouseOverStructureListener for full details or
177 // the embedded Jmol example.
178 // modelSet - is a separator separated list of PDB file URIs that this viewer is handling (where position in list equals model number in Jmol).
179 // (v2.7)
180 public void setStructureListener(String listener, String modelSet)
181
182 // remove any callback using the given listener function and associated with
183 // the given alignFrame (or null for all callbacks) (v2.7)
184 public void removeJavascriptListener(AlignFrame af, String listener)
185
186 // send a mouseover message to all the alignment windows associated with the
187 // given residue in the pdbfile (v2.7)
188 public void mouseOverStructure(String pdbResNum, String chain, String pdbfile)
189
190 // bind a pdb file to a sequence in the given alignFrame - this will be searched
191 // for sequences matching sequenceId. The PDB file in pdbFile is either the contents
192 // of a PDB file or a URI that can be used to retrieve the file, and the pdbEntryString
193 // is the user friendly name (or PDBID) shown in jalview's user interface.
194 // returns true if binding was as success (v2.7)
195 public boolean addPdbFile(AlignFrame alFrame, 
196     String sequenceId, String pdbEntryString, String pdbFile)
197
198 // adjust horizontal/vertical scroll in alf to the make 
199 // the given location the top left hand corner for given current view (v2.7)
200 public void scrollViewToIn(AlignFrame alf, String topRow, String leftHandColumn)
201
202 // adjust horizontal scroll in alf to the make 
203 // the given location the left hand corner for given current view (v2.7)
204 public void scrollViewToColumnIn(AlignFrame alf, String leftHandColumn)
205
206 // adjust horizontal/vertical scroll in alf to the make 
207 // the given location the top row for given current view (v2.7)
208 public void scrollViewToRowIn(AlignFrame alf, String topRow)
209
210
211 // return separator separated list of feature groups 
212 // on the current alignment
213 public String getFeatureGroups()
214
215 // return separator separated list of feature groups on alf
216 public String getFeatureGroupsOn(AlignFrame alf)
217
218 // return separator separated list of feature groups 
219 // either visible or hidden
220 public String getFeatureGroupsOfState(boolean state)
221
222 // return separator separated list of feature groups 
223 // either visible or hidden on alf
224 public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean state)
225
226 // set the separator separated list of feature groups as 
227 // visible or hidden on the current alignment
228 public void setFeatureGroupState(String groupList, boolean state)
229
230 // set the separator separated list of feature groups 
231 // as visible or hidden on alf
232 public void setFeatureGroupStateOn(AlignFrame alf, String groupList, boolean state)
233
234 // helper functions
235
236 // Asynchronously retrieve next chunk of a large packet of data made available 
237 // for a JalviewLite event handler, or the empty string if no more data is available.
238 // messageclass and viewId are keys used to retrieve a specific message related
239 // to an event.  
240 // Use this in a javascript timer or GUI update thread to retrieve data without 
241 // blocking the JalviewLite applet. DO NOT USE IN THE CALLBACK THAT HANDLED THE EVENT
242 // (v2.7)
243 public String getJsMessage(String messageclass, String viewId)
244
245
246 // convert list to a separator separated array
247 public String arrayToSeparatorList(String[] list) 
248
249 // get a string array from a list
250 public String[] separatorListToArray(String list)
251
252 // get the current separator
253 public String getSeparator()
254
255 // set the current separator
256 public void setSeparator(String)
257
258 //// JalviewLite global state methods and fields
259
260 // return the build date as a string
261 public static String getBuildDate() 
262
263 // return the JalviewLite version as a string
264 public static String getVersion()
265
266 // debug flag - controls output to standard out
267 public static boolean debug
268
269 </pre>
270 <!-- content end -->