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