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.SelectionSource;
51 import jalview.structure.StructureSelectionManager;
59 public class AlignViewport implements SelectionSource
69 boolean showJVSuffix = true;
71 boolean showText = true;
73 boolean showColourText = false;
75 boolean showBoxes = true;
77 boolean wrapAlignment = false;
79 boolean renderGaps = true;
81 boolean showSequenceFeatures = false;
83 boolean showAnnotation = true;
85 boolean colourAppliesToAllGroups = true;
87 ColourSchemeI globalColourScheme = null;
89 boolean conservationColourSelected = false;
91 boolean abovePIDThreshold = false;
93 SequenceGroup selectionGroup;
99 boolean validCharWidth;
105 boolean seqNameItalics;
107 AlignmentI alignment;
109 ColumnSelection colSel = new ColumnSelection();
115 NJTree currentTree = null;
117 boolean scaleAboveWrapped = false;
119 boolean scaleLeftWrapped = true;
121 boolean scaleRightWrapped = true;
123 boolean hasHiddenColumns = false;
125 boolean hasHiddenRows = false;
127 boolean showHiddenMarkers = true;
129 boolean cursorMode = false;
131 // The following vector holds the features which are
132 // currently visible, in the correct order or rendering
133 Hashtable featuresDisplayed = null;
136 public Hashtable[] hconsensus;
138 AlignmentAnnotation consensus;
140 AlignmentAnnotation conservation;
142 AlignmentAnnotation quality;
144 boolean autoCalculateConsensus = true;
147 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
149 // JBPNote Prolly only need this in the applet version.
150 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
153 boolean ignoreGapsInConsensusCalculation = false;
155 boolean isDataset = false;
157 boolean antiAlias = false;
159 boolean padGaps = false;
161 Rectangle explodedPosition;
165 String sequenceSetID;
167 boolean gatherViewsHere = false;
169 Stack historyList = new Stack();
171 Stack redoList = new Stack();
173 Hashtable sequenceColours;
175 int thresholdTextColour = 0;
177 Color textColour = Color.black;
179 Color textColour2 = Color.white;
181 boolean rightAlignIds = false;
183 Hashtable hiddenRepSequences;
186 * Creates a new AlignViewport object.
188 * @param al alignment to view
190 public AlignViewport(AlignmentI al)
196 * Create a new AlignViewport object with a specific sequence set ID
198 * @param seqsetid (may be null - but potential for ambiguous constructor exception)
200 public AlignViewport(AlignmentI al, String seqsetid)
202 this(al,seqsetid,null);
204 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
206 sequenceSetID = seqsetid;
208 // TODO remove these once 2.4.VAMSAS release finished
209 if (Cache.log!=null && Cache.log.isDebugEnabled() && seqsetid!=null) { Cache.log.debug("Setting viewport's sequence set id : "+sequenceSetID); }
210 if (Cache.log!=null && Cache.log.isDebugEnabled() && viewId!=null) { Cache.log.debug("Setting viewport's view id : "+viewId); }
216 * Create a new AlignViewport with hidden regions
220 * @param hiddenColumns
223 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
226 if (hiddenColumns != null)
228 this.colSel = hiddenColumns;
229 if (hiddenColumns.getHiddenColumns() != null)
231 hasHiddenColumns = true;
237 * New viewport with hidden columns and an existing sequence set id
239 * @param hiddenColumns
240 * @param seqsetid (may be null)
242 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, String seqsetid)
244 this(al,hiddenColumns,seqsetid,null);
247 * New viewport with hidden columns and an existing sequence set id and viewid
249 * @param hiddenColumns
250 * @param seqsetid (may be null)
251 * @param viewid (may be null)
253 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, String seqsetid, String viewid)
255 sequenceSetID = seqsetid;
257 // TODO remove these once 2.4.VAMSAS release finished
258 if (Cache.log!=null && Cache.log.isDebugEnabled() && seqsetid!=null) { Cache.log.debug("Setting viewport's sequence set id : "+sequenceSetID); }
259 if (Cache.log!=null && Cache.log.isDebugEnabled() && viewId!=null) { Cache.log.debug("Setting viewport's view id : "+viewId); }
261 if (hiddenColumns != null)
263 this.colSel = hiddenColumns;
264 if (hiddenColumns.getHiddenColumns() != null)
266 hasHiddenColumns = true;
275 this.endRes = alignment.getWidth() - 1;
277 this.endSeq = alignment.getHeight() - 1;
279 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
281 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
282 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
284 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
285 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
286 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
288 padGaps = Cache.getDefault("PAD_GAPS", true);
289 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP",true);
290 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP",true);
292 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
293 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
294 String fontSize = Cache.getDefault("FONT_SIZE", "10");
296 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
300 if (fontStyle.equals("bold"))
304 else if (fontStyle.equals("italic"))
309 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
312 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
314 // We must set conservation and consensus before setting colour,
315 // as Blosum and Clustal require this to be done
316 if (hconsensus == null && !isDataset)
318 if (!alignment.isNucleotide())
320 conservation = new AlignmentAnnotation("Conservation",
321 "Conservation of total alignment less than " + ConsPercGaps
322 + "% gaps", new Annotation[1], 0f, 11f,
323 AlignmentAnnotation.BAR_GRAPH);
324 conservation.hasText = true;
325 conservation.autoCalculated = true;
327 if (Cache.getDefault("SHOW_CONSERVATION", true))
329 alignment.addAnnotation(conservation);
332 if (Cache.getDefault("SHOW_QUALITY", true))
334 quality = new AlignmentAnnotation("Quality",
335 "Alignment Quality based on Blosum62 scores",
336 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
337 quality.hasText = true;
338 quality.autoCalculated = true;
340 alignment.addAnnotation(quality);
344 consensus = new AlignmentAnnotation("Consensus", "PID",
345 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
346 consensus.hasText = true;
347 consensus.autoCalculated = true;
349 if (Cache.getDefault("SHOW_IDENTITY", true))
351 alignment.addAnnotation(consensus);
355 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
357 globalColourScheme = ColourSchemeProperty.getColour(alignment,
358 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
360 if (globalColourScheme instanceof UserColourScheme)
362 globalColourScheme = UserDefinedColours.loadDefaultColours();
363 ((UserColourScheme) globalColourScheme).setThreshold(0,
364 getIgnoreGapsConsensus());
367 if (globalColourScheme != null)
369 globalColourScheme.setConsensus(hconsensus);
373 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
382 public void setShowSequenceFeatures(boolean b)
384 showSequenceFeatures = b;
387 public boolean getShowSequenceFeatures()
389 return showSequenceFeatures;
392 class ConservationThread extends Thread
396 public ConservationThread(AlignmentPanel ap)
405 updatingConservation = true;
407 while (UPDATING_CONSERVATION)
413 ap.paintAlignment(false);
416 } catch (Exception ex)
418 ex.printStackTrace();
422 UPDATING_CONSERVATION = true;
424 int alWidth = alignment.getWidth();
430 Conservation cons = new jalview.analysis.Conservation("All",
431 jalview.schemes.ResidueProperties.propHash, 3, alignment
432 .getSequences(), 0, alWidth - 1);
435 cons.verdict(false, ConsPercGaps);
442 char[] sequence = cons.getConsSequence().getSequence();
454 maxB = 0f - minB; // scalable range for colouring both Conservation and
464 conservation.annotations = new Annotation[alWidth];
468 quality.graphMax = cons.qualityRange[1].floatValue();
469 quality.annotations = new Annotation[alWidth];
470 qmin = cons.qualityRange[0].floatValue();
471 qmax = cons.qualityRange[1].floatValue();
474 for (int i = 0; i < alWidth; i++)
480 if (Character.isDigit(c))
482 value = (int) (c - '0');
493 float vprop = value - min;
495 conservation.annotations[i] = new Annotation(String.valueOf(c),
496 String.valueOf(value), ' ', value, new Color(minR
497 + (maxR * vprop), minG + (maxG * vprop), minB
503 value = ((Double) cons.quality.get(i)).floatValue();
504 vprop = value - qmin;
506 quality.annotations[i] = new Annotation(" ", String
507 .valueOf(value), ' ', value, new Color(minR
508 + (maxR * vprop), minG + (maxG * vprop), minB
512 } catch (OutOfMemoryError error)
514 new OOMWarning("calculating conservation", error);
521 UPDATING_CONSERVATION = false;
522 updatingConservation = false;
526 ap.paintAlignment(true);
532 ConservationThread conservationThread;
534 ConsensusThread consensusThread;
536 boolean consUpdateNeeded = false;
538 static boolean UPDATING_CONSENSUS = false;
540 static boolean UPDATING_CONSERVATION = false;
542 boolean updatingConsensus = false;
544 boolean updatingConservation = false;
547 * centre columnar annotation labels in displayed alignment annotation TODO:
548 * add to jalviewXML and annotation display settings
550 boolean centreColumnLabels = false;
552 private boolean showdbrefs;
554 private boolean shownpfeats;
557 * trigger update of conservation annotation
559 public void updateConservation(final AlignmentPanel ap)
561 if (alignment.isNucleotide() || conservation == null)
566 conservationThread = new ConservationThread(ap);
567 conservationThread.start();
571 * trigger update of consensus annotation
573 public void updateConsensus(final AlignmentPanel ap)
575 consensusThread = new ConsensusThread(ap);
576 consensusThread.start();
579 class ConsensusThread extends Thread
583 public ConsensusThread(AlignmentPanel ap)
590 updatingConsensus = true;
591 while (UPDATING_CONSENSUS)
597 ap.paintAlignment(false);
601 } catch (Exception ex)
603 ex.printStackTrace();
607 UPDATING_CONSENSUS = true;
611 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
620 consensus.annotations = null;
621 consensus.annotations = new Annotation[aWidth];
623 hconsensus = new Hashtable[aWidth];
624 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
625 .getWidth(), hconsensus);
627 for (int i = 0; i < aWidth; i++)
630 if (ignoreGapsInConsensusCalculation)
632 value = ((Float) hconsensus[i].get(AAFrequency.PID_NOGAPS))
637 value = ((Float) hconsensus[i].get(AAFrequency.PID_GAPS))
641 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE)
643 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE)
646 if (maxRes.length() > 1)
648 mouseOver = "[" + maxRes + "] ";
652 mouseOver += ((int) value + "%");
653 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
657 if (globalColourScheme != null)
659 globalColourScheme.setConsensus(hconsensus);
662 } catch (OutOfMemoryError error)
664 alignment.deleteAnnotation(consensus);
668 new OOMWarning("calculating consensus", error);
670 UPDATING_CONSENSUS = false;
671 updatingConsensus = false;
675 ap.paintAlignment(true);
681 * get the consensus sequence as displayed under the PID consensus annotation
684 * @return consensus sequence as a new sequence object
686 public SequenceI getConsensusSeq()
688 if (consensus == null)
690 updateConsensus(null);
692 if (consensus == null)
696 StringBuffer seqs = new StringBuffer();
697 for (int i = 0; i < consensus.annotations.length; i++)
699 if (consensus.annotations[i] != null)
701 if (consensus.annotations[i].description.charAt(0) == '[')
703 seqs.append(consensus.annotations[i].description.charAt(1));
707 seqs.append(consensus.annotations[i].displayCharacter);
712 SequenceI sq = new Sequence("Consensus", seqs.toString());
713 sq.setDescription("Percentage Identity Consensus "
714 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
721 * @return DOCUMENT ME!
723 public SequenceGroup getSelectionGroup()
725 return selectionGroup;
734 public void setSelectionGroup(SequenceGroup sg)
742 * @return DOCUMENT ME!
744 public boolean getConservationSelected()
746 return conservationColourSelected;
755 public void setConservationSelected(boolean b)
757 conservationColourSelected = b;
763 * @return DOCUMENT ME!
765 public boolean getAbovePIDThreshold()
767 return abovePIDThreshold;
776 public void setAbovePIDThreshold(boolean b)
778 abovePIDThreshold = b;
784 * @return DOCUMENT ME!
786 public int getStartRes()
794 * @return DOCUMENT ME!
796 public int getEndRes()
804 * @return DOCUMENT ME!
806 public int getStartSeq()
817 public void setGlobalColourScheme(ColourSchemeI cs)
819 globalColourScheme = cs;
825 * @return DOCUMENT ME!
827 public ColourSchemeI getGlobalColourScheme()
829 return globalColourScheme;
838 public void setStartRes(int res)
849 public void setStartSeq(int seq)
860 public void setEndRes(int res)
862 if (res > (alignment.getWidth() - 1))
864 // log.System.out.println(" Corrected res from " + res + " to maximum " +
865 // (alignment.getWidth()-1));
866 res = alignment.getWidth() - 1;
883 public void setEndSeq(int seq)
885 if (seq > alignment.getHeight())
887 seq = alignment.getHeight();
901 * @return DOCUMENT ME!
903 public int getEndSeq()
914 public void setFont(Font f)
918 Container c = new Container();
920 java.awt.FontMetrics fm = c.getFontMetrics(font);
921 setCharHeight(fm.getHeight());
922 setCharWidth(fm.charWidth('M'));
923 validCharWidth = true;
929 * @return DOCUMENT ME!
931 public Font getFont()
942 public void setCharWidth(int w)
950 * @return DOCUMENT ME!
952 public int getCharWidth()
963 public void setCharHeight(int h)
971 * @return DOCUMENT ME!
973 public int getCharHeight()
984 public void setWrappedWidth(int w)
986 this.wrappedWidth = w;
992 * @return DOCUMENT ME!
994 public int getWrappedWidth()
1002 * @return DOCUMENT ME!
1004 public AlignmentI getAlignment()
1015 public void setAlignment(AlignmentI align)
1017 if (alignment != null && alignment.getCodonFrames() != null)
1019 StructureSelectionManager.getStructureSelectionManager()
1020 .removeMappings(alignment.getCodonFrames());
1022 this.alignment = align;
1023 if (alignment.getCodonFrames() != null)
1025 StructureSelectionManager.getStructureSelectionManager().addMappings(
1026 alignment.getCodonFrames());
1036 public void setWrapAlignment(boolean state)
1038 wrapAlignment = state;
1047 public void setShowText(boolean state)
1058 public void setRenderGaps(boolean state)
1066 * @return DOCUMENT ME!
1068 public boolean getColourText()
1070 return showColourText;
1079 public void setColourText(boolean state)
1081 showColourText = state;
1090 public void setShowBoxes(boolean state)
1098 * @return DOCUMENT ME!
1100 public boolean getWrapAlignment()
1102 return wrapAlignment;
1108 * @return DOCUMENT ME!
1110 public boolean getShowText()
1118 * @return DOCUMENT ME!
1120 public boolean getShowBoxes()
1128 * @return DOCUMENT ME!
1130 public char getGapCharacter()
1132 return getAlignment().getGapCharacter();
1141 public void setGapCharacter(char gap)
1143 if (getAlignment() != null)
1145 getAlignment().setGapCharacter(gap);
1155 public void setThreshold(int thresh)
1163 * @return DOCUMENT ME!
1165 public int getThreshold()
1176 public void setIncrement(int inc)
1184 * @return DOCUMENT ME!
1186 public int getIncrement()
1194 * @return DOCUMENT ME!
1196 public ColumnSelection getColumnSelection()
1207 public void setCurrentTree(NJTree tree)
1215 * @return DOCUMENT ME!
1217 public NJTree getCurrentTree()
1228 public void setColourAppliesToAllGroups(boolean b)
1230 colourAppliesToAllGroups = b;
1236 * @return DOCUMENT ME!
1238 public boolean getColourAppliesToAllGroups()
1240 return colourAppliesToAllGroups;
1246 * @return DOCUMENT ME!
1248 public boolean getShowJVSuffix()
1250 return showJVSuffix;
1259 public void setShowJVSuffix(boolean b)
1267 * @return DOCUMENT ME!
1269 public boolean getShowAnnotation()
1271 return showAnnotation;
1280 public void setShowAnnotation(boolean b)
1288 * @return DOCUMENT ME!
1290 public boolean getScaleAboveWrapped()
1292 return scaleAboveWrapped;
1298 * @return DOCUMENT ME!
1300 public boolean getScaleLeftWrapped()
1302 return scaleLeftWrapped;
1308 * @return DOCUMENT ME!
1310 public boolean getScaleRightWrapped()
1312 return scaleRightWrapped;
1321 public void setScaleAboveWrapped(boolean b)
1323 scaleAboveWrapped = b;
1332 public void setScaleLeftWrapped(boolean b)
1334 scaleLeftWrapped = b;
1343 public void setScaleRightWrapped(boolean b)
1345 scaleRightWrapped = b;
1349 * Property change listener for changes in alignment
1354 public void addPropertyChangeListener(
1355 java.beans.PropertyChangeListener listener)
1357 changeSupport.addPropertyChangeListener(listener);
1366 public void removePropertyChangeListener(
1367 java.beans.PropertyChangeListener listener)
1369 changeSupport.removePropertyChangeListener(listener);
1373 * Property change listener for changes in alignment
1382 public void firePropertyChange(String prop, Object oldvalue,
1385 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1388 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1390 ignoreGapsInConsensusCalculation = b;
1391 updateConsensus(ap);
1392 if (globalColourScheme != null)
1394 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1395 ignoreGapsInConsensusCalculation);
1399 public boolean getIgnoreGapsConsensus()
1401 return ignoreGapsInConsensusCalculation;
1404 public void setDataset(boolean b)
1409 public boolean isDataset()
1414 public void hideSelectedColumns()
1416 if (colSel.size() < 1)
1421 colSel.hideSelectedColumns();
1422 setSelectionGroup(null);
1424 hasHiddenColumns = true;
1427 public void hideColumns(int start, int end)
1431 colSel.hideColumns(start);
1435 colSel.hideColumns(start, end);
1438 hasHiddenColumns = true;
1441 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1443 int sSize = sg.getSize();
1449 if (hiddenRepSequences == null)
1451 hiddenRepSequences = new Hashtable();
1454 hiddenRepSequences.put(repSequence, sg);
1456 // Hide all sequences except the repSequence
1457 SequenceI[] seqs = new SequenceI[sSize - 1];
1459 for (int i = 0; i < sSize; i++)
1461 if (sg.getSequenceAt(i) != repSequence)
1463 if (index == sSize - 1)
1468 seqs[index++] = sg.getSequenceAt(i);
1471 sg.setSeqrep(repSequence);
1472 sg.setHidereps(true);
1477 public void hideAllSelectedSeqs()
1479 if (selectionGroup == null || selectionGroup.getSize() < 1)
1484 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1488 setSelectionGroup(null);
1491 public void hideSequence(SequenceI[] seq)
1495 for (int i = 0; i < seq.length; i++)
1497 alignment.getHiddenSequences().hideSequence(seq[i]);
1499 hasHiddenRows = true;
1500 firePropertyChange("alignment", null, alignment.getSequences());
1504 public void showSequence(int index)
1506 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1507 hiddenRepSequences);
1510 if (selectionGroup == null)
1512 selectionGroup = new SequenceGroup();
1513 selectionGroup.setEndRes(alignment.getWidth() - 1);
1516 for (int t = 0; t < tmp.size(); t++)
1518 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1520 firePropertyChange("alignment", null, alignment.getSequences());
1524 if (alignment.getHiddenSequences().getSize() < 1)
1526 hasHiddenRows = false;
1530 public void showColumn(int col)
1532 colSel.revealHiddenColumns(col);
1533 if (colSel.getHiddenColumns() == null)
1535 hasHiddenColumns = false;
1539 public void showAllHiddenColumns()
1541 colSel.revealAllHiddenColumns();
1542 hasHiddenColumns = false;
1545 public void showAllHiddenSeqs()
1547 if (alignment.getHiddenSequences().getSize() > 0)
1549 if (selectionGroup == null)
1551 selectionGroup = new SequenceGroup();
1552 selectionGroup.setEndRes(alignment.getWidth() - 1);
1554 Vector tmp = alignment.getHiddenSequences().showAll(
1555 hiddenRepSequences);
1556 for (int t = 0; t < tmp.size(); t++)
1558 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1560 firePropertyChange("alignment", null, alignment.getSequences());
1562 hasHiddenRows = false;
1563 hiddenRepSequences = null;
1567 public void invertColumnSelection()
1569 colSel.invertColumnSelection(0, alignment.getWidth());
1572 public int adjustForHiddenSeqs(int alignmentIndex)
1574 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1579 * This method returns an array of new SequenceI objects derived from the
1580 * whole alignment or just the current selection with start and end points
1583 * @note if you need references to the actual SequenceI objects in the
1584 * alignment or currently selected then use getSequenceSelection()
1585 * @return selection as new sequenceI objects
1587 public SequenceI[] getSelectionAsNewSequence()
1589 SequenceI[] sequences;
1591 if (selectionGroup == null)
1593 sequences = alignment.getSequencesArray();
1594 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1595 for (int i = 0; i < sequences.length; i++)
1597 sequences[i] = new Sequence(sequences[i], annots); // construct new
1599 // subset of visible
1605 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1612 * get the currently selected sequence objects or all the sequences in the
1615 * @return array of references to sequence objects
1617 public SequenceI[] getSequenceSelection()
1619 SequenceI[] sequences;
1620 if (selectionGroup == null)
1622 sequences = alignment.getSequencesArray();
1626 sequences = selectionGroup.getSequencesInOrder(alignment);
1632 * This method returns the visible alignment as text, as seen on the GUI, ie
1633 * if columns are hidden they will not be returned in the result. Use this for
1634 * calculating trees, PCA, redundancy etc on views which contain hidden
1639 public jalview.datamodel.CigarArray getViewAsCigars(
1640 boolean selectedRegionOnly)
1642 CigarArray selection = null;
1643 SequenceI[] seqs = null;
1645 int start = 0, end = 0;
1646 if (selectedRegionOnly && selectionGroup != null)
1648 iSize = selectionGroup.getSize();
1649 seqs = selectionGroup.getSequencesInOrder(alignment);
1650 start = selectionGroup.getStartRes();
1651 end = selectionGroup.getEndRes(); // inclusive for start and end in
1652 // SeqCigar constructor
1656 iSize = alignment.getHeight();
1657 seqs = alignment.getSequencesArray();
1658 end = alignment.getWidth() - 1;
1660 SeqCigar[] selseqs = new SeqCigar[iSize];
1661 for (i = 0; i < iSize; i++)
1663 selseqs[i] = new SeqCigar(seqs[i], start, end);
1665 selection = new CigarArray(selseqs);
1666 // now construct the CigarArray operations
1667 if (hasHiddenColumns)
1669 Vector regions = colSel.getHiddenColumns();
1671 int hideStart, hideEnd;
1673 for (int j = 0; last < end & j < regions.size(); j++)
1675 region = (int[]) regions.elementAt(j);
1676 hideStart = region[0];
1677 hideEnd = region[1];
1678 // edit hidden regions to selection range
1679 if (hideStart < last)
1691 if (hideStart > end)
1701 if (hideStart > hideEnd)
1706 * form operations...
1708 if (last < hideStart)
1710 selection.addOperation(CigarArray.M, hideStart - last);
1712 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1715 // Final match if necessary.
1718 selection.addOperation(CigarArray.M, end - last + 1);
1723 selection.addOperation(CigarArray.M, end - start + 1);
1729 * return a compact representation of the current alignment selection to pass
1730 * to an analysis function
1732 * @param selectedOnly
1733 * boolean true to just return the selected view
1734 * @return AlignmentView
1736 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1739 // this is here because the AlignmentView constructor modifies the
1741 // object. Refactoring of Cigar and alignment view representation should
1742 // be done to remove redundancy.
1743 CigarArray aligview = getViewAsCigars(selectedOnly);
1744 if (aligview != null)
1746 return new AlignmentView(aligview,
1747 (selectedOnly && selectionGroup != null) ? selectionGroup
1748 .getStartRes() : 0);
1754 * This method returns the visible alignment as text, as seen on the GUI, ie
1755 * if columns are hidden they will not be returned in the result. Use this for
1756 * calculating trees, PCA, redundancy etc on views which contain hidden
1761 public String[] getViewAsString(boolean selectedRegionOnly)
1763 String[] selection = null;
1764 SequenceI[] seqs = null;
1766 int start = 0, end = 0;
1767 if (selectedRegionOnly && selectionGroup != null)
1769 iSize = selectionGroup.getSize();
1770 seqs = selectionGroup.getSequencesInOrder(alignment);
1771 start = selectionGroup.getStartRes();
1772 end = selectionGroup.getEndRes() + 1;
1776 iSize = alignment.getHeight();
1777 seqs = alignment.getSequencesArray();
1778 end = alignment.getWidth();
1781 selection = new String[iSize];
1782 if (hasHiddenColumns)
1784 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1788 for (i = 0; i < iSize; i++)
1790 selection[i] = seqs[i].getSequenceAsString(start, end);
1797 public int[][] getVisibleRegionBoundaries(int min, int max)
1799 Vector regions = new Vector();
1805 if (hasHiddenColumns)
1809 start = colSel.adjustForHiddenColumns(start);
1812 end = colSel.getHiddenBoundaryRight(start);
1823 regions.addElement(new int[]
1826 if (hasHiddenColumns)
1828 start = colSel.adjustForHiddenColumns(end);
1829 start = colSel.getHiddenBoundaryLeft(start) + 1;
1831 } while (end < max);
1833 int[][] startEnd = new int[regions.size()][2];
1835 regions.copyInto(startEnd);
1841 public boolean getShowHiddenMarkers()
1843 return showHiddenMarkers;
1846 public void setShowHiddenMarkers(boolean show)
1848 showHiddenMarkers = show;
1851 public String getSequenceSetId()
1853 if (sequenceSetID == null)
1855 sequenceSetID = alignment.hashCode() + "";
1858 return sequenceSetID;
1861 * unique viewId for synchronizing state with stored Jalview Project
1864 private String viewId=null;
1867 public String getViewId()
1871 viewId = this.getSequenceSetId()+"."+this.hashCode()+"";
1876 public void alignmentChanged(AlignmentPanel ap)
1880 alignment.padGaps();
1883 if (hconsensus != null && autoCalculateConsensus)
1885 updateConsensus(ap);
1886 updateConservation(ap);
1889 // Reset endRes of groups if beyond alignment width
1890 int alWidth = alignment.getWidth();
1891 Vector groups = alignment.getGroups();
1894 for (int i = 0; i < groups.size(); i++)
1896 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1897 if (sg.getEndRes() > alWidth)
1899 sg.setEndRes(alWidth - 1);
1904 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1906 selectionGroup.setEndRes(alWidth - 1);
1909 resetAllColourSchemes();
1911 // alignment.adjustSequenceAnnotations();
1914 void resetAllColourSchemes()
1916 ColourSchemeI cs = globalColourScheme;
1919 if (cs instanceof ClustalxColourScheme)
1921 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1922 alignment.getWidth());
1925 cs.setConsensus(hconsensus);
1926 if (cs.conservationApplied())
1928 Alignment al = (Alignment) alignment;
1929 Conservation c = new Conservation("All",
1930 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1933 c.verdict(false, ConsPercGaps);
1935 cs.setConservation(c);
1939 int s, sSize = alignment.getGroups().size();
1940 for (s = 0; s < sSize; s++)
1942 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1943 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1945 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1946 .getSequences(hiddenRepSequences), sg.getWidth());
1948 sg.recalcConservation();
1952 public Color getSequenceColour(SequenceI seq)
1954 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1960 return (Color) sequenceColours.get(seq);
1964 public void setSequenceColour(SequenceI seq, Color col)
1966 if (sequenceColours == null)
1968 sequenceColours = new Hashtable();
1973 sequenceColours.remove(seq);
1977 sequenceColours.put(seq, col);
1982 * returns the visible column regions of the alignment
1984 * @param selectedRegionOnly
1985 * true to just return the contigs intersecting with the
1989 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1991 int[] viscontigs = null;
1992 int start = 0, end = 0;
1993 if (selectedRegionOnly && selectionGroup != null)
1995 start = selectionGroup.getStartRes();
1996 end = selectionGroup.getEndRes() + 1;
2000 end = alignment.getWidth();
2002 viscontigs = colSel.getVisibleContigs(start, end);
2007 * get hash of undo and redo list for the alignment
2009 * @return long[] { historyList.hashCode, redoList.hashCode };
2011 public long[] getUndoRedoHash()
2013 if (historyList == null || redoList == null)
2017 { historyList.hashCode(), this.redoList.hashCode() };
2021 * test if a particular set of hashcodes are different to the hashcodes for
2022 * the undo and redo list.
2025 * the stored set of hashcodes as returned by getUndoRedoHash
2026 * @return true if the hashcodes differ (ie the alignment has been edited) or
2027 * the stored hashcode array differs in size
2029 public boolean isUndoRedoHashModified(long[] undoredo)
2031 if (undoredo == null)
2035 long[] cstate = getUndoRedoHash();
2036 if (cstate.length != undoredo.length)
2041 for (int i = 0; i < cstate.length; i++)
2043 if (cstate[i] != undoredo[i])
2051 public boolean getCentreColumnLabels()
2053 return centreColumnLabels;
2056 public void setCentreColumnLabels(boolean centrecolumnlabels)
2058 centreColumnLabels = centrecolumnlabels;
2061 public void updateSequenceIdColours()
2063 Vector groups = alignment.getGroups();
2064 if (sequenceColours == null)
2066 sequenceColours = new Hashtable();
2068 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
2070 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
2071 if (sg.idColour != null)
2073 Vector sqs = sg.getSequences(hiddenRepSequences);
2074 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2076 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2083 * enable or disable the display of Database Cross References in the sequence ID tooltip
2085 public void setShowDbRefs(boolean show)
2092 * @return true if Database References are to be displayed on tooltips.
2094 public boolean isShowDbRefs()
2101 * @return true if Non-positional features are to be displayed on tooltips.
2103 public boolean isShowNpFeats()
2108 * enable or disable the display of Non-Positional sequence features in the sequence ID tooltip
2111 public void setShowNpFeats(boolean show)
2117 * @return true if view has hidden rows
2119 public boolean hasHiddenRows()
2121 return hasHiddenRows;
2125 * @return true if view has hidden columns
2127 public boolean hasHiddenColumns()
2129 return hasHiddenColumns;
2132 * when set, view will scroll to show the highlighted position
2134 public boolean followHighlight=true;
2136 * @return true if view should scroll to show the highlighted region of a sequence
2139 public boolean getFollowHighlight() {
2140 return followHighlight;
2142 public boolean followSelection=true;
2144 * @return true if view selection should always follow the selections broadcast by other selection sources
2146 public boolean getFollowSelection() {
2147 return followSelection;
2149 private long sgrouphash=-1,colselhash=-1;
2151 * checks current SelectionGroup against record of last hash value, and updates record.
2152 * @return true if SelectionGroup changed since last call
2154 boolean isSelectionGroupChanged() {
2155 int hc=(selectionGroup==null) ? -1 : selectionGroup.hashCode();
2164 * checks current colsel against record of last hash value, and updates record.
2165 * @return true if colsel changed since last call
2167 boolean isColSelChanged() {
2168 int hc=(colSel==null) ? -1 : colSel.hashCode();
2176 public void sendSelection()
2178 jalview.structure.StructureSelectionManager.getStructureSelectionManager().sendSelection(new SequenceGroup(getSelectionGroup()), new ColumnSelection(getColumnSelection()), this);