Merge branch 'develop' into spike/JAL-4047/JAL-4048_columns_in_sequenceID
[jalview.git] / src / jalview / api / AlignViewportI.java
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
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.api;
22
23 import java.awt.Color;
24 import java.awt.Font;
25 import java.util.Hashtable;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.Map;
29
30 import jalview.analysis.Conservation;
31 import jalview.analysis.TreeModel;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentExportData;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.AlignmentView;
36 import jalview.datamodel.ColumnSelection;
37 import jalview.datamodel.ContactListI;
38 import jalview.datamodel.ContactMatrixI;
39 import jalview.datamodel.ProfilesI;
40 import jalview.datamodel.SearchResultsI;
41 import jalview.datamodel.SequenceCollectionI;
42 import jalview.datamodel.SequenceGroup;
43 import jalview.datamodel.SequenceI;
44 import jalview.renderer.ResidueShaderI;
45 import jalview.schemes.ColourSchemeI;
46 import jalview.viewmodel.ViewportRanges;
47 import jalview.viewmodel.seqfeatures.IdColumns;
48
49 /**
50  * @author jimp
51  * 
52  */
53 public interface AlignViewportI extends ViewStyleI
54 {
55
56   /**
57    * Get the ranges object containing details of the start and end sequences and
58    * residues
59    * 
60    * @return
61    */
62   public ViewportRanges getRanges();
63
64   /**
65    * calculate the height for visible annotation, revalidating bounds where
66    * necessary ABSTRACT GUI METHOD
67    * 
68    * @return total height of annotation
69    */
70   public int calcPanelHeight();
71
72   /**
73    * Answers true if the viewport has at least one column selected
74    * 
75    * @return
76    */
77   boolean hasSelectedColumns();
78
79   /**
80    * Answers true if the viewport has at least one hidden column
81    * 
82    * @return
83    */
84   boolean hasHiddenColumns();
85
86   boolean isValidCharWidth();
87
88   boolean isShowConsensusHistogram();
89
90   boolean isShowSequenceLogo();
91
92   boolean isNormaliseSequenceLogo();
93
94   ColourSchemeI getGlobalColourScheme();
95
96   /**
97    * Returns an object that describes colouring (including any thresholding or
98    * fading) of the alignment
99    * 
100    * @return
101    */
102   ResidueShaderI getResidueShading();
103
104   AlignmentI getAlignment();
105
106   ColumnSelection getColumnSelection();
107
108   ProfilesI getSequenceConsensusHash();
109
110   /**
111    * Get consensus data table for the cDNA complement of this alignment (if any)
112    * 
113    * @return
114    */
115   Hashtable<String, Object>[] getComplementConsensusHash();
116
117   Hashtable<String, Object>[] getRnaStructureConsensusHash();
118
119   boolean isIgnoreGapsConsensus();
120
121   boolean isCalculationInProgress(AlignmentAnnotation alignmentAnnotation);
122
123   AlignmentAnnotation getAlignmentQualityAnnot();
124
125   AlignmentAnnotation getAlignmentConservationAnnotation();
126
127   /**
128    * get the container for alignment consensus annotation
129    * 
130    * @return
131    */
132   AlignmentAnnotation getAlignmentConsensusAnnotation();
133
134   /**
135    * get the container for alignment gap annotation
136    * 
137    * @return
138    */
139   AlignmentAnnotation getAlignmentGapAnnotation();
140
141   /**
142    * get the container for cDNA complement consensus annotation
143    * 
144    * @return
145    */
146   AlignmentAnnotation getComplementConsensusAnnotation();
147
148   /**
149    * Test to see if viewport is still open and active
150    * 
151    * @return true indicates that all references to viewport should be dropped
152    */
153   boolean isClosed();
154
155   /**
156    * Dispose of all references or resources held by the viewport
157    */
158   void dispose();
159
160   /**
161    * get the associated calculation thread manager for the view
162    * 
163    * @return
164    */
165   AlignCalcManagerI getCalcManager();
166
167   /**
168    * get the percentage gaps allowed in a conservation calculation
169    * 
170    */
171   public int getConsPercGaps();
172
173   /**
174    * set the consensus result object for the viewport
175    * 
176    * @param hconsensus
177    */
178   void setSequenceConsensusHash(ProfilesI hconsensus);
179
180   /**
181    * Set the cDNA complement consensus for the viewport
182    * 
183    * @param hconsensus
184    */
185   void setComplementConsensusHash(Hashtable<String, Object>[] hconsensus);
186
187   /**
188    * 
189    * @return the alignment annotation row for the structure consensus
190    *         calculation
191    */
192   AlignmentAnnotation getAlignmentStrucConsensusAnnotation();
193
194   /**
195    * set the Rna structure consensus result object for the viewport
196    * 
197    * @param hStrucConsensus
198    */
199   void setRnaStructureConsensusHash(
200           Hashtable<String, Object>[] hStrucConsensus);
201
202   /**
203    * Sets the colour scheme for the background alignment (as distinct from
204    * sub-groups, which may have their own colour schemes). A null value is used
205    * for no residue colour (white).
206    * 
207    * @param cs
208    */
209   void setGlobalColourScheme(ColourSchemeI cs);
210
211   Map<SequenceI, SequenceCollectionI> getHiddenRepSequences();
212
213   void setHiddenRepSequences(
214           Map<SequenceI, SequenceCollectionI> hiddenRepSequences);
215
216   /**
217    * hides or shows dynamic annotation rows based on groups and group and
218    * alignment associated auto-annotation state flags apply the current
219    * group/autoannotation settings to the alignment view. Usually you should
220    * call the AlignmentViewPanel.adjustAnnotationHeight() method afterwards to
221    * ensure the annotation panel bounds are set correctly.
222    * 
223    * @param applyGlobalSettings
224    *          - apply to all autoannotation rows or just the ones associated
225    *          with the current visible region
226    * @param preserveNewGroupSettings
227    *          - don't apply global settings to groups which don't already have
228    *          group associated annotation
229    */
230   void updateGroupAnnotationSettings(boolean applyGlobalSettings,
231           boolean preserveNewGroupSettings);
232
233   void setSequenceColour(SequenceI seq, Color col);
234
235   Color getSequenceColour(SequenceI seq);
236
237   void updateSequenceIdColours();
238
239   SequenceGroup getSelectionGroup();
240
241   /**
242    * get the currently selected sequence objects or all the sequences in the
243    * alignment. TODO: change to List<>
244    * 
245    * @return array of references to sequence objects
246    */
247   SequenceI[] getSequenceSelection();
248
249   void clearSequenceColours();
250
251   /**
252    * return a compact representation of the current alignment selection to pass
253    * to an analysis function
254    * 
255    * @param selectedOnly
256    *          boolean true to just return the selected view
257    * @return AlignmentView
258    */
259   AlignmentView getAlignmentView(boolean selectedOnly);
260
261   /**
262    * return a compact representation of the current alignment selection to pass
263    * to an analysis function
264    * 
265    * @param selectedOnly
266    *          boolean true to just return the selected view
267    * @param markGroups
268    *          boolean true to annotate the alignment view with groups on the
269    *          alignment (and intersecting with selected region if selectedOnly
270    *          is true)
271    * @return AlignmentView
272    */
273   AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups);
274
275   /**
276    * This method returns the visible alignment as text, as seen on the GUI, ie
277    * if columns are hidden they will not be returned in the result. Use this for
278    * calculating trees, PCA, redundancy etc on views which contain hidden
279    * columns. This method doesn't exclude hidden sequences from the output.
280    *
281    * @param selectedRegionOnly
282    *          - determines if only the selected region or entire alignment is
283    *          exported
284    * @return String[]
285    */
286   String[] getViewAsString(boolean selectedRegionOnly);
287
288   /**
289    * This method returns the visible alignment as text, as seen on the GUI, ie
290    * if columns are hidden they will not be returned in the result. Use this for
291    * calculating trees, PCA, redundancy etc on views which contain hidden
292    * columns.
293    * 
294    * @param selectedRegionOnly
295    *          - determines if only the selected region or entire alignment is
296    *          exported
297    * @param isExportHiddenSeqs
298    *          - determines if hidden sequences would be exported or not.
299    * 
300    * @return String[]
301    */
302   String[] getViewAsString(boolean selectedRegionOnly,
303           boolean isExportHiddenSeqs);
304
305   void setSelectionGroup(SequenceGroup sg);
306
307   char getGapCharacter();
308
309   void setColumnSelection(ColumnSelection cs);
310
311   void setConservation(Conservation cons);
312
313   /**
314    * get a copy of the currently visible alignment annotation
315    * 
316    * @param selectedOnly
317    *          if true - trim to selected regions on the alignment
318    * @return an empty list or new alignment annotation objects shown only
319    *         visible columns trimmed to selected region only
320    */
321   List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
322           boolean selectedOnly);
323
324   FeaturesDisplayedI getFeaturesDisplayed();
325
326   String getSequenceSetId();
327
328   boolean areFeaturesDisplayed();
329
330   void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI);
331
332   void alignmentChanged(AlignmentViewPanel ap);
333
334   /**
335    * @return the padGaps
336    */
337   boolean isPadGaps();
338
339   /**
340    * @param padGaps
341    *          the padGaps to set
342    */
343   void setPadGaps(boolean padGaps);
344
345   /**
346    * return visible region boundaries within given column range
347    * 
348    * @param min
349    *          first column (inclusive, from 0)
350    * @param max
351    *          last column (exclusive)
352    * @return int[][] range of {start,end} visible positions
353    */
354   List<int[]> getVisibleRegionBoundaries(int min, int max);
355
356   /**
357    * This method returns an array of new SequenceI objects derived from the
358    * whole alignment or just the current selection with start and end points
359    * adjusted
360    * 
361    * @note if you need references to the actual SequenceI objects in the
362    *       alignment or currently selected then use getSequenceSelection()
363    * @return selection as new sequenceI objects
364    */
365   SequenceI[] getSelectionAsNewSequence();
366
367   void invertColumnSelection();
368
369   /**
370    * broadcast selection to any interested parties
371    */
372   void sendSelection();
373
374   /**
375    * calculate the row position for alignmentIndex if all hidden sequences were
376    * shown
377    * 
378    * @param alignmentIndex
379    * @return adjusted row position
380    */
381   int adjustForHiddenSeqs(int alignmentIndex);
382
383   boolean hasHiddenRows();
384
385   /**
386    * 
387    * @return a copy of this view's current display settings
388    */
389   public ViewStyleI getViewStyle();
390
391   /**
392    * update the view's display settings with the given style set
393    * 
394    * @param settingsForView
395    */
396   public void setViewStyle(ViewStyleI settingsForView);
397
398   /**
399    * Returns a viewport which holds the cDna for this (protein), or vice versa,
400    * or null if none is set.
401    * 
402    * @return
403    */
404   AlignViewportI getCodingComplement();
405
406   /**
407    * Sets the viewport which holds the cDna for this (protein), or vice versa.
408    * Implementation should guarantee that the reciprocal relationship is always
409    * set, i.e. each viewport is the complement of the other.
410    */
411   void setCodingComplement(AlignViewportI sl);
412
413   /**
414    * Answers true if viewport hosts DNA/RNA, else false.
415    * 
416    * @return
417    */
418   boolean isNucleotide();
419
420   /**
421    * Returns an id guaranteed to be unique for this viewport.
422    * 
423    * @return
424    */
425   String getViewId();
426
427   /**
428    * Return true if view should scroll to show the highlighted region of a
429    * sequence
430    * 
431    * @return
432    */
433   boolean isFollowHighlight();
434
435   /**
436    * Set whether view should scroll to show the highlighted region of a sequence
437    */
438   void setFollowHighlight(boolean b);
439
440   /**
441    * configure the feature renderer with predefined feature settings
442    * 
443    * @param featureSettings
444    */
445   public void applyFeaturesStyle(FeatureSettingsModelI featureSettings);
446
447   /**
448    * Apply the given feature settings on top of existing feature settings.
449    */
450   public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings);
451
452   /**
453    * check if current selection group is defined on the view, or is simply a
454    * temporary group.
455    * 
456    * @return true if group is defined on the alignment
457    */
458   boolean isSelectionDefinedGroup();
459
460   /**
461    * 
462    * @return true if there are search results on the view
463    */
464   boolean hasSearchResults();
465
466   /**
467    * set the search results for the view
468    * 
469    * @param results
470    *          - or null to clear current results
471    */
472   void setSearchResults(SearchResultsI results);
473
474   /**
475    * get search results for this view (if any)
476    * 
477    * @return search results or null
478    */
479   SearchResultsI getSearchResults();
480
481   /**
482    * Retrieve a ContactListI corresponding to column in an annotation row in an
483    * alignment.
484    * 
485    * @param _aa
486    *          - annotation with associated matrix data
487    * @param column
488    *          - column in alignment where _aa is associated
489    */
490   ContactListI getContactList(AlignmentAnnotation _aa, int column);
491
492   /**
493    * Updates view settings with the given font. You may need to call
494    * AlignmentPanel.fontChanged to update the layout geometry.
495    * 
496    * @param setGrid
497    *          when true, charWidth/height is set according to font metrics
498    */
499   void setFont(Font newFont, boolean b);
500
501   /**
502    * Answers true if split screen protein and cDNA use the same font
503    * 
504    * @return
505    */
506   @Override
507   boolean isProteinFontAsCdna();
508
509   /**
510    * Set the flag for whether split screen protein and cDNA use the same font
511    * 
512    * @return
513    */
514   @Override
515   void setProteinFontAsCdna(boolean b);
516
517   TreeModel getCurrentTree();
518
519   void setCurrentTree(TreeModel tree);
520
521   /**
522    * Answers a data bean containing data for export as configured by the
523    * supplied options
524    * 
525    * @param options
526    * @return
527    */
528   AlignmentExportData getAlignExportData(AlignExportSettingsI options);
529
530   /**
531    * @param update
532    *          - set the flag for updating structures on next repaint
533    */
534   void setUpdateStructures(boolean update);
535
536   /**
537    *
538    * @return true if structure views will be updated on next refresh
539    */
540   boolean isUpdateStructures();
541
542   /**
543    * check if structure views need to be updated, and clear the flag afterwards.
544    * 
545    * @return if an update is needed
546    */
547   boolean needToUpdateStructureViews();
548
549   /**
550    * Adds sequencegroup to the alignment in the view. Also adds a group to the
551    * complement view if one is defined.
552    * 
553    * @param sequenceGroup
554    *          - a group defined on sequences in the alignment held by the view
555    */
556   void addSequenceGroup(SequenceGroup sequenceGroup);
557
558   /**
559    * Returns an interator over the [start, end] column positions of the visible
560    * regions of the alignment
561    * 
562    * @param selectedRegionOnly
563    *          if true, and the view has a selection region, then only the
564    *          intersection of visible columns with the selection region is
565    *          returned
566    * @return
567    */
568   Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly);
569
570   IdColumns getIdColumns();
571
572   ContactMatrixI getContactMatrix(AlignmentAnnotation alignmentAnnotation);
573 }