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 rightAlignIds = 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 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
163 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
165 padGaps = Cache.getDefault("PAD_GAPS", true);
167 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
168 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;
169 String fontSize = Cache.getDefault("FONT_SIZE", "10");
173 if (fontStyle.equals("bold"))
177 else if (fontStyle.equals("italic"))
182 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
184 alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );
187 // We must set conservation and consensus before setting colour,
188 // as Blosum and Clustal require this to be done
189 if(hconsensus==null && !isDataset)
191 if(!alignment.isNucleotide())
193 conservation = new AlignmentAnnotation("Conservation",
194 "Conservation of total alignment less than " +
195 ConsPercGaps + "% gaps",
196 new Annotation[1], 0f,
198 AlignmentAnnotation.BAR_GRAPH);
199 conservation.hasText = true;
202 if (Cache.getDefault("SHOW_CONSERVATION", true))
204 alignment.addAnnotation(conservation);
207 if (Cache.getDefault("SHOW_QUALITY", true))
209 quality = new AlignmentAnnotation("Quality",
210 "Alignment Quality based on Blosum62 scores",
214 AlignmentAnnotation.BAR_GRAPH);
215 quality.hasText = true;
217 alignment.addAnnotation(quality);
221 consensus = new AlignmentAnnotation("Consensus", "PID",
222 new Annotation[1], 0f, 100f,
223 AlignmentAnnotation.BAR_GRAPH);
224 consensus.hasText = true;
226 if (Cache.getDefault("SHOW_IDENTITY", true))
228 alignment.addAnnotation(consensus);
232 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
234 globalColourScheme = ColourSchemeProperty.getColour(alignment,
235 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
237 if (globalColourScheme instanceof UserColourScheme)
239 globalColourScheme = UserDefinedColours.loadDefaultColours();
240 ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());
243 if (globalColourScheme != null)
245 globalColourScheme.setConsensus(hconsensus);
249 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
257 * @param b DOCUMENT ME!
259 public void setShowSequenceFeatures(boolean b)
261 showSequenceFeatures = b;
264 public boolean getShowSequenceFeatures()
266 return showSequenceFeatures;
271 class ConservationThread extends Thread
274 public ConservationThread(AlignmentPanel ap)
283 updatingConservation = true;
285 while (UPDATING_CONSERVATION)
297 ex.printStackTrace();
301 UPDATING_CONSERVATION = true;
304 int alWidth = alignment.getWidth();
308 Conservation cons = new jalview.analysis.Conservation("All",
309 jalview.schemes.ResidueProperties.propHash, 3,
310 alignment.getSequences(), 0, alWidth -1);
313 cons.verdict(false, ConsPercGaps);
320 char [] sequence = cons.getConsSequence().getSequence();
332 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
341 conservation.annotations = new Annotation[alWidth];
345 quality.graphMax = cons.qualityRange[1].floatValue();
346 quality.annotations = new Annotation[alWidth];
347 qmin = cons.qualityRange[0].floatValue();
348 qmax = cons.qualityRange[1].floatValue();
351 for (int i = 0; i < alWidth; i++)
357 if (Character.isDigit(c))
358 value = (int) (c - '0');
364 float vprop = value - min;
366 conservation.annotations[i] =
367 new Annotation(String.valueOf(c),
368 String.valueOf(value), ' ', value,
369 new Color(minR + (maxR * vprop),
370 minG + (maxG * vprop),
371 minB + (maxB * vprop)));
376 value = ( (Double) cons.quality.get(i)).floatValue();
377 vprop = value - qmin;
379 quality.annotations[i] = new Annotation(" ", String.valueOf(value), ' ',
381 new Color(minR + (maxR * vprop),
382 minG + (maxG * vprop),
383 minB + (maxB * vprop)));
387 catch (OutOfMemoryError error)
389 javax.swing.SwingUtilities.invokeLater(new Runnable()
395 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
396 "Out of memory calculating conservation!!"
398 "\nSee help files for increasing Java Virtual Machine memory."
400 javax.swing.JOptionPane.WARNING_MESSAGE);
407 System.out.println("Conservation calculation: " + error);
412 UPDATING_CONSERVATION = false;
413 updatingConservation = false;
424 ConservationThread conservationThread;
426 ConsensusThread consensusThread;
428 boolean consUpdateNeeded = false;
430 static boolean UPDATING_CONSENSUS = false;
432 static boolean UPDATING_CONSERVATION = false;
434 boolean updatingConsensus = false;
436 boolean updatingConservation = false;
441 public void updateConservation(final AlignmentPanel ap)
443 if (alignment.isNucleotide() || conservation==null)
446 conservationThread = new ConservationThread(ap);
447 conservationThread.start();
453 public void updateConsensus(final AlignmentPanel ap)
455 consensusThread = new ConsensusThread(ap);
456 consensusThread.start();
460 class ConsensusThread extends Thread
463 public ConsensusThread(AlignmentPanel ap)
469 updatingConsensus = true;
470 while (UPDATING_CONSENSUS)
483 ex.printStackTrace();
488 UPDATING_CONSENSUS = true;
492 int aWidth = alignment.getWidth();
496 consensus.annotations = null;
497 consensus.annotations = new Annotation[aWidth];
500 hconsensus = new Hashtable[aWidth];
501 AAFrequency.calculate(alignment.getSequencesArray(),
503 alignment.getWidth(),
506 for (int i = 0; i < aWidth; i++)
509 if (ignoreGapsInConsensusCalculation)
510 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
513 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
516 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
517 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
519 if (maxRes.length() > 1)
521 mouseOver = "[" + maxRes + "] ";
525 mouseOver += ( (int) value + "%");
526 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
530 if (globalColourScheme != null)
531 globalColourScheme.setConsensus(hconsensus);
534 catch (OutOfMemoryError error)
536 alignment.deleteAnnotation(consensus);
540 javax.swing.SwingUtilities.invokeLater(new Runnable()
544 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
545 "Out of memory calculating consensus!!"
547 "\nSee help files for increasing Java Virtual Machine memory."
549 javax.swing.JOptionPane.WARNING_MESSAGE);
553 System.out.println("Consensus calculation: " + error);
556 UPDATING_CONSENSUS = false;
557 updatingConsensus = false;
566 * get the consensus sequence as displayed under the PID consensus annotation row.
567 * @return consensus sequence as a new sequence object
569 public SequenceI getConsensusSeq() {
571 updateConsensus(null);
574 StringBuffer seqs=new StringBuffer();
575 for (int i=0; i<consensus.annotations.length; i++) {
576 if (consensus.annotations[i]!=null) {
577 if (consensus.annotations[i].description.charAt(0) == '[')
578 seqs.append(consensus.annotations[i].description.charAt(1));
580 seqs.append(consensus.annotations[i].displayCharacter);
584 SequenceI sq = new Sequence("Consensus", seqs.toString());
585 sq.setDescription("Percentage Identity Consensus "+((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
591 * @return DOCUMENT ME!
593 public SequenceGroup getSelectionGroup()
595 return selectionGroup;
601 * @param sg DOCUMENT ME!
603 public void setSelectionGroup(SequenceGroup sg)
611 * @return DOCUMENT ME!
613 public boolean getConservationSelected()
615 return conservationColourSelected;
621 * @param b DOCUMENT ME!
623 public void setConservationSelected(boolean b)
625 conservationColourSelected = b;
631 * @return DOCUMENT ME!
633 public boolean getAbovePIDThreshold()
635 return abovePIDThreshold;
641 * @param b DOCUMENT ME!
643 public void setAbovePIDThreshold(boolean b)
645 abovePIDThreshold = b;
651 * @return DOCUMENT ME!
653 public int getStartRes()
661 * @return DOCUMENT ME!
663 public int getEndRes()
671 * @return DOCUMENT ME!
673 public int getStartSeq()
681 * @param cs DOCUMENT ME!
683 public void setGlobalColourScheme(ColourSchemeI cs)
685 globalColourScheme = cs;
691 * @return DOCUMENT ME!
693 public ColourSchemeI getGlobalColourScheme()
695 return globalColourScheme;
701 * @param res DOCUMENT ME!
703 public void setStartRes(int res)
711 * @param seq DOCUMENT ME!
713 public void setStartSeq(int seq)
721 * @param res DOCUMENT ME!
723 public void setEndRes(int res)
725 if (res > (alignment.getWidth() - 1))
727 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
728 res = alignment.getWidth() - 1;
742 * @param seq DOCUMENT ME!
744 public void setEndSeq(int seq)
746 if (seq > alignment.getHeight())
748 seq = alignment.getHeight();
762 * @return DOCUMENT ME!
764 public int getEndSeq()
772 * @param f DOCUMENT ME!
774 public void setFont(Font f)
778 Container c = new Container();
780 java.awt.FontMetrics fm = c.getFontMetrics(font);
781 setCharHeight(fm.getHeight());
782 setCharWidth(fm.charWidth('M'));
783 validCharWidth = true;
789 * @return DOCUMENT ME!
791 public Font getFont()
799 * @param w DOCUMENT ME!
801 public void setCharWidth(int w)
809 * @return DOCUMENT ME!
811 public int getCharWidth()
819 * @param h DOCUMENT ME!
821 public void setCharHeight(int h)
829 * @return DOCUMENT ME!
831 public int getCharHeight()
839 * @param w DOCUMENT ME!
841 public void setWrappedWidth(int w)
843 this.wrappedWidth = w;
849 * @return DOCUMENT ME!
851 public int getWrappedWidth()
860 * @return DOCUMENT ME!
862 public AlignmentI getAlignment()
870 * @param align DOCUMENT ME!
872 public void setAlignment(AlignmentI align)
874 this.alignment = align;
880 * @param state DOCUMENT ME!
882 public void setWrapAlignment(boolean state)
884 wrapAlignment = state;
890 * @param state DOCUMENT ME!
892 public void setShowText(boolean state)
900 * @param state DOCUMENT ME!
902 public void setRenderGaps(boolean state)
910 * @return DOCUMENT ME!
912 public boolean getColourText()
914 return showColourText;
920 * @param state DOCUMENT ME!
922 public void setColourText(boolean state)
924 showColourText = state;
930 * @param state DOCUMENT ME!
932 public void setShowBoxes(boolean state)
940 * @return DOCUMENT ME!
942 public boolean getWrapAlignment()
944 return wrapAlignment;
950 * @return DOCUMENT ME!
952 public boolean getShowText()
960 * @return DOCUMENT ME!
962 public boolean getShowBoxes()
970 * @return DOCUMENT ME!
972 public char getGapCharacter()
974 return getAlignment().getGapCharacter();
980 * @param gap DOCUMENT ME!
982 public void setGapCharacter(char gap)
984 if (getAlignment() != null)
986 getAlignment().setGapCharacter(gap);
993 * @param thresh DOCUMENT ME!
995 public void setThreshold(int thresh)
1003 * @return DOCUMENT ME!
1005 public int getThreshold()
1013 * @param inc DOCUMENT ME!
1015 public void setIncrement(int inc)
1023 * @return DOCUMENT ME!
1025 public int getIncrement()
1034 * @return DOCUMENT ME!
1036 public ColumnSelection getColumnSelection()
1045 * @param tree DOCUMENT ME!
1047 public void setCurrentTree(NJTree tree)
1055 * @return DOCUMENT ME!
1057 public NJTree getCurrentTree()
1065 * @param b DOCUMENT ME!
1067 public void setColourAppliesToAllGroups(boolean b)
1069 colourAppliesToAllGroups = b;
1075 * @return DOCUMENT ME!
1077 public boolean getColourAppliesToAllGroups()
1079 return colourAppliesToAllGroups;
1085 * @return DOCUMENT ME!
1087 public boolean getShowJVSuffix()
1089 return showJVSuffix;
1095 * @param b DOCUMENT ME!
1097 public void setShowJVSuffix(boolean b)
1106 * @return DOCUMENT ME!
1108 public boolean getShowAnnotation()
1110 return showAnnotation;
1116 * @param b DOCUMENT ME!
1118 public void setShowAnnotation(boolean b)
1126 * @return DOCUMENT ME!
1128 public boolean getScaleAboveWrapped()
1130 return scaleAboveWrapped;
1136 * @return DOCUMENT ME!
1138 public boolean getScaleLeftWrapped()
1140 return scaleLeftWrapped;
1146 * @return DOCUMENT ME!
1148 public boolean getScaleRightWrapped()
1150 return scaleRightWrapped;
1156 * @param b DOCUMENT ME!
1158 public void setScaleAboveWrapped(boolean b)
1160 scaleAboveWrapped = b;
1166 * @param b DOCUMENT ME!
1168 public void setScaleLeftWrapped(boolean b)
1170 scaleLeftWrapped = b;
1176 * @param b DOCUMENT ME!
1178 public void setScaleRightWrapped(boolean b)
1180 scaleRightWrapped = b;
1184 * Property change listener for changes in alignment
1186 * @param listener DOCUMENT ME!
1188 public void addPropertyChangeListener(
1189 java.beans.PropertyChangeListener listener)
1191 changeSupport.addPropertyChangeListener(listener);
1197 * @param listener DOCUMENT ME!
1199 public void removePropertyChangeListener(
1200 java.beans.PropertyChangeListener listener)
1202 changeSupport.removePropertyChangeListener(listener);
1206 * Property change listener for changes in alignment
1208 * @param prop DOCUMENT ME!
1209 * @param oldvalue DOCUMENT ME!
1210 * @param newvalue DOCUMENT ME!
1212 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
1214 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1217 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1219 ignoreGapsInConsensusCalculation = b;
1220 updateConsensus(ap);
1221 if(globalColourScheme!=null)
1223 globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);
1227 public boolean getIgnoreGapsConsensus()
1229 return ignoreGapsInConsensusCalculation;
1232 public void setDataset(boolean b)
1237 public boolean isDataset()
1243 public void hideSelectedColumns()
1245 if (colSel.size() < 1)
1248 colSel.hideSelectedColumns();
1249 setSelectionGroup(null);
1251 hasHiddenColumns = true;
1255 public void hideColumns(int start, int end)
1258 colSel.hideColumns(start);
1260 colSel.hideColumns(start, end);
1262 hasHiddenColumns = true;
1265 public void hideAllSelectedSeqs()
1267 if (selectionGroup == null)
1270 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1274 setSelectionGroup(null);
1277 public void hideSequence(SequenceI [] seq)
1281 for (int i = 0; i < seq.length; i++)
1282 alignment.getHiddenSequences().hideSequence(seq[i]);
1284 hasHiddenRows = true;
1285 firePropertyChange("alignment", null, alignment.getSequences());
1289 public void showSequence(int index)
1291 Vector tmp = alignment.getHiddenSequences().showSequence(index);
1294 if(selectionGroup==null)
1296 selectionGroup = new SequenceGroup();
1297 selectionGroup.setEndRes(alignment.getWidth()-1);
1300 for (int t = 0; t < tmp.size(); t++)
1302 selectionGroup.addSequence(
1303 (SequenceI) tmp.elementAt(t), false
1306 firePropertyChange("alignment", null, alignment.getSequences());
1309 if(alignment.getHiddenSequences().getSize()<1)
1310 hasHiddenRows = false;
1313 public void showColumn(int col)
1315 colSel.revealHiddenColumns(col);
1316 if(colSel.getHiddenColumns()==null)
1317 hasHiddenColumns = false;
1320 public void showAllHiddenColumns()
1322 colSel.revealAllHiddenColumns();
1323 hasHiddenColumns = false;
1326 public void showAllHiddenSeqs()
1328 if(alignment.getHiddenSequences().getSize()>0)
1330 if(selectionGroup==null)
1332 selectionGroup = new SequenceGroup();
1333 selectionGroup.setEndRes(alignment.getWidth()-1);
1335 Vector tmp = alignment.getHiddenSequences().showAll();
1336 for(int t=0; t<tmp.size(); t++)
1338 selectionGroup.addSequence(
1339 (SequenceI)tmp.elementAt(t), false
1342 firePropertyChange("alignment", null, alignment.getSequences());
1343 hasHiddenRows = false;
1347 public void invertColumnSelection()
1349 for(int i=0; i<alignment.getWidth(); i++)
1351 if(colSel.contains(i))
1352 colSel.removeElement(i);
1355 if (!hasHiddenColumns || colSel.isVisible(i))
1357 colSel.addElement(i);
1365 public int adjustForHiddenSeqs(int alignmentIndex)
1367 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
1371 * This method returns the a new SequenceI [] with
1372 * the selection sequence and start and end points adjusted
1375 public SequenceI[] getSelectionAsNewSequence()
1377 SequenceI[] sequences;
1379 if (selectionGroup == null)
1380 sequences = alignment.getSequencesArray();
1382 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1388 * This method returns the visible alignment as text, as
1389 * seen on the GUI, ie if columns are hidden they will not
1390 * be returned in the result.
1391 * Use this for calculating trees, PCA, redundancy etc on views
1392 * which contain hidden columns.
1395 public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)
1397 CigarArray selection=null;
1398 SequenceI [] seqs= null;
1400 int start = 0, end = 0;
1401 if(selectedRegionOnly && selectionGroup!=null)
1403 iSize = selectionGroup.getSize(false);
1404 seqs = selectionGroup.getSequencesInOrder(alignment);
1405 start = selectionGroup.getStartRes();
1406 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
1410 iSize = alignment.getHeight();
1411 seqs = alignment.getSequencesArray();
1412 end = alignment.getWidth()-1;
1414 SeqCigar[] selseqs = new SeqCigar[iSize];
1415 for(i=0; i<iSize; i++)
1417 selseqs[i] = new SeqCigar(seqs[i], start, end);
1419 selection=new CigarArray(selseqs);
1420 // now construct the CigarArray operations
1421 if (hasHiddenColumns) {
1422 Vector regions = colSel.getHiddenColumns();
1424 int hideStart, hideEnd;
1426 for (int j = 0; last<end & j < regions.size(); j++)
1428 region = (int[]) regions.elementAt(j);
1429 hideStart = region[0];
1430 hideEnd = region[1];
1431 // edit hidden regions to selection range
1432 if(hideStart<last) {
1446 if (hideStart>hideEnd)
1449 * form operations...
1452 selection.addOperation(CigarArray.M, hideStart-last);
1453 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
1456 // Final match if necessary.
1458 selection.addOperation(CigarArray.M, end-last+1);
1460 selection.addOperation(CigarArray.M, end-start+1);
1465 * return a compact representation of the current alignment selection to
1466 * pass to an analysis function
1467 * @param selectedOnly boolean true to just return the selected view
1468 * @return AlignmentView
1470 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {
1472 // this is here because the AlignmentView constructor modifies the CigarArray
1473 // object. Refactoring of Cigar and alignment view representation should
1474 // be done to remove redundancy.
1475 CigarArray aligview = getViewAsCigars(selectedOnly);
1476 if (aligview!=null) {
1477 return new AlignmentView(aligview,
1478 (selectedOnly && selectionGroup!=null) ? selectionGroup.getStartRes() : 0);
1483 * This method returns the visible alignment as text, as
1484 * seen on the GUI, ie if columns are hidden they will not
1485 * be returned in the result.
1486 * Use this for calculating trees, PCA, redundancy etc on views
1487 * which contain hidden columns.
1490 public String [] getViewAsString(boolean selectedRegionOnly)
1492 String [] selection = null;
1493 SequenceI [] seqs= null;
1495 int start = 0, end = 0;
1496 if(selectedRegionOnly && selectionGroup!=null)
1498 iSize = selectionGroup.getSize(false);
1499 seqs = selectionGroup.getSequencesInOrder(alignment);
1500 start = selectionGroup.getStartRes();
1501 end = selectionGroup.getEndRes()+1;
1505 iSize = alignment.getHeight();
1506 seqs = alignment.getSequencesArray();
1507 end = alignment.getWidth();
1510 selection = new String[iSize];
1511 if (hasHiddenColumns) {
1512 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1514 for(i=0; i<iSize; i++)
1516 selection[i] = seqs[i].getSequenceAsString(start, end);
1523 public boolean getShowHiddenMarkers()
1525 return showHiddenMarkers;
1528 public void setShowHiddenMarkers(boolean show)
1530 showHiddenMarkers = show;
1533 public String getSequenceSetId()
1535 if(sequenceSetID==null)
1536 sequenceSetID = alignment.hashCode()+"";
1538 return sequenceSetID;
1541 public void alignmentChanged(AlignmentPanel ap)
1544 alignment.padGaps();
1546 if (hconsensus != null && autoCalculateConsensus)
1548 updateConsensus(ap);
1549 updateConservation(ap);
1552 //Reset endRes of groups if beyond alignment width
1553 int alWidth = alignment.getWidth();
1554 Vector groups = alignment.getGroups();
1557 for(int i=0; i<groups.size(); i++)
1559 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
1560 if(sg.getEndRes()>alWidth)
1561 sg.setEndRes(alWidth-1);
1565 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
1566 selectionGroup.setEndRes(alWidth-1);
1568 resetAllColourSchemes();
1570 alignment.adjustSequenceAnnotations();
1574 void resetAllColourSchemes()
1576 ColourSchemeI cs = globalColourScheme;
1579 if (cs instanceof ClustalxColourScheme)
1581 ( (ClustalxColourScheme) cs).
1582 resetClustalX(alignment.getSequences(),
1583 alignment.getWidth());
1586 cs.setConsensus(hconsensus);
1587 if (cs.conservationApplied())
1589 Alignment al = (Alignment) alignment;
1590 Conservation c = new Conservation("All",
1591 ResidueProperties.propHash, 3,
1592 al.getSequences(), 0,
1595 c.verdict(false, ConsPercGaps);
1597 cs.setConservation(c);
1601 int s, sSize = alignment.getGroups().size();
1602 for(s=0; s<sSize; s++)
1604 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
1605 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1607 ((ClustalxColourScheme)sg.cs).resetClustalX(
1608 sg.getSequences(true), sg.getWidth());
1610 sg.recalcConservation();
1615 public Color getSequenceColour(SequenceI seq)
1617 if(sequenceColours==null || !sequenceColours.containsKey(seq))
1620 return (Color)sequenceColours.get(seq);
1623 public void setSequenceColour(SequenceI seq, Color col)
1625 if(sequenceColours==null)
1626 sequenceColours = new Hashtable();
1629 sequenceColours.remove(seq);
1631 sequenceColours.put(seq, col);