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.*;
43 import jalview.api.StructureSelectionManagerProvider;
47 import jalview.datamodel.*;
49 import jalview.schemes.*;
50 import jalview.structure.SelectionSource;
51 import jalview.structure.StructureSelectionManager;
52 import jalview.structure.VamsasSource;
58 * @version $Revision: 1.141 $
60 public class AlignViewport implements SelectionSource, VamsasSource
62 private static final int RIGHT_JUSTIFY = 1;
72 boolean showJVSuffix = true;
74 boolean showText = true;
76 boolean showColourText = false;
78 boolean showBoxes = true;
80 boolean wrapAlignment = false;
82 boolean renderGaps = true;
84 boolean showSequenceFeatures = false;
86 boolean showAnnotation = true;
88 boolean colourAppliesToAllGroups = true;
90 ColourSchemeI globalColourScheme = null;
92 boolean conservationColourSelected = false;
94 boolean abovePIDThreshold = false;
96 SequenceGroup selectionGroup;
102 boolean validCharWidth;
108 boolean seqNameItalics;
110 AlignmentI alignment;
112 ColumnSelection colSel = new ColumnSelection();
118 NJTree currentTree = null;
120 boolean scaleAboveWrapped = false;
122 boolean scaleLeftWrapped = true;
124 boolean scaleRightWrapped = true;
126 boolean hasHiddenColumns = false;
128 boolean hasHiddenRows = false;
130 boolean showHiddenMarkers = true;
132 boolean cursorMode = false;
135 * Keys are the feature types which are currently visible. Note: Values are
138 Hashtable featuresDisplayed = null;
141 public Hashtable[] hconsensus;
143 AlignmentAnnotation consensus;
145 AlignmentAnnotation conservation;
147 AlignmentAnnotation quality;
149 AlignmentAnnotation[] groupConsensus;
151 AlignmentAnnotation[] groupConservation;
153 boolean autoCalculateConsensus = true;
156 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
158 // JBPNote Prolly only need this in the applet version.
159 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
162 boolean ignoreGapsInConsensusCalculation = false;
164 boolean isDataset = false;
166 boolean antiAlias = false;
168 boolean padGaps = false;
170 Rectangle explodedPosition;
174 String sequenceSetID;
176 boolean gatherViewsHere = false;
178 Stack historyList = new Stack();
180 Stack redoList = new Stack();
182 Hashtable sequenceColours;
184 int thresholdTextColour = 0;
186 Color textColour = Color.black;
188 Color textColour2 = Color.white;
190 boolean rightAlignIds = false;
192 Hashtable hiddenRepSequences;
197 * Creates a new AlignViewport object.
202 public AlignViewport(AlignmentI al)
209 * Create a new AlignViewport object with a specific sequence set ID
213 * (may be null - but potential for ambiguous constructor exception)
215 public AlignViewport(AlignmentI al, String seqsetid)
217 this(al, seqsetid, null);
220 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
222 sequenceSetID = seqsetid;
224 // TODO remove these once 2.4.VAMSAS release finished
225 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
227 Cache.log.debug("Setting viewport's sequence set id : "
230 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
232 Cache.log.debug("Setting viewport's view id : " + viewId);
239 * Create a new AlignViewport with hidden regions
243 * @param hiddenColumns
246 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
249 if (hiddenColumns != null)
251 this.colSel = hiddenColumns;
252 if (hiddenColumns.getHiddenColumns() != null
253 && hiddenColumns.getHiddenColumns().size() > 0)
255 hasHiddenColumns = true;
259 hasHiddenColumns = false;
266 * New viewport with hidden columns and an existing sequence set id
269 * @param hiddenColumns
273 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
276 this(al, hiddenColumns, seqsetid, null);
280 * New viewport with hidden columns and an existing sequence set id and viewid
283 * @param hiddenColumns
289 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
290 String seqsetid, String viewid)
292 sequenceSetID = seqsetid;
294 // TODO remove these once 2.4.VAMSAS release finished
295 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
297 Cache.log.debug("Setting viewport's sequence set id : "
300 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
302 Cache.log.debug("Setting viewport's view id : " + viewId);
305 if (hiddenColumns != null)
307 this.colSel = hiddenColumns;
308 if (hiddenColumns.getHiddenColumns() != null
309 && hiddenColumns.getHiddenColumns().size() > 0)
311 hasHiddenColumns = true;
315 hasHiddenColumns = false;
324 this.endRes = alignment.getWidth() - 1;
326 this.endSeq = alignment.getHeight() - 1;
328 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
330 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
331 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
333 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
334 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
335 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
337 padGaps = Cache.getDefault("PAD_GAPS", true);
338 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
339 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
341 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
342 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
343 String fontSize = Cache.getDefault("FONT_SIZE", "10");
345 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
349 if (fontStyle.equals("bold"))
353 else if (fontStyle.equals("italic"))
358 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
361 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
363 // We must set conservation and consensus before setting colour,
364 // as Blosum and Clustal require this to be done
365 if (hconsensus == null && !isDataset)
367 if (!alignment.isNucleotide())
369 conservation = new AlignmentAnnotation("Conservation",
370 "Conservation of total alignment less than " + ConsPercGaps
371 + "% gaps", new Annotation[1], 0f, 11f,
372 AlignmentAnnotation.BAR_GRAPH);
373 conservation.hasText = true;
374 conservation.autoCalculated = true;
376 if (Cache.getDefault("SHOW_CONSERVATION", true))
378 alignment.addAnnotation(conservation);
381 if (Cache.getDefault("SHOW_QUALITY", true))
383 quality = new AlignmentAnnotation("Quality",
384 "Alignment Quality based on Blosum62 scores",
385 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
386 quality.hasText = true;
387 quality.autoCalculated = true;
389 alignment.addAnnotation(quality);
391 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
398 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
400 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
401 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
402 // TODO: add menu option action that nulls or creates consensus object
403 // depending on if the user wants to see the annotation or not in a
404 // specific alignment
405 consensus = new AlignmentAnnotation("Consensus", "PID",
406 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
407 consensus.hasText = true;
408 consensus.autoCalculated = true;
410 if (Cache.getDefault("SHOW_IDENTITY", true))
412 alignment.addAnnotation(consensus);
416 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
418 globalColourScheme = ColourSchemeProperty.getColour(alignment,
419 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
421 if (globalColourScheme instanceof UserColourScheme)
423 globalColourScheme = UserDefinedColours.loadDefaultColours();
424 ((UserColourScheme) globalColourScheme).setThreshold(0,
425 getIgnoreGapsConsensus());
428 if (globalColourScheme != null)
430 globalColourScheme.setConsensus(hconsensus);
434 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
435 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED",
437 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
438 followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS",
446 * features are displayed if true
448 public void setShowSequenceFeatures(boolean b)
450 showSequenceFeatures = b;
453 public boolean getShowSequenceFeatures()
455 return showSequenceFeatures;
458 ConservationThread conservationThread;
460 ConsensusThread consensusThread;
462 boolean consUpdateNeeded = false;
464 static boolean UPDATING_CONSENSUS = false;
466 static boolean UPDATING_CONSERVATION = false;
468 boolean updatingConsensus = false;
470 boolean updatingConservation = false;
473 * centre columnar annotation labels in displayed alignment annotation TODO:
474 * add to jalviewXML and annotation display settings
476 boolean centreColumnLabels = false;
478 private boolean showdbrefs;
480 private boolean shownpfeats;
483 * trigger update of conservation annotation
485 public void updateConservation(final AlignmentPanel ap)
487 // see note in mantis : issue number 8585
488 if (alignment.isNucleotide() || conservation == null
489 || !autoCalculateConsensus)
494 conservationThread = new ConservationThread(this, ap);
495 conservationThread.start();
499 * trigger update of consensus annotation
501 public void updateConsensus(final AlignmentPanel ap)
503 // see note in mantis : issue number 8585
504 if (consensus == null || !autoCalculateConsensus)
508 consensusThread = new ConsensusThread(ap);
509 consensusThread.start();
512 class ConsensusThread extends Thread
516 public ConsensusThread(AlignmentPanel ap)
523 updatingConsensus = true;
524 while (UPDATING_CONSENSUS)
530 ap.paintAlignment(false);
534 } catch (Exception ex)
536 ex.printStackTrace();
540 UPDATING_CONSENSUS = true;
544 int aWidth = (alignment != null) ? alignment.getWidth() : -1; // null
550 updatingConsensus = false;
551 UPDATING_CONSENSUS = false;
555 consensus.annotations = null;
556 consensus.annotations = new Annotation[aWidth];
558 hconsensus = new Hashtable[aWidth];
559 AAFrequency.calculate(alignment.getSequencesArray(), 0,
560 alignment.getWidth(), hconsensus, true);
561 updateAnnotation(true);
563 if (globalColourScheme != null)
565 globalColourScheme.setConsensus(hconsensus);
568 } catch (OutOfMemoryError error)
570 alignment.deleteAnnotation(consensus);
574 new OOMWarning("calculating consensus", error);
576 UPDATING_CONSENSUS = false;
577 updatingConsensus = false;
581 ap.paintAlignment(true);
586 * update the consensus annotation from the sequence profile data using
587 * current visualization settings.
589 public void updateAnnotation()
591 updateAnnotation(false);
594 protected void updateAnnotation(boolean immediate)
596 // TODO: make calls thread-safe, so if another thread calls this method,
597 // it will either return or wait until one calculation is finished.
599 || (!updatingConsensus && consensus != null && hconsensus != null))
601 AAFrequency.completeConsensus(consensus, hconsensus, 0,
602 hconsensus.length, ignoreGapsInConsensusCalculation,
609 * get the consensus sequence as displayed under the PID consensus annotation
612 * @return consensus sequence as a new sequence object
614 public SequenceI getConsensusSeq()
616 if (consensus == null)
618 updateConsensus(null);
620 if (consensus == null)
624 StringBuffer seqs = new StringBuffer();
625 for (int i = 0; i < consensus.annotations.length; i++)
627 if (consensus.annotations[i] != null)
629 if (consensus.annotations[i].description.charAt(0) == '[')
631 seqs.append(consensus.annotations[i].description.charAt(1));
635 seqs.append(consensus.annotations[i].displayCharacter);
640 SequenceI sq = new Sequence("Consensus", seqs.toString());
641 sq.setDescription("Percentage Identity Consensus "
642 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
649 * @return null or the currently selected sequence region
651 public SequenceGroup getSelectionGroup()
653 return selectionGroup;
657 * Set the selection group for this window.
659 * @param sg - group holding references to sequences in this alignment view
662 public void setSelectionGroup(SequenceGroup sg)
669 * @return true if conservation based shading is enabled
671 public boolean getConservationSelected()
673 return conservationColourSelected;
679 * enable conservation based shading
681 public void setConservationSelected(boolean b)
683 conservationColourSelected = b;
688 * @return true if percent identity threshold is applied to shading
690 public boolean getAbovePIDThreshold()
692 return abovePIDThreshold;
699 * @param b indicate if percent identity threshold is applied to shading
701 public void setAbovePIDThreshold(boolean b)
703 abovePIDThreshold = b;
709 * @return DOCUMENT ME!
711 public int getStartRes()
719 * @return DOCUMENT ME!
721 public int getEndRes()
729 * @return DOCUMENT ME!
731 public int getStartSeq()
742 public void setGlobalColourScheme(ColourSchemeI cs)
744 globalColourScheme = cs;
750 * @return DOCUMENT ME!
752 public ColourSchemeI getGlobalColourScheme()
754 return globalColourScheme;
763 public void setStartRes(int res)
774 public void setStartSeq(int seq)
785 public void setEndRes(int res)
787 if (res > (alignment.getWidth() - 1))
789 // log.System.out.println(" Corrected res from " + res + " to maximum " +
790 // (alignment.getWidth()-1));
791 res = alignment.getWidth() - 1;
808 public void setEndSeq(int seq)
810 if (seq > alignment.getHeight())
812 seq = alignment.getHeight();
826 * @return DOCUMENT ME!
828 public int getEndSeq()
839 public void setFont(Font f)
843 Container c = new Container();
845 java.awt.FontMetrics fm = c.getFontMetrics(font);
846 setCharHeight(fm.getHeight());
847 setCharWidth(fm.charWidth('M'));
848 validCharWidth = true;
854 * @return DOCUMENT ME!
856 public Font getFont()
867 public void setCharWidth(int w)
875 * @return DOCUMENT ME!
877 public int getCharWidth()
888 public void setCharHeight(int h)
896 * @return DOCUMENT ME!
898 public int getCharHeight()
909 public void setWrappedWidth(int w)
911 this.wrappedWidth = w;
917 * @return DOCUMENT ME!
919 public int getWrappedWidth()
927 * @return DOCUMENT ME!
929 public AlignmentI getAlignment()
940 public void setAlignment(AlignmentI align)
942 if (alignment != null && alignment.getCodonFrames() != null)
944 StructureSelectionManager.getStructureSelectionManager(Desktop.instance)
945 .removeMappings(alignment.getCodonFrames());
947 this.alignment = align;
948 if (alignment.getCodonFrames() != null)
950 StructureSelectionManager.getStructureSelectionManager(Desktop.instance).addMappings(
951 alignment.getCodonFrames());
961 public void setWrapAlignment(boolean state)
963 wrapAlignment = state;
972 public void setShowText(boolean state)
983 public void setRenderGaps(boolean state)
991 * @return DOCUMENT ME!
993 public boolean getColourText()
995 return showColourText;
1004 public void setColourText(boolean state)
1006 showColourText = state;
1015 public void setShowBoxes(boolean state)
1023 * @return DOCUMENT ME!
1025 public boolean getWrapAlignment()
1027 return wrapAlignment;
1033 * @return DOCUMENT ME!
1035 public boolean getShowText()
1043 * @return DOCUMENT ME!
1045 public boolean getShowBoxes()
1053 * @return DOCUMENT ME!
1055 public char getGapCharacter()
1057 return getAlignment().getGapCharacter();
1066 public void setGapCharacter(char gap)
1068 if (getAlignment() != null)
1070 getAlignment().setGapCharacter(gap);
1080 public void setThreshold(int thresh)
1088 * @return DOCUMENT ME!
1090 public int getThreshold()
1101 public void setIncrement(int inc)
1109 * @return DOCUMENT ME!
1111 public int getIncrement()
1119 * @return DOCUMENT ME!
1121 public ColumnSelection getColumnSelection()
1132 public void setCurrentTree(NJTree tree)
1140 * @return DOCUMENT ME!
1142 public NJTree getCurrentTree()
1153 public void setColourAppliesToAllGroups(boolean b)
1155 colourAppliesToAllGroups = b;
1161 * @return DOCUMENT ME!
1163 public boolean getColourAppliesToAllGroups()
1165 return colourAppliesToAllGroups;
1171 * @return DOCUMENT ME!
1173 public boolean getShowJVSuffix()
1175 return showJVSuffix;
1184 public void setShowJVSuffix(boolean b)
1192 * @return DOCUMENT ME!
1194 public boolean getShowAnnotation()
1196 return showAnnotation;
1205 public void setShowAnnotation(boolean b)
1213 * @return DOCUMENT ME!
1215 public boolean getScaleAboveWrapped()
1217 return scaleAboveWrapped;
1223 * @return DOCUMENT ME!
1225 public boolean getScaleLeftWrapped()
1227 return scaleLeftWrapped;
1233 * @return DOCUMENT ME!
1235 public boolean getScaleRightWrapped()
1237 return scaleRightWrapped;
1246 public void setScaleAboveWrapped(boolean b)
1248 scaleAboveWrapped = b;
1257 public void setScaleLeftWrapped(boolean b)
1259 scaleLeftWrapped = b;
1268 public void setScaleRightWrapped(boolean b)
1270 scaleRightWrapped = b;
1274 * Property change listener for changes in alignment
1279 public void addPropertyChangeListener(
1280 java.beans.PropertyChangeListener listener)
1282 changeSupport.addPropertyChangeListener(listener);
1291 public void removePropertyChangeListener(
1292 java.beans.PropertyChangeListener listener)
1294 changeSupport.removePropertyChangeListener(listener);
1298 * Property change listener for changes in alignment
1307 public void firePropertyChange(String prop, Object oldvalue,
1310 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1313 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1315 ignoreGapsInConsensusCalculation = b;
1316 updateConsensus(ap);
1317 if (globalColourScheme != null)
1319 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1320 ignoreGapsInConsensusCalculation);
1324 public boolean getIgnoreGapsConsensus()
1326 return ignoreGapsInConsensusCalculation;
1329 public void setDataset(boolean b)
1334 public boolean isDataset()
1339 public void hideSelectedColumns()
1341 if (colSel.size() < 1)
1346 colSel.hideSelectedColumns();
1347 setSelectionGroup(null);
1349 hasHiddenColumns = true;
1352 public void hideColumns(int start, int end)
1356 colSel.hideColumns(start);
1360 colSel.hideColumns(start, end);
1363 hasHiddenColumns = true;
1366 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1368 int sSize = sg.getSize();
1374 if (hiddenRepSequences == null)
1376 hiddenRepSequences = new Hashtable();
1379 hiddenRepSequences.put(repSequence, sg);
1381 // Hide all sequences except the repSequence
1382 SequenceI[] seqs = new SequenceI[sSize - 1];
1384 for (int i = 0; i < sSize; i++)
1386 if (sg.getSequenceAt(i) != repSequence)
1388 if (index == sSize - 1)
1393 seqs[index++] = sg.getSequenceAt(i);
1396 sg.setSeqrep(repSequence);
1397 sg.setHidereps(true);
1402 public void hideAllSelectedSeqs()
1404 if (selectionGroup == null || selectionGroup.getSize() < 1)
1409 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1413 setSelectionGroup(null);
1416 public void hideSequence(SequenceI[] seq)
1420 for (int i = 0; i < seq.length; i++)
1422 alignment.getHiddenSequences().hideSequence(seq[i]);
1424 hasHiddenRows = true;
1425 firePropertyChange("alignment", null, alignment.getSequences());
1429 public void showSequence(int index)
1431 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1432 hiddenRepSequences);
1435 if (selectionGroup == null)
1437 selectionGroup = new SequenceGroup();
1438 selectionGroup.setEndRes(alignment.getWidth() - 1);
1441 for (int t = 0; t < tmp.size(); t++)
1443 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1445 firePropertyChange("alignment", null, alignment.getSequences());
1449 if (alignment.getHiddenSequences().getSize() < 1)
1451 hasHiddenRows = false;
1455 public void showColumn(int col)
1457 colSel.revealHiddenColumns(col);
1458 if (colSel.getHiddenColumns() == null)
1460 hasHiddenColumns = false;
1464 public void showAllHiddenColumns()
1466 colSel.revealAllHiddenColumns();
1467 hasHiddenColumns = false;
1470 public void showAllHiddenSeqs()
1472 if (alignment.getHiddenSequences().getSize() > 0)
1474 if (selectionGroup == null)
1476 selectionGroup = new SequenceGroup();
1477 selectionGroup.setEndRes(alignment.getWidth() - 1);
1479 Vector tmp = alignment.getHiddenSequences().showAll(
1480 hiddenRepSequences);
1481 for (int t = 0; t < tmp.size(); t++)
1483 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1485 firePropertyChange("alignment", null, alignment.getSequences());
1487 hasHiddenRows = false;
1488 hiddenRepSequences = null;
1492 public void invertColumnSelection()
1494 colSel.invertColumnSelection(0, alignment.getWidth());
1497 public int adjustForHiddenSeqs(int alignmentIndex)
1499 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1504 * This method returns an array of new SequenceI objects derived from the
1505 * whole alignment or just the current selection with start and end points
1508 * @note if you need references to the actual SequenceI objects in the
1509 * alignment or currently selected then use getSequenceSelection()
1510 * @return selection as new sequenceI objects
1512 public SequenceI[] getSelectionAsNewSequence()
1514 SequenceI[] sequences;
1516 if (selectionGroup == null)
1518 sequences = alignment.getSequencesArray();
1519 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1520 for (int i = 0; i < sequences.length; i++)
1522 sequences[i] = new Sequence(sequences[i], annots); // construct new
1524 // subset of visible
1530 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1537 * get the currently selected sequence objects or all the sequences in the
1540 * @return array of references to sequence objects
1542 public SequenceI[] getSequenceSelection()
1544 SequenceI[] sequences = null;
1545 if (selectionGroup != null)
1547 sequences = selectionGroup.getSequencesInOrder(alignment);
1549 if (sequences == null)
1551 sequences = alignment.getSequencesArray();
1557 * This method returns the visible alignment as text, as seen on the GUI, ie
1558 * if columns are hidden they will not be returned in the result. Use this for
1559 * calculating trees, PCA, redundancy etc on views which contain hidden
1564 public jalview.datamodel.CigarArray getViewAsCigars(
1565 boolean selectedRegionOnly)
1567 return new jalview.datamodel.CigarArray(alignment, (hasHiddenColumns ? colSel : null), (selectedRegionOnly ? selectionGroup : null));
1571 * return a compact representation of the current alignment selection to pass
1572 * to an analysis function
1574 * @param selectedOnly
1575 * boolean true to just return the selected view
1576 * @return AlignmentView
1578 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1580 return getAlignmentView(selectedOnly, false);
1584 * return a compact representation of the current alignment selection to pass
1585 * to an analysis function
1587 * @param selectedOnly
1588 * boolean true to just return the selected view
1590 * boolean true to annotate the alignment view with groups on the alignment (and intersecting with selected region if selectedOnly is true)
1591 * @return AlignmentView
1593 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups)
1595 return new AlignmentView(alignment, colSel, selectionGroup, hasHiddenColumns, selectedOnly, markGroups);
1599 * This method returns the visible alignment as text, as seen on the GUI, ie
1600 * if columns are hidden they will not be returned in the result. Use this for
1601 * calculating trees, PCA, redundancy etc on views which contain hidden
1606 public String[] getViewAsString(boolean selectedRegionOnly)
1608 String[] selection = null;
1609 SequenceI[] seqs = null;
1611 int start = 0, end = 0;
1612 if (selectedRegionOnly && selectionGroup != null)
1614 iSize = selectionGroup.getSize();
1615 seqs = selectionGroup.getSequencesInOrder(alignment);
1616 start = selectionGroup.getStartRes();
1617 end = selectionGroup.getEndRes() + 1;
1621 iSize = alignment.getHeight();
1622 seqs = alignment.getSequencesArray();
1623 end = alignment.getWidth();
1626 selection = new String[iSize];
1627 if (hasHiddenColumns)
1629 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1633 for (i = 0; i < iSize; i++)
1635 selection[i] = seqs[i].getSequenceAsString(start, end);
1642 public int[][] getVisibleRegionBoundaries(int min, int max)
1644 Vector regions = new Vector();
1650 if (hasHiddenColumns)
1654 start = colSel.adjustForHiddenColumns(start);
1657 end = colSel.getHiddenBoundaryRight(start);
1668 regions.addElement(new int[]
1671 if (hasHiddenColumns)
1673 start = colSel.adjustForHiddenColumns(end);
1674 start = colSel.getHiddenBoundaryLeft(start) + 1;
1676 } while (end < max);
1678 int[][] startEnd = new int[regions.size()][2];
1680 regions.copyInto(startEnd);
1686 public boolean getShowHiddenMarkers()
1688 return showHiddenMarkers;
1691 public void setShowHiddenMarkers(boolean show)
1693 showHiddenMarkers = show;
1696 public String getSequenceSetId()
1698 if (sequenceSetID == null)
1700 sequenceSetID = alignment.hashCode() + "";
1703 return sequenceSetID;
1707 * unique viewId for synchronizing state with stored Jalview Project
1710 private String viewId = null;
1712 public String getViewId()
1716 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1721 public void alignmentChanged(AlignmentPanel ap)
1725 alignment.padGaps();
1727 if (hconsensus != null && autoCalculateConsensus)
1729 updateConservation(ap);
1731 if (autoCalculateConsensus)
1733 updateConsensus(ap);
1736 // Reset endRes of groups if beyond alignment width
1737 int alWidth = alignment.getWidth();
1738 Vector groups = alignment.getGroups();
1741 for (int i = 0; i < groups.size(); i++)
1743 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1744 if (sg.getEndRes() > alWidth)
1746 sg.setEndRes(alWidth - 1);
1751 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1753 selectionGroup.setEndRes(alWidth - 1);
1756 resetAllColourSchemes();
1758 // alignment.adjustSequenceAnnotations();
1761 void resetAllColourSchemes()
1763 ColourSchemeI cs = globalColourScheme;
1766 if (cs instanceof ClustalxColourScheme)
1768 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1769 alignment.getWidth());
1772 cs.setConsensus(hconsensus);
1773 if (cs.conservationApplied())
1775 Alignment al = (Alignment) alignment;
1776 Conservation c = new Conservation("All",
1777 ResidueProperties.propHash, 3, al.getSequences(), 0,
1780 c.verdict(false, ConsPercGaps);
1782 cs.setConservation(c);
1786 int s, sSize = alignment.getGroups().size();
1787 for (s = 0; s < sSize; s++)
1789 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1790 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1792 ((ClustalxColourScheme) sg.cs).resetClustalX(
1793 sg.getSequences(hiddenRepSequences), sg.getWidth());
1795 sg.recalcConservation();
1799 public Color getSequenceColour(SequenceI seq)
1801 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1807 return (Color) sequenceColours.get(seq);
1811 public void setSequenceColour(SequenceI seq, Color col)
1813 if (sequenceColours == null)
1815 sequenceColours = new Hashtable();
1820 sequenceColours.remove(seq);
1824 sequenceColours.put(seq, col);
1829 * returns the visible column regions of the alignment
1831 * @param selectedRegionOnly
1832 * true to just return the contigs intersecting with the selected
1836 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1838 int[] viscontigs = null;
1839 int start = 0, end = 0;
1840 if (selectedRegionOnly && selectionGroup != null)
1842 start = selectionGroup.getStartRes();
1843 end = selectionGroup.getEndRes() + 1;
1847 end = alignment.getWidth();
1849 viscontigs = colSel.getVisibleContigs(start, end);
1854 * get hash of undo and redo list for the alignment
1856 * @return long[] { historyList.hashCode, redoList.hashCode };
1858 public long[] getUndoRedoHash()
1860 if (historyList == null || redoList == null)
1864 { historyList.hashCode(), this.redoList.hashCode() };
1868 * test if a particular set of hashcodes are different to the hashcodes for
1869 * the undo and redo list.
1872 * the stored set of hashcodes as returned by getUndoRedoHash
1873 * @return true if the hashcodes differ (ie the alignment has been edited) or
1874 * the stored hashcode array differs in size
1876 public boolean isUndoRedoHashModified(long[] undoredo)
1878 if (undoredo == null)
1882 long[] cstate = getUndoRedoHash();
1883 if (cstate.length != undoredo.length)
1888 for (int i = 0; i < cstate.length; i++)
1890 if (cstate[i] != undoredo[i])
1898 public boolean getCentreColumnLabels()
1900 return centreColumnLabels;
1903 public void setCentreColumnLabels(boolean centrecolumnlabels)
1905 centreColumnLabels = centrecolumnlabels;
1908 public void updateSequenceIdColours()
1910 Vector groups = alignment.getGroups();
1911 if (sequenceColours == null)
1913 sequenceColours = new Hashtable();
1915 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1917 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1918 if (sg.idColour != null)
1920 Vector sqs = sg.getSequences(hiddenRepSequences);
1921 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1923 sequenceColours.put(sqs.elementAt(s), sg.idColour);
1930 * enable or disable the display of Database Cross References in the sequence
1933 public void setShowDbRefs(boolean show)
1940 * @return true if Database References are to be displayed on tooltips.
1942 public boolean isShowDbRefs()
1949 * @return true if Non-positional features are to be displayed on tooltips.
1951 public boolean isShowNpFeats()
1957 * enable or disable the display of Non-Positional sequence features in the
1958 * sequence ID tooltip
1962 public void setShowNpFeats(boolean show)
1969 * @return true if view has hidden rows
1971 public boolean hasHiddenRows()
1973 return hasHiddenRows;
1978 * @return true if view has hidden columns
1980 public boolean hasHiddenColumns()
1982 return hasHiddenColumns;
1986 * when set, view will scroll to show the highlighted position
1988 public boolean followHighlight = true;
1991 * @return true if view should scroll to show the highlighted region of a
1995 public boolean getFollowHighlight()
1997 return followHighlight;
2000 public boolean followSelection = true;
2003 * @return true if view selection should always follow the selections
2004 * broadcast by other selection sources
2006 public boolean getFollowSelection()
2008 return followSelection;
2011 private long sgrouphash = -1, colselhash = -1;
2013 boolean showSeqFeaturesHeight;
2016 * checks current SelectionGroup against record of last hash value, and
2018 * @param b update the record of last hash value
2020 * @return true if SelectionGroup changed since last call (when b is true)
2022 boolean isSelectionGroupChanged(boolean b)
2024 int hc = (selectionGroup == null || selectionGroup.getSize()==0) ? -1 : selectionGroup.hashCode();
2025 if (hc!=-1 && hc != sgrouphash)
2027 if (b) {sgrouphash = hc;}
2034 * checks current colsel against record of last hash value, and optionally updates
2037 * @param b update the record of last hash value
2038 * @return true if colsel changed since last call (when b is true)
2040 boolean isColSelChanged(boolean b)
2042 int hc = (colSel == null || colSel.size()==0) ? -1 : colSel.hashCode();
2043 if (hc!=-1 && hc != colselhash)
2045 if (b) {colselhash = hc;}
2051 public void sendSelection()
2053 jalview.structure.StructureSelectionManager
2054 .getStructureSelectionManager(Desktop.instance).sendSelection(
2055 new SequenceGroup(getSelectionGroup()),
2056 new ColumnSelection(getColumnSelection()), this);
2059 public void setShowSequenceFeaturesHeight(boolean selected)
2061 showSeqFeaturesHeight = selected;
2064 public boolean getShowSequenceFeaturesHeight()
2066 return showSeqFeaturesHeight;
2069 boolean showUnconserved = false;
2071 public boolean getShowUnconserved()
2073 return showUnconserved;
2076 public void setShowUnconserved(boolean showunconserved)
2078 showUnconserved = showunconserved;
2082 * return the alignPanel containing the given viewport. Use this to get the
2083 * components currently handling the given viewport.
2086 * @return null or an alignPanel guaranteed to have non-null alignFrame
2089 public AlignmentPanel getAlignPanel()
2091 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2092 .getSequenceSetId());
2093 AlignmentPanel ap = null;
2094 for (int p = 0; aps != null && p < aps.length; p++)
2096 if (aps[p].av == this)
2104 public boolean getSortByTree()
2109 public void setSortByTree(boolean sort)
2115 * should conservation rows be shown for groups
2117 boolean showGroupConservation = false;
2120 * should consensus rows be shown for groups
2122 boolean showGroupConsensus = false;
2125 * should consensus profile be rendered by default
2127 public boolean showSequenceLogo = false;
2130 * should consensus histograms be rendered by default
2132 public boolean showConsensusHistogram = true;
2135 * @return the showConsensusProfile
2137 public boolean isShowSequenceLogo()
2139 return showSequenceLogo;
2143 * @param showSequenceLogo
2146 public void setShowSequenceLogo(boolean showSequenceLogo)
2148 if (showSequenceLogo != this.showSequenceLogo)
2150 // TODO: decouple settings setting from calculation when refactoring
2151 // annotation update method from alignframe to viewport
2152 this.showSequenceLogo = showSequenceLogo;
2153 if (consensusThread != null)
2155 consensusThread.updateAnnotation();
2158 this.showSequenceLogo = showSequenceLogo;
2162 * @param showConsensusHistogram
2163 * the showConsensusHistogram to set
2165 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2167 this.showConsensusHistogram = showConsensusHistogram;
2171 * @return the showGroupConservation
2173 public boolean isShowGroupConservation()
2175 return showGroupConservation;
2179 * @param showGroupConservation
2180 * the showGroupConservation to set
2182 public void setShowGroupConservation(boolean showGroupConservation)
2184 this.showGroupConservation = showGroupConservation;
2188 * @return the showGroupConsensus
2190 public boolean isShowGroupConsensus()
2192 return showGroupConsensus;
2196 * @param showGroupConsensus
2197 * the showGroupConsensus to set
2199 public void setShowGroupConsensus(boolean showGroupConsensus)
2201 this.showGroupConsensus = showGroupConsensus;
2206 * @return flag to indicate if the consensus histogram should be rendered by
2209 public boolean isShowConsensusHistogram()
2211 return this.showConsensusHistogram;
2215 * synthesize a column selection if none exists so it covers the given
2216 * selection group. if wholewidth is false, no column selection is made if the
2217 * selection group covers the whole alignment width.
2222 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2226 && (sgs = sg.getStartRes()) >= 0
2227 && sg.getStartRes() <= (sge = sg.getEndRes())
2228 && (colSel == null || colSel.getSelected() == null || colSel
2229 .getSelected().size() == 0))
2231 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2238 colSel = new ColumnSelection();
2240 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2242 colSel.addElement(cspos);
2247 public StructureSelectionManager getStructureSelectionManager()
2249 return StructureSelectionManager.getStructureSelectionManager(Desktop.instance);
2255 * @return a series of SequenceI arrays, one for each PDBEntry, listing which sequence in the alignment holds a reference to it
2257 public SequenceI[][] collateForPDB(PDBEntry[] pdbEntries)
2259 ArrayList<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
2260 for (PDBEntry pdb: pdbEntries) {
2261 ArrayList<SequenceI> seqs = new ArrayList<SequenceI>();
2262 for (int i = 0; i < alignment.getHeight(); i++)
2264 Vector pdbs = alignment.getSequenceAt(i)
2265 .getDatasetSequence().getPDBId();
2269 for (int p = 0; p < pdbs.size(); p++)
2271 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
2272 if (p1.getId().equals(pdb.getId()))
2274 if (!seqs.contains(sq=alignment.getSequenceAt(i)))
2281 seqvectors.add(seqs.toArray(new SequenceI[seqs.size()]));
2283 return seqvectors.toArray(new SequenceI[seqvectors.size()][]);