JAL-2629 add documentation to previous work
[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.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.AlignmentView;
27 import jalview.datamodel.CigarArray;
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   public 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   public 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 getSequenceConsensusHash();
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 getAlignmentGapAnnotation();
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 setSequenceConsensusHash(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    * This method returns the visible alignment as text, as seen on the GUI, ie
255    * if columns are hidden they will not be returned in the result. Use this for
256    * calculating trees, PCA, redundancy etc on views which contain hidden
257    * columns.
258    * 
259    * @return String[]
260    */
261   CigarArray getViewAsCigars(boolean selectedRegionOnly);
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    * @return AlignmentView
270    */
271   AlignmentView getAlignmentView(boolean selectedOnly);
272
273   /**
274    * return a compact representation of the current alignment selection to pass
275    * to an analysis function
276    * 
277    * @param selectedOnly
278    *          boolean true to just return the selected view
279    * @param markGroups
280    *          boolean true to annotate the alignment view with groups on the
281    *          alignment (and intersecting with selected region if selectedOnly
282    *          is true)
283    * @return AlignmentView
284    */
285   AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups);
286
287   /**
288    * This method returns the visible alignment as text, as seen on the GUI, ie
289    * if columns are hidden they will not be returned in the result. Use this for
290    * calculating trees, PCA, redundancy etc on views which contain hidden
291    * columns. This method doesn't exclude hidden sequences from the output.
292    *
293    * @param selectedRegionOnly
294    *          - determines if only the selected region or entire alignment is
295    *          exported
296    * @return String[]
297    */
298   String[] getViewAsString(boolean selectedRegionOnly);
299
300   /**
301    * This method returns the visible alignment as text, as seen on the GUI, ie
302    * if columns are hidden they will not be returned in the result. Use this for
303    * calculating trees, PCA, redundancy etc on views which contain hidden
304    * columns.
305    * 
306    * @param selectedRegionOnly
307    *          - determines if only the selected region or entire alignment is
308    *          exported
309    * @param isExportHiddenSeqs
310    *          - determines if hidden sequences would be exported or not.
311    * 
312    * @return String[]
313    */
314   String[] getViewAsString(boolean selectedRegionOnly,
315           boolean isExportHiddenSeqs);
316
317   void setSelectionGroup(SequenceGroup sg);
318
319   char getGapCharacter();
320
321   void setColumnSelection(ColumnSelection cs);
322
323   void setConservation(Conservation cons);
324
325   /**
326    * get a copy of the currently visible alignment annotation
327    * 
328    * @param selectedOnly
329    *          if true - trim to selected regions on the alignment
330    * @return an empty list or new alignment annotation objects shown only
331    *         visible columns trimmed to selected region only
332    */
333   List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
334           boolean selectedOnly);
335
336   FeaturesDisplayedI getFeaturesDisplayed();
337
338   String getSequenceSetId();
339
340   boolean areFeaturesDisplayed();
341
342   void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI);
343
344   void alignmentChanged(AlignmentViewPanel ap);
345
346   /**
347    * @return the padGaps
348    */
349   boolean isPadGaps();
350
351   /**
352    * @param padGaps
353    *          the padGaps to set
354    */
355   void setPadGaps(boolean padGaps);
356
357   /**
358    * return visible region boundaries within given column range
359    * 
360    * @param min
361    *          first column (inclusive, from 0)
362    * @param max
363    *          last column (exclusive)
364    * @return int[][] range of {start,end} visible positions
365    */
366   List<int[]> getVisibleRegionBoundaries(int min, int max);
367
368   /**
369    * This method returns an array of new SequenceI objects derived from the
370    * whole alignment or just the current selection with start and end points
371    * adjusted
372    * 
373    * @note if you need references to the actual SequenceI objects in the
374    *       alignment or currently selected then use getSequenceSelection()
375    * @return selection as new sequenceI objects
376    */
377   SequenceI[] getSelectionAsNewSequence();
378
379   void invertColumnSelection();
380
381   /**
382    * broadcast selection to any interested parties
383    */
384   void sendSelection();
385
386   /**
387    * calculate the row position for alignmentIndex if all hidden sequences were
388    * shown
389    * 
390    * @param alignmentIndex
391    * @return adjusted row position
392    */
393   int adjustForHiddenSeqs(int alignmentIndex);
394
395   boolean hasHiddenRows();
396
397   /**
398    * 
399    * @return a copy of this view's current display settings
400    */
401   public ViewStyleI getViewStyle();
402
403   /**
404    * update the view's display settings with the given style set
405    * 
406    * @param settingsForView
407    */
408   public void setViewStyle(ViewStyleI settingsForView);
409
410   /**
411    * Returns a viewport which holds the cDna for this (protein), or vice versa,
412    * or null if none is set.
413    * 
414    * @return
415    */
416   AlignViewportI getCodingComplement();
417
418   /**
419    * Sets the viewport which holds the cDna for this (protein), or vice versa.
420    * Implementation should guarantee that the reciprocal relationship is always
421    * set, i.e. each viewport is the complement of the other.
422    */
423   void setCodingComplement(AlignViewportI sl);
424
425   /**
426    * Answers true if viewport hosts DNA/RNA, else false.
427    * 
428    * @return
429    */
430   boolean isNucleotide();
431
432   /**
433    * Returns an id guaranteed to be unique for this viewport.
434    * 
435    * @return
436    */
437   String getViewId();
438
439   /**
440    * Return true if view should scroll to show the highlighted region of a
441    * sequence
442    * 
443    * @return
444    */
445   boolean isFollowHighlight();
446
447   /**
448    * Set whether view should scroll to show the highlighted region of a sequence
449    */
450   void setFollowHighlight(boolean b);
451
452   public void applyFeaturesStyle(FeatureSettingsModelI featureSettings);
453
454   /**
455    * check if current selection group is defined on the view, or is simply a
456    * temporary group.
457    * 
458    * @return true if group is defined on the alignment
459    */
460   boolean isSelectionDefinedGroup();
461
462   /**
463    * 
464    * @return true if there are search results on the view
465    */
466   boolean hasSearchResults();
467
468   /**
469    * set the search results for the view
470    * 
471    * @param results
472    *          - or null to clear current results
473    */
474   void setSearchResults(SearchResultsI results);
475
476   /**
477    * get search results for this view (if any)
478    * 
479    * @return search results or null
480    */
481   SearchResultsI getSearchResults();
482
483   /**
484    * Updates view settings with the given font. You may need to call
485    * AlignmentPanel.fontChanged to update the layout geometry.
486    * 
487    * @param setGrid
488    *          when true, charWidth/height is set according to font metrics
489    */
490   void setFont(Font newFont, boolean b);
491
492   /**
493    * Answers true if split screen protein and cDNA use the same font
494    * 
495    * @return
496    */
497   @Override
498   boolean isProteinFontAsCdna();
499
500   /**
501    * Set the flag for whether split screen protein and cDNA use the same font
502    * 
503    * @return
504    */
505   @Override
506   void setProteinFontAsCdna(boolean b);
507
508   void setSequenceInformationHashes(List<ProfilesI> info);
509
510   List<ProfilesI> getSequenceInformationHashes();
511
512   ProfilesI getSequenceInformationHash(int index);
513
514   List<AlignmentAnnotation> getInformationAnnotations();
515
516   AlignmentAnnotation getInformationAnnotation(int index);
517
518   void setSequenceInformationHash(ProfilesI info, int index);
519
520   /**
521    * Initiates the information annotation for all uninitiated sequences.
522    */
523   void initInformation();
524
525   /**
526    * Updates all information annotations.
527    * 
528    * @param ap
529    */
530   void updateInformation(AlignmentViewPanel ap);
531
532 }