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