2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 import jalview.analysis.*;
25 import jalview.datamodel.*;
27 import jalview.schemes.*;
40 public class AlignViewport
46 boolean showJVSuffix = true;
47 boolean showText = true;
48 boolean showColourText = false;
49 boolean showBoxes = true;
50 boolean wrapAlignment = false;
51 boolean renderGaps = true;
52 boolean showSequenceFeatures = false;
53 boolean showAnnotation = true;
54 boolean colourAppliesToAllGroups = true;
55 ColourSchemeI globalColourScheme = null;
56 boolean conservationColourSelected = false;
57 boolean abovePIDThreshold = false;
58 SequenceGroup selectionGroup;
61 boolean validCharWidth;
65 ColumnSelection colSel = new ColumnSelection();
68 NJTree currentTree = null;
69 boolean scaleAboveWrapped = false;
70 boolean scaleLeftWrapped = true;
71 boolean scaleRightWrapped = true;
72 boolean hasHiddenColumns = false;
73 boolean hasHiddenRows = false;
74 boolean showHiddenMarkers = true;
76 boolean cursorMode = false;
78 // The following vector holds the features which are
79 // currently visible, in the correct order or rendering
80 Hashtable featuresDisplayed = null;
84 public Hashtable [] hconsensus;
85 AlignmentAnnotation consensus;
86 AlignmentAnnotation conservation;
87 AlignmentAnnotation quality;
88 boolean autoCalculateConsensus = true;
91 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
93 // JBPNote Prolly only need this in the applet version.
94 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
96 boolean ignoreGapsInConsensusCalculation = false;
98 boolean isDataset = false;
100 boolean antiAlias = false;
102 boolean padGaps = false;
104 Rectangle explodedPosition;
108 String sequenceSetID;
110 boolean gatherViewsHere = false;
112 Stack historyList = new Stack();
113 Stack redoList = new Stack();
115 Hashtable sequenceColours;
117 int thresholdTextColour = 0;
118 Color textColour = Color.black;
119 Color textColour2 = Color.white;
123 * Creates a new AlignViewport object.
125 * @param al DOCUMENT ME!
127 public AlignViewport(AlignmentI al)
133 * Create a new AlignViewport with hidden regions
134 * @param al AlignmentI
135 * @param hiddenColumns ColumnSelection
137 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) {
139 if (hiddenColumns!=null) {
140 this.colSel = hiddenColumns;
141 if (hiddenColumns.getHiddenColumns() != null)
142 hasHiddenColumns = true;
150 this.endRes = alignment.getWidth() - 1;
152 this.endSeq = alignment.getHeight() - 1;
154 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
156 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
157 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
159 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
161 padGaps = Cache.getDefault("PAD_GAPS", true);
163 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
164 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;
165 String fontSize = Cache.getDefault("FONT_SIZE", "10");
169 if (fontStyle.equals("bold"))
173 else if (fontStyle.equals("italic"))
178 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
180 alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );
183 // We must set conservation and consensus before setting colour,
184 // as Blosum and Clustal require this to be done
185 if(hconsensus==null && !isDataset)
187 if(!alignment.isNucleotide())
189 conservation = new AlignmentAnnotation("Conservation",
190 "Conservation of total alignment less than " +
191 ConsPercGaps + "% gaps",
192 new Annotation[1], 0f,
194 AlignmentAnnotation.BAR_GRAPH);
195 conservation.hasText = true;
198 if (Cache.getDefault("SHOW_CONSERVATION", true))
200 alignment.addAnnotation(conservation);
203 if (Cache.getDefault("SHOW_QUALITY", true))
205 quality = new AlignmentAnnotation("Quality",
206 "Alignment Quality based on Blosum62 scores",
210 AlignmentAnnotation.BAR_GRAPH);
211 quality.hasText = true;
213 alignment.addAnnotation(quality);
217 consensus = new AlignmentAnnotation("Consensus", "PID",
218 new Annotation[1], 0f, 100f,
219 AlignmentAnnotation.BAR_GRAPH);
220 consensus.hasText = true;
222 if (Cache.getDefault("SHOW_IDENTITY", true))
224 alignment.addAnnotation(consensus);
228 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
230 globalColourScheme = ColourSchemeProperty.getColour(alignment,
231 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
233 if (globalColourScheme instanceof UserColourScheme)
235 globalColourScheme = UserDefinedColours.loadDefaultColours();
236 ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());
239 if (globalColourScheme != null)
241 globalColourScheme.setConsensus(hconsensus);
245 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
253 * @param b DOCUMENT ME!
255 public void setShowSequenceFeatures(boolean b)
257 showSequenceFeatures = b;
260 public boolean getShowSequenceFeatures()
262 return showSequenceFeatures;
267 class ConservationThread extends Thread
270 public ConservationThread(AlignmentPanel ap)
279 updatingConservation = true;
281 while (UPDATING_CONSERVATION)
293 ex.printStackTrace();
297 UPDATING_CONSERVATION = true;
300 int alWidth = alignment.getWidth();
304 Conservation cons = new jalview.analysis.Conservation("All",
305 jalview.schemes.ResidueProperties.propHash, 3,
306 alignment.getSequences(), 0, alWidth -1);
309 cons.verdict(false, ConsPercGaps);
316 String sequence = cons.getConsSequence().getSequence();
328 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
337 conservation.annotations = new Annotation[alWidth];
341 quality.graphMax = cons.qualityRange[1].floatValue();
342 quality.annotations = new Annotation[alWidth];
343 qmin = cons.qualityRange[0].floatValue();
344 qmax = cons.qualityRange[1].floatValue();
347 for (int i = 0; i < alWidth; i++)
351 c = sequence.charAt(i);
353 if (Character.isDigit(c))
354 value = (int) (c - '0');
360 float vprop = value - min;
362 conservation.annotations[i] =
363 new Annotation(String.valueOf(c),
364 String.valueOf(value), ' ', value,
365 new Color(minR + (maxR * vprop),
366 minG + (maxG * vprop),
367 minB + (maxB * vprop)));
372 value = ( (Double) cons.quality.get(i)).floatValue();
373 vprop = value - qmin;
375 quality.annotations[i] = new Annotation(" ", String.valueOf(value), ' ',
377 new Color(minR + (maxR * vprop),
378 minG + (maxG * vprop),
379 minB + (maxB * vprop)));
383 catch (OutOfMemoryError error)
385 javax.swing.SwingUtilities.invokeLater(new Runnable()
391 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
392 "Out of memory calculating conservation!!"
394 "\nSee help files for increasing Java Virtual Machine memory."
396 javax.swing.JOptionPane.WARNING_MESSAGE);
403 System.out.println("Conservation calculation: " + error);
408 UPDATING_CONSERVATION = false;
409 updatingConservation = false;
420 ConservationThread conservationThread;
422 ConsensusThread consensusThread;
424 boolean consUpdateNeeded = false;
426 static boolean UPDATING_CONSENSUS = false;
428 static boolean UPDATING_CONSERVATION = false;
430 boolean updatingConsensus = false;
432 boolean updatingConservation = false;
437 public void updateConservation(final AlignmentPanel ap)
439 if (alignment.isNucleotide() || conservation==null)
442 conservationThread = new ConservationThread(ap);
443 conservationThread.start();
449 public void updateConsensus(final AlignmentPanel ap)
451 consensusThread = new ConsensusThread(ap);
452 consensusThread.start();
456 class ConsensusThread extends Thread
459 public ConsensusThread(AlignmentPanel ap)
465 updatingConsensus = true;
466 while (UPDATING_CONSENSUS)
479 ex.printStackTrace();
484 UPDATING_CONSENSUS = true;
488 int aWidth = alignment.getWidth();
492 consensus.annotations = null;
493 consensus.annotations = new Annotation[aWidth];
496 hconsensus = new Hashtable[aWidth];
497 AAFrequency.calculate(alignment.getSequencesArray(),
499 alignment.getWidth(),
502 for (int i = 0; i < aWidth; i++)
505 if (ignoreGapsInConsensusCalculation)
506 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
509 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
512 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
513 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
515 if (maxRes.length() > 1)
517 mouseOver = "[" + maxRes + "] ";
521 mouseOver += ( (int) value + "%");
522 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
526 if (globalColourScheme != null)
527 globalColourScheme.setConsensus(hconsensus);
530 catch (OutOfMemoryError error)
532 alignment.deleteAnnotation(consensus);
536 javax.swing.SwingUtilities.invokeLater(new Runnable()
540 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
541 "Out of memory calculating consensus!!"
543 "\nSee help files for increasing Java Virtual Machine memory."
545 javax.swing.JOptionPane.WARNING_MESSAGE);
549 System.out.println("Consensus calculation: " + error);
552 UPDATING_CONSENSUS = false;
553 updatingConsensus = false;
562 * get the consensus sequence as displayed under the PID consensus annotation row.
563 * @return consensus sequence as a new sequence object
565 public SequenceI getConsensusSeq() {
567 updateConsensus(null);
570 StringBuffer seqs=new StringBuffer();
571 for (int i=0; i<consensus.annotations.length; i++) {
572 if (consensus.annotations[i]!=null) {
573 if (consensus.annotations[i].description.charAt(0) == '[')
574 seqs.append(consensus.annotations[i].description.charAt(1));
576 seqs.append(consensus.annotations[i].displayCharacter);
580 SequenceI sq = new Sequence("Consensus", seqs.toString());
581 sq.setDescription("Percentage Identity Consensus "+((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
587 * @return DOCUMENT ME!
589 public SequenceGroup getSelectionGroup()
591 return selectionGroup;
597 * @param sg DOCUMENT ME!
599 public void setSelectionGroup(SequenceGroup sg)
607 * @return DOCUMENT ME!
609 public boolean getConservationSelected()
611 return conservationColourSelected;
617 * @param b DOCUMENT ME!
619 public void setConservationSelected(boolean b)
621 conservationColourSelected = b;
627 * @return DOCUMENT ME!
629 public boolean getAbovePIDThreshold()
631 return abovePIDThreshold;
637 * @param b DOCUMENT ME!
639 public void setAbovePIDThreshold(boolean b)
641 abovePIDThreshold = b;
647 * @return DOCUMENT ME!
649 public int getStartRes()
657 * @return DOCUMENT ME!
659 public int getEndRes()
667 * @return DOCUMENT ME!
669 public int getStartSeq()
677 * @param cs DOCUMENT ME!
679 public void setGlobalColourScheme(ColourSchemeI cs)
681 globalColourScheme = cs;
687 * @return DOCUMENT ME!
689 public ColourSchemeI getGlobalColourScheme()
691 return globalColourScheme;
697 * @param res DOCUMENT ME!
699 public void setStartRes(int res)
707 * @param seq DOCUMENT ME!
709 public void setStartSeq(int seq)
717 * @param res DOCUMENT ME!
719 public void setEndRes(int res)
721 if (res > (alignment.getWidth() - 1))
723 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
724 res = alignment.getWidth() - 1;
738 * @param seq DOCUMENT ME!
740 public void setEndSeq(int seq)
742 if (seq > alignment.getHeight())
744 seq = alignment.getHeight();
758 * @return DOCUMENT ME!
760 public int getEndSeq()
768 * @param f DOCUMENT ME!
770 public void setFont(Font f)
774 Container c = new Container();
776 java.awt.FontMetrics fm = c.getFontMetrics(font);
777 setCharHeight(fm.getHeight());
778 setCharWidth(fm.charWidth('M'));
779 validCharWidth = true;
785 * @return DOCUMENT ME!
787 public Font getFont()
795 * @param w DOCUMENT ME!
797 public void setCharWidth(int w)
805 * @return DOCUMENT ME!
807 public int getCharWidth()
815 * @param h DOCUMENT ME!
817 public void setCharHeight(int h)
825 * @return DOCUMENT ME!
827 public int getCharHeight()
835 * @param w DOCUMENT ME!
837 public void setWrappedWidth(int w)
839 this.wrappedWidth = w;
845 * @return DOCUMENT ME!
847 public int getWrappedWidth()
856 * @return DOCUMENT ME!
858 public AlignmentI getAlignment()
866 * @param align DOCUMENT ME!
868 public void setAlignment(AlignmentI align)
870 this.alignment = align;
876 * @param state DOCUMENT ME!
878 public void setWrapAlignment(boolean state)
880 wrapAlignment = state;
886 * @param state DOCUMENT ME!
888 public void setShowText(boolean state)
896 * @param state DOCUMENT ME!
898 public void setRenderGaps(boolean state)
906 * @return DOCUMENT ME!
908 public boolean getColourText()
910 return showColourText;
916 * @param state DOCUMENT ME!
918 public void setColourText(boolean state)
920 showColourText = state;
926 * @param state DOCUMENT ME!
928 public void setShowBoxes(boolean state)
936 * @return DOCUMENT ME!
938 public boolean getWrapAlignment()
940 return wrapAlignment;
946 * @return DOCUMENT ME!
948 public boolean getShowText()
956 * @return DOCUMENT ME!
958 public boolean getShowBoxes()
966 * @return DOCUMENT ME!
968 public char getGapCharacter()
970 return getAlignment().getGapCharacter();
976 * @param gap DOCUMENT ME!
978 public void setGapCharacter(char gap)
980 if (getAlignment() != null)
982 getAlignment().setGapCharacter(gap);
989 * @param thresh DOCUMENT ME!
991 public void setThreshold(int thresh)
999 * @return DOCUMENT ME!
1001 public int getThreshold()
1009 * @param inc DOCUMENT ME!
1011 public void setIncrement(int inc)
1019 * @return DOCUMENT ME!
1021 public int getIncrement()
1030 * @return DOCUMENT ME!
1032 public ColumnSelection getColumnSelection()
1041 * @param tree DOCUMENT ME!
1043 public void setCurrentTree(NJTree tree)
1051 * @return DOCUMENT ME!
1053 public NJTree getCurrentTree()
1061 * @param b DOCUMENT ME!
1063 public void setColourAppliesToAllGroups(boolean b)
1065 colourAppliesToAllGroups = b;
1071 * @return DOCUMENT ME!
1073 public boolean getColourAppliesToAllGroups()
1075 return colourAppliesToAllGroups;
1081 * @return DOCUMENT ME!
1083 public boolean getShowJVSuffix()
1085 return showJVSuffix;
1091 * @param b DOCUMENT ME!
1093 public void setShowJVSuffix(boolean b)
1102 * @return DOCUMENT ME!
1104 public boolean getShowAnnotation()
1106 return showAnnotation;
1112 * @param b DOCUMENT ME!
1114 public void setShowAnnotation(boolean b)
1122 * @return DOCUMENT ME!
1124 public boolean getScaleAboveWrapped()
1126 return scaleAboveWrapped;
1132 * @return DOCUMENT ME!
1134 public boolean getScaleLeftWrapped()
1136 return scaleLeftWrapped;
1142 * @return DOCUMENT ME!
1144 public boolean getScaleRightWrapped()
1146 return scaleRightWrapped;
1152 * @param b DOCUMENT ME!
1154 public void setScaleAboveWrapped(boolean b)
1156 scaleAboveWrapped = b;
1162 * @param b DOCUMENT ME!
1164 public void setScaleLeftWrapped(boolean b)
1166 scaleLeftWrapped = b;
1172 * @param b DOCUMENT ME!
1174 public void setScaleRightWrapped(boolean b)
1176 scaleRightWrapped = b;
1180 * Property change listener for changes in alignment
1182 * @param listener DOCUMENT ME!
1184 public void addPropertyChangeListener(
1185 java.beans.PropertyChangeListener listener)
1187 changeSupport.addPropertyChangeListener(listener);
1193 * @param listener DOCUMENT ME!
1195 public void removePropertyChangeListener(
1196 java.beans.PropertyChangeListener listener)
1198 changeSupport.removePropertyChangeListener(listener);
1202 * Property change listener for changes in alignment
1204 * @param prop DOCUMENT ME!
1205 * @param oldvalue DOCUMENT ME!
1206 * @param newvalue DOCUMENT ME!
1208 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
1210 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1213 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1215 ignoreGapsInConsensusCalculation = b;
1216 updateConsensus(ap);
1217 if(globalColourScheme!=null)
1219 globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);
1223 public boolean getIgnoreGapsConsensus()
1225 return ignoreGapsInConsensusCalculation;
1228 public void setDataset(boolean b)
1233 public boolean isDataset()
1239 public void hideSelectedColumns()
1241 if (colSel.size() < 1)
1244 colSel.hideSelectedColumns();
1245 setSelectionGroup(null);
1247 hasHiddenColumns = true;
1251 public void hideColumns(int start, int end)
1254 colSel.hideColumns(start);
1256 colSel.hideColumns(start, end);
1258 hasHiddenColumns = true;
1261 public void hideAllSelectedSeqs()
1263 if (selectionGroup == null)
1266 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1270 setSelectionGroup(null);
1273 public void hideSequence(SequenceI [] seq)
1277 for (int i = 0; i < seq.length; i++)
1278 alignment.getHiddenSequences().hideSequence(seq[i]);
1280 hasHiddenRows = true;
1281 firePropertyChange("alignment", null, alignment.getSequences());
1285 public void showSequence(int index)
1287 Vector tmp = alignment.getHiddenSequences().showSequence(index);
1290 if(selectionGroup==null)
1292 selectionGroup = new SequenceGroup();
1293 selectionGroup.setEndRes(alignment.getWidth()-1);
1296 for (int t = 0; t < tmp.size(); t++)
1298 selectionGroup.addSequence(
1299 (SequenceI) tmp.elementAt(t), false
1302 firePropertyChange("alignment", null, alignment.getSequences());
1305 if(alignment.getHiddenSequences().getSize()<1)
1306 hasHiddenRows = false;
1309 public void showColumn(int col)
1311 colSel.revealHiddenColumns(col);
1312 if(colSel.getHiddenColumns()==null)
1313 hasHiddenColumns = false;
1316 public void showAllHiddenColumns()
1318 colSel.revealAllHiddenColumns();
1319 hasHiddenColumns = false;
1322 public void showAllHiddenSeqs()
1324 if(alignment.getHiddenSequences().getSize()>0)
1326 if(selectionGroup==null)
1328 selectionGroup = new SequenceGroup();
1329 selectionGroup.setEndRes(alignment.getWidth()-1);
1331 Vector tmp = alignment.getHiddenSequences().showAll();
1332 for(int t=0; t<tmp.size(); t++)
1334 selectionGroup.addSequence(
1335 (SequenceI)tmp.elementAt(t), false
1338 firePropertyChange("alignment", null, alignment.getSequences());
1339 hasHiddenRows = false;
1343 public void invertColumnSelection()
1346 for(int i=0; i<alignment.getWidth(); i++)
1350 if(colSel.contains(column))
1351 colSel.removeElement(column);
1353 colSel.addElement(column);
1359 public int adjustForHiddenSeqs(int alignmentIndex)
1361 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
1365 * This method returns the a new SequenceI [] with
1366 * the selection sequence and start and end points adjusted
1369 public SequenceI[] getSelectionAsNewSequence()
1371 SequenceI[] sequences;
1373 if (selectionGroup == null)
1374 sequences = alignment.getSequencesArray();
1376 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1382 * This method returns the visible alignment as text, as
1383 * seen on the GUI, ie if columns are hidden they will not
1384 * be returned in the result.
1385 * Use this for calculating trees, PCA, redundancy etc on views
1386 * which contain hidden columns.
1389 public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)
1391 CigarArray selection=null;
1392 SequenceI [] seqs= null;
1394 int start = 0, end = 0;
1395 if(selectedRegionOnly && selectionGroup!=null)
1397 iSize = selectionGroup.getSize(false);
1398 seqs = selectionGroup.getSequencesInOrder(alignment);
1399 start = selectionGroup.getStartRes();
1400 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
1404 iSize = alignment.getHeight();
1405 seqs = alignment.getSequencesArray();
1406 end = alignment.getWidth()-1;
1408 SeqCigar[] selseqs = new SeqCigar[iSize];
1409 for(i=0; i<iSize; i++)
1411 selseqs[i] = new SeqCigar(seqs[i], start, end);
1413 selection=new CigarArray(selseqs);
1414 // now construct the CigarArray operations
1415 if (hasHiddenColumns) {
1416 Vector regions = colSel.getHiddenColumns();
1418 int hideStart, hideEnd;
1420 for (int j = 0; last<end & j < regions.size(); j++)
1422 region = (int[]) regions.elementAt(j);
1423 hideStart = region[0];
1424 hideEnd = region[1];
1425 // edit hidden regions to selection range
1426 if(hideStart<last) {
1440 if (hideStart>hideEnd)
1443 * form operations...
1446 selection.addOperation(CigarArray.M, hideStart-last);
1447 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
1450 // Final match if necessary.
1452 selection.addOperation(CigarArray.M, end-last+1);
1454 selection.addOperation(CigarArray.M, end-start+1);
1459 * return a compact representation of the current alignment selection to
1460 * pass to an analysis function
1461 * @param selectedOnly boolean true to just return the selected view
1462 * @return AlignmentView
1464 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {
1466 // this is here because the AlignmentView constructor modifies the CigarArray
1467 // object. Refactoring of Cigar and alignment view representation should
1468 // be done to remove redundancy.
1469 CigarArray aligview = getViewAsCigars(selectedOnly);
1470 if (aligview!=null) {
1471 return new AlignmentView(aligview,
1472 (selectedOnly && selectionGroup!=null) ? selectionGroup.getStartRes() : 0);
1477 * This method returns the visible alignment as text, as
1478 * seen on the GUI, ie if columns are hidden they will not
1479 * be returned in the result.
1480 * Use this for calculating trees, PCA, redundancy etc on views
1481 * which contain hidden columns.
1484 public String [] getViewAsString(boolean selectedRegionOnly)
1486 String [] selection = null;
1487 SequenceI [] seqs= null;
1489 int start = 0, end = 0;
1490 if(selectedRegionOnly && selectionGroup!=null)
1492 iSize = selectionGroup.getSize(false);
1493 seqs = selectionGroup.getSequencesInOrder(alignment);
1494 start = selectionGroup.getStartRes();
1495 end = selectionGroup.getEndRes()+1;
1499 iSize = alignment.getHeight();
1500 seqs = alignment.getSequencesArray();
1501 end = alignment.getWidth();
1504 selection = new String[iSize];
1505 if (hasHiddenColumns) {
1506 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1508 for(i=0; i<iSize; i++)
1510 selection[i] = seqs[i].getSequence(start, end);
1517 public boolean getShowHiddenMarkers()
1519 return showHiddenMarkers;
1522 public void setShowHiddenMarkers(boolean show)
1524 showHiddenMarkers = show;
1527 public String getSequenceSetId()
1529 if(sequenceSetID==null)
1530 sequenceSetID = alignment.hashCode()+"";
1532 return sequenceSetID;
1535 public void alignmentChanged(AlignmentPanel ap)
1538 alignment.padGaps();
1540 if (hconsensus != null && autoCalculateConsensus)
1542 updateConsensus(ap);
1543 updateConservation(ap);
1546 //Reset endRes of groups if beyond alignment width
1547 int alWidth = alignment.getWidth();
1548 Vector groups = alignment.getGroups();
1551 for(int i=0; i<groups.size(); i++)
1553 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
1554 if(sg.getEndRes()>alWidth)
1555 sg.setEndRes(alWidth-1);
1559 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
1560 selectionGroup.setEndRes(alWidth-1);
1562 resetAllColourSchemes();
1564 alignment.adjustSequenceAnnotations();
1568 void resetAllColourSchemes()
1570 ColourSchemeI cs = globalColourScheme;
1573 if (cs instanceof ClustalxColourScheme)
1575 ( (ClustalxColourScheme) cs).
1576 resetClustalX(alignment.getSequences(),
1577 alignment.getWidth());
1580 cs.setConsensus(hconsensus);
1581 if (cs.conservationApplied())
1583 Alignment al = (Alignment) alignment;
1584 Conservation c = new Conservation("All",
1585 ResidueProperties.propHash, 3,
1586 al.getSequences(), 0,
1589 c.verdict(false, ConsPercGaps);
1591 cs.setConservation(c);
1595 int s, sSize = alignment.getGroups().size();
1596 for(s=0; s<sSize; s++)
1598 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
1599 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1601 ((ClustalxColourScheme)sg.cs).resetClustalX(
1602 sg.getSequences(true), sg.getWidth());
1604 sg.recalcConservation();
1609 public Color getSequenceColour(SequenceI seq)
1611 if(sequenceColours==null || !sequenceColours.containsKey(seq))
1614 return (Color)sequenceColours.get(seq);
1617 public void setSequenceColour(SequenceI seq, Color col)
1619 if(sequenceColours==null)
1620 sequenceColours = new Hashtable();
1623 sequenceColours.remove(seq);
1625 sequenceColours.put(seq, col);