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