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