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);
235 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP",true);
236 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP",true);
238 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
239 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
240 String fontSize = Cache.getDefault("FONT_SIZE", "10");
242 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
246 if (fontStyle.equals("bold"))
250 else if (fontStyle.equals("italic"))
255 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
258 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
260 // We must set conservation and consensus before setting colour,
261 // as Blosum and Clustal require this to be done
262 if (hconsensus == null && !isDataset)
264 if (!alignment.isNucleotide())
266 conservation = new AlignmentAnnotation("Conservation",
267 "Conservation of total alignment less than " + ConsPercGaps
268 + "% gaps", new Annotation[1], 0f, 11f,
269 AlignmentAnnotation.BAR_GRAPH);
270 conservation.hasText = true;
271 conservation.autoCalculated = true;
273 if (Cache.getDefault("SHOW_CONSERVATION", true))
275 alignment.addAnnotation(conservation);
278 if (Cache.getDefault("SHOW_QUALITY", true))
280 quality = new AlignmentAnnotation("Quality",
281 "Alignment Quality based on Blosum62 scores",
282 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
283 quality.hasText = true;
284 quality.autoCalculated = true;
286 alignment.addAnnotation(quality);
290 consensus = new AlignmentAnnotation("Consensus", "PID",
291 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
292 consensus.hasText = true;
293 consensus.autoCalculated = true;
295 if (Cache.getDefault("SHOW_IDENTITY", true))
297 alignment.addAnnotation(consensus);
301 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
303 globalColourScheme = ColourSchemeProperty.getColour(alignment,
304 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
306 if (globalColourScheme instanceof UserColourScheme)
308 globalColourScheme = UserDefinedColours.loadDefaultColours();
309 ((UserColourScheme) globalColourScheme).setThreshold(0,
310 getIgnoreGapsConsensus());
313 if (globalColourScheme != null)
315 globalColourScheme.setConsensus(hconsensus);
319 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
328 public void setShowSequenceFeatures(boolean b)
330 showSequenceFeatures = b;
333 public boolean getShowSequenceFeatures()
335 return showSequenceFeatures;
338 class ConservationThread extends Thread
342 public ConservationThread(AlignmentPanel ap)
351 updatingConservation = true;
353 while (UPDATING_CONSERVATION)
359 ap.paintAlignment(false);
362 } catch (Exception ex)
364 ex.printStackTrace();
368 UPDATING_CONSERVATION = true;
370 int alWidth = alignment.getWidth();
376 Conservation cons = new jalview.analysis.Conservation("All",
377 jalview.schemes.ResidueProperties.propHash, 3, alignment
378 .getSequences(), 0, alWidth - 1);
381 cons.verdict(false, ConsPercGaps);
388 char[] sequence = cons.getConsSequence().getSequence();
400 maxB = 0f - minB; // scalable range for colouring both Conservation and
410 conservation.annotations = new Annotation[alWidth];
414 quality.graphMax = cons.qualityRange[1].floatValue();
415 quality.annotations = new Annotation[alWidth];
416 qmin = cons.qualityRange[0].floatValue();
417 qmax = cons.qualityRange[1].floatValue();
420 for (int i = 0; i < alWidth; i++)
426 if (Character.isDigit(c))
428 value = (int) (c - '0');
439 float vprop = value - min;
441 conservation.annotations[i] = new Annotation(String.valueOf(c),
442 String.valueOf(value), ' ', value, new Color(minR
443 + (maxR * vprop), minG + (maxG * vprop), minB
449 value = ((Double) cons.quality.get(i)).floatValue();
450 vprop = value - qmin;
452 quality.annotations[i] = new Annotation(" ", String
453 .valueOf(value), ' ', value, new Color(minR
454 + (maxR * vprop), minG + (maxG * vprop), minB
458 } catch (OutOfMemoryError error)
460 new OOMWarning("calculating conservation", error);
467 UPDATING_CONSERVATION = false;
468 updatingConservation = false;
472 ap.paintAlignment(true);
478 ConservationThread conservationThread;
480 ConsensusThread consensusThread;
482 boolean consUpdateNeeded = false;
484 static boolean UPDATING_CONSENSUS = false;
486 static boolean UPDATING_CONSERVATION = false;
488 boolean updatingConsensus = false;
490 boolean updatingConservation = false;
493 * centre columnar annotation labels in displayed alignment annotation TODO:
494 * add to jalviewXML and annotation display settings
496 boolean centreColumnLabels = false;
498 private boolean showdbrefs;
500 private boolean shownpfeats;
503 * trigger update of conservation annotation
505 public void updateConservation(final AlignmentPanel ap)
507 if (alignment.isNucleotide() || conservation == null)
512 conservationThread = new ConservationThread(ap);
513 conservationThread.start();
517 * trigger update of consensus annotation
519 public void updateConsensus(final AlignmentPanel ap)
521 consensusThread = new ConsensusThread(ap);
522 consensusThread.start();
525 class ConsensusThread extends Thread
529 public ConsensusThread(AlignmentPanel ap)
536 updatingConsensus = true;
537 while (UPDATING_CONSENSUS)
543 ap.paintAlignment(false);
547 } catch (Exception ex)
549 ex.printStackTrace();
553 UPDATING_CONSENSUS = true;
557 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
566 consensus.annotations = null;
567 consensus.annotations = new Annotation[aWidth];
569 hconsensus = new Hashtable[aWidth];
570 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
571 .getWidth(), hconsensus);
573 for (int i = 0; i < aWidth; i++)
576 if (ignoreGapsInConsensusCalculation)
578 value = ((Float) hconsensus[i].get(AAFrequency.PID_NOGAPS))
583 value = ((Float) hconsensus[i].get(AAFrequency.PID_GAPS))
587 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE)
589 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE)
592 if (maxRes.length() > 1)
594 mouseOver = "[" + maxRes + "] ";
598 mouseOver += ((int) value + "%");
599 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
603 if (globalColourScheme != null)
605 globalColourScheme.setConsensus(hconsensus);
608 } catch (OutOfMemoryError error)
610 alignment.deleteAnnotation(consensus);
614 new OOMWarning("calculating consensus", error);
616 UPDATING_CONSENSUS = false;
617 updatingConsensus = false;
621 ap.paintAlignment(true);
627 * get the consensus sequence as displayed under the PID consensus annotation
630 * @return consensus sequence as a new sequence object
632 public SequenceI getConsensusSeq()
634 if (consensus == null)
636 updateConsensus(null);
638 if (consensus == null)
642 StringBuffer seqs = new StringBuffer();
643 for (int i = 0; i < consensus.annotations.length; i++)
645 if (consensus.annotations[i] != null)
647 if (consensus.annotations[i].description.charAt(0) == '[')
649 seqs.append(consensus.annotations[i].description.charAt(1));
653 seqs.append(consensus.annotations[i].displayCharacter);
658 SequenceI sq = new Sequence("Consensus", seqs.toString());
659 sq.setDescription("Percentage Identity Consensus "
660 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
667 * @return DOCUMENT ME!
669 public SequenceGroup getSelectionGroup()
671 return selectionGroup;
680 public void setSelectionGroup(SequenceGroup sg)
688 * @return DOCUMENT ME!
690 public boolean getConservationSelected()
692 return conservationColourSelected;
701 public void setConservationSelected(boolean b)
703 conservationColourSelected = b;
709 * @return DOCUMENT ME!
711 public boolean getAbovePIDThreshold()
713 return abovePIDThreshold;
722 public void setAbovePIDThreshold(boolean b)
724 abovePIDThreshold = b;
730 * @return DOCUMENT ME!
732 public int getStartRes()
740 * @return DOCUMENT ME!
742 public int getEndRes()
750 * @return DOCUMENT ME!
752 public int getStartSeq()
763 public void setGlobalColourScheme(ColourSchemeI cs)
765 globalColourScheme = cs;
771 * @return DOCUMENT ME!
773 public ColourSchemeI getGlobalColourScheme()
775 return globalColourScheme;
784 public void setStartRes(int res)
795 public void setStartSeq(int seq)
806 public void setEndRes(int res)
808 if (res > (alignment.getWidth() - 1))
810 // log.System.out.println(" Corrected res from " + res + " to maximum " +
811 // (alignment.getWidth()-1));
812 res = alignment.getWidth() - 1;
829 public void setEndSeq(int seq)
831 if (seq > alignment.getHeight())
833 seq = alignment.getHeight();
847 * @return DOCUMENT ME!
849 public int getEndSeq()
860 public void setFont(Font f)
864 Container c = new Container();
866 java.awt.FontMetrics fm = c.getFontMetrics(font);
867 setCharHeight(fm.getHeight());
868 setCharWidth(fm.charWidth('M'));
869 validCharWidth = true;
875 * @return DOCUMENT ME!
877 public Font getFont()
888 public void setCharWidth(int w)
896 * @return DOCUMENT ME!
898 public int getCharWidth()
909 public void setCharHeight(int h)
917 * @return DOCUMENT ME!
919 public int getCharHeight()
930 public void setWrappedWidth(int w)
932 this.wrappedWidth = w;
938 * @return DOCUMENT ME!
940 public int getWrappedWidth()
948 * @return DOCUMENT ME!
950 public AlignmentI getAlignment()
961 public void setAlignment(AlignmentI align)
963 if (alignment != null && alignment.getCodonFrames() != null)
965 StructureSelectionManager.getStructureSelectionManager()
966 .removeMappings(alignment.getCodonFrames());
968 this.alignment = align;
969 if (alignment.getCodonFrames() != null)
971 StructureSelectionManager.getStructureSelectionManager().addMappings(
972 alignment.getCodonFrames());
982 public void setWrapAlignment(boolean state)
984 wrapAlignment = state;
993 public void setShowText(boolean state)
1004 public void setRenderGaps(boolean state)
1012 * @return DOCUMENT ME!
1014 public boolean getColourText()
1016 return showColourText;
1025 public void setColourText(boolean state)
1027 showColourText = state;
1036 public void setShowBoxes(boolean state)
1044 * @return DOCUMENT ME!
1046 public boolean getWrapAlignment()
1048 return wrapAlignment;
1054 * @return DOCUMENT ME!
1056 public boolean getShowText()
1064 * @return DOCUMENT ME!
1066 public boolean getShowBoxes()
1074 * @return DOCUMENT ME!
1076 public char getGapCharacter()
1078 return getAlignment().getGapCharacter();
1087 public void setGapCharacter(char gap)
1089 if (getAlignment() != null)
1091 getAlignment().setGapCharacter(gap);
1101 public void setThreshold(int thresh)
1109 * @return DOCUMENT ME!
1111 public int getThreshold()
1122 public void setIncrement(int inc)
1130 * @return DOCUMENT ME!
1132 public int getIncrement()
1140 * @return DOCUMENT ME!
1142 public ColumnSelection getColumnSelection()
1153 public void setCurrentTree(NJTree tree)
1161 * @return DOCUMENT ME!
1163 public NJTree getCurrentTree()
1174 public void setColourAppliesToAllGroups(boolean b)
1176 colourAppliesToAllGroups = b;
1182 * @return DOCUMENT ME!
1184 public boolean getColourAppliesToAllGroups()
1186 return colourAppliesToAllGroups;
1192 * @return DOCUMENT ME!
1194 public boolean getShowJVSuffix()
1196 return showJVSuffix;
1205 public void setShowJVSuffix(boolean b)
1213 * @return DOCUMENT ME!
1215 public boolean getShowAnnotation()
1217 return showAnnotation;
1226 public void setShowAnnotation(boolean b)
1234 * @return DOCUMENT ME!
1236 public boolean getScaleAboveWrapped()
1238 return scaleAboveWrapped;
1244 * @return DOCUMENT ME!
1246 public boolean getScaleLeftWrapped()
1248 return scaleLeftWrapped;
1254 * @return DOCUMENT ME!
1256 public boolean getScaleRightWrapped()
1258 return scaleRightWrapped;
1267 public void setScaleAboveWrapped(boolean b)
1269 scaleAboveWrapped = b;
1278 public void setScaleLeftWrapped(boolean b)
1280 scaleLeftWrapped = b;
1289 public void setScaleRightWrapped(boolean b)
1291 scaleRightWrapped = b;
1295 * Property change listener for changes in alignment
1300 public void addPropertyChangeListener(
1301 java.beans.PropertyChangeListener listener)
1303 changeSupport.addPropertyChangeListener(listener);
1312 public void removePropertyChangeListener(
1313 java.beans.PropertyChangeListener listener)
1315 changeSupport.removePropertyChangeListener(listener);
1319 * Property change listener for changes in alignment
1328 public void firePropertyChange(String prop, Object oldvalue,
1331 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1334 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1336 ignoreGapsInConsensusCalculation = b;
1337 updateConsensus(ap);
1338 if (globalColourScheme != null)
1340 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1341 ignoreGapsInConsensusCalculation);
1345 public boolean getIgnoreGapsConsensus()
1347 return ignoreGapsInConsensusCalculation;
1350 public void setDataset(boolean b)
1355 public boolean isDataset()
1360 public void hideSelectedColumns()
1362 if (colSel.size() < 1)
1367 colSel.hideSelectedColumns();
1368 setSelectionGroup(null);
1370 hasHiddenColumns = true;
1373 public void hideColumns(int start, int end)
1377 colSel.hideColumns(start);
1381 colSel.hideColumns(start, end);
1384 hasHiddenColumns = true;
1387 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1389 int sSize = sg.getSize();
1395 if (hiddenRepSequences == null)
1397 hiddenRepSequences = new Hashtable();
1400 hiddenRepSequences.put(repSequence, sg);
1402 // Hide all sequences except the repSequence
1403 SequenceI[] seqs = new SequenceI[sSize - 1];
1405 for (int i = 0; i < sSize; i++)
1407 if (sg.getSequenceAt(i) != repSequence)
1409 if (index == sSize - 1)
1414 seqs[index++] = sg.getSequenceAt(i);
1422 public void hideAllSelectedSeqs()
1424 if (selectionGroup == null || selectionGroup.getSize() < 1)
1429 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1433 setSelectionGroup(null);
1436 public void hideSequence(SequenceI[] seq)
1440 for (int i = 0; i < seq.length; i++)
1442 alignment.getHiddenSequences().hideSequence(seq[i]);
1444 hasHiddenRows = true;
1445 firePropertyChange("alignment", null, alignment.getSequences());
1449 public void showSequence(int index)
1451 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1452 hiddenRepSequences);
1455 if (selectionGroup == null)
1457 selectionGroup = new SequenceGroup();
1458 selectionGroup.setEndRes(alignment.getWidth() - 1);
1461 for (int t = 0; t < tmp.size(); t++)
1463 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1465 firePropertyChange("alignment", null, alignment.getSequences());
1468 if (alignment.getHiddenSequences().getSize() < 1)
1470 hasHiddenRows = false;
1474 public void showColumn(int col)
1476 colSel.revealHiddenColumns(col);
1477 if (colSel.getHiddenColumns() == null)
1479 hasHiddenColumns = false;
1483 public void showAllHiddenColumns()
1485 colSel.revealAllHiddenColumns();
1486 hasHiddenColumns = false;
1489 public void showAllHiddenSeqs()
1491 if (alignment.getHiddenSequences().getSize() > 0)
1493 if (selectionGroup == null)
1495 selectionGroup = new SequenceGroup();
1496 selectionGroup.setEndRes(alignment.getWidth() - 1);
1498 Vector tmp = alignment.getHiddenSequences().showAll(
1499 hiddenRepSequences);
1500 for (int t = 0; t < tmp.size(); t++)
1502 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1504 firePropertyChange("alignment", null, alignment.getSequences());
1505 hasHiddenRows = false;
1506 hiddenRepSequences = null;
1510 public void invertColumnSelection()
1512 colSel.invertColumnSelection(0, alignment.getWidth());
1515 public int adjustForHiddenSeqs(int alignmentIndex)
1517 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1522 * This method returns an array of new SequenceI objects derived from the
1523 * whole alignment or just the current selection with start and end points
1526 * @note if you need references to the actual SequenceI objects in the
1527 * alignment or currently selected then use getSequenceSelection()
1528 * @return selection as new sequenceI objects
1530 public SequenceI[] getSelectionAsNewSequence()
1532 SequenceI[] sequences;
1534 if (selectionGroup == null)
1536 sequences = alignment.getSequencesArray();
1537 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1538 for (int i = 0; i < sequences.length; i++)
1540 sequences[i] = new Sequence(sequences[i], annots); // construct new
1542 // subset of visible
1548 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1555 * get the currently selected sequence objects or all the sequences in the
1558 * @return array of references to sequence objects
1560 public SequenceI[] getSequenceSelection()
1562 SequenceI[] sequences;
1563 if (selectionGroup == null)
1565 sequences = alignment.getSequencesArray();
1569 sequences = selectionGroup.getSequencesInOrder(alignment);
1575 * This method returns the visible alignment as text, as seen on the GUI, ie
1576 * if columns are hidden they will not be returned in the result. Use this for
1577 * calculating trees, PCA, redundancy etc on views which contain hidden
1582 public jalview.datamodel.CigarArray getViewAsCigars(
1583 boolean selectedRegionOnly)
1585 CigarArray selection = null;
1586 SequenceI[] seqs = null;
1588 int start = 0, end = 0;
1589 if (selectedRegionOnly && selectionGroup != null)
1591 iSize = selectionGroup.getSize();
1592 seqs = selectionGroup.getSequencesInOrder(alignment);
1593 start = selectionGroup.getStartRes();
1594 end = selectionGroup.getEndRes(); // inclusive for start and end in
1595 // SeqCigar constructor
1599 iSize = alignment.getHeight();
1600 seqs = alignment.getSequencesArray();
1601 end = alignment.getWidth() - 1;
1603 SeqCigar[] selseqs = new SeqCigar[iSize];
1604 for (i = 0; i < iSize; i++)
1606 selseqs[i] = new SeqCigar(seqs[i], start, end);
1608 selection = new CigarArray(selseqs);
1609 // now construct the CigarArray operations
1610 if (hasHiddenColumns)
1612 Vector regions = colSel.getHiddenColumns();
1614 int hideStart, hideEnd;
1616 for (int j = 0; last < end & j < regions.size(); j++)
1618 region = (int[]) regions.elementAt(j);
1619 hideStart = region[0];
1620 hideEnd = region[1];
1621 // edit hidden regions to selection range
1622 if (hideStart < last)
1634 if (hideStart > end)
1644 if (hideStart > hideEnd)
1649 * form operations...
1651 if (last < hideStart)
1653 selection.addOperation(CigarArray.M, hideStart - last);
1655 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1658 // Final match if necessary.
1661 selection.addOperation(CigarArray.M, end - last + 1);
1666 selection.addOperation(CigarArray.M, end - start + 1);
1672 * return a compact representation of the current alignment selection to pass
1673 * to an analysis function
1675 * @param selectedOnly
1676 * boolean true to just return the selected view
1677 * @return AlignmentView
1679 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1682 // this is here because the AlignmentView constructor modifies the
1684 // object. Refactoring of Cigar and alignment view representation should
1685 // be done to remove redundancy.
1686 CigarArray aligview = getViewAsCigars(selectedOnly);
1687 if (aligview != null)
1689 return new AlignmentView(aligview,
1690 (selectedOnly && selectionGroup != null) ? selectionGroup
1691 .getStartRes() : 0);
1697 * This method returns the visible alignment as text, as seen on the GUI, ie
1698 * if columns are hidden they will not be returned in the result. Use this for
1699 * calculating trees, PCA, redundancy etc on views which contain hidden
1704 public String[] getViewAsString(boolean selectedRegionOnly)
1706 String[] selection = null;
1707 SequenceI[] seqs = null;
1709 int start = 0, end = 0;
1710 if (selectedRegionOnly && selectionGroup != null)
1712 iSize = selectionGroup.getSize();
1713 seqs = selectionGroup.getSequencesInOrder(alignment);
1714 start = selectionGroup.getStartRes();
1715 end = selectionGroup.getEndRes() + 1;
1719 iSize = alignment.getHeight();
1720 seqs = alignment.getSequencesArray();
1721 end = alignment.getWidth();
1724 selection = new String[iSize];
1725 if (hasHiddenColumns)
1727 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1731 for (i = 0; i < iSize; i++)
1733 selection[i] = seqs[i].getSequenceAsString(start, end);
1740 public int[][] getVisibleRegionBoundaries(int min, int max)
1742 Vector regions = new Vector();
1748 if (hasHiddenColumns)
1752 start = colSel.adjustForHiddenColumns(start);
1755 end = colSel.getHiddenBoundaryRight(start);
1766 regions.addElement(new int[]
1769 if (hasHiddenColumns)
1771 start = colSel.adjustForHiddenColumns(end);
1772 start = colSel.getHiddenBoundaryLeft(start) + 1;
1774 } while (end < max);
1776 int[][] startEnd = new int[regions.size()][2];
1778 regions.copyInto(startEnd);
1784 public boolean getShowHiddenMarkers()
1786 return showHiddenMarkers;
1789 public void setShowHiddenMarkers(boolean show)
1791 showHiddenMarkers = show;
1794 public String getSequenceSetId()
1796 if (sequenceSetID == null)
1798 sequenceSetID = alignment.hashCode() + "";
1801 return sequenceSetID;
1804 public void alignmentChanged(AlignmentPanel ap)
1808 alignment.padGaps();
1811 if (hconsensus != null && autoCalculateConsensus)
1813 updateConsensus(ap);
1814 updateConservation(ap);
1817 // Reset endRes of groups if beyond alignment width
1818 int alWidth = alignment.getWidth();
1819 Vector groups = alignment.getGroups();
1822 for (int i = 0; i < groups.size(); i++)
1824 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1825 if (sg.getEndRes() > alWidth)
1827 sg.setEndRes(alWidth - 1);
1832 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1834 selectionGroup.setEndRes(alWidth - 1);
1837 resetAllColourSchemes();
1839 // alignment.adjustSequenceAnnotations();
1842 void resetAllColourSchemes()
1844 ColourSchemeI cs = globalColourScheme;
1847 if (cs instanceof ClustalxColourScheme)
1849 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1850 alignment.getWidth());
1853 cs.setConsensus(hconsensus);
1854 if (cs.conservationApplied())
1856 Alignment al = (Alignment) alignment;
1857 Conservation c = new Conservation("All",
1858 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1861 c.verdict(false, ConsPercGaps);
1863 cs.setConservation(c);
1867 int s, sSize = alignment.getGroups().size();
1868 for (s = 0; s < sSize; s++)
1870 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1871 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1873 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1874 .getSequences(hiddenRepSequences), sg.getWidth());
1876 sg.recalcConservation();
1880 public Color getSequenceColour(SequenceI seq)
1882 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1888 return (Color) sequenceColours.get(seq);
1892 public void setSequenceColour(SequenceI seq, Color col)
1894 if (sequenceColours == null)
1896 sequenceColours = new Hashtable();
1901 sequenceColours.remove(seq);
1905 sequenceColours.put(seq, col);
1910 * returns the visible column regions of the alignment
1912 * @param selectedRegionOnly
1913 * true to just return the contigs intersecting with the
1917 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1919 int[] viscontigs = null;
1920 int start = 0, end = 0;
1921 if (selectedRegionOnly && selectionGroup != null)
1923 start = selectionGroup.getStartRes();
1924 end = selectionGroup.getEndRes() + 1;
1928 end = alignment.getWidth();
1930 viscontigs = colSel.getVisibleContigs(start, end);
1935 * get hash of undo and redo list for the alignment
1937 * @return long[] { historyList.hashCode, redoList.hashCode };
1939 public long[] getUndoRedoHash()
1941 if (historyList == null || redoList == null)
1945 { historyList.hashCode(), this.redoList.hashCode() };
1949 * test if a particular set of hashcodes are different to the hashcodes for
1950 * the undo and redo list.
1953 * the stored set of hashcodes as returned by getUndoRedoHash
1954 * @return true if the hashcodes differ (ie the alignment has been edited) or
1955 * the stored hashcode array differs in size
1957 public boolean isUndoRedoHashModified(long[] undoredo)
1959 if (undoredo == null)
1963 long[] cstate = getUndoRedoHash();
1964 if (cstate.length != undoredo.length)
1969 for (int i = 0; i < cstate.length; i++)
1971 if (cstate[i] != undoredo[i])
1979 public boolean getCentreColumnLabels()
1981 return centreColumnLabels;
1984 public void setCentreColumnLabels(boolean centrecolumnlabels)
1986 centreColumnLabels = centrecolumnlabels;
1989 public void updateSequenceIdColours()
1991 Vector groups = alignment.getGroups();
1992 if (sequenceColours == null)
1994 sequenceColours = new Hashtable();
1996 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1998 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1999 if (sg.idColour != null)
2001 Vector sqs = sg.getSequences(hiddenRepSequences);
2002 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2004 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2011 * enable or disable the display of Database Cross References in the sequence ID tooltip
2013 public void setShowDbRefs(boolean show)
2020 * @return true if Database References are to be displayed on tooltips.
2022 public boolean isShowDbRefs()
2029 * @return true if Non-positional features are to be displayed on tooltips.
2031 public boolean isShowNpFeats()
2036 * enable or disable the display of Non-Positional sequence features in the sequence ID tooltip
2039 public void setShowNpFeats(boolean show)