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