Clover icon

Coverage Report

  1. Project Clover database Wed Sep 17 2025 10:52:37 BST
  2. Package jalview.viewmodel

File AlignmentViewport.java

 

Coverage histogram

../../img/srcFileCovDistChart8.png
21% of files have more coverage

Code metrics

352
805
258
1
3,536
2,425
483
0.6
3.12
258
1.87

Classes

Class Line # Actions
AlignmentViewport 91 805 483
0.763250976.3%
 

Contributing tests

This file is covered by 328 tests. .

Source view

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.viewmodel;
22   
23    import java.awt.Color;
24    import java.beans.PropertyChangeSupport;
25    import java.util.ArrayDeque;
26    import java.util.ArrayList;
27    import java.util.BitSet;
28    import java.util.Deque;
29    import java.util.HashMap;
30    import java.util.Hashtable;
31    import java.util.Iterator;
32    import java.util.List;
33    import java.util.Map;
34   
35    import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
36    import jalview.analysis.AlignmentUtils;
37    import jalview.analysis.Conservation;
38    import jalview.analysis.TreeModel;
39    import jalview.api.AlignCalcManagerI;
40    import jalview.api.AlignExportSettingsI;
41    import jalview.api.AlignViewportI;
42    import jalview.api.AlignmentViewPanel;
43    import jalview.api.FeaturesDisplayedI;
44    import jalview.api.ViewStyleI;
45    import jalview.bin.Console;
46    import jalview.commands.CommandI;
47    import jalview.datamodel.AlignedCodonFrame;
48    import jalview.datamodel.AlignmentAnnotation;
49    import jalview.datamodel.AlignmentExportData;
50    import jalview.datamodel.AlignmentI;
51    import jalview.datamodel.AlignmentView;
52    import jalview.datamodel.Annotation;
53    import jalview.datamodel.ColumnSelection;
54    import jalview.datamodel.ContactListI;
55    import jalview.datamodel.ContactMatrixI;
56    import jalview.datamodel.HiddenColumns;
57    import jalview.datamodel.HiddenSequences;
58    import jalview.datamodel.ProfilesI;
59    import jalview.datamodel.SearchResultsI;
60    import jalview.datamodel.Sequence;
61    import jalview.datamodel.SequenceCollectionI;
62    import jalview.datamodel.SequenceGroup;
63    import jalview.datamodel.SequenceI;
64    import jalview.gui.QuitHandler;
65    import jalview.project.Jalview2XML;
66    import jalview.renderer.ResidueShader;
67    import jalview.renderer.ResidueShaderI;
68    import jalview.schemes.ColourSchemeI;
69    import jalview.structure.CommandListener;
70    import jalview.structure.StructureSelectionManager;
71    import jalview.structure.VamsasSource;
72    import jalview.util.Comparison;
73    import jalview.util.Constants;
74    import jalview.util.MapList;
75    import jalview.util.MappingUtils;
76    import jalview.util.MessageManager;
77    import jalview.viewmodel.styles.ViewStyle;
78    import jalview.workers.AlignCalcManager;
79    import jalview.workers.ComplementConsensusThread;
80    import jalview.workers.ConsensusThread;
81    import jalview.workers.SecondaryStructureConsensusThread;
82    import jalview.workers.StrucConsensusThread;
83   
84    /**
85    * base class holding visualization and analysis attributes and common logic for
86    * an active alignment view displayed in the GUI
87    *
88    * @author jimp
89    *
90    */
 
