Merge develop to Release_2_8_3_Branch
[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.SequenceCollectionI;
30 import jalview.datamodel.SequenceGroup;
31 import jalview.datamodel.SequenceI;
32 import jalview.schemes.ColourSchemeI;
33
34 import java.awt.Color;
35 import java.util.Hashtable;
36 import java.util.List;
37 import java.util.Map;
38
39 /**
40  * @author jimp
41  * 
42  */
43 public interface AlignViewportI extends ViewStyleI
44 {
45
46   int getCharWidth();
47
48   int getEndRes();
49
50   int getCharHeight();
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   boolean hasHiddenColumns();
61
62   boolean isValidCharWidth();
63
64   boolean isShowConsensusHistogram();
65
66   boolean isShowSequenceLogo();
67
68   boolean isNormaliseSequenceLogo();
69
70   ColourSchemeI getGlobalColourScheme();
71
72   AlignmentI getAlignment();
73
74   ColumnSelection getColumnSelection();
75
76   Hashtable[] getSequenceConsensusHash();
77
78   /**
79    * Get consensus data table for the cDNA complement of this alignment (if any)
80    * 
81    * @return
82    */
83   Hashtable[] getComplementConsensusHash();
84
85   Hashtable[] getRnaStructureConsensusHash();
86
87   boolean isIgnoreGapsConsensus();
88
89   boolean isCalculationInProgress(AlignmentAnnotation alignmentAnnotation);
90
91   AlignmentAnnotation getAlignmentQualityAnnot();
92
93   AlignmentAnnotation getAlignmentConservationAnnotation();
94
95   /**
96    * get the container for alignment consensus annotation
97    * 
98    * @return
99    */
100   AlignmentAnnotation getAlignmentConsensusAnnotation();
101
102   /**
103    * get the container for cDNA complement consensus annotation
104    * 
105    * @return
106    */
107   AlignmentAnnotation getComplementConsensusAnnotation();
108
109   /**
110    * Test to see if viewport is still open and active
111    * 
112    * @return true indicates that all references to viewport should be dropped
113    */
114   boolean isClosed();
115
116   /**
117    * get the associated calculation thread manager for the view
118    * 
119    * @return
120    */
121   AlignCalcManagerI getCalcManager();
122
123   /**
124    * get the percentage gaps allowed in a conservation calculation
125    * 
126    */
127   public int getConsPercGaps();
128
129   /**
130    * set the consensus result object for the viewport
131    * 
132    * @param hconsensus
133    */
134   void setSequenceConsensusHash(Hashtable[] hconsensus);
135
136   /**
137    * Set the cDNA complement consensus for the viewport
138    * 
139    * @param hconsensus
140    */
141   void setComplementConsensusHash(Hashtable[] hconsensus);
142
143   /**
144    * 
145    * @return the alignment annotatino row for the structure consensus
146    *         calculation
147    */
148   AlignmentAnnotation getAlignmentStrucConsensusAnnotation();
149
150   /**
151    * set the Rna structure consensus result object for the viewport
152    * 
153    * @param hStrucConsensus
154    */
155   void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus);
156
157   /**
158    * set global colourscheme
159    * 
160    * @param rhc
161    */
162   void setGlobalColourScheme(ColourSchemeI rhc);
163
164   Map<SequenceI, SequenceCollectionI> getHiddenRepSequences();
165
166   void setHiddenRepSequences(
167           Map<SequenceI, SequenceCollectionI> hiddenRepSequences);
168
169   /**
170    * hides or shows dynamic annotation rows based on groups and group and
171    * alignment associated auto-annotation state flags apply the current
172    * group/autoannotation settings to the alignment view. Usually you should
173    * call the AlignmentViewPanel.adjustAnnotationHeight() method afterwards to
174    * ensure the annotation panel bounds are set correctly.
175    * 
176    * @param applyGlobalSettings
177    *          - apply to all autoannotation rows or just the ones associated
178    *          with the current visible region
179    * @param preserveNewGroupSettings
180    *          - don't apply global settings to groups which don't already have
181    *          group associated annotation
182    */
183   void updateGroupAnnotationSettings(boolean applyGlobalSettings,
184           boolean preserveNewGroupSettings);
185   
186   /**
187    * @return true if a reference sequence is set and should be displayed
188    */
189   public boolean isDisplayReferenceSeq();
190
191   /**
192    * @return set the flag for displaying reference sequences when they are
193    *         available
194    */
195   public void setDisplayReferenceSeq(boolean displayReferenceSeq);
196
197   /**
198    * @return true if colourschemes should render according to reference sequence
199    *         rather than consensus if available
200    */
201   public boolean isColourByReferenceSeq();
202
203   /**
204    * @return true set flag for deciding if colourschemes should render according
205    *         to reference sequence rather than consensus if available
206    */
207   public void setColourByReferenceSeq(boolean colourByReferenceSeq);
208
209   void setSequenceColour(SequenceI seq, Color col);
210
211   Color getSequenceColour(SequenceI seq);
212
213   void updateSequenceIdColours();
214
215   SequenceGroup getSelectionGroup();
216
217   /**
218    * get the currently selected sequence objects or all the sequences in the
219    * alignment. TODO: change to List<>
220    * 
221    * @return array of references to sequence objects
222    */
223   SequenceI[] getSequenceSelection();
224
225   void clearSequenceColours();
226
227   /**
228    * This method returns the visible alignment as text, as seen on the GUI, ie
229    * if columns are hidden they will not be returned in the result. Use this for
230    * calculating trees, PCA, redundancy etc on views which contain hidden
231    * columns.
232    * 
233    * @return String[]
234    */
235   CigarArray getViewAsCigars(boolean selectedRegionOnly);
236
237   /**
238    * return a compact representation of the current alignment selection to pass
239    * to an analysis function
240    * 
241    * @param selectedOnly
242    *          boolean true to just return the selected view
243    * @return AlignmentView
244    */
245   AlignmentView getAlignmentView(boolean selectedOnly);
246
247   /**
248    * return a compact representation of the current alignment selection to pass
249    * to an analysis function
250    * 
251    * @param selectedOnly
252    *          boolean true to just return the selected view
253    * @param markGroups
254    *          boolean true to annotate the alignment view with groups on the
255    *          alignment (and intersecting with selected region if selectedOnly
256    *          is true)
257    * @return AlignmentView
258    */
259   AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups);
260
261   /**
262    * This method returns the visible alignment as text, as seen on the GUI, ie
263    * if columns are hidden they will not be returned in the result. Use this for
264    * calculating trees, PCA, redundancy etc on views which contain hidden
265    * columns.
266    * 
267    * @return String[]
268    */
269   String[] getViewAsString(boolean selectedRegionOnly);
270
271   void setSelectionGroup(SequenceGroup sg);
272
273   char getGapCharacter();
274
275   void setColumnSelection(ColumnSelection cs);
276
277   void setConservation(Conservation cons);
278
279   /**
280    * get a copy of the currently visible alignment annotation
281    * @param selectedOnly if true - trim to selected regions on the alignment
282    * @return an empty list or new alignment annotation objects shown only visible columns trimmed to selected region only
283    */
284   List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
285           boolean selectedOnly);
286
287   FeaturesDisplayedI getFeaturesDisplayed();
288
289   String getSequenceSetId();
290
291   boolean isShowSequenceFeatures();
292
293   void setShowSequenceFeatures(boolean b);
294
295   /**
296    * 
297    * @param flag
298    *          indicating if annotation panel shown below alignment
299    * 
300    */
301   void setShowAnnotation(boolean b);
302
303   /**
304    * flag indicating if annotation panel shown below alignment
305    * 
306    * @return
307    */
308   boolean isShowAnnotation();
309
310   boolean isRightAlignIds();
311
312   void setRightAlignIds(boolean rightAlignIds);
313
314   boolean areFeaturesDisplayed();
315
316   void setShowSequenceFeaturesHeight(boolean selected);
317
318   boolean isShowSequenceFeaturesHeight();
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 }