2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
26 import jalview.analysis.*;
\r
27 import jalview.bin.*;
\r
28 import jalview.datamodel.*;
\r
29 import jalview.schemes.*;
\r
31 public class AlignViewport
\r
39 boolean cursorMode = false;
\r
41 boolean showJVSuffix = true;
\r
42 boolean showText = true;
\r
43 boolean showColourText = false;
\r
44 boolean showBoxes = true;
\r
45 boolean wrapAlignment = false;
\r
46 boolean renderGaps = true;
\r
47 boolean showSequenceFeatures = false;
\r
48 boolean showAnnotation = true;
\r
49 boolean showConservation = true;
\r
50 boolean showQuality = true;
\r
51 boolean showConsensus = true;
\r
52 boolean upperCasebold = false;
\r
54 boolean colourAppliesToAllGroups = true;
\r
55 ColourSchemeI globalColourScheme = null;
\r
56 boolean conservationColourSelected = false;
\r
57 boolean abovePIDThreshold = false;
\r
59 SequenceGroup selectionGroup;
\r
65 Font font = new Font("SansSerif", Font.PLAIN, 10);
\r
66 boolean validCharWidth = true;
\r
67 AlignmentI alignment;
\r
69 ColumnSelection colSel = new ColumnSelection();
\r
74 NJTree currentTree = null;
\r
76 boolean scaleAboveWrapped = true;
\r
77 boolean scaleLeftWrapped = true;
\r
78 boolean scaleRightWrapped = true;
\r
80 // The following vector holds the features which are
\r
81 // currently visible, in the correct order or rendering
\r
82 public Hashtable featuresDisplayed;
\r
84 boolean hasHiddenColumns = false;
\r
85 boolean hasHiddenRows = false;
\r
86 boolean showHiddenMarkers = true;
\r
88 public Hashtable[] hconsensus;
\r
89 AlignmentAnnotation consensus;
\r
90 AlignmentAnnotation conservation;
\r
91 AlignmentAnnotation quality;
\r
93 boolean autocalculateConsensus = true;
\r
95 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
97 private java.beans.PropertyChangeSupport changeSupport = new java.beans.
\r
98 PropertyChangeSupport(this);
\r
100 boolean ignoreGapsInConsensusCalculation = false;
\r
102 jalview.bin.JalviewLite applet;
\r
104 Hashtable sequenceColours;
\r
106 boolean MAC = false;
\r
108 Stack historyList = new Stack();
\r
109 Stack redoList = new Stack();
\r
111 String sequenceSetID;
\r
113 Hashtable hiddenRepSequences;
\r
115 public AlignViewport(AlignmentI al, JalviewLite applet)
\r
117 this.applet = applet;
\r
120 this.endRes = al.getWidth() - 1;
\r
122 this.endSeq = al.getHeight() - 1;
\r
125 if (System.getProperty("os.name").startsWith("Mac"))
\r
130 if (applet != null)
\r
132 String param = applet.getParameter("showFullId");
\r
135 showJVSuffix = Boolean.valueOf(param).booleanValue();
\r
138 param = applet.getParameter("showAnnotation");
\r
141 showAnnotation = Boolean.valueOf(param).booleanValue();
\r
144 param = applet.getParameter("showConservation");
\r
147 showConservation = Boolean.valueOf(param).booleanValue();
\r
150 param = applet.getParameter("showQuality");
\r
153 showQuality = Boolean.valueOf(param).booleanValue();
\r
156 param = applet.getParameter("showConsensus");
\r
159 showConsensus = Boolean.valueOf(param).booleanValue();
\r
162 param = applet.getParameter("upperCase");
\r
165 if (param.equalsIgnoreCase("bold"))
\r
167 upperCasebold = true;
\r
173 if (applet != null)
\r
175 String colour = applet.getParameter("defaultColour");
\r
177 if (colour == null)
\r
179 colour = applet.getParameter("userDefinedColour");
\r
180 if (colour != null)
\r
182 colour = "User Defined";
\r
186 if (colour != null)
\r
188 globalColourScheme = ColourSchemeProperty.getColour(alignment, colour);
\r
189 if (globalColourScheme != null)
\r
191 globalColourScheme.setConsensus(hconsensus);
\r
195 if (applet.getParameter("userDefinedColour") != null)
\r
197 ( (UserColourScheme) globalColourScheme).parseAppletParameter(
\r
198 applet.getParameter("userDefinedColour"));
\r
201 if (hconsensus == null)
\r
203 if (!alignment.isNucleotide())
\r
205 conservation = new AlignmentAnnotation("Conservation",
\r
206 "Conservation of total alignment less than " +
\r
207 ConsPercGaps + "% gaps",
\r
208 new Annotation[1], 0f,
\r
210 AlignmentAnnotation.BAR_GRAPH);
\r
211 conservation.hasText = true;
\r
212 conservation.autoCalculated = true;
\r
214 if (showConservation)
\r
216 alignment.addAnnotation(conservation);
\r
221 quality = new AlignmentAnnotation("Quality",
\r
222 "Alignment Quality based on Blosum62 scores",
\r
226 AlignmentAnnotation.BAR_GRAPH);
\r
227 quality.hasText = true;
\r
228 quality.autoCalculated = true;
\r
230 alignment.addAnnotation(quality);
\r
234 consensus = new AlignmentAnnotation("Consensus", "PID",
\r
235 new Annotation[1], 0f, 100f,
\r
236 AlignmentAnnotation.BAR_GRAPH);
\r
237 consensus.hasText = true;
\r
238 consensus.autoCalculated = true;
\r
242 alignment.addAnnotation(consensus);
\r
248 public void showSequenceFeatures(boolean b)
\r
250 showSequenceFeatures = b;
\r
253 public boolean getShowSequenceFeatures()
\r
255 return showSequenceFeatures;
\r
258 class ConservationThread
\r
262 public ConservationThread(AlignmentPanel ap)
\r
271 updatingConservation = true;
\r
273 while (UPDATING_CONSERVATION)
\r
279 ap.paintAlignment(true);
\r
283 catch (Exception ex)
\r
285 ex.printStackTrace();
\r
289 UPDATING_CONSERVATION = true;
\r
291 int alWidth = alignment.getWidth();
\r
297 Conservation cons = new jalview.analysis.Conservation("All",
\r
298 jalview.schemes.ResidueProperties.propHash, 3,
\r
299 alignment.getSequences(), 0, alWidth - 1);
\r
302 cons.verdict(false, ConsPercGaps);
\r
304 if (quality != null)
\r
306 cons.findQuality();
\r
309 char[] sequence = cons.getConsSequence().getSequence();
\r
319 maxR = 1.0f - minR;
\r
320 maxG = 0.9f - minG;
\r
321 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
330 conservation.annotations = new Annotation[alWidth];
\r
332 if (quality != null)
\r
334 quality.graphMax = cons.qualityRange[1].floatValue();
\r
335 quality.annotations = new Annotation[alWidth];
\r
336 qmin = cons.qualityRange[0].floatValue();
\r
337 qmax = cons.qualityRange[1].floatValue();
\r
340 for (int i = 0; i < alWidth; i++)
\r
346 if (Character.isDigit(c))
\r
348 value = (int) (c - '0');
\r
359 float vprop = value - min;
\r
361 conservation.annotations[i] =
\r
362 new Annotation(String.valueOf(c),
\r
363 String.valueOf(value), ' ', value,
\r
364 new Color(minR + (maxR * vprop),
\r
365 minG + (maxG * vprop),
\r
366 minB + (maxB * vprop)));
\r
369 if (quality != null)
\r
371 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
372 vprop = value - qmin;
\r
374 quality.annotations[i] = new Annotation(" ", String.valueOf(value),
\r
377 new Color(minR + (maxR * vprop),
\r
378 minG + (maxG * vprop),
\r
379 minB + (maxB * vprop)));
\r
383 catch (OutOfMemoryError error)
\r
385 System.out.println("Out of memory calculating conservation!!");
\r
386 conservation = null;
\r
391 UPDATING_CONSERVATION = false;
\r
392 updatingConservation = false;
\r
396 ap.paintAlignment(true);
\r
402 ConservationThread conservationThread;
\r
404 ConsensusThread consensusThread;
\r
406 boolean consUpdateNeeded = false;
\r
408 static boolean UPDATING_CONSENSUS = false;
\r
410 static boolean UPDATING_CONSERVATION = false;
\r
412 boolean updatingConsensus = false;
\r
414 boolean updatingConservation = false;
\r
419 public void updateConservation(final AlignmentPanel ap)
\r
421 if (alignment.isNucleotide() || conservation == null)
\r
426 conservationThread = new ConservationThread(ap);
\r
427 conservationThread.start();
\r
433 public void updateConsensus(final AlignmentPanel ap)
\r
435 consensusThread = new ConsensusThread(ap);
\r
436 consensusThread.start();
\r
439 class ConsensusThread
\r
443 public ConsensusThread(AlignmentPanel ap)
\r
450 updatingConsensus = true;
\r
451 while (UPDATING_CONSENSUS)
\r
457 ap.paintAlignment(true);
\r
462 catch (Exception ex)
\r
464 ex.printStackTrace();
\r
468 UPDATING_CONSENSUS = true;
\r
472 int aWidth = alignment.getWidth();
\r
478 consensus.annotations = null;
\r
479 consensus.annotations = new Annotation[aWidth];
\r
481 hconsensus = new Hashtable[aWidth];
\r
482 AAFrequency.calculate(alignment.getSequencesArray(),
\r
484 alignment.getWidth(),
\r
487 for (int i = 0; i < aWidth; i++)
\r
490 if (ignoreGapsInConsensusCalculation)
\r
492 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
\r
497 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
\r
501 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
\r
502 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
\r
504 if (maxRes.length() > 1)
\r
506 mouseOver = "[" + maxRes + "] ";
\r
510 mouseOver += ( (int) value + "%");
\r
511 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
\r
515 if (globalColourScheme != null)
\r
517 globalColourScheme.setConsensus(hconsensus);
\r
521 catch (OutOfMemoryError error)
\r
523 alignment.deleteAnnotation(consensus);
\r
527 System.out.println("Out of memory calculating consensus!!");
\r
530 UPDATING_CONSENSUS = false;
\r
531 updatingConsensus = false;
\r
535 ap.paintAlignment(true);
\r
541 * get the consensus sequence as displayed under the PID consensus annotation row.
\r
542 * @return consensus sequence as a new sequence object
\r
545 * get the consensus sequence as displayed under the PID consensus annotation row.
\r
546 * @return consensus sequence as a new sequence object
\r
548 public SequenceI getConsensusSeq()
\r
550 if (consensus == null)
\r
554 StringBuffer seqs = new StringBuffer();
\r
555 for (int i = 0; i < consensus.annotations.length; i++)
\r
557 if (consensus.annotations[i] != null)
\r
559 if (consensus.annotations[i].description.charAt(0) == '[')
\r
561 seqs.append(consensus.annotations[i].description.charAt(1));
\r
565 seqs.append(consensus.annotations[i].displayCharacter);
\r
569 SequenceI sq = new Sequence("Consensus", seqs.toString());
\r
570 sq.setDescription("Percentage Identity Consensus " +
\r
571 ( (ignoreGapsInConsensusCalculation) ? " without gaps" :
\r
576 public SequenceGroup getSelectionGroup()
\r
578 return selectionGroup;
\r
581 public void setSelectionGroup(SequenceGroup sg)
\r
583 selectionGroup = sg;
\r
586 public boolean getConservationSelected()
\r
588 return conservationColourSelected;
\r
591 public void setConservationSelected(boolean b)
\r
593 conservationColourSelected = b;
\r
596 public boolean getAbovePIDThreshold()
\r
598 return abovePIDThreshold;
\r
601 public void setAbovePIDThreshold(boolean b)
\r
603 abovePIDThreshold = b;
\r
606 public int getStartRes()
\r
611 public int getEndRes()
\r
616 public int getStartSeq()
\r
621 public void setGlobalColourScheme(ColourSchemeI cs)
\r
623 globalColourScheme = cs;
\r
626 public ColourSchemeI getGlobalColourScheme()
\r
628 return globalColourScheme;
\r
631 public void setStartRes(int res)
\r
633 this.startRes = res;
\r
636 public void setStartSeq(int seq)
\r
638 this.startSeq = seq;
\r
641 public void setEndRes(int res)
\r
643 if (res > alignment.getWidth() - 1)
\r
645 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
646 res = alignment.getWidth() - 1;
\r
655 public void setEndSeq(int seq)
\r
657 if (seq > alignment.getHeight())
\r
659 seq = alignment.getHeight();
\r
668 public int getEndSeq()
\r
673 java.awt.Frame nullFrame;
\r
674 public void setFont(Font f)
\r
677 if (nullFrame == null)
\r
679 nullFrame = new java.awt.Frame();
\r
680 nullFrame.addNotify();
\r
683 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
\r
684 setCharHeight(fm.getHeight());
\r
685 charWidth = fm.charWidth('M');
\r
689 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
\r
690 fm = nullFrame.getGraphics().getFontMetrics(f2);
\r
691 charWidth = fm.stringWidth("MMMMMMMMMMM") / 10;
\r
695 public Font getFont()
\r
700 public int getCharWidth()
\r
705 public void setCharHeight(int h)
\r
707 this.charHeight = h;
\r
710 public int getCharHeight()
\r
715 public void setWrappedWidth(int w)
\r
717 this.wrappedWidth = w;
\r
720 public int getwrappedWidth()
\r
722 return wrappedWidth;
\r
725 public AlignmentI getAlignment()
\r
730 public void setAlignment(AlignmentI align)
\r
732 this.alignment = align;
\r
735 public void setWrapAlignment(boolean state)
\r
737 wrapAlignment = state;
\r
740 public void setShowText(boolean state)
\r
745 public void setRenderGaps(boolean state)
\r
747 renderGaps = state;
\r
750 public boolean getColourText()
\r
752 return showColourText;
\r
755 public void setColourText(boolean state)
\r
757 showColourText = state;
\r
760 public void setShowBoxes(boolean state)
\r
765 public boolean getWrapAlignment()
\r
767 return wrapAlignment;
\r
770 public boolean getShowText()
\r
775 public boolean getShowBoxes()
\r
780 public char getGapCharacter()
\r
782 return getAlignment().getGapCharacter();
\r
785 public void setGapCharacter(char gap)
\r
787 if (getAlignment() != null)
\r
789 getAlignment().setGapCharacter(gap);
\r
793 public void setThreshold(int thresh)
\r
795 threshold = thresh;
\r
798 public int getThreshold()
\r
803 public void setIncrement(int inc)
\r
808 public int getIncrement()
\r
813 public void setHiddenColumns(ColumnSelection colsel)
\r
815 this.colSel = colsel;
\r
816 if (colSel.getHiddenColumns() != null)
\r
818 hasHiddenColumns = true;
\r
822 public ColumnSelection getColumnSelection()
\r
827 public void resetSeqLimits(int height)
\r
829 setEndSeq(height / getCharHeight());
\r
832 public void setCurrentTree(NJTree tree)
\r
834 currentTree = tree;
\r
837 public NJTree getCurrentTree()
\r
839 return currentTree;
\r
842 public void setColourAppliesToAllGroups(boolean b)
\r
844 colourAppliesToAllGroups = b;
\r
847 public boolean getColourAppliesToAllGroups()
\r
849 return colourAppliesToAllGroups;
\r
852 public boolean getShowJVSuffix()
\r
854 return showJVSuffix;
\r
857 public void setShowJVSuffix(boolean b)
\r
862 public boolean getShowAnnotation()
\r
864 return showAnnotation;
\r
867 public void setShowAnnotation(boolean b)
\r
869 showAnnotation = b;
\r
872 public boolean getScaleAboveWrapped()
\r
874 return scaleAboveWrapped;
\r
877 public boolean getScaleLeftWrapped()
\r
879 return scaleLeftWrapped;
\r
882 public boolean getScaleRightWrapped()
\r
884 return scaleRightWrapped;
\r
887 public void setScaleAboveWrapped(boolean b)
\r
889 scaleAboveWrapped = b;
\r
892 public void setScaleLeftWrapped(boolean b)
\r
894 scaleLeftWrapped = b;
\r
897 public void setScaleRightWrapped(boolean b)
\r
899 scaleRightWrapped = b;
\r
902 public void setIgnoreGapsConsensus(boolean b)
\r
904 ignoreGapsInConsensusCalculation = b;
\r
905 updateConsensus(null);
\r
906 if (globalColourScheme != null)
\r
908 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
\r
909 ignoreGapsInConsensusCalculation);
\r
915 * Property change listener for changes in alignment
\r
917 * @param listener DOCUMENT ME!
\r
919 public void addPropertyChangeListener(
\r
920 java.beans.PropertyChangeListener listener)
\r
922 changeSupport.addPropertyChangeListener(listener);
\r
928 * @param listener DOCUMENT ME!
\r
930 public void removePropertyChangeListener(
\r
931 java.beans.PropertyChangeListener listener)
\r
933 changeSupport.removePropertyChangeListener(listener);
\r
937 * Property change listener for changes in alignment
\r
939 * @param prop DOCUMENT ME!
\r
940 * @param oldvalue DOCUMENT ME!
\r
941 * @param newvalue DOCUMENT ME!
\r
943 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
945 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r
948 public boolean getIgnoreGapsConsensus()
\r
950 return ignoreGapsInConsensusCalculation;
\r
953 public void hideSelectedColumns()
\r
955 if (colSel.size() < 1)
\r
960 colSel.hideSelectedColumns();
\r
961 setSelectionGroup(null);
\r
963 hasHiddenColumns = true;
\r
966 public void invertColumnSelection()
\r
968 for (int i = 0; i < alignment.getWidth(); i++)
\r
970 if (colSel.contains(i))
\r
972 colSel.removeElement(i);
\r
976 if (!hasHiddenColumns || colSel.isVisible(i))
\r
978 colSel.addElement(i);
\r
984 public void hideColumns(int start, int end)
\r
988 colSel.hideColumns(start);
\r
992 colSel.hideColumns(start, end);
\r
995 hasHiddenColumns = true;
\r
998 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
\r
1000 int sSize = sg.getSize();
\r
1006 if (hiddenRepSequences == null)
\r
1008 hiddenRepSequences = new Hashtable();
\r
1011 hiddenRepSequences.put(repSequence, sg);
\r
1013 //Hide all sequences except the repSequence
\r
1014 SequenceI[] seqs = new SequenceI[sSize - 1];
\r
1016 for (int i = 0; i < sSize; i++)
\r
1018 if (sg.getSequenceAt(i) != repSequence)
\r
1020 if (index == sSize - 1)
\r
1025 seqs[index++] = sg.getSequenceAt(i);
\r
1029 hideSequence(seqs);
\r
1033 public void hideAllSelectedSeqs()
\r
1035 if (selectionGroup == null || selectionGroup.getSize()<1)
\r
1040 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
\r
1042 hideSequence(seqs);
\r
1044 setSelectionGroup(null);
\r
1047 public void hideSequence(SequenceI[] seq)
\r
1051 for (int i = 0; i < seq.length; i++)
\r
1053 alignment.getHiddenSequences().hideSequence(seq[i]);
\r
1056 hasHiddenRows = true;
\r
1057 firePropertyChange("alignment", null, alignment.getSequences());
\r
1061 public void showColumn(int col)
\r
1063 colSel.revealHiddenColumns(col);
\r
1064 if (colSel.getHiddenColumns() == null)
\r
1066 hasHiddenColumns = false;
\r
1070 public void showAllHiddenColumns()
\r
1072 colSel.revealAllHiddenColumns();
\r
1073 hasHiddenColumns = false;
\r
1076 public void showAllHiddenSeqs()
\r
1078 if (alignment.getHiddenSequences().getSize() > 0)
\r
1080 if (selectionGroup == null)
\r
1082 selectionGroup = new SequenceGroup();
\r
1083 selectionGroup.setEndRes(alignment.getWidth() - 1);
\r
1085 Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
\r
1086 for (int t = 0; t < tmp.size(); t++)
\r
1088 selectionGroup.addSequence(
\r
1089 (SequenceI) tmp.elementAt(t), false
\r
1092 firePropertyChange("alignment", null, alignment.getSequences());
\r
1093 hasHiddenRows = false;
\r
1094 hiddenRepSequences = null;
\r
1098 public int adjustForHiddenSeqs(int alignmentIndex)
\r
1100 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
\r
1104 * This method returns the a new SequenceI [] with
\r
1105 * the selection sequence and start and end points adjusted
\r
1106 * @return String[]
\r
1108 public SequenceI[] getSelectionAsNewSequence()
\r
1110 SequenceI[] sequences;
\r
1112 if (selectionGroup == null)
\r
1114 sequences = alignment.getSequencesArray();
\r
1118 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
\r
1125 * This method returns the visible alignment as text, as
\r
1126 * seen on the GUI, ie if columns are hidden they will not
\r
1127 * be returned in the result.
\r
1128 * Use this for calculating trees, PCA, redundancy etc on views
\r
1129 * which contain hidden columns.
\r
1130 * @return String[]
\r
1132 public jalview.datamodel.CigarArray getViewAsCigars(boolean
\r
1133 selectedRegionOnly)
\r
1135 CigarArray selection = null;
\r
1136 SequenceI[] seqs = null;
\r
1138 int start = 0, end = 0;
\r
1139 if (selectedRegionOnly && selectionGroup != null)
\r
1141 iSize = selectionGroup.getSize();
\r
1142 seqs = selectionGroup.getSequencesInOrder(alignment);
\r
1143 start = selectionGroup.getStartRes();
\r
1144 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
\r
1148 iSize = alignment.getHeight();
\r
1149 seqs = alignment.getSequencesArray();
\r
1150 end = alignment.getWidth() - 1;
\r
1152 SeqCigar[] selseqs = new SeqCigar[iSize];
\r
1153 for (i = 0; i < iSize; i++)
\r
1155 selseqs[i] = new SeqCigar(seqs[i], start, end);
\r
1157 selection = new CigarArray(selseqs);
\r
1158 // now construct the CigarArray operations
\r
1159 if (hasHiddenColumns)
\r
1161 Vector regions = colSel.getHiddenColumns();
\r
1163 int hideStart, hideEnd;
\r
1165 for (int j = 0; last < end & j < regions.size(); j++)
\r
1167 region = (int[]) regions.elementAt(j);
\r
1168 hideStart = region[0];
\r
1169 hideEnd = region[1];
\r
1170 // edit hidden regions to selection range
\r
1171 if (hideStart < last)
\r
1173 if (hideEnd > last)
\r
1183 if (hideStart > end)
\r
1188 if (hideEnd > end)
\r
1193 if (hideStart > hideEnd)
\r
1198 * form operations...
\r
1200 if (last < hideStart)
\r
1202 selection.addOperation(CigarArray.M, hideStart - last);
\r
1204 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
\r
1205 last = hideEnd + 1;
\r
1207 // Final match if necessary.
\r
1210 selection.addOperation(CigarArray.M, end - last + 1);
\r
1215 selection.addOperation(CigarArray.M, end - start + 1);
\r
1221 * return a compact representation of the current alignment selection to
\r
1222 * pass to an analysis function
\r
1223 * @param selectedOnly boolean true to just return the selected view
\r
1224 * @return AlignmentView
\r
1226 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
\r
1229 // this is here because the AlignmentView constructor modifies the CigarArray
\r
1230 // object. Refactoring of Cigar and alignment view representation should
\r
1231 // be done to remove redundancy.
\r
1232 CigarArray aligview = getViewAsCigars(selectedOnly);
\r
1233 if (aligview != null)
\r
1235 return new AlignmentView(aligview,
\r
1236 (selectedOnly && selectionGroup != null) ?
\r
1237 selectionGroup.getStartRes() : 0);
\r
1243 * This method returns the visible alignment as text, as
\r
1244 * seen on the GUI, ie if columns are hidden they will not
\r
1245 * be returned in the result.
\r
1246 * Use this for calculating trees, PCA, redundancy etc on views
\r
1247 * which contain hidden columns.
\r
1248 * @return String[]
\r
1250 public String[] getViewAsString(boolean selectedRegionOnly)
\r
1252 String[] selection = null;
\r
1253 SequenceI[] seqs = null;
\r
1255 int start = 0, end = 0;
\r
1256 if (selectedRegionOnly && selectionGroup != null)
\r
1258 iSize = selectionGroup.getSize();
\r
1259 seqs = selectionGroup.getSequencesInOrder(alignment);
\r
1260 start = selectionGroup.getStartRes();
\r
1261 end = selectionGroup.getEndRes() + 1;
\r
1265 iSize = alignment.getHeight();
\r
1266 seqs = alignment.getSequencesArray();
\r
1267 end = alignment.getWidth();
\r
1270 selection = new String[iSize];
\r
1272 for (i = 0; i < iSize; i++)
\r
1274 if (hasHiddenColumns)
\r
1276 StringBuffer visibleSeq = new StringBuffer();
\r
1277 Vector regions = colSel.getHiddenColumns();
\r
1279 int blockStart = start, blockEnd = end;
\r
1281 int hideStart, hideEnd;
\r
1283 for (int j = 0; j < regions.size(); j++)
\r
1285 region = (int[]) regions.elementAt(j);
\r
1286 hideStart = region[0];
\r
1287 hideEnd = region[1];
\r
1289 if (hideStart < start)
\r
1294 blockStart = Math.min(blockStart, hideEnd + 1);
\r
1295 blockEnd = Math.min(blockEnd, hideStart);
\r
1297 if (blockStart > blockEnd)
\r
1302 visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
\r
1304 blockStart = hideEnd + 1;
\r
1308 if (end > blockStart)
\r
1310 visibleSeq.append(seqs[i].getSequence(blockStart, end));
\r
1313 selection[i] = visibleSeq.toString();
\r
1317 selection[i] = seqs[i].getSequenceAsString(start, end);
\r
1324 public boolean getShowHiddenMarkers()
\r
1326 return showHiddenMarkers;
\r
1329 public void setShowHiddenMarkers(boolean show)
\r
1331 showHiddenMarkers = show;
\r
1334 public Color getSequenceColour(SequenceI seq)
\r
1336 if (sequenceColours == null || !sequenceColours.containsKey(seq))
\r
1338 return Color.white;
\r
1342 return (Color) sequenceColours.get(seq);
\r
1346 public void setSequenceColour(SequenceI seq, Color col)
\r
1348 if (sequenceColours == null)
\r
1350 sequenceColours = new Hashtable();
\r
1355 sequenceColours.remove(seq);
\r
1359 sequenceColours.put(seq, col);
\r
1363 public String getSequenceSetId()
\r
1365 if (sequenceSetID == null)
\r
1367 sequenceSetID = alignment.hashCode() + "";
\r
1370 return sequenceSetID;
\r
1373 public void alignmentChanged(AlignmentPanel ap)
\r
1375 alignment.padGaps();
\r
1377 if (hconsensus != null && autocalculateConsensus)
\r
1379 updateConsensus(ap);
\r
1380 updateConservation(ap);
\r
1383 //Reset endRes of groups if beyond alignment width
\r
1384 int alWidth = alignment.getWidth();
\r
1385 Vector groups = alignment.getGroups();
\r
1386 if (groups != null)
\r
1388 for (int i = 0; i < groups.size(); i++)
\r
1390 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
\r
1391 if (sg.getEndRes() > alWidth)
\r
1393 sg.setEndRes(alWidth - 1);
\r
1398 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
\r
1400 selectionGroup.setEndRes(alWidth - 1);
\r
1403 resetAllColourSchemes();
\r
1405 //AW alignment.adjustSequenceAnnotations();
\r
1408 void resetAllColourSchemes()
\r
1410 ColourSchemeI cs = globalColourScheme;
\r
1413 if (cs instanceof ClustalxColourScheme)
\r
1415 ( (ClustalxColourScheme) cs).
\r
1416 resetClustalX(alignment.getSequences(),
\r
1417 alignment.getWidth());
\r
1420 cs.setConsensus(hconsensus);
\r
1421 if (cs.conservationApplied())
\r
1423 Alignment al = (Alignment) alignment;
\r
1424 Conservation c = new Conservation("All",
\r
1425 ResidueProperties.propHash, 3,
\r
1426 al.getSequences(), 0,
\r
1427 al.getWidth() - 1);
\r
1429 c.verdict(false, ConsPercGaps);
\r
1431 cs.setConservation(c);
\r
1435 int s, sSize = alignment.getGroups().size();
\r
1436 for (s = 0; s < sSize; s++)
\r
1438 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
\r
1439 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
\r
1441 ( (ClustalxColourScheme) sg.cs).resetClustalX(
\r
1442 sg.getSequences(hiddenRepSequences), sg.getWidth());
\r
1444 sg.recalcConservation();
\r