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