91    public abstract class AlignmentViewport
92    implements AlignViewportI, CommandListener, VamsasSource
93    {
94    protected ViewportRanges ranges;
95   
96    protected ViewStyleI viewStyle = new ViewStyle();
97   
98    /**
99    * A viewport that hosts the cDna view of this (protein), or vice versa (if
100    * set).
101    */
102    AlignViewportI codingComplement = null;
103   
104    FeaturesDisplayedI featuresDisplayed = null;
105   
106    protected Deque<CommandI> historyList = new ArrayDeque<>();
107   
108    protected Deque<CommandI> redoList = new ArrayDeque<>();
109   
110    /**
111    * used to determine if quit should be confirmed
112    */
113    private boolean savedUpToDate = false;
114   
115    /**
116    * alignment displayed in the viewport. Please use get/setter
117    */
118    protected AlignmentI alignment;
119   
 
120  531 toggle public AlignmentViewport(AlignmentI al)
121    {
122  531 setAlignment(al);
123  531 ranges = new ViewportRanges(al);
124    }
125   
126    /**
127    * @param name
128    * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
129    */
 
130  0 toggle @Override
131    public void setFontName(String name)
132    {
133  0 viewStyle.setFontName(name);
134    }
135   
136    /**
137    * @param style
138    * @see jalview.api.ViewStyleI#setFontStyle(int)
139    */
 
140  0 toggle @Override
141    public void setFontStyle(int style)
142    {
143  0 viewStyle.setFontStyle(style);
144    }
145   
146    /**
147    * @param size
148    * @see jalview.api.ViewStyleI#setFontSize(int)
149    */
 
150  0 toggle @Override
151    public void setFontSize(int size)
152    {
153  0 viewStyle.setFontSize(size);
154    }
155   
156    /**
157    * @return
158    * @see jalview.api.ViewStyleI#getFontStyle()
159    */
 
160  0 toggle @Override
161    public int getFontStyle()
162    {
163  0 return viewStyle.getFontStyle();
164    }
165   
166    /**
167    * @return
168    * @see jalview.api.ViewStyleI#getFontName()
169    */
 
170  0 toggle @Override
171    public String getFontName()
172    {
173  0 return viewStyle.getFontName();
174    }
175   
176    /**
177    * @return
178    * @see jalview.api.ViewStyleI#getFontSize()
179    */
 
180  0 toggle @Override
181    public int getFontSize()
182    {
183  0 return viewStyle.getFontSize();
184    }
185   
186    /**
187    * @param upperCasebold
188    * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
189    */
 
190  0 toggle @Override
191    public void setUpperCasebold(boolean upperCasebold)
192    {
193  0 viewStyle.setUpperCasebold(upperCasebold);
194    }
195   
196    /**
197    * @return
198    * @see jalview.api.ViewStyleI#isUpperCasebold()
199    */
 
200  0 toggle @Override
201    public boolean isUpperCasebold()
202    {
203  0 return viewStyle.isUpperCasebold();
204    }
205   
206    /**
207    * @return
208    * @see jalview.api.ViewStyleI#isSeqNameItalics()
209    */
 
210  3052 toggle @Override
211    public boolean isSeqNameItalics()
212    {
213  3052 return viewStyle.isSeqNameItalics();
214    }
215   
216    /**
217    * @param colourByReferenceSeq
218    * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
219    */
 
220  10 toggle @Override
221    public void setColourByReferenceSeq(boolean colourByReferenceSeq)
222    {
223  10 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
224    }
225   
226    /**
227    * @param b
228    * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
229    */
 
230  724 toggle @Override
231    public void setColourAppliesToAllGroups(boolean b)
232    {
233  724 viewStyle.setColourAppliesToAllGroups(b);
234    }
235   
236    /**
237    * @return
238    * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
239    */
 
240  1004 toggle @Override
241    public boolean getColourAppliesToAllGroups()
242    {
243  1004 return viewStyle.getColourAppliesToAllGroups();
244    }
245   
246    /**
247    * @return
248    * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
249    */
 
250  911 toggle @Override
251    public boolean getAbovePIDThreshold()
252    {
253  911 return viewStyle.getAbovePIDThreshold();
254    }
255   
 
256  911 toggle @Override
257    public boolean getByConsensusSecondaryStructureSelected()
258    {
259  911 return viewStyle.getByConsensusSecondaryStructureSelected();
260    }
261   
 
262  89 toggle public void setShowStructureProvider(boolean b)
263    {
264  89 viewStyle.setShowStructureProvider(b);
265    }
266   
 
267  6537 toggle public boolean isShowStructureProvider()
268    {
269  6537 return viewStyle.isShowStructureProvider();
270    }
271   
272    /**
273    * @param inc
274    * @see jalview.api.ViewStyleI#setIncrement(int)
275    */
 
276  89 toggle @Override
277    public void setIncrement(int inc)
278    {
279  89 viewStyle.setIncrement(inc);
280    }
281   
282    /**
283    * @return
284    * @see jalview.api.ViewStyleI#getIncrement()
285    */
 
286  0 toggle @Override
287    public int getIncrement()
288    {
289  0 return viewStyle.getIncrement();
290    }
291   
292    /**
293    * @param inc
294    * @see jalview.api.ViewStyleI#setConsensusSecondaryStructureThreshold(int)
295    */
 
296  89 toggle @Override
297    public void setConsensusSecondaryStructureThreshold(int val)
298    {
299  89 viewStyle.setConsensusSecondaryStructureThreshold(val);
300    }
301   
302    /**
303    * @return
304    * @see jalview.api.ViewStyleI#getConsensusSecondaryStructureThreshold()
305    */
 
306  0 toggle @Override
307    public int getConsensusSecondaryStructureThreshold()
308    {
309  0 return viewStyle.getConsensusSecondaryStructureThreshold();
310    }
311   
312    /**
313    * @param b
314    * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
315    */
 
316  97 toggle @Override
317    public void setConservationSelected(boolean b)
318    {
319  97 viewStyle.setConservationSelected(b);
320    }
321   
322    /**
323    * @param show
324    * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
325    */
 
326  0 toggle @Override
327    public void setShowHiddenMarkers(boolean show)
328    {
329  0 viewStyle.setShowHiddenMarkers(show);
330    }
331   
332    /**
333    * @return
334    * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
335    */
 
336  5252 toggle @Override
337    public boolean getShowHiddenMarkers()
338    {
339  5252 return viewStyle.getShowHiddenMarkers();
340    }
341   
342    /**
343    * @param b
344    * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
345    */
 
346  9 toggle @Override
347    public void setScaleRightWrapped(boolean b)
348    {
349  9 viewStyle.setScaleRightWrapped(b);
350    }
351   
352    /**
353    * @param b
354    * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
355    */
 
356  11 toggle @Override
357    public void setScaleLeftWrapped(boolean b)
358    {
359  11 viewStyle.setScaleLeftWrapped(b);
360    }
361   
362    /**
363    * @param b
364    * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
365    */
 
366  9 toggle @Override
367    public void setScaleAboveWrapped(boolean b)
368    {
369  9 viewStyle.setScaleAboveWrapped(b);
370    }
371   
372    /**
373    * @return
374    * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
375    */
 
376  1232 toggle @Override
377    public boolean getScaleLeftWrapped()
378    {
379  1232 return viewStyle.getScaleLeftWrapped();
380    }
381   
382    /**
383    * @return
384    * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
385    */
 
386  856 toggle @Override
387    public boolean getScaleAboveWrapped()
388    {
389  856 return viewStyle.getScaleAboveWrapped();
390    }
391   
392    /**
393    * @return
394    * @see jalview.api.ViewStyleI#getScaleRightWrapped()
395    */
 
396  1991 toggle @Override
397    public boolean getScaleRightWrapped()
398    {
399  1991 return viewStyle.getScaleRightWrapped();
400    }
401   
402    /**
403    * @param b
404    * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
405    */
 
406  98 toggle @Override
407    public void setAbovePIDThreshold(boolean b)
408    {
409  98 viewStyle.setAbovePIDThreshold(b);
410    }
411   
 
412  89 toggle @Override
413    public void setByConsensusSecondaryStructureSelected(boolean b)
414    {
415  89 viewStyle.setByConsensusSecondaryStructureSelected(b);
416    }
417   
418    /**
419    * @param thresh
420    * @see jalview.api.ViewStyleI#setThreshold(int)
421    */
 
422  110 toggle @Override
423    public void setThreshold(int thresh)
424    {
425  110 viewStyle.setThreshold(thresh);
426    }
427   
428    /**
429    * @return
430    * @see jalview.api.ViewStyleI#getThreshold()
431    */
 
432  0 toggle @Override
433    public int getThreshold()
434    {
435  0 return viewStyle.getThreshold();
436    }
437   
438    /**
439    * @return
440    * @see jalview.api.ViewStyleI#getShowJVSuffix()
441    */
 
442  46562 toggle @Override
443    public boolean getShowJVSuffix()
444    {
445  46562 return viewStyle.getShowJVSuffix();
446    }
447   
448    /**
449    * @param b
450    * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
451    */
 
452  90 toggle @Override
453    public void setShowJVSuffix(boolean b)
454    {
455  90 viewStyle.setShowJVSuffix(b);
456    }
457   
458    /**
459    * @param state
460    * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
461    */
 
462  101 toggle @Override
463    public void setWrapAlignment(boolean state)
464    {
465  101 viewStyle.setWrapAlignment(state);
466  101 ranges.setWrappedMode(state);
467    }
468   
469    /**
470    * @param state
471    * @see jalview.api.ViewStyleI#setShowText(boolean)
472    */
 
473  89 toggle @Override
474    public void setShowText(boolean state)
475    {
476  89 viewStyle.setShowText(state);
477    }
478   
479    /**
480    * @param state
481    * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
482    */
 
483  89 toggle @Override
484    public void setRenderGaps(boolean state)
485    {
486  89 viewStyle.setRenderGaps(state);
487    }
488   
489    /**
490    * @return
491    * @see jalview.api.ViewStyleI#getColourText()
492    */
 
493  480707 toggle @Override
494    public boolean getColourText()
495    {
496  480707 return viewStyle.getColourText();
497    }
498   
499    /**
500    * @param state
501    * @see jalview.api.ViewStyleI#setColourText(boolean)
502    */
 
503  89 toggle @Override
504    public void setColourText(boolean state)
505    {
506  89 viewStyle.setColourText(state);
507    }
508   
509    /**
510    * @return
511    * @see jalview.api.ViewStyleI#getWrapAlignment()
512    */
 
513  31328 toggle @Override
514    public boolean getWrapAlignment()
515    {
516  31328 return viewStyle.getWrapAlignment();
517    }
518   
519    /**
520    * @return
521    * @see jalview.api.ViewStyleI#getShowText()
522    */
 
523  481410 toggle @Override
524    public boolean getShowText()
525    {
526  481410 return viewStyle.getShowText();
527    }
528   
529    /**
530    * @return
531    * @see jalview.api.ViewStyleI#getWrappedWidth()
532    */
 
533  2 toggle @Override
534    public int getWrappedWidth()
535    {
536  2 return viewStyle.getWrappedWidth();
537    }
538   
539    /**
540    * @param w
541    * @see jalview.api.ViewStyleI#setWrappedWidth(int)
542    */
 
543  785 toggle @Override
544    public void setWrappedWidth(int w)
545    {
546  785 viewStyle.setWrappedWidth(w);
547    }
548   
549    /**
550    * @return
551    * @see jalview.api.ViewStyleI#getCharHeight()
552    */
 
553  109154 toggle @Override
554    public int getCharHeight()
555    {
556  109154 return viewStyle.getCharHeight();
557    }
558   
559    /**
560    * @param h
561    * @see jalview.api.ViewStyleI#setCharHeight(int)
562    */
 
563  623 toggle @Override
564    public void setCharHeight(int h)
565    {
566  623 viewStyle.setCharHeight(h);
567    }
568   
569    /**
570    * @return
571    * @see jalview.api.ViewStyleI#getCharWidth()
572    */
 
573  1458625 toggle @Override
574    public int getCharWidth()
575    {
576  1458625 return viewStyle.getCharWidth();
577    }
578   
579    /**
580    * @param w
581    * @see jalview.api.ViewStyleI#setCharWidth(int)
582    */
 
583  626 toggle @Override
584    public void setCharWidth(int w)
585    {
586  626 viewStyle.setCharWidth(w);
587    }
588   
589    /**
590    * @return
591    * @see jalview.api.ViewStyleI#getShowBoxes()
592    */
 
593  552753 toggle @Override
594    public boolean getShowBoxes()
595    {
596  552766 return viewStyle.getShowBoxes();
597    }
598   
599    /**
600    * @return
601    * @see jalview.api.ViewStyleI#getShowUnconserved()
602    */
 
603  479000 toggle @Override
604    public boolean getShowUnconserved()
605    {
606  479000 return viewStyle.getShowUnconserved();
607    }
608   
609    /**
610    * @param showunconserved
611    * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
612    */
 
613  89 toggle @Override
614    public void setShowUnconserved(boolean showunconserved)
615    {
616  89 viewStyle.setShowUnconserved(showunconserved);
617    }
618   
619    /**
620    * @param default1
621    * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
622    */
 
623  0 toggle @Override
624    public void setSeqNameItalics(boolean default1)
625    {
626  0 viewStyle.setSeqNameItalics(default1);
627    }
628   
 
629  241688 toggle @Override
630    public AlignmentI getAlignment()
631    {
632  241688 return alignment;
633    }
634   
 
635  0 toggle @Override
636    public char getGapCharacter()
637    {
638  0 return alignment.getGapCharacter();
639    }
640   
641    protected String sequenceSetID;
642   
643    /**
644    * probably unused indicator that view is of a dataset rather than an
645    * alignment
646    */
647    protected boolean isDataset = false;
648   
 
649  0 toggle public void setDataset(boolean b)
650    {
651  0 isDataset = b;
652    }
653   
 
654  501 toggle public boolean isDataset()
655    {
656  501 return isDataset;
657    }
658   
659    private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
660   
661    protected ColumnSelection colSel = new ColumnSelection();
662   
663    public boolean autoCalculateConsensus = true;
664   
665    protected boolean autoCalculateStrucConsensus = true;
666   
667    protected boolean ignoreGapsInConsensusCalculation = false;
668   
669    protected ResidueShaderI residueShading = new ResidueShader();
670   
 
671  285 toggle @Override
672    public void setGlobalColourScheme(ColourSchemeI cs)
673    {
674    // TODO: logic refactored from AlignFrame changeColour -
675    // TODO: autorecalc stuff should be changed to rely on the worker system
676    // check to see if we should implement a changeColour(cs) method rather than
677    // put the logic in here
678    // - means that caller decides if they want to just modify state and defer
679    // calculation till later or to do all calculations in thread.
680    // via changecolour
681   
682    /*
683    * only instantiate alignment colouring once, thereafter update it;
684    * this means that any conservation or PID threshold settings
685    * persist when the alignment colour scheme is changed
686    */
687  285 if (residueShading == null)
688    {
689  0 residueShading = new ResidueShader(viewStyle);
690    }
691  285 residueShading.setColourScheme(cs);
692   
693    // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
694    // ...problem: groups need these, but do not currently have a ViewStyle
695   
696  285 if (cs != null)
697    {
698  88 if (getConservationSelected())
699    {
700  15 residueShading.setConservation(hconservation);
701    }
702    /*
703    * reset conservation flag in case just set to false if
704    * Conservation was null (calculation still in progress)
705    */
706  88 residueShading.setConservationApplied(getConservationSelected());
707  88 residueShading.alignmentChanged(alignment, hiddenRepSequences);
708    }
709   
710    /*
711    * if 'apply colour to all groups' is selected... do so
712    * (but don't transfer any colour threshold settings to groups)
713    */
714  285 if (getColourAppliesToAllGroups())
715    {
716  89 for (SequenceGroup sg : getAlignment().getGroups())
717    {
718    /*
719    * retain any colour thresholds per group while
720    * changing choice of colour scheme (JAL-2386)
721    */
722  9 sg.setColourScheme(cs == null ? null : cs.getInstance(this, sg));
723  9 if (cs != null)
724    {
725  8 sg.getGroupColourScheme().alignmentChanged(sg,
726    hiddenRepSequences);
727    }
728    }
729    }
730    }
731   
 
732  1463 toggle @Override
733    public ColourSchemeI getGlobalColourScheme()
734    {
735  1463 return residueShading == null ? null : residueShading.getColourScheme();
736    }
737   
 
738  557907 toggle @Override
739    public ResidueShaderI getResidueShading()
740    {
741  557910 return residueShading;
742    }
743   
744    protected AlignmentAnnotation consensus;
745   
746    protected List<AlignmentAnnotation> secondaryStructureConsensus;
747   
748    protected AlignmentAnnotation complementConsensus;
749   
750    protected AlignmentAnnotation gapcounts;
751   
752    protected AlignmentAnnotation strucConsensus;
753   
754    protected AlignmentAnnotation conservation;
755   
756    protected AlignmentAnnotation quality;
757   
758    protected AlignmentAnnotation[] groupConsensus;
759   
760    protected AlignmentAnnotation[] groupSSConsensus;
761   
762    protected AlignmentAnnotation[] groupConservation;
763   
764    /**
765    * results of alignment consensus analysis for visible portion of view
766    */
767    protected ProfilesI hconsensus = null;
768   
769    protected Map<String, ProfilesI> hSSConsensusProfileMap = null;
770   
771   
772    /**
773    * results of cDNA complement consensus visible portion of view
774    */
775    protected Hashtable<String, Object>[] hcomplementConsensus = null;
776   
777    /**
778    * results of secondary structure base pair consensus for visible portion of
779    * view
780    */
781    protected Hashtable<String, Object>[] hStrucConsensus = null;
782   
783    protected Conservation hconservation = null;
784   
 
785  1454 toggle @Override
786    public void setConservation(Conservation cons)
787    {
788  1454 hconservation = cons;
789    }
790   
 
791  1876 toggle @Override
792    public List<String> getSecondaryStructureSources()
793    {
794  1876 return viewStyle.getSecondaryStructureSources();
795    }
796   
 
797  1345 toggle @Override
798    public void setSecondaryStructureSources(
799    List<String> secondaryStructureSources)
800    {
801  1345 viewStyle.setSecondaryStructureSources(secondaryStructureSources);
802    }
803   
 
804  531 toggle protected void setSecondaryStructureSources(AlignmentAnnotation[] aa)
805    {
806  531 List<String> sources = null;
807   
808  531 if (aa != null)
809    {
810  439 sources = AlignmentUtils.extractSSSourceInAlignmentAnnotation(aa);
811  439 if (sources != null)
812    {
813  439 sources.add(0, Constants.SS_ALL_PROVIDERS);
814  439 viewStyle.setSecondaryStructureSources(sources);
815    }
816    }
817    }
818   
819    /**
820    * percentage gaps allowed in a column before all amino acid properties should
821    * be considered unconserved
822    */
823    int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
824   
 
825  2412 toggle @Override
826    public int getConsPercGaps()
827    {
828  2412 return ConsPercGaps;
829    }
830   
 
831  1330 toggle @Override
832    public void setSequenceConsensusHash(ProfilesI hconsensus)
833    {
834  1330 this.hconsensus = hconsensus;
835    }
836   
 
837  1345 toggle @Override
838    public void setSequenceSSConsensusHash(
839    Map<String, ProfilesI> hSSConsensusProfileMap)
840    {
841  1345 this.hSSConsensusProfileMap = hSSConsensusProfileMap;
842    }
843   
 
844  5 toggle @Override
845    public void setComplementConsensusHash(
846    Hashtable<String, Object>[] hconsensus)
847    {
848  5 this.hcomplementConsensus = hconsensus;
849    }
850   
 
851  3982 toggle @Override
852    public ProfilesI getSequenceConsensusHash()
853    {
854  3982 return hconsensus;
855    }
856   
 
857  3993 toggle @Override
858    public Map<String, ProfilesI> getSequenceSSConsensusHash()
859    {
860  3993 return hSSConsensusProfileMap;
861    }
862   
 
863  2548 toggle @Override
864    public Hashtable<String, Object>[] getComplementConsensusHash()
865    {
866  2548 return hcomplementConsensus;
867    }
868   
 
869  2549 toggle @Override
870    public Hashtable<String, Object>[] getRnaStructureConsensusHash()
871    {
872  2549 return hStrucConsensus;
873    }
874   
 
875  6 toggle @Override
876    public void setRnaStructureConsensusHash(
877    Hashtable<String, Object>[] hStrucConsensus)
878    {
879  6 this.hStrucConsensus = hStrucConsensus;
880   
881    }
882   
 
883  2199 toggle @Override
884    public AlignmentAnnotation getAlignmentQualityAnnot()
885    {
886  2199 return quality;
887    }
888   
 
889  3092 toggle @Override
890    public AlignmentAnnotation getAlignmentConservationAnnotation()
891    {
892  3092 return conservation;
893    }
894   
 
895  7309 toggle @Override
896    public AlignmentAnnotation getAlignmentConsensusAnnotation()
897    {
898  7309 return consensus;
899    }
900   
 
901  6717 toggle @Override
902    public List<AlignmentAnnotation> getAlignmentSecondaryStructureConsensusAnnotation()
903    {
904  6717 return secondaryStructureConsensus;
905    }
906   
 
907  4120 toggle @Override
908    public AlignmentAnnotation getAlignmentGapAnnotation()
909    {
910  4120 return gapcounts;
911    }
912   
 
913  2558 toggle @Override
914    public AlignmentAnnotation getComplementConsensusAnnotation()
915    {
916  2558 return complementConsensus;
917    }
918   
 
919  2549 toggle @Override
920    public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
921    {
922  2549 return strucConsensus;
923    }
924   
925    protected AlignCalcManagerI calculator = new AlignCalcManager();
926   
927    /**
928    * trigger update of conservation annotation
929    */
 
930  1354 toggle public void updateConservation(final AlignmentViewPanel ap)
931    {
932    // see note in mantis : issue number 8585
933  1354 if (alignment.isNucleotide()
934    || (conservation == null && quality == null)
935    || !autoCalculateConsensus)
936    {
937  286 return;
938    }
939  1068 if (calculator.getRegisteredWorkersOfClass(
940    jalview.workers.ConservationThread.class) == null)
941    {
942  533 calculator.registerWorker(
943    new jalview.workers.ConservationThread(this, ap));
944    }
945    }
946   
947    /**
948    * trigger update of consensus annotation
949    */
 
950  1366 toggle public void updateConsensus(final AlignmentViewPanel ap)
951    {
952    // see note in mantis : issue number 8585
953  1366 if (consensus == null || !autoCalculateConsensus)
954    {
955  0 return;
956    }
957  1366 if (calculator
958    .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
959    {
960  507 calculator.registerWorker(new ConsensusThread(this, ap));
961    }
962   
963    /*
964    * A separate thread to compute cDNA consensus for a protein alignment
965    * which has mapping to cDNA
966    */
967  1366 final AlignmentI al = this.getAlignment();
968  1366 if (!al.isNucleotide() && al.getCodonFrames() != null
969    && !al.getCodonFrames().isEmpty())
970    {
971    /*
972    * fudge - check first for protein-to-nucleotide mappings
973    * (we don't want to do this for protein-to-protein)
974    */
975  5 boolean doConsensus = false;
976  5 for (AlignedCodonFrame mapping : al.getCodonFrames())
977    {
978    // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
979  5 MapList[] mapLists = mapping.getdnaToProt();
980    // mapLists can be empty if project load has not finished resolving seqs
981  5 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
982    {
983  5 doConsensus = true;
984  5 break;
985    }
986    }
987  5 if (doConsensus)
988    {
989  5 if (calculator.getRegisteredWorkersOfClass(
990    ComplementConsensusThread.class) == null)
991    {
992  4 calculator
993    .registerWorker(new ComplementConsensusThread(this, ap));
994    }
995    }
996    }
997    }
998   
999    /**
1000    * trigger update of Secondary Structure consensus annotation
1001    */
 
1002  1366 toggle public void updateSecondaryStructureConsensus(final AlignmentViewPanel ap)
1003    {
1004    // see note in mantis : issue number 8585
1005  1366 if (secondaryStructureConsensus == null || !autoCalculateConsensus)
1006    {
1007  0 return;
1008    }
1009  1366 List<String> ssSources = viewStyle.getSecondaryStructureSources();
1010  1366 if (secondaryStructureConsensus.size() != ssSources.size())
1011    {
1012   
1013  88 for (String source : ssSources)
1014    {
1015  107 boolean ssConsensusForSourcePresent = false;
1016  107 for (AlignmentAnnotation aa : secondaryStructureConsensus)
1017    {
1018  38 if (aa.description.startsWith(source))
1019    {
1020  19 ssConsensusForSourcePresent = true;
1021  19 break;
1022    }
1023    }
1024   
1025  107 if (!ssConsensusForSourcePresent)
1026    {
1027  88 AlignmentAnnotation ssConsensus = new AlignmentAnnotation(
1028    MessageManager.getString("label.ssconsensus_label") + " "
1029    + source,
1030    source + " "
1031    + MessageManager
1032    .getString("label.ssconsensus_descr"),
1033    new Annotation[1], 0f, 100f,
1034    AlignmentAnnotation.BAR_GRAPH);
1035   
1036  88 ssConsensus.hasText = true;
1037  88 ssConsensus.autoCalculated = true;
1038  88 secondaryStructureConsensus.add(ssConsensus);
1039  88 if (showSSConsensus)
1040    {
1041  0 ssConsensus.visible = true;
1042  0 alignment.addAnnotation(ssConsensus);
1043   
1044    }
1045    }
1046    }
1047    }
1048  1366 if (calculator.getRegisteredWorkersOfClass(
1049    SecondaryStructureConsensusThread.class) == null)
1050    {
1051  519 calculator.registerWorker(
1052    new SecondaryStructureConsensusThread(this, ap));
1053    }
1054  1366 ap.adjustAnnotationHeight();
1055   
1056    }
1057   
1058    // --------START Structure Conservation
 
1059  1363 toggle public void updateStrucConsensus(final AlignmentViewPanel ap)
1060    {
1061  1363 if (autoCalculateStrucConsensus && strucConsensus == null
1062    && alignment.isNucleotide() && alignment.hasRNAStructure())
1063    {
1064    // secondary structure has been added - so init the consensus line
1065  0 initRNAStructure();
1066    }
1067   
1068    // see note in mantis : issue number 8585
1069  1363 if (strucConsensus == null || !autoCalculateStrucConsensus)
1070    {
1071  1359 return;
1072    }
1073  4 if (calculator.getRegisteredWorkersOfClass(
1074    StrucConsensusThread.class) == null)
1075    {
1076  3 calculator.registerWorker(new StrucConsensusThread(this, ap));
1077    }
1078    }
1079   
 
1080  3010 toggle public boolean isCalcInProgress()
1081    {
1082  3010 return calculator.isWorking();
1083    }
1084   
 
1085  9640 toggle @Override
1086    public boolean isCalculationInProgress(
1087    AlignmentAnnotation alignmentAnnotation)
1088    {
1089  9640 if (!alignmentAnnotation.autoCalculated)
1090    {
1091  0 return false;
1092    }
1093  9640 if (calculator.workingInvolvedWith(alignmentAnnotation))
1094    {
1095    // jalview.bin.Console.errPrintln("grey out
1096    // ("+alignmentAnnotation.label+")");
1097  339 return true;
1098    }
1099  9301 return false;
1100    }
1101   
 
1102  800 toggle public void setAlignment(AlignmentI align)
1103    {
1104  800 this.alignment = align;
1105    }
1106   
1107    /**
1108    * Clean up references when this viewport is closed
1109    */
 
1110  269 toggle @Override
1111    public void dispose()
1112    {
1113    /*
1114    * defensively null out references to large objects in case
1115    * this object is not garbage collected (as if!)
1116    */
1117  269 consensus = null;
1118  269 complementConsensus = null;
1119  269 strucConsensus = null;
1120  269 secondaryStructureConsensus = null;
1121  269 conservation = null;
1122  269 quality = null;
1123  269 groupConsensus = null;
1124  269 groupConservation = null;
1125  269 hconsensus = null;
1126  269 hconservation = null;
1127  269 hcomplementConsensus = null;
1128  269 gapcounts = null;
1129  269 calculator = null;
1130  269 residueShading = null; // may hold a reference to Consensus
1131  269 changeSupport = null;
1132  269 ranges = null;
1133  269 currentTree = null;
1134  269 selectionGroup = null;
1135  269 colSel = null;
1136  269 setAlignment(null);
1137    }
1138   
 
1139  5614 toggle @Override
1140    public boolean isClosed()
1141    {
1142    // TODO: check that this isClosed is only true after panel is closed, not
1143    // before it is fully constructed.
1144  5614 return alignment == null;
1145    }
1146   
 
1147  1879 toggle @Override
1148    public AlignCalcManagerI getCalcManager()
1149    {
1150  1879 return calculator;
1151    }
1152   
1153    /**
1154    * should conservation rows be shown for groups
1155    */
1156    protected boolean showGroupConservation = false;
1157   
1158    /**
1159    * should consensus rows be shown for groups
1160    */
1161    protected boolean showGroupConsensus = false;
1162   
1163    protected boolean showGroupSSConsensus = false;
1164   
1165    /**
1166    * should consensus profile be rendered by default
1167    */
1168    protected boolean showSequenceLogo = false;
1169   
1170    /**
1171    * should consensus profile be rendered normalised to row height
1172    */
1173    protected boolean normaliseSequenceLogo = false;
1174   
1175    /**
1176    * should consensus histograms be rendered by default
1177    */
1178    protected boolean showConsensusHistogram = true;
1179   
1180    /**
1181    * @return the showConsensusProfile
1182    */
 
1183  6167 toggle @Override
1184    public boolean isShowSequenceLogo()
1185    {
1186  6167 return showSequenceLogo;
1187    }
1188   
1189    /**
1190    * @param showSequenceLogo
1191    * the new value
1192    */
 
1193  89 toggle public void setShowSequenceLogo(boolean showSequenceLogo)
1194    {
1195  89 if (showSequenceLogo != this.showSequenceLogo)
1196    {
1197    // TODO: decouple settings setting from calculation when refactoring
1198    // annotation update method from alignframe to viewport
1199  20 this.showSequenceLogo = showSequenceLogo;
1200  20 calculator.updateAnnotationFor(ConsensusThread.class);
1201  20 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1202  20 calculator.updateAnnotationFor(StrucConsensusThread.class);
1203   
1204    // to do
1205   
1206  20 calculator
1207    .updateAnnotationFor(SecondaryStructureConsensusThread.class);
1208    }
1209  89 this.showSequenceLogo = showSequenceLogo;
1210    }
1211   
1212    /**
1213    * @param showConsensusHistogram
1214    * the showConsensusHistogram to set
1215    */
 
1216  89 toggle public void setShowConsensusHistogram(boolean showConsensusHistogram)
1217    {
1218  89 this.showConsensusHistogram = showConsensusHistogram;
1219    }
1220   
1221    /**
1222    * @return the showGroupConservation
1223    */
 
1224  886 toggle public boolean isShowGroupConservation()
1225    {
1226  886 return showGroupConservation;
1227    }
1228   
1229    /**
1230    * @param showGroupConservation
1231    * the showGroupConservation to set
1232    */
 
1233  89 toggle public void setShowGroupConservation(boolean showGroupConservation)
1234    {
1235  89 this.showGroupConservation = showGroupConservation;
1236    }
1237   
1238    /**
1239    * @return the showGroupConsensus
1240    */
 
1241  886 toggle public boolean isShowGroupConsensus()
1242    {
1243  886 return showGroupConsensus;
1244    }
1245   
 
1246  886 toggle public boolean isShowGroupSSConsensus()
1247    {
1248  886 return showGroupSSConsensus;
1249    }
1250   
1251    /**
1252    * @param showGroupConsensus
1253    * the showGroupConsensus to set
1254    */
 
1255  89 toggle public void setShowGroupConsensus(boolean showGroupConsensus)
1256    {
1257  89 this.showGroupConsensus = showGroupConsensus;
1258    }
1259   
 
1260  89 toggle public void setShowGroupSSConsensus(boolean showGroupSSConsensus)
1261    {
1262  89 this.showGroupSSConsensus = showGroupSSConsensus;
1263    }
1264   
1265    /**
1266    * @param showSSConsensus
1267    * the showSSConsensus to set
1268    */
 
1269  0 toggle public void setShowSSConsensus(boolean showSSConsensus)
1270    {
1271  0 this.showSSConsensus = showSSConsensus;
1272    }
1273   
1274    /**
1275    *
1276    * @return flag to indicate if the consensus histogram should be rendered by
1277    * default
1278    */
 
1279  3429 toggle @Override
1280    public boolean isShowConsensusHistogram()
1281    {
1282  3429 return this.showConsensusHistogram;
1283    }
1284   
1285    /**
1286    * when set, updateAlignment will always ensure sequences are of equal length
1287    */
1288    private boolean padGaps = false;
1289   
1290    /**
1291    * when set, alignment should be reordered according to a newly opened tree
1292    */
1293    public boolean sortByTree = false;
1294   
1295    /**
1296    *
1297    *
1298    * @return null or the currently selected sequence region
1299    */
 
1300  27749 toggle @Override
1301    public SequenceGroup getSelectionGroup()
1302    {
1303  27749 return selectionGroup;
1304    }
1305   
1306    /**
1307    * Set the selection group for this window. Also sets the current alignment as
1308    * the context for the group, if it does not already have one.
1309    * @param sg
1310    * - group holding references to sequences in this alignment view
1311    *
1312    */
 
1313  150 toggle @Override
1314    public void setSelectionGroup(SequenceGroup sg)
1315    {
1316  150 selectionGroup = sg;
1317  150 if (sg != null && sg.getContext() == null)
1318    {
1319  37 sg.setContext(alignment);
1320    }
1321    }
1322   
 
1323  1 toggle public void setHiddenColumns(HiddenColumns hidden)
1324    {
1325  1 this.alignment.setHiddenColumns(hidden);
1326    }
1327   
 
1328  5067 toggle @Override
1329    public ColumnSelection getColumnSelection()
1330    {
1331  5067 return colSel;
1332    }
1333   
 
1334  13 toggle @Override
1335    public void setColumnSelection(ColumnSelection colSel)
1336    {
1337  13 this.colSel = colSel;
1338  13 if (colSel != null)
1339    {
1340  13 updateHiddenColumns();
1341    }
1342  13 isColSelChanged(true);
1343    }
1344   
1345    /**
1346    *
1347    * @return
1348    */
 
1349  32 toggle @Override
1350    public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1351    {
1352  32 return hiddenRepSequences;
1353    }
1354   
 
1355  0 toggle @Override
1356    public void setHiddenRepSequences(
1357    Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1358    {
1359  0 this.hiddenRepSequences = hiddenRepSequences;
1360    }
1361   
 
1362  0 toggle @Override
1363    public boolean hasSelectedColumns()
1364    {
1365  0 ColumnSelection columnSelection = getColumnSelection();
1366  0 return columnSelection != null && columnSelection.hasSelectedColumns();
1367    }
1368   
 
1369  8878 toggle @Override
1370    public boolean hasHiddenColumns()
1371    {
1372  8878 return alignment.getHiddenColumns() != null
1373    && alignment.getHiddenColumns().hasHiddenColumns();
1374    }
1375   
 
1376  14 toggle public void updateHiddenColumns()
1377    {
1378    // this method doesn't really do anything now. But - it could, since a
1379    // column Selection could be in the process of modification
1380    // hasHiddenColumns = colSel.hasHiddenColumns();
1381    }
1382   
 
1383  4545 toggle @Override
1384    public boolean hasHiddenRows()
1385    {
1386  4545 return alignment.getHiddenSequences().getSize() > 0;
1387    }
1388   
1389    protected SequenceGroup selectionGroup;
1390   
 
1391  89 toggle public void setSequenceSetId(String newid)
1392    {
1393  89 if (sequenceSetID != null)
1394    {
1395  89 jalview.bin.Console.errPrintln(
1396    "Warning - overwriting a sequenceSetId for a viewport!");
1397    }
1398  89 sequenceSetID = new String(newid);
1399    }
1400   
 
1401  4528 toggle @Override
1402    public String getSequenceSetId()
1403    {
1404  4528 if (sequenceSetID == null)
1405    {
1406  383 sequenceSetID = alignment.hashCode() + "";
1407    }
1408   
1409  4528 return sequenceSetID;
1410    }
1411   
1412    /**
1413    * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1414    *
1415    */
1416    protected String viewId = null;
1417   
 
1418  619 toggle @Override
1419    public String getViewId()
1420    {
1421  619 if (viewId == null)
1422    {
1423  315 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1424    }
1425  619 return viewId;
1426    }
1427   
 
1428  92 toggle public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1429    {
1430  92 ignoreGapsInConsensusCalculation = b;
1431  92 if (ap != null)
1432    {
1433  3 updateConsensus(ap);
1434  3 updateSecondaryStructureConsensus(ap);
1435  3 if (residueShading != null)
1436    {
1437  3 residueShading.setThreshold(residueShading.getThreshold(),
1438    ignoreGapsInConsensusCalculation);
1439    }
1440    }
1441   
1442    }
1443   
1444    private long sgrouphash = -1, colselhash = -1;
1445   
1446    /**
1447    * checks current SelectionGroup against record of last hash value, and
1448    * updates record.
1449    *
1450    * @param b
1451    * update the record of last hash value
1452    *
1453    * @return true if SelectionGroup changed since last call (when b is true)
1454    */
 
1455  177 toggle public boolean isSelectionGroupChanged(boolean b)
1456    {
1457  177 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1458    : selectionGroup.hashCode();
1459  177 if (hc != -1 && hc != sgrouphash)
1460    {
1461  9 if (b)
1462    {
1463  9 sgrouphash = hc;
1464    }
1465  9 return true;
1466    }
1467  168 return false;
1468    }
1469   
1470    /**
1471    * checks current colsel against record of last hash value, and optionally
1472    * updates record.
1473    *
1474    * @param b
1475    * update the record of last hash value
1476    * @return true if colsel changed since last call (when b is true)
1477    */
 
1478  181 toggle public boolean isColSelChanged(boolean b)
1479    {
1480  181 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1481  181 if (hc != -1 && hc != colselhash)
1482    {
1483  17 if (b)
1484    {
1485  17 colselhash = hc;
1486    }
1487  17 return true;
1488    }
1489  164 return false;
1490    }
1491   
 
1492  5351 toggle @Override
1493    public boolean isIgnoreGapsConsensus()
1494    {
1495  5351 return ignoreGapsInConsensusCalculation;
1496    }
1497   
1498    // property change stuff
1499    // JBPNote Prolly only need this in the applet version.
1500    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1501    this);
1502   
1503    protected boolean showConservation = true;
1504   
1505    protected boolean showQuality = true;
1506   
1507    protected boolean showConsensus = true;
1508   
1509    protected boolean showSSConsensus = true;
1510   
1511    protected boolean showOccupancy = true;
1512   
1513    private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1514   
1515    private Map<AlignmentAnnotation, Color> annotationColours = new HashMap<>();
1516   
1517    protected SequenceAnnotationOrder sortAnnotationsBy = null;
1518   
1519    protected boolean showAutocalculatedAbove;
1520   
1521    /**
1522    * when set, view will scroll to show the highlighted position
1523    */
1524    private boolean followHighlight = true;
1525   
1526    /**
1527    * Property change listener for changes in alignment
1528    *
1529    * @param listener
1530    * DOCUMENT ME!
1531    */
 
1532  519 toggle public void addPropertyChangeListener(
1533    java.beans.PropertyChangeListener listener)
1534    {
1535  519 changeSupport.addPropertyChangeListener(listener);
1536    }
1537   
1538    /**
1539    * DOCUMENT ME!
1540    *
1541    * @param listener
1542    * DOCUMENT ME!
1543    */
 
1544  286 toggle public void removePropertyChangeListener(
1545    java.beans.PropertyChangeListener listener)
1546    {
1547  286 if (changeSupport != null)
1548    {
1549  285 changeSupport.removePropertyChangeListener(listener);
1550    }
1551    }
1552   
1553    /**
1554    * Property change listener for changes in alignment
1555    *
1556    * @param prop
1557    * DOCUMENT ME!
1558    * @param oldvalue
1559    * DOCUMENT ME!
1560    * @param newvalue
1561    * DOCUMENT ME!
1562    */
 
1563  78 toggle public void firePropertyChange(String prop, Object oldvalue,
1564    Object newvalue)
1565    {
1566  78 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1567    }
1568   
 
1569  0 toggle @Override
1570    public void notifyAlignmentChanged()
1571    {
1572  0 firePropertyChange("alignment", null, alignment);
1573    }
1574   
1575    // common hide/show column stuff
1576   
 
1577  6 toggle public void hideSelectedColumns()
1578    {
1579  6 if (colSel.isEmpty())
1580    {
1581  2 return;
1582    }
1583   
1584  4 colSel.hideSelectedColumns(alignment);
1585  4 setSelectionGroup(null);
1586  4 isColSelChanged(true);
1587    }
1588   
 
1589  71 toggle public void hideColumns(int start, int end)
1590    {
1591  71 if (start == end)
1592    {
1593  2 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1594    }
1595    else
1596    {
1597  69 alignment.getHiddenColumns().hideColumns(start, end);
1598    }
1599  71 isColSelChanged(true);
1600    }
1601   
 
1602  1 toggle public void showColumn(int col)
1603    {
1604  1 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1605  1 isColSelChanged(true);
1606    }
1607   
 
1608  5 toggle public void showAllHiddenColumns()
1609    {
1610  5 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1611  5 isColSelChanged(true);
1612    }
1613   
1614    // common hide/show seq stuff
 
1615  1 toggle public void showAllHiddenSeqs()
1616    {
1617  1 int startSeq = ranges.getStartSeq();
1618  1 int endSeq = ranges.getEndSeq();
1619   
1620  1 if (alignment.getHiddenSequences().getSize() > 0)
1621    {
1622  1 if (selectionGroup == null)
1623    {
1624  0 selectionGroup = new SequenceGroup();
1625  0 selectionGroup.setEndRes(alignment.getWidth() - 1);
1626    }
1627  1 List<SequenceI> tmp = alignment.getHiddenSequences()
1628    .showAll(hiddenRepSequences);
1629  1 for (SequenceI seq : tmp)
1630    {
1631  2 selectionGroup.addSequence(seq, false);
1632  2 setSequenceAnnotationsVisible(seq, true);
1633    }
1634   
1635  1 hiddenRepSequences = null;
1636   
1637  1 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1638   
1639  1 firePropertyChange("alignment", null, alignment.getSequences());
1640    // used to set hasHiddenRows/hiddenRepSequences here, after the property
1641    // changed event
1642  1 sendSelection();
1643    }
1644    }
1645   
 
1646  2 toggle public void showSequence(int index)
1647    {
1648  2 int startSeq = ranges.getStartSeq();
1649  2 int endSeq = ranges.getEndSeq();
1650   
1651  2 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1652    hiddenRepSequences);
1653  2 if (tmp.size() > 0)
1654    {
1655  2 if (selectionGroup == null)
1656    {
1657  2 selectionGroup = new SequenceGroup();
1658  2 selectionGroup.setEndRes(alignment.getWidth() - 1);
1659    }
1660   
1661  2 for (SequenceI seq : tmp)
1662    {
1663  3 selectionGroup.addSequence(seq, false);
1664  3 setSequenceAnnotationsVisible(seq, true);
1665    }
1666   
1667  2 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1668   
1669  2 firePropertyChange("alignment", null, alignment.getSequences());
1670  2 sendSelection();
1671    }
1672    }
1673   
 
1674  0 toggle public void hideAllSelectedSeqs()
1675    {
1676  0 if (selectionGroup == null || selectionGroup.getSize() < 1)
1677    {
1678  0 return;
1679    }
1680   
1681  0 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1682   
1683  0 hideSequence(seqs);
1684   
1685  0 setSelectionGroup(null);
1686    }
1687   
 
1688  54 toggle public void hideSequence(SequenceI[] seq)
1689    {
1690    /*
1691    * cache offset to first visible sequence
1692    */
1693  54 int startSeq = ranges.getStartSeq();
1694   
1695  54 if (seq != null)
1696    {
1697  252 for (int i = 0; i < seq.length; i++)
1698    {
1699  198 alignment.getHiddenSequences().hideSequence(seq[i]);
1700  198 setSequenceAnnotationsVisible(seq[i], false);
1701    }
1702  54 ranges.setStartSeq(startSeq);
1703  54 firePropertyChange("alignment", null, alignment.getSequences());
1704    }
1705    }
1706   
1707    /**
1708    * Hides the specified sequence, or the sequences it represents
1709    *
1710    * @param sequence
1711    * the sequence to hide, or keep as representative
1712    * @param representGroup
1713    * if true, hide the current selection group except for the
1714    * representative sequence
1715    */
 
1716  3 toggle public void hideSequences(SequenceI sequence, boolean representGroup)
1717    {
1718  3 if (selectionGroup == null || selectionGroup.getSize() < 1)
1719    {
1720  0 hideSequence(new SequenceI[] { sequence });
1721  0 return;
1722    }
1723   
1724  3 if (representGroup)
1725    {
1726  3 hideRepSequences(sequence, selectionGroup);
1727  3 setSelectionGroup(null);
1728  3 return;
1729    }
1730   
1731  0 int gsize = selectionGroup.getSize();
1732  0 SequenceI[] hseqs = selectionGroup.getSequences()
1733    .toArray(new SequenceI[gsize]);
1734   
1735  0 hideSequence(hseqs);
1736  0 setSelectionGroup(null);
1737  0 sendSelection();
1738    }
1739   
1740    /**
1741    * Set visibility for any annotations for the given sequence.
1742    *
1743    * @param sequenceI
1744    */
 
1745  203 toggle protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1746    boolean visible)
1747    {
1748  203 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1749  203 if (anns != null)
1750    {
1751  203 for (AlignmentAnnotation ann : anns)
1752    {
1753  1033 if (ann.sequenceRef == sequenceI)
1754    {
1755  0 ann.visible = visible;
1756    }
1757    }
1758    }
1759    }
1760   
 
