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