1 /*******************************************************************************
2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
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.
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.
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 *******************************************************************************/
18 package jalview.javascript;
20 import jalview.appletgui.AlignFrame;
23 * The following public methods may be called
24 * externally, eg via javascript in an HTML page.
26 * <br><em>TODO: introduce abstract interface for jalview.appletgui.AlignFrame</em><br>
28 * Most function arguments are strings, which contain serialised versions of lists.
29 * Lists of things are separated by a separator character - either the default or a user supplied one.
30 * Ranges and positions on an alignment or sequence can be specified as a list, where an item containing a single number is a single position, and an item like 1-2 specifies columns 1 and 2 as a range.
37 public interface JalviewLiteJsApi
41 * @return String list of selected sequence IDs, each terminated by the
42 * 'boolean not' character (""+0x00AC) or (¬)
44 public abstract String getSelectedSequences();
48 * separator string or null for default
49 * @return String list of selected sequence IDs, each terminated by given
52 public abstract String getSelectedSequences(String sep);
56 * alignframe containing selection
57 * @return String list of selected sequence IDs, each terminated by current
58 * default separator sequence
61 public abstract String getSelectedSequencesFrom(AlignFrame alf);
64 * get list of selected sequence IDs separated by given separator
67 * window containing selection
69 * separator string to use - default is 'boolean not'
70 * @return String list of selected sequence IDs, each terminated by the given
73 public abstract String getSelectedSequencesFrom(AlignFrame alf, String sep);
78 * id of sequence to highlight
80 * integer position [ tobe implemented or range ] on sequence
81 * @param alignedPosition
82 * true/false/empty string - indicate if position is an alignment
83 * column or unaligned sequence position
85 public abstract void highlight(String sequenceId, String position,
86 String alignedPosition);
91 * id of sequence to highlight
93 * integer position [ tobe implemented or range ] on sequence
94 * @param alignedPosition
95 * false, blank or something else - indicate if position is an
96 * alignment column or unaligned sequence position
98 public abstract void highlightIn(AlignFrame alf, String sequenceId,
99 String position, String alignedPosition);
102 * select regions of the currrent alignment frame
105 * String separated list of sequence ids or empty string
107 * String separated list { column range or column, ..} or empty
110 public abstract void select(String sequenceIds, String columns);
113 * select regions of the currrent alignment frame
116 * String separated list { column range, seq1...seqn sequence ids }
118 * separator between toselect fields
120 public abstract void select(String sequenceIds, String columns, String sep);
123 * select regions of the given alignment frame
127 * String separated list { column range, seq1...seqn sequence ids }
129 * separator between toselect fields
131 public abstract void selectIn(AlignFrame alf, String sequenceIds,
135 * select regions of the given alignment frame
139 * String separated list { column range, seq1...seqn sequence ids }
141 * separator between toselect fields
143 public abstract void selectIn(AlignFrame alf, String sequenceIds,
144 String columns, String sep);
147 * get sequences selected in current alignFrame and return their alignment in
148 * format 'format' either with or without suffix
151 * - where selection is
153 * - format of alignment file
155 * - "true" to append /start-end string to each sequence ID
156 * @return selected sequences as flat file or empty string if there was no
159 public abstract String getSelectedSequencesAsAlignment(String format,
163 * get sequences selected in alf and return their alignment in format 'format'
164 * either with or without suffix
167 * - where selection is
169 * - format of alignment file
171 * - "true" to append /start-end string to each sequence ID
172 * @return selected sequences as flat file or empty string if there was no
175 public abstract String getSelectedSequencesAsAlignmentFrom(
176 AlignFrame alf, String format, String suffix);
179 * get a separator separated list of sequence IDs reflecting the order of the current alignment
182 public abstract String getAlignmentOrder();
184 * get a separator separated list of sequence IDs reflecting the order of the alignment in alf
189 public abstract String getAlignmentOrderFrom(AlignFrame alf);
192 * get a sep separated list of sequence IDs reflecting the order of the alignment in alf
195 * @param sep - separator to use
198 public abstract String getAlignmentOrderFrom(AlignFrame alf, String sep);
200 * re-order the current alignment using the given list of sequence IDs
201 * @param order - sep separated list
202 * @param undoName - string to use when referring to ordering action in undo buffer
203 * @return 'true' if alignment was actually reordered. empty string if alignment did not contain sequences.
205 public abstract String orderBy(String order, String undoName);
208 * re-order the current alignment using the given list of sequence IDs
212 * - sep separated list
214 * - string to use when referring to ordering action in undo buffer
216 * @return 'true' if alignment was actually reordered. empty string if alignment did not contain sequences.
218 public abstract String orderBy(String order, String undoName, String sep);
221 * re-order the given alignment using the given list of sequence IDs
226 * - sep separated list
228 * - string to use when referring to ordering action in undo buffer
230 * @return 'true' if alignment was actually reordered. empty string if alignment did not contain sequences.
232 public abstract String orderAlignmentBy(AlignFrame alf, String order,
233 String undoName, String sep);
236 * get alignment as format (format names FASTA, BLC, CLUSTAL, MSF, PILEUP, PFAM - see jalview.io.AppletFormatAdapter for full list)
240 public abstract String getAlignment(String format);
243 * get alignment displayed in alf as format
248 public abstract String getAlignmentFrom(AlignFrame alf, String format);
251 * get alignment as format with jalview start-end sequence suffix appended
256 public abstract String getAlignment(String format, String suffix);
259 * get alignment displayed in alf as format
260 * with or without the jalview start-end sequence suffix appended
266 public abstract String getAlignmentFrom(AlignFrame alf, String format,
270 * add the given features or annotation to the current alignment
273 public abstract void loadAnnotation(String annotation);
276 * add the given features or annotation to the given alignment view
280 public abstract void loadAnnotationFrom(AlignFrame alf, String annotation);
283 * parse the given string as a jalview feature or GFF annotation file and optionally enable feature display on the current alignFrame
284 * @param features - gff or features file
285 * @param autoenabledisplay - when true, feature display will be enabled if any features can be parsed from the string.
287 public abstract void loadFeatures(String features, boolean autoenabledisplay);
290 * parse the given string as a jalview feature or GFF annotation file and optionally enable feature display on the given alignFrame.
292 * @param features - gff or features file
293 * @param autoenabledisplay - when true, feature display will be enabled if any features can be parsed from the string.
295 public abstract void loadFeaturesFrom(AlignFrame alf, String features, boolean autoenabledisplay);
298 * get the sequence features in the given format (Jalview or GFF)
302 public abstract String getFeatures(String format);
305 * get the sequence features in alf in the given format (Jalview or GFF)
310 public abstract String getFeaturesFrom(AlignFrame alf, String format);
313 * get current alignment's annotation as an annotation file
316 public abstract String getAnnotation();
319 * get alignment view alf's annotation as an annotation file
323 public abstract String getAnnotationFrom(AlignFrame alf);
326 * create a new view and return the alignFrame instance
329 public abstract AlignFrame newView();
332 * create a new view named name and return the alignFrame instance
336 public abstract AlignFrame newView(String name);
339 * create a new view on alf and return the alignFrame instance
343 public abstract AlignFrame newViewFrom(AlignFrame alf);
346 * create a new view named name on alf
351 public abstract AlignFrame newViewFrom(AlignFrame alf, String name);
356 * alignment file as a string
359 * @return null or new alignment frame
361 public abstract AlignFrame loadAlignment(String text, String title);
364 * register a javascript function to handle any alignment mouseover events
365 * @param listener name of javascript function (called with arguments [jalview.appletgui.AlignFrame,String(sequence id),String(column in alignment), String(position in sequence)]
367 public abstract void setMouseoverListener(String listener);
370 * register a javascript function to handle mouseover events
371 * @param af (null or specific alignframe for which events are to be listened for)
372 * @param listener name of javascript function
374 public abstract void setMouseoverListener(AlignFrame af, String listener);
377 * register a javascript function to handle any alignment selection events. Events are generated when the user completes a selection event, or when the user deselects all selected regions.
378 * @param listener name of javascript function (called with arguments [jalview.appletgui.AlignFrame, String(sequence set id), String(separator separated list of sequences which were selected), String(separator separated list of column ranges (i.e. single number or hyphenated range) that were selected)]
380 public abstract void setSelectionListener(String listener);
382 public abstract void setSelectionListener(AlignFrame af, String listener);
385 * register a javascript function to handle events normally routed to a Jmol structure viewer.
386 * @param listener - javascript function (arguments are variable, see jalview.javascript.MouseOverStructureListener for full details)
387 * @param modelSet - separator separated list of PDB file URIs that this viewer is handling. These files must be in the same order they appear in Jmol (e.g. first one is frame 1, second is frame 2, etc).
388 @see jalview.javascript.MouseOverStructureListener
390 public abstract void setStructureListener(String listener, String modelSet);
393 * remove any callback using the given listener function and associated with
394 * the given alignFrame (or null for all callbacks)
401 public abstract void removeJavascriptListener(AlignFrame af,
405 * send a mouseover message to all the alignment windows associated with the
406 * given residue in the pdbfile
412 public abstract void mouseOverStructure(String pdbResNum, String chain,
416 * bind a pdb file to a sequence in the given alignFrame.
419 * - null or specific alignFrame. This specifies the dataset that
420 * will be searched for a seuqence called sequenceId
422 * - sequenceId within the dataset.
423 * @param pdbEntryString
424 * - the short name for the PDB file
426 * - pdb file - either a URL or a valid PDB file.
427 * @return true if binding was as success TODO: consider making an exception
428 * structure for indicating when PDB parsing or sequenceId location
431 public abstract boolean addPdbFile(AlignFrame alFrame, String sequenceId,
432 String pdbEntryString, String pdbFile);
435 * adjust horizontal/vertical scroll to make the given location the top left hand corner for the given view
439 * @param leftHandColumn
441 public abstract void scrollViewToIn(AlignFrame alf, String topRow,
442 String leftHandColumn);
444 * adjust vertical scroll to make the given row the top one for given view
449 public abstract void scrollViewToRowIn(AlignFrame alf, String topRow);
451 * adjust horizontal scroll to make the given column the left one in the given view
454 * @param leftHandColumn
456 public abstract void scrollViewToColumnIn(AlignFrame alf, String leftHandColumn);
461 * @see jalview.appletgui.AlignFrame#getFeatureGroups()
463 public abstract String getFeatureGroups();
467 * alignframe to get feature groups on
469 * @see jalview.appletgui.AlignFrame#getFeatureGroups()
471 public abstract String getFeatureGroupsOn(AlignFrame alf);
476 * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean)
478 public abstract String getFeatureGroupsOfState(boolean visible);
482 * align frame to get groups of state visible
485 * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean)
487 public abstract String getFeatureGroupsOfStateOn(AlignFrame alf,
492 * tab separated list of group names
495 * @see jalview.appletgui.AlignFrame#setFeatureGroupState(java.lang.String[],
498 public abstract void setFeatureGroupStateOn(AlignFrame alf,
499 String groups, boolean state);
501 public abstract void setFeatureGroupState(String groups, boolean state);
504 * List separator string
506 * @return the separator
508 public abstract String getSeparator();
511 * List separator string
514 * the separator to set. empty string will reset separator to default
516 public abstract void setSeparator(String separator);
519 * Retrieve fragments of a large packet of data made available by JalviewLite.
520 * @param messageclass
522 * @return next chunk of message
524 public abstract String getJsMessage(String messageclass, String viewId);