3 import java.io.IOException;
5 import java.util.Hashtable;
7 import jalview.api.AlignViewportI;
8 import jalview.datamodel.ColumnSelection;
9 import jalview.datamodel.HiddenColumns;
10 import jalview.datamodel.PDBEntry;
11 import jalview.datamodel.SequenceGroup;
12 import jalview.datamodel.SequenceI;
13 import jalview.gui.AlignFrame;
14 import jalview.io.DataSourceType;
15 import jalview.io.NewickFile;
16 import jalview.structure.SelectionSource;
17 import jalview.structure.VamsasSource;
20 * JAL-3369 JalviewJS API BH 2019.07.17
25 public interface JalviewJSApi
28 // debug flag - controls output to standard out
29 public static boolean debug = false;
32 * bind a pdb file to a sequence in the given AlignFrame.
35 * - null or specific AlignFrame. This specifies the dataset that
36 * will be searched for a seuqence called sequenceId
38 * - sequenceId within the dataset.
39 * @param pdbEntryString
40 * - the short name for the PDB file
42 * - pdb file - either a URL or a valid PDB file.
43 * @return true if binding was as success TODO: consider making an exception
44 * structure for indicating when PDB parsing or sequenceId location
47 public abstract boolean addPdbFile(AlignFrame alFrame, String sequenceId,
48 String pdbEntryString, String pdbFile);
50 public String arrayToSeparatorList(String[] array);
53 * The following public methods may be called externally, eg via javascript in
57 * <em>TODO: introduce abstract interface for
58 * jalview.appletgui.AlignFrame</em><br>
60 * Most function arguments are strings, which contain serialised versions of
61 * lists. Lists of things are separated by a separator character - either the
62 * default or a user supplied one. Ranges and positions on an alignment or
63 * sequence can be specified as a list, where an item containing a single
64 * number is a single position, and an item like 1-2 specifies columns 1 and 2
72 // public interface JalviewLiteJsApi
76 * get alignment as format (format names FASTA, BLC, CLUSTAL, MSF, PILEUP,
77 * PFAM - see jalview.io.AppletFormatAdapter for full list);
83 public abstract String getAlignment(String format);
86 * get alignment as format with jalview start-end sequence suffix appended
93 public abstract String getAlignment(String format, String suffix);
96 * get alignment displayed in alf as format
102 public abstract String getAlignmentFrom(AlignFrame alf, String format);
105 * get alignment displayed in alf as format with or without the jalview
106 * start-end sequence suffix appended
113 public abstract String getAlignmentFrom(AlignFrame alf, String format,
117 * get a separator separated list of sequence IDs reflecting the order of the
123 public abstract String getAlignmentOrder();
126 * get a separator separated list of sequence IDs reflecting the order of the
132 public abstract String getAlignmentOrderFrom(AlignFrame alf);
135 * get a sep separated list of sequence IDs reflecting the order of the
143 public abstract String getAlignmentOrderFrom(AlignFrame alf, String sep);
146 * get current alignment's annotation as an annotation file
151 public abstract String getAnnotation();
154 * get alignment view alf's annotation as an annotation file
159 public abstract String getAnnotationFrom(AlignFrame alf);
161 public Object getAppletParameter(String name, boolean asString);
163 public URL getCodeBase();
165 public URL getDocumentBase();
170 * @see jalview.appletgui.AlignFrame#getFeatureGroups();
173 public abstract String getFeatureGroups();
178 * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean);
181 public abstract String getFeatureGroupsOfState(boolean visible);
185 * align frame to get groups of state visible
188 * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean);
190 public abstract String getFeatureGroupsOfStateOn(AlignFrame alf,
195 * AlignFrame to get feature groups on
197 * @see jalview.appletgui.AlignFrame#getFeatureGroups();
199 public abstract String getFeatureGroupsOn(AlignFrame alf);
202 * get the sequence features in the given format (Jalview or GFF);
208 public abstract String getFeatures(String format);
211 * get the sequence features in alf in the given format (Jalview or GFF);
217 public abstract String getFeaturesFrom(AlignFrame alf, String format);
219 public Object getFrameForSource(VamsasSource source);
221 public Hashtable<String, int[]> getJSHashes();
224 * Retrieve fragments of a large packet of data made available by JalviewLite.
226 * @param messageclass
228 * @return next chunk of message
231 public abstract String getJsMessage(String messageclass, String viewId);
233 Hashtable<String, Hashtable<String, String[]>> getJSMessages();
235 public Object getJSObject();
237 public jalview.renderer.seqfeatures.FeatureRenderer getNewFeatureRenderer(
240 public String getParameter(String name);
243 * @return String list of selected sequence IDs, each terminated by the
244 * 'boolean not' character (""+0x00AC); or (¬);
247 public abstract String getSelectedSequences();
251 * separator string or null for default
252 * @return String list of selected sequence IDs, each terminated by given
256 public abstract String getSelectedSequences(String sep);
259 * get sequences selected in current AlignFrame and return their alignment in
260 * format 'format' either with or without suffix
263 * - where selection is
265 * - format of alignment file
267 * - "true" to append /start-end string to each sequence ID
268 * @return selected sequences as flat file or empty string if there was no
272 public abstract String getSelectedSequencesAsAlignment(String format,
276 * get sequences selected in alf and return their alignment in format 'format'
277 * either with or without suffix
280 * - where selection is
282 * - format of alignment file
284 * - "true" to append /start-end string to each sequence ID
285 * @return selected sequences as flat file or empty string if there was no
288 public abstract String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
289 String format, String suffix);
293 * AlignFrame containing selection
294 * @return String list of selected sequence IDs, each terminated by current
295 * default separator sequence
298 public abstract String getSelectedSequencesFrom(AlignFrame alf);
300 // BH incompatibility here -- JalviewLite created an AlignFrame; Jalview
301 // creates an AlignmentPanel
303 // * create a new view and return the AlignFrame instance
308 // public abstract AlignFrame newView();
311 // * create a new view named name and return the AlignFrame instance
317 // public abstract AlignFrame newView(String name);
320 // * create a new view on alf and return the AlignFrame instance
325 // public abstract AlignFrame newViewFrom(AlignFrame alf);
328 // * create a new view named name on alf
334 // public abstract AlignFrame newViewFrom(AlignFrame alf, String name);
337 * get list of selected sequence IDs separated by given separator
340 * window containing selection
342 * separator string to use - default is 'boolean not'
343 * @return String list of selected sequence IDs, each terminated by the given
346 public abstract String getSelectedSequencesFrom(AlignFrame alf,
349 public Object[] getSelectionForListener(SequenceGroup seqsel,
350 ColumnSelection colsel, HiddenColumns hidden,
351 SelectionSource source, Object alignFrame);
354 * List separator string
356 * @return the separator
359 public abstract String getSeparator();
361 public AlignViewportI getViewport();
366 * id of sequence to highlight
368 * integer position [ tobe implemented or range ] on sequence
369 * @param alignedPosition
370 * true/false/empty string - indicate if position is an alignment
371 * column or unaligned sequence position
374 public abstract void highlight(String sequenceId, String position,
375 String alignedPosition);
380 * id of sequence to highlight
382 * integer position [ tobe implemented or range ] on sequence
383 * @param alignedPosition
384 * false, blank or something else - indicate if position is an
385 * alignment column or unaligned sequence position
387 public abstract void highlightIn(AlignFrame alf, String sequenceId,
388 String position, String alignedPosition);
393 * alignment file as a string
396 * @return null or new alignment frame
399 public abstract AlignFrame loadAlignment(String text, String title);
402 * add the given features or annotation to the current alignment
407 public abstract void loadAnnotation(String annotation);
410 * add the given features or annotation to the given alignment view
415 public abstract void loadAnnotationFrom(AlignFrame alf,
419 * parse the given string as a jalview feature or GFF annotation file and
420 * optionally enable feature display on the current AlignFrame
423 * - gff or features file
424 * @param autoenabledisplay
425 * - when true, feature display will be enabled if any features can
426 * be parsed from the string.
429 public abstract void loadFeatures(String features,
430 boolean autoenabledisplay);
433 * parse the given string as a jalview feature or GFF annotation file and
434 * optionally enable feature display on the given AlignFrame.
438 * - gff or features file
439 * @param autoenabledisplay
440 * - when true, feature display will be enabled if any features can
441 * be parsed from the string.
442 * @return true if data parsed as features
444 public abstract boolean loadFeaturesFrom(AlignFrame alf, String features,
445 boolean autoenabledisplay);
447 public boolean loadScoreFile(String sScoreFile) throws IOException;
449 public void newFeatureSettings();
451 public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
452 String[] chains, DataSourceType protocol);
455 * public static method for JalviewJS API to open a PCAPanel without
456 * necessarily using a dialog.
461 * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
462 * if number of sequences selected is inappropriate
464 public Object openPcaPanel(AlignFrame af, String modelName);
467 * Open a new Tree panel on the desktop statically. Params are standard (not
468 * set by Groovy). No dialog is opened.
474 * @return null, or the string "label.you_need_at_least_n_sequences" if number
475 * of sequences selected is inappropriate
477 public Object openTreePanel(AlignFrame af, String treeType,
480 /// in http://www.jalview.org/examples/jalviewLiteJs.html but missing here
482 // get selected sequences as alignment as format with or without start-end
486 * re-order the given alignment using the given list of sequence IDs separated
491 * - sep separated list
493 * - string to use when referring to ordering action in undo buffer
495 * @return 'true' if alignment was actually reordered. empty string if
496 * alignment did not contain sequences.
498 public abstract String orderAlignmentBy(AlignFrame alf, String order,
499 String undoName, String sep);
501 // get a string array from a list
504 * re-order the current alignment using the given list of sequence IDs
507 * - sep separated list
509 * - string to use when referring to ordering action in undo buffer
510 * @return 'true' if alignment was actually reordered. empty string if
511 * alignment did not contain sequences.
514 public abstract String orderBy(String order, String undoName);
517 * re-order the current alignment using the given list of sequence IDs
521 * - sep separated list
523 * - string to use when referring to ordering action in undo buffer
525 * @return 'true' if alignment was actually reordered. empty string if
526 * alignment did not contain sequences.
529 public abstract String orderBy(String order, String undoName, String sep);
532 * process commandline arguments after the JavaScript application has started
537 Object parseArguments(String[] args);
539 // public boolean getDefaultParameter(String name, boolean def);
541 public boolean parseFeaturesFile(String param, DataSourceType protocol);
544 * remove any callback using the given listener function and associated with
545 * the given AlignFrame (or null for all callbacks);
552 public abstract void removeSelectionListener(AlignFrame af,
555 // public void setAlignPdbStructures(boolean defaultParameter);
558 * adjust horizontal scroll to make the given column the left one in the given
562 * @param leftHandColumn
564 public abstract void scrollViewToColumnIn(AlignFrame alf,
565 String leftHandColumn);
568 * adjust horizontal/vertical scroll to make the given location the top left
569 * hand corner for the given view
573 * @param leftHandColumn
575 public abstract void scrollViewToIn(AlignFrame alf, String topRow,
576 String leftHandColumn);
579 * adjust vertical scroll to make the given row the top one for given view
584 public abstract void scrollViewToRowIn(AlignFrame alf, String topRow);
587 * select regions of the currrent alignment frame
590 * String separated list of sequence ids or empty string
592 * String separated list { column range or column, ..} or empty
596 public abstract void select(String sequenceIds, String columns);
599 * select regions of the currrent alignment frame
602 * String separated list { column range, seq1...seqn sequence ids }
604 * separator between toselect fields
607 public abstract void select(String sequenceIds, String columns,
611 * select regions of the given alignment frame
615 * String separated list { column range, seq1...seqn sequence ids }
617 * separator between toselect fields
619 public abstract void selectIn(AlignFrame alf, String sequenceIds,
623 * select regions of the given alignment frame
627 * String separated list { column range, seq1...seqn sequence ids }
629 * separator between toselect fields
631 public abstract void selectIn(AlignFrame alf, String sequenceIds,
632 String columns, String sep);
634 public String[] separatorListToArray(String list);
636 public abstract void setFeatureGroupState(String groups, boolean state);
638 public void setFeatureGroupState(String[] groups, boolean state);
640 // public StructureSelectionManagerProvider
641 // getStructureSelectionManagerProvider();
645 * tab separated list of group names
648 * @see jalview.appletgui.AlignFrame#setFeatureGroupState(java.lang.String[],
651 public abstract void setFeatureGroupStateOn(AlignFrame alf, String groups,
654 public abstract void setSelectionListener(AlignFrame af, String listener);
657 * register a javascript function to handle any alignment selection events.
658 * Events are generated when the user completes a selection event, or when the
659 * user deselects all selected regions.
662 * name of javascript function (called with arguments
663 * [jalview.appletgui.AlignFrame, String(sequence set id);,
664 * String(separator separated list of sequences which were
665 * selected);, String(separator separated list of column ranges (i.e.
666 * single number or hyphenated range); that were selected);]
669 public abstract void setSelectionListener(String listener);
672 * List separator string
675 * the separator to set. empty string will reset separator to default
678 public abstract void setSeparator(String separator);
682 public void updateForAnnotations();