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();
116 * Creates a new AlignViewport object.
118 * @param al DOCUMENT ME!
120 public AlignViewport(AlignmentI al)
126 * Create a new AlignViewport with hidden regions
127 * @param al AlignmentI
128 * @param hiddenColumns ColumnSelection
130 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) {
132 if (hiddenColumns!=null) {
133 this.colSel = hiddenColumns;
134 if (hiddenColumns.getHiddenColumns() != null)
135 hasHiddenColumns = true;
143 this.endRes = alignment.getWidth() - 1;
145 this.endSeq = alignment.getHeight() - 1;
147 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
149 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
150 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
152 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
154 padGaps = Cache.getDefault("PAD_GAPS", true);
156 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
157 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;
158 String fontSize = Cache.getDefault("FONT_SIZE", "10");
162 if (fontStyle.equals("bold"))
166 else if (fontStyle.equals("italic"))
171 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
173 alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );
176 // We must set conservation and consensus before setting colour,
177 // as Blosum and Clustal require this to be done
178 if(hconsensus==null && !isDataset)
180 if(!alignment.isNucleotide())
182 conservation = new AlignmentAnnotation("Conservation",
183 "Conservation of total alignment less than " +
184 ConsPercGaps + "% gaps",
185 new Annotation[1], 0f,
187 AlignmentAnnotation.BAR_GRAPH);
188 conservation.hasText = true;
191 if (Cache.getDefault("SHOW_CONSERVATION", true))
193 alignment.addAnnotation(conservation);
196 if (Cache.getDefault("SHOW_QUALITY", true))
198 quality = new AlignmentAnnotation("Quality",
199 "Alignment Quality based on Blosum62 scores",
203 AlignmentAnnotation.BAR_GRAPH);
204 quality.hasText = true;
206 alignment.addAnnotation(quality);
210 consensus = new AlignmentAnnotation("Consensus", "PID",
211 new Annotation[1], 0f, 100f,
212 AlignmentAnnotation.BAR_GRAPH);
213 consensus.hasText = true;
215 if (Cache.getDefault("SHOW_IDENTITY", true))
217 alignment.addAnnotation(consensus);
221 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
223 globalColourScheme = ColourSchemeProperty.getColour(alignment,
224 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
226 if (globalColourScheme instanceof UserColourScheme)
228 globalColourScheme = UserDefinedColours.loadDefaultColours();
229 ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());
232 if (globalColourScheme != null)
234 globalColourScheme.setConsensus(hconsensus);
238 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
246 * @param b DOCUMENT ME!
248 public void setShowSequenceFeatures(boolean b)
250 showSequenceFeatures = b;
253 public boolean getShowSequenceFeatures()
255 return showSequenceFeatures;
260 class ConservationThread extends Thread
263 public ConservationThread(AlignmentPanel ap)
272 updatingConservation = true;
274 while (UPDATING_CONSERVATION)
286 ex.printStackTrace();
290 UPDATING_CONSERVATION = true;
293 int alWidth = alignment.getWidth();
297 Conservation cons = new jalview.analysis.Conservation("All",
298 jalview.schemes.ResidueProperties.propHash, 3,
299 alignment.getSequences(), 0, alWidth -1);
302 cons.verdict(false, ConsPercGaps);
309 String sequence = cons.getConsSequence().getSequence();
321 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
330 conservation.annotations = new Annotation[alWidth];
334 quality.graphMax = cons.qualityRange[1].floatValue();
335 quality.annotations = new Annotation[alWidth];
336 qmin = cons.qualityRange[0].floatValue();
337 qmax = cons.qualityRange[1].floatValue();
340 for (int i = 0; i < alWidth; i++)
344 c = sequence.charAt(i);
346 if (Character.isDigit(c))
347 value = (int) (c - '0');
353 float vprop = value - min;
355 conservation.annotations[i] =
356 new Annotation(String.valueOf(c),
357 String.valueOf(value), ' ', value,
358 new Color(minR + (maxR * vprop),
359 minG + (maxG * vprop),
360 minB + (maxB * vprop)));
365 value = ( (Double) cons.quality.get(i)).floatValue();
366 vprop = value - qmin;
368 quality.annotations[i] = new Annotation(" ", String.valueOf(value), ' ',
370 new Color(minR + (maxR * vprop),
371 minG + (maxG * vprop),
372 minB + (maxB * vprop)));
376 catch (OutOfMemoryError error)
378 javax.swing.SwingUtilities.invokeLater(new Runnable()
384 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
385 "Out of memory calculating conservation!!"
387 "\nSee help files for increasing Java Virtual Machine memory."
389 javax.swing.JOptionPane.WARNING_MESSAGE);
396 System.out.println("Conservation calculation: " + error);
401 UPDATING_CONSERVATION = false;
402 updatingConservation = false;
413 ConservationThread conservationThread;
415 ConsensusThread consensusThread;
417 boolean consUpdateNeeded = false;
419 static boolean UPDATING_CONSENSUS = false;
421 static boolean UPDATING_CONSERVATION = false;
423 boolean updatingConsensus = false;
425 boolean updatingConservation = false;
430 public void updateConservation(final AlignmentPanel ap)
432 if (alignment.isNucleotide() || conservation==null)
435 conservationThread = new ConservationThread(ap);
436 conservationThread.start();
442 public void updateConsensus(final AlignmentPanel ap)
444 consensusThread = new ConsensusThread(ap);
445 consensusThread.start();
449 class ConsensusThread extends Thread
452 public ConsensusThread(AlignmentPanel ap)
458 updatingConsensus = true;
459 while (UPDATING_CONSENSUS)
472 ex.printStackTrace();
477 UPDATING_CONSENSUS = true;
481 int aWidth = alignment.getWidth();
485 consensus.annotations = null;
486 consensus.annotations = new Annotation[aWidth];
489 hconsensus = new Hashtable[aWidth];
490 AAFrequency.calculate(alignment.getSequencesArray(),
492 alignment.getWidth(),
495 for (int i = 0; i < aWidth; i++)
498 if (ignoreGapsInConsensusCalculation)
499 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
502 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
505 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
506 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
508 if (maxRes.length() > 1)
510 mouseOver = "[" + maxRes + "] ";
514 mouseOver += ( (int) value + "%");
515 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
519 if (globalColourScheme != null)
520 globalColourScheme.setConsensus(hconsensus);
523 catch (OutOfMemoryError error)
525 alignment.deleteAnnotation(consensus);
529 javax.swing.SwingUtilities.invokeLater(new Runnable()
533 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
534 "Out of memory calculating consensus!!"
536 "\nSee help files for increasing Java Virtual Machine memory."
538 javax.swing.JOptionPane.WARNING_MESSAGE);
542 System.out.println("Consensus calculation: " + error);
545 UPDATING_CONSENSUS = false;
546 updatingConsensus = false;
555 * get the consensus sequence as displayed under the PID consensus annotation row.
556 * @return consensus sequence as a new sequence object
558 public SequenceI getConsensusSeq() {
560 updateConsensus(null);
563 StringBuffer seqs=new StringBuffer();
564 for (int i=0; i<consensus.annotations.length; i++) {
565 if (consensus.annotations[i]!=null) {
566 if (consensus.annotations[i].description.charAt(0) == '[')
567 seqs.append(consensus.annotations[i].description.charAt(1));
569 seqs.append(consensus.annotations[i].displayCharacter);
573 SequenceI sq = new Sequence("Consensus", seqs.toString());
574 sq.setDescription("Percentage Identity Consensus "+((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
580 * @return DOCUMENT ME!
582 public SequenceGroup getSelectionGroup()
584 return selectionGroup;
590 * @param sg DOCUMENT ME!
592 public void setSelectionGroup(SequenceGroup sg)
600 * @return DOCUMENT ME!
602 public boolean getConservationSelected()
604 return conservationColourSelected;
610 * @param b DOCUMENT ME!
612 public void setConservationSelected(boolean b)
614 conservationColourSelected = b;
620 * @return DOCUMENT ME!
622 public boolean getAbovePIDThreshold()
624 return abovePIDThreshold;
630 * @param b DOCUMENT ME!
632 public void setAbovePIDThreshold(boolean b)
634 abovePIDThreshold = b;
640 * @return DOCUMENT ME!
642 public int getStartRes()
650 * @return DOCUMENT ME!
652 public int getEndRes()
660 * @return DOCUMENT ME!
662 public int getStartSeq()
670 * @param cs DOCUMENT ME!
672 public void setGlobalColourScheme(ColourSchemeI cs)
674 globalColourScheme = cs;
680 * @return DOCUMENT ME!
682 public ColourSchemeI getGlobalColourScheme()
684 return globalColourScheme;
690 * @param res DOCUMENT ME!
692 public void setStartRes(int res)
700 * @param seq DOCUMENT ME!
702 public void setStartSeq(int seq)
710 * @param res DOCUMENT ME!
712 public void setEndRes(int res)
714 if (res > (alignment.getWidth() - 1))
716 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
717 res = alignment.getWidth() - 1;
731 * @param seq DOCUMENT ME!
733 public void setEndSeq(int seq)
735 if (seq > alignment.getHeight())
737 seq = alignment.getHeight();
751 * @return DOCUMENT ME!
753 public int getEndSeq()
761 * @param f DOCUMENT ME!
763 public void setFont(Font f)
767 Container c = new Container();
769 java.awt.FontMetrics fm = c.getFontMetrics(font);
770 setCharHeight(fm.getHeight());
771 setCharWidth(fm.charWidth('M'));
772 validCharWidth = true;
778 * @return DOCUMENT ME!
780 public Font getFont()
788 * @param w DOCUMENT ME!
790 public void setCharWidth(int w)
798 * @return DOCUMENT ME!
800 public int getCharWidth()
808 * @param h DOCUMENT ME!
810 public void setCharHeight(int h)
818 * @return DOCUMENT ME!
820 public int getCharHeight()
828 * @param w DOCUMENT ME!
830 public void setWrappedWidth(int w)
832 this.wrappedWidth = w;
838 * @return DOCUMENT ME!
840 public int getWrappedWidth()
849 * @return DOCUMENT ME!
851 public AlignmentI getAlignment()
859 * @param align DOCUMENT ME!
861 public void setAlignment(AlignmentI align)
863 this.alignment = align;
869 * @param state DOCUMENT ME!
871 public void setWrapAlignment(boolean state)
873 wrapAlignment = state;
879 * @param state DOCUMENT ME!
881 public void setShowText(boolean state)
889 * @param state DOCUMENT ME!
891 public void setRenderGaps(boolean state)
899 * @return DOCUMENT ME!
901 public boolean getColourText()
903 return showColourText;
909 * @param state DOCUMENT ME!
911 public void setColourText(boolean state)
913 showColourText = state;
919 * @param state DOCUMENT ME!
921 public void setShowBoxes(boolean state)
929 * @return DOCUMENT ME!
931 public boolean getWrapAlignment()
933 return wrapAlignment;
939 * @return DOCUMENT ME!
941 public boolean getShowText()
949 * @return DOCUMENT ME!
951 public boolean getShowBoxes()
959 * @return DOCUMENT ME!
961 public char getGapCharacter()
963 return getAlignment().getGapCharacter();
969 * @param gap DOCUMENT ME!
971 public void setGapCharacter(char gap)
973 if (getAlignment() != null)
975 getAlignment().setGapCharacter(gap);
982 * @param thresh DOCUMENT ME!
984 public void setThreshold(int thresh)
992 * @return DOCUMENT ME!
994 public int getThreshold()
1002 * @param inc DOCUMENT ME!
1004 public void setIncrement(int inc)
1012 * @return DOCUMENT ME!
1014 public int getIncrement()
1023 * @return DOCUMENT ME!
1025 public ColumnSelection getColumnSelection()
1034 * @param tree DOCUMENT ME!
1036 public void setCurrentTree(NJTree tree)
1044 * @return DOCUMENT ME!
1046 public NJTree getCurrentTree()
1054 * @param b DOCUMENT ME!
1056 public void setColourAppliesToAllGroups(boolean b)
1058 colourAppliesToAllGroups = b;
1064 * @return DOCUMENT ME!
1066 public boolean getColourAppliesToAllGroups()
1068 return colourAppliesToAllGroups;
1074 * @return DOCUMENT ME!
1076 public boolean getShowJVSuffix()
1078 return showJVSuffix;
1084 * @param b DOCUMENT ME!
1086 public void setShowJVSuffix(boolean b)
1095 * @return DOCUMENT ME!
1097 public boolean getShowAnnotation()
1099 return showAnnotation;
1105 * @param b DOCUMENT ME!
1107 public void setShowAnnotation(boolean b)
1115 * @return DOCUMENT ME!
1117 public boolean getScaleAboveWrapped()
1119 return scaleAboveWrapped;
1125 * @return DOCUMENT ME!
1127 public boolean getScaleLeftWrapped()
1129 return scaleLeftWrapped;
1135 * @return DOCUMENT ME!
1137 public boolean getScaleRightWrapped()
1139 return scaleRightWrapped;
1145 * @param b DOCUMENT ME!
1147 public void setScaleAboveWrapped(boolean b)
1149 scaleAboveWrapped = b;
1155 * @param b DOCUMENT ME!
1157 public void setScaleLeftWrapped(boolean b)
1159 scaleLeftWrapped = b;
1165 * @param b DOCUMENT ME!
1167 public void setScaleRightWrapped(boolean b)
1169 scaleRightWrapped = b;
1173 * Property change listener for changes in alignment
1175 * @param listener DOCUMENT ME!
1177 public void addPropertyChangeListener(
1178 java.beans.PropertyChangeListener listener)
1180 changeSupport.addPropertyChangeListener(listener);
1186 * @param listener DOCUMENT ME!
1188 public void removePropertyChangeListener(
1189 java.beans.PropertyChangeListener listener)
1191 changeSupport.removePropertyChangeListener(listener);
1195 * Property change listener for changes in alignment
1197 * @param prop DOCUMENT ME!
1198 * @param oldvalue DOCUMENT ME!
1199 * @param newvalue DOCUMENT ME!
1201 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
1203 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1206 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1208 ignoreGapsInConsensusCalculation = b;
1209 updateConsensus(ap);
1210 if(globalColourScheme!=null)
1212 globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);
1216 public boolean getIgnoreGapsConsensus()
1218 return ignoreGapsInConsensusCalculation;
1221 public void setDataset(boolean b)
1226 public boolean isDataset()
1232 public void hideSelectedColumns()
1234 if (colSel.size() < 1)
1237 colSel.hideSelectedColumns();
1238 setSelectionGroup(null);
1240 hasHiddenColumns = true;
1244 public void hideColumns(int start, int end)
1247 colSel.hideColumns(start);
1249 colSel.hideColumns(start, end);
1251 hasHiddenColumns = true;
1254 public void hideAllSelectedSeqs()
1256 if (selectionGroup == null)
1259 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1263 setSelectionGroup(null);
1266 public void hideSequence(SequenceI [] seq)
1270 for (int i = 0; i < seq.length; i++)
1271 alignment.getHiddenSequences().hideSequence(seq[i]);
1273 hasHiddenRows = true;
1274 firePropertyChange("alignment", null, alignment.getSequences());
1278 public void showSequence(int index)
1280 Vector tmp = alignment.getHiddenSequences().showSequence(index);
1283 if(selectionGroup==null)
1285 selectionGroup = new SequenceGroup();
1286 selectionGroup.setEndRes(alignment.getWidth()-1);
1289 for (int t = 0; t < tmp.size(); t++)
1291 selectionGroup.addSequence(
1292 (SequenceI) tmp.elementAt(t), false
1295 firePropertyChange("alignment", null, alignment.getSequences());
1298 if(alignment.getHiddenSequences().getSize()<1)
1299 hasHiddenRows = false;
1302 public void showColumn(int col)
1304 colSel.revealHiddenColumns(col);
1305 if(colSel.getHiddenColumns()==null)
1306 hasHiddenColumns = false;
1309 public void showAllHiddenColumns()
1311 colSel.revealAllHiddenColumns();
1312 hasHiddenColumns = false;
1315 public void showAllHiddenSeqs()
1317 if(alignment.getHiddenSequences().getSize()>0)
1319 if(selectionGroup==null)
1321 selectionGroup = new SequenceGroup();
1322 selectionGroup.setEndRes(alignment.getWidth()-1);
1324 Vector tmp = alignment.getHiddenSequences().showAll();
1325 for(int t=0; t<tmp.size(); t++)
1327 selectionGroup.addSequence(
1328 (SequenceI)tmp.elementAt(t), false
1331 firePropertyChange("alignment", null, alignment.getSequences());
1332 hasHiddenRows = false;
1336 public void invertColumnSelection()
1339 for(int i=0; i<alignment.getWidth(); i++)
1343 if(colSel.contains(column))
1344 colSel.removeElement(column);
1346 colSel.addElement(column);
1352 public int adjustForHiddenSeqs(int alignmentIndex)
1354 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
1358 * This method returns the a new SequenceI [] with
1359 * the selection sequence and start and end points adjusted
1362 public SequenceI[] getSelectionAsNewSequence()
1364 SequenceI[] sequences;
1366 if (selectionGroup == null)
1367 sequences = alignment.getSequencesArray();
1369 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1375 * This method returns the visible alignment as text, as
1376 * seen on the GUI, ie if columns are hidden they will not
1377 * be returned in the result.
1378 * Use this for calculating trees, PCA, redundancy etc on views
1379 * which contain hidden columns.
1382 public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)
1384 CigarArray selection=null;
1385 SequenceI [] seqs= null;
1387 int start = 0, end = 0;
1388 if(selectedRegionOnly && selectionGroup!=null)
1390 iSize = selectionGroup.getSize(false);
1391 seqs = selectionGroup.getSequencesInOrder(alignment);
1392 start = selectionGroup.getStartRes();
1393 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
1397 iSize = alignment.getHeight();
1398 seqs = alignment.getSequencesArray();
1399 end = alignment.getWidth()-1;
1401 SeqCigar[] selseqs = new SeqCigar[iSize];
1402 for(i=0; i<iSize; i++)
1404 selseqs[i] = new SeqCigar(seqs[i], start, end);
1406 selection=new CigarArray(selseqs);
1407 // now construct the CigarArray operations
1408 if (hasHiddenColumns) {
1409 Vector regions = colSel.getHiddenColumns();
1411 int hideStart, hideEnd;
1413 for (int j = 0; last<end & j < regions.size(); j++)
1415 region = (int[]) regions.elementAt(j);
1416 hideStart = region[0];
1417 hideEnd = region[1];
1418 // edit hidden regions to selection range
1419 if(hideStart<last) {
1433 if (hideStart>hideEnd)
1436 * form operations...
1439 selection.addOperation(CigarArray.M, hideStart-last);
1440 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
1443 // Final match if necessary.
1445 selection.addOperation(CigarArray.M, end-last+1);
1447 selection.addOperation(CigarArray.M, end-start+1);
1452 * return a compact representation of the current alignment selection to
1453 * pass to an analysis function
1454 * @param selectedOnly boolean true to just return the selected view
1455 * @return AlignmentView
1457 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {
1459 // this is here because the AlignmentView constructor modifies the CigarArray
1460 // object. Refactoring of Cigar and alignment view representation should
1461 // be done to remove redundancy.
1462 CigarArray aligview = getViewAsCigars(selectedOnly);
1463 if (aligview!=null) {
1464 return new AlignmentView(aligview,
1465 (selectedOnly && selectionGroup!=null) ? selectionGroup.getStartRes() : 0);
1470 * This method returns the visible alignment as text, as
1471 * seen on the GUI, ie if columns are hidden they will not
1472 * be returned in the result.
1473 * Use this for calculating trees, PCA, redundancy etc on views
1474 * which contain hidden columns.
1477 public String [] getViewAsString(boolean selectedRegionOnly)
1479 String [] selection = null;
1480 SequenceI [] seqs= null;
1482 int start = 0, end = 0;
1483 if(selectedRegionOnly && selectionGroup!=null)
1485 iSize = selectionGroup.getSize(false);
1486 seqs = selectionGroup.getSequencesInOrder(alignment);
1487 start = selectionGroup.getStartRes();
1488 end = selectionGroup.getEndRes()+1;
1492 iSize = alignment.getHeight();
1493 seqs = alignment.getSequencesArray();
1494 end = alignment.getWidth();
1497 selection = new String[iSize];
1498 if (hasHiddenColumns) {
1499 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1501 for(i=0; i<iSize; i++)
1503 selection[i] = seqs[i].getSequence(start, end);
1510 public boolean getShowHiddenMarkers()
1512 return showHiddenMarkers;
1515 public void setShowHiddenMarkers(boolean show)
1517 showHiddenMarkers = show;
1520 public String getSequenceSetId()
1522 if(sequenceSetID==null)
1523 sequenceSetID = alignment.hashCode()+"";
1525 return sequenceSetID;
1528 public void alignmentChanged(AlignmentPanel ap)
1531 alignment.padGaps();
1533 if (hconsensus != null && autoCalculateConsensus)
1535 updateConsensus(ap);
1536 updateConservation(ap);
1539 //Reset endRes of groups if beyond alignment width
1540 int alWidth = alignment.getWidth();
1541 Vector groups = alignment.getGroups();
1544 for(int i=0; i<groups.size(); i++)
1546 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
1547 if(sg.getEndRes()>alWidth)
1548 sg.setEndRes(alWidth-1);
1552 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
1553 selectionGroup.setEndRes(alWidth-1);
1555 resetAllColourSchemes();
1557 alignment.adjustSequenceAnnotations();
1561 void resetAllColourSchemes()
1563 ColourSchemeI cs = globalColourScheme;
1566 if (cs instanceof ClustalxColourScheme)
1568 ( (ClustalxColourScheme) cs).
1569 resetClustalX(alignment.getSequences(),
1570 alignment.getWidth());
1573 cs.setConsensus(hconsensus);
1574 if (cs.conservationApplied())
1576 Alignment al = (Alignment) alignment;
1577 Conservation c = new Conservation("All",
1578 ResidueProperties.propHash, 3,
1579 al.getSequences(), 0,
1582 c.verdict(false, ConsPercGaps);
1584 cs.setConservation(c);
1588 int s, sSize = alignment.getGroups().size();
1589 for(s=0; s<sSize; s++)
1591 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
1592 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1594 ((ClustalxColourScheme)sg.cs).resetClustalX(
1595 sg.getSequences(true), sg.getWidth());
1597 sg.recalcConservation();