2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
40 boolean cursorMode = false;
\r
42 boolean showJVSuffix = true;
\r
43 boolean showText = true;
\r
44 boolean showColourText = false;
\r
45 boolean showBoxes = true;
\r
46 boolean wrapAlignment = false;
\r
47 boolean renderGaps = true;
\r
48 boolean showSequenceFeatures = false;
\r
49 boolean showAnnotation = true;
\r
50 boolean showConservation = true;
\r
51 boolean showQuality = true;
\r
52 boolean showConsensus = true;
\r
53 boolean upperCasebold = false;
\r
55 boolean colourAppliesToAllGroups = true;
\r
56 ColourSchemeI globalColourScheme = null;
\r
57 boolean conservationColourSelected = false;
\r
58 boolean abovePIDThreshold = false;
\r
60 SequenceGroup selectionGroup;
\r
66 Font font = new Font("SansSerif", Font.PLAIN, 10);
\r
67 boolean validCharWidth = true;
\r
68 AlignmentI alignment;
\r
70 ColumnSelection colSel = new ColumnSelection();
\r
75 NJTree currentTree = null;
\r
77 boolean scaleAboveWrapped = true;
\r
78 boolean scaleLeftWrapped = true;
\r
79 boolean scaleRightWrapped = true;
\r
81 // The following vector holds the features which are
\r
82 // currently visible, in the correct order or rendering
\r
83 public Hashtable featuresDisplayed;
\r
85 boolean hasHiddenColumns = false;
\r
86 boolean hasHiddenRows = false;
\r
87 boolean showHiddenMarkers = true;
\r
90 public Hashtable [] hconsensus;
\r
91 AlignmentAnnotation consensus;
\r
92 AlignmentAnnotation conservation;
\r
93 AlignmentAnnotation quality;
\r
95 boolean autocalculateConsensus = true;
\r
97 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
\r
99 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
\r
101 boolean ignoreGapsInConsensusCalculation = false;
\r
103 jalview.bin.JalviewLite applet;
\r
105 Hashtable sequenceColours;
\r
107 boolean MAC = false;
\r
109 Stack historyList = new Stack();
\r
110 Stack redoList = new Stack();
\r
112 String sequenceSetID;
\r
114 Hashtable hiddenRepSequences;
\r
116 public AlignViewport(AlignmentI al, JalviewLite applet)
\r
118 this.applet = applet;
\r
121 this.endRes = al.getWidth() - 1;
\r
123 this.endSeq = al.getHeight() - 1;
\r
126 if(System.getProperty("os.name").startsWith("Mac"))
\r
129 if (applet != null)
\r
131 String param = applet.getParameter("showFullId");
\r
134 showJVSuffix = Boolean.valueOf(param).booleanValue();
\r
137 param = applet.getParameter("showAnnotation");
\r
140 showAnnotation = Boolean.valueOf(param).booleanValue();
\r
143 param = applet.getParameter("showConservation");
\r
146 showConservation = Boolean.valueOf(param).booleanValue();
\r
149 param = applet.getParameter("showQuality");
\r
152 showQuality = Boolean.valueOf(param).booleanValue();
\r
155 param = applet.getParameter("showConsensus");
\r
158 showConsensus = Boolean.valueOf(param).booleanValue();
\r
161 param = applet.getParameter("upperCase");
\r
164 if(param.equalsIgnoreCase("bold"))
\r
165 upperCasebold = true;
\r
170 if (applet != null)
\r
172 String colour = applet.getParameter("defaultColour");
\r
176 colour = applet.getParameter("userDefinedColour");
\r
178 colour = "User Defined";
\r
183 globalColourScheme = ColourSchemeProperty.getColour(alignment, colour);
\r
184 if (globalColourScheme != null)
\r
186 globalColourScheme.setConsensus(hconsensus);
\r
190 if(applet.getParameter("userDefinedColour")!=null)
\r
192 ((UserColourScheme)globalColourScheme).parseAppletParameter(
\r
193 applet.getParameter("userDefinedColour"));
\r
196 if(hconsensus==null)
\r
198 if(!alignment.isNucleotide())
\r
200 conservation = new AlignmentAnnotation("Conservation",
\r
201 "Conservation of total alignment less than " +
\r
202 ConsPercGaps + "% gaps",
\r
203 new Annotation[1], 0f,
\r
205 AlignmentAnnotation.BAR_GRAPH);
\r
206 conservation.hasText = true;
\r
207 conservation.autoCalculated = true;
\r
211 if (showConservation)
\r
213 alignment.addAnnotation(conservation);
\r
218 quality = new AlignmentAnnotation("Quality",
\r
219 "Alignment Quality based on Blosum62 scores",
\r
223 AlignmentAnnotation.BAR_GRAPH);
\r
224 quality.hasText = true;
\r
225 quality.autoCalculated = true;
\r
227 alignment.addAnnotation(quality);
\r
231 consensus = new AlignmentAnnotation("Consensus", "PID",
\r
232 new Annotation[1], 0f, 100f,
\r
233 AlignmentAnnotation.BAR_GRAPH);
\r
234 consensus.hasText = true;
\r
235 consensus.autoCalculated = true;
\r
239 alignment.addAnnotation(consensus);
\r
245 public void showSequenceFeatures(boolean b)
\r
247 showSequenceFeatures = b;
\r
250 public boolean getShowSequenceFeatures()
\r
252 return showSequenceFeatures;
\r
256 class ConservationThread extends Thread
\r
259 public ConservationThread(AlignmentPanel ap)
\r
268 updatingConservation = true;
\r
270 while (UPDATING_CONSERVATION)
\r
280 catch (Exception ex)
\r
282 ex.printStackTrace();
\r
286 UPDATING_CONSERVATION = true;
\r
289 int alWidth = alignment.getWidth();
\r
293 Conservation cons = new jalview.analysis.Conservation("All",
\r
294 jalview.schemes.ResidueProperties.propHash, 3,
\r
295 alignment.getSequences(), 0, alWidth -1);
\r
298 cons.verdict(false, ConsPercGaps);
\r
302 cons.findQuality();
\r
305 char [] sequence = cons.getConsSequence().getSequence();
\r
315 maxR = 1.0f - minR;
\r
316 maxG = 0.9f - minG;
\r
317 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
326 conservation.annotations = new Annotation[alWidth];
\r
330 quality.graphMax = cons.qualityRange[1].floatValue();
\r
331 quality.annotations = new Annotation[alWidth];
\r
332 qmin = cons.qualityRange[0].floatValue();
\r
333 qmax = cons.qualityRange[1].floatValue();
\r
336 for (int i = 0; i < alWidth; i++)
\r
342 if (Character.isDigit(c))
\r
343 value = (int) (c - '0');
\r
349 float vprop = value - min;
\r
351 conservation.annotations[i] =
\r
352 new Annotation(String.valueOf(c),
\r
353 String.valueOf(value), ' ', value,
\r
354 new Color(minR + (maxR * vprop),
\r
355 minG + (maxG * vprop),
\r
356 minB + (maxB * vprop)));
\r
361 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
362 vprop = value - qmin;
\r
364 quality.annotations[i] = new Annotation(" ", String.valueOf(value), ' ',
\r
366 new Color(minR + (maxR * vprop),
\r
367 minG + (maxG * vprop),
\r
368 minB + (maxB * vprop)));
\r
372 catch (OutOfMemoryError error)
\r
374 System.out.println("Out of memory calculating conservation!!");
\r
375 conservation = null;
\r
380 UPDATING_CONSERVATION = false;
\r
381 updatingConservation = false;
\r
392 ConservationThread conservationThread;
\r
394 ConsensusThread consensusThread;
\r
396 boolean consUpdateNeeded = false;
\r
398 static boolean UPDATING_CONSENSUS = false;
\r
400 static boolean UPDATING_CONSERVATION = false;
\r
402 boolean updatingConsensus = false;
\r
404 boolean updatingConservation = false;
\r
409 public void updateConservation(final AlignmentPanel ap)
\r
411 if (alignment.isNucleotide() || conservation==null)
\r
414 conservationThread = new ConservationThread(ap);
\r
415 conservationThread.start();
\r
421 public void updateConsensus(final AlignmentPanel ap)
\r
423 consensusThread = new ConsensusThread(ap);
\r
424 consensusThread.start();
\r
428 class ConsensusThread extends Thread
\r
431 public ConsensusThread(AlignmentPanel ap)
\r
437 updatingConsensus = true;
\r
438 while (UPDATING_CONSENSUS)
\r
449 catch (Exception ex)
\r
451 ex.printStackTrace();
\r
456 UPDATING_CONSENSUS = true;
\r
460 int aWidth = alignment.getWidth();
\r
464 consensus.annotations = null;
\r
465 consensus.annotations = new Annotation[aWidth];
\r
468 hconsensus = new Hashtable[aWidth];
\r
469 AAFrequency.calculate(alignment.getSequencesArray(),
\r
471 alignment.getWidth(),
\r
474 for (int i = 0; i < aWidth; i++)
\r
477 if (ignoreGapsInConsensusCalculation)
\r
478 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
\r
481 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
\r
484 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
\r
485 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
\r
487 if (maxRes.length() > 1)
\r
489 mouseOver = "[" + maxRes + "] ";
\r
493 mouseOver += ( (int) value + "%");
\r
494 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
498 if (globalColourScheme != null)
\r
499 globalColourScheme.setConsensus(hconsensus);
\r
502 catch (OutOfMemoryError error)
\r
504 alignment.deleteAnnotation(consensus);
\r
508 System.out.println("Out of memory calculating consensus!!");
\r
511 UPDATING_CONSENSUS = false;
\r
512 updatingConsensus = false;
\r
522 * get the consensus sequence as displayed under the PID consensus annotation row.
\r
523 * @return consensus sequence as a new sequence object
\r
526 * get the consensus sequence as displayed under the PID consensus annotation row.
\r
527 * @return consensus sequence as a new sequence object
\r
529 public SequenceI getConsensusSeq()
\r
531 if (consensus==null)
\r
533 StringBuffer seqs=new StringBuffer();
\r
534 for (int i=0; i<consensus.annotations.length; i++) {
\r
535 if (consensus.annotations[i]!=null) {
\r
536 if (consensus.annotations[i].description.charAt(0) == '[')
\r
537 seqs.append(consensus.annotations[i].description.charAt(1));
\r
539 seqs.append(consensus.annotations[i].displayCharacter);
\r
542 SequenceI sq = new Sequence("Consensus", seqs.toString());
\r
543 sq.setDescription("Percentage Identity Consensus "+((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
\r
546 public SequenceGroup getSelectionGroup()
\r
548 return selectionGroup;
\r
551 public void setSelectionGroup(SequenceGroup sg)
\r
553 selectionGroup = sg;
\r
556 public boolean getConservationSelected()
\r
558 return conservationColourSelected;
\r
561 public void setConservationSelected(boolean b)
\r
563 conservationColourSelected = b;
\r
566 public boolean getAbovePIDThreshold()
\r
568 return abovePIDThreshold;
\r
571 public void setAbovePIDThreshold(boolean b)
\r
573 abovePIDThreshold = b;
\r
576 public int getStartRes()
\r
581 public int getEndRes()
\r
586 public int getStartSeq()
\r
591 public void setGlobalColourScheme(ColourSchemeI cs)
\r
593 globalColourScheme = cs;
\r
596 public ColourSchemeI getGlobalColourScheme()
\r
598 return globalColourScheme;
\r
601 public void setStartRes(int res)
\r
603 this.startRes = res;
\r
606 public void setStartSeq(int seq)
\r
608 this.startSeq = seq;
\r
611 public void setEndRes(int res)
\r
613 if (res > alignment.getWidth() - 1)
\r
615 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
616 res = alignment.getWidth() - 1;
\r
625 public void setEndSeq(int seq)
\r
627 if (seq > alignment.getHeight())
\r
629 seq = alignment.getHeight();
\r
638 public int getEndSeq()
\r
643 java.awt.Frame nullFrame;
\r
644 public void setFont(Font f)
\r
647 if(nullFrame == null)
\r
649 nullFrame = new java.awt.Frame();
\r
650 nullFrame.addNotify();
\r
653 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
\r
654 setCharHeight(fm.getHeight());
\r
655 charWidth = fm.charWidth('M');
\r
659 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
\r
660 fm = nullFrame.getGraphics().getFontMetrics(f2);
\r
661 charWidth = fm.stringWidth("MMMMMMMMMMM") / 10;
\r
665 public Font getFont()
\r
670 public int getCharWidth()
\r
675 public void setCharHeight(int h)
\r
677 this.charHeight = h;
\r
680 public int getCharHeight()
\r
685 public void setWrappedWidth(int w)
\r
687 this.wrappedWidth = w;
\r
690 public int getwrappedWidth()
\r
692 return wrappedWidth;
\r
695 public AlignmentI getAlignment()
\r
700 public void setAlignment(AlignmentI align)
\r
702 this.alignment = align;
\r
705 public void setWrapAlignment(boolean state)
\r
707 wrapAlignment = state;
\r
710 public void setShowText(boolean state)
\r
715 public void setRenderGaps(boolean state)
\r
717 renderGaps = state;
\r
720 public boolean getColourText()
\r
722 return showColourText;
\r
725 public void setColourText(boolean state)
\r
727 showColourText = state;
\r
730 public void setShowBoxes(boolean state)
\r
735 public boolean getWrapAlignment()
\r
737 return wrapAlignment;
\r
740 public boolean getShowText()
\r
745 public boolean getShowBoxes()
\r
750 public char getGapCharacter()
\r
752 return getAlignment().getGapCharacter();
\r
755 public void setGapCharacter(char gap)
\r
757 if (getAlignment() != null)
\r
759 getAlignment().setGapCharacter(gap);
\r
763 public void setThreshold(int thresh)
\r
765 threshold = thresh;
\r
768 public int getThreshold()
\r
773 public void setIncrement(int inc)
\r
778 public int getIncrement()
\r
783 public void setHiddenColumns(ColumnSelection colsel)
\r
785 this.colSel = colsel;
\r
786 if(colSel.getHiddenColumns()!=null)
\r
787 hasHiddenColumns = true;
\r
790 public ColumnSelection getColumnSelection()
\r
795 public void resetSeqLimits(int height)
\r
797 setEndSeq(height / getCharHeight());
\r
800 public void setCurrentTree(NJTree tree)
\r
802 currentTree = tree;
\r
805 public NJTree getCurrentTree()
\r
807 return currentTree;
\r
810 public void setColourAppliesToAllGroups(boolean b)
\r
812 colourAppliesToAllGroups = b;
\r
815 public boolean getColourAppliesToAllGroups()
\r
817 return colourAppliesToAllGroups;
\r
820 public boolean getShowJVSuffix()
\r
822 return showJVSuffix;
\r
825 public void setShowJVSuffix(boolean b)
\r
830 public boolean getShowAnnotation()
\r
832 return showAnnotation;
\r
835 public void setShowAnnotation(boolean b)
\r
837 showAnnotation = b;
\r
840 public boolean getScaleAboveWrapped()
\r
842 return scaleAboveWrapped;
\r
845 public boolean getScaleLeftWrapped()
\r
847 return scaleLeftWrapped;
\r
850 public boolean getScaleRightWrapped()
\r
852 return scaleRightWrapped;
\r
855 public void setScaleAboveWrapped(boolean b)
\r
857 scaleAboveWrapped = b;
\r
860 public void setScaleLeftWrapped(boolean b)
\r
862 scaleLeftWrapped = b;
\r
865 public void setScaleRightWrapped(boolean b)
\r
867 scaleRightWrapped = b;
\r
870 public void setIgnoreGapsConsensus(boolean b)
\r
872 ignoreGapsInConsensusCalculation = b;
\r
873 updateConsensus(null);
\r
874 if (globalColourScheme!=null)
\r
876 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
\r
877 ignoreGapsInConsensusCalculation);
\r
883 * Property change listener for changes in alignment
\r
885 * @param listener DOCUMENT ME!
\r
887 public void addPropertyChangeListener(
\r
888 java.beans.PropertyChangeListener listener)
\r
890 changeSupport.addPropertyChangeListener(listener);
\r
896 * @param listener DOCUMENT ME!
\r
898 public void removePropertyChangeListener(
\r
899 java.beans.PropertyChangeListener listener)
\r
901 changeSupport.removePropertyChangeListener(listener);
\r
905 * Property change listener for changes in alignment
\r
907 * @param prop DOCUMENT ME!
\r
908 * @param oldvalue DOCUMENT ME!
\r
909 * @param newvalue DOCUMENT ME!
\r
911 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
913 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r
918 public boolean getIgnoreGapsConsensus()
\r
920 return ignoreGapsInConsensusCalculation;
\r
922 public void hideSelectedColumns()
\r
924 if (colSel.size() < 1)
\r
927 colSel.hideSelectedColumns();
\r
928 setSelectionGroup(null);
\r
930 hasHiddenColumns = true;
\r
933 public void invertColumnSelection()
\r
935 for (int i = 0; i < alignment.getWidth(); i++)
\r
937 if (colSel.contains(i))
\r
938 colSel.removeElement(i);
\r
941 if (!hasHiddenColumns || colSel.isVisible(i))
\r
943 colSel.addElement(i);
\r
950 public void hideColumns(int start, int end)
\r
953 colSel.hideColumns(start);
\r
955 colSel.hideColumns(start, end);
\r
957 hasHiddenColumns = true;
\r
960 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
\r
962 int sSize = sg.getSize();
\r
966 if(hiddenRepSequences==null)
\r
967 hiddenRepSequences = new Hashtable();
\r
969 hiddenRepSequences.put(repSequence, sg);
\r
971 //Hide all sequences except the repSequence
\r
972 SequenceI [] seqs = new SequenceI[sSize-1];
\r
974 for(int i=0; i<sSize; i++)
\r
975 if(sg.getSequenceAt(i)!=repSequence)
\r
980 seqs[index++] = sg.getSequenceAt(i);
\r
983 hideSequence(seqs);
\r
987 public void hideAllSelectedSeqs()
\r
989 if (selectionGroup == null)
\r
992 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
\r
994 hideSequence(seqs);
\r
996 setSelectionGroup(null);
\r
999 public void hideSequence(SequenceI [] seq)
\r
1003 for (int i = 0; i < seq.length; i++)
\r
1004 alignment.getHiddenSequences().hideSequence(seq[i]);
\r
1006 hasHiddenRows = true;
\r
1007 firePropertyChange("alignment", null, alignment.getSequences());
\r
1011 public void showColumn(int col)
\r
1013 colSel.revealHiddenColumns(col);
\r
1014 if(colSel.getHiddenColumns()==null)
\r
1015 hasHiddenColumns = false;
\r
1018 public void showAllHiddenColumns()
\r
1020 colSel.revealAllHiddenColumns();
\r
1021 hasHiddenColumns = false;
\r
1024 public void showAllHiddenSeqs()
\r
1026 if(alignment.getHiddenSequences().getSize()>0)
\r
1028 if(selectionGroup==null)
\r
1030 selectionGroup = new SequenceGroup();
\r
1031 selectionGroup.setEndRes(alignment.getWidth()-1);
\r
1033 Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
\r
1034 for(int t=0; t<tmp.size(); t++)
\r
1036 selectionGroup.addSequence(
\r
1037 (SequenceI)tmp.elementAt(t), false
\r
1040 firePropertyChange("alignment", null, alignment.getSequences());
\r
1041 hasHiddenRows = false;
\r
1042 hiddenRepSequences = null;
\r
1046 public int adjustForHiddenSeqs(int alignmentIndex)
\r
1048 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
\r
1052 * This method returns the a new SequenceI [] with
\r
1053 * the selection sequence and start and end points adjusted
\r
1054 * @return String[]
\r
1056 public SequenceI[] getSelectionAsNewSequence()
\r
1058 SequenceI[] sequences;
\r
1060 if (selectionGroup == null)
\r
1061 sequences = alignment.getSequencesArray();
\r
1063 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
\r
1069 * This method returns the visible alignment as text, as
\r
1070 * seen on the GUI, ie if columns are hidden they will not
\r
1071 * be returned in the result.
\r
1072 * Use this for calculating trees, PCA, redundancy etc on views
\r
1073 * which contain hidden columns.
\r
1074 * @return String[]
\r
1076 public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)
\r
1078 CigarArray selection=null;
\r
1079 SequenceI [] seqs= null;
\r
1081 int start = 0, end = 0;
\r
1082 if(selectedRegionOnly && selectionGroup!=null)
\r
1084 iSize = selectionGroup.getSize();
\r
1085 seqs = selectionGroup.getSequencesInOrder(alignment);
\r
1086 start = selectionGroup.getStartRes();
\r
1087 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
\r
1091 iSize = alignment.getHeight();
\r
1092 seqs = alignment.getSequencesArray();
\r
1093 end = alignment.getWidth()-1;
\r
1095 SeqCigar[] selseqs = new SeqCigar[iSize];
\r
1096 for(i=0; i<iSize; i++)
\r
1098 selseqs[i] = new SeqCigar(seqs[i], start, end);
\r
1100 selection=new CigarArray(selseqs);
\r
1101 // now construct the CigarArray operations
\r
1102 if (hasHiddenColumns) {
\r
1103 Vector regions = colSel.getHiddenColumns();
\r
1105 int hideStart, hideEnd;
\r
1107 for (int j = 0; last<end & j < regions.size(); j++)
\r
1109 region = (int[]) regions.elementAt(j);
\r
1110 hideStart = region[0];
\r
1111 hideEnd = region[1];
\r
1112 // edit hidden regions to selection range
\r
1113 if(hideStart<last) {
\r
1114 if (hideEnd > last)
\r
1121 if (hideStart>end)
\r
1127 if (hideStart>hideEnd)
\r
1130 * form operations...
\r
1132 if (last<hideStart)
\r
1133 selection.addOperation(CigarArray.M, hideStart-last);
\r
1134 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
\r
1137 // Final match if necessary.
\r
1139 selection.addOperation(CigarArray.M, end-last+1);
\r
1141 selection.addOperation(CigarArray.M, end-start+1);
\r
1146 * return a compact representation of the current alignment selection to
\r
1147 * pass to an analysis function
\r
1148 * @param selectedOnly boolean true to just return the selected view
\r
1149 * @return AlignmentView
\r
1151 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {
\r
1153 // this is here because the AlignmentView constructor modifies the CigarArray
\r
1154 // object. Refactoring of Cigar and alignment view representation should
\r
1155 // be done to remove redundancy.
\r
1156 CigarArray aligview = getViewAsCigars(selectedOnly);
\r
1157 if (aligview!=null) {
\r
1158 return new AlignmentView(aligview,
\r
1159 (selectedOnly && selectionGroup!=null) ? selectionGroup.getStartRes() : 0);
\r
1164 * This method returns the visible alignment as text, as
\r
1165 * seen on the GUI, ie if columns are hidden they will not
\r
1166 * be returned in the result.
\r
1167 * Use this for calculating trees, PCA, redundancy etc on views
\r
1168 * which contain hidden columns.
\r
1169 * @return String[]
\r
1171 public String [] getViewAsString(boolean selectedRegionOnly)
\r
1173 String [] selection = null;
\r
1174 SequenceI [] seqs= null;
\r
1176 int start = 0, end = 0;
\r
1177 if(selectedRegionOnly && selectionGroup!=null)
\r
1179 iSize = selectionGroup.getSize();
\r
1180 seqs = selectionGroup.getSequencesInOrder(alignment);
\r
1181 start = selectionGroup.getStartRes();
\r
1182 end = selectionGroup.getEndRes()+1;
\r
1186 iSize = alignment.getHeight();
\r
1187 seqs = alignment.getSequencesArray();
\r
1188 end = alignment.getWidth();
\r
1191 selection = new String[iSize];
\r
1194 for(i=0; i<iSize; i++)
\r
1196 if (hasHiddenColumns)
\r
1198 StringBuffer visibleSeq = new StringBuffer();
\r
1199 Vector regions = colSel.getHiddenColumns();
\r
1201 int blockStart = start, blockEnd=end;
\r
1203 int hideStart, hideEnd;
\r
1205 for (int j = 0; j < regions.size(); j++)
\r
1207 region = (int[]) regions.elementAt(j);
\r
1208 hideStart = region[0];
\r
1209 hideEnd = region[1];
\r
1211 if(hideStart < start)
\r
1216 blockStart = Math.min(blockStart, hideEnd+1);
\r
1217 blockEnd = Math.min(blockEnd, hideStart);
\r
1219 if(blockStart>blockEnd)
\r
1225 visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
\r
1227 blockStart = hideEnd+1;
\r
1231 if(end>blockStart)
\r
1232 visibleSeq.append(seqs[i].getSequence(blockStart, end));
\r
1234 selection[i] = visibleSeq.toString();
\r
1238 selection[i] = seqs[i].getSequenceAsString(start, end);
\r
1245 public boolean getShowHiddenMarkers()
\r
1247 return showHiddenMarkers;
\r
1250 public void setShowHiddenMarkers(boolean show)
\r
1252 showHiddenMarkers = show;
\r
1255 public Color getSequenceColour(SequenceI seq)
\r
1257 if (sequenceColours == null || !sequenceColours.containsKey(seq))
\r
1258 return Color.white;
\r
1260 return (Color) sequenceColours.get(seq);
\r
1263 public void setSequenceColour(SequenceI seq, Color col)
\r
1265 if (sequenceColours == null)
\r
1266 sequenceColours = new Hashtable();
\r
1269 sequenceColours.remove(seq);
\r
1271 sequenceColours.put(seq, col);
\r
1274 public String getSequenceSetId()
\r
1276 if (sequenceSetID == null)
\r
1277 sequenceSetID = alignment.hashCode() + "";
\r
1279 return sequenceSetID;
\r
1282 public void alignmentChanged(AlignmentPanel ap)
\r
1284 alignment.padGaps();
\r
1286 if (hconsensus != null && autocalculateConsensus)
\r
1288 updateConsensus(ap);
\r
1289 updateConservation(ap);
\r
1292 //Reset endRes of groups if beyond alignment width
\r
1293 int alWidth = alignment.getWidth();
\r
1294 Vector groups = alignment.getGroups();
\r
1297 for(int i=0; i<groups.size(); i++)
\r
1299 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
\r
1300 if(sg.getEndRes()>alWidth)
\r
1301 sg.setEndRes(alWidth-1);
\r
1305 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
\r
1306 selectionGroup.setEndRes(alWidth-1);
\r
1308 resetAllColourSchemes();
\r
1310 //AW alignment.adjustSequenceAnnotations();
\r
1313 void resetAllColourSchemes()
\r
1315 ColourSchemeI cs = globalColourScheme;
\r
1318 if (cs instanceof ClustalxColourScheme)
\r
1320 ( (ClustalxColourScheme) cs).
\r
1321 resetClustalX(alignment.getSequences(),
\r
1322 alignment.getWidth());
\r
1325 cs.setConsensus(hconsensus);
\r
1326 if (cs.conservationApplied())
\r
1328 Alignment al = (Alignment) alignment;
\r
1329 Conservation c = new Conservation("All",
\r
1330 ResidueProperties.propHash, 3,
\r
1331 al.getSequences(), 0,
\r
1332 al.getWidth() - 1);
\r
1334 c.verdict(false, ConsPercGaps);
\r
1336 cs.setConservation(c);
\r
1340 int s, sSize = alignment.getGroups().size();
\r
1341 for(s=0; s<sSize; s++)
\r
1343 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
\r
1344 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
\r
1346 ((ClustalxColourScheme)sg.cs).resetClustalX(
\r
1347 sg.getSequences(hiddenRepSequences), sg.getWidth());
\r
1349 sg.recalcConservation();
\r