1761  5 toggle public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1762    {
1763  5 int sSize = sg.getSize();
1764  5 if (sSize < 2)
1765    {
1766  0 return;
1767    }
1768   
1769  5 if (hiddenRepSequences == null)
1770    {
1771  5 hiddenRepSequences = new Hashtable<>();
1772    }
1773   
1774  5 hiddenRepSequences.put(repSequence, sg);
1775   
1776    // Hide all sequences except the repSequence
1777  5 SequenceI[] seqs = new SequenceI[sSize - 1];
1778  5 int index = 0;
1779  16 for (int i = 0; i < sSize; i++)
1780    {
1781  11 if (sg.getSequenceAt(i) != repSequence)
1782    {
1783  6 if (index == sSize - 1)
1784    {
1785  0 return;
1786    }
1787   
1788  6 seqs[index++] = sg.getSequenceAt(i);
1789    }
1790    }
1791  5 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1792  5 sg.setHidereps(true); // note: not done in 2.7applet
1793  5 hideSequence(seqs);
1794   
1795    }
1796   
1797    /**
1798    *
1799    * @return null or the current reference sequence
1800    */
 
1801  0 toggle public SequenceI getReferenceSeq()
1802    {
1803  0 return alignment.getSeqrep();
1804    }
1805   
1806    /**
1807    * @param seq
1808    * @return true iff seq is the reference for the alignment
1809    */
 
