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