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