2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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.*;
25 import jalview.api.AlignViewportI;
27 import jalview.datamodel.*;
28 import jalview.schemes.*;
29 import jalview.structure.SelectionSource;
30 import jalview.structure.VamsasSource;
32 public class AlignViewport implements AlignViewportI, 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 normaliseSequenceLogo = applet.getDefaultParameter("normaliseSequenceLogo", normaliseSequenceLogo);
249 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus", showGroupConsensus);
251 showGroupConservation = applet.getDefaultParameter("showGroupConservation", showGroupConservation);
253 showConsensusHistogram = applet.getDefaultParameter("showConsensusHistogram", showConsensusHistogram);
259 String colour = applet.getParameter("defaultColour");
263 colour = applet.getParameter("userDefinedColour");
266 colour = "User Defined";
272 globalColourScheme = ColourSchemeProperty.getColour(alignment,
274 if (globalColourScheme != null)
276 globalColourScheme.setConsensus(hconsensus);
280 if (applet.getParameter("userDefinedColour") != null)
282 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
283 .getParameter("userDefinedColour"));
286 if (hconsensus == null)
288 if (!alignment.isNucleotide())
290 conservation = new AlignmentAnnotation("Conservation",
291 "Conservation of total alignment less than " + ConsPercGaps
292 + "% gaps", new Annotation[1], 0f, 11f,
293 AlignmentAnnotation.BAR_GRAPH);
294 conservation.hasText = true;
295 conservation.autoCalculated = true;
297 if (showConservation)
299 alignment.addAnnotation(conservation);
304 quality = new AlignmentAnnotation("Quality",
305 "Alignment Quality based on Blosum62 scores",
306 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
307 quality.hasText = true;
308 quality.autoCalculated = true;
310 alignment.addAnnotation(quality);
314 consensus = new AlignmentAnnotation("Consensus", "PID",
315 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
316 consensus.hasText = true;
317 consensus.autoCalculated = true;
321 alignment.addAnnotation(consensus);
327 public void showSequenceFeatures(boolean b)
329 showSequenceFeatures = b;
332 public boolean getShowSequenceFeatures()
334 return showSequenceFeatures;
337 class ConservationThread extends Thread
341 public ConservationThread(AlignmentPanel ap)
350 updatingConservation = true;
352 while (UPDATING_CONSERVATION)
358 ap.paintAlignment(false);
361 } catch (Exception ex)
363 ex.printStackTrace();
367 UPDATING_CONSERVATION = true;
369 int alWidth = (alignment==null) ? -1 : alignment.getWidth();
372 updatingConservation = false;
373 UPDATING_CONSERVATION = false;
377 Conservation cons = new jalview.analysis.Conservation("All",
378 jalview.schemes.ResidueProperties.propHash, 3,
379 alignment.getSequences(), 0, alWidth - 1);
382 cons.verdict(false, ConsPercGaps);
389 char[] sequence = cons.getConsSequence().getSequence();
401 maxB = 0f - minB; // scalable range for colouring both Conservation and
411 conservation.annotations = new Annotation[alWidth];
415 quality.graphMax = cons.qualityRange[1].floatValue();
416 quality.annotations = new Annotation[alWidth];
417 qmin = cons.qualityRange[0].floatValue();
418 qmax = cons.qualityRange[1].floatValue();
421 for (int i = 0; i < alWidth; i++)
427 if (Character.isDigit(c))
429 value = (int) (c - '0');
439 // TODO - refactor to use a graduatedColorScheme to calculate the
441 float vprop = value - min;
443 conservation.annotations[i] = new Annotation(String.valueOf(c),
444 String.valueOf(value), ' ', value, new Color(minR
445 + (maxR * vprop), minG + (maxG * vprop), minB
451 value = ((Double) cons.quality.elementAt(i)).floatValue();
452 vprop = value - qmin;
454 quality.annotations[i] = new Annotation(" ",
455 String.valueOf(value), ' ', value, new Color(minR
456 + (maxR * vprop), minG + (maxG * vprop), minB
460 } catch (OutOfMemoryError error)
462 System.out.println("Out of memory calculating conservation!!");
468 UPDATING_CONSERVATION = false;
469 updatingConservation = false;
473 ap.paintAlignment(true);
479 ConservationThread conservationThread;
481 ConsensusThread consensusThread;
483 // StrucConsensusThread strucConsensusThread;
486 boolean consUpdateNeeded = false;
488 static boolean UPDATING_CONSENSUS = false;
490 static boolean UPDATING_STRUC_CONSENSUS = false;
492 static boolean UPDATING_CONSERVATION = false;
494 boolean updatingConsensus = false;
496 boolean updatingStrucConsensus = false;
498 boolean updatingConservation = false;
503 public void updateConservation(final AlignmentPanel ap)
505 if (alignment.isNucleotide() || conservation == null)
510 conservationThread = new ConservationThread(ap);
511 conservationThread.start();
517 public void updateConsensus(final AlignmentPanel ap)
519 consensusThread = new ConsensusThread(ap);
520 consensusThread.start();
523 class ConsensusThread extends Thread
527 public ConsensusThread(AlignmentPanel ap)
534 updatingConsensus = true;
535 while (UPDATING_CONSENSUS)
541 ap.paintAlignment(false);
545 } catch (Exception ex)
547 ex.printStackTrace();
551 UPDATING_CONSENSUS = true;
555 int aWidth = alignment==null ? -1 : alignment.getWidth();
558 UPDATING_CONSENSUS = false;
559 updatingConsensus = false;
563 consensus.annotations = null;
564 consensus.annotations = new Annotation[aWidth];
566 hconsensus = new Hashtable[aWidth];
567 AAFrequency.calculate(alignment.getSequencesArray(), 0,
568 alignment.getWidth(), hconsensus, true); // always calculate the
570 updateAnnotation(true);
571 //AAFrequency.completeConsensus(consensus, hconsensus, 0, aWidth,
572 // ignoreGapsInConsensusCalculation,
575 if (globalColourScheme != null)
577 globalColourScheme.setConsensus(hconsensus);
580 } catch (OutOfMemoryError error)
582 alignment.deleteAnnotation(consensus);
586 System.out.println("Out of memory calculating consensus!!");
589 UPDATING_CONSENSUS = false;
590 updatingConsensus = false;
594 ap.paintAlignment(true);
599 * update the consensus annotation from the sequence profile data using
600 * current visualization settings.
602 public void updateAnnotation()
604 updateAnnotation(false);
607 protected void updateAnnotation(boolean immediate)
609 // TODO: make calls thread-safe, so if another thread calls this method,
610 // it will either return or wait until one calculation is finished.
612 || (!updatingConsensus && consensus != null && hconsensus != null))
614 AAFrequency.completeConsensus(consensus, hconsensus, 0,
615 hconsensus.length, ignoreGapsInConsensusCalculation,
622 * get the consensus sequence as displayed under the PID consensus annotation
625 * @return consensus sequence as a new sequence object
627 public SequenceI getConsensusSeq()
629 if (consensus == null)
631 updateConsensus(null);
633 if (consensus == null)
637 StringBuffer seqs = new StringBuffer();
638 for (int i = 0; i < consensus.annotations.length; i++)
640 if (consensus.annotations[i] != null)
642 if (consensus.annotations[i].description.charAt(0) == '[')
644 seqs.append(consensus.annotations[i].description.charAt(1));
648 seqs.append(consensus.annotations[i].displayCharacter);
652 SequenceI sq = new Sequence("Consensus", seqs.toString());
653 sq.setDescription("Percentage Identity Consensus "
654 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
658 public SequenceGroup getSelectionGroup()
660 return selectionGroup;
663 public void setSelectionGroup(SequenceGroup sg)
668 public boolean getConservationSelected()
670 return conservationColourSelected;
673 public void setConservationSelected(boolean b)
675 conservationColourSelected = b;
678 public boolean getAbovePIDThreshold()
680 return abovePIDThreshold;
683 public void setAbovePIDThreshold(boolean b)
685 abovePIDThreshold = b;
688 public int getStartRes()
693 public int getEndRes()
698 public int getStartSeq()
703 public void setGlobalColourScheme(ColourSchemeI cs)
705 globalColourScheme = cs;
708 public ColourSchemeI getGlobalColourScheme()
710 return globalColourScheme;
713 public void setStartRes(int res)
718 public void setStartSeq(int seq)
723 public void setEndRes(int res)
725 if (res > alignment.getWidth() - 1)
727 // log.System.out.println(" Corrected res from " + res + " to maximum " +
728 // (alignment.getWidth()-1));
729 res = alignment.getWidth() - 1;
738 public void setEndSeq(int seq)
740 if (seq > alignment.getHeight())
742 seq = alignment.getHeight();
751 public int getEndSeq()
756 java.awt.Frame nullFrame;
758 protected FeatureSettings featureSettings = null;
760 private float heightScale = 1, widthScale = 1;
762 public void setFont(Font f)
765 if (nullFrame == null)
767 nullFrame = new java.awt.Frame();
768 nullFrame.addNotify();
771 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
772 setCharHeight((int) (heightScale * fm.getHeight()));
773 charWidth = (int) (widthScale * fm.charWidth('M'));
777 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
778 fm = nullFrame.getGraphics().getFontMetrics(f2);
779 charWidth = (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10));
783 public Font getFont()
788 public int getCharWidth()
793 public void setCharHeight(int h)
798 public int getCharHeight()
803 public void setWrappedWidth(int w)
805 this.wrappedWidth = w;
808 public int getwrappedWidth()
813 public AlignmentI getAlignment()
818 public void setAlignment(AlignmentI align)
820 this.alignment = align;
823 public void setWrapAlignment(boolean state)
825 wrapAlignment = state;
828 public void setShowText(boolean state)
833 public void setRenderGaps(boolean state)
838 public boolean getColourText()
840 return showColourText;
843 public void setColourText(boolean state)
845 showColourText = state;
848 public void setShowBoxes(boolean state)
853 public boolean getWrapAlignment()
855 return wrapAlignment;
858 public boolean getShowText()
863 public boolean getShowBoxes()
868 public char getGapCharacter()
870 return getAlignment().getGapCharacter();
873 public void setGapCharacter(char gap)
875 if (getAlignment() != null)
877 getAlignment().setGapCharacter(gap);
881 public void setThreshold(int thresh)
886 public int getThreshold()
891 public void setIncrement(int inc)
896 public int getIncrement()
901 public void setHiddenColumns(ColumnSelection colsel)
903 this.colSel = colsel;
904 if (colSel.getHiddenColumns() != null)
906 hasHiddenColumns = true;
910 public ColumnSelection getColumnSelection()
915 public void resetSeqLimits(int height)
917 setEndSeq(height / getCharHeight());
920 public void setCurrentTree(NJTree tree)
925 public NJTree getCurrentTree()
930 public void setColourAppliesToAllGroups(boolean b)
932 colourAppliesToAllGroups = b;
935 public boolean getColourAppliesToAllGroups()
937 return colourAppliesToAllGroups;
940 public boolean getShowJVSuffix()
945 public void setShowJVSuffix(boolean b)
950 public boolean getShowAnnotation()
952 return showAnnotation;
955 public void setShowAnnotation(boolean b)
960 public boolean getScaleAboveWrapped()
962 return scaleAboveWrapped;
965 public boolean getScaleLeftWrapped()
967 return scaleLeftWrapped;
970 public boolean getScaleRightWrapped()
972 return scaleRightWrapped;
975 public void setScaleAboveWrapped(boolean b)
977 scaleAboveWrapped = b;
980 public void setScaleLeftWrapped(boolean b)
982 scaleLeftWrapped = b;
985 public void setScaleRightWrapped(boolean b)
987 scaleRightWrapped = b;
990 public void setIgnoreGapsConsensus(boolean b)
992 ignoreGapsInConsensusCalculation = b;
993 updateConsensus(null);
994 if (globalColourScheme != null)
996 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
997 ignoreGapsInConsensusCalculation);
1003 * Property change listener for changes in alignment
1008 public void addPropertyChangeListener(
1009 java.beans.PropertyChangeListener listener)
1011 changeSupport.addPropertyChangeListener(listener);
1020 public void removePropertyChangeListener(
1021 java.beans.PropertyChangeListener listener)
1023 changeSupport.removePropertyChangeListener(listener);
1027 * Property change listener for changes in alignment
1036 public void firePropertyChange(String prop, Object oldvalue,
1039 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1042 public boolean getIgnoreGapsConsensus()
1044 return ignoreGapsInConsensusCalculation;
1047 public void hideSelectedColumns()
1049 if (colSel.size() < 1)
1054 colSel.hideSelectedColumns();
1055 setSelectionGroup(null);
1057 hasHiddenColumns = true;
1060 public void invertColumnSelection()
1062 for (int i = 0; i < alignment.getWidth(); i++)
1064 if (colSel.contains(i))
1066 colSel.removeElement(i);
1070 if (!hasHiddenColumns || colSel.isVisible(i))
1072 colSel.addElement(i);
1078 public void hideColumns(int start, int end)
1082 colSel.hideColumns(start);
1086 colSel.hideColumns(start, end);
1089 hasHiddenColumns = true;
1092 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1094 int sSize = sg.getSize();
1100 if (hiddenRepSequences == null)
1102 hiddenRepSequences = new Hashtable();
1105 hiddenRepSequences.put(repSequence, sg);
1107 // Hide all sequences except the repSequence
1108 SequenceI[] seqs = new SequenceI[sSize - 1];
1110 for (int i = 0; i < sSize; i++)
1112 if (sg.getSequenceAt(i) != repSequence)
1114 if (index == sSize - 1)
1119 seqs[index++] = sg.getSequenceAt(i);
1127 public void hideAllSelectedSeqs()
1129 if (selectionGroup == null || selectionGroup.getSize() < 1)
1134 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1138 setSelectionGroup(null);
1141 public void hideSequence(SequenceI[] seq)
1145 for (int i = 0; i < seq.length; i++)
1147 alignment.getHiddenSequences().hideSequence(seq[i]);
1150 hasHiddenRows = true;
1151 firePropertyChange("alignment", null, alignment.getSequences());
1154 public void showSequence(int index)
1156 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1157 hiddenRepSequences);
1160 if (selectionGroup == null)
1162 selectionGroup = new SequenceGroup();
1163 selectionGroup.setEndRes(alignment.getWidth() - 1);
1166 for (int t = 0; t < tmp.size(); t++)
1168 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1170 firePropertyChange("alignment", null, alignment.getSequences());
1174 if (alignment.getHiddenSequences().getSize() < 1)
1176 hasHiddenRows = false;
1179 public void showColumn(int col)
1181 colSel.revealHiddenColumns(col);
1182 if (colSel.getHiddenColumns() == null)
1184 hasHiddenColumns = false;
1188 public void showAllHiddenColumns()
1190 colSel.revealAllHiddenColumns();
1191 hasHiddenColumns = false;
1194 public void showAllHiddenSeqs()
1196 if (alignment.getHiddenSequences().getSize() > 0)
1198 if (selectionGroup == null)
1200 selectionGroup = new SequenceGroup();
1201 selectionGroup.setEndRes(alignment.getWidth() - 1);
1203 Vector tmp = alignment.getHiddenSequences().showAll(
1204 hiddenRepSequences);
1205 for (int t = 0; t < tmp.size(); t++)
1207 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1209 firePropertyChange("alignment", null, alignment.getSequences());
1210 hasHiddenRows = false;
1211 hiddenRepSequences = null;
1216 public int adjustForHiddenSeqs(int alignmentIndex)
1218 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1223 * This method returns the a new SequenceI [] with the selection sequence and
1224 * start and end points adjusted
1228 public SequenceI[] getSelectionAsNewSequence()
1230 SequenceI[] sequences;
1232 if (selectionGroup == null)
1234 sequences = alignment.getSequencesArray();
1238 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1245 * get the currently selected sequence objects or all the sequences in the
1248 * @return array of references to sequence objects
1250 public SequenceI[] getSequenceSelection()
1252 SequenceI[] sequences = null;
1253 if (selectionGroup != null)
1255 sequences = selectionGroup.getSequencesInOrder(alignment);
1257 if (sequences == null)
1259 sequences = alignment.getSequencesArray();
1265 * This method returns the visible alignment as text, as seen on the GUI, ie
1266 * if columns are hidden they will not be returned in the result. Use this for
1267 * calculating trees, PCA, redundancy etc on views which contain hidden
1272 public jalview.datamodel.CigarArray getViewAsCigars(
1273 boolean selectedRegionOnly)
1275 return new jalview.datamodel.CigarArray(alignment, (hasHiddenColumns ? colSel : null), (selectedRegionOnly ? selectionGroup : null));
1279 * return a compact representation of the current alignment selection to pass
1280 * to an analysis function
1282 * @param selectedOnly
1283 * boolean true to just return the selected view
1284 * @return AlignmentView
1286 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1288 return getAlignmentView(selectedOnly, false);
1292 * return a compact representation of the current alignment selection to pass
1293 * to an analysis function
1295 * @param selectedOnly
1296 * boolean true to just return the selected view
1298 * boolean true to annotate the alignment view with groups on the alignment (and intersecting with selected region if selectedOnly is true)
1299 * @return AlignmentView
1301 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups)
1303 return new AlignmentView(alignment, colSel, selectionGroup, hasHiddenColumns, selectedOnly, markGroups);
1306 * This method returns the visible alignment as text, as seen on the GUI, ie
1307 * if columns are hidden they will not be returned in the result. Use this for
1308 * calculating trees, PCA, redundancy etc on views which contain hidden
1313 public String[] getViewAsString(boolean selectedRegionOnly)
1315 String[] selection = null;
1316 SequenceI[] seqs = null;
1318 int start = 0, end = 0;
1319 if (selectedRegionOnly && selectionGroup != null)
1321 iSize = selectionGroup.getSize();
1322 seqs = selectionGroup.getSequencesInOrder(alignment);
1323 start = selectionGroup.getStartRes();
1324 end = selectionGroup.getEndRes() + 1;
1328 iSize = alignment.getHeight();
1329 seqs = alignment.getSequencesArray();
1330 end = alignment.getWidth();
1333 selection = new String[iSize];
1335 for (i = 0; i < iSize; i++)
1337 if (hasHiddenColumns)
1339 StringBuffer visibleSeq = new StringBuffer();
1340 Vector regions = colSel.getHiddenColumns();
1342 int blockStart = start, blockEnd = end;
1344 int hideStart, hideEnd;
1346 for (int j = 0; j < regions.size(); j++)
1348 region = (int[]) regions.elementAt(j);
1349 hideStart = region[0];
1350 hideEnd = region[1];
1352 if (hideStart < start)
1357 blockStart = Math.min(blockStart, hideEnd + 1);
1358 blockEnd = Math.min(blockEnd, hideStart);
1360 if (blockStart > blockEnd)
1365 visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
1367 blockStart = hideEnd + 1;
1371 if (end > blockStart)
1373 visibleSeq.append(seqs[i].getSequence(blockStart, end));
1376 selection[i] = visibleSeq.toString();
1380 selection[i] = seqs[i].getSequenceAsString(start, end);
1387 public boolean getShowHiddenMarkers()
1389 return showHiddenMarkers;
1392 public void setShowHiddenMarkers(boolean show)
1394 showHiddenMarkers = show;
1397 public Color getSequenceColour(SequenceI seq)
1399 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1405 return (Color) sequenceColours.get(seq);
1409 public void setSequenceColour(SequenceI seq, Color col)
1411 if (sequenceColours == null)
1413 sequenceColours = new Hashtable();
1418 sequenceColours.remove(seq);
1422 sequenceColours.put(seq, col);
1426 public String getSequenceSetId()
1428 if (sequenceSetID == null)
1430 sequenceSetID = alignment.hashCode() + "";
1433 return sequenceSetID;
1436 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1439 private String viewId = null;
1441 public String getViewId()
1445 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1450 public void alignmentChanged(AlignmentPanel ap)
1452 alignment.padGaps();
1454 if (hconsensus != null && autocalculateConsensus)
1456 updateConsensus(ap);
1457 updateConservation(ap);
1460 // Reset endRes of groups if beyond alignment width
1461 int alWidth = alignment.getWidth();
1462 Vector groups = alignment.getGroups();
1465 for (int i = 0; i < groups.size(); i++)
1467 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1468 if (sg.getEndRes() > alWidth)
1470 sg.setEndRes(alWidth - 1);
1475 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1477 selectionGroup.setEndRes(alWidth - 1);
1480 resetAllColourSchemes();
1482 // AW alignment.adjustSequenceAnnotations();
1485 void resetAllColourSchemes()
1487 ColourSchemeI cs = globalColourScheme;
1490 if (cs instanceof ClustalxColourScheme)
1492 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1493 alignment.getWidth());
1496 cs.setConsensus(hconsensus);
1497 if (cs.conservationApplied())
1499 Alignment al = (Alignment) alignment;
1500 Conservation c = new Conservation("All",
1501 ResidueProperties.propHash, 3, al.getSequences(), 0,
1504 c.verdict(false, ConsPercGaps);
1506 cs.setConservation(c);
1510 int s, sSize = alignment.getGroups().size();
1511 for (s = 0; s < sSize; s++)
1513 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1514 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1516 ((ClustalxColourScheme) sg.cs).resetClustalX(
1517 sg.getSequences(hiddenRepSequences), sg.getWidth());
1519 sg.recalcConservation();
1523 boolean centreColumnLabels;
1525 public boolean getCentreColumnLabels()
1527 return centreColumnLabels;
1530 public void updateSequenceIdColours()
1532 Vector groups = alignment.getGroups();
1533 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1535 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1536 if (sg.idColour != null)
1538 Vector sqs = sg.getSequences(hiddenRepSequences);
1539 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1541 this.setSequenceColour((SequenceI) sqs.elementAt(s), sg.idColour);
1547 public boolean followHighlight = true;
1549 public boolean getFollowHighlight()
1551 return followHighlight;
1554 public boolean followSelection = true;
1557 * @return true if view selection should always follow the selections
1558 * broadcast by other selection sources
1560 public boolean getFollowSelection()
1562 return followSelection;
1565 private long sgrouphash = -1, colselhash = -1;
1568 * checks current SelectionGroup against record of last hash value, and
1571 * @return true if SelectionGroup changed since last call
1573 boolean isSelectionGroupChanged()
1575 int hc = (selectionGroup == null) ? -1 : selectionGroup.hashCode();
1576 if (hc != sgrouphash)
1585 * checks current colsel against record of last hash value, and updates
1588 * @return true if colsel changed since last call
1590 boolean isColSelChanged()
1592 int hc = (colSel == null) ? -1 : colSel.hashCode();
1593 if (hc != colselhash)
1600 public void sendSelection()
1602 jalview.structure.StructureSelectionManager
1603 .getStructureSelectionManager(applet).sendSelection(
1604 new SequenceGroup(getSelectionGroup()),
1605 new ColumnSelection(getColumnSelection()), this);
1612 * show non-conserved residues only
1614 public boolean showUnconserved = false;
1617 * when set, alignment should be reordered according to a newly opened tree
1619 public boolean sortByTree = false;
1622 * @return the showUnconserved
1624 public boolean getShowunconserved()
1626 return showUnconserved;
1630 * @param showNonconserved
1631 * the showUnconserved to set
1633 public void setShowunconserved(boolean displayNonconserved)
1635 this.showUnconserved = displayNonconserved;
1639 * should conservation rows be shown for groups
1641 boolean showGroupConservation = false;
1644 * should consensus rows be shown for groups
1646 boolean showGroupConsensus = false;
1649 * should consensus profile be rendered by default
1651 public boolean showSequenceLogo = false;
1653 * should consensus profile be rendered normalised to row height
1655 public boolean normaliseSequenceLogo = false;
1658 * should consensus histograms be rendered by default
1660 public boolean showConsensusHistogram = true;
1663 * @return the showConsensusProfile
1665 public boolean isShowSequenceLogo()
1667 return showSequenceLogo;
1671 * @param showSequenceLogo
1674 public void setShowSequenceLogo(boolean showSequenceLogo)
1676 if (showSequenceLogo != this.showSequenceLogo)
1678 // TODO: decouple settings setting from calculation when refactoring
1679 // annotation update method from alignframe to viewport
1680 this.showSequenceLogo = showSequenceLogo;
1681 if (consensusThread != null)
1683 consensusThread.updateAnnotation();
1686 this.showSequenceLogo = showSequenceLogo;
1690 * @param showConsensusHistogram
1691 * the showConsensusHistogram to set
1693 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1695 this.showConsensusHistogram = showConsensusHistogram;
1699 * @return the showGroupConservation
1701 public boolean isShowGroupConservation()
1703 return showGroupConservation;
1707 * @param showGroupConservation
1708 * the showGroupConservation to set
1710 public void setShowGroupConservation(boolean showGroupConservation)
1712 this.showGroupConservation = showGroupConservation;
1716 * @return the showGroupConsensus
1718 public boolean isShowGroupConsensus()
1720 return showGroupConsensus;
1724 * @param showGroupConsensus
1725 * the showGroupConsensus to set
1727 public void setShowGroupConsensus(boolean showGroupConsensus)
1729 this.showGroupConsensus = showGroupConsensus;
1734 * @return flag to indicate if the consensus histogram should be rendered by
1737 public boolean isShowConsensusHistogram()
1739 return this.showConsensusHistogram;
1743 * synthesize a column selection if none exists so it covers the given
1744 * selection group. if wholewidth is false, no column selection is made if the
1745 * selection group covers the whole alignment width.
1750 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
1754 && (sgs = sg.getStartRes()) >= 0
1755 && sg.getStartRes() <= (sge = sg.getEndRes())
1756 && (colSel == null || colSel.getSelected() == null || colSel
1757 .getSelected().size() == 0))
1759 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
1766 colSel = new ColumnSelection();
1768 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
1770 colSel.addElement(cspos);
1776 public boolean hasHiddenColumns()
1778 return hasHiddenColumns;
1781 public boolean isNormaliseSequenceLogo()
1783 return normaliseSequenceLogo;
1786 public void setNormaliseSequenceLogo(boolean state)
1788 normaliseSequenceLogo = state;
1791 public boolean isCalcInProgress()
1793 // TODO generalise to iterate over all calculators associated with av
1794 return updatingConsensus || updatingConservation || updatingStrucConsensus;
1797 public boolean isCalculationInProgress(
1798 AlignmentAnnotation alignmentAnnotation)
1800 if (!alignmentAnnotation.autoCalculated)
1802 if ((updatingConsensus && consensus==alignmentAnnotation)
1803 || (updatingConservation && (conservation==alignmentAnnotation || quality==alignmentAnnotation))
1804 // || (updatingStrucConsensus && strucConsensus==alignmentAnnotation)
1814 * @return true if alignment characters should be displayed
1816 public boolean isValidCharWidth()
1818 return validCharWidth;
1822 public Hashtable[] getSequenceConsensusHash()
1828 public Hashtable[] getRnaStructureConsensusHash()
1830 return null; // TODO: JAL-891 port to jvlite : refactor and introduce hStrucConsensus;