1810  3568 toggle public boolean isReferenceSeq(SequenceI seq)
1811    {
1812  3568 return alignment.getSeqrep() == seq;
1813    }
1814   
1815    /**
1816    *
1817    * @param seq
1818    * @return true if there are sequences represented by this sequence that are
1819    * currently hidden
1820    */
 
1821  3648 toggle public boolean isHiddenRepSequence(SequenceI seq)
1822    {
1823  3648 return (hiddenRepSequences != null
1824    && hiddenRepSequences.containsKey(seq));
1825    }
1826   
1827    /**
1828    *
1829    * @param seq
1830    * @return null or a sequence group containing the sequences that seq
1831    * represents
1832    */
 
1833  2 toggle public SequenceGroup getRepresentedSequences(SequenceI seq)
1834    {
1835  2 return (SequenceGroup) (hiddenRepSequences == null ? null
1836    : hiddenRepSequences.get(seq));
1837    }
1838   
 
1839  0 toggle @Override
1840    public int adjustForHiddenSeqs(int alignmentIndex)
1841    {
1842  0 return alignment.getHiddenSequences()
1843    .adjustForHiddenSeqs(alignmentIndex);
1844    }
1845   
 
1846  0 toggle @Override
1847    public void invertColumnSelection()
1848    {
1849  0 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1850  0 isColSelChanged(true);
1851    }
1852   
 
