2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * Jalview - A Sequence Alignment Editor and Viewer
20 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * as published by the Free Software Foundation; either version 2
25 * of the License, or (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 import jalview.analysis.*;
46 import jalview.datamodel.*;
48 import jalview.schemes.*;
49 import jalview.structure.SelectionSource;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.structure.VamsasSource;
59 public class AlignViewport implements SelectionSource, VamsasSource
61 private static final int RIGHT_JUSTIFY = 1;
71 boolean showJVSuffix = true;
73 boolean showText = true;
75 boolean showColourText = false;
77 boolean showBoxes = true;
79 boolean wrapAlignment = false;
81 boolean renderGaps = true;
83 boolean showSequenceFeatures = false;
85 boolean showAnnotation = true;
87 boolean colourAppliesToAllGroups = true;
89 ColourSchemeI globalColourScheme = null;
91 boolean conservationColourSelected = false;
93 boolean abovePIDThreshold = false;
95 SequenceGroup selectionGroup;
101 boolean validCharWidth;
107 boolean seqNameItalics;
109 AlignmentI alignment;
111 ColumnSelection colSel = new ColumnSelection();
117 NJTree currentTree = null;
119 boolean scaleAboveWrapped = false;
121 boolean scaleLeftWrapped = true;
123 boolean scaleRightWrapped = true;
125 boolean hasHiddenColumns = false;
127 boolean hasHiddenRows = false;
129 boolean showHiddenMarkers = true;
131 boolean cursorMode = false;
134 * Keys are the feature types which are currently visible. Note: Values are
137 Hashtable featuresDisplayed = null;
140 public Hashtable[] hconsensus;
142 AlignmentAnnotation consensus;
144 AlignmentAnnotation conservation;
146 AlignmentAnnotation quality;
148 AlignmentAnnotation[] groupConsensus;
150 AlignmentAnnotation[] groupConservation;
152 boolean autoCalculateConsensus = true;
155 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
157 // JBPNote Prolly only need this in the applet version.
158 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
161 boolean ignoreGapsInConsensusCalculation = false;
163 boolean isDataset = false;
165 boolean antiAlias = false;
167 boolean padGaps = false;
169 Rectangle explodedPosition;
173 String sequenceSetID;
175 boolean gatherViewsHere = false;
177 Stack historyList = new Stack();
179 Stack redoList = new Stack();
181 Hashtable sequenceColours;
183 int thresholdTextColour = 0;
185 Color textColour = Color.black;
187 Color textColour2 = Color.white;
189 boolean rightAlignIds = false;
191 Hashtable hiddenRepSequences;
196 * Creates a new AlignViewport object.
201 public AlignViewport(AlignmentI al)
208 * Create a new AlignViewport object with a specific sequence set ID
212 * (may be null - but potential for ambiguous constructor exception)
214 public AlignViewport(AlignmentI al, String seqsetid)
216 this(al, seqsetid, null);
219 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
221 sequenceSetID = seqsetid;
223 // TODO remove these once 2.4.VAMSAS release finished
224 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
226 Cache.log.debug("Setting viewport's sequence set id : "
229 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
231 Cache.log.debug("Setting viewport's view id : " + viewId);
238 * Create a new AlignViewport with hidden regions
242 * @param hiddenColumns
245 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
248 if (hiddenColumns != null)
250 this.colSel = hiddenColumns;
251 if (hiddenColumns.getHiddenColumns() != null
252 && hiddenColumns.getHiddenColumns().size() > 0)
254 hasHiddenColumns = true;
258 hasHiddenColumns = false;
265 * New viewport with hidden columns and an existing sequence set id
268 * @param hiddenColumns
272 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
275 this(al, hiddenColumns, seqsetid, null);
279 * New viewport with hidden columns and an existing sequence set id and viewid
282 * @param hiddenColumns
288 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
289 String seqsetid, String viewid)
291 sequenceSetID = seqsetid;
293 // TODO remove these once 2.4.VAMSAS release finished
294 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
296 Cache.log.debug("Setting viewport's sequence set id : "
299 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
301 Cache.log.debug("Setting viewport's view id : " + viewId);
304 if (hiddenColumns != null)
306 this.colSel = hiddenColumns;
307 if (hiddenColumns.getHiddenColumns() != null
308 && hiddenColumns.getHiddenColumns().size() > 0)
310 hasHiddenColumns = true;
314 hasHiddenColumns = false;
323 this.endRes = alignment.getWidth() - 1;
325 this.endSeq = alignment.getHeight() - 1;
327 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
329 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
330 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
332 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
333 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
334 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
336 padGaps = Cache.getDefault("PAD_GAPS", true);
337 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
338 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
340 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
341 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
342 String fontSize = Cache.getDefault("FONT_SIZE", "10");
344 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
348 if (fontStyle.equals("bold"))
352 else if (fontStyle.equals("italic"))
357 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
360 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
362 // We must set conservation and consensus before setting colour,
363 // as Blosum and Clustal require this to be done
364 if (hconsensus == null && !isDataset)
366 if (!alignment.isNucleotide())
368 conservation = new AlignmentAnnotation("Conservation",
369 "Conservation of total alignment less than " + ConsPercGaps
370 + "% gaps", new Annotation[1], 0f, 11f,
371 AlignmentAnnotation.BAR_GRAPH);
372 conservation.hasText = true;
373 conservation.autoCalculated = true;
375 if (Cache.getDefault("SHOW_CONSERVATION", true))
377 alignment.addAnnotation(conservation);
380 if (Cache.getDefault("SHOW_QUALITY", true))
382 quality = new AlignmentAnnotation("Quality",
383 "Alignment Quality based on Blosum62 scores",
384 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
385 quality.hasText = true;
386 quality.autoCalculated = true;
388 alignment.addAnnotation(quality);
390 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
397 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
399 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
400 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
401 // TODO: add menu option action that nulls or creates consensus object
402 // depending on if the user wants to see the annotation or not in a
403 // specific alignment
404 consensus = new AlignmentAnnotation("Consensus", "PID",
405 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
406 consensus.hasText = true;
407 consensus.autoCalculated = true;
409 if (Cache.getDefault("SHOW_IDENTITY", true))
411 alignment.addAnnotation(consensus);
415 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
417 globalColourScheme = ColourSchemeProperty.getColour(alignment,
418 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
420 if (globalColourScheme instanceof UserColourScheme)
422 globalColourScheme = UserDefinedColours.loadDefaultColours();
423 ((UserColourScheme) globalColourScheme).setThreshold(0,
424 getIgnoreGapsConsensus());
427 if (globalColourScheme != null)
429 globalColourScheme.setConsensus(hconsensus);
433 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
434 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED",
436 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
437 followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS",
445 * features are displayed if true
447 public void setShowSequenceFeatures(boolean b)
449 showSequenceFeatures = b;
452 public boolean getShowSequenceFeatures()
454 return showSequenceFeatures;
457 ConservationThread conservationThread;
459 ConsensusThread consensusThread;
461 boolean consUpdateNeeded = false;
463 static boolean UPDATING_CONSENSUS = false;
465 static boolean UPDATING_CONSERVATION = false;
467 boolean updatingConsensus = false;
469 boolean updatingConservation = false;
472 * centre columnar annotation labels in displayed alignment annotation TODO:
473 * add to jalviewXML and annotation display settings
475 boolean centreColumnLabels = false;
477 private boolean showdbrefs;
479 private boolean shownpfeats;
482 * trigger update of conservation annotation
484 public void updateConservation(final AlignmentPanel ap)
486 // see note in mantis : issue number 8585
487 if (alignment.isNucleotide() || conservation == null
488 || !autoCalculateConsensus)
493 conservationThread = new ConservationThread(this, ap);
494 conservationThread.start();
498 * trigger update of consensus annotation
500 public void updateConsensus(final AlignmentPanel ap)
502 // see note in mantis : issue number 8585
503 if (consensus == null || !autoCalculateConsensus)
507 consensusThread = new ConsensusThread(ap);
508 consensusThread.start();
511 class ConsensusThread extends Thread
515 public ConsensusThread(AlignmentPanel ap)
522 updatingConsensus = true;
523 while (UPDATING_CONSENSUS)
529 ap.paintAlignment(false);
533 } catch (Exception ex)
535 ex.printStackTrace();
539 UPDATING_CONSENSUS = true;
543 int aWidth = (alignment != null) ? alignment.getWidth() : -1; // null
549 updatingConsensus = false;
550 UPDATING_CONSENSUS = false;
554 consensus.annotations = null;
555 consensus.annotations = new Annotation[aWidth];
557 hconsensus = new Hashtable[aWidth];
558 AAFrequency.calculate(alignment.getSequencesArray(), 0,
559 alignment.getWidth(), hconsensus, true);
560 updateAnnotation(true);
562 if (globalColourScheme != null)
564 globalColourScheme.setConsensus(hconsensus);
567 } catch (OutOfMemoryError error)
569 alignment.deleteAnnotation(consensus);
573 new OOMWarning("calculating consensus", error);
575 UPDATING_CONSENSUS = false;
576 updatingConsensus = false;
580 ap.paintAlignment(true);
585 * update the consensus annotation from the sequence profile data using
586 * current visualization settings.
588 public void updateAnnotation()
590 updateAnnotation(false);
593 protected void updateAnnotation(boolean immediate)
595 // TODO: make calls thread-safe, so if another thread calls this method,
596 // it will either return or wait until one calculation is finished.
598 || (!updatingConsensus && consensus != null && hconsensus != null))
600 AAFrequency.completeConsensus(consensus, hconsensus, 0,
601 hconsensus.length, ignoreGapsInConsensusCalculation,
608 * get the consensus sequence as displayed under the PID consensus annotation
611 * @return consensus sequence as a new sequence object
613 public SequenceI getConsensusSeq()
615 if (consensus == null)
617 updateConsensus(null);
619 if (consensus == null)
623 StringBuffer seqs = new StringBuffer();
624 for (int i = 0; i < consensus.annotations.length; i++)
626 if (consensus.annotations[i] != null)
628 if (consensus.annotations[i].description.charAt(0) == '[')
630 seqs.append(consensus.annotations[i].description.charAt(1));
634 seqs.append(consensus.annotations[i].displayCharacter);
639 SequenceI sq = new Sequence("Consensus", seqs.toString());
640 sq.setDescription("Percentage Identity Consensus "
641 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
648 * @return null or the currently selected sequence region
650 public SequenceGroup getSelectionGroup()
652 return selectionGroup;
656 * Set the selection group for this window.
658 * @param sg - group holding references to sequences in this alignment view
661 public void setSelectionGroup(SequenceGroup sg)
668 * @return true if conservation based shading is enabled
670 public boolean getConservationSelected()
672 return conservationColourSelected;
678 * enable conservation based shading
680 public void setConservationSelected(boolean b)
682 conservationColourSelected = b;
687 * @return true if percent identity threshold is applied to shading
689 public boolean getAbovePIDThreshold()
691 return abovePIDThreshold;
698 * @param b indicate if percent identity threshold is applied to shading
700 public void setAbovePIDThreshold(boolean b)
702 abovePIDThreshold = b;
708 * @return DOCUMENT ME!
710 public int getStartRes()
718 * @return DOCUMENT ME!
720 public int getEndRes()
728 * @return DOCUMENT ME!
730 public int getStartSeq()
741 public void setGlobalColourScheme(ColourSchemeI cs)
743 globalColourScheme = cs;
749 * @return DOCUMENT ME!
751 public ColourSchemeI getGlobalColourScheme()
753 return globalColourScheme;
762 public void setStartRes(int res)
773 public void setStartSeq(int seq)
784 public void setEndRes(int res)
786 if (res > (alignment.getWidth() - 1))
788 // log.System.out.println(" Corrected res from " + res + " to maximum " +
789 // (alignment.getWidth()-1));
790 res = alignment.getWidth() - 1;
807 public void setEndSeq(int seq)
809 if (seq > alignment.getHeight())
811 seq = alignment.getHeight();
825 * @return DOCUMENT ME!
827 public int getEndSeq()
838 public void setFont(Font f)
842 Container c = new Container();
844 java.awt.FontMetrics fm = c.getFontMetrics(font);
845 setCharHeight(fm.getHeight());
846 setCharWidth(fm.charWidth('M'));
847 validCharWidth = true;
853 * @return DOCUMENT ME!
855 public Font getFont()
866 public void setCharWidth(int w)
874 * @return DOCUMENT ME!
876 public int getCharWidth()
887 public void setCharHeight(int h)
895 * @return DOCUMENT ME!
897 public int getCharHeight()
908 public void setWrappedWidth(int w)
910 this.wrappedWidth = w;
916 * @return DOCUMENT ME!
918 public int getWrappedWidth()
926 * @return DOCUMENT ME!
928 public AlignmentI getAlignment()
939 public void setAlignment(AlignmentI align)
941 if (alignment != null && alignment.getCodonFrames() != null)
943 StructureSelectionManager.getStructureSelectionManager()
944 .removeMappings(alignment.getCodonFrames());
946 this.alignment = align;
947 if (alignment.getCodonFrames() != null)
949 StructureSelectionManager.getStructureSelectionManager().addMappings(
950 alignment.getCodonFrames());
960 public void setWrapAlignment(boolean state)
962 wrapAlignment = state;
971 public void setShowText(boolean state)
982 public void setRenderGaps(boolean state)
990 * @return DOCUMENT ME!
992 public boolean getColourText()
994 return showColourText;
1003 public void setColourText(boolean state)
1005 showColourText = state;
1014 public void setShowBoxes(boolean state)
1022 * @return DOCUMENT ME!
1024 public boolean getWrapAlignment()
1026 return wrapAlignment;
1032 * @return DOCUMENT ME!
1034 public boolean getShowText()
1042 * @return DOCUMENT ME!
1044 public boolean getShowBoxes()
1052 * @return DOCUMENT ME!
1054 public char getGapCharacter()
1056 return getAlignment().getGapCharacter();
1065 public void setGapCharacter(char gap)
1067 if (getAlignment() != null)
1069 getAlignment().setGapCharacter(gap);
1079 public void setThreshold(int thresh)
1087 * @return DOCUMENT ME!
1089 public int getThreshold()
1100 public void setIncrement(int inc)
1108 * @return DOCUMENT ME!
1110 public int getIncrement()
1118 * @return DOCUMENT ME!
1120 public ColumnSelection getColumnSelection()
1131 public void setCurrentTree(NJTree tree)
1139 * @return DOCUMENT ME!
1141 public NJTree getCurrentTree()
1152 public void setColourAppliesToAllGroups(boolean b)
1154 colourAppliesToAllGroups = b;
1160 * @return DOCUMENT ME!
1162 public boolean getColourAppliesToAllGroups()
1164 return colourAppliesToAllGroups;
1170 * @return DOCUMENT ME!
1172 public boolean getShowJVSuffix()
1174 return showJVSuffix;
1183 public void setShowJVSuffix(boolean b)
1191 * @return DOCUMENT ME!
1193 public boolean getShowAnnotation()
1195 return showAnnotation;
1204 public void setShowAnnotation(boolean b)
1212 * @return DOCUMENT ME!
1214 public boolean getScaleAboveWrapped()
1216 return scaleAboveWrapped;
1222 * @return DOCUMENT ME!
1224 public boolean getScaleLeftWrapped()
1226 return scaleLeftWrapped;
1232 * @return DOCUMENT ME!
1234 public boolean getScaleRightWrapped()
1236 return scaleRightWrapped;
1245 public void setScaleAboveWrapped(boolean b)
1247 scaleAboveWrapped = b;
1256 public void setScaleLeftWrapped(boolean b)
1258 scaleLeftWrapped = b;
1267 public void setScaleRightWrapped(boolean b)
1269 scaleRightWrapped = b;
1273 * Property change listener for changes in alignment
1278 public void addPropertyChangeListener(
1279 java.beans.PropertyChangeListener listener)
1281 changeSupport.addPropertyChangeListener(listener);
1290 public void removePropertyChangeListener(
1291 java.beans.PropertyChangeListener listener)
1293 changeSupport.removePropertyChangeListener(listener);
1297 * Property change listener for changes in alignment
1306 public void firePropertyChange(String prop, Object oldvalue,
1309 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1312 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1314 ignoreGapsInConsensusCalculation = b;
1315 updateConsensus(ap);
1316 if (globalColourScheme != null)
1318 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1319 ignoreGapsInConsensusCalculation);
1323 public boolean getIgnoreGapsConsensus()
1325 return ignoreGapsInConsensusCalculation;
1328 public void setDataset(boolean b)
1333 public boolean isDataset()
1338 public void hideSelectedColumns()
1340 if (colSel.size() < 1)
1345 colSel.hideSelectedColumns();
1346 setSelectionGroup(null);
1348 hasHiddenColumns = true;
1351 public void hideColumns(int start, int end)
1355 colSel.hideColumns(start);
1359 colSel.hideColumns(start, end);
1362 hasHiddenColumns = true;
1365 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1367 int sSize = sg.getSize();
1373 if (hiddenRepSequences == null)
1375 hiddenRepSequences = new Hashtable();
1378 hiddenRepSequences.put(repSequence, sg);
1380 // Hide all sequences except the repSequence
1381 SequenceI[] seqs = new SequenceI[sSize - 1];
1383 for (int i = 0; i < sSize; i++)
1385 if (sg.getSequenceAt(i) != repSequence)
1387 if (index == sSize - 1)
1392 seqs[index++] = sg.getSequenceAt(i);
1395 sg.setSeqrep(repSequence);
1396 sg.setHidereps(true);
1401 public void hideAllSelectedSeqs()
1403 if (selectionGroup == null || selectionGroup.getSize() < 1)
1408 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1412 setSelectionGroup(null);
1415 public void hideSequence(SequenceI[] seq)
1419 for (int i = 0; i < seq.length; i++)
1421 alignment.getHiddenSequences().hideSequence(seq[i]);
1423 hasHiddenRows = true;
1424 firePropertyChange("alignment", null, alignment.getSequences());
1428 public void showSequence(int index)
1430 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1431 hiddenRepSequences);
1434 if (selectionGroup == null)
1436 selectionGroup = new SequenceGroup();
1437 selectionGroup.setEndRes(alignment.getWidth() - 1);
1440 for (int t = 0; t < tmp.size(); t++)
1442 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1444 firePropertyChange("alignment", null, alignment.getSequences());
1448 if (alignment.getHiddenSequences().getSize() < 1)
1450 hasHiddenRows = false;
1454 public void showColumn(int col)
1456 colSel.revealHiddenColumns(col);
1457 if (colSel.getHiddenColumns() == null)
1459 hasHiddenColumns = false;
1463 public void showAllHiddenColumns()
1465 colSel.revealAllHiddenColumns();
1466 hasHiddenColumns = false;
1469 public void showAllHiddenSeqs()
1471 if (alignment.getHiddenSequences().getSize() > 0)
1473 if (selectionGroup == null)
1475 selectionGroup = new SequenceGroup();
1476 selectionGroup.setEndRes(alignment.getWidth() - 1);
1478 Vector tmp = alignment.getHiddenSequences().showAll(
1479 hiddenRepSequences);
1480 for (int t = 0; t < tmp.size(); t++)
1482 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1484 firePropertyChange("alignment", null, alignment.getSequences());
1486 hasHiddenRows = false;
1487 hiddenRepSequences = null;
1491 public void invertColumnSelection()
1493 colSel.invertColumnSelection(0, alignment.getWidth());
1496 public int adjustForHiddenSeqs(int alignmentIndex)
1498 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1503 * This method returns an array of new SequenceI objects derived from the
1504 * whole alignment or just the current selection with start and end points
1507 * @note if you need references to the actual SequenceI objects in the
1508 * alignment or currently selected then use getSequenceSelection()
1509 * @return selection as new sequenceI objects
1511 public SequenceI[] getSelectionAsNewSequence()
1513 SequenceI[] sequences;
1515 if (selectionGroup == null)
1517 sequences = alignment.getSequencesArray();
1518 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1519 for (int i = 0; i < sequences.length; i++)
1521 sequences[i] = new Sequence(sequences[i], annots); // construct new
1523 // subset of visible
1529 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1536 * get the currently selected sequence objects or all the sequences in the
1539 * @return array of references to sequence objects
1541 public SequenceI[] getSequenceSelection()
1543 SequenceI[] sequences = null;
1544 if (selectionGroup != null)
1546 sequences = selectionGroup.getSequencesInOrder(alignment);
1548 if (sequences == null)
1550 sequences = alignment.getSequencesArray();
1556 * This method returns the visible alignment as text, as seen on the GUI, ie
1557 * if columns are hidden they will not be returned in the result. Use this for
1558 * calculating trees, PCA, redundancy etc on views which contain hidden
1563 public jalview.datamodel.CigarArray getViewAsCigars(
1564 boolean selectedRegionOnly)
1566 return new jalview.datamodel.CigarArray(alignment, (hasHiddenColumns ? colSel : null), (selectedRegionOnly ? selectionGroup : null));
1570 * return a compact representation of the current alignment selection to pass
1571 * to an analysis function
1573 * @param selectedOnly
1574 * boolean true to just return the selected view
1575 * @return AlignmentView
1577 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1579 return getAlignmentView(selectedOnly, false);
1583 * return a compact representation of the current alignment selection to pass
1584 * to an analysis function
1586 * @param selectedOnly
1587 * boolean true to just return the selected view
1589 * boolean true to annotate the alignment view with groups on the alignment (and intersecting with selected region if selectedOnly is true)
1590 * @return AlignmentView
1592 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups)
1594 return new AlignmentView(alignment, colSel, selectionGroup, hasHiddenColumns, selectedOnly, markGroups);
1598 * This method returns the visible alignment as text, as seen on the GUI, ie
1599 * if columns are hidden they will not be returned in the result. Use this for
1600 * calculating trees, PCA, redundancy etc on views which contain hidden
1605 public String[] getViewAsString(boolean selectedRegionOnly)
1607 String[] selection = null;
1608 SequenceI[] seqs = null;
1610 int start = 0, end = 0;
1611 if (selectedRegionOnly && selectionGroup != null)
1613 iSize = selectionGroup.getSize();
1614 seqs = selectionGroup.getSequencesInOrder(alignment);
1615 start = selectionGroup.getStartRes();
1616 end = selectionGroup.getEndRes() + 1;
1620 iSize = alignment.getHeight();
1621 seqs = alignment.getSequencesArray();
1622 end = alignment.getWidth();
1625 selection = new String[iSize];
1626 if (hasHiddenColumns)
1628 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1632 for (i = 0; i < iSize; i++)
1634 selection[i] = seqs[i].getSequenceAsString(start, end);
1641 public int[][] getVisibleRegionBoundaries(int min, int max)
1643 Vector regions = new Vector();
1649 if (hasHiddenColumns)
1653 start = colSel.adjustForHiddenColumns(start);
1656 end = colSel.getHiddenBoundaryRight(start);
1667 regions.addElement(new int[]
1670 if (hasHiddenColumns)
1672 start = colSel.adjustForHiddenColumns(end);
1673 start = colSel.getHiddenBoundaryLeft(start) + 1;
1675 } while (end < max);
1677 int[][] startEnd = new int[regions.size()][2];
1679 regions.copyInto(startEnd);
1685 public boolean getShowHiddenMarkers()
1687 return showHiddenMarkers;
1690 public void setShowHiddenMarkers(boolean show)
1692 showHiddenMarkers = show;
1695 public String getSequenceSetId()
1697 if (sequenceSetID == null)
1699 sequenceSetID = alignment.hashCode() + "";
1702 return sequenceSetID;
1706 * unique viewId for synchronizing state with stored Jalview Project
1709 private String viewId = null;
1711 public String getViewId()
1715 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1720 public void alignmentChanged(AlignmentPanel ap)
1724 alignment.padGaps();
1726 if (hconsensus != null && autoCalculateConsensus)
1728 updateConservation(ap);
1730 if (autoCalculateConsensus)
1732 updateConsensus(ap);
1735 // Reset endRes of groups if beyond alignment width
1736 int alWidth = alignment.getWidth();
1737 Vector groups = alignment.getGroups();
1740 for (int i = 0; i < groups.size(); i++)
1742 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1743 if (sg.getEndRes() > alWidth)
1745 sg.setEndRes(alWidth - 1);
1750 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1752 selectionGroup.setEndRes(alWidth - 1);
1755 resetAllColourSchemes();
1757 // alignment.adjustSequenceAnnotations();
1760 void resetAllColourSchemes()
1762 ColourSchemeI cs = globalColourScheme;
1765 if (cs instanceof ClustalxColourScheme)
1767 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1768 alignment.getWidth());
1771 cs.setConsensus(hconsensus);
1772 if (cs.conservationApplied())
1774 Alignment al = (Alignment) alignment;
1775 Conservation c = new Conservation("All",
1776 ResidueProperties.propHash, 3, al.getSequences(), 0,
1779 c.verdict(false, ConsPercGaps);
1781 cs.setConservation(c);
1785 int s, sSize = alignment.getGroups().size();
1786 for (s = 0; s < sSize; s++)
1788 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1789 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1791 ((ClustalxColourScheme) sg.cs).resetClustalX(
1792 sg.getSequences(hiddenRepSequences), sg.getWidth());
1794 sg.recalcConservation();
1798 public Color getSequenceColour(SequenceI seq)
1800 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1806 return (Color) sequenceColours.get(seq);
1810 public void setSequenceColour(SequenceI seq, Color col)
1812 if (sequenceColours == null)
1814 sequenceColours = new Hashtable();
1819 sequenceColours.remove(seq);
1823 sequenceColours.put(seq, col);
1828 * returns the visible column regions of the alignment
1830 * @param selectedRegionOnly
1831 * true to just return the contigs intersecting with the selected
1835 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1837 int[] viscontigs = null;
1838 int start = 0, end = 0;
1839 if (selectedRegionOnly && selectionGroup != null)
1841 start = selectionGroup.getStartRes();
1842 end = selectionGroup.getEndRes() + 1;
1846 end = alignment.getWidth();
1848 viscontigs = colSel.getVisibleContigs(start, end);
1853 * get hash of undo and redo list for the alignment
1855 * @return long[] { historyList.hashCode, redoList.hashCode };
1857 public long[] getUndoRedoHash()
1859 if (historyList == null || redoList == null)
1863 { historyList.hashCode(), this.redoList.hashCode() };
1867 * test if a particular set of hashcodes are different to the hashcodes for
1868 * the undo and redo list.
1871 * the stored set of hashcodes as returned by getUndoRedoHash
1872 * @return true if the hashcodes differ (ie the alignment has been edited) or
1873 * the stored hashcode array differs in size
1875 public boolean isUndoRedoHashModified(long[] undoredo)
1877 if (undoredo == null)
1881 long[] cstate = getUndoRedoHash();
1882 if (cstate.length != undoredo.length)
1887 for (int i = 0; i < cstate.length; i++)
1889 if (cstate[i] != undoredo[i])
1897 public boolean getCentreColumnLabels()
1899 return centreColumnLabels;
1902 public void setCentreColumnLabels(boolean centrecolumnlabels)
1904 centreColumnLabels = centrecolumnlabels;
1907 public void updateSequenceIdColours()
1909 Vector groups = alignment.getGroups();
1910 if (sequenceColours == null)
1912 sequenceColours = new Hashtable();
1914 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1916 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1917 if (sg.idColour != null)
1919 Vector sqs = sg.getSequences(hiddenRepSequences);
1920 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1922 sequenceColours.put(sqs.elementAt(s), sg.idColour);
1929 * enable or disable the display of Database Cross References in the sequence
1932 public void setShowDbRefs(boolean show)
1939 * @return true if Database References are to be displayed on tooltips.
1941 public boolean isShowDbRefs()
1948 * @return true if Non-positional features are to be displayed on tooltips.
1950 public boolean isShowNpFeats()
1956 * enable or disable the display of Non-Positional sequence features in the
1957 * sequence ID tooltip
1961 public void setShowNpFeats(boolean show)
1968 * @return true if view has hidden rows
1970 public boolean hasHiddenRows()
1972 return hasHiddenRows;
1977 * @return true if view has hidden columns
1979 public boolean hasHiddenColumns()
1981 return hasHiddenColumns;
1985 * when set, view will scroll to show the highlighted position
1987 public boolean followHighlight = true;
1990 * @return true if view should scroll to show the highlighted region of a
1994 public boolean getFollowHighlight()
1996 return followHighlight;
1999 public boolean followSelection = true;
2002 * @return true if view selection should always follow the selections
2003 * broadcast by other selection sources
2005 public boolean getFollowSelection()
2007 return followSelection;
2010 private long sgrouphash = -1, colselhash = -1;
2012 boolean showSeqFeaturesHeight;
2015 * checks current SelectionGroup against record of last hash value, and
2017 * @param b update the record of last hash value
2019 * @return true if SelectionGroup changed since last call (when b is true)
2021 boolean isSelectionGroupChanged(boolean b)
2023 int hc = (selectionGroup == null || selectionGroup.getSize()==0) ? -1 : selectionGroup.hashCode();
2024 if (hc!=-1 && hc != sgrouphash)
2026 if (b) {sgrouphash = hc;}
2033 * checks current colsel against record of last hash value, and optionally updates
2036 * @param b update the record of last hash value
2037 * @return true if colsel changed since last call (when b is true)
2039 boolean isColSelChanged(boolean b)
2041 int hc = (colSel == null || colSel.size()==0) ? -1 : colSel.hashCode();
2042 if (hc!=-1 && hc != colselhash)
2044 if (b) {colselhash = hc;}
2050 public void sendSelection()
2052 jalview.structure.StructureSelectionManager
2053 .getStructureSelectionManager().sendSelection(
2054 new SequenceGroup(getSelectionGroup()),
2055 new ColumnSelection(getColumnSelection()), this);
2058 public void setShowSequenceFeaturesHeight(boolean selected)
2060 showSeqFeaturesHeight = selected;
2063 public boolean getShowSequenceFeaturesHeight()
2065 return showSeqFeaturesHeight;
2068 boolean showUnconserved = false;
2070 public boolean getShowUnconserved()
2072 return showUnconserved;
2075 public void setShowUnconserved(boolean showunconserved)
2077 showUnconserved = showunconserved;
2081 * return the alignPanel containing the given viewport. Use this to get the
2082 * components currently handling the given viewport.
2085 * @return null or an alignPanel guaranteed to have non-null alignFrame
2088 public AlignmentPanel getAlignPanel()
2090 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2091 .getSequenceSetId());
2092 AlignmentPanel ap = null;
2093 for (int p = 0; aps != null && p < aps.length; p++)
2095 if (aps[p].av == this)
2103 public boolean getSortByTree()
2108 public void setSortByTree(boolean sort)
2114 * should conservation rows be shown for groups
2116 boolean showGroupConservation = false;
2119 * should consensus rows be shown for groups
2121 boolean showGroupConsensus = false;
2124 * should consensus profile be rendered by default
2126 public boolean showSequenceLogo = false;
2129 * should consensus histograms be rendered by default
2131 public boolean showConsensusHistogram = true;
2134 * @return the showConsensusProfile
2136 public boolean isShowSequenceLogo()
2138 return showSequenceLogo;
2142 * @param showSequenceLogo
2145 public void setShowSequenceLogo(boolean showSequenceLogo)
2147 if (showSequenceLogo != this.showSequenceLogo)
2149 // TODO: decouple settings setting from calculation when refactoring
2150 // annotation update method from alignframe to viewport
2151 this.showSequenceLogo = showSequenceLogo;
2152 if (consensusThread != null)
2154 consensusThread.updateAnnotation();
2157 this.showSequenceLogo = showSequenceLogo;
2161 * @param showConsensusHistogram
2162 * the showConsensusHistogram to set
2164 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2166 this.showConsensusHistogram = showConsensusHistogram;
2170 * @return the showGroupConservation
2172 public boolean isShowGroupConservation()
2174 return showGroupConservation;
2178 * @param showGroupConservation
2179 * the showGroupConservation to set
2181 public void setShowGroupConservation(boolean showGroupConservation)
2183 this.showGroupConservation = showGroupConservation;
2187 * @return the showGroupConsensus
2189 public boolean isShowGroupConsensus()
2191 return showGroupConsensus;
2195 * @param showGroupConsensus
2196 * the showGroupConsensus to set
2198 public void setShowGroupConsensus(boolean showGroupConsensus)
2200 this.showGroupConsensus = showGroupConsensus;
2205 * @return flag to indicate if the consensus histogram should be rendered by
2208 public boolean isShowConsensusHistogram()
2210 return this.showConsensusHistogram;
2214 * synthesize a column selection if none exists so it covers the given
2215 * selection group. if wholewidth is false, no column selection is made if the
2216 * selection group covers the whole alignment width.
2221 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2225 && (sgs = sg.getStartRes()) >= 0
2226 && sg.getStartRes() <= (sge = sg.getEndRes())
2227 && (colSel == null || colSel.getSelected() == null || colSel
2228 .getSelected().size() == 0))
2230 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2237 colSel = new ColumnSelection();
2239 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2241 colSel.addElement(cspos);