2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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
20 * Jalview - A Sequence Alignment Editor and Viewer
21 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * as published by the Free Software Foundation; either version 2
26 * of the License, or (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
43 import jalview.analysis.*;
47 import jalview.datamodel.*;
49 import jalview.schemes.*;
50 import jalview.structure.StructureSelectionManager;
58 public class AlignViewport
68 boolean showJVSuffix = true;
70 boolean showText = true;
72 boolean showColourText = false;
74 boolean showBoxes = true;
76 boolean wrapAlignment = false;
78 boolean renderGaps = true;
80 boolean showSequenceFeatures = false;
82 boolean showAnnotation = true;
84 boolean colourAppliesToAllGroups = true;
86 ColourSchemeI globalColourScheme = null;
88 boolean conservationColourSelected = false;
90 boolean abovePIDThreshold = false;
92 SequenceGroup selectionGroup;
98 boolean validCharWidth;
104 boolean seqNameItalics;
106 AlignmentI alignment;
108 ColumnSelection colSel = new ColumnSelection();
114 NJTree currentTree = null;
116 boolean scaleAboveWrapped = false;
118 boolean scaleLeftWrapped = true;
120 boolean scaleRightWrapped = true;
122 boolean hasHiddenColumns = false;
124 boolean hasHiddenRows = false;
126 boolean showHiddenMarkers = true;
128 boolean cursorMode = false;
130 // The following vector holds the features which are
131 // currently visible, in the correct order or rendering
132 Hashtable featuresDisplayed = null;
135 public Hashtable[] hconsensus;
137 AlignmentAnnotation consensus;
139 AlignmentAnnotation conservation;
141 AlignmentAnnotation quality;
143 boolean autoCalculateConsensus = true;
146 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
148 // JBPNote Prolly only need this in the applet version.
149 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
152 boolean ignoreGapsInConsensusCalculation = false;
154 boolean isDataset = false;
156 boolean antiAlias = false;
158 boolean padGaps = false;
160 Rectangle explodedPosition;
164 String sequenceSetID;
166 boolean gatherViewsHere = false;
168 Stack historyList = new Stack();
170 Stack redoList = new Stack();
172 Hashtable sequenceColours;
174 int thresholdTextColour = 0;
176 Color textColour = Color.black;
178 Color textColour2 = Color.white;
180 boolean rightAlignIds = false;
182 Hashtable hiddenRepSequences;
185 * Creates a new AlignViewport object.
190 public AlignViewport(AlignmentI al)
197 * Create a new AlignViewport with hidden regions
201 * @param hiddenColumns
204 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
207 if (hiddenColumns != null)
209 this.colSel = hiddenColumns;
210 if (hiddenColumns.getHiddenColumns() != null)
212 hasHiddenColumns = true;
221 this.endRes = alignment.getWidth() - 1;
223 this.endSeq = alignment.getHeight() - 1;
225 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
227 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
228 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
230 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
231 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
232 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
234 padGaps = Cache.getDefault("PAD_GAPS", true);
236 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
237 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
238 String fontSize = Cache.getDefault("FONT_SIZE", "10");
240 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
244 if (fontStyle.equals("bold"))
248 else if (fontStyle.equals("italic"))
253 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
256 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
258 // We must set conservation and consensus before setting colour,
259 // as Blosum and Clustal require this to be done
260 if (hconsensus == null && !isDataset)
262 if (!alignment.isNucleotide())
264 conservation = new AlignmentAnnotation("Conservation",
265 "Conservation of total alignment less than " + ConsPercGaps
266 + "% gaps", new Annotation[1], 0f, 11f,
267 AlignmentAnnotation.BAR_GRAPH);
268 conservation.hasText = true;
269 conservation.autoCalculated = true;
271 if (Cache.getDefault("SHOW_CONSERVATION", true))
273 alignment.addAnnotation(conservation);
276 if (Cache.getDefault("SHOW_QUALITY", true))
278 quality = new AlignmentAnnotation("Quality",
279 "Alignment Quality based on Blosum62 scores",
280 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
281 quality.hasText = true;
282 quality.autoCalculated = true;
284 alignment.addAnnotation(quality);
288 consensus = new AlignmentAnnotation("Consensus", "PID",
289 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
290 consensus.hasText = true;
291 consensus.autoCalculated = true;
293 if (Cache.getDefault("SHOW_IDENTITY", true))
295 alignment.addAnnotation(consensus);
299 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
301 globalColourScheme = ColourSchemeProperty.getColour(alignment,
302 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
304 if (globalColourScheme instanceof UserColourScheme)
306 globalColourScheme = UserDefinedColours.loadDefaultColours();
307 ((UserColourScheme) globalColourScheme).setThreshold(0,
308 getIgnoreGapsConsensus());
311 if (globalColourScheme != null)
313 globalColourScheme.setConsensus(hconsensus);
317 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
326 public void setShowSequenceFeatures(boolean b)
328 showSequenceFeatures = b;
331 public boolean getShowSequenceFeatures()
333 return showSequenceFeatures;
336 class ConservationThread extends Thread
340 public ConservationThread(AlignmentPanel ap)
349 updatingConservation = true;
351 while (UPDATING_CONSERVATION)
357 ap.paintAlignment(false);
360 } catch (Exception ex)
362 ex.printStackTrace();
366 UPDATING_CONSERVATION = true;
368 int alWidth = alignment.getWidth();
374 Conservation cons = new jalview.analysis.Conservation("All",
375 jalview.schemes.ResidueProperties.propHash, 3, alignment
376 .getSequences(), 0, alWidth - 1);
379 cons.verdict(false, ConsPercGaps);
386 char[] sequence = cons.getConsSequence().getSequence();
398 maxB = 0f - minB; // scalable range for colouring both Conservation and
408 conservation.annotations = new Annotation[alWidth];
412 quality.graphMax = cons.qualityRange[1].floatValue();
413 quality.annotations = new Annotation[alWidth];
414 qmin = cons.qualityRange[0].floatValue();
415 qmax = cons.qualityRange[1].floatValue();
418 for (int i = 0; i < alWidth; i++)
424 if (Character.isDigit(c))
426 value = (int) (c - '0');
437 float vprop = value - min;
439 conservation.annotations[i] = new Annotation(String.valueOf(c),
440 String.valueOf(value), ' ', value, new Color(minR
441 + (maxR * vprop), minG + (maxG * vprop), minB
447 value = ((Double) cons.quality.get(i)).floatValue();
448 vprop = value - qmin;
450 quality.annotations[i] = new Annotation(" ", String
451 .valueOf(value), ' ', value, new Color(minR
452 + (maxR * vprop), minG + (maxG * vprop), minB
456 } catch (OutOfMemoryError error)
458 new OOMWarning("calculating conservation", error);
465 UPDATING_CONSERVATION = false;
466 updatingConservation = false;
470 ap.paintAlignment(true);
476 ConservationThread conservationThread;
478 ConsensusThread consensusThread;
480 boolean consUpdateNeeded = false;
482 static boolean UPDATING_CONSENSUS = false;
484 static boolean UPDATING_CONSERVATION = false;
486 boolean updatingConsensus = false;
488 boolean updatingConservation = false;
491 * centre columnar annotation labels in displayed alignment annotation TODO:
492 * add to jalviewXML and annotation display settings
494 boolean centreColumnLabels = false;
497 * trigger update of conservation annotation
499 public void updateConservation(final AlignmentPanel ap)
501 if (alignment.isNucleotide() || conservation == null)
506 conservationThread = new ConservationThread(ap);
507 conservationThread.start();
511 * trigger update of consensus annotation
513 public void updateConsensus(final AlignmentPanel ap)
515 consensusThread = new ConsensusThread(ap);
516 consensusThread.start();
519 class ConsensusThread extends Thread
523 public ConsensusThread(AlignmentPanel ap)
530 updatingConsensus = true;
531 while (UPDATING_CONSENSUS)
537 ap.paintAlignment(false);
541 } catch (Exception ex)
543 ex.printStackTrace();
547 UPDATING_CONSENSUS = true;
551 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
560 consensus.annotations = null;
561 consensus.annotations = new Annotation[aWidth];
563 hconsensus = new Hashtable[aWidth];
564 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
565 .getWidth(), hconsensus);
567 for (int i = 0; i < aWidth; i++)
570 if (ignoreGapsInConsensusCalculation)
572 value = ((Float) hconsensus[i].get(AAFrequency.PID_NOGAPS))
577 value = ((Float) hconsensus[i].get(AAFrequency.PID_GAPS))
581 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE)
583 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE)
586 if (maxRes.length() > 1)
588 mouseOver = "[" + maxRes + "] ";
592 mouseOver += ((int) value + "%");
593 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
597 if (globalColourScheme != null)
599 globalColourScheme.setConsensus(hconsensus);
602 } catch (OutOfMemoryError error)
604 alignment.deleteAnnotation(consensus);
608 new OOMWarning("calculating consensus", error);
610 UPDATING_CONSENSUS = false;
611 updatingConsensus = false;
615 ap.paintAlignment(true);
621 * get the consensus sequence as displayed under the PID consensus annotation
624 * @return consensus sequence as a new sequence object
626 public SequenceI getConsensusSeq()
628 if (consensus == null)
630 updateConsensus(null);
632 if (consensus == null)
636 StringBuffer seqs = new StringBuffer();
637 for (int i = 0; i < consensus.annotations.length; i++)
639 if (consensus.annotations[i] != null)
641 if (consensus.annotations[i].description.charAt(0) == '[')
643 seqs.append(consensus.annotations[i].description.charAt(1));
647 seqs.append(consensus.annotations[i].displayCharacter);
652 SequenceI sq = new Sequence("Consensus", seqs.toString());
653 sq.setDescription("Percentage Identity Consensus "
654 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
661 * @return DOCUMENT ME!
663 public SequenceGroup getSelectionGroup()
665 return selectionGroup;
674 public void setSelectionGroup(SequenceGroup sg)
682 * @return DOCUMENT ME!
684 public boolean getConservationSelected()
686 return conservationColourSelected;
695 public void setConservationSelected(boolean b)
697 conservationColourSelected = b;
703 * @return DOCUMENT ME!
705 public boolean getAbovePIDThreshold()
707 return abovePIDThreshold;
716 public void setAbovePIDThreshold(boolean b)
718 abovePIDThreshold = b;
724 * @return DOCUMENT ME!
726 public int getStartRes()
734 * @return DOCUMENT ME!
736 public int getEndRes()
744 * @return DOCUMENT ME!
746 public int getStartSeq()
757 public void setGlobalColourScheme(ColourSchemeI cs)
759 globalColourScheme = cs;
765 * @return DOCUMENT ME!
767 public ColourSchemeI getGlobalColourScheme()
769 return globalColourScheme;
778 public void setStartRes(int res)
789 public void setStartSeq(int seq)
800 public void setEndRes(int res)
802 if (res > (alignment.getWidth() - 1))
804 // log.System.out.println(" Corrected res from " + res + " to maximum " +
805 // (alignment.getWidth()-1));
806 res = alignment.getWidth() - 1;
823 public void setEndSeq(int seq)
825 if (seq > alignment.getHeight())
827 seq = alignment.getHeight();
841 * @return DOCUMENT ME!
843 public int getEndSeq()
854 public void setFont(Font f)
858 Container c = new Container();
860 java.awt.FontMetrics fm = c.getFontMetrics(font);
861 setCharHeight(fm.getHeight());
862 setCharWidth(fm.charWidth('M'));
863 validCharWidth = true;
869 * @return DOCUMENT ME!
871 public Font getFont()
882 public void setCharWidth(int w)
890 * @return DOCUMENT ME!
892 public int getCharWidth()
903 public void setCharHeight(int h)
911 * @return DOCUMENT ME!
913 public int getCharHeight()
924 public void setWrappedWidth(int w)
926 this.wrappedWidth = w;
932 * @return DOCUMENT ME!
934 public int getWrappedWidth()
942 * @return DOCUMENT ME!
944 public AlignmentI getAlignment()
955 public void setAlignment(AlignmentI align)
957 if (alignment != null && alignment.getCodonFrames() != null)
959 StructureSelectionManager.getStructureSelectionManager()
960 .removeMappings(alignment.getCodonFrames());
962 this.alignment = align;
963 if (alignment.getCodonFrames() != null)
965 StructureSelectionManager.getStructureSelectionManager().addMappings(
966 alignment.getCodonFrames());
976 public void setWrapAlignment(boolean state)
978 wrapAlignment = state;
987 public void setShowText(boolean state)
998 public void setRenderGaps(boolean state)
1006 * @return DOCUMENT ME!
1008 public boolean getColourText()
1010 return showColourText;
1019 public void setColourText(boolean state)
1021 showColourText = state;
1030 public void setShowBoxes(boolean state)
1038 * @return DOCUMENT ME!
1040 public boolean getWrapAlignment()
1042 return wrapAlignment;
1048 * @return DOCUMENT ME!
1050 public boolean getShowText()
1058 * @return DOCUMENT ME!
1060 public boolean getShowBoxes()
1068 * @return DOCUMENT ME!
1070 public char getGapCharacter()
1072 return getAlignment().getGapCharacter();
1081 public void setGapCharacter(char gap)
1083 if (getAlignment() != null)
1085 getAlignment().setGapCharacter(gap);
1095 public void setThreshold(int thresh)
1103 * @return DOCUMENT ME!
1105 public int getThreshold()
1116 public void setIncrement(int inc)
1124 * @return DOCUMENT ME!
1126 public int getIncrement()
1134 * @return DOCUMENT ME!
1136 public ColumnSelection getColumnSelection()
1147 public void setCurrentTree(NJTree tree)
1155 * @return DOCUMENT ME!
1157 public NJTree getCurrentTree()
1168 public void setColourAppliesToAllGroups(boolean b)
1170 colourAppliesToAllGroups = b;
1176 * @return DOCUMENT ME!
1178 public boolean getColourAppliesToAllGroups()
1180 return colourAppliesToAllGroups;
1186 * @return DOCUMENT ME!
1188 public boolean getShowJVSuffix()
1190 return showJVSuffix;
1199 public void setShowJVSuffix(boolean b)
1207 * @return DOCUMENT ME!
1209 public boolean getShowAnnotation()
1211 return showAnnotation;
1220 public void setShowAnnotation(boolean b)
1228 * @return DOCUMENT ME!
1230 public boolean getScaleAboveWrapped()
1232 return scaleAboveWrapped;
1238 * @return DOCUMENT ME!
1240 public boolean getScaleLeftWrapped()
1242 return scaleLeftWrapped;
1248 * @return DOCUMENT ME!
1250 public boolean getScaleRightWrapped()
1252 return scaleRightWrapped;
1261 public void setScaleAboveWrapped(boolean b)
1263 scaleAboveWrapped = b;
1272 public void setScaleLeftWrapped(boolean b)
1274 scaleLeftWrapped = b;
1283 public void setScaleRightWrapped(boolean b)
1285 scaleRightWrapped = b;
1289 * Property change listener for changes in alignment
1294 public void addPropertyChangeListener(
1295 java.beans.PropertyChangeListener listener)
1297 changeSupport.addPropertyChangeListener(listener);
1306 public void removePropertyChangeListener(
1307 java.beans.PropertyChangeListener listener)
1309 changeSupport.removePropertyChangeListener(listener);
1313 * Property change listener for changes in alignment
1322 public void firePropertyChange(String prop, Object oldvalue,
1325 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1328 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1330 ignoreGapsInConsensusCalculation = b;
1331 updateConsensus(ap);
1332 if (globalColourScheme != null)
1334 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1335 ignoreGapsInConsensusCalculation);
1339 public boolean getIgnoreGapsConsensus()
1341 return ignoreGapsInConsensusCalculation;
1344 public void setDataset(boolean b)
1349 public boolean isDataset()
1354 public void hideSelectedColumns()
1356 if (colSel.size() < 1)
1361 colSel.hideSelectedColumns();
1362 setSelectionGroup(null);
1364 hasHiddenColumns = true;
1367 public void hideColumns(int start, int end)
1371 colSel.hideColumns(start);
1375 colSel.hideColumns(start, end);
1378 hasHiddenColumns = true;
1381 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1383 int sSize = sg.getSize();
1389 if (hiddenRepSequences == null)
1391 hiddenRepSequences = new Hashtable();
1394 hiddenRepSequences.put(repSequence, sg);
1396 // Hide all sequences except the repSequence
1397 SequenceI[] seqs = new SequenceI[sSize - 1];
1399 for (int i = 0; i < sSize; i++)
1401 if (sg.getSequenceAt(i) != repSequence)
1403 if (index == sSize - 1)
1408 seqs[index++] = sg.getSequenceAt(i);
1416 public void hideAllSelectedSeqs()
1418 if (selectionGroup == null || selectionGroup.getSize() < 1)
1423 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1427 setSelectionGroup(null);
1430 public void hideSequence(SequenceI[] seq)
1434 for (int i = 0; i < seq.length; i++)
1436 alignment.getHiddenSequences().hideSequence(seq[i]);
1438 hasHiddenRows = true;
1439 firePropertyChange("alignment", null, alignment.getSequences());
1443 public void showSequence(int index)
1445 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1446 hiddenRepSequences);
1449 if (selectionGroup == null)
1451 selectionGroup = new SequenceGroup();
1452 selectionGroup.setEndRes(alignment.getWidth() - 1);
1455 for (int t = 0; t < tmp.size(); t++)
1457 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1459 firePropertyChange("alignment", null, alignment.getSequences());
1462 if (alignment.getHiddenSequences().getSize() < 1)
1464 hasHiddenRows = false;
1468 public void showColumn(int col)
1470 colSel.revealHiddenColumns(col);
1471 if (colSel.getHiddenColumns() == null)
1473 hasHiddenColumns = false;
1477 public void showAllHiddenColumns()
1479 colSel.revealAllHiddenColumns();
1480 hasHiddenColumns = false;
1483 public void showAllHiddenSeqs()
1485 if (alignment.getHiddenSequences().getSize() > 0)
1487 if (selectionGroup == null)
1489 selectionGroup = new SequenceGroup();
1490 selectionGroup.setEndRes(alignment.getWidth() - 1);
1492 Vector tmp = alignment.getHiddenSequences().showAll(
1493 hiddenRepSequences);
1494 for (int t = 0; t < tmp.size(); t++)
1496 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1498 firePropertyChange("alignment", null, alignment.getSequences());
1499 hasHiddenRows = false;
1500 hiddenRepSequences = null;
1504 public void invertColumnSelection()
1506 colSel.invertColumnSelection(0, alignment.getWidth());
1509 public int adjustForHiddenSeqs(int alignmentIndex)
1511 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1516 * This method returns an array of new SequenceI objects derived from the
1517 * whole alignment or just the current selection with start and end points
1520 * @note if you need references to the actual SequenceI objects in the
1521 * alignment or currently selected then use getSequenceSelection()
1522 * @return selection as new sequenceI objects
1524 public SequenceI[] getSelectionAsNewSequence()
1526 SequenceI[] sequences;
1528 if (selectionGroup == null)
1530 sequences = alignment.getSequencesArray();
1531 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1532 for (int i = 0; i < sequences.length; i++)
1534 sequences[i] = new Sequence(sequences[i], annots); // construct new
1536 // subset of visible
1542 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1549 * get the currently selected sequence objects or all the sequences in the
1552 * @return array of references to sequence objects
1554 public SequenceI[] getSequenceSelection()
1556 SequenceI[] sequences;
1557 if (selectionGroup == null)
1559 sequences = alignment.getSequencesArray();
1563 sequences = selectionGroup.getSequencesInOrder(alignment);
1569 * This method returns the visible alignment as text, as seen on the GUI, ie
1570 * if columns are hidden they will not be returned in the result. Use this for
1571 * calculating trees, PCA, redundancy etc on views which contain hidden
1576 public jalview.datamodel.CigarArray getViewAsCigars(
1577 boolean selectedRegionOnly)
1579 CigarArray selection = null;
1580 SequenceI[] seqs = null;
1582 int start = 0, end = 0;
1583 if (selectedRegionOnly && selectionGroup != null)
1585 iSize = selectionGroup.getSize();
1586 seqs = selectionGroup.getSequencesInOrder(alignment);
1587 start = selectionGroup.getStartRes();
1588 end = selectionGroup.getEndRes(); // inclusive for start and end in
1589 // SeqCigar constructor
1593 iSize = alignment.getHeight();
1594 seqs = alignment.getSequencesArray();
1595 end = alignment.getWidth() - 1;
1597 SeqCigar[] selseqs = new SeqCigar[iSize];
1598 for (i = 0; i < iSize; i++)
1600 selseqs[i] = new SeqCigar(seqs[i], start, end);
1602 selection = new CigarArray(selseqs);
1603 // now construct the CigarArray operations
1604 if (hasHiddenColumns)
1606 Vector regions = colSel.getHiddenColumns();
1608 int hideStart, hideEnd;
1610 for (int j = 0; last < end & j < regions.size(); j++)
1612 region = (int[]) regions.elementAt(j);
1613 hideStart = region[0];
1614 hideEnd = region[1];
1615 // edit hidden regions to selection range
1616 if (hideStart < last)
1628 if (hideStart > end)
1638 if (hideStart > hideEnd)
1643 * form operations...
1645 if (last < hideStart)
1647 selection.addOperation(CigarArray.M, hideStart - last);
1649 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1652 // Final match if necessary.
1655 selection.addOperation(CigarArray.M, end - last + 1);
1660 selection.addOperation(CigarArray.M, end - start + 1);
1666 * return a compact representation of the current alignment selection to pass
1667 * to an analysis function
1669 * @param selectedOnly
1670 * boolean true to just return the selected view
1671 * @return AlignmentView
1673 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1676 // this is here because the AlignmentView constructor modifies the
1678 // object. Refactoring of Cigar and alignment view representation should
1679 // be done to remove redundancy.
1680 CigarArray aligview = getViewAsCigars(selectedOnly);
1681 if (aligview != null)
1683 return new AlignmentView(aligview,
1684 (selectedOnly && selectionGroup != null) ? selectionGroup
1685 .getStartRes() : 0);
1691 * This method returns the visible alignment as text, as seen on the GUI, ie
1692 * if columns are hidden they will not be returned in the result. Use this for
1693 * calculating trees, PCA, redundancy etc on views which contain hidden
1698 public String[] getViewAsString(boolean selectedRegionOnly)
1700 String[] selection = null;
1701 SequenceI[] seqs = null;
1703 int start = 0, end = 0;
1704 if (selectedRegionOnly && selectionGroup != null)
1706 iSize = selectionGroup.getSize();
1707 seqs = selectionGroup.getSequencesInOrder(alignment);
1708 start = selectionGroup.getStartRes();
1709 end = selectionGroup.getEndRes() + 1;
1713 iSize = alignment.getHeight();
1714 seqs = alignment.getSequencesArray();
1715 end = alignment.getWidth();
1718 selection = new String[iSize];
1719 if (hasHiddenColumns)
1721 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1725 for (i = 0; i < iSize; i++)
1727 selection[i] = seqs[i].getSequenceAsString(start, end);
1734 public int[][] getVisibleRegionBoundaries(int min, int max)
1736 Vector regions = new Vector();
1742 if (hasHiddenColumns)
1746 start = colSel.adjustForHiddenColumns(start);
1749 end = colSel.getHiddenBoundaryRight(start);
1760 regions.addElement(new int[]
1763 if (hasHiddenColumns)
1765 start = colSel.adjustForHiddenColumns(end);
1766 start = colSel.getHiddenBoundaryLeft(start) + 1;
1768 } while (end < max);
1770 int[][] startEnd = new int[regions.size()][2];
1772 regions.copyInto(startEnd);
1778 public boolean getShowHiddenMarkers()
1780 return showHiddenMarkers;
1783 public void setShowHiddenMarkers(boolean show)
1785 showHiddenMarkers = show;
1788 public String getSequenceSetId()
1790 if (sequenceSetID == null)
1792 sequenceSetID = alignment.hashCode() + "";
1795 return sequenceSetID;
1798 public void alignmentChanged(AlignmentPanel ap)
1802 alignment.padGaps();
1805 if (hconsensus != null && autoCalculateConsensus)
1807 updateConsensus(ap);
1808 updateConservation(ap);
1811 // Reset endRes of groups if beyond alignment width
1812 int alWidth = alignment.getWidth();
1813 Vector groups = alignment.getGroups();
1816 for (int i = 0; i < groups.size(); i++)
1818 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1819 if (sg.getEndRes() > alWidth)
1821 sg.setEndRes(alWidth - 1);
1826 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1828 selectionGroup.setEndRes(alWidth - 1);
1831 resetAllColourSchemes();
1833 // alignment.adjustSequenceAnnotations();
1836 void resetAllColourSchemes()
1838 ColourSchemeI cs = globalColourScheme;
1841 if (cs instanceof ClustalxColourScheme)
1843 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1844 alignment.getWidth());
1847 cs.setConsensus(hconsensus);
1848 if (cs.conservationApplied())
1850 Alignment al = (Alignment) alignment;
1851 Conservation c = new Conservation("All",
1852 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1855 c.verdict(false, ConsPercGaps);
1857 cs.setConservation(c);
1861 int s, sSize = alignment.getGroups().size();
1862 for (s = 0; s < sSize; s++)
1864 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1865 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1867 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1868 .getSequences(hiddenRepSequences), sg.getWidth());
1870 sg.recalcConservation();
1874 public Color getSequenceColour(SequenceI seq)
1876 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1882 return (Color) sequenceColours.get(seq);
1886 public void setSequenceColour(SequenceI seq, Color col)
1888 if (sequenceColours == null)
1890 sequenceColours = new Hashtable();
1895 sequenceColours.remove(seq);
1899 sequenceColours.put(seq, col);
1904 * returns the visible column regions of the alignment
1906 * @param selectedRegionOnly
1907 * true to just return the contigs intersecting with the
1911 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1913 int[] viscontigs = null;
1914 int start = 0, end = 0;
1915 if (selectedRegionOnly && selectionGroup != null)
1917 start = selectionGroup.getStartRes();
1918 end = selectionGroup.getEndRes() + 1;
1922 end = alignment.getWidth();
1924 viscontigs = colSel.getVisibleContigs(start, end);
1929 * get hash of undo and redo list for the alignment
1931 * @return long[] { historyList.hashCode, redoList.hashCode };
1933 public long[] getUndoRedoHash()
1935 if (historyList == null || redoList == null)
1939 { historyList.hashCode(), this.redoList.hashCode() };
1943 * test if a particular set of hashcodes are different to the hashcodes for
1944 * the undo and redo list.
1947 * the stored set of hashcodes as returned by getUndoRedoHash
1948 * @return true if the hashcodes differ (ie the alignment has been edited) or
1949 * the stored hashcode array differs in size
1951 public boolean isUndoRedoHashModified(long[] undoredo)
1953 if (undoredo == null)
1957 long[] cstate = getUndoRedoHash();
1958 if (cstate.length != undoredo.length)
1963 for (int i = 0; i < cstate.length; i++)
1965 if (cstate[i] != undoredo[i])
1973 public boolean getCentreColumnLabels()
1975 return centreColumnLabels;
1978 public void setCentreColumnLabels(boolean centrecolumnlabels)
1980 centreColumnLabels = centrecolumnlabels;
1983 public void updateSequenceIdColours()
1985 Vector groups = alignment.getGroups();
1986 if (sequenceColours == null)
1988 sequenceColours = new Hashtable();
1990 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1992 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1993 if (sg.idColour != null)
1995 Vector sqs = sg.getSequences(hiddenRepSequences);
1996 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1998 sequenceColours.put(sqs.elementAt(s), sg.idColour);