1853  4 toggle @Override
1854    public SequenceI[] getSelectionAsNewSequence()
1855    {
1856  4 SequenceI[] sequences;
1857    // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1858    // this was the only caller in the applet for this method
1859    // JBPNote: in applet, this method returned references to the alignment
1860    // sequences, and it did not honour the presence/absence of annotation
1861    // attached to the alignment (probably!)
1862  4 if (selectionGroup == null || selectionGroup.getSize() == 0)
1863    {
1864  2 sequences = alignment.getSequencesArray();
1865  2 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1866  4 for (int i = 0; i < sequences.length; i++)
1867    {
1868    // construct new sequence with subset of visible annotation
1869  2 sequences[i] = new Sequence(sequences[i], annots);
1870    }
1871    }
1872    else
1873    {
1874  2 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1875    }
1876   
1877  4 return sequences;
1878    }
1879   
 
1880  28 toggle @Override
1881    public SequenceI[] getSequenceSelection()
1882    {
1883  28 SequenceI[] sequences = null;
1884  28 if (selectionGroup != null)
1885    {
1886  4 sequences = selectionGroup.getSequencesInOrder(alignment);
1887    }
1888  28 if (sequences == null)
1889    {
1890  24 sequences = alignment.getSequencesArray();
1891    }
1892  28 return sequences;
1893    }
1894   
 
1895  25 toggle @Override
1896    public jalview.datamodel.AlignmentView getAlignmentView(
1897    boolean selectedOnly)
1898    {
1899  25 return getAlignmentView(selectedOnly, false);
1900    }
1901   
 
1902  26 toggle @Override
1903    public jalview.datamodel.AlignmentView getAlignmentView(
1904    boolean selectedOnly, boolean markGroups)
1905    {
1906  26 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1907    selectionGroup,
1908    alignment.getHiddenColumns() != null
1909    && alignment.getHiddenColumns().hasHiddenColumns(),
1910    selectedOnly, markGroups);
1911    }
1912   
 
1913  24 toggle @Override
1914    public String[] getViewAsString(boolean selectedRegionOnly)
1915    {
1916  24 return getViewAsString(selectedRegionOnly, true);
1917    }
1918   
 
1919  24 toggle @Override
1920    public String[] getViewAsString(boolean selectedRegionOnly,
1921    boolean exportHiddenSeqs)
1922    {
1923  24 String[] selection = null;
1924  24 SequenceI[] seqs = null;
1925  24 int i, iSize;
1926  24 int start = 0, end = 0;
1927  24 if (selectedRegionOnly && selectionGroup != null)
1928    {
1929  0 iSize = selectionGroup.getSize();
1930  0 seqs = selectionGroup.getSequencesInOrder(alignment);
1931  0 start = selectionGroup.getStartRes();
1932  0 end = selectionGroup.getEndRes() + 1;
1933    }
1934    else
1935    {
1936  24 if (hasHiddenRows() && exportHiddenSeqs)
1937    {
1938  0 AlignmentI fullAlignment = alignment.getHiddenSequences()
1939    .getFullAlignment();
1940  0 iSize = fullAlignment.getHeight();
1941  0 seqs = fullAlignment.getSequencesArray();
1942  0 end = fullAlignment.getWidth();
1943    }
1944    else
1945    {
1946  24 iSize = alignment.getHeight();
1947  24 seqs = alignment.getSequencesArray();
1948  24 end = alignment.getWidth();
1949    }
1950    }
1951   
1952  24 selection = new String[iSize];
1953  24 if (alignment.getHiddenColumns() != null
1954    && alignment.getHiddenColumns().hasHiddenColumns())
1955    {
1956  206 for (i = 0; i < iSize; i++)
1957    {
1958  188 Iterator<int[]> blocks = alignment.getHiddenColumns()
1959    .getVisContigsIterator(start, end + 1, false);
1960  188 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1961    }
1962    }
1963    else
1964    {
1965  36 for (i = 0; i < iSize; i++)
1966    {
1967  30 selection[i] = seqs[i].getSequenceAsString(start, end);
1968    }
1969   
1970    }
1971  24 return selection;
1972    }
1973   
 
1974  0 toggle @Override
1975    public List<int[]> getVisibleRegionBoundaries(int min, int max)
1976    {
1977  0 ArrayList<int[]> regions = new ArrayList<>();
1978  0 int start = min;
1979  0 int end = max;
1980   
1981  0 do
1982    {
1983  0 HiddenColumns hidden = alignment.getHiddenColumns();
1984  0 if (hidden != null && hidden.hasHiddenColumns())
1985    {
1986  0 if (start == 0)
1987    {
1988  0 start = hidden.visibleToAbsoluteColumn(start);
1989    }
1990   
1991  0 end = hidden.getNextHiddenBoundary(false, start);
1992  0 if (start == end)
1993    {
1994  0 end = max;
1995    }
1996  0 if (end > max)
1997    {
1998  0 end = max;
1999    }
2000    }
2001   
2002  0 regions.add(new int[] { start, end });
2003   
2004  0 if (hidden != null && hidden.hasHiddenColumns())
2005    {
2006  0 start = hidden.visibleToAbsoluteColumn(end);
2007  0 start = hidden.getNextHiddenBoundary(true, start) + 1;
2008    }
2009  0 } while (end < max);
2010   
2011    // int[][] startEnd = new int[regions.size()][2];
2012   
2013  0 return regions;
2014    }
2015   
 
2016  1 toggle @Override
2017    public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
2018    boolean selectedOnly)
2019    {
2020  1 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
2021  1 AlignmentAnnotation[] aa;
2022  ? if ((aa = alignment.getAlignmentAnnotation()) != null)
2023    {
2024  1 for (AlignmentAnnotation annot : aa)
2025    {
2026  4 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
2027  4 if (selectedOnly && selectionGroup != null)
2028    {
2029  4 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
2030    selectionGroup.getEndRes(), alignment.getHiddenColumns());
2031    }
2032    else
2033    {
2034  0 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
2035    }
2036  4 ala.add(clone);
2037    }
2038    }
2039  1 return ala;
2040    }
2041   
 
2042  2066 toggle @Override
2043    public boolean isPadGaps()
2044    {
2045  2066 return padGaps;
2046    }
2047   
 
2048  531 toggle @Override
2049    public void setPadGaps(boolean padGaps)
2050    {
2051  531 this.padGaps = padGaps;
2052    }
2053   
2054    /**
2055    * apply any post-edit constraints and trigger any calculations needed after
2056    * an edit has been performed on the alignment
2057    *
2058    * @param ap
2059    */
 
2060  883 toggle @Override
2061    public void alignmentChanged(AlignmentViewPanel ap)
2062    {
2063  883 if (isPadGaps())
2064    {
2065  501 alignment.padGaps();
2066    }
2067  883 if (autoCalculateConsensus)
2068    {
2069  883 updateConsensus(ap);
2070  883 updateSecondaryStructureConsensus(ap);
2071    }
2072  883 if (hconsensus != null && autoCalculateConsensus)
2073    {
2074  874 updateConservation(ap);
2075    }
2076  883 if (autoCalculateStrucConsensus)
2077    {
2078  883 updateStrucConsensus(ap);
2079    }
2080   
2081    // Reset endRes of groups if beyond alignment width
2082  883 int alWidth = alignment.getWidth();
2083  883 List<SequenceGroup> groups = alignment.getGroups();
2084  883 if (groups != null)
2085    {
2086  883 for (SequenceGroup sg : groups)
2087    {
2088  187 if (sg.getEndRes() > alWidth)
2089    {
2090  0 sg.setEndRes(alWidth - 1);
2091    }
2092    }
2093    }
2094   
2095  883 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2096    {
2097  0 selectionGroup.setEndRes(alWidth - 1);
2098    }
2099   
2100  883 updateAllColourSchemes();
2101  883 calculator.restartWorkers();
2102    // alignment.adjustSequenceAnnotations();
2103    }
2104   
2105    /**
2106    * reset scope and do calculations for all applied colourschemes on alignment
2107    */
 
2108  883 toggle void updateAllColourSchemes()
2109    {
2110  883 ResidueShaderI rs = residueShading;
2111  883 if (rs != null)
2112    {
2113  883 rs.alignmentChanged(alignment, hiddenRepSequences);
2114   
2115  883 rs.setConsensus(hconsensus);
2116  883 if (rs.conservationApplied())
2117    {
2118  3 rs.setConservation(Conservation.calculateConservation("All",
2119    alignment.getSequences(), 0, alignment.getWidth(), false,
2120    getConsPercGaps(), false));
2121    }
2122    }
2123   
2124  883 for (SequenceGroup sg : alignment.getGroups())
2125    {
2126  187 if (sg.cs != null)
2127    {
2128  187 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2129    }
2130  187 sg.recalcConservation();
2131    }
2132    }
2133   
 
2134  531 toggle protected void initAutoAnnotation()
2135    {
2136    // TODO: add menu option action that nulls or creates consensus object
2137    // depending on if the user wants to see the annotation or not in a
2138    // specific alignment
2139   
2140  531 if (hconsensus == null && !isDataset)
2141    {
2142  531 if (!alignment.isNucleotide())
2143    {
2144  420 initConservation();
2145  420 initQuality();
2146    }
2147    else
2148    {
2149  111 initRNAStructure();
2150    }
2151  531 consensus = new AlignmentAnnotation("Consensus",
2152    MessageManager.getString("label.consensus_descr"),
2153    new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2154  531 setSecondaryStructureSources(alignment.getAlignmentAnnotation());
2155   
2156  531 List<String> secondaryStructureSources = getSecondaryStructureSources();
2157   
2158  531 if (secondaryStructureSources != null)
2159    {
2160   
2161   
2162  531 AlignmentUtils.assignColorsForSecondaryStructureProviders(secondaryStructureSources);
2163   
2164  531 secondaryStructureConsensus = new ArrayList<AlignmentAnnotation>();
2165  531 for (String ssSource : secondaryStructureSources)
2166    {
2167   
2168  473 AlignmentAnnotation ssConsensus = new AlignmentAnnotation(
2169    MessageManager.getString("label.ssconsensus_label") + " "
2170    + ssSource,
2171    ssSource + " "
2172    + MessageManager
2173    .getString("label.ssconsensus_descr"),
2174    new Annotation[1], 0f, 100f,
2175    AlignmentAnnotation.BAR_GRAPH);
2176  473 ssConsensus.autoCalculated=true;
2177  473 ssConsensus.hasData=false;
2178  473 ssConsensus.hasText=true;
2179  473 secondaryStructureConsensus.add(ssConsensus);
2180    }
2181   
2182    }
2183   
2184  531 initConsensus(consensus);
2185  531 initSSConsensus(secondaryStructureConsensus);
2186  531 initGapCounts();
2187  531 initComplementConsensus();
2188    }
2189    }
2190   
2191    /**
2192    * If this is a protein alignment and there are mappings to cDNA, adds the
2193    * cDNA consensus annotation and returns true, else returns false.
2194    */
 
2195  541 toggle public boolean initComplementConsensus()
2196    {
2197  541 if (!alignment.isNucleotide())
2198    {
2199  429 final List<AlignedCodonFrame> codonMappings = alignment
2200    .getCodonFrames();
2201  429 if (codonMappings != null && !codonMappings.isEmpty())
2202    {
2203  4 boolean doConsensus = false;
2204  4 for (AlignedCodonFrame mapping : codonMappings)
2205    {
2206    // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2207  4 MapList[] mapLists = mapping.getdnaToProt();
2208    // mapLists can be empty if project load has not finished resolving
2209    // seqs
2210  4 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2211    {
2212  4 doConsensus = true;
2213  4 break;
2214    }
2215    }
2216  4 if (doConsensus)
2217    {
2218  4 Iterable<AlignmentAnnotation> annots = alignment
2219    .findAnnotations(null, null, "cDNA Consensus");
2220  4 if (annots != null && (complementConsensus == null))
2221    {
2222  4 for (AlignmentAnnotation ann : annots)
2223    {
2224  0 if (ann.autoCalculated)
2225    {
2226  0 complementConsensus = ann;
2227    }
2228    }
2229    }
2230  4 if (complementConsensus == null)
2231    {
2232  4 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2233    MessageManager
2234    .getString("label.complement_consensus_descr"),
2235    new Annotation[1], 0f, 100f,
2236    AlignmentAnnotation.BAR_GRAPH);
2237  4 initConsensus(complementConsensus);
2238    }
2239  4 return true;
2240    }
2241    }
2242    }
2243  537 return false;
2244    }
2245   
 
