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);
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;
463 public void updateConservation(final AlignmentPanel ap)
465 if (alignment.isNucleotide() || conservation==null)
470 conservationThread = new ConservationThread(ap);
471 conservationThread.start();
477 public void updateConsensus(final AlignmentPanel ap)
479 consensusThread = new ConsensusThread(ap);
480 consensusThread.start();
483 class ConsensusThread
487 public ConsensusThread(AlignmentPanel ap)
493 updatingConsensus = true;
494 while (UPDATING_CONSENSUS)
500 ap.paintAlignment(false);
507 ex.printStackTrace();
512 UPDATING_CONSENSUS = true;
516 int aWidth = (alignment!=null) ? alignment.getWidth() : 0; // null pointer possibility here.
522 consensus.annotations = null;
523 consensus.annotations = new Annotation[aWidth];
526 hconsensus = new Hashtable[aWidth];
527 AAFrequency.calculate(alignment.getSequencesArray(),
529 alignment.getWidth(),
532 for (int i = 0; i < aWidth; i++)
535 if (ignoreGapsInConsensusCalculation)
537 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
542 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
546 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
547 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
549 if (maxRes.length() > 1)
551 mouseOver = "[" + maxRes + "] ";
555 mouseOver += ( (int) value + "%");
556 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
561 if (globalColourScheme != null)
563 globalColourScheme.setConsensus(hconsensus);
567 catch (OutOfMemoryError error)
569 alignment.deleteAnnotation(consensus);
573 javax.swing.SwingUtilities.invokeLater(new Runnable()
577 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
578 "Out of memory calculating consensus!!"
580 "\nSee help files for increasing Java Virtual Machine memory."
582 javax.swing.JOptionPane.WARNING_MESSAGE);
586 System.out.println("Consensus calculation: " + error);
589 UPDATING_CONSENSUS = false;
590 updatingConsensus = false;
594 ap.paintAlignment(true);
599 * get the consensus sequence as displayed under the PID consensus annotation row.
600 * @return consensus sequence as a new sequence object
602 public SequenceI getConsensusSeq()
606 updateConsensus(null);
612 StringBuffer seqs=new StringBuffer();
613 for (int i = 0; i < consensus.annotations.length; i++)
615 if (consensus.annotations[i] != null)
617 if (consensus.annotations[i].description.charAt(0) == '[')
619 seqs.append(consensus.annotations[i].description.charAt(1));
623 seqs.append(consensus.annotations[i].displayCharacter);
628 SequenceI sq = new Sequence("Consensus", seqs.toString());
629 sq.setDescription("Percentage Identity Consensus " +
630 ( (ignoreGapsInConsensusCalculation) ? " without gaps" :
637 * @return DOCUMENT ME!
639 public SequenceGroup getSelectionGroup()
641 return selectionGroup;
647 * @param sg DOCUMENT ME!
649 public void setSelectionGroup(SequenceGroup sg)
657 * @return DOCUMENT ME!
659 public boolean getConservationSelected()
661 return conservationColourSelected;
667 * @param b DOCUMENT ME!
669 public void setConservationSelected(boolean b)
671 conservationColourSelected = b;
677 * @return DOCUMENT ME!
679 public boolean getAbovePIDThreshold()
681 return abovePIDThreshold;
687 * @param b DOCUMENT ME!
689 public void setAbovePIDThreshold(boolean b)
691 abovePIDThreshold = b;
697 * @return DOCUMENT ME!
699 public int getStartRes()
707 * @return DOCUMENT ME!
709 public int getEndRes()
717 * @return DOCUMENT ME!
719 public int getStartSeq()
727 * @param cs DOCUMENT ME!
729 public void setGlobalColourScheme(ColourSchemeI cs)
731 globalColourScheme = cs;
737 * @return DOCUMENT ME!
739 public ColourSchemeI getGlobalColourScheme()
741 return globalColourScheme;
747 * @param res DOCUMENT ME!
749 public void setStartRes(int res)
757 * @param seq DOCUMENT ME!
759 public void setStartSeq(int seq)
767 * @param res DOCUMENT ME!
769 public void setEndRes(int res)
771 if (res > (alignment.getWidth() - 1))
773 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
774 res = alignment.getWidth() - 1;
788 * @param seq DOCUMENT ME!
790 public void setEndSeq(int seq)
792 if (seq > alignment.getHeight())
794 seq = alignment.getHeight();
808 * @return DOCUMENT ME!
810 public int getEndSeq()
818 * @param f DOCUMENT ME!
820 public void setFont(Font f)
824 Container c = new Container();
826 java.awt.FontMetrics fm = c.getFontMetrics(font);
827 setCharHeight(fm.getHeight());
828 setCharWidth(fm.charWidth('M'));
829 validCharWidth = true;
835 * @return DOCUMENT ME!
837 public Font getFont()
845 * @param w DOCUMENT ME!
847 public void setCharWidth(int w)
855 * @return DOCUMENT ME!
857 public int getCharWidth()
865 * @param h DOCUMENT ME!
867 public void setCharHeight(int h)
875 * @return DOCUMENT ME!
877 public int getCharHeight()
885 * @param w DOCUMENT ME!
887 public void setWrappedWidth(int w)
889 this.wrappedWidth = w;
895 * @return DOCUMENT ME!
897 public int getWrappedWidth()
906 * @return DOCUMENT ME!
908 public AlignmentI getAlignment()
916 * @param align DOCUMENT ME!
918 public void setAlignment(AlignmentI align)
920 if (alignment!=null && alignment.getCodonFrames()!=null)
922 StructureSelectionManager.getStructureSelectionManager().removeMappings(alignment.getCodonFrames());
924 this.alignment = align;
925 if (alignment.getCodonFrames()!=null)
927 StructureSelectionManager.getStructureSelectionManager().addMappings(alignment.getCodonFrames());
934 * @param state DOCUMENT ME!
936 public void setWrapAlignment(boolean state)
938 wrapAlignment = state;
944 * @param state DOCUMENT ME!
946 public void setShowText(boolean state)
954 * @param state DOCUMENT ME!
956 public void setRenderGaps(boolean state)
964 * @return DOCUMENT ME!
966 public boolean getColourText()
968 return showColourText;
974 * @param state DOCUMENT ME!
976 public void setColourText(boolean state)
978 showColourText = state;
984 * @param state DOCUMENT ME!
986 public void setShowBoxes(boolean state)
994 * @return DOCUMENT ME!
996 public boolean getWrapAlignment()
998 return wrapAlignment;
1004 * @return DOCUMENT ME!
1006 public boolean getShowText()
1014 * @return DOCUMENT ME!
1016 public boolean getShowBoxes()
1024 * @return DOCUMENT ME!
1026 public char getGapCharacter()
1028 return getAlignment().getGapCharacter();
1034 * @param gap DOCUMENT ME!
1036 public void setGapCharacter(char gap)
1038 if (getAlignment() != null)
1040 getAlignment().setGapCharacter(gap);
1047 * @param thresh DOCUMENT ME!
1049 public void setThreshold(int thresh)
1057 * @return DOCUMENT ME!
1059 public int getThreshold()
1067 * @param inc DOCUMENT ME!
1069 public void setIncrement(int inc)
1077 * @return DOCUMENT ME!
1079 public int getIncrement()
1088 * @return DOCUMENT ME!
1090 public ColumnSelection getColumnSelection()
1099 * @param tree DOCUMENT ME!
1101 public void setCurrentTree(NJTree tree)
1109 * @return DOCUMENT ME!
1111 public NJTree getCurrentTree()
1119 * @param b DOCUMENT ME!
1121 public void setColourAppliesToAllGroups(boolean b)
1123 colourAppliesToAllGroups = b;
1129 * @return DOCUMENT ME!
1131 public boolean getColourAppliesToAllGroups()
1133 return colourAppliesToAllGroups;
1139 * @return DOCUMENT ME!
1141 public boolean getShowJVSuffix()
1143 return showJVSuffix;
1149 * @param b DOCUMENT ME!
1151 public void setShowJVSuffix(boolean b)
1160 * @return DOCUMENT ME!
1162 public boolean getShowAnnotation()
1164 return showAnnotation;
1170 * @param b DOCUMENT ME!
1172 public void setShowAnnotation(boolean b)
1180 * @return DOCUMENT ME!
1182 public boolean getScaleAboveWrapped()
1184 return scaleAboveWrapped;
1190 * @return DOCUMENT ME!
1192 public boolean getScaleLeftWrapped()
1194 return scaleLeftWrapped;
1200 * @return DOCUMENT ME!
1202 public boolean getScaleRightWrapped()
1204 return scaleRightWrapped;
1210 * @param b DOCUMENT ME!
1212 public void setScaleAboveWrapped(boolean b)
1214 scaleAboveWrapped = b;
1220 * @param b DOCUMENT ME!
1222 public void setScaleLeftWrapped(boolean b)
1224 scaleLeftWrapped = b;
1230 * @param b DOCUMENT ME!
1232 public void setScaleRightWrapped(boolean b)
1234 scaleRightWrapped = b;
1238 * Property change listener for changes in alignment
1240 * @param listener DOCUMENT ME!
1242 public void addPropertyChangeListener(
1243 java.beans.PropertyChangeListener listener)
1245 changeSupport.addPropertyChangeListener(listener);
1251 * @param listener DOCUMENT ME!
1253 public void removePropertyChangeListener(
1254 java.beans.PropertyChangeListener listener)
1256 changeSupport.removePropertyChangeListener(listener);
1260 * Property change listener for changes in alignment
1262 * @param prop DOCUMENT ME!
1263 * @param oldvalue DOCUMENT ME!
1264 * @param newvalue DOCUMENT ME!
1266 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
1268 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1271 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1273 ignoreGapsInConsensusCalculation = b;
1274 updateConsensus(ap);
1275 if(globalColourScheme!=null)
1277 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1278 ignoreGapsInConsensusCalculation);
1282 public boolean getIgnoreGapsConsensus()
1284 return ignoreGapsInConsensusCalculation;
1287 public void setDataset(boolean b)
1292 public boolean isDataset()
1298 public void hideSelectedColumns()
1300 if (colSel.size() < 1)
1305 colSel.hideSelectedColumns();
1306 setSelectionGroup(null);
1308 hasHiddenColumns = true;
1312 public void hideColumns(int start, int end)
1316 colSel.hideColumns(start);
1320 colSel.hideColumns(start, end);
1323 hasHiddenColumns = true;
1326 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1328 int sSize = sg.getSize();
1334 if(hiddenRepSequences==null)
1336 hiddenRepSequences = new Hashtable();
1339 hiddenRepSequences.put(repSequence, sg);
1341 //Hide all sequences except the repSequence
1342 SequenceI [] seqs = new SequenceI[sSize-1];
1344 for(int i=0; i<sSize; i++)
1346 if(sg.getSequenceAt(i)!=repSequence)
1353 seqs[index++] = sg.getSequenceAt(i);
1361 public void hideAllSelectedSeqs()
1363 if (selectionGroup == null || selectionGroup.getSize()<1)
1368 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1372 setSelectionGroup(null);
1375 public void hideSequence(SequenceI [] seq)
1379 for (int i = 0; i < seq.length; i++)
1381 alignment.getHiddenSequences().hideSequence(seq[i]);
1383 hasHiddenRows = true;
1384 firePropertyChange("alignment", null, alignment.getSequences());
1388 public void showSequence(int index)
1390 Vector tmp = alignment.getHiddenSequences().showSequence(index
1391 , hiddenRepSequences);
1394 if(selectionGroup==null)
1396 selectionGroup = new SequenceGroup();
1397 selectionGroup.setEndRes(alignment.getWidth()-1);
1400 for (int t = 0; t < tmp.size(); t++)
1402 selectionGroup.addSequence(
1403 (SequenceI) tmp.elementAt(t), false
1406 firePropertyChange("alignment", null, alignment.getSequences());
1409 if(alignment.getHiddenSequences().getSize()<1)
1411 hasHiddenRows = false;
1415 public void showColumn(int col)
1417 colSel.revealHiddenColumns(col);
1418 if(colSel.getHiddenColumns()==null)
1420 hasHiddenColumns = false;
1424 public void showAllHiddenColumns()
1426 colSel.revealAllHiddenColumns();
1427 hasHiddenColumns = false;
1430 public void showAllHiddenSeqs()
1432 if(alignment.getHiddenSequences().getSize()>0)
1434 if(selectionGroup==null)
1436 selectionGroup = new SequenceGroup();
1437 selectionGroup.setEndRes(alignment.getWidth()-1);
1439 Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
1440 for(int t=0; t<tmp.size(); t++)
1442 selectionGroup.addSequence(
1443 (SequenceI)tmp.elementAt(t), false
1446 firePropertyChange("alignment", null, alignment.getSequences());
1447 hasHiddenRows = false;
1448 hiddenRepSequences = null;
1454 public void invertColumnSelection()
1456 colSel.invertColumnSelection(0,alignment.getWidth());
1459 public int adjustForHiddenSeqs(int alignmentIndex)
1461 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
1465 * This method returns an array of new SequenceI objects
1466 * derived from the whole alignment or just the current
1467 * selection with start and end points adjusted
1468 * @note if you need references to the actual SequenceI objects in the alignment or currently selected then use getSequenceSelection()
1469 * @return selection as new sequenceI objects
1471 public SequenceI[] getSelectionAsNewSequence()
1473 SequenceI[] sequences;
1475 if (selectionGroup == null)
1477 sequences = alignment.getSequencesArray();
1478 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1479 for (int i=0; i<sequences.length; i++)
1481 sequences[i] = new Sequence(sequences[i], annots); // construct new sequence with subset of visible annotation
1486 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1493 * get the currently selected sequence objects or all the sequences in the alignment.
1494 * @return array of references to sequence objects
1496 public SequenceI[] getSequenceSelection()
1498 SequenceI[] sequences;
1499 if (selectionGroup==null)
1501 sequences = alignment.getSequencesArray();
1505 sequences = selectionGroup.getSequencesInOrder(alignment);
1510 * This method returns the visible alignment as text, as
1511 * seen on the GUI, ie if columns are hidden they will not
1512 * be returned in the result.
1513 * Use this for calculating trees, PCA, redundancy etc on views
1514 * which contain hidden columns.
1517 public jalview.datamodel.CigarArray getViewAsCigars(boolean
1520 CigarArray selection=null;
1521 SequenceI [] seqs= null;
1523 int start = 0, end = 0;
1524 if(selectedRegionOnly && selectionGroup!=null)
1526 iSize = selectionGroup.getSize();
1527 seqs = selectionGroup.getSequencesInOrder(alignment);
1528 start = selectionGroup.getStartRes();
1529 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
1533 iSize = alignment.getHeight();
1534 seqs = alignment.getSequencesArray();
1535 end = alignment.getWidth()-1;
1537 SeqCigar[] selseqs = new SeqCigar[iSize];
1538 for(i=0; i<iSize; i++)
1540 selseqs[i] = new SeqCigar(seqs[i], start, end);
1542 selection=new CigarArray(selseqs);
1543 // now construct the CigarArray operations
1544 if (hasHiddenColumns)
1546 Vector regions = colSel.getHiddenColumns();
1548 int hideStart, hideEnd;
1550 for (int j = 0; last<end & j < regions.size(); j++)
1552 region = (int[]) regions.elementAt(j);
1553 hideStart = region[0];
1554 hideEnd = region[1];
1555 // edit hidden regions to selection range
1556 if (hideStart < last)
1578 if (hideStart>hideEnd)
1583 * form operations...
1587 selection.addOperation(CigarArray.M, hideStart-last);
1589 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
1592 // Final match if necessary.
1595 selection.addOperation(CigarArray.M, end-last+1);
1600 selection.addOperation(CigarArray.M, end-start+1);
1605 * return a compact representation of the current alignment selection to
1606 * pass to an analysis function
1607 * @param selectedOnly boolean true to just return the selected view
1608 * @return AlignmentView
1610 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1613 // this is here because the AlignmentView constructor modifies the CigarArray
1614 // object. Refactoring of Cigar and alignment view representation should
1615 // be done to remove redundancy.
1616 CigarArray aligview = getViewAsCigars(selectedOnly);
1617 if (aligview != null)
1619 return new AlignmentView(aligview,
1620 (selectedOnly && selectionGroup != null) ?
1621 selectionGroup.getStartRes() : 0);
1626 * This method returns the visible alignment as text, as
1627 * seen on the GUI, ie if columns are hidden they will not
1628 * be returned in the result.
1629 * Use this for calculating trees, PCA, redundancy etc on views
1630 * which contain hidden columns.
1633 public String [] getViewAsString(boolean selectedRegionOnly)
1635 String [] selection = null;
1636 SequenceI [] seqs= null;
1638 int start = 0, end = 0;
1639 if(selectedRegionOnly && selectionGroup!=null)
1641 iSize = selectionGroup.getSize();
1642 seqs = selectionGroup.getSequencesInOrder(alignment);
1643 start = selectionGroup.getStartRes();
1644 end = selectionGroup.getEndRes()+1;
1648 iSize = alignment.getHeight();
1649 seqs = alignment.getSequencesArray();
1650 end = alignment.getWidth();
1653 selection = new String[iSize];
1654 if (hasHiddenColumns)
1656 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1660 for(i=0; i<iSize; i++)
1662 selection[i] = seqs[i].getSequenceAsString(start, end);
1669 public int [][] getVisibleRegionBoundaries(int min, int max)
1671 Vector regions = new Vector();
1677 if (hasHiddenColumns)
1681 start = colSel.adjustForHiddenColumns(start);
1684 end = colSel.getHiddenBoundaryRight(start);
1695 regions.addElement(new int[]
1698 if (hasHiddenColumns)
1700 start = colSel.adjustForHiddenColumns(end);
1701 start = colSel.getHiddenBoundaryLeft(start) + 1;
1706 int[][] startEnd = new int[regions.size()][2];
1708 regions.copyInto(startEnd);
1714 public boolean getShowHiddenMarkers()
1716 return showHiddenMarkers;
1719 public void setShowHiddenMarkers(boolean show)
1721 showHiddenMarkers = show;
1724 public String getSequenceSetId()
1726 if(sequenceSetID==null)
1728 sequenceSetID = alignment.hashCode()+"";
1731 return sequenceSetID;
1734 public void alignmentChanged(AlignmentPanel ap)
1738 alignment.padGaps();
1741 if (hconsensus != null && autoCalculateConsensus)
1743 updateConsensus(ap);
1744 updateConservation(ap);
1747 //Reset endRes of groups if beyond alignment width
1748 int alWidth = alignment.getWidth();
1749 Vector groups = alignment.getGroups();
1752 for(int i=0; i<groups.size(); i++)
1754 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
1755 if(sg.getEndRes()>alWidth)
1757 sg.setEndRes(alWidth-1);
1762 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
1764 selectionGroup.setEndRes(alWidth-1);
1767 resetAllColourSchemes();
1769 // alignment.adjustSequenceAnnotations();
1773 void resetAllColourSchemes()
1775 ColourSchemeI cs = globalColourScheme;
1778 if (cs instanceof ClustalxColourScheme)
1780 ( (ClustalxColourScheme) cs).
1781 resetClustalX(alignment.getSequences(),
1782 alignment.getWidth());
1785 cs.setConsensus(hconsensus);
1786 if (cs.conservationApplied())
1788 Alignment al = (Alignment) alignment;
1789 Conservation c = new Conservation("All",
1790 ResidueProperties.propHash, 3,
1791 al.getSequences(), 0,
1794 c.verdict(false, ConsPercGaps);
1796 cs.setConservation(c);
1800 int s, sSize = alignment.getGroups().size();
1801 for(s=0; s<sSize; s++)
1803 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
1804 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1806 ((ClustalxColourScheme)sg.cs).resetClustalX(
1807 sg.getSequences(hiddenRepSequences), sg.getWidth());
1809 sg.recalcConservation();
1814 public Color getSequenceColour(SequenceI seq)
1816 if(sequenceColours==null || !sequenceColours.containsKey(seq))
1822 return (Color)sequenceColours.get(seq);
1826 public void setSequenceColour(SequenceI seq, Color col)
1828 if(sequenceColours==null)
1830 sequenceColours = new Hashtable();
1835 sequenceColours.remove(seq);
1839 sequenceColours.put(seq, col);
1843 * returns the visible column regions of the alignment
1844 * @param selectedRegionOnly true to just return the contigs intersecting with the selected area
1847 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly) {
1848 int[] viscontigs=null;
1849 int start = 0, end = 0;
1850 if(selectedRegionOnly && selectionGroup!=null)
1852 start = selectionGroup.getStartRes();
1853 end = selectionGroup.getEndRes()+1;
1857 end = alignment.getWidth();
1859 viscontigs = colSel.getVisibleContigs(start, end);
1863 * get hash of undo and redo list for the alignment
1864 * @return long[] { historyList.hashCode, redoList.hashCode };
1866 public long[] getUndoRedoHash()
1868 if (historyList==null || redoList==null)
1869 return new long[] { -1, -1};
1870 return new long[] { historyList.hashCode(), this.redoList.hashCode() };
1873 * test if a particular set of hashcodes are different to the hashcodes for the undo and redo list.
1874 * @param undoredo the stored set of hashcodes as returned by getUndoRedoHash
1875 * @return true if the hashcodes differ (ie the alignment has been edited) or the stored hashcode array differs in size
1877 public boolean isUndoRedoHashModified(long[] undoredo)
1883 long[] cstate = getUndoRedoHash();
1884 if (cstate.length!=undoredo.length)
1887 for (int i=0; i<cstate.length; i++)
1889 if (cstate[i]!=undoredo[i])