2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.viewmodel;
23 import jalview.analysis.Conservation;
24 import jalview.api.AlignCalcManagerI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.api.FeaturesDisplayedI;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.AlignmentView;
31 import jalview.datamodel.Annotation;
32 import jalview.datamodel.ColumnSelection;
33 import jalview.datamodel.Sequence;
34 import jalview.datamodel.SequenceCollectionI;
35 import jalview.datamodel.SequenceGroup;
36 import jalview.datamodel.SequenceI;
37 import jalview.schemes.Blosum62ColourScheme;
38 import jalview.schemes.ColourSchemeI;
39 import jalview.schemes.PIDColourScheme;
40 import jalview.schemes.ResidueProperties;
41 import jalview.workers.AlignCalcManager;
42 import jalview.workers.ConsensusThread;
43 import jalview.workers.StrucConsensusThread;
45 import java.awt.Color;
46 import java.util.ArrayList;
47 import java.util.BitSet;
48 import java.util.Hashtable;
49 import java.util.List;
51 import java.util.Vector;
54 * base class holding visualization and analysis attributes and common logic for
55 * an active alignment view displayed in the GUI
60 public abstract class AlignmentViewport implements AlignViewportI
63 * alignment displayed in the viewport. Please use get/setter
65 protected AlignmentI alignment;
67 protected String sequenceSetID;
70 * probably unused indicator that view is of a dataset rather than an
73 protected boolean isDataset = false;
75 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
77 protected ColumnSelection colSel = new ColumnSelection();
79 public boolean autoCalculateConsensus = true;
81 protected boolean autoCalculateStrucConsensus = true;
83 protected boolean ignoreGapsInConsensusCalculation = false;
85 protected ColourSchemeI globalColourScheme = null;
88 * gui state - changes to colour scheme propagated to all groups
90 private boolean colourAppliesToAllGroups;
94 * indicating if subsequent colourscheme changes will be propagated
97 public void setColourAppliesToAllGroups(boolean b)
99 colourAppliesToAllGroups = b;
105 * @return flag indicating if colourchanges propagated to all groups
107 public boolean getColourAppliesToAllGroups()
109 return colourAppliesToAllGroups;
112 boolean abovePIDThreshold = false;
117 * @return true if percent identity threshold is applied to shading
119 public boolean getAbovePIDThreshold()
121 return abovePIDThreshold;
129 * indicate if percent identity threshold is applied to shading
131 public void setAbovePIDThreshold(boolean b)
133 abovePIDThreshold = b;
144 public void setThreshold(int thresh)
152 * @return DOCUMENT ME!
154 public int getThreshold()
164 * set the scalar for bleaching colourschemes according to degree of
167 public void setIncrement(int inc)
175 * @return get scalar for bleaching colourschemes by conservation
177 public int getIncrement()
182 boolean conservationColourSelected = false;
187 * @return true if conservation based shading is enabled
189 public boolean getConservationSelected()
191 return conservationColourSelected;
198 * enable conservation based shading
200 public void setConservationSelected(boolean b)
202 conservationColourSelected = b;
206 public void setGlobalColourScheme(ColourSchemeI cs)
208 // TODO: logic refactored from AlignFrame changeColour -
209 // autorecalc stuff should be changed to rely on the worker system
210 // check to see if we should implement a changeColour(cs) method rather than
211 // put th logic in here
212 // - means that caller decides if they want to just modify state and defer
213 // calculation till later or to do all calculations in thread.
215 globalColourScheme = cs;
216 boolean recalc = false;
219 cs.setConservationApplied(recalc = getConservationSelected());
220 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
221 || cs instanceof Blosum62ColourScheme)
224 cs.setThreshold(threshold, ignoreGapsInConsensusCalculation);
228 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
232 cs.setConsensus(hconsensus);
233 cs.setConservation(hconservation);
235 cs.alignmentChanged(alignment, hiddenRepSequences);
237 if (getColourAppliesToAllGroups())
239 for (SequenceGroup sg : getAlignment().getGroups())
246 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
247 sg.setConsPercGaps(ConsPercGaps);
248 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
249 || cs instanceof Blosum62ColourScheme)
251 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
256 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
259 if (getConservationSelected())
261 sg.cs.setConservationApplied(true);
266 sg.cs.setConservation(null);
267 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
271 sg.recalcConservation();
275 sg.cs.alignmentChanged(sg, hiddenRepSequences);
283 public ColourSchemeI getGlobalColourScheme()
285 return globalColourScheme;
288 protected AlignmentAnnotation consensus;
290 protected AlignmentAnnotation strucConsensus;
292 protected AlignmentAnnotation conservation;
294 protected AlignmentAnnotation quality;
296 protected AlignmentAnnotation[] groupConsensus;
298 protected AlignmentAnnotation[] groupConservation;
301 * results of alignment consensus analysis for visible portion of view
303 protected Hashtable[] hconsensus = null;
306 * results of secondary structure base pair consensus for visible portion of
309 protected Hashtable[] hStrucConsensus = null;
311 protected Conservation hconservation = null;
314 public void setConservation(Conservation cons)
316 hconservation = cons;
320 * percentage gaps allowed in a column before all amino acid properties should
321 * be considered unconserved
323 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
326 public int getConsPercGaps()
332 public void setSequenceConsensusHash(Hashtable[] hconsensus)
334 this.hconsensus = hconsensus;
339 public Hashtable[] getSequenceConsensusHash()
345 public Hashtable[] getRnaStructureConsensusHash()
347 return hStrucConsensus;
351 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
353 this.hStrucConsensus = hStrucConsensus;
358 public AlignmentAnnotation getAlignmentQualityAnnot()
364 public AlignmentAnnotation getAlignmentConservationAnnotation()
370 public AlignmentAnnotation getAlignmentConsensusAnnotation()
376 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
378 return strucConsensus;
381 protected AlignCalcManagerI calculator = new AlignCalcManager();
384 * trigger update of conservation annotation
386 public void updateConservation(final AlignmentViewPanel ap)
388 // see note in mantis : issue number 8585
389 if (alignment.isNucleotide() || conservation == null
390 || !autoCalculateConsensus)
395 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
397 calculator.registerWorker(new jalview.workers.ConservationThread(
403 * trigger update of consensus annotation
405 public void updateConsensus(final AlignmentViewPanel ap)
407 // see note in mantis : issue number 8585
408 if (consensus == null || !autoCalculateConsensus)
412 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
414 calculator.registerWorker(new ConsensusThread(this, ap));
418 // --------START Structure Conservation
419 public void updateStrucConsensus(final AlignmentViewPanel ap)
421 if (autoCalculateStrucConsensus && strucConsensus == null
422 && alignment.isNucleotide() && alignment.hasRNAStructure())
424 // secondary structure has been added - so init the consensus line
428 // see note in mantis : issue number 8585
429 if (strucConsensus == null || !autoCalculateStrucConsensus)
433 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
435 calculator.registerWorker(new StrucConsensusThread(this, ap));
439 public boolean isCalcInProgress()
441 return calculator.isWorking();
445 public boolean isCalculationInProgress(
446 AlignmentAnnotation alignmentAnnotation)
448 if (!alignmentAnnotation.autoCalculated)
452 if (calculator.workingInvolvedWith(alignmentAnnotation))
454 // System.err.println("grey out ("+alignmentAnnotation.label+")");
461 public boolean isClosed()
463 // TODO: check that this isClosed is only true after panel is closed, not
464 // before it is fully constructed.
465 return alignment == null;
469 public AlignCalcManagerI getCalcManager()
475 * should conservation rows be shown for groups
477 protected boolean showGroupConservation = false;
480 * should consensus rows be shown for groups
482 protected boolean showGroupConsensus = false;
485 * should consensus profile be rendered by default
487 protected boolean showSequenceLogo = false;
490 * should consensus profile be rendered normalised to row height
492 protected boolean normaliseSequenceLogo = false;
495 * should consensus histograms be rendered by default
497 protected boolean showConsensusHistogram = true;
500 * @return the showConsensusProfile
503 public boolean isShowSequenceLogo()
505 return showSequenceLogo;
509 * @param showSequenceLogo
512 public void setShowSequenceLogo(boolean showSequenceLogo)
514 if (showSequenceLogo != this.showSequenceLogo)
516 // TODO: decouple settings setting from calculation when refactoring
517 // annotation update method from alignframe to viewport
518 this.showSequenceLogo = showSequenceLogo;
519 calculator.updateAnnotationFor(ConsensusThread.class);
520 calculator.updateAnnotationFor(StrucConsensusThread.class);
522 this.showSequenceLogo = showSequenceLogo;
526 * @param showConsensusHistogram
527 * the showConsensusHistogram to set
529 public void setShowConsensusHistogram(boolean showConsensusHistogram)
531 this.showConsensusHistogram = showConsensusHistogram;
535 * @return the showGroupConservation
537 public boolean isShowGroupConservation()
539 return showGroupConservation;
543 * @param showGroupConservation
544 * the showGroupConservation to set
546 public void setShowGroupConservation(boolean showGroupConservation)
548 this.showGroupConservation = showGroupConservation;
552 * @return the showGroupConsensus
554 public boolean isShowGroupConsensus()
556 return showGroupConsensus;
560 * @param showGroupConsensus
561 * the showGroupConsensus to set
563 public void setShowGroupConsensus(boolean showGroupConsensus)
565 this.showGroupConsensus = showGroupConsensus;
570 * @return flag to indicate if the consensus histogram should be rendered by
574 public boolean isShowConsensusHistogram()
576 return this.showConsensusHistogram;
580 * show non-conserved residues only
582 protected boolean showUnconserved = false;
585 * when set, updateAlignment will always ensure sequences are of equal length
587 private boolean padGaps = false;
590 * when set, alignment should be reordered according to a newly opened tree
592 public boolean sortByTree = false;
594 public boolean getShowUnconserved()
596 return showUnconserved;
599 public void setShowUnconserved(boolean showunconserved)
601 showUnconserved = showunconserved;
605 * @param showNonconserved
606 * the showUnconserved to set
608 public void setShowunconserved(boolean displayNonconserved)
610 this.showUnconserved = displayNonconserved;
616 * @return null or the currently selected sequence region
619 public SequenceGroup getSelectionGroup()
621 return selectionGroup;
625 * Set the selection group for this window.
628 * - group holding references to sequences in this alignment view
632 public void setSelectionGroup(SequenceGroup sg)
637 public void setHiddenColumns(ColumnSelection colsel)
639 this.colSel = colsel;
643 public ColumnSelection getColumnSelection()
649 public void setColumnSelection(ColumnSelection colSel)
651 this.colSel = colSel;
654 updateHiddenColumns();
663 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
665 return hiddenRepSequences;
669 public void setHiddenRepSequences(
670 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
672 this.hiddenRepSequences = hiddenRepSequences;
676 public boolean hasHiddenColumns()
678 return colSel != null && colSel.hasHiddenColumns();
681 public void updateHiddenColumns()
683 // this method doesn't really do anything now. But - it could, since a
684 // column Selection could be in the process of modification
685 // hasHiddenColumns = colSel.hasHiddenColumns();
688 protected boolean hasHiddenRows = false;
690 public boolean hasHiddenRows()
692 return hasHiddenRows;
695 protected SequenceGroup selectionGroup;
697 public void setSequenceSetId(String newid)
699 if (sequenceSetID != null)
702 .println("Warning - overwriting a sequenceSetId for a viewport!");
704 sequenceSetID = new String(newid);
708 public String getSequenceSetId()
710 if (sequenceSetID == null)
712 sequenceSetID = alignment.hashCode() + "";
715 return sequenceSetID;
719 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
722 protected String viewId = null;
724 public String getViewId()
728 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
733 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
735 ignoreGapsInConsensusCalculation = b;
739 if (globalColourScheme != null)
741 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
742 ignoreGapsInConsensusCalculation);
748 private long sgrouphash = -1, colselhash = -1;
751 * checks current SelectionGroup against record of last hash value, and
755 * update the record of last hash value
757 * @return true if SelectionGroup changed since last call (when b is true)
759 public boolean isSelectionGroupChanged(boolean b)
761 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
762 : selectionGroup.hashCode();
763 if (hc != -1 && hc != sgrouphash)
775 * checks current colsel against record of last hash value, and optionally
779 * update the record of last hash value
780 * @return true if colsel changed since last call (when b is true)
782 public boolean isColSelChanged(boolean b)
784 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
786 if (hc != -1 && hc != colselhash)
798 public boolean getIgnoreGapsConsensus()
800 return ignoreGapsInConsensusCalculation;
803 // / property change stuff
805 // JBPNote Prolly only need this in the applet version.
806 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
809 protected boolean showConservation = true;
811 protected boolean showQuality = true;
813 protected boolean showConsensus = true;
815 Hashtable sequenceColours;
818 * Property change listener for changes in alignment
823 public void addPropertyChangeListener(
824 java.beans.PropertyChangeListener listener)
826 changeSupport.addPropertyChangeListener(listener);
835 public void removePropertyChangeListener(
836 java.beans.PropertyChangeListener listener)
838 changeSupport.removePropertyChangeListener(listener);
842 * Property change listener for changes in alignment
851 public void firePropertyChange(String prop, Object oldvalue,
854 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
857 // common hide/show column stuff
859 public void hideSelectedColumns()
861 if (colSel.size() < 1)
866 colSel.hideSelectedColumns();
867 setSelectionGroup(null);
871 public void hideColumns(int start, int end)
875 colSel.hideColumns(start);
879 colSel.hideColumns(start, end);
883 public void showColumn(int col)
885 colSel.revealHiddenColumns(col);
889 public void showAllHiddenColumns()
891 colSel.revealAllHiddenColumns();
894 // common hide/show seq stuff
895 public void showAllHiddenSeqs()
897 if (alignment.getHiddenSequences().getSize() > 0)
899 if (selectionGroup == null)
901 selectionGroup = new SequenceGroup();
902 selectionGroup.setEndRes(alignment.getWidth() - 1);
904 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
906 for (SequenceI seq : tmp)
908 selectionGroup.addSequence(seq, false);
909 setSequenceAnnotationsVisible(seq, true);
912 hasHiddenRows = false;
913 hiddenRepSequences = null;
915 firePropertyChange("alignment", null, alignment.getSequences());
916 // used to set hasHiddenRows/hiddenRepSequences here, after the property
922 public void showSequence(int index)
924 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
929 if (selectionGroup == null)
931 selectionGroup = new SequenceGroup();
932 selectionGroup.setEndRes(alignment.getWidth() - 1);
935 for (SequenceI seq : tmp)
937 selectionGroup.addSequence(seq, false);
938 setSequenceAnnotationsVisible(seq, true);
940 // JBPNote: refactor: only update flag if we modified visiblity (used to
941 // do this regardless)
942 if (alignment.getHiddenSequences().getSize() < 1)
944 hasHiddenRows = false;
946 firePropertyChange("alignment", null, alignment.getSequences());
951 public void hideAllSelectedSeqs()
953 if (selectionGroup == null || selectionGroup.getSize() < 1)
958 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
962 setSelectionGroup(null);
965 public void hideSequence(SequenceI[] seq)
969 for (int i = 0; i < seq.length; i++)
971 alignment.getHiddenSequences().hideSequence(seq[i]);
972 setSequenceAnnotationsVisible(seq[i], false);
974 hasHiddenRows = true;
975 firePropertyChange("alignment", null, alignment.getSequences());
980 * Set visibility for any annotations for the given sequence.
984 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
987 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
989 if (ann.sequenceRef == sequenceI)
991 ann.visible = visible;
996 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
998 int sSize = sg.getSize();
1004 if (hiddenRepSequences == null)
1006 hiddenRepSequences = new Hashtable();
1009 hiddenRepSequences.put(repSequence, sg);
1011 // Hide all sequences except the repSequence
1012 SequenceI[] seqs = new SequenceI[sSize - 1];
1014 for (int i = 0; i < sSize; i++)
1016 if (sg.getSequenceAt(i) != repSequence)
1018 if (index == sSize - 1)
1023 seqs[index++] = sg.getSequenceAt(i);
1026 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1027 sg.setHidereps(true); // note: not done in 2.7applet
1032 public boolean isHiddenRepSequence(SequenceI seq)
1034 return alignment.getSeqrep()==seq || (hiddenRepSequences != null
1035 && hiddenRepSequences.containsKey(seq));
1038 public SequenceGroup getRepresentedSequences(SequenceI seq)
1040 return (SequenceGroup) (hiddenRepSequences == null ? null
1041 : hiddenRepSequences.get(seq));
1045 public int adjustForHiddenSeqs(int alignmentIndex)
1047 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1052 public abstract void sendSelection();
1055 public void invertColumnSelection()
1057 colSel.invertColumnSelection(0, alignment.getWidth());
1062 public SequenceI[] getSelectionAsNewSequence()
1064 SequenceI[] sequences;
1065 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1066 // this was the only caller in the applet for this method
1067 // JBPNote: in applet, this method returned references to the alignment
1068 // sequences, and it did not honour the presence/absence of annotation
1069 // attached to the alignment (probably!)
1070 if (selectionGroup == null || selectionGroup.getSize() == 0)
1072 sequences = alignment.getSequencesArray();
1073 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1074 for (int i = 0; i < sequences.length; i++)
1076 sequences[i] = new Sequence(sequences[i], annots); // construct new
1078 // subset of visible
1084 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1092 public SequenceI[] getSequenceSelection()
1094 SequenceI[] sequences = null;
1095 if (selectionGroup != null)
1097 sequences = selectionGroup.getSequencesInOrder(alignment);
1099 if (sequences == null)
1101 sequences = alignment.getSequencesArray();
1108 public jalview.datamodel.CigarArray getViewAsCigars(
1109 boolean selectedRegionOnly)
1111 return new jalview.datamodel.CigarArray(alignment, colSel,
1112 (selectedRegionOnly ? selectionGroup : null));
1117 public jalview.datamodel.AlignmentView getAlignmentView(
1118 boolean selectedOnly)
1120 return getAlignmentView(selectedOnly, false);
1125 public jalview.datamodel.AlignmentView getAlignmentView(
1126 boolean selectedOnly, boolean markGroups)
1128 return new AlignmentView(alignment, colSel, selectionGroup,
1129 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1135 public String[] getViewAsString(boolean selectedRegionOnly)
1137 String[] selection = null;
1138 SequenceI[] seqs = null;
1140 int start = 0, end = 0;
1141 if (selectedRegionOnly && selectionGroup != null)
1143 iSize = selectionGroup.getSize();
1144 seqs = selectionGroup.getSequencesInOrder(alignment);
1145 start = selectionGroup.getStartRes();
1146 end = selectionGroup.getEndRes() + 1;
1150 iSize = alignment.getHeight();
1151 seqs = alignment.getSequencesArray();
1152 end = alignment.getWidth();
1155 selection = new String[iSize];
1156 if (colSel != null && colSel.hasHiddenColumns())
1158 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1162 for (i = 0; i < iSize; i++)
1164 selection[i] = seqs[i].getSequenceAsString(start, end);
1173 public int[][] getVisibleRegionBoundaries(int min, int max)
1175 Vector regions = new Vector();
1181 if (colSel != null && colSel.hasHiddenColumns())
1185 start = colSel.adjustForHiddenColumns(start);
1188 end = colSel.getHiddenBoundaryRight(start);
1199 regions.addElement(new int[]
1202 if (colSel != null && colSel.hasHiddenColumns())
1204 start = colSel.adjustForHiddenColumns(end);
1205 start = colSel.getHiddenBoundaryLeft(start) + 1;
1207 } while (end < max);
1209 int[][] startEnd = new int[regions.size()][2];
1211 regions.copyInto(startEnd);
1218 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1220 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1221 AlignmentAnnotation[] aa;
1222 if ((aa=alignment.getAlignmentAnnotation())!=null)
1224 for (AlignmentAnnotation annot:aa)
1226 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1227 if (selectedOnly && selectionGroup!=null)
1229 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1231 colSel.makeVisibleAnnotation(clone);
1241 public boolean isPadGaps()
1248 public void setPadGaps(boolean padGaps)
1250 this.padGaps = padGaps;
1254 * apply any post-edit constraints and trigger any calculations needed after
1255 * an edit has been performed on the alignment
1260 public void alignmentChanged(AlignmentViewPanel ap)
1264 alignment.padGaps();
1266 if (autoCalculateConsensus)
1268 updateConsensus(ap);
1270 if (hconsensus != null && autoCalculateConsensus)
1272 updateConservation(ap);
1274 if (autoCalculateStrucConsensus)
1276 updateStrucConsensus(ap);
1279 // Reset endRes of groups if beyond alignment width
1280 int alWidth = alignment.getWidth();
1281 List<SequenceGroup> groups = alignment.getGroups();
1284 for (SequenceGroup sg : groups)
1286 if (sg.getEndRes() > alWidth)
1288 sg.setEndRes(alWidth - 1);
1293 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1295 selectionGroup.setEndRes(alWidth - 1);
1298 resetAllColourSchemes();
1299 calculator.restartWorkers();
1300 // alignment.adjustSequenceAnnotations();
1304 * reset scope and do calculations for all applied colourschemes on alignment
1306 void resetAllColourSchemes()
1308 ColourSchemeI cs = globalColourScheme;
1311 cs.alignmentChanged(alignment, hiddenRepSequences);
1313 cs.setConsensus(hconsensus);
1314 if (cs.conservationApplied())
1316 cs.setConservation(Conservation.calculateConservation("All",
1317 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1318 alignment.getWidth(), false, getConsPercGaps(), false));
1322 for (SequenceGroup sg : alignment.getGroups())
1326 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1328 sg.recalcConservation();
1332 protected void initAutoAnnotation()
1334 // TODO: add menu option action that nulls or creates consensus object
1335 // depending on if the user wants to see the annotation or not in a
1336 // specific alignment
1338 if (hconsensus == null && !isDataset)
1340 if (!alignment.isNucleotide())
1353 private void initConsensus()
1356 consensus = new AlignmentAnnotation("Consensus", "PID",
1357 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1358 consensus.hasText = true;
1359 consensus.autoCalculated = true;
1363 alignment.addAnnotation(consensus);
1367 private void initConservation()
1369 if (showConservation)
1371 if (conservation == null)
1373 conservation = new AlignmentAnnotation("Conservation",
1374 "Conservation of total alignment less than "
1375 + getConsPercGaps() + "% gaps", new Annotation[1],
1376 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1377 conservation.hasText = true;
1378 conservation.autoCalculated = true;
1379 alignment.addAnnotation(conservation);
1384 private void initQuality()
1388 if (quality == null)
1390 quality = new AlignmentAnnotation("Quality",
1391 "Alignment Quality based on Blosum62 scores",
1392 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1393 quality.hasText = true;
1394 quality.autoCalculated = true;
1395 alignment.addAnnotation(quality);
1400 private void initRNAStructure()
1402 if (alignment.hasRNAStructure() && strucConsensus == null)
1404 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1405 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1406 strucConsensus.hasText = true;
1407 strucConsensus.autoCalculated = true;
1411 alignment.addAnnotation(strucConsensus);
1419 * @see jalview.api.AlignViewportI#calcPanelHeight()
1422 public int calcPanelHeight()
1424 // setHeight of panels
1425 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1427 int charHeight = getCharHeight();
1430 BitSet graphgrp = new BitSet();
1431 for (int i = 0; i < aa.length; i++)
1435 System.err.println("Null annotation row: ignoring.");
1442 if (aa[i].graphGroup > -1)
1444 if (graphgrp.get(aa[i].graphGroup))
1450 graphgrp.set(aa[i].graphGroup);
1457 aa[i].height += charHeight;
1465 if (aa[i].graph > 0)
1467 aa[i].height += aa[i].graphHeight;
1470 if (aa[i].height == 0)
1475 height += aa[i].height;
1487 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1488 boolean preserveNewGroupSettings)
1490 boolean updateCalcs = false;
1491 boolean conv = isShowGroupConservation();
1492 boolean cons = isShowGroupConsensus();
1493 boolean showprf = isShowSequenceLogo();
1494 boolean showConsHist = isShowConsensusHistogram();
1495 boolean normLogo = isNormaliseSequenceLogo();
1498 * TODO reorder the annotation rows according to group/sequence ordering on
1501 boolean sortg = true;
1503 // remove old automatic annotation
1504 // add any new annotation
1506 // intersect alignment annotation with alignment groups
1508 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1509 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1512 for (int an = 0; an < aan.length; an++)
1514 if (aan[an].autoCalculated && aan[an].groupRef != null)
1516 oldrfs.add(aan[an].groupRef);
1517 alignment.deleteAnnotation(aan[an], false);
1521 if (alignment.getGroups() != null)
1523 for (SequenceGroup sg : alignment.getGroups())
1525 updateCalcs = false;
1526 if (applyGlobalSettings
1527 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1529 // set defaults for this group's conservation/consensus
1530 sg.setshowSequenceLogo(showprf);
1531 sg.setShowConsensusHistogram(showConsHist);
1532 sg.setNormaliseSequenceLogo(normLogo);
1537 alignment.addAnnotation(sg.getConservationRow(), 0);
1542 alignment.addAnnotation(sg.getConsensus(), 0);
1544 // refresh the annotation rows
1547 sg.recalcConservation();
1554 * show the reference sequence in the alignment view
1556 private boolean displayReferenceSeq=false;
1558 * colour according to the reference sequence defined on the alignment
1560 private boolean colourByReferenceSeq=false;
1563 public boolean isDisplayReferenceSeq()
1565 return alignment.hasSeqrep() && displayReferenceSeq;
1569 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1571 this.displayReferenceSeq = displayReferenceSeq;
1574 public boolean isColourByReferenceSeq()
1576 return alignment.hasSeqrep() && colourByReferenceSeq;
1579 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
1581 this.colourByReferenceSeq = colourByReferenceSeq;
1585 public Color getSequenceColour(SequenceI seq)
1587 Color sqc = Color.white;
1588 if (sequenceColours != null)
1590 sqc = (Color) sequenceColours.get(seq);
1600 public void setSequenceColour(SequenceI seq, Color col)
1602 if (sequenceColours == null)
1604 sequenceColours = new Hashtable();
1609 sequenceColours.remove(seq);
1613 sequenceColours.put(seq, col);
1618 public void updateSequenceIdColours()
1620 if (sequenceColours == null)
1622 sequenceColours = new Hashtable();
1624 for (SequenceGroup sg : alignment.getGroups())
1626 if (sg.idColour != null)
1628 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1630 sequenceColours.put(s, sg.idColour);
1637 public void clearSequenceColours()
1639 sequenceColours = null;
1642 FeaturesDisplayedI featuresDisplayed = null;
1645 public FeaturesDisplayedI getFeaturesDisplayed()
1647 return featuresDisplayed;
1651 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1653 featuresDisplayed = featuresDisplayedI;
1657 public boolean areFeaturesDisplayed()
1659 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
1663 * display setting for showing/hiding sequence features on alignment view
1665 boolean showSequenceFeatures = false;
1671 * features are displayed if true
1674 public void setShowSequenceFeatures(boolean b)
1676 showSequenceFeatures = b;
1679 public boolean isShowSequenceFeatures()
1681 return showSequenceFeatures;
1684 boolean showSeqFeaturesHeight;
1687 public void setShowSequenceFeaturesHeight(boolean selected)
1689 showSeqFeaturesHeight = selected;
1693 public boolean isShowSequenceFeaturesHeight()
1695 return showSeqFeaturesHeight;
1698 private boolean showAnnotation = true;
1700 private boolean rightAlignIds = false;
1704 public void setShowAnnotation(boolean b)
1710 public boolean isShowAnnotation()
1712 return showAnnotation;
1716 public boolean isRightAlignIds()
1718 return rightAlignIds;
1722 public void setRightAlignIds(boolean rightAlignIds)
1724 this.rightAlignIds = rightAlignIds;