2246  535 toggle private void initConsensus(AlignmentAnnotation aa)
2247    {
2248  535 aa.hasText = true;
2249  535 aa.autoCalculated = true;
2250   
2251  535 if (showConsensus)
2252    {
2253  534 alignment.addAnnotation(aa);
2254    }
2255    }
2256   
 
2257  531 toggle private void initSSConsensus(
2258    List<AlignmentAnnotation> secondaryStructureConsensuses)
2259    {
2260  531 if (secondaryStructureConsensuses == null)
2261    {
2262  0 return;
2263    }
2264  531 for (AlignmentAnnotation aa : secondaryStructureConsensuses)
2265    {
2266  473 aa.hasText = true;
2267  473 aa.autoCalculated = true;
2268   
2269  473 if (showSSConsensus)
2270    {
2271  0 alignment.addAnnotation(aa);
2272    }
2273   
2274    }
2275    }
2276   
2277    // these should be extracted from the view model - style and settings for
2278    // derived annotation
 
2279  531 toggle private void initGapCounts()
2280    {
2281  531 if (showOccupancy)
2282    {
2283  527 gapcounts = new AlignmentAnnotation("Occupancy",
2284    MessageManager.getString("label.occupancy_descr"),
2285    new Annotation[1], 0f, alignment.getHeight(),
2286    AlignmentAnnotation.BAR_GRAPH);
2287  527 gapcounts.hasText = true;
2288  527 gapcounts.autoCalculated = true;
2289  527 gapcounts.scaleColLabel = true;
2290  527 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2291   
2292  527 alignment.addAnnotation(gapcounts);
2293    }
2294    }
2295   
 
