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