add partial button fix to annotation and statistics output
[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 information content annotation
139    * 
140    * @return
141    */
142   AlignmentAnnotation getAlignmentInformationAnnotation();
143
144   /**
145    * get the container for alignment gap annotation
146    * 
147    * @return
148    */
149   AlignmentAnnotation getAlignmentGapAnnotation();
150
151   /**
152    * get the container for cDNA complement consensus annotation
153    * 
154    * @return
155    */
156   AlignmentAnnotation getComplementConsensusAnnotation();
157
158   /**
159    * Test to see if viewport is still open and active
160    * 
161    * @return true indicates that all references to viewport should be dropped
162    */
163   boolean isClosed();
164
165   /**
166    * Dispose of all references or resources held by the viewport
167    */
168   void dispose();
169
170   /**
171    * get the associated calculation thread manager for the view
172    * 
173    * @return
174    */
175   AlignCalcManagerI getCalcManager();
176
177   /**
178    * get the percentage gaps allowed in a conservation calculation
179    * 
180    */
181   public int getConsPercGaps();
182
183   /**
184    * set the consensus result object for the viewport
185    * 
186    * @param hconsensus
187    */
188   void setSequenceConsensusHash(ProfilesI hconsensus);
189
190   /**
191    * Set the cDNA complement consensus for the viewport
192    * 
193    * @param hconsensus
194    */
195   void setComplementConsensusHash(Hashtable[] hconsensus);
196
197   /**
198    * 
199    * @return the alignment annotation row for the structure consensus
200    *         calculation
201    */
202   AlignmentAnnotation getAlignmentStrucConsensusAnnotation();
203
204   /**
205    * set the Rna structure consensus result object for the viewport
206    * 
207    * @param hStrucConsensus
208    */
209   void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus);
210
211   /**
212    * Sets the colour scheme for the background alignment (as distinct from
213    * sub-groups, which may have their own colour schemes). A null value is used
214    * for no residue colour (white).
215    * 
216    * @param cs
217    */
218   void setGlobalColourScheme(ColourSchemeI cs);
219
220   Map<SequenceI, SequenceCollectionI> getHiddenRepSequences();
221
222   void setHiddenRepSequences(
223           Map<SequenceI, SequenceCollectionI> hiddenRepSequences);
224
225   /**
226    * hides or shows dynamic annotation rows based on groups and group and
227    * alignment associated auto-annotation state flags apply the current
228    * group/autoannotation settings to the alignment view. Usually you should
229    * call the AlignmentViewPanel.adjustAnnotationHeight() method afterwards to
230    * ensure the annotation panel bounds are set correctly.
231    * 
232    * @param applyGlobalSettings
233    *          - apply to all autoannotation rows or just the ones associated
234    *          with the current visible region
235    * @param preserveNewGroupSettings
236    *          - don't apply global settings to groups which don't already have
237    *          group associated annotation
238    */
239   void updateGroupAnnotationSettings(boolean applyGlobalSettings,
240           boolean preserveNewGroupSettings);
241
242   void setSequenceColour(SequenceI seq, Color col);
243
244   Color getSequenceColour(SequenceI seq);
245
246   void updateSequenceIdColours();
247
248   SequenceGroup getSelectionGroup();
249
250   /**
251    * get the currently selected sequence objects or all the sequences in the
252    * alignment. TODO: change to List<>
253    * 
254    * @return array of references to sequence objects
255    */
256   SequenceI[] getSequenceSelection();
257
258   void clearSequenceColours();
259
260   /**
261    * This method returns the visible alignment as text, as seen on the GUI, ie
262    * if columns are hidden they will not be returned in the result. Use this for
263    * calculating trees, PCA, redundancy etc on views which contain hidden
264    * columns.
265    * 
266    * @return String[]
267    */
268   CigarArray getViewAsCigars(boolean selectedRegionOnly);
269
270   /**
271    * return a compact representation of the current alignment selection to pass
272    * to an analysis function
273    * 
274    * @param selectedOnly
275    *          boolean true to just return the selected view
276    * @return AlignmentView
277    */
278   AlignmentView getAlignmentView(boolean selectedOnly);
279
280   /**
281    * return a compact representation of the current alignment selection to pass
282    * to an analysis function
283    * 
284    * @param selectedOnly
285    *          boolean true to just return the selected view
286    * @param markGroups
287    *          boolean true to annotate the alignment view with groups on the
288    *          alignment (and intersecting with selected region if selectedOnly
289    *          is true)
290    * @return AlignmentView
291    */
292   AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups);
293
294   /**
295    * This method returns the visible alignment as text, as seen on the GUI, ie
296    * if columns are hidden they will not be returned in the result. Use this for
297    * calculating trees, PCA, redundancy etc on views which contain hidden
298    * columns. This method doesn't exclude hidden sequences from the output.
299    *
300    * @param selectedRegionOnly
301    *          - determines if only the selected region or entire alignment is
302    *          exported
303    * @return String[]
304    */
305   String[] getViewAsString(boolean selectedRegionOnly);
306
307   /**
308    * This method returns the visible alignment as text, as seen on the GUI, ie
309    * if columns are hidden they will not be returned in the result. Use this for
310    * calculating trees, PCA, redundancy etc on views which contain hidden
311    * columns.
312    * 
313    * @param selectedRegionOnly
314    *          - determines if only the selected region or entire alignment is
315    *          exported
316    * @param isExportHiddenSeqs
317    *          - determines if hidden sequences would be exported or not.
318    * 
319    * @return String[]
320    */
321   String[] getViewAsString(boolean selectedRegionOnly,
322           boolean isExportHiddenSeqs);
323
324   void setSelectionGroup(SequenceGroup sg);
325
326   char getGapCharacter();
327
328   void setColumnSelection(ColumnSelection cs);
329
330   void setConservation(Conservation cons);
331
332   /**
333    * get a copy of the currently visible alignment annotation
334    * 
335    * @param selectedOnly
336    *          if true - trim to selected regions on the alignment
337    * @return an empty list or new alignment annotation objects shown only
338    *         visible columns trimmed to selected region only
339    */
340   List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
341           boolean selectedOnly);
342
343   FeaturesDisplayedI getFeaturesDisplayed();
344
345   String getSequenceSetId();
346
347   boolean areFeaturesDisplayed();
348
349   void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI);
350
351   void alignmentChanged(AlignmentViewPanel ap);
352
353   /**
354    * @return the padGaps
355    */
356   boolean isPadGaps();
357
358   /**
359    * @param padGaps
360    *          the padGaps to set
361    */
362   void setPadGaps(boolean padGaps);
363
364   /**
365    * return visible region boundaries within given column range
366    * 
367    * @param min
368    *          first column (inclusive, from 0)
369    * @param max
370    *          last column (exclusive)
371    * @return int[][] range of {start,end} visible positions
372    */
373   List<int[]> getVisibleRegionBoundaries(int min, int max);
374
375   /**
376    * This method returns an array of new SequenceI objects derived from the
377    * whole alignment or just the current selection with start and end points
378    * adjusted
379    * 
380    * @note if you need references to the actual SequenceI objects in the
381    *       alignment or currently selected then use getSequenceSelection()
382    * @return selection as new sequenceI objects
383    */
384   SequenceI[] getSelectionAsNewSequence();
385
386   void invertColumnSelection();
387
388   /**
389    * broadcast selection to any interested parties
390    */
391   void sendSelection();
392
393   /**
394    * calculate the row position for alignmentIndex if all hidden sequences were
395    * shown
396    * 
397    * @param alignmentIndex
398    * @return adjusted row position
399    */
400   int adjustForHiddenSeqs(int alignmentIndex);
401
402   boolean hasHiddenRows();
403
404   /**
405    * 
406    * @return a copy of this view's current display settings
407    */
408   public ViewStyleI getViewStyle();
409
410   /**
411    * update the view's display settings with the given style set
412    * 
413    * @param settingsForView
414    */
415   public void setViewStyle(ViewStyleI settingsForView);
416
417   /**
418    * Returns a viewport which holds the cDna for this (protein), or vice versa,
419    * or null if none is set.
420    * 
421    * @return
422    */
423   AlignViewportI getCodingComplement();
424
425   /**
426    * Sets the viewport which holds the cDna for this (protein), or vice versa.
427    * Implementation should guarantee that the reciprocal relationship is always
428    * set, i.e. each viewport is the complement of the other.
429    */
430   void setCodingComplement(AlignViewportI sl);
431
432   /**
433    * Answers true if viewport hosts DNA/RNA, else false.
434    * 
435    * @return
436    */
437   boolean isNucleotide();
438
439   /**
440    * Returns an id guaranteed to be unique for this viewport.
441    * 
442    * @return
443    */
444   String getViewId();
445
446   /**
447    * Return true if view should scroll to show the highlighted region of a
448    * sequence
449    * 
450    * @return
451    */
452   boolean isFollowHighlight();
453
454   /**
455    * Set whether view should scroll to show the highlighted region of a sequence
456    */
457   void setFollowHighlight(boolean b);
458
459   public void applyFeaturesStyle(FeatureSettingsModelI featureSettings);
460
461   /**
462    * check if current selection group is defined on the view, or is simply a
463    * temporary group.
464    * 
465    * @return true if group is defined on the alignment
466    */
467   boolean isSelectionDefinedGroup();
468
469   /**
470    * 
471    * @return true if there are search results on the view
472    */
473   boolean hasSearchResults();
474
475   /**
476    * set the search results for the view
477    * 
478    * @param results
479    *          - or null to clear current results
480    */
481   void setSearchResults(SearchResultsI results);
482
483   /**
484    * get search results for this view (if any)
485    * 
486    * @return search results or null
487    */
488   SearchResultsI getSearchResults();
489
490   /**
491    * Updates view settings with the given font. You may need to call
492    * AlignmentPanel.fontChanged to update the layout geometry.
493    * 
494    * @param setGrid
495    *          when true, charWidth/height is set according to font metrics
496    */
497   void setFont(Font newFont, boolean b);
498
499   /**
500    * Answers true if split screen protein and cDNA use the same font
501    * 
502    * @return
503    */
504   @Override
505   boolean isProteinFontAsCdna();
506
507   /**
508    * Set the flag for whether split screen protein and cDNA use the same font
509    * 
510    * @return
511    */
512   @Override
513   void setProteinFontAsCdna(boolean b);
514 }