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
209 if (showConservation)
\r
211 alignment.addAnnotation(conservation);
\r
216 quality = new AlignmentAnnotation("Quality",
\r
217 "Alignment Quality based on Blosum62 scores",
\r
221 AlignmentAnnotation.BAR_GRAPH);
\r
222 quality.hasText = true;
\r
224 alignment.addAnnotation(quality);
\r
228 consensus = new AlignmentAnnotation("Consensus", "PID",
\r
229 new Annotation[1], 0f, 100f,
\r
230 AlignmentAnnotation.BAR_GRAPH);
\r
231 consensus.hasText = true;
\r
235 alignment.addAnnotation(consensus);
\r
241 public void showSequenceFeatures(boolean b)
\r
243 showSequenceFeatures = b;
\r
246 public boolean getShowSequenceFeatures()
\r
248 return showSequenceFeatures;
\r
252 class ConservationThread extends Thread
\r
255 public ConservationThread(AlignmentPanel ap)
\r
264 updatingConservation = true;
\r
266 while (UPDATING_CONSERVATION)
\r
276 catch (Exception ex)
\r
278 ex.printStackTrace();
\r
282 UPDATING_CONSERVATION = true;
\r
285 int alWidth = alignment.getWidth();
\r
289 Conservation cons = new jalview.analysis.Conservation("All",
\r
290 jalview.schemes.ResidueProperties.propHash, 3,
\r
291 alignment.getSequences(), 0, alWidth -1);
\r
294 cons.verdict(false, ConsPercGaps);
\r
298 cons.findQuality();
\r
301 char [] sequence = cons.getConsSequence().getSequence();
\r
311 maxR = 1.0f - minR;
\r
312 maxG = 0.9f - minG;
\r
313 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
\r
322 conservation.annotations = new Annotation[alWidth];
\r
326 quality.graphMax = cons.qualityRange[1].floatValue();
\r
327 quality.annotations = new Annotation[alWidth];
\r
328 qmin = cons.qualityRange[0].floatValue();
\r
329 qmax = cons.qualityRange[1].floatValue();
\r
332 for (int i = 0; i < alWidth; i++)
\r
338 if (Character.isDigit(c))
\r
339 value = (int) (c - '0');
\r
345 float vprop = value - min;
\r
347 conservation.annotations[i] =
\r
348 new Annotation(String.valueOf(c),
\r
349 String.valueOf(value), ' ', value,
\r
350 new Color(minR + (maxR * vprop),
\r
351 minG + (maxG * vprop),
\r
352 minB + (maxB * vprop)));
\r
357 value = ( (Double) cons.quality.elementAt(i)).floatValue();
\r
358 vprop = value - qmin;
\r
360 quality.annotations[i] = new Annotation(" ", String.valueOf(value), ' ',
\r
362 new Color(minR + (maxR * vprop),
\r
363 minG + (maxG * vprop),
\r
364 minB + (maxB * vprop)));
\r
368 catch (OutOfMemoryError error)
\r
370 System.out.println("Out of memory calculating conservation!!");
\r
371 conservation = null;
\r
376 UPDATING_CONSERVATION = false;
\r
377 updatingConservation = false;
\r
388 ConservationThread conservationThread;
\r
390 ConsensusThread consensusThread;
\r
392 boolean consUpdateNeeded = false;
\r
394 static boolean UPDATING_CONSENSUS = false;
\r
396 static boolean UPDATING_CONSERVATION = false;
\r
398 boolean updatingConsensus = false;
\r
400 boolean updatingConservation = false;
\r
405 public void updateConservation(final AlignmentPanel ap)
\r
407 if (alignment.isNucleotide() || conservation==null)
\r
410 conservationThread = new ConservationThread(ap);
\r
411 conservationThread.start();
\r
417 public void updateConsensus(final AlignmentPanel ap)
\r
419 consensusThread = new ConsensusThread(ap);
\r
420 consensusThread.start();
\r
424 class ConsensusThread extends Thread
\r
427 public ConsensusThread(AlignmentPanel ap)
\r
433 updatingConsensus = true;
\r
434 while (UPDATING_CONSENSUS)
\r
445 catch (Exception ex)
\r
447 ex.printStackTrace();
\r
452 UPDATING_CONSENSUS = true;
\r
456 int aWidth = alignment.getWidth();
\r
460 consensus.annotations = null;
\r
461 consensus.annotations = new Annotation[aWidth];
\r
464 hconsensus = new Hashtable[aWidth];
\r
465 AAFrequency.calculate(alignment.getSequencesArray(),
\r
467 alignment.getWidth(),
\r
470 for (int i = 0; i < aWidth; i++)
\r
473 if (ignoreGapsInConsensusCalculation)
\r
474 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
\r
477 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
\r
480 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
\r
481 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
\r
483 if (maxRes.length() > 1)
\r
485 mouseOver = "[" + maxRes + "] ";
\r
489 mouseOver += ( (int) value + "%");
\r
490 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
\r
494 if (globalColourScheme != null)
\r
495 globalColourScheme.setConsensus(hconsensus);
\r
498 catch (OutOfMemoryError error)
\r
500 alignment.deleteAnnotation(consensus);
\r
504 System.out.println("Out of memory calculating consensus!!");
\r
507 UPDATING_CONSENSUS = false;
\r
508 updatingConsensus = false;
\r
518 * get the consensus sequence as displayed under the PID consensus annotation row.
\r
519 * @return consensus sequence as a new sequence object
\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
525 public SequenceI getConsensusSeq()
\r
527 if (consensus==null)
\r
529 StringBuffer seqs=new StringBuffer();
\r
530 for (int i=0; i<consensus.annotations.length; i++) {
\r
531 if (consensus.annotations[i]!=null) {
\r
532 if (consensus.annotations[i].description.charAt(0) == '[')
\r
533 seqs.append(consensus.annotations[i].description.charAt(1));
\r
535 seqs.append(consensus.annotations[i].displayCharacter);
\r
538 SequenceI sq = new Sequence("Consensus", seqs.toString());
\r
539 sq.setDescription("Percentage Identity Consensus "+((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
\r
542 public SequenceGroup getSelectionGroup()
\r
544 return selectionGroup;
\r
547 public void setSelectionGroup(SequenceGroup sg)
\r
549 selectionGroup = sg;
\r
552 public boolean getConservationSelected()
\r
554 return conservationColourSelected;
\r
557 public void setConservationSelected(boolean b)
\r
559 conservationColourSelected = b;
\r
562 public boolean getAbovePIDThreshold()
\r
564 return abovePIDThreshold;
\r
567 public void setAbovePIDThreshold(boolean b)
\r
569 abovePIDThreshold = b;
\r
572 public int getStartRes()
\r
577 public int getEndRes()
\r
582 public int getStartSeq()
\r
587 public void setGlobalColourScheme(ColourSchemeI cs)
\r
589 globalColourScheme = cs;
\r
592 public ColourSchemeI getGlobalColourScheme()
\r
594 return globalColourScheme;
\r
597 public void setStartRes(int res)
\r
599 this.startRes = res;
\r
602 public void setStartSeq(int seq)
\r
604 this.startSeq = seq;
\r
607 public void setEndRes(int res)
\r
609 if (res > alignment.getWidth() - 1)
\r
611 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
\r
612 res = alignment.getWidth() - 1;
\r
621 public void setEndSeq(int seq)
\r
623 if (seq > alignment.getHeight())
\r
625 seq = alignment.getHeight();
\r
634 public int getEndSeq()
\r
639 java.awt.Frame nullFrame;
\r
640 public void setFont(Font f)
\r
643 if(nullFrame == null)
\r
645 nullFrame = new java.awt.Frame();
\r
646 nullFrame.addNotify();
\r
649 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
\r
650 setCharHeight(fm.getHeight());
\r
651 charWidth = fm.charWidth('M');
\r
655 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
\r
656 fm = nullFrame.getGraphics().getFontMetrics(f2);
\r
657 charWidth = fm.stringWidth("MMMMMMMMMMM") / 10;
\r
661 public Font getFont()
\r
666 public int getCharWidth()
\r
671 public void setCharHeight(int h)
\r
673 this.charHeight = h;
\r
676 public int getCharHeight()
\r
681 public void setWrappedWidth(int w)
\r
683 this.wrappedWidth = w;
\r
686 public int getwrappedWidth()
\r
688 return wrappedWidth;
\r
691 public AlignmentI getAlignment()
\r
696 public void setAlignment(AlignmentI align)
\r
698 this.alignment = align;
\r
701 public void setWrapAlignment(boolean state)
\r
703 wrapAlignment = state;
\r
706 public void setShowText(boolean state)
\r
711 public void setRenderGaps(boolean state)
\r
713 renderGaps = state;
\r
716 public boolean getColourText()
\r
718 return showColourText;
\r
721 public void setColourText(boolean state)
\r
723 showColourText = state;
\r
726 public void setShowBoxes(boolean state)
\r
731 public boolean getWrapAlignment()
\r
733 return wrapAlignment;
\r
736 public boolean getShowText()
\r
741 public boolean getShowBoxes()
\r
746 public char getGapCharacter()
\r
748 return getAlignment().getGapCharacter();
\r
751 public void setGapCharacter(char gap)
\r
753 if (getAlignment() != null)
\r
755 getAlignment().setGapCharacter(gap);
\r
759 public void setThreshold(int thresh)
\r
761 threshold = thresh;
\r
764 public int getThreshold()
\r
769 public void setIncrement(int inc)
\r
774 public int getIncrement()
\r
779 public void setHiddenColumns(ColumnSelection colsel)
\r
781 this.colSel = colsel;
\r
782 if(colSel.getHiddenColumns()!=null)
\r
783 hasHiddenColumns = true;
\r
786 public ColumnSelection getColumnSelection()
\r
791 public void resetSeqLimits(int height)
\r
793 setEndSeq(height / getCharHeight());
\r
796 public void setCurrentTree(NJTree tree)
\r
798 currentTree = tree;
\r
801 public NJTree getCurrentTree()
\r
803 return currentTree;
\r
806 public void setColourAppliesToAllGroups(boolean b)
\r
808 colourAppliesToAllGroups = b;
\r
811 public boolean getColourAppliesToAllGroups()
\r
813 return colourAppliesToAllGroups;
\r
816 public boolean getShowJVSuffix()
\r
818 return showJVSuffix;
\r
821 public void setShowJVSuffix(boolean b)
\r
826 public boolean getShowAnnotation()
\r
828 return showAnnotation;
\r
831 public void setShowAnnotation(boolean b)
\r
833 showAnnotation = b;
\r
836 public boolean getScaleAboveWrapped()
\r
838 return scaleAboveWrapped;
\r
841 public boolean getScaleLeftWrapped()
\r
843 return scaleLeftWrapped;
\r
846 public boolean getScaleRightWrapped()
\r
848 return scaleRightWrapped;
\r
851 public void setScaleAboveWrapped(boolean b)
\r
853 scaleAboveWrapped = b;
\r
856 public void setScaleLeftWrapped(boolean b)
\r
858 scaleLeftWrapped = b;
\r
861 public void setScaleRightWrapped(boolean b)
\r
863 scaleRightWrapped = b;
\r
866 public void setIgnoreGapsConsensus(boolean b)
\r
868 ignoreGapsInConsensusCalculation = b;
\r
869 updateConsensus(null);
\r
870 if (globalColourScheme!=null)
\r
872 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
\r
873 ignoreGapsInConsensusCalculation);
\r
879 * Property change listener for changes in alignment
\r
881 * @param listener DOCUMENT ME!
\r
883 public void addPropertyChangeListener(
\r
884 java.beans.PropertyChangeListener listener)
\r
886 changeSupport.addPropertyChangeListener(listener);
\r
892 * @param listener DOCUMENT ME!
\r
894 public void removePropertyChangeListener(
\r
895 java.beans.PropertyChangeListener listener)
\r
897 changeSupport.removePropertyChangeListener(listener);
\r
901 * Property change listener for changes in alignment
\r
903 * @param prop DOCUMENT ME!
\r
904 * @param oldvalue DOCUMENT ME!
\r
905 * @param newvalue DOCUMENT ME!
\r
907 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
\r
909 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
\r
914 public boolean getIgnoreGapsConsensus()
\r
916 return ignoreGapsInConsensusCalculation;
\r
918 public void hideSelectedColumns()
\r
920 if (colSel.size() < 1)
\r
923 colSel.hideSelectedColumns();
\r
924 setSelectionGroup(null);
\r
926 hasHiddenColumns = true;
\r
929 public void invertColumnSelection()
\r
931 for (int i = 0; i < alignment.getWidth(); i++)
\r
933 if (colSel.contains(i))
\r
934 colSel.removeElement(i);
\r
937 if (!hasHiddenColumns || colSel.isVisible(i))
\r
939 colSel.addElement(i);
\r
946 public void hideColumns(int start, int end)
\r
949 colSel.hideColumns(start);
\r
951 colSel.hideColumns(start, end);
\r
953 hasHiddenColumns = true;
\r
956 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
\r
958 int sSize = sg.getSize();
\r
962 if(hiddenRepSequences==null)
\r
963 hiddenRepSequences = new Hashtable();
\r
965 hiddenRepSequences.put(repSequence, sg);
\r
967 //Hide all sequences except the repSequence
\r
968 SequenceI [] seqs = new SequenceI[sSize-1];
\r
970 for(int i=0; i<sSize; i++)
\r
971 if(sg.getSequenceAt(i)!=repSequence)
\r
976 seqs[index++] = sg.getSequenceAt(i);
\r
979 hideSequence(seqs);
\r
983 public void hideAllSelectedSeqs()
\r
985 if (selectionGroup == null)
\r
988 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
\r
990 hideSequence(seqs);
\r
992 setSelectionGroup(null);
\r
995 public void hideSequence(SequenceI [] seq)
\r
999 for (int i = 0; i < seq.length; i++)
\r
1000 alignment.getHiddenSequences().hideSequence(seq[i]);
\r
1002 hasHiddenRows = true;
\r
1003 firePropertyChange("alignment", null, alignment.getSequences());
\r
1007 public void showColumn(int col)
\r
1009 colSel.revealHiddenColumns(col);
\r
1010 if(colSel.getHiddenColumns()==null)
\r
1011 hasHiddenColumns = false;
\r
1014 public void showAllHiddenColumns()
\r
1016 colSel.revealAllHiddenColumns();
\r
1017 hasHiddenColumns = false;
\r
1020 public void showAllHiddenSeqs()
\r
1022 if(alignment.getHiddenSequences().getSize()>0)
\r
1024 if(selectionGroup==null)
\r
1026 selectionGroup = new SequenceGroup();
\r
1027 selectionGroup.setEndRes(alignment.getWidth()-1);
\r
1029 Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
\r
1030 for(int t=0; t<tmp.size(); t++)
\r
1032 selectionGroup.addSequence(
\r
1033 (SequenceI)tmp.elementAt(t), false
\r
1036 firePropertyChange("alignment", null, alignment.getSequences());
\r
1037 hasHiddenRows = false;
\r
1038 hiddenRepSequences = null;
\r
1042 public int adjustForHiddenSeqs(int alignmentIndex)
\r
1044 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
\r
1048 * This method returns the a new SequenceI [] with
\r
1049 * the selection sequence and start and end points adjusted
\r
1050 * @return String[]
\r
1052 public SequenceI[] getSelectionAsNewSequence()
\r
1054 SequenceI[] sequences;
\r
1056 if (selectionGroup == null)
\r
1057 sequences = alignment.getSequencesArray();
\r
1059 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
\r
1065 * This method returns the visible alignment as text, as
\r
1066 * seen on the GUI, ie if columns are hidden they will not
\r
1067 * be returned in the result.
\r
1068 * Use this for calculating trees, PCA, redundancy etc on views
\r
1069 * which contain hidden columns.
\r
1070 * @return String[]
\r
1072 public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)
\r
1074 CigarArray selection=null;
\r
1075 SequenceI [] seqs= null;
\r
1077 int start = 0, end = 0;
\r
1078 if(selectedRegionOnly && selectionGroup!=null)
\r
1080 iSize = selectionGroup.getSize();
\r
1081 seqs = selectionGroup.getSequencesInOrder(alignment);
\r
1082 start = selectionGroup.getStartRes();
\r
1083 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
\r
1087 iSize = alignment.getHeight();
\r
1088 seqs = alignment.getSequencesArray();
\r
1089 end = alignment.getWidth()-1;
\r
1091 SeqCigar[] selseqs = new SeqCigar[iSize];
\r
1092 for(i=0; i<iSize; i++)
\r
1094 selseqs[i] = new SeqCigar(seqs[i], start, end);
\r
1096 selection=new CigarArray(selseqs);
\r
1097 // now construct the CigarArray operations
\r
1098 if (hasHiddenColumns) {
\r
1099 Vector regions = colSel.getHiddenColumns();
\r
1101 int hideStart, hideEnd;
\r
1103 for (int j = 0; last<end & j < regions.size(); j++)
\r
1105 region = (int[]) regions.elementAt(j);
\r
1106 hideStart = region[0];
\r
1107 hideEnd = region[1];
\r
1108 // edit hidden regions to selection range
\r
1109 if(hideStart<last) {
\r
1110 if (hideEnd > last)
\r
1117 if (hideStart>end)
\r
1123 if (hideStart>hideEnd)
\r
1126 * form operations...
\r
1128 if (last<hideStart)
\r
1129 selection.addOperation(CigarArray.M, hideStart-last);
\r
1130 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
\r
1133 // Final match if necessary.
\r
1135 selection.addOperation(CigarArray.M, end-last+1);
\r
1137 selection.addOperation(CigarArray.M, end-start+1);
\r
1142 * return a compact representation of the current alignment selection to
\r
1143 * pass to an analysis function
\r
1144 * @param selectedOnly boolean true to just return the selected view
\r
1145 * @return AlignmentView
\r
1147 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {
\r
1149 // this is here because the AlignmentView constructor modifies the CigarArray
\r
1150 // object. Refactoring of Cigar and alignment view representation should
\r
1151 // be done to remove redundancy.
\r
1152 CigarArray aligview = getViewAsCigars(selectedOnly);
\r
1153 if (aligview!=null) {
\r
1154 return new AlignmentView(aligview,
\r
1155 (selectedOnly && selectionGroup!=null) ? selectionGroup.getStartRes() : 0);
\r
1160 * This method returns the visible alignment as text, as
\r
1161 * seen on the GUI, ie if columns are hidden they will not
\r
1162 * be returned in the result.
\r
1163 * Use this for calculating trees, PCA, redundancy etc on views
\r
1164 * which contain hidden columns.
\r
1165 * @return String[]
\r
1167 public String [] getViewAsString(boolean selectedRegionOnly)
\r
1169 String [] selection = null;
\r
1170 SequenceI [] seqs= null;
\r
1172 int start = 0, end = 0;
\r
1173 if(selectedRegionOnly && selectionGroup!=null)
\r
1175 iSize = selectionGroup.getSize();
\r
1176 seqs = selectionGroup.getSequencesInOrder(alignment);
\r
1177 start = selectionGroup.getStartRes();
\r
1178 end = selectionGroup.getEndRes()+1;
\r
1182 iSize = alignment.getHeight();
\r
1183 seqs = alignment.getSequencesArray();
\r
1184 end = alignment.getWidth();
\r
1187 selection = new String[iSize];
\r
1190 for(i=0; i<iSize; i++)
\r
1192 if (hasHiddenColumns)
\r
1194 StringBuffer visibleSeq = new StringBuffer();
\r
1195 Vector regions = colSel.getHiddenColumns();
\r
1197 int blockStart = start, blockEnd=end;
\r
1199 int hideStart, hideEnd;
\r
1201 for (int j = 0; j < regions.size(); j++)
\r
1203 region = (int[]) regions.elementAt(j);
\r
1204 hideStart = region[0];
\r
1205 hideEnd = region[1];
\r
1207 if(hideStart < start)
\r
1212 blockStart = Math.min(blockStart, hideEnd+1);
\r
1213 blockEnd = Math.min(blockEnd, hideStart);
\r
1215 if(blockStart>blockEnd)
\r
1221 visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
\r
1223 blockStart = hideEnd+1;
\r
1227 if(end>blockStart)
\r
1228 visibleSeq.append(seqs[i].getSequence(blockStart, end));
\r
1230 selection[i] = visibleSeq.toString();
\r
1234 selection[i] = seqs[i].getSequenceAsString(start, end);
\r
1241 public boolean getShowHiddenMarkers()
\r
1243 return showHiddenMarkers;
\r
1246 public void setShowHiddenMarkers(boolean show)
\r
1248 showHiddenMarkers = show;
\r
1251 public Color getSequenceColour(SequenceI seq)
\r
1253 if (sequenceColours == null || !sequenceColours.containsKey(seq))
\r
1254 return Color.white;
\r
1256 return (Color) sequenceColours.get(seq);
\r
1259 public void setSequenceColour(SequenceI seq, Color col)
\r
1261 if (sequenceColours == null)
\r
1262 sequenceColours = new Hashtable();
\r
1265 sequenceColours.remove(seq);
\r
1267 sequenceColours.put(seq, col);
\r
1270 public String getSequenceSetId()
\r
1272 if (sequenceSetID == null)
\r
1273 sequenceSetID = alignment.hashCode() + "";
\r
1275 return sequenceSetID;
\r
1278 public void alignmentChanged(AlignmentPanel ap)
\r
1280 alignment.padGaps();
\r
1282 if (hconsensus != null && autocalculateConsensus)
\r
1284 updateConsensus(ap);
\r
1285 updateConservation(ap);
\r
1288 //Reset endRes of groups if beyond alignment width
\r
1289 int alWidth = alignment.getWidth();
\r
1290 Vector groups = alignment.getGroups();
\r
1293 for(int i=0; i<groups.size(); i++)
\r
1295 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
\r
1296 if(sg.getEndRes()>alWidth)
\r
1297 sg.setEndRes(alWidth-1);
\r
1301 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
\r
1302 selectionGroup.setEndRes(alWidth-1);
\r
1304 resetAllColourSchemes();
\r
1306 alignment.adjustSequenceAnnotations();
\r
1309 void resetAllColourSchemes()
\r
1311 ColourSchemeI cs = globalColourScheme;
\r
1314 if (cs instanceof ClustalxColourScheme)
\r
1316 ( (ClustalxColourScheme) cs).
\r
1317 resetClustalX(alignment.getSequences(),
\r
1318 alignment.getWidth());
\r
1321 cs.setConsensus(hconsensus);
\r
1322 if (cs.conservationApplied())
\r
1324 Alignment al = (Alignment) alignment;
\r
1325 Conservation c = new Conservation("All",
\r
1326 ResidueProperties.propHash, 3,
\r
1327 al.getSequences(), 0,
\r
1328 al.getWidth() - 1);
\r
1330 c.verdict(false, ConsPercGaps);
\r
1332 cs.setConservation(c);
\r
1336 int s, sSize = alignment.getGroups().size();
\r
1337 for(s=0; s<sSize; s++)
\r
1339 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
\r
1340 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
\r
1342 ((ClustalxColourScheme)sg.cs).resetClustalX(
\r
1343 sg.getSequences(hiddenRepSequences), sg.getWidth());
\r
1345 sg.recalcConservation();
\r