2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
24 import jalview.analysis.*;
26 import jalview.datamodel.*;
27 import jalview.schemes.*;
28 import jalview.structure.SelectionSource;
29 import jalview.structure.StructureSelectionManager;
30 import jalview.structure.VamsasSource;
32 public class AlignViewport implements SelectionSource, VamsasSource
42 boolean cursorMode = false;
44 boolean showJVSuffix = true;
46 boolean showText = true;
48 boolean showColourText = false;
50 boolean showBoxes = true;
52 boolean wrapAlignment = false;
54 boolean renderGaps = true;
56 boolean showSequenceFeatures = false;
58 boolean showAnnotation = true;
60 boolean showConservation = true;
62 boolean showQuality = true;
64 boolean showConsensus = true;
66 boolean upperCasebold = false;
68 boolean colourAppliesToAllGroups = true;
70 ColourSchemeI globalColourScheme = null;
72 boolean conservationColourSelected = false;
74 boolean abovePIDThreshold = false;
76 SequenceGroup selectionGroup;
84 Font font = new Font("SansSerif", Font.PLAIN, 10);
86 boolean validCharWidth = true;
90 ColumnSelection colSel = new ColumnSelection();
96 NJTree currentTree = null;
98 boolean scaleAboveWrapped = true;
100 boolean scaleLeftWrapped = true;
102 boolean scaleRightWrapped = true;
104 // The following vector holds the features which are
105 // currently visible, in the correct order or rendering
106 public Hashtable featuresDisplayed;
108 boolean hasHiddenColumns = false;
110 boolean hasHiddenRows = false;
112 boolean showHiddenMarkers = true;
114 public Hashtable[] hconsensus;
116 AlignmentAnnotation consensus;
118 AlignmentAnnotation conservation;
120 AlignmentAnnotation quality;
122 AlignmentAnnotation[] groupConsensus;
124 AlignmentAnnotation[] groupConservation;
126 boolean autocalculateConsensus = true;
128 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
130 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
133 boolean ignoreGapsInConsensusCalculation = false;
135 public jalview.bin.JalviewLite applet;
137 Hashtable sequenceColours;
141 Stack historyList = new Stack();
143 Stack redoList = new Stack();
145 String sequenceSetID;
147 Hashtable hiddenRepSequences;
149 public void finalize() {
156 public AlignViewport(AlignmentI al, JalviewLite applet)
158 this.applet = applet;
161 this.endRes = al.getWidth() - 1;
163 this.endSeq = al.getHeight() - 1;
166 // get the width and height scaling factors if they were specified
167 String param = applet.getParameter("widthScale");
172 widthScale = new Float(param).floatValue();
173 } catch (Exception e)
176 if (widthScale <= 1.0)
179 .println("Invalid alignment character width scaling factor ("
180 + widthScale + "). Ignoring.");
186 .println("Alignment character width scaling factor is now "
190 param = applet.getParameter("heightScale");
195 heightScale = new Float(param).floatValue();
196 } catch (Exception e)
199 if (heightScale <= 1.0)
202 .println("Invalid alignment character height scaling factor ("
203 + heightScale + "). Ignoring.");
209 .println("Alignment character height scaling factor is now "
216 MAC = new jalview.util.Platform().isAMac();
220 showJVSuffix = applet.getDefaultParameter("showFullId", showJVSuffix);
222 showAnnotation = applet.getDefaultParameter("showAnnotation", showAnnotation);
224 showConservation = applet.getDefaultParameter("showConservation", showConservation);
226 showQuality = applet.getDefaultParameter("showQuality", showQuality);
228 showConsensus = applet.getDefaultParameter("showConsensus", showConsensus);
230 showUnconserved = applet.getDefaultParameter("showUnconserved", showUnconserved);
232 String param = applet.getParameter("upperCase");
235 if (param.equalsIgnoreCase("bold"))
237 upperCasebold = true;
240 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
242 followHighlight = applet.getDefaultParameter("automaticScrolling",followHighlight);
243 followSelection = followHighlight;
245 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo", showSequenceLogo);
247 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus", showGroupConsensus);
249 showGroupConservation = applet.getDefaultParameter("showGroupConservation", showGroupConservation);
251 showConsensusHistogram = applet.getDefaultParameter("showConsensusHistogram", showConsensusHistogram);
257 String colour = applet.getParameter("defaultColour");
261 colour = applet.getParameter("userDefinedColour");
264 colour = "User Defined";
270 globalColourScheme = ColourSchemeProperty.getColour(alignment,
272 if (globalColourScheme != null)
274 globalColourScheme.setConsensus(hconsensus);
278 if (applet.getParameter("userDefinedColour") != null)
280 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
281 .getParameter("userDefinedColour"));
284 if (hconsensus == null)
286 if (!alignment.isNucleotide())
288 conservation = new AlignmentAnnotation("Conservation",
289 "Conservation of total alignment less than " + ConsPercGaps
290 + "% gaps", new Annotation[1], 0f, 11f,
291 AlignmentAnnotation.BAR_GRAPH);
292 conservation.hasText = true;
293 conservation.autoCalculated = true;
295 if (showConservation)
297 alignment.addAnnotation(conservation);
302 quality = new AlignmentAnnotation("Quality",
303 "Alignment Quality based on Blosum62 scores",
304 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
305 quality.hasText = true;
306 quality.autoCalculated = true;
308 alignment.addAnnotation(quality);
312 consensus = new AlignmentAnnotation("Consensus", "PID",
313 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
314 consensus.hasText = true;
315 consensus.autoCalculated = true;
319 alignment.addAnnotation(consensus);
325 public void showSequenceFeatures(boolean b)
327 showSequenceFeatures = b;
330 public boolean getShowSequenceFeatures()
332 return showSequenceFeatures;
335 class ConservationThread extends Thread
339 public ConservationThread(AlignmentPanel ap)
348 updatingConservation = true;
350 while (UPDATING_CONSERVATION)
356 ap.paintAlignment(false);
359 } catch (Exception ex)
361 ex.printStackTrace();
365 UPDATING_CONSERVATION = true;
367 int alWidth = (alignment==null) ? -1 : alignment.getWidth();
370 updatingConservation = false;
371 UPDATING_CONSERVATION = false;
375 Conservation cons = new jalview.analysis.Conservation("All",
376 jalview.schemes.ResidueProperties.propHash, 3,
377 alignment.getSequences(), 0, alWidth - 1);
380 cons.verdict(false, ConsPercGaps);
387 char[] sequence = cons.getConsSequence().getSequence();
399 maxB = 0f - minB; // scalable range for colouring both Conservation and
409 conservation.annotations = new Annotation[alWidth];
413 quality.graphMax = cons.qualityRange[1].floatValue();
414 quality.annotations = new Annotation[alWidth];
415 qmin = cons.qualityRange[0].floatValue();
416 qmax = cons.qualityRange[1].floatValue();
419 for (int i = 0; i < alWidth; i++)
425 if (Character.isDigit(c))
427 value = (int) (c - '0');
437 // TODO - refactor to use a graduatedColorScheme to calculate the
439 float vprop = value - min;
441 conservation.annotations[i] = new Annotation(String.valueOf(c),
442 String.valueOf(value), ' ', value, new Color(minR
443 + (maxR * vprop), minG + (maxG * vprop), minB
449 value = ((Double) cons.quality.elementAt(i)).floatValue();
450 vprop = value - qmin;
452 quality.annotations[i] = new Annotation(" ",
453 String.valueOf(value), ' ', value, new Color(minR
454 + (maxR * vprop), minG + (maxG * vprop), minB
458 } catch (OutOfMemoryError error)
460 System.out.println("Out of memory calculating conservation!!");
466 UPDATING_CONSERVATION = false;
467 updatingConservation = false;
471 ap.paintAlignment(true);
477 ConservationThread conservationThread;
479 ConsensusThread consensusThread;
481 boolean consUpdateNeeded = false;
483 static boolean UPDATING_CONSENSUS = false;
485 static boolean UPDATING_CONSERVATION = false;
487 boolean updatingConsensus = false;
489 boolean updatingConservation = false;
494 public void updateConservation(final AlignmentPanel ap)
496 if (alignment.isNucleotide() || conservation == null)
501 conservationThread = new ConservationThread(ap);
502 conservationThread.start();
508 public void updateConsensus(final AlignmentPanel ap)
510 consensusThread = new ConsensusThread(ap);
511 consensusThread.start();
514 class ConsensusThread extends Thread
518 public ConsensusThread(AlignmentPanel ap)
525 updatingConsensus = true;
526 while (UPDATING_CONSENSUS)
532 ap.paintAlignment(false);
536 } catch (Exception ex)
538 ex.printStackTrace();
542 UPDATING_CONSENSUS = true;
546 int aWidth = alignment==null ? -1 : alignment.getWidth();
549 UPDATING_CONSENSUS = false;
550 updatingConsensus = false;
554 consensus.annotations = null;
555 consensus.annotations = new Annotation[aWidth];
557 hconsensus = new Hashtable[aWidth];
558 AAFrequency.calculate(alignment.getSequencesArray(), 0,
559 alignment.getWidth(), hconsensus, true); // always calculate the
561 updateAnnotation(true);
562 //AAFrequency.completeConsensus(consensus, hconsensus, 0, aWidth,
563 // ignoreGapsInConsensusCalculation,
566 if (globalColourScheme != null)
568 globalColourScheme.setConsensus(hconsensus);
571 } catch (OutOfMemoryError error)
573 alignment.deleteAnnotation(consensus);
577 System.out.println("Out of memory calculating consensus!!");
580 UPDATING_CONSENSUS = false;
581 updatingConsensus = false;
585 ap.paintAlignment(true);
590 * update the consensus annotation from the sequence profile data using
591 * current visualization settings.
593 public void updateAnnotation()
595 updateAnnotation(false);
598 protected void updateAnnotation(boolean immediate)
600 // TODO: make calls thread-safe, so if another thread calls this method,
601 // it will either return or wait until one calculation is finished.
603 || (!updatingConsensus && consensus != null && hconsensus != null))
605 AAFrequency.completeConsensus(consensus, hconsensus, 0,
606 hconsensus.length, ignoreGapsInConsensusCalculation,
613 * get the consensus sequence as displayed under the PID consensus annotation
616 * @return consensus sequence as a new sequence object
618 public SequenceI getConsensusSeq()
620 if (consensus == null)
622 updateConsensus(null);
624 if (consensus == null)
628 StringBuffer seqs = new StringBuffer();
629 for (int i = 0; i < consensus.annotations.length; i++)
631 if (consensus.annotations[i] != null)
633 if (consensus.annotations[i].description.charAt(0) == '[')
635 seqs.append(consensus.annotations[i].description.charAt(1));
639 seqs.append(consensus.annotations[i].displayCharacter);
643 SequenceI sq = new Sequence("Consensus", seqs.toString());
644 sq.setDescription("Percentage Identity Consensus "
645 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
649 public SequenceGroup getSelectionGroup()
651 return selectionGroup;
654 public void setSelectionGroup(SequenceGroup sg)
659 public boolean getConservationSelected()
661 return conservationColourSelected;
664 public void setConservationSelected(boolean b)
666 conservationColourSelected = b;
669 public boolean getAbovePIDThreshold()
671 return abovePIDThreshold;
674 public void setAbovePIDThreshold(boolean b)
676 abovePIDThreshold = b;
679 public int getStartRes()
684 public int getEndRes()
689 public int getStartSeq()
694 public void setGlobalColourScheme(ColourSchemeI cs)
696 globalColourScheme = cs;
699 public ColourSchemeI getGlobalColourScheme()
701 return globalColourScheme;
704 public void setStartRes(int res)
709 public void setStartSeq(int seq)
714 public void setEndRes(int res)
716 if (res > alignment.getWidth() - 1)
718 // log.System.out.println(" Corrected res from " + res + " to maximum " +
719 // (alignment.getWidth()-1));
720 res = alignment.getWidth() - 1;
729 public void setEndSeq(int seq)
731 if (seq > alignment.getHeight())
733 seq = alignment.getHeight();
742 public int getEndSeq()
747 java.awt.Frame nullFrame;
749 protected FeatureSettings featureSettings = null;
751 private float heightScale = 1, widthScale = 1;
753 public void setFont(Font f)
756 if (nullFrame == null)
758 nullFrame = new java.awt.Frame();
759 nullFrame.addNotify();
762 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
763 setCharHeight((int) (heightScale * fm.getHeight()));
764 charWidth = (int) (widthScale * fm.charWidth('M'));
768 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
769 fm = nullFrame.getGraphics().getFontMetrics(f2);
770 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
774 public Font getFont()
779 public int getCharWidth()
784 public void setCharHeight(int h)
789 public int getCharHeight()
794 public void setWrappedWidth(int w)
796 this.wrappedWidth = w;
799 public int getwrappedWidth()
804 public AlignmentI getAlignment()
809 public void setAlignment(AlignmentI align)
811 this.alignment = align;
814 public void setWrapAlignment(boolean state)
816 wrapAlignment = state;
819 public void setShowText(boolean state)
824 public void setRenderGaps(boolean state)
829 public boolean getColourText()
831 return showColourText;
834 public void setColourText(boolean state)
836 showColourText = state;
839 public void setShowBoxes(boolean state)
844 public boolean getWrapAlignment()
846 return wrapAlignment;
849 public boolean getShowText()
854 public boolean getShowBoxes()
859 public char getGapCharacter()
861 return getAlignment().getGapCharacter();
864 public void setGapCharacter(char gap)
866 if (getAlignment() != null)
868 getAlignment().setGapCharacter(gap);
872 public void setThreshold(int thresh)
877 public int getThreshold()
882 public void setIncrement(int inc)
887 public int getIncrement()
892 public void setHiddenColumns(ColumnSelection colsel)
894 this.colSel = colsel;
895 if (colSel.getHiddenColumns() != null)
897 hasHiddenColumns = true;
901 public ColumnSelection getColumnSelection()
906 public void resetSeqLimits(int height)
908 setEndSeq(height / getCharHeight());
911 public void setCurrentTree(NJTree tree)
916 public NJTree getCurrentTree()
921 public void setColourAppliesToAllGroups(boolean b)
923 colourAppliesToAllGroups = b;
926 public boolean getColourAppliesToAllGroups()
928 return colourAppliesToAllGroups;
931 public boolean getShowJVSuffix()
936 public void setShowJVSuffix(boolean b)
941 public boolean getShowAnnotation()
943 return showAnnotation;
946 public void setShowAnnotation(boolean b)
951 public boolean getScaleAboveWrapped()
953 return scaleAboveWrapped;
956 public boolean getScaleLeftWrapped()
958 return scaleLeftWrapped;
961 public boolean getScaleRightWrapped()
963 return scaleRightWrapped;
966 public void setScaleAboveWrapped(boolean b)
968 scaleAboveWrapped = b;
971 public void setScaleLeftWrapped(boolean b)
973 scaleLeftWrapped = b;
976 public void setScaleRightWrapped(boolean b)
978 scaleRightWrapped = b;
981 public void setIgnoreGapsConsensus(boolean b)
983 ignoreGapsInConsensusCalculation = b;
984 updateConsensus(null);
985 if (globalColourScheme != null)
987 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
988 ignoreGapsInConsensusCalculation);
994 * Property change listener for changes in alignment
999 public void addPropertyChangeListener(
1000 java.beans.PropertyChangeListener listener)
1002 changeSupport.addPropertyChangeListener(listener);
1011 public void removePropertyChangeListener(
1012 java.beans.PropertyChangeListener listener)
1014 changeSupport.removePropertyChangeListener(listener);
1018 * Property change listener for changes in alignment
1027 public void firePropertyChange(String prop, Object oldvalue,
1030 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1033 public boolean getIgnoreGapsConsensus()
1035 return ignoreGapsInConsensusCalculation;
1038 public void hideSelectedColumns()
1040 if (colSel.size() < 1)
1045 colSel.hideSelectedColumns();
1046 setSelectionGroup(null);
1048 hasHiddenColumns = true;
1051 public void invertColumnSelection()
1053 for (int i = 0; i < alignment.getWidth(); i++)
1055 if (colSel.contains(i))
1057 colSel.removeElement(i);
1061 if (!hasHiddenColumns || colSel.isVisible(i))
1063 colSel.addElement(i);
1069 public void hideColumns(int start, int end)
1073 colSel.hideColumns(start);
1077 colSel.hideColumns(start, end);
1080 hasHiddenColumns = true;
1083 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1085 int sSize = sg.getSize();
1091 if (hiddenRepSequences == null)
1093 hiddenRepSequences = new Hashtable();
1096 hiddenRepSequences.put(repSequence, sg);
1098 // Hide all sequences except the repSequence
1099 SequenceI[] seqs = new SequenceI[sSize - 1];
1101 for (int i = 0; i < sSize; i++)
1103 if (sg.getSequenceAt(i) != repSequence)
1105 if (index == sSize - 1)
1110 seqs[index++] = sg.getSequenceAt(i);
1118 public void hideAllSelectedSeqs()
1120 if (selectionGroup == null || selectionGroup.getSize() < 1)
1125 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1129 setSelectionGroup(null);
1132 public void hideSequence(SequenceI[] seq)
1136 for (int i = 0; i < seq.length; i++)
1138 alignment.getHiddenSequences().hideSequence(seq[i]);
1141 hasHiddenRows = true;
1142 firePropertyChange("alignment", null, alignment.getSequences());
1145 public void showSequence(int index)
1147 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1148 hiddenRepSequences);
1151 if (selectionGroup == null)
1153 selectionGroup = new SequenceGroup();
1154 selectionGroup.setEndRes(alignment.getWidth() - 1);
1157 for (int t = 0; t < tmp.size(); t++)
1159 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1161 firePropertyChange("alignment", null, alignment.getSequences());
1165 if (alignment.getHiddenSequences().getSize() < 1)
1167 hasHiddenRows = false;
1170 public void showColumn(int col)
1172 colSel.revealHiddenColumns(col);
1173 if (colSel.getHiddenColumns() == null)
1175 hasHiddenColumns = false;
1179 public void showAllHiddenColumns()
1181 colSel.revealAllHiddenColumns();
1182 hasHiddenColumns = false;
1185 public void showAllHiddenSeqs()
1187 if (alignment.getHiddenSequences().getSize() > 0)
1189 if (selectionGroup == null)
1191 selectionGroup = new SequenceGroup();
1192 selectionGroup.setEndRes(alignment.getWidth() - 1);
1194 Vector tmp = alignment.getHiddenSequences().showAll(
1195 hiddenRepSequences);
1196 for (int t = 0; t < tmp.size(); t++)
1198 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1200 firePropertyChange("alignment", null, alignment.getSequences());
1201 hasHiddenRows = false;
1202 hiddenRepSequences = null;
1207 public int adjustForHiddenSeqs(int alignmentIndex)
1209 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1214 * This method returns the a new SequenceI [] with the selection sequence and
1215 * start and end points adjusted
1219 public SequenceI[] getSelectionAsNewSequence()
1221 SequenceI[] sequences;
1223 if (selectionGroup == null)
1225 sequences = alignment.getSequencesArray();
1229 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1236 * get the currently selected sequence objects or all the sequences in the
1239 * @return array of references to sequence objects
1241 public SequenceI[] getSequenceSelection()
1243 SequenceI[] sequences = null;
1244 if (selectionGroup != null)
1246 sequences = selectionGroup.getSequencesInOrder(alignment);
1248 if (sequences == null)
1250 sequences = alignment.getSequencesArray();
1256 * This method returns the visible alignment as text, as seen on the GUI, ie
1257 * if columns are hidden they will not be returned in the result. Use this for
1258 * calculating trees, PCA, redundancy etc on views which contain hidden
1263 public jalview.datamodel.CigarArray getViewAsCigars(
1264 boolean selectedRegionOnly)
1266 return new jalview.datamodel.CigarArray(alignment, (hasHiddenColumns ? colSel : null), (selectedRegionOnly ? selectionGroup : null));
1270 * return a compact representation of the current alignment selection to pass
1271 * to an analysis function
1273 * @param selectedOnly
1274 * boolean true to just return the selected view
1275 * @return AlignmentView
1277 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1279 return getAlignmentView(selectedOnly, false);
1283 * return a compact representation of the current alignment selection to pass
1284 * to an analysis function
1286 * @param selectedOnly
1287 * boolean true to just return the selected view
1289 * boolean true to annotate the alignment view with groups on the alignment (and intersecting with selected region if selectedOnly is true)
1290 * @return AlignmentView
1292 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups)
1294 return new AlignmentView(alignment, colSel, selectionGroup, hasHiddenColumns, selectedOnly, markGroups);
1297 * This method returns the visible alignment as text, as seen on the GUI, ie
1298 * if columns are hidden they will not be returned in the result. Use this for
1299 * calculating trees, PCA, redundancy etc on views which contain hidden
1304 public String[] getViewAsString(boolean selectedRegionOnly)
1306 String[] selection = null;
1307 SequenceI[] seqs = null;
1309 int start = 0, end = 0;
1310 if (selectedRegionOnly && selectionGroup != null)
1312 iSize = selectionGroup.getSize();
1313 seqs = selectionGroup.getSequencesInOrder(alignment);
1314 start = selectionGroup.getStartRes();
1315 end = selectionGroup.getEndRes() + 1;
1319 iSize = alignment.getHeight();
1320 seqs = alignment.getSequencesArray();
1321 end = alignment.getWidth();
1324 selection = new String[iSize];
1326 for (i = 0; i < iSize; i++)
1328 if (hasHiddenColumns)
1330 StringBuffer visibleSeq = new StringBuffer();
1331 Vector regions = colSel.getHiddenColumns();
1333 int blockStart = start, blockEnd = end;
1335 int hideStart, hideEnd;
1337 for (int j = 0; j < regions.size(); j++)
1339 region = (int[]) regions.elementAt(j);
1340 hideStart = region[0];
1341 hideEnd = region[1];
1343 if (hideStart < start)
1348 blockStart = Math.min(blockStart, hideEnd + 1);
1349 blockEnd = Math.min(blockEnd, hideStart);
1351 if (blockStart > blockEnd)
1356 visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
1358 blockStart = hideEnd + 1;
1362 if (end > blockStart)
1364 visibleSeq.append(seqs[i].getSequence(blockStart, end));
1367 selection[i] = visibleSeq.toString();
1371 selection[i] = seqs[i].getSequenceAsString(start, end);
1378 public boolean getShowHiddenMarkers()
1380 return showHiddenMarkers;
1383 public void setShowHiddenMarkers(boolean show)
1385 showHiddenMarkers = show;
1388 public Color getSequenceColour(SequenceI seq)
1390 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1396 return (Color) sequenceColours.get(seq);
1400 public void setSequenceColour(SequenceI seq, Color col)
1402 if (sequenceColours == null)
1404 sequenceColours = new Hashtable();
1409 sequenceColours.remove(seq);
1413 sequenceColours.put(seq, col);
1417 public String getSequenceSetId()
1419 if (sequenceSetID == null)
1421 sequenceSetID = alignment.hashCode() + "";
1424 return sequenceSetID;
1427 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1430 private String viewId = null;
1432 public String getViewId()
1436 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1441 public void alignmentChanged(AlignmentPanel ap)
1443 alignment.padGaps();
1445 if (hconsensus != null && autocalculateConsensus)
1447 updateConsensus(ap);
1448 updateConservation(ap);
1451 // Reset endRes of groups if beyond alignment width
1452 int alWidth = alignment.getWidth();
1453 Vector groups = alignment.getGroups();
1456 for (int i = 0; i < groups.size(); i++)
1458 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1459 if (sg.getEndRes() > alWidth)
1461 sg.setEndRes(alWidth - 1);
1466 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1468 selectionGroup.setEndRes(alWidth - 1);
1471 resetAllColourSchemes();
1473 // AW alignment.adjustSequenceAnnotations();
1476 void resetAllColourSchemes()
1478 ColourSchemeI cs = globalColourScheme;
1481 if (cs instanceof ClustalxColourScheme)
1483 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1484 alignment.getWidth());
1487 cs.setConsensus(hconsensus);
1488 if (cs.conservationApplied())
1490 Alignment al = (Alignment) alignment;
1491 Conservation c = new Conservation("All",
1492 ResidueProperties.propHash, 3, al.getSequences(), 0,
1495 c.verdict(false, ConsPercGaps);
1497 cs.setConservation(c);
1501 int s, sSize = alignment.getGroups().size();
1502 for (s = 0; s < sSize; s++)
1504 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1505 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1507 ((ClustalxColourScheme) sg.cs).resetClustalX(
1508 sg.getSequences(hiddenRepSequences), sg.getWidth());
1510 sg.recalcConservation();
1514 boolean centreColumnLabels;
1516 public boolean getCentreColumnLabels()
1518 return centreColumnLabels;
1521 public void updateSequenceIdColours()
1523 Vector groups = alignment.getGroups();
1524 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1526 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1527 if (sg.idColour != null)
1529 Vector sqs = sg.getSequences(hiddenRepSequences);
1530 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1532 this.setSequenceColour((SequenceI) sqs.elementAt(s), sg.idColour);
1538 public boolean followHighlight = true;
1540 public boolean getFollowHighlight()
1542 return followHighlight;
1545 public boolean followSelection = true;
1548 * @return true if view selection should always follow the selections
1549 * broadcast by other selection sources
1551 public boolean getFollowSelection()
1553 return followSelection;
1556 private long sgrouphash = -1, colselhash = -1;
1559 * checks current SelectionGroup against record of last hash value, and
1562 * @return true if SelectionGroup changed since last call
1564 boolean isSelectionGroupChanged()
1566 int hc = (selectionGroup == null) ? -1 : selectionGroup.hashCode();
1567 if (hc != sgrouphash)
1576 * checks current colsel against record of last hash value, and updates
1579 * @return true if colsel changed since last call
1581 boolean isColSelChanged()
1583 int hc = (colSel == null) ? -1 : colSel.hashCode();
1584 if (hc != colselhash)
1591 public void sendSelection()
1593 jalview.structure.StructureSelectionManager
1594 .getStructureSelectionManager(applet).sendSelection(
1595 new SequenceGroup(getSelectionGroup()),
1596 new ColumnSelection(getColumnSelection()), this);
1603 * show non-conserved residues only
1605 public boolean showUnconserved = false;
1608 * when set, alignment should be reordered according to a newly opened tree
1610 public boolean sortByTree = false;
1613 * @return the showUnconserved
1615 public boolean getShowunconserved()
1617 return showUnconserved;
1621 * @param showNonconserved
1622 * the showUnconserved to set
1624 public void setShowunconserved(boolean displayNonconserved)
1626 this.showUnconserved = displayNonconserved;
1630 * should conservation rows be shown for groups
1632 boolean showGroupConservation = false;
1635 * should consensus rows be shown for groups
1637 boolean showGroupConsensus = false;
1640 * should consensus profile be rendered by default
1642 public boolean showSequenceLogo = false;
1645 * should consensus histograms be rendered by default
1647 public boolean showConsensusHistogram = true;
1650 * @return the showConsensusProfile
1652 public boolean isShowSequenceLogo()
1654 return showSequenceLogo;
1658 * @param showSequenceLogo
1661 public void setShowSequenceLogo(boolean showSequenceLogo)
1663 if (showSequenceLogo != this.showSequenceLogo)
1665 // TODO: decouple settings setting from calculation when refactoring
1666 // annotation update method from alignframe to viewport
1667 this.showSequenceLogo = showSequenceLogo;
1668 if (consensusThread != null)
1670 consensusThread.updateAnnotation();
1673 this.showSequenceLogo = showSequenceLogo;
1677 * @param showConsensusHistogram
1678 * the showConsensusHistogram to set
1680 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1682 this.showConsensusHistogram = showConsensusHistogram;
1686 * @return the showGroupConservation
1688 public boolean isShowGroupConservation()
1690 return showGroupConservation;
1694 * @param showGroupConservation
1695 * the showGroupConservation to set
1697 public void setShowGroupConservation(boolean showGroupConservation)
1699 this.showGroupConservation = showGroupConservation;
1703 * @return the showGroupConsensus
1705 public boolean isShowGroupConsensus()
1707 return showGroupConsensus;
1711 * @param showGroupConsensus
1712 * the showGroupConsensus to set
1714 public void setShowGroupConsensus(boolean showGroupConsensus)
1716 this.showGroupConsensus = showGroupConsensus;
1721 * @return flag to indicate if the consensus histogram should be rendered by
1724 public boolean isShowConsensusHistogram()
1726 return this.showConsensusHistogram;
1730 * synthesize a column selection if none exists so it covers the given
1731 * selection group. if wholewidth is false, no column selection is made if the
1732 * selection group covers the whole alignment width.
1737 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
1741 && (sgs = sg.getStartRes()) >= 0
1742 && sg.getStartRes() <= (sge = sg.getEndRes())
1743 && (colSel == null || colSel.getSelected() == null || colSel
1744 .getSelected().size() == 0))
1746 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
1753 colSel = new ColumnSelection();
1755 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
1757 colSel.addElement(cspos);