2296  420 toggle private void initConservation()
2297    {
2298  420 if (showConservation)
2299    {
2300  419 if (conservation == null)
2301    {
2302  419 conservation = new AlignmentAnnotation("Conservation",
2303    MessageManager.formatMessage("label.conservation_descr",
2304    getConsPercGaps()),
2305    new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2306  419 conservation.hasText = true;
2307  419 conservation.autoCalculated = true;
2308  419 alignment.addAnnotation(conservation);
2309    }
2310    }
2311    }
2312   
 
2313  420 toggle private void initQuality()
2314    {
2315  420 if (showQuality)
2316    {
2317  420 if (quality == null)
2318    {
2319  420 quality = new AlignmentAnnotation("Quality",
2320    MessageManager.getString("label.quality_descr"),
2321    new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2322  420 quality.hasText = true;
2323  420 quality.autoCalculated = true;
2324  420 alignment.addAnnotation(quality);
2325    }
2326    }
2327    }
2328   
 
2329  111 toggle private void initRNAStructure()
2330    {
2331  111 if (alignment.hasRNAStructure() && strucConsensus == null)
2332    {
2333  2 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2334    MessageManager.getString("label.strucconsensus_descr"),
2335    new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2336  2 strucConsensus.hasText = true;
2337  2 strucConsensus.autoCalculated = true;
2338   
2339  2 if (showConsensus)
2340    {
2341  2 alignment.addAnnotation(strucConsensus);
2342    }
2343    }
2344    }
2345   
2346    /*
2347    * (non-Javadoc)
2348    *
2349    * @see jalview.api.AlignViewportI#calcPanelHeight()
2350    */
 
2351  5324 toggle @Override
2352    public int calcPanelHeight()
2353    {
2354    // setHeight of panels
2355  5324 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2356  5324 int height = 0;
2357  5324 int charHeight = getCharHeight();
2358  5324 if (anns != null)
2359    {
2360  5324 BitSet graphgrp = new BitSet();
2361  5324 for (AlignmentAnnotation aa : anns)
2362    {
2363  27794 if (aa == null)
2364    {
2365  0 jalview.bin.Console.errPrintln("Null annotation row: ignoring.");
2366  0 continue;
2367    }
2368  27794 if (!aa.isForDisplay())
2369    {
2370  4109 continue;
2371    }
2372  23685 if (aa.graphGroup > -1)
2373    {
2374  390 if (graphgrp.get(aa.graphGroup))
2375    {
2376  195 continue;
2377    }
2378    else
2379    {
2380  195 graphgrp.set(aa.graphGroup);
2381    }
2382    }
2383  23490 aa.height = 0;
2384   
2385  23490 if (aa.hasText)
2386    {
2387  20235 aa.height += charHeight;
2388    }
2389   
2390  23490 if (aa.hasIcons)
2391    {
2392  1781 aa.height += 16;
2393    }
2394   
2395  23490 if (aa.graph > 0)
2396    {
2397  21145 aa.height += aa.graphHeight + 20;
2398    }
2399   
2400  23490 if (aa.height == 0)
2401    {
2402  158 aa.height = 20;
2403    }
2404   
2405  23490 height += aa.height;
2406    }
2407    }
2408  5324 if (height == 0)
2409    {
2410    // set minimum
2411  23 height = 20;
2412    }
2413  5324 return height;
2414    }
2415   
 
2416  135 toggle @Override
2417    public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2418    boolean preserveNewGroupSettings)
2419    {
2420  135 boolean updateCalcs = false;
2421  135 boolean conv = isShowGroupConservation();
2422  135 boolean cons = isShowGroupConsensus();
2423  135 boolean sscons = isShowGroupSSConsensus();
2424  135 boolean showprf = isShowSequenceLogo();
2425  135 boolean showConsHist = isShowConsensusHistogram();
2426  135 boolean normLogo = isNormaliseSequenceLogo();
2427   
2428    /**
2429    * TODO reorder the annotation rows according to group/sequence ordering on
2430    * alignment
2431    */
2432    // boolean sortg = true;
2433   
2434    // remove old automatic annotation
2435    // add any new annotation
2436   
2437    // intersect alignment annotation with alignment groups
2438   
2439  135 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2440  135 List<SequenceGroup> oldrfs = new ArrayList<>();
2441  135 if (aan != null)
2442    {
2443  1375 for (int an = 0; an < aan.length; an++)
2444    {
2445  1240 if (aan[an].autoCalculated && aan[an].groupRef != null)
2446    {
2447  0 oldrfs.add(aan[an].groupRef);
2448  0 alignment.deleteAnnotation(aan[an], false);
2449    }
2450    }
2451    }
2452  135 if (alignment.getGroups() != null)
2453    {
2454  135 for (SequenceGroup sg : alignment.getGroups())
2455    {
2456  70 updateCalcs = false;
2457  70 if (applyGlobalSettings
2458    || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2459    {
2460    // set defaults for this group's conservation/consensus
2461  11 sg.setshowSequenceLogo(showprf);
2462  11 sg.setShowConsensusHistogram(showConsHist);
2463  11 sg.setNormaliseSequenceLogo(normLogo);
2464    }
2465  70 if (conv)
2466    {
2467  0 updateCalcs = true;
2468  0 alignment.addAnnotation(sg.getConservationRow(), 0);
2469    }
2470  70 if (cons)
2471    {
2472  24 updateCalcs = true;
2473  24 alignment.addAnnotation(sg.getConsensus(), 0);
2474    }
2475  70 if (sscons)
2476    {
2477  0 updateCalcs = true;
2478  0 List<String> secondaryStructureSources = getSecondaryStructureSources();
2479  0 if (secondaryStructureSources != null)
2480    {
2481  0 List<AlignmentAnnotation> ssAa = sg
2482    .getSSConsensus(secondaryStructureSources);
2483  0 if (ssAa != null)
2484    {
2485  0 for (AlignmentAnnotation aa : ssAa)
2486    {
2487    // Setting annotation visibility to true for the secondary
2488    // structure consensus for all providers
2489  0 if (aa.label.contains(Constants.SS_ALL_PROVIDERS))
2490    {
2491  0 aa.visible = true;
2492    }
2493  0 alignment.addAnnotation(aa, 0);
2494    }
2495    }
2496    }
2497    }
2498    // refresh the annotation rows
2499  70 if (updateCalcs)
2500    {
2501  24 sg.recalcConservation();
2502    }
2503    }
2504    }
2505  135 oldrfs.clear();
2506    }
2507   
 
2508  24690 toggle @Override
2509    public boolean isDisplayReferenceSeq()
2510    {
2511  24690 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2512    }
2513   
 
2514  10 toggle @Override
2515    public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2516    {
2517  10 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2518    }
2519   
 
2520  5 toggle @Override
2521    public boolean isColourByReferenceSeq()
2522    {
2523  5 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2524    }
2525   
 
2526  35397 toggle @Override
2527    public Color getSequenceColour(SequenceI seq)
2528    {
2529  35397 Color sqc = sequenceColours.get(seq);
2530  35397 return (sqc == null ? Color.white : sqc);
2531    }
2532   
 
2533  1303 toggle @Override
2534    public void setSequenceColour(SequenceI seq, Color col)
2535    {
2536  1303 if (col == null)
2537    {
2538  0 sequenceColours.remove(seq);
2539    }
2540    else
2541    {
2542  1303 sequenceColours.put(seq, col);
2543    }
2544    }
2545   
 
2546  9 toggle @Override
2547    public void updateSequenceIdColours()
2548    {
2549  9 for (SequenceGroup sg : alignment.getGroups())
2550    {
2551  5 if (sg.idColour != null)
2552    {
2553  0 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2554    {
2555  0 sequenceColours.put(s, sg.idColour);
2556    }
2557    }
2558    }
2559    }
2560   
 
2561  1 toggle @Override
2562    public void clearSequenceColours()
2563    {
2564  1 sequenceColours.clear();
2565    }
2566   
2567   
 
2568  0 toggle @Override
2569    public Color getAnnotationColour(AlignmentAnnotation annot)
2570    {
2571  0 Color annotColor = annotationColours.get(annot);
2572  0 return (annotColor == null ? Color.white : annotColor);
2573    }
2574   
 
2575  12 toggle @Override
2576    public void setAnnotationColour(AlignmentAnnotation annot, Color col)
2577    {
2578  12 if (col == null)
2579    {
2580  0 annotationColours.remove(annot);
2581  0 annot.setAnnotationGroupColour(Color.WHITE);
2582    }
2583    else
2584    {
2585  12 annotationColours.put(annot, col);
2586  12 annot.setAnnotationGroupColour(col);
2587    }
2588    }
2589   
 
2590  1261 toggle @Override
2591    public void updateAnnotationColours()
2592    {
2593  1261 for (SequenceGroup sg : alignment.getGroups())
2594    {
2595  930 if (sg.idColour != null)
2596    {
2597  925 for (AlignmentAnnotation annot : sg.getAlignmentAnnotation())
2598    {
2599  384 annotationColours.put(annot, sg.idColour);
2600  384 annot.setAnnotationGroupColour(sg.idColour);
2601    }
2602    }
2603    }
2604    }
2605   
 
2606  1 toggle @Override
2607    public void clearAnnotationColours()
2608    {
2609  1 for (AlignmentAnnotation annot : annotationColours.keySet())
2610    {
2611  4 annot.setAnnotationGroupColour(Color.WHITE);
2612    }
2613  1 annotationColours.clear();
2614    }
2615   
 
2616  0 toggle @Override
2617    public Map<AlignmentAnnotation, Color> getAnnotationColours()
2618    {
2619  0 return annotationColours;
2620    }
2621   
 
2622  0 toggle @Override
2623    public void setAnnotationColours(
2624    Map<AlignmentAnnotation, Color> annotationColours)
2625    {
2626  0 this.annotationColours = annotationColours;
2627    }
2628   
 
2629  1193 toggle @Override
2630    public AlignViewportI getCodingComplement()
2631    {
2632  1193 return this.codingComplement;
2633    }
2634   
2635    /**
2636    * Set this as the (cDna/protein) complement of the given viewport. Also
2637    * ensures the reverse relationship is set on the given viewport.
2638    */
 
2639  6 toggle @Override
2640    public void setCodingComplement(AlignViewportI av)
2641    {
2642  6 if (this == av)
2643    {
2644  0 jalview.bin.Console
2645    .errPrintln("Ignoring recursive setCodingComplement request");
2646    }
2647    else
2648    {
2649  6 this.codingComplement = av;
2650    // avoid infinite recursion!
2651  6 if (av.getCodingComplement() != this)
2652    {
2653  3 av.setCodingComplement(this);
2654    }
2655    }
2656    }
2657   
 
2658  25 toggle @Override
2659    public boolean isNucleotide()
2660    {
2661  25 return getAlignment() == null ? false : getAlignment().isNucleotide();
2662    }
2663   
 
2664  1755109 toggle @Override
2665    public FeaturesDisplayedI getFeaturesDisplayed()
2666    {
2667  1756071 return featuresDisplayed;
2668    }
2669   
 
2670  129 toggle @Override
2671    public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2672    {
2673  129 featuresDisplayed = featuresDisplayedI;
2674    }
2675   
 
2676  83 toggle @Override
2677    public boolean areFeaturesDisplayed()
2678    {
2679  83 return featuresDisplayed != null
2680    && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2681    }
2682   
2683    /**
2684    * set the flag
2685    *
2686    * @param b
2687    * features are displayed if true
2688    */
 
2689  149 toggle @Override
2690    public void setShowSequenceFeatures(boolean b)
2691    {
2692  149 viewStyle.setShowSequenceFeatures(b);
2693    }
2694   
 
2695  509366 toggle @Override
2696    public boolean isShowSequenceFeatures()
2697    {
2698  509454 return viewStyle.isShowSequenceFeatures();
2699    }
2700   
 
2701  0 toggle @Override
2702    public void setShowSequenceFeaturesHeight(boolean selected)
2703    {
2704  0 viewStyle.setShowSequenceFeaturesHeight(selected);
2705    }
2706   
 
2707  0 toggle @Override
2708    public boolean isShowSequenceFeaturesHeight()
2709    {
2710  0 return viewStyle.isShowSequenceFeaturesHeight();
2711    }
2712   
 
2713  711 toggle @Override
2714    public void setShowAnnotation(boolean b)
2715    {
2716  711 viewStyle.setShowAnnotation(b);
2717    }
2718   
 
2719  4494 toggle @Override
2720    public boolean isShowAnnotation()
2721    {
2722  4494 return viewStyle.isShowAnnotation();
2723    }
2724   
 
2725  16386 toggle @Override
2726    public boolean isRightAlignIds()
2727    {
2728  16386 return viewStyle.isRightAlignIds();
2729    }
2730   
 
2731  620 toggle @Override
2732    public void setRightAlignIds(boolean rightAlignIds)
2733    {
2734  620 viewStyle.setRightAlignIds(rightAlignIds);
2735    }
2736   
 
2737  1087 toggle @Override
2738    public boolean getConservationSelected()
2739    {
2740  1087 return viewStyle.getConservationSelected();
2741    }
2742   
 
2743  89 toggle @Override
2744    public void setShowBoxes(boolean state)
2745    {
2746  89 viewStyle.setShowBoxes(state);
2747    }
2748   
2749    /**
2750    * @return
2751    * @see jalview.api.ViewStyleI#getTextColour()
2752    */
 
2753  705934 toggle @Override
2754    public Color getTextColour()
2755    {
2756  705934 return viewStyle.getTextColour();
2757    }
2758   
2759    /**
2760    * @return
2761    * @see jalview.api.ViewStyleI#getTextColour2()
2762    */
 
2763  48 toggle @Override
2764    public Color getTextColour2()
2765    {
2766  48 return viewStyle.getTextColour2();
2767    }
2768   
2769    /**
2770    * @return
2771    * @see jalview.api.ViewStyleI#getThresholdTextColour()
2772    */
 
2773  480707 toggle @Override
2774    public int getThresholdTextColour()
2775    {
2776  480707 return viewStyle.getThresholdTextColour();
2777    }
2778   
2779    /**
2780    * @return
2781    * @see jalview.api.ViewStyleI#isConservationColourSelected()
2782    */
 
2783  0 toggle @Override
2784    public boolean isConservationColourSelected()
2785    {
2786  0 return viewStyle.isConservationColourSelected();
2787    }
2788   
2789    /**
2790    * @return
2791    * @see jalview.api.ViewStyleI#isRenderGaps()
2792    */
 
2793  3454 toggle @Override
2794    public boolean isRenderGaps()
2795    {
2796  3454 return viewStyle.isRenderGaps();
2797    }
2798   
2799    /**
2800    * @return
2801    * @see jalview.api.ViewStyleI#isShowColourText()
2802    */
 
2803  703 toggle @Override
2804    public boolean isShowColourText()
2805    {
2806  703 return viewStyle.isShowColourText();
2807    }
2808   
2809    /**
2810    * @param conservationColourSelected
2811    * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2812    */
 
2813  0 toggle @Override
2814    public void setConservationColourSelected(
2815    boolean conservationColourSelected)
2816    {
2817  0 viewStyle.setConservationColourSelected(conservationColourSelected);
2818    }
2819   
2820    /**
2821    * @param showColourText
2822    * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2823    */
 
2824  0 toggle @Override
2825    public void setShowColourText(boolean showColourText)
2826    {
2827  0 viewStyle.setShowColourText(showColourText);
2828    }
2829   
2830    /**
2831    * @param textColour
2832    * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2833    */
 
2834  89 toggle @Override
2835    public void setTextColour(Color textColour)
2836    {
2837  89 viewStyle.setTextColour(textColour);
2838    }
2839   
2840    /**
2841    * @param thresholdTextColour
2842    * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2843    */
 
2844  89 toggle @Override
2845    public void setThresholdTextColour(int thresholdTextColour)
2846    {
2847  89 viewStyle.setThresholdTextColour(thresholdTextColour);
2848    }
2849   
2850    /**
2851    * @param textColour2
2852    * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2853    */
 
2854  89 toggle @Override
2855    public void setTextColour2(Color textColour2)
2856    {
2857  89 viewStyle.setTextColour2(textColour2);
2858    }
2859   
 
2860  149 toggle @Override
2861    public ViewStyleI getViewStyle()
2862    {
2863  149 return new ViewStyle(viewStyle);
2864    }
2865   
 
2866  90 toggle @Override
2867    public void setViewStyle(ViewStyleI settingsForView)
2868    {
2869  90 viewStyle = new ViewStyle(settingsForView);
2870  90 if (residueShading != null)
2871    {
2872  90 residueShading.setConservationApplied(
2873    settingsForView.isConservationColourSelected());
2874    }
2875    }
2876   
 
2877  0 toggle @Override
2878    public boolean sameStyle(ViewStyleI them)
2879    {
2880  0 return viewStyle.sameStyle(them);
2881    }
2882   
2883    /**
2884    * @return
2885    * @see jalview.api.ViewStyleI#getIdWidth()
2886    */
 
2887  6706 toggle @Override
2888    public int getIdWidth()
2889    {
2890  6706 return viewStyle.getIdWidth();
2891    }
2892   
2893    /**
2894    * @param i
2895    * @see jalview.api.ViewStyleI#setIdWidth(int)
2896    */
 
2897  832 toggle @Override
2898    public void setIdWidth(int i)
2899    {
2900  832 viewStyle.setIdWidth(i);
2901    }
2902   
2903    /**
2904    * @return
2905    * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2906    */
 
2907  703 toggle @Override
2908    public boolean isCentreColumnLabels()
2909    {
2910  703 return viewStyle.isCentreColumnLabels();
2911    }
2912   
2913    /**
2914    * @param centreColumnLabels
2915    * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2916    */
 
2917  620 toggle @Override
2918    public void setCentreColumnLabels(boolean centreColumnLabels)
2919    {
2920  620 viewStyle.setCentreColumnLabels(centreColumnLabels);
2921    }
2922   
2923    /**
2924    * @param showdbrefs
2925    * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2926    */
 
2927  620 toggle @Override
2928    public void setShowDBRefs(boolean showdbrefs)
2929    {
2930  620 viewStyle.setShowDBRefs(showdbrefs);
2931    }
2932   
2933    /**
2934    * @return
2935    * @see jalview.api.ViewStyleI#isShowDBRefs()
2936    */
 
2937  751 toggle @Override
2938    public boolean isShowDBRefs()
2939    {
2940  751 return viewStyle.isShowDBRefs();
2941    }
2942   
2943    /**
2944    * @return
2945    * @see jalview.api.ViewStyleI#isShowNPFeats()
2946    */
 
2947  751 toggle @Override
2948    public boolean isShowNPFeats()
2949    {
2950  751 return viewStyle.isShowNPFeats();
2951    }
2952   
2953    /**
2954    * @param shownpfeats
2955    * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2956    */
 
2957  620 toggle @Override
2958    public void setShowNPFeats(boolean shownpfeats)
2959    {
2960  620 viewStyle.setShowNPFeats(shownpfeats);
2961    }
2962   
2963    public abstract StructureSelectionManager getStructureSelectionManager();
2964   
2965    /**
2966    * Add one command to the command history list.
2967    *
2968    * @param command
2969    */
 
2970  1 toggle public void addToHistoryList(CommandI command)
2971    {
2972  1 if (this.historyList != null)
2973    {
2974  1 this.historyList.push(command);
2975  1 broadcastCommand(command, false);
2976  1 setSavedUpToDate(false);
2977  1 Jalview2XML.setStateSavedUpToDate(false);
2978    }
2979    }
2980   
 
2981  1 toggle protected void broadcastCommand(CommandI command, boolean undo)
2982    {
2983  1 getStructureSelectionManager().commandPerformed(command, undo,
2984    getVamsasSource());
2985    }
2986   
2987    /**
2988    * Add one command to the command redo list.
2989    *
2990    * @param command
2991    */
 
2992  0 toggle public void addToRedoList(CommandI command)
2993    {
2994  0 if (this.redoList != null)
2995    {
2996  0 this.redoList.push(command);
2997    }
2998  0 broadcastCommand(command, true);
2999    }
3000   
3001    /**
3002    * Clear the command redo list.
3003    */
 
3004  1 toggle public void clearRedoList()
3005    {
3006  1 if (this.redoList != null)
3007    {
3008  1 this.redoList.clear();
3009    }
3010    }
3011   
 
3012  53 toggle public void setHistoryList(Deque<CommandI> list)
3013    {
3014  53 this.historyList = list;
3015    }
3016   
 
3017  1643 toggle public Deque<CommandI> getHistoryList()
3018    {
3019  1643 return this.historyList;
3020    }
3021   
 
3022  53 toggle public void setRedoList(Deque<CommandI> list)
3023    {
3024  53 this.redoList = list;
3025    }
3026   
 
3027  1640 toggle public Deque<CommandI> getRedoList()
3028    {
3029  1640 return this.redoList;
3030    }
3031   
 
3032  1 toggle @Override
3033    public VamsasSource getVamsasSource()
3034    {
3035  1 return this;
3036    }
3037   
 
3038  7530 toggle public SequenceAnnotationOrder getSortAnnotationsBy()
3039    {
3040  7530 return sortAnnotationsBy;
3041    }
3042   
 
3043  0 toggle public void setSortAnnotationsBy(
3044    SequenceAnnotationOrder sortAnnotationsBy)
3045    {
3046  0 this.sortAnnotationsBy = sortAnnotationsBy;
3047    }
3048   
 
3049  7531 toggle public boolean isShowAutocalculatedAbove()
3050    {
3051  7531 return showAutocalculatedAbove;
3052    }
3053   
 
3054  475 toggle public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
3055    {
3056  475 this.showAutocalculatedAbove = showAutocalculatedAbove;
3057    }
3058   
 
3059  3 toggle @Override
3060    public boolean isScaleProteinAsCdna()
3061    {
3062  3 return viewStyle.isScaleProteinAsCdna();
3063    }
3064   
 
3065  0 toggle @Override
3066    public void setScaleProteinAsCdna(boolean b)
3067    {
3068  0 viewStyle.setScaleProteinAsCdna(b);
3069    }
3070   
 
3071  0 toggle @Override
3072    public boolean isProteinFontAsCdna()
3073    {
3074  0 return viewStyle.isProteinFontAsCdna();
3075    }
3076   
 
3077  0 toggle @Override
3078    public void setProteinFontAsCdna(boolean b)
3079    {
3080  0 viewStyle.setProteinFontAsCdna(b);
3081    }
3082   
 
3083  89 toggle @Override
3084    public void setShowComplementFeatures(boolean b)
3085    {
3086  89 viewStyle.setShowComplementFeatures(b);
3087    }
3088   
 
3089  512643 toggle @Override
3090    public boolean isShowComplementFeatures()
3091    {
3092  512702 return viewStyle.isShowComplementFeatures();
3093    }
3094   
 
3095  89 toggle @Override
3096    public void setShowComplementFeaturesOnTop(boolean b)
3097    {
3098  89 viewStyle.setShowComplementFeaturesOnTop(b);
3099    }
3100   
 
3101  49 toggle @Override
3102    public boolean isShowComplementFeaturesOnTop()
3103    {
3104  49 return viewStyle.isShowComplementFeaturesOnTop();
3105    }
3106   
3107    /**
3108    * @return true if view should scroll to show the highlighted region of a
3109    * sequence
3110    * @return
3111    */
 
3112  53 toggle @Override
3113    public final boolean isFollowHighlight()
3114    {
3115  53 return followHighlight;
3116    }
3117   
 
3118  89 toggle @Override
3119    public final void setFollowHighlight(boolean b)
3120    {
3121  89 this.followHighlight = b;
3122    }
3123   
 
3124  41375 toggle @Override
3125    public ViewportRanges getRanges()
3126    {
3127  41375 return ranges;
3128    }
3129   
3130    /**
3131    * Helper method to populate the SearchResults with the location in the
3132    * complementary alignment to scroll to, in order to match this one.
3133    *
3134    * @param sr
3135    * the SearchResults to add to
3136    * @return the offset (below top of visible region) of the matched sequence
3137    */
 
3138  751 toggle protected int findComplementScrollTarget(SearchResultsI sr)
3139    {
3140  751 final AlignViewportI complement = getCodingComplement();
3141  751 if (complement == null || !complement.isFollowHighlight())
3142    {
3143  747 return 0;
3144    }
3145  4 boolean iAmProtein = !getAlignment().isNucleotide();
3146  4 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
3147    : complement.getAlignment();
3148  4 if (proteinAlignment == null)
3149    {
3150  0 return 0;
3151    }
3152  4 final List<AlignedCodonFrame> mappings = proteinAlignment
3153    .getCodonFrames();
3154   
3155    /*
3156    * Heuristic: find the first mapped sequence (if any) with a non-gapped
3157    * residue in the middle column of the visible region. Scroll the
3158    * complementary alignment to line up the corresponding residue.
3159    */
3160  4 int seqOffset = 0;
3161  4 SequenceI sequence = null;
3162   
3163    /*
3164    * locate 'middle' column (true middle if an odd number visible, left of
3165    * middle if an even number visible)
3166    */
3167  4 int middleColumn = ranges.getStartRes()
3168    + (ranges.getEndRes() - ranges.getStartRes()) / 2;
3169  4 final HiddenSequences hiddenSequences = getAlignment()
3170    .getHiddenSequences();
3171   
3172    /*
3173    * searching to the bottom of the alignment gives smoother scrolling across
3174    * all gapped visible regions
3175    */
3176  4 int lastSeq = alignment.getHeight() - 1;
3177  4 List<AlignedCodonFrame> seqMappings = null;
3178  4 for (int seqNo = ranges
3179  4 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
3180    {
3181  4 sequence = getAlignment().getSequenceAt(seqNo);
3182  4 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
3183    {
3184  0 continue;
3185    }
3186  4 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
3187    {
3188  0 continue;
3189    }
3190  4 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
3191    mappings,
3192    getCodingComplement().getAlignment().getSequences());
3193  4 if (!seqMappings.isEmpty())
3194    {
3195  4 break;
3196    }
3197    }
3198   
3199  4 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
3200    {
3201    /*
3202    * No ungapped mapped sequence in middle column - do nothing
3203    */
3204  0 return 0;
3205    }
3206  4 MappingUtils.addSearchResults(sr, sequence,
3207    sequence.findPosition(middleColumn), seqMappings);
3208  4 return seqOffset;
3209    }
3210   
3211    /**
3212    * synthesize a column selection if none exists so it covers the given
3213    * selection group. if wholewidth is false, no column selection is made if the
3214    * selection group covers the whole alignment width.
3215    *
3216    * @param sg
3217    * @param wholewidth
3218    */
 
3219  0 toggle public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3220    {
3221  0 int sgs, sge;
3222  0 if (sg != null && (sgs = sg.getStartRes()) >= 0
3223    && sg.getStartRes() <= (sge = sg.getEndRes())
3224    && !this.hasSelectedColumns())
3225    {
3226  0 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3227    {
3228    // do nothing
3229  0 return;
3230    }
3231  0 if (colSel == null)
3232    {
3233  0 colSel = new ColumnSelection();
3234    }
3235  0 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3236    {
3237  0 colSel.addElement(cspos);
3238    }
3239    }
3240    }
3241   
3242    /**
3243    * hold status of current selection group - defined on alignment or not.
3244    */
3245    private boolean selectionIsDefinedGroup = false;
3246   
 
3247  0 toggle @Override
3248    public boolean isSelectionDefinedGroup()
3249    {
3250  0 if (selectionGroup == null)
3251    {
3252  0 return false;
3253    }
3254  0 if (isSelectionGroupChanged(true))
3255    {
3256  0 selectionIsDefinedGroup = false;
3257  0 List<SequenceGroup> gps = alignment.getGroups();
3258  0 if (gps == null || gps.size() == 0)
3259    {
3260  0 selectionIsDefinedGroup = false;
3261    }
3262    else
3263    {
3264  0 selectionIsDefinedGroup = gps.contains(selectionGroup);
3265    }
3266    }
3267  0 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3268    }
3269   
3270    /**
3271    * null, or currently highlighted results on this view
3272    */
3273    private SearchResultsI searchResults = null;
3274   
3275    protected TreeModel currentTree = null;
3276   
 
3277  12622 toggle @Override
3278    public boolean hasSearchResults()
3279    {
3280  12622 return searchResults != null;
3281    }
3282   
 
3283  7 toggle @Override
3284    public void setSearchResults(SearchResultsI results)
3285    {
3286  7 searchResults = results;
3287    }
3288   
 
3289  45 toggle @Override
3290    public SearchResultsI getSearchResults()
3291    {
3292  45 return searchResults;
3293    }
3294   
 
3295  5095 toggle @Override
3296    public ContactListI getContactList(AlignmentAnnotation _aa, int column)
3297    {
3298  5095 return alignment.getContactListFor(_aa, column);
3299    }
3300   
 
3301  315 toggle @Override
3302    public ContactMatrixI getContactMatrix(
3303    AlignmentAnnotation alignmentAnnotation)
3304    {
3305  315 return alignment.getContactMatrixFor(alignmentAnnotation);
3306    }
3307   
3308    /**
3309    * get the consensus sequence as displayed under the PID consensus annotation
3310    * row.
3311    *
3312    * @return consensus sequence as a new sequence object
3313    */
 
3314  1 toggle public SequenceI getConsensusSeq()
3315    {
3316  1 if (consensus == null)
3317    {
3318  0 updateConsensus(null);
3319    }
3320  1 if (consensus == null)
3321    {
3322  0 return null;
3323    }
3324  1 StringBuffer seqs = new StringBuffer();
3325  4 for (int i = 0; i < consensus.annotations.length; i++)
3326    {
3327  3 Annotation annotation = consensus.annotations[i];
3328  3 if (annotation != null)
3329    {
3330  3 String description = annotation.description;
3331  3 if (description != null && description.startsWith("["))
3332    {
3333    // consensus is a tie - just pick the first one
3334  1 seqs.append(description.charAt(1));
3335    }
3336    else
3337    {
3338  2 seqs.append(annotation.displayCharacter);
3339    }
3340    }
3341    }
3342   
3343  1 SequenceI sq = new Sequence("Consensus", seqs.toString());
3344  1 sq.setDescription("Percentage Identity Consensus "
3345  1 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3346  1 return sq;
3347    }
3348   
3349    // to do jal-4386
 
3350  0 toggle public SequenceI getSSConsensusSeq()
3351    {
3352  0 if (secondaryStructureConsensus == null)
3353    {
3354  0 updateSecondaryStructureConsensus(null);
3355    }
3356  0 if (secondaryStructureConsensus == null)
3357    {
3358  0 return null;
3359    }
3360  0 StringBuffer seqs = new StringBuffer();
3361    // for (int i = 0; i < secondaryStructureConsensus.annotations.length; i++)
3362    // {
3363    // Annotation annotation = secondaryStructureConsensus.annotations[i];
3364    // if (annotation != null)
3365    // {
3366    // String description = annotation.description;
3367    // if (description != null && description.startsWith("["))
3368    // {
3369    // // consensus is a tie - just pick the first one
3370    // seqs.append(description.charAt(1));
3371    // }
3372    // else
3373    // {
3374    // seqs.append(annotation.displayCharacter);
3375    // }
3376    // }
3377    // }
3378   
3379  0 SequenceI sq = new Sequence("Sec Str Consensus", seqs.toString());
3380  0 sq.setDescription("Percentage Identity Sec Str Consensus "
3381  0 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3382  0 return sq;
3383    }
3384   
 
3385  24 toggle @Override
3386    public void setCurrentTree(TreeModel tree)
3387    {
3388  24 currentTree = tree;
3389    }
3390   
 
3391  54 toggle @Override
3392    public TreeModel getCurrentTree()
3393    {
3394  54 return currentTree;
3395    }
3396   
 
3397  121 toggle @Override
3398    public AlignmentExportData getAlignExportData(
3399    AlignExportSettingsI options)
3400    {
3401  121 AlignmentI alignmentToExport = null;
3402  121 String[] omitHidden = null;
3403  121 alignmentToExport = null;
3404   
3405  121 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3406    {
3407  0 omitHidden = getViewAsString(false,
3408    options.isExportHiddenSequences());
3409    }
3410   
3411  121 int[] alignmentStartEnd = new int[2];
3412  121 if (hasHiddenRows() && options.isExportHiddenSequences())
3413    {
3414  0 alignmentToExport = getAlignment().getHiddenSequences()
3415    .getFullAlignment();
3416    }
3417    else
3418    {
3419  121 alignmentToExport = getAlignment();
3420    }
3421  121 alignmentStartEnd = getAlignment().getHiddenColumns()
3422    .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3423  121 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3424    omitHidden, alignmentStartEnd);
3425  121 return ed;
3426    }
3427   
3428    /**
3429    * flag set to indicate if structure views might be out of sync with sequences
3430    * in the alignment
3431    */
3432   
3433    private boolean needToUpdateStructureViews = false;
3434   
 
3435  0 toggle @Override
3436    public boolean isUpdateStructures()
3437    {
3438  0 return needToUpdateStructureViews;
3439    }
3440   
 
3441  3 toggle @Override
3442    public void setUpdateStructures(boolean update)
3443    {
3444  3 needToUpdateStructureViews = update;
3445    }
3446   
 
3447  2155 toggle @Override
3448    public boolean needToUpdateStructureViews()
3449    {
3450  2155 boolean update = needToUpdateStructureViews;
3451  2155 needToUpdateStructureViews = false;
3452  2155 return update;
3453    }
3454   
 
3455  2 toggle @Override
3456    public void addSequenceGroup(SequenceGroup sequenceGroup)
3457    {
3458  2 alignment.addGroup(sequenceGroup);
3459   
3460  2 Color col = sequenceGroup.idColour;
3461  2 if (col != null)
3462    {
3463  2 col = col.brighter();
3464   
3465  2 for (SequenceI sq : sequenceGroup.getSequences())
3466    {
3467  15 setSequenceColour(sq, col);
3468    }
3469   
3470  2 List<AlignmentAnnotation> annotations = sequenceGroup.getAnnotationsFromTree();
3471  2 if (annotations != null) {
3472  2 for (AlignmentAnnotation annot : annotations) {
3473  4 setAnnotationColour(annot, col);
3474    }
3475    }
3476    }
3477   
3478  2 if (codingComplement != null)
3479    {
3480  0 SequenceGroup mappedGroup = MappingUtils
3481    .mapSequenceGroup(sequenceGroup, this, codingComplement);
3482  0 if (mappedGroup.getSequences().size() > 0)
3483    {
3484  0 codingComplement.getAlignment().addGroup(mappedGroup);
3485   
3486  0 if (col != null)
3487    {
3488  0 for (SequenceI seq : mappedGroup.getSequences())
3489    {
3490  0 codingComplement.setSequenceColour(seq, col);
3491    }
3492    }
3493    }
3494    // propagate the structure view update flag according to our own setting
3495  0 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3496    }
3497    }
3498   
 
3499  34 toggle @Override
3500    public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3501    {
3502  34 int start = 0;
3503  34 int end = 0;
3504  34 if (selectedRegionOnly && selectionGroup != null)
3505    {
3506  4 start = selectionGroup.getStartRes();
3507  4 end = selectionGroup.getEndRes() + 1;
3508    }
3509    else
3510    {
3511  30 end = alignment.getWidth();
3512    }
3513  34 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3514    false));
3515    }
3516   
 
3517  133 toggle public void setSavedUpToDate(boolean s)
3518    {
3519  133 setSavedUpToDate(s, QuitHandler.Message.UNSAVED_CHANGES);
3520    }
3521   
 
3522  471 toggle public void setSavedUpToDate(boolean s, QuitHandler.Message m)
3523    {
3524  471 Console.debug(
3525    "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
3526  471 savedUpToDate = s;
3527  471 QuitHandler.setMessage(m);
3528    }
3529   
 
3530  4 toggle public boolean savedUpToDate()
3531    {
3532  4 Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
3533    + savedUpToDate);
3534  4 return savedUpToDate;
3535    }
3536    }