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