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