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;
121 boolean idsAlignRight = false;
125 * Creates a new AlignViewport object.
127 * @param al DOCUMENT ME!
129 public AlignViewport(AlignmentI al)
135 * Create a new AlignViewport with hidden regions
136 * @param al AlignmentI
137 * @param hiddenColumns ColumnSelection
139 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) {
141 if (hiddenColumns!=null) {
142 this.colSel = hiddenColumns;
143 if (hiddenColumns.getHiddenColumns() != null)
144 hasHiddenColumns = true;
152 this.endRes = alignment.getWidth() - 1;
154 this.endSeq = alignment.getHeight() - 1;
156 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
158 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
159 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
161 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
163 padGaps = Cache.getDefault("PAD_GAPS", true);
165 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
166 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;
167 String fontSize = Cache.getDefault("FONT_SIZE", "10");
171 if (fontStyle.equals("bold"))
175 else if (fontStyle.equals("italic"))
180 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
182 alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );
185 // We must set conservation and consensus before setting colour,
186 // as Blosum and Clustal require this to be done
187 if(hconsensus==null && !isDataset)
189 if(!alignment.isNucleotide())
191 conservation = new AlignmentAnnotation("Conservation",
192 "Conservation of total alignment less than " +
193 ConsPercGaps + "% gaps",
194 new Annotation[1], 0f,
196 AlignmentAnnotation.BAR_GRAPH);
197 conservation.hasText = true;
200 if (Cache.getDefault("SHOW_CONSERVATION", true))
202 alignment.addAnnotation(conservation);
205 if (Cache.getDefault("SHOW_QUALITY", true))
207 quality = new AlignmentAnnotation("Quality",
208 "Alignment Quality based on Blosum62 scores",
212 AlignmentAnnotation.BAR_GRAPH);
213 quality.hasText = true;
215 alignment.addAnnotation(quality);
219 consensus = new AlignmentAnnotation("Consensus", "PID",
220 new Annotation[1], 0f, 100f,
221 AlignmentAnnotation.BAR_GRAPH);
222 consensus.hasText = true;
224 if (Cache.getDefault("SHOW_IDENTITY", true))
226 alignment.addAnnotation(consensus);
230 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
232 globalColourScheme = ColourSchemeProperty.getColour(alignment,
233 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
235 if (globalColourScheme instanceof UserColourScheme)
237 globalColourScheme = UserDefinedColours.loadDefaultColours();
238 ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());
241 if (globalColourScheme != null)
243 globalColourScheme.setConsensus(hconsensus);
247 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
255 * @param b DOCUMENT ME!
257 public void setShowSequenceFeatures(boolean b)
259 showSequenceFeatures = b;
262 public boolean getShowSequenceFeatures()
264 return showSequenceFeatures;
269 class ConservationThread extends Thread
272 public ConservationThread(AlignmentPanel ap)
281 updatingConservation = true;
283 while (UPDATING_CONSERVATION)
295 ex.printStackTrace();
299 UPDATING_CONSERVATION = true;
302 int alWidth = alignment.getWidth();
306 Conservation cons = new jalview.analysis.Conservation("All",
307 jalview.schemes.ResidueProperties.propHash, 3,
308 alignment.getSequences(), 0, alWidth -1);
311 cons.verdict(false, ConsPercGaps);
318 String sequence = cons.getConsSequence().getSequence();
330 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
339 conservation.annotations = new Annotation[alWidth];
343 quality.graphMax = cons.qualityRange[1].floatValue();
344 quality.annotations = new Annotation[alWidth];
345 qmin = cons.qualityRange[0].floatValue();
346 qmax = cons.qualityRange[1].floatValue();
349 for (int i = 0; i < alWidth; i++)
353 c = sequence.charAt(i);
355 if (Character.isDigit(c))
356 value = (int) (c - '0');
362 float vprop = value - min;
364 conservation.annotations[i] =
365 new Annotation(String.valueOf(c),
366 String.valueOf(value), ' ', value,
367 new Color(minR + (maxR * vprop),
368 minG + (maxG * vprop),
369 minB + (maxB * vprop)));
374 value = ( (Double) cons.quality.get(i)).floatValue();
375 vprop = value - qmin;
377 quality.annotations[i] = new Annotation(" ", String.valueOf(value), ' ',
379 new Color(minR + (maxR * vprop),
380 minG + (maxG * vprop),
381 minB + (maxB * vprop)));
385 catch (OutOfMemoryError error)
387 javax.swing.SwingUtilities.invokeLater(new Runnable()
393 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
394 "Out of memory calculating conservation!!"
396 "\nSee help files for increasing Java Virtual Machine memory."
398 javax.swing.JOptionPane.WARNING_MESSAGE);
405 System.out.println("Conservation calculation: " + error);
410 UPDATING_CONSERVATION = false;
411 updatingConservation = false;
422 ConservationThread conservationThread;
424 ConsensusThread consensusThread;
426 boolean consUpdateNeeded = false;
428 static boolean UPDATING_CONSENSUS = false;
430 static boolean UPDATING_CONSERVATION = false;
432 boolean updatingConsensus = false;
434 boolean updatingConservation = false;
439 public void updateConservation(final AlignmentPanel ap)
441 if (alignment.isNucleotide() || conservation==null)
444 conservationThread = new ConservationThread(ap);
445 conservationThread.start();
451 public void updateConsensus(final AlignmentPanel ap)
453 consensusThread = new ConsensusThread(ap);
454 consensusThread.start();
458 class ConsensusThread extends Thread
461 public ConsensusThread(AlignmentPanel ap)
467 updatingConsensus = true;
468 while (UPDATING_CONSENSUS)
481 ex.printStackTrace();
486 UPDATING_CONSENSUS = true;
490 int aWidth = alignment.getWidth();
494 consensus.annotations = null;
495 consensus.annotations = new Annotation[aWidth];
498 hconsensus = new Hashtable[aWidth];
499 AAFrequency.calculate(alignment.getSequencesArray(),
501 alignment.getWidth(),
504 for (int i = 0; i < aWidth; i++)
507 if (ignoreGapsInConsensusCalculation)
508 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
511 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
514 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
515 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
517 if (maxRes.length() > 1)
519 mouseOver = "[" + maxRes + "] ";
523 mouseOver += ( (int) value + "%");
524 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
528 if (globalColourScheme != null)
529 globalColourScheme.setConsensus(hconsensus);
532 catch (OutOfMemoryError error)
534 alignment.deleteAnnotation(consensus);
538 javax.swing.SwingUtilities.invokeLater(new Runnable()
542 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
543 "Out of memory calculating consensus!!"
545 "\nSee help files for increasing Java Virtual Machine memory."
547 javax.swing.JOptionPane.WARNING_MESSAGE);
551 System.out.println("Consensus calculation: " + error);
554 UPDATING_CONSENSUS = false;
555 updatingConsensus = false;
564 * get the consensus sequence as displayed under the PID consensus annotation row.
565 * @return consensus sequence as a new sequence object
567 public SequenceI getConsensusSeq() {
569 updateConsensus(null);
572 StringBuffer seqs=new StringBuffer();
573 for (int i=0; i<consensus.annotations.length; i++) {
574 if (consensus.annotations[i]!=null) {
575 if (consensus.annotations[i].description.charAt(0) == '[')
576 seqs.append(consensus.annotations[i].description.charAt(1));
578 seqs.append(consensus.annotations[i].displayCharacter);
582 SequenceI sq = new Sequence("Consensus", seqs.toString());
583 sq.setDescription("Percentage Identity Consensus "+((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
589 * @return DOCUMENT ME!
591 public SequenceGroup getSelectionGroup()
593 return selectionGroup;
599 * @param sg DOCUMENT ME!
601 public void setSelectionGroup(SequenceGroup sg)
609 * @return DOCUMENT ME!
611 public boolean getConservationSelected()
613 return conservationColourSelected;
619 * @param b DOCUMENT ME!
621 public void setConservationSelected(boolean b)
623 conservationColourSelected = b;
629 * @return DOCUMENT ME!
631 public boolean getAbovePIDThreshold()
633 return abovePIDThreshold;
639 * @param b DOCUMENT ME!
641 public void setAbovePIDThreshold(boolean b)
643 abovePIDThreshold = b;
649 * @return DOCUMENT ME!
651 public int getStartRes()
659 * @return DOCUMENT ME!
661 public int getEndRes()
669 * @return DOCUMENT ME!
671 public int getStartSeq()
679 * @param cs DOCUMENT ME!
681 public void setGlobalColourScheme(ColourSchemeI cs)
683 globalColourScheme = cs;
689 * @return DOCUMENT ME!
691 public ColourSchemeI getGlobalColourScheme()
693 return globalColourScheme;
699 * @param res DOCUMENT ME!
701 public void setStartRes(int res)
709 * @param seq DOCUMENT ME!
711 public void setStartSeq(int seq)
719 * @param res DOCUMENT ME!
721 public void setEndRes(int res)
723 if (res > (alignment.getWidth() - 1))
725 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
726 res = alignment.getWidth() - 1;
740 * @param seq DOCUMENT ME!
742 public void setEndSeq(int seq)
744 if (seq > alignment.getHeight())
746 seq = alignment.getHeight();
760 * @return DOCUMENT ME!
762 public int getEndSeq()
770 * @param f DOCUMENT ME!
772 public void setFont(Font f)
776 Container c = new Container();
778 java.awt.FontMetrics fm = c.getFontMetrics(font);
779 setCharHeight(fm.getHeight());
780 setCharWidth(fm.charWidth('M'));
781 validCharWidth = true;
787 * @return DOCUMENT ME!
789 public Font getFont()
797 * @param w DOCUMENT ME!
799 public void setCharWidth(int w)
807 * @return DOCUMENT ME!
809 public int getCharWidth()
817 * @param h DOCUMENT ME!
819 public void setCharHeight(int h)
827 * @return DOCUMENT ME!
829 public int getCharHeight()
837 * @param w DOCUMENT ME!
839 public void setWrappedWidth(int w)
841 this.wrappedWidth = w;
847 * @return DOCUMENT ME!
849 public int getWrappedWidth()
858 * @return DOCUMENT ME!
860 public AlignmentI getAlignment()
868 * @param align DOCUMENT ME!
870 public void setAlignment(AlignmentI align)
872 this.alignment = align;
878 * @param state DOCUMENT ME!
880 public void setWrapAlignment(boolean state)
882 wrapAlignment = state;
888 * @param state DOCUMENT ME!
890 public void setShowText(boolean state)
898 * @param state DOCUMENT ME!
900 public void setRenderGaps(boolean state)
908 * @return DOCUMENT ME!
910 public boolean getColourText()
912 return showColourText;
918 * @param state DOCUMENT ME!
920 public void setColourText(boolean state)
922 showColourText = state;
928 * @param state DOCUMENT ME!
930 public void setShowBoxes(boolean state)
938 * @return DOCUMENT ME!
940 public boolean getWrapAlignment()
942 return wrapAlignment;
948 * @return DOCUMENT ME!
950 public boolean getShowText()
958 * @return DOCUMENT ME!
960 public boolean getShowBoxes()
968 * @return DOCUMENT ME!
970 public char getGapCharacter()
972 return getAlignment().getGapCharacter();
978 * @param gap DOCUMENT ME!
980 public void setGapCharacter(char gap)
982 if (getAlignment() != null)
984 getAlignment().setGapCharacter(gap);
991 * @param thresh DOCUMENT ME!
993 public void setThreshold(int thresh)
1001 * @return DOCUMENT ME!
1003 public int getThreshold()
1011 * @param inc DOCUMENT ME!
1013 public void setIncrement(int inc)
1021 * @return DOCUMENT ME!
1023 public int getIncrement()
1032 * @return DOCUMENT ME!
1034 public ColumnSelection getColumnSelection()
1043 * @param tree DOCUMENT ME!
1045 public void setCurrentTree(NJTree tree)
1053 * @return DOCUMENT ME!
1055 public NJTree getCurrentTree()
1063 * @param b DOCUMENT ME!
1065 public void setColourAppliesToAllGroups(boolean b)
1067 colourAppliesToAllGroups = b;
1073 * @return DOCUMENT ME!
1075 public boolean getColourAppliesToAllGroups()
1077 return colourAppliesToAllGroups;
1083 * @return DOCUMENT ME!
1085 public boolean getShowJVSuffix()
1087 return showJVSuffix;
1093 * @param b DOCUMENT ME!
1095 public void setShowJVSuffix(boolean b)
1104 * @return DOCUMENT ME!
1106 public boolean getShowAnnotation()
1108 return showAnnotation;
1114 * @param b DOCUMENT ME!
1116 public void setShowAnnotation(boolean b)
1124 * @return DOCUMENT ME!
1126 public boolean getScaleAboveWrapped()
1128 return scaleAboveWrapped;
1134 * @return DOCUMENT ME!
1136 public boolean getScaleLeftWrapped()
1138 return scaleLeftWrapped;
1144 * @return DOCUMENT ME!
1146 public boolean getScaleRightWrapped()
1148 return scaleRightWrapped;
1154 * @param b DOCUMENT ME!
1156 public void setScaleAboveWrapped(boolean b)
1158 scaleAboveWrapped = b;
1164 * @param b DOCUMENT ME!
1166 public void setScaleLeftWrapped(boolean b)
1168 scaleLeftWrapped = b;
1174 * @param b DOCUMENT ME!
1176 public void setScaleRightWrapped(boolean b)
1178 scaleRightWrapped = b;
1182 * Property change listener for changes in alignment
1184 * @param listener DOCUMENT ME!
1186 public void addPropertyChangeListener(
1187 java.beans.PropertyChangeListener listener)
1189 changeSupport.addPropertyChangeListener(listener);
1195 * @param listener DOCUMENT ME!
1197 public void removePropertyChangeListener(
1198 java.beans.PropertyChangeListener listener)
1200 changeSupport.removePropertyChangeListener(listener);
1204 * Property change listener for changes in alignment
1206 * @param prop DOCUMENT ME!
1207 * @param oldvalue DOCUMENT ME!
1208 * @param newvalue DOCUMENT ME!
1210 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
1212 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1215 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1217 ignoreGapsInConsensusCalculation = b;
1218 updateConsensus(ap);
1219 if(globalColourScheme!=null)
1221 globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);
1225 public boolean getIgnoreGapsConsensus()
1227 return ignoreGapsInConsensusCalculation;
1230 public void setDataset(boolean b)
1235 public boolean isDataset()
1241 public void hideSelectedColumns()
1243 if (colSel.size() < 1)
1246 colSel.hideSelectedColumns();
1247 setSelectionGroup(null);
1249 hasHiddenColumns = true;
1253 public void hideColumns(int start, int end)
1256 colSel.hideColumns(start);
1258 colSel.hideColumns(start, end);
1260 hasHiddenColumns = true;
1263 public void hideAllSelectedSeqs()
1265 if (selectionGroup == null)
1268 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1272 setSelectionGroup(null);
1275 public void hideSequence(SequenceI [] seq)
1279 for (int i = 0; i < seq.length; i++)
1280 alignment.getHiddenSequences().hideSequence(seq[i]);
1282 hasHiddenRows = true;
1283 firePropertyChange("alignment", null, alignment.getSequences());
1287 public void showSequence(int index)
1289 Vector tmp = alignment.getHiddenSequences().showSequence(index);
1292 if(selectionGroup==null)
1294 selectionGroup = new SequenceGroup();
1295 selectionGroup.setEndRes(alignment.getWidth()-1);
1298 for (int t = 0; t < tmp.size(); t++)
1300 selectionGroup.addSequence(
1301 (SequenceI) tmp.elementAt(t), false
1304 firePropertyChange("alignment", null, alignment.getSequences());
1307 if(alignment.getHiddenSequences().getSize()<1)
1308 hasHiddenRows = false;
1311 public void showColumn(int col)
1313 colSel.revealHiddenColumns(col);
1314 if(colSel.getHiddenColumns()==null)
1315 hasHiddenColumns = false;
1318 public void showAllHiddenColumns()
1320 colSel.revealAllHiddenColumns();
1321 hasHiddenColumns = false;
1324 public void showAllHiddenSeqs()
1326 if(alignment.getHiddenSequences().getSize()>0)
1328 if(selectionGroup==null)
1330 selectionGroup = new SequenceGroup();
1331 selectionGroup.setEndRes(alignment.getWidth()-1);
1333 Vector tmp = alignment.getHiddenSequences().showAll();
1334 for(int t=0; t<tmp.size(); t++)
1336 selectionGroup.addSequence(
1337 (SequenceI)tmp.elementAt(t), false
1340 firePropertyChange("alignment", null, alignment.getSequences());
1341 hasHiddenRows = false;
1345 public void invertColumnSelection()
1348 for(int i=0; i<alignment.getWidth(); i++)
1352 if(colSel.contains(column))
1353 colSel.removeElement(column);
1355 colSel.addElement(column);
1361 public int adjustForHiddenSeqs(int alignmentIndex)
1363 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
1367 * This method returns the a new SequenceI [] with
1368 * the selection sequence and start and end points adjusted
1371 public SequenceI[] getSelectionAsNewSequence()
1373 SequenceI[] sequences;
1375 if (selectionGroup == null)
1376 sequences = alignment.getSequencesArray();
1378 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1384 * This method returns the visible alignment as text, as
1385 * seen on the GUI, ie if columns are hidden they will not
1386 * be returned in the result.
1387 * Use this for calculating trees, PCA, redundancy etc on views
1388 * which contain hidden columns.
1391 public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)
1393 CigarArray selection=null;
1394 SequenceI [] seqs= null;
1396 int start = 0, end = 0;
1397 if(selectedRegionOnly && selectionGroup!=null)
1399 iSize = selectionGroup.getSize(false);
1400 seqs = selectionGroup.getSequencesInOrder(alignment);
1401 start = selectionGroup.getStartRes();
1402 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
1406 iSize = alignment.getHeight();
1407 seqs = alignment.getSequencesArray();
1408 end = alignment.getWidth()-1;
1410 SeqCigar[] selseqs = new SeqCigar[iSize];
1411 for(i=0; i<iSize; i++)
1413 selseqs[i] = new SeqCigar(seqs[i], start, end);
1415 selection=new CigarArray(selseqs);
1416 // now construct the CigarArray operations
1417 if (hasHiddenColumns) {
1418 Vector regions = colSel.getHiddenColumns();
1420 int hideStart, hideEnd;
1422 for (int j = 0; last<end & j < regions.size(); j++)
1424 region = (int[]) regions.elementAt(j);
1425 hideStart = region[0];
1426 hideEnd = region[1];
1427 // edit hidden regions to selection range
1428 if(hideStart<last) {
1442 if (hideStart>hideEnd)
1445 * form operations...
1448 selection.addOperation(CigarArray.M, hideStart-last);
1449 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
1452 // Final match if necessary.
1454 selection.addOperation(CigarArray.M, end-last+1);
1456 selection.addOperation(CigarArray.M, end-start+1);
1461 * return a compact representation of the current alignment selection to
1462 * pass to an analysis function
1463 * @param selectedOnly boolean true to just return the selected view
1464 * @return AlignmentView
1466 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {
1468 // this is here because the AlignmentView constructor modifies the CigarArray
1469 // object. Refactoring of Cigar and alignment view representation should
1470 // be done to remove redundancy.
1471 CigarArray aligview = getViewAsCigars(selectedOnly);
1472 if (aligview!=null) {
1473 return new AlignmentView(aligview,
1474 (selectedOnly && selectionGroup!=null) ? selectionGroup.getStartRes() : 0);
1479 * This method returns the visible alignment as text, as
1480 * seen on the GUI, ie if columns are hidden they will not
1481 * be returned in the result.
1482 * Use this for calculating trees, PCA, redundancy etc on views
1483 * which contain hidden columns.
1486 public String [] getViewAsString(boolean selectedRegionOnly)
1488 String [] selection = null;
1489 SequenceI [] seqs= null;
1491 int start = 0, end = 0;
1492 if(selectedRegionOnly && selectionGroup!=null)
1494 iSize = selectionGroup.getSize(false);
1495 seqs = selectionGroup.getSequencesInOrder(alignment);
1496 start = selectionGroup.getStartRes();
1497 end = selectionGroup.getEndRes()+1;
1501 iSize = alignment.getHeight();
1502 seqs = alignment.getSequencesArray();
1503 end = alignment.getWidth();
1506 selection = new String[iSize];
1507 if (hasHiddenColumns) {
1508 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1510 for(i=0; i<iSize; i++)
1512 selection[i] = seqs[i].getSequence(start, end);
1519 public boolean getShowHiddenMarkers()
1521 return showHiddenMarkers;
1524 public void setShowHiddenMarkers(boolean show)
1526 showHiddenMarkers = show;
1529 public String getSequenceSetId()
1531 if(sequenceSetID==null)
1532 sequenceSetID = alignment.hashCode()+"";
1534 return sequenceSetID;
1537 public void alignmentChanged(AlignmentPanel ap)
1540 alignment.padGaps();
1542 if (hconsensus != null && autoCalculateConsensus)
1544 updateConsensus(ap);
1545 updateConservation(ap);
1548 //Reset endRes of groups if beyond alignment width
1549 int alWidth = alignment.getWidth();
1550 Vector groups = alignment.getGroups();
1553 for(int i=0; i<groups.size(); i++)
1555 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
1556 if(sg.getEndRes()>alWidth)
1557 sg.setEndRes(alWidth-1);
1561 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
1562 selectionGroup.setEndRes(alWidth-1);
1564 resetAllColourSchemes();
1566 alignment.adjustSequenceAnnotations();
1570 void resetAllColourSchemes()
1572 ColourSchemeI cs = globalColourScheme;
1575 if (cs instanceof ClustalxColourScheme)
1577 ( (ClustalxColourScheme) cs).
1578 resetClustalX(alignment.getSequences(),
1579 alignment.getWidth());
1582 cs.setConsensus(hconsensus);
1583 if (cs.conservationApplied())
1585 Alignment al = (Alignment) alignment;
1586 Conservation c = new Conservation("All",
1587 ResidueProperties.propHash, 3,
1588 al.getSequences(), 0,
1591 c.verdict(false, ConsPercGaps);
1593 cs.setConservation(c);
1597 int s, sSize = alignment.getGroups().size();
1598 for(s=0; s<sSize; s++)
1600 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
1601 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1603 ((ClustalxColourScheme)sg.cs).resetClustalX(
1604 sg.getSequences(true), sg.getWidth());
1606 sg.recalcConservation();
1611 public Color getSequenceColour(SequenceI seq)
1613 if(sequenceColours==null || !sequenceColours.containsKey(seq))
1616 return (Color)sequenceColours.get(seq);
1619 public void setSequenceColour(SequenceI seq, Color col)
1621 if(sequenceColours==null)
1622 sequenceColours = new Hashtable();
1625 sequenceColours.remove(seq);
1627 sequenceColours.put(seq, col);