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