2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
25 import jalview.analysis.*;
29 import jalview.datamodel.*;
31 import jalview.schemes.*;
32 import jalview.structure.StructureSelectionManager;
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;
64 boolean seqNameItalics;
66 ColumnSelection colSel = new ColumnSelection();
69 NJTree currentTree = null;
70 boolean scaleAboveWrapped = false;
71 boolean scaleLeftWrapped = true;
72 boolean scaleRightWrapped = true;
73 boolean hasHiddenColumns = false;
74 boolean hasHiddenRows = false;
75 boolean showHiddenMarkers = true;
77 boolean cursorMode = false;
79 // The following vector holds the features which are
80 // currently visible, in the correct order or rendering
81 Hashtable featuresDisplayed = null;
85 public Hashtable [] hconsensus;
86 AlignmentAnnotation consensus;
87 AlignmentAnnotation conservation;
88 AlignmentAnnotation quality;
89 boolean autoCalculateConsensus = true;
92 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
94 // JBPNote Prolly only need this in the applet version.
95 private java.beans.PropertyChangeSupport changeSupport = new java.beans.
96 PropertyChangeSupport(this);
98 boolean ignoreGapsInConsensusCalculation = false;
100 boolean isDataset = false;
102 boolean antiAlias = false;
104 boolean padGaps = false;
106 Rectangle explodedPosition;
110 String sequenceSetID;
112 boolean gatherViewsHere = false;
114 Stack historyList = new Stack();
115 Stack redoList = new Stack();
117 Hashtable sequenceColours;
119 int thresholdTextColour = 0;
120 Color textColour = Color.black;
121 Color textColour2 = Color.white;
123 boolean rightAlignIds = false;
125 Hashtable hiddenRepSequences;
129 * Creates a new AlignViewport object.
131 * @param al DOCUMENT ME!
133 public AlignViewport(AlignmentI al)
139 * Create a new AlignViewport with hidden regions
140 * @param al AlignmentI
141 * @param hiddenColumns ColumnSelection
143 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
146 if (hiddenColumns != null)
148 this.colSel = hiddenColumns;
149 if (hiddenColumns.getHiddenColumns() != null)
151 hasHiddenColumns = true;
160 this.endRes = alignment.getWidth() - 1;
162 this.endSeq = alignment.getHeight() - 1;
164 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
166 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
167 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
169 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
170 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
171 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
173 padGaps = Cache.getDefault("PAD_GAPS", true);
175 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
176 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;
177 String fontSize = Cache.getDefault("FONT_SIZE", "10");
179 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
183 if (fontStyle.equals("bold"))
187 else if (fontStyle.equals("italic"))
192 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
194 alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );
197 // We must set conservation and consensus before setting colour,
198 // as Blosum and Clustal require this to be done
199 if(hconsensus==null && !isDataset)
201 if(!alignment.isNucleotide())
203 conservation = new AlignmentAnnotation("Conservation",
204 "Conservation of total alignment less than " +
205 ConsPercGaps + "% gaps",
206 new Annotation[1], 0f,
208 AlignmentAnnotation.BAR_GRAPH);
209 conservation.hasText = true;
210 conservation.autoCalculated=true;
213 if (Cache.getDefault("SHOW_CONSERVATION", true))
215 alignment.addAnnotation(conservation);
218 if (Cache.getDefault("SHOW_QUALITY", true))
220 quality = new AlignmentAnnotation("Quality",
221 "Alignment Quality based on Blosum62 scores",
225 AlignmentAnnotation.BAR_GRAPH);
226 quality.hasText = true;
227 quality.autoCalculated=true;
229 alignment.addAnnotation(quality);
233 consensus = new AlignmentAnnotation("Consensus", "PID",
234 new Annotation[1], 0f, 100f,
235 AlignmentAnnotation.BAR_GRAPH);
236 consensus.hasText = true;
237 consensus.autoCalculated=true;
239 if (Cache.getDefault("SHOW_IDENTITY", true))
241 alignment.addAnnotation(consensus);
245 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
247 globalColourScheme = ColourSchemeProperty.getColour(alignment,
248 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
250 if (globalColourScheme instanceof UserColourScheme)
252 globalColourScheme = UserDefinedColours.loadDefaultColours();
253 ( (UserColourScheme) globalColourScheme).setThreshold(0,
254 getIgnoreGapsConsensus());
257 if (globalColourScheme != null)
259 globalColourScheme.setConsensus(hconsensus);
263 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
271 * @param b DOCUMENT ME!
273 public void setShowSequenceFeatures(boolean b)
275 showSequenceFeatures = b;
278 public boolean getShowSequenceFeatures()
280 return showSequenceFeatures;
283 class ConservationThread
287 public ConservationThread(AlignmentPanel ap)
296 updatingConservation = true;
298 while (UPDATING_CONSERVATION)
304 ap.paintAlignment(false);
310 ex.printStackTrace();
314 UPDATING_CONSERVATION = true;
317 int alWidth = alignment.getWidth();
323 Conservation cons = new jalview.analysis.Conservation("All",
324 jalview.schemes.ResidueProperties.propHash, 3,
325 alignment.getSequences(), 0, alWidth -1);
328 cons.verdict(false, ConsPercGaps);
335 char [] sequence = cons.getConsSequence().getSequence();
347 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
356 conservation.annotations = new Annotation[alWidth];
360 quality.graphMax = cons.qualityRange[1].floatValue();
361 quality.annotations = new Annotation[alWidth];
362 qmin = cons.qualityRange[0].floatValue();
363 qmax = cons.qualityRange[1].floatValue();
366 for (int i = 0; i < alWidth; i++)
372 if (Character.isDigit(c))
374 value = (int) (c - '0');
385 float vprop = value - min;
387 conservation.annotations[i] =
388 new Annotation(String.valueOf(c),
389 String.valueOf(value), ' ', value,
390 new Color(minR + (maxR * vprop),
391 minG + (maxG * vprop),
392 minB + (maxB * vprop)));
397 value = ( (Double) cons.quality.get(i)).floatValue();
398 vprop = value - qmin;
400 quality.annotations[i] = new Annotation(" ", String.valueOf(value),
403 new Color(minR + (maxR * vprop),
404 minG + (maxG * vprop),
405 minB + (maxB * vprop)));
409 catch (OutOfMemoryError error)
411 javax.swing.SwingUtilities.invokeLater(new Runnable()
417 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
418 "Out of memory calculating conservation!!"
420 "\nSee help files for increasing Java Virtual Machine memory."
422 javax.swing.JOptionPane.WARNING_MESSAGE);
429 System.out.println("Conservation calculation: " + error);
434 UPDATING_CONSERVATION = false;
435 updatingConservation = false;
439 ap.paintAlignment(true);
446 ConservationThread conservationThread;
448 ConsensusThread consensusThread;
450 boolean consUpdateNeeded = false;
452 static boolean UPDATING_CONSENSUS = false;
454 static boolean UPDATING_CONSERVATION = false;
456 boolean updatingConsensus = false;
458 boolean updatingConservation = false;
460 * centre columnar annotation labels in displayed alignment annotation
461 * TODO: add to jalviewXML and annotation display settings
463 boolean centreColumnLabels=false;
466 * trigger update of conservation annotation
468 public void updateConservation(final AlignmentPanel ap)
470 if (alignment.isNucleotide() || conservation==null)
475 conservationThread = new ConservationThread(ap);
476 conservationThread.start();
480 * trigger update of consensus annotation
482 public void updateConsensus(final AlignmentPanel ap)
484 consensusThread = new ConsensusThread(ap);
485 consensusThread.start();
488 class ConsensusThread
492 public ConsensusThread(AlignmentPanel ap)
498 updatingConsensus = true;
499 while (UPDATING_CONSENSUS)
505 ap.paintAlignment(false);
512 ex.printStackTrace();
517 UPDATING_CONSENSUS = true;
521 int aWidth = (alignment!=null) ? alignment.getWidth() : 0; // null pointer possibility here.
527 consensus.annotations = null;
528 consensus.annotations = new Annotation[aWidth];
531 hconsensus = new Hashtable[aWidth];
532 AAFrequency.calculate(alignment.getSequencesArray(),
534 alignment.getWidth(),
537 for (int i = 0; i < aWidth; i++)
540 if (ignoreGapsInConsensusCalculation)
542 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
547 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
551 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
552 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
554 if (maxRes.length() > 1)
556 mouseOver = "[" + maxRes + "] ";
560 mouseOver += ( (int) value + "%");
561 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
566 if (globalColourScheme != null)
568 globalColourScheme.setConsensus(hconsensus);
572 catch (OutOfMemoryError error)
574 alignment.deleteAnnotation(consensus);
578 javax.swing.SwingUtilities.invokeLater(new Runnable()
582 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
583 "Out of memory calculating consensus!!"
585 "\nSee help files for increasing Java Virtual Machine memory."
587 javax.swing.JOptionPane.WARNING_MESSAGE);
591 System.out.println("Consensus calculation: " + error);
594 UPDATING_CONSENSUS = false;
595 updatingConsensus = false;
599 ap.paintAlignment(true);
604 * get the consensus sequence as displayed under the PID consensus annotation row.
605 * @return consensus sequence as a new sequence object
607 public SequenceI getConsensusSeq()
611 updateConsensus(null);
617 StringBuffer seqs=new StringBuffer();
618 for (int i = 0; i < consensus.annotations.length; i++)
620 if (consensus.annotations[i] != null)
622 if (consensus.annotations[i].description.charAt(0) == '[')
624 seqs.append(consensus.annotations[i].description.charAt(1));
628 seqs.append(consensus.annotations[i].displayCharacter);
633 SequenceI sq = new Sequence("Consensus", seqs.toString());
634 sq.setDescription("Percentage Identity Consensus " +
635 ( (ignoreGapsInConsensusCalculation) ? " without gaps" :
642 * @return DOCUMENT ME!
644 public SequenceGroup getSelectionGroup()
646 return selectionGroup;
652 * @param sg DOCUMENT ME!
654 public void setSelectionGroup(SequenceGroup sg)
662 * @return DOCUMENT ME!
664 public boolean getConservationSelected()
666 return conservationColourSelected;
672 * @param b DOCUMENT ME!
674 public void setConservationSelected(boolean b)
676 conservationColourSelected = b;
682 * @return DOCUMENT ME!
684 public boolean getAbovePIDThreshold()
686 return abovePIDThreshold;
692 * @param b DOCUMENT ME!
694 public void setAbovePIDThreshold(boolean b)
696 abovePIDThreshold = b;
702 * @return DOCUMENT ME!
704 public int getStartRes()
712 * @return DOCUMENT ME!
714 public int getEndRes()
722 * @return DOCUMENT ME!
724 public int getStartSeq()
732 * @param cs DOCUMENT ME!
734 public void setGlobalColourScheme(ColourSchemeI cs)
736 globalColourScheme = cs;
742 * @return DOCUMENT ME!
744 public ColourSchemeI getGlobalColourScheme()
746 return globalColourScheme;
752 * @param res DOCUMENT ME!
754 public void setStartRes(int res)
762 * @param seq DOCUMENT ME!
764 public void setStartSeq(int seq)
772 * @param res DOCUMENT ME!
774 public void setEndRes(int res)
776 if (res > (alignment.getWidth() - 1))
778 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
779 res = alignment.getWidth() - 1;
793 * @param seq DOCUMENT ME!
795 public void setEndSeq(int seq)
797 if (seq > alignment.getHeight())
799 seq = alignment.getHeight();
813 * @return DOCUMENT ME!
815 public int getEndSeq()
823 * @param f DOCUMENT ME!
825 public void setFont(Font f)
829 Container c = new Container();
831 java.awt.FontMetrics fm = c.getFontMetrics(font);
832 setCharHeight(fm.getHeight());
833 setCharWidth(fm.charWidth('M'));
834 validCharWidth = true;
840 * @return DOCUMENT ME!
842 public Font getFont()
850 * @param w DOCUMENT ME!
852 public void setCharWidth(int w)
860 * @return DOCUMENT ME!
862 public int getCharWidth()
870 * @param h DOCUMENT ME!
872 public void setCharHeight(int h)
880 * @return DOCUMENT ME!
882 public int getCharHeight()
890 * @param w DOCUMENT ME!
892 public void setWrappedWidth(int w)
894 this.wrappedWidth = w;
900 * @return DOCUMENT ME!
902 public int getWrappedWidth()
911 * @return DOCUMENT ME!
913 public AlignmentI getAlignment()
921 * @param align DOCUMENT ME!
923 public void setAlignment(AlignmentI align)
925 if (alignment!=null && alignment.getCodonFrames()!=null)
927 StructureSelectionManager.getStructureSelectionManager().removeMappings(alignment.getCodonFrames());
929 this.alignment = align;
930 if (alignment.getCodonFrames()!=null)
932 StructureSelectionManager.getStructureSelectionManager().addMappings(alignment.getCodonFrames());
939 * @param state DOCUMENT ME!
941 public void setWrapAlignment(boolean state)
943 wrapAlignment = state;
949 * @param state DOCUMENT ME!
951 public void setShowText(boolean state)
959 * @param state DOCUMENT ME!
961 public void setRenderGaps(boolean state)
969 * @return DOCUMENT ME!
971 public boolean getColourText()
973 return showColourText;
979 * @param state DOCUMENT ME!
981 public void setColourText(boolean state)
983 showColourText = state;
989 * @param state DOCUMENT ME!
991 public void setShowBoxes(boolean state)
999 * @return DOCUMENT ME!
1001 public boolean getWrapAlignment()
1003 return wrapAlignment;
1009 * @return DOCUMENT ME!
1011 public boolean getShowText()
1019 * @return DOCUMENT ME!
1021 public boolean getShowBoxes()
1029 * @return DOCUMENT ME!
1031 public char getGapCharacter()
1033 return getAlignment().getGapCharacter();
1039 * @param gap DOCUMENT ME!
1041 public void setGapCharacter(char gap)
1043 if (getAlignment() != null)
1045 getAlignment().setGapCharacter(gap);
1052 * @param thresh DOCUMENT ME!
1054 public void setThreshold(int thresh)
1062 * @return DOCUMENT ME!
1064 public int getThreshold()
1072 * @param inc DOCUMENT ME!
1074 public void setIncrement(int inc)
1082 * @return DOCUMENT ME!
1084 public int getIncrement()
1093 * @return DOCUMENT ME!
1095 public ColumnSelection getColumnSelection()
1104 * @param tree DOCUMENT ME!
1106 public void setCurrentTree(NJTree tree)
1114 * @return DOCUMENT ME!
1116 public NJTree getCurrentTree()
1124 * @param b DOCUMENT ME!
1126 public void setColourAppliesToAllGroups(boolean b)
1128 colourAppliesToAllGroups = b;
1134 * @return DOCUMENT ME!
1136 public boolean getColourAppliesToAllGroups()
1138 return colourAppliesToAllGroups;
1144 * @return DOCUMENT ME!
1146 public boolean getShowJVSuffix()
1148 return showJVSuffix;
1154 * @param b DOCUMENT ME!
1156 public void setShowJVSuffix(boolean b)
1165 * @return DOCUMENT ME!
1167 public boolean getShowAnnotation()
1169 return showAnnotation;
1175 * @param b DOCUMENT ME!
1177 public void setShowAnnotation(boolean b)
1185 * @return DOCUMENT ME!
1187 public boolean getScaleAboveWrapped()
1189 return scaleAboveWrapped;
1195 * @return DOCUMENT ME!
1197 public boolean getScaleLeftWrapped()
1199 return scaleLeftWrapped;
1205 * @return DOCUMENT ME!
1207 public boolean getScaleRightWrapped()
1209 return scaleRightWrapped;
1215 * @param b DOCUMENT ME!
1217 public void setScaleAboveWrapped(boolean b)
1219 scaleAboveWrapped = b;
1225 * @param b DOCUMENT ME!
1227 public void setScaleLeftWrapped(boolean b)
1229 scaleLeftWrapped = b;
1235 * @param b DOCUMENT ME!
1237 public void setScaleRightWrapped(boolean b)
1239 scaleRightWrapped = b;
1243 * Property change listener for changes in alignment
1245 * @param listener DOCUMENT ME!
1247 public void addPropertyChangeListener(
1248 java.beans.PropertyChangeListener listener)
1250 changeSupport.addPropertyChangeListener(listener);
1256 * @param listener DOCUMENT ME!
1258 public void removePropertyChangeListener(
1259 java.beans.PropertyChangeListener listener)
1261 changeSupport.removePropertyChangeListener(listener);
1265 * Property change listener for changes in alignment
1267 * @param prop DOCUMENT ME!
1268 * @param oldvalue DOCUMENT ME!
1269 * @param newvalue DOCUMENT ME!
1271 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
1273 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1276 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1278 ignoreGapsInConsensusCalculation = b;
1279 updateConsensus(ap);
1280 if(globalColourScheme!=null)
1282 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1283 ignoreGapsInConsensusCalculation);
1287 public boolean getIgnoreGapsConsensus()
1289 return ignoreGapsInConsensusCalculation;
1292 public void setDataset(boolean b)
1297 public boolean isDataset()
1303 public void hideSelectedColumns()
1305 if (colSel.size() < 1)
1310 colSel.hideSelectedColumns();
1311 setSelectionGroup(null);
1313 hasHiddenColumns = true;
1317 public void hideColumns(int start, int end)
1321 colSel.hideColumns(start);
1325 colSel.hideColumns(start, end);
1328 hasHiddenColumns = true;
1331 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1333 int sSize = sg.getSize();
1339 if(hiddenRepSequences==null)
1341 hiddenRepSequences = new Hashtable();
1344 hiddenRepSequences.put(repSequence, sg);
1346 //Hide all sequences except the repSequence
1347 SequenceI [] seqs = new SequenceI[sSize-1];
1349 for(int i=0; i<sSize; i++)
1351 if(sg.getSequenceAt(i)!=repSequence)
1358 seqs[index++] = sg.getSequenceAt(i);
1366 public void hideAllSelectedSeqs()
1368 if (selectionGroup == null || selectionGroup.getSize()<1)
1373 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1377 setSelectionGroup(null);
1380 public void hideSequence(SequenceI [] seq)
1384 for (int i = 0; i < seq.length; i++)
1386 alignment.getHiddenSequences().hideSequence(seq[i]);
1388 hasHiddenRows = true;
1389 firePropertyChange("alignment", null, alignment.getSequences());
1393 public void showSequence(int index)
1395 Vector tmp = alignment.getHiddenSequences().showSequence(index
1396 , hiddenRepSequences);
1399 if(selectionGroup==null)
1401 selectionGroup = new SequenceGroup();
1402 selectionGroup.setEndRes(alignment.getWidth()-1);
1405 for (int t = 0; t < tmp.size(); t++)
1407 selectionGroup.addSequence(
1408 (SequenceI) tmp.elementAt(t), false
1411 firePropertyChange("alignment", null, alignment.getSequences());
1414 if(alignment.getHiddenSequences().getSize()<1)
1416 hasHiddenRows = false;
1420 public void showColumn(int col)
1422 colSel.revealHiddenColumns(col);
1423 if(colSel.getHiddenColumns()==null)
1425 hasHiddenColumns = false;
1429 public void showAllHiddenColumns()
1431 colSel.revealAllHiddenColumns();
1432 hasHiddenColumns = false;
1435 public void showAllHiddenSeqs()
1437 if(alignment.getHiddenSequences().getSize()>0)
1439 if(selectionGroup==null)
1441 selectionGroup = new SequenceGroup();
1442 selectionGroup.setEndRes(alignment.getWidth()-1);
1444 Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
1445 for(int t=0; t<tmp.size(); t++)
1447 selectionGroup.addSequence(
1448 (SequenceI)tmp.elementAt(t), false
1451 firePropertyChange("alignment", null, alignment.getSequences());
1452 hasHiddenRows = false;
1453 hiddenRepSequences = null;
1459 public void invertColumnSelection()
1461 colSel.invertColumnSelection(0,alignment.getWidth());
1464 public int adjustForHiddenSeqs(int alignmentIndex)
1466 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
1470 * This method returns an array of new SequenceI objects
1471 * derived from the whole alignment or just the current
1472 * selection with start and end points adjusted
1473 * @note if you need references to the actual SequenceI objects in the alignment or currently selected then use getSequenceSelection()
1474 * @return selection as new sequenceI objects
1476 public SequenceI[] getSelectionAsNewSequence()
1478 SequenceI[] sequences;
1480 if (selectionGroup == null)
1482 sequences = alignment.getSequencesArray();
1483 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1484 for (int i=0; i<sequences.length; i++)
1486 sequences[i] = new Sequence(sequences[i], annots); // construct new sequence with subset of visible annotation
1491 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1498 * get the currently selected sequence objects or all the sequences in the alignment.
1499 * @return array of references to sequence objects
1501 public SequenceI[] getSequenceSelection()
1503 SequenceI[] sequences;
1504 if (selectionGroup==null)
1506 sequences = alignment.getSequencesArray();
1510 sequences = selectionGroup.getSequencesInOrder(alignment);
1515 * This method returns the visible alignment as text, as
1516 * seen on the GUI, ie if columns are hidden they will not
1517 * be returned in the result.
1518 * Use this for calculating trees, PCA, redundancy etc on views
1519 * which contain hidden columns.
1522 public jalview.datamodel.CigarArray getViewAsCigars(boolean
1525 CigarArray selection=null;
1526 SequenceI [] seqs= null;
1528 int start = 0, end = 0;
1529 if(selectedRegionOnly && selectionGroup!=null)
1531 iSize = selectionGroup.getSize();
1532 seqs = selectionGroup.getSequencesInOrder(alignment);
1533 start = selectionGroup.getStartRes();
1534 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
1538 iSize = alignment.getHeight();
1539 seqs = alignment.getSequencesArray();
1540 end = alignment.getWidth()-1;
1542 SeqCigar[] selseqs = new SeqCigar[iSize];
1543 for(i=0; i<iSize; i++)
1545 selseqs[i] = new SeqCigar(seqs[i], start, end);
1547 selection=new CigarArray(selseqs);
1548 // now construct the CigarArray operations
1549 if (hasHiddenColumns)
1551 Vector regions = colSel.getHiddenColumns();
1553 int hideStart, hideEnd;
1555 for (int j = 0; last<end & j < regions.size(); j++)
1557 region = (int[]) regions.elementAt(j);
1558 hideStart = region[0];
1559 hideEnd = region[1];
1560 // edit hidden regions to selection range
1561 if (hideStart < last)
1583 if (hideStart>hideEnd)
1588 * form operations...
1592 selection.addOperation(CigarArray.M, hideStart-last);
1594 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
1597 // Final match if necessary.
1600 selection.addOperation(CigarArray.M, end-last+1);
1605 selection.addOperation(CigarArray.M, end-start+1);
1610 * return a compact representation of the current alignment selection to
1611 * pass to an analysis function
1612 * @param selectedOnly boolean true to just return the selected view
1613 * @return AlignmentView
1615 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1618 // this is here because the AlignmentView constructor modifies the CigarArray
1619 // object. Refactoring of Cigar and alignment view representation should
1620 // be done to remove redundancy.
1621 CigarArray aligview = getViewAsCigars(selectedOnly);
1622 if (aligview != null)
1624 return new AlignmentView(aligview,
1625 (selectedOnly && selectionGroup != null) ?
1626 selectionGroup.getStartRes() : 0);
1631 * This method returns the visible alignment as text, as
1632 * seen on the GUI, ie if columns are hidden they will not
1633 * be returned in the result.
1634 * Use this for calculating trees, PCA, redundancy etc on views
1635 * which contain hidden columns.
1638 public String [] getViewAsString(boolean selectedRegionOnly)
1640 String [] selection = null;
1641 SequenceI [] seqs= null;
1643 int start = 0, end = 0;
1644 if(selectedRegionOnly && selectionGroup!=null)
1646 iSize = selectionGroup.getSize();
1647 seqs = selectionGroup.getSequencesInOrder(alignment);
1648 start = selectionGroup.getStartRes();
1649 end = selectionGroup.getEndRes()+1;
1653 iSize = alignment.getHeight();
1654 seqs = alignment.getSequencesArray();
1655 end = alignment.getWidth();
1658 selection = new String[iSize];
1659 if (hasHiddenColumns)
1661 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1665 for(i=0; i<iSize; i++)
1667 selection[i] = seqs[i].getSequenceAsString(start, end);
1674 public int [][] getVisibleRegionBoundaries(int min, int max)
1676 Vector regions = new Vector();
1682 if (hasHiddenColumns)
1686 start = colSel.adjustForHiddenColumns(start);
1689 end = colSel.getHiddenBoundaryRight(start);
1700 regions.addElement(new int[]
1703 if (hasHiddenColumns)
1705 start = colSel.adjustForHiddenColumns(end);
1706 start = colSel.getHiddenBoundaryLeft(start) + 1;
1711 int[][] startEnd = new int[regions.size()][2];
1713 regions.copyInto(startEnd);
1719 public boolean getShowHiddenMarkers()
1721 return showHiddenMarkers;
1724 public void setShowHiddenMarkers(boolean show)
1726 showHiddenMarkers = show;
1729 public String getSequenceSetId()
1731 if(sequenceSetID==null)
1733 sequenceSetID = alignment.hashCode()+"";
1736 return sequenceSetID;
1739 public void alignmentChanged(AlignmentPanel ap)
1743 alignment.padGaps();
1746 if (hconsensus != null && autoCalculateConsensus)
1748 updateConsensus(ap);
1749 updateConservation(ap);
1752 //Reset endRes of groups if beyond alignment width
1753 int alWidth = alignment.getWidth();
1754 Vector groups = alignment.getGroups();
1757 for(int i=0; i<groups.size(); i++)
1759 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
1760 if(sg.getEndRes()>alWidth)
1762 sg.setEndRes(alWidth-1);
1767 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
1769 selectionGroup.setEndRes(alWidth-1);
1772 resetAllColourSchemes();
1774 // alignment.adjustSequenceAnnotations();
1778 void resetAllColourSchemes()
1780 ColourSchemeI cs = globalColourScheme;
1783 if (cs instanceof ClustalxColourScheme)
1785 ( (ClustalxColourScheme) cs).
1786 resetClustalX(alignment.getSequences(),
1787 alignment.getWidth());
1790 cs.setConsensus(hconsensus);
1791 if (cs.conservationApplied())
1793 Alignment al = (Alignment) alignment;
1794 Conservation c = new Conservation("All",
1795 ResidueProperties.propHash, 3,
1796 al.getSequences(), 0,
1799 c.verdict(false, ConsPercGaps);
1801 cs.setConservation(c);
1805 int s, sSize = alignment.getGroups().size();
1806 for(s=0; s<sSize; s++)
1808 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
1809 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1811 ((ClustalxColourScheme)sg.cs).resetClustalX(
1812 sg.getSequences(hiddenRepSequences), sg.getWidth());
1814 sg.recalcConservation();
1819 public Color getSequenceColour(SequenceI seq)
1821 if(sequenceColours==null || !sequenceColours.containsKey(seq))
1827 return (Color)sequenceColours.get(seq);
1831 public void setSequenceColour(SequenceI seq, Color col)
1833 if(sequenceColours==null)
1835 sequenceColours = new Hashtable();
1840 sequenceColours.remove(seq);
1844 sequenceColours.put(seq, col);
1848 * returns the visible column regions of the alignment
1849 * @param selectedRegionOnly true to just return the contigs intersecting with the selected area
1852 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly) {
1853 int[] viscontigs=null;
1854 int start = 0, end = 0;
1855 if(selectedRegionOnly && selectionGroup!=null)
1857 start = selectionGroup.getStartRes();
1858 end = selectionGroup.getEndRes()+1;
1862 end = alignment.getWidth();
1864 viscontigs = colSel.getVisibleContigs(start, end);
1868 * get hash of undo and redo list for the alignment
1869 * @return long[] { historyList.hashCode, redoList.hashCode };
1871 public long[] getUndoRedoHash()
1873 if (historyList==null || redoList==null)
1874 return new long[] { -1, -1};
1875 return new long[] { historyList.hashCode(), this.redoList.hashCode() };
1878 * test if a particular set of hashcodes are different to the hashcodes for the undo and redo list.
1879 * @param undoredo the stored set of hashcodes as returned by getUndoRedoHash
1880 * @return true if the hashcodes differ (ie the alignment has been edited) or the stored hashcode array differs in size
1882 public boolean isUndoRedoHashModified(long[] undoredo)
1888 long[] cstate = getUndoRedoHash();
1889 if (cstate.length!=undoredo.length)
1892 for (int i=0; i<cstate.length; i++)
1894 if (cstate[i]!=undoredo[i])
1902 public boolean getCentreColumnLabels()
1904 return centreColumnLabels;
1906 public void setCentreColumnLabels(boolean centrecolumnlabels)
1908 centreColumnLabels = centrecolumnlabels;
1910 public void updateSequenceIdColours()
1912 Vector groups = alignment.getGroups();
1913 if (sequenceColours==null)
1915 sequenceColours = new Hashtable();
1917 for (int ig=0,igSize=groups.size(); ig<igSize; ig++)
1919 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1920 if (sg.idColour!=null)
1922 Vector sqs = sg.getSequences(hiddenRepSequences);
1923 for (int s=0,sSize=sqs.size();s<sSize;s++)
1925 sequenceColours.put(sqs.elementAt(s), sg.idColour);