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