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 public Hashtable[] hStrucConsensus;
145 AlignmentAnnotation consensus;
147 AlignmentAnnotation strucConsensus;
149 AlignmentAnnotation conservation;
151 AlignmentAnnotation quality;
153 AlignmentAnnotation[] groupConsensus;
155 AlignmentAnnotation[] groupConservation;
157 boolean autoCalculateConsensus = true;
159 boolean autoCalculateStrucConsensus = true;
162 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
164 // JBPNote Prolly only need this in the applet version.
165 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
168 boolean ignoreGapsInConsensusCalculation = false;
170 boolean isDataset = false;
172 boolean antiAlias = false;
174 boolean padGaps = false;
176 Rectangle explodedPosition;
180 String sequenceSetID;
182 boolean gatherViewsHere = false;
184 Stack historyList = new Stack();
186 Stack redoList = new Stack();
188 Hashtable sequenceColours;
190 int thresholdTextColour = 0;
192 Color textColour = Color.black;
194 Color textColour2 = Color.white;
196 boolean rightAlignIds = false;
198 Hashtable hiddenRepSequences;
203 * Creates a new AlignViewport object.
208 public AlignViewport(AlignmentI al)
215 * Create a new AlignViewport object with a specific sequence set ID
219 * (may be null - but potential for ambiguous constructor exception)
221 public AlignViewport(AlignmentI al, String seqsetid)
223 this(al, seqsetid, null);
226 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
228 sequenceSetID = seqsetid;
230 // TODO remove these once 2.4.VAMSAS release finished
231 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
233 Cache.log.debug("Setting viewport's sequence set id : "
236 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
238 Cache.log.debug("Setting viewport's view id : " + viewId);
245 * Create a new AlignViewport with hidden regions
249 * @param hiddenColumns
252 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
255 if (hiddenColumns != null)
257 this.colSel = hiddenColumns;
258 if (hiddenColumns.getHiddenColumns() != null
259 && hiddenColumns.getHiddenColumns().size() > 0)
261 hasHiddenColumns = true;
265 hasHiddenColumns = false;
272 * New viewport with hidden columns and an existing sequence set id
275 * @param hiddenColumns
279 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
282 this(al, hiddenColumns, seqsetid, null);
286 * New viewport with hidden columns and an existing sequence set id and viewid
289 * @param hiddenColumns
295 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
296 String seqsetid, String viewid)
298 sequenceSetID = seqsetid;
300 // TODO remove these once 2.4.VAMSAS release finished
301 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
303 Cache.log.debug("Setting viewport's sequence set id : "
306 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
308 Cache.log.debug("Setting viewport's view id : " + viewId);
311 if (hiddenColumns != null)
313 this.colSel = hiddenColumns;
314 if (hiddenColumns.getHiddenColumns() != null
315 && hiddenColumns.getHiddenColumns().size() > 0)
317 hasHiddenColumns = true;
321 hasHiddenColumns = false;
330 this.endRes = alignment.getWidth() - 1;
332 this.endSeq = alignment.getHeight() - 1;
334 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
336 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
337 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
339 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
340 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
341 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
343 padGaps = Cache.getDefault("PAD_GAPS", true);
344 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
345 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
347 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
348 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
349 String fontSize = Cache.getDefault("FONT_SIZE", "10");
351 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
355 if (fontStyle.equals("bold"))
359 else if (fontStyle.equals("italic"))
364 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
367 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
369 // We must set conservation and consensus before setting colour,
370 // as Blosum and Clustal require this to be done
371 if (hconsensus == null && !isDataset)
373 if (!alignment.isNucleotide())
375 conservation = new AlignmentAnnotation("Conservation",
376 "Conservation of total alignment less than " + ConsPercGaps
377 + "% gaps", new Annotation[1], 0f, 11f,
378 AlignmentAnnotation.BAR_GRAPH);
379 conservation.hasText = true;
380 conservation.autoCalculated = true;
382 if (Cache.getDefault("SHOW_CONSERVATION", true))
384 alignment.addAnnotation(conservation);
387 if (Cache.getDefault("SHOW_QUALITY", true))
389 quality = new AlignmentAnnotation("Quality",
390 "Alignment Quality based on Blosum62 scores",
391 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
392 quality.hasText = true;
393 quality.autoCalculated = true;
395 alignment.addAnnotation(quality);
397 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
404 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
406 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
407 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
408 // TODO: add menu option action that nulls or creates consensus object
409 // depending on if the user wants to see the annotation or not in a
410 // specific alignment
411 consensus = new AlignmentAnnotation("Consensus", "PID",
412 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
413 consensus.hasText = true;
414 consensus.autoCalculated = true;
416 if (alignment.isNucleotide())
418 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
419 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
420 strucConsensus.hasText = true;
421 strucConsensus.autoCalculated = true;
424 if (Cache.getDefault("SHOW_IDENTITY", true))
426 alignment.addAnnotation(consensus);
427 // TODO: Make own if for structure
428 if (alignment.isNucleotide())
430 alignment.addAnnotation(strucConsensus);
436 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
438 globalColourScheme = ColourSchemeProperty.getColour(alignment,
439 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
441 if (globalColourScheme instanceof UserColourScheme)
443 globalColourScheme = UserDefinedColours.loadDefaultColours();
444 ((UserColourScheme) globalColourScheme).setThreshold(0,
445 getIgnoreGapsConsensus());
448 if (globalColourScheme != null)
450 globalColourScheme.setConsensus(hconsensus);
454 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
455 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED",
457 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
458 followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS",
466 * features are displayed if true
468 public void setShowSequenceFeatures(boolean b)
470 showSequenceFeatures = b;
473 public boolean getShowSequenceFeatures()
475 return showSequenceFeatures;
478 ConservationThread conservationThread;
480 ConsensusThread consensusThread;
482 StrucConsensusThread strucConsensusThread;
484 boolean consUpdateNeeded = false;
486 static boolean UPDATING_CONSENSUS = false;
488 static boolean UPDATING_STRUC_CONSENSUS = false;
490 static boolean UPDATING_CONSERVATION = false;
492 boolean updatingConsensus = false;
494 boolean updatingStrucConsensus = false;
496 boolean updatingConservation = false;
499 * centre columnar annotation labels in displayed alignment annotation TODO:
500 * add to jalviewXML and annotation display settings
502 boolean centreColumnLabels = false;
504 private boolean showdbrefs;
506 private boolean shownpfeats;
509 * trigger update of conservation annotation
511 public void updateConservation(final AlignmentPanel ap)
513 // see note in mantis : issue number 8585
514 if (alignment.isNucleotide() || conservation == null
515 || !autoCalculateConsensus)
520 conservationThread = new ConservationThread(this, ap);
521 conservationThread.start();
525 * trigger update of consensus annotation
527 public void updateConsensus(final AlignmentPanel ap)
529 // see note in mantis : issue number 8585
530 if (consensus == null || !autoCalculateConsensus)
534 consensusThread = new ConsensusThread(ap);
535 consensusThread.start();
538 class ConsensusThread extends Thread
542 public ConsensusThread(AlignmentPanel ap)
549 updatingConsensus = true;
550 while (UPDATING_CONSENSUS)
556 ap.paintAlignment(false);
560 } catch (Exception ex)
562 ex.printStackTrace();
566 UPDATING_CONSENSUS = true;
570 int aWidth = (alignment != null) ? alignment.getWidth() : -1; // null
576 updatingConsensus = false;
577 UPDATING_CONSENSUS = false;
581 consensus.annotations = null;
582 consensus.annotations = new Annotation[aWidth];
584 hconsensus = new Hashtable[aWidth];
585 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
586 .getWidth(), hconsensus, true);
587 updateAnnotation(true);
588 if (globalColourScheme != null)
590 globalColourScheme.setConsensus(hconsensus);
593 } catch (OutOfMemoryError error)
595 alignment.deleteAnnotation(consensus);
599 new OOMWarning("calculating consensus", error);
601 UPDATING_CONSENSUS = false;
602 updatingConsensus = false;
606 ap.paintAlignment(true);
611 * update the consensus annotation from the sequence profile data using
612 * current visualization settings.
614 public void updateAnnotation()
616 updateAnnotation(false);
619 protected void updateAnnotation(boolean immediate)
621 // TODO: make calls thread-safe, so if another thread calls this method,
622 // it will either return or wait until one calculation is finished.
624 || (!updatingConsensus && consensus != null && hconsensus != null))
626 AAFrequency.completeConsensus(consensus, hconsensus, 0,
627 hconsensus.length, ignoreGapsInConsensusCalculation,
633 // --------START Structure Conservation
634 public void updateStrucConsensus(final AlignmentPanel ap)
636 // see note in mantis : issue number 8585
637 if (strucConsensus == null || !autoCalculateStrucConsensus)
641 strucConsensusThread = new StrucConsensusThread(ap);
642 strucConsensusThread.start();
645 class StrucConsensusThread extends Thread
649 public StrucConsensusThread(AlignmentPanel ap)
656 updatingStrucConsensus = true;
657 while (UPDATING_STRUC_CONSENSUS)
663 ap.paintAlignment(false);
667 } catch (Exception ex)
669 ex.printStackTrace();
673 UPDATING_STRUC_CONSENSUS = true;
677 int aWidth = (alignment != null) ? alignment.getWidth() : -1; // null
683 updatingStrucConsensus = false;
684 UPDATING_STRUC_CONSENSUS = false;
688 strucConsensus.annotations = null;
689 strucConsensus.annotations = new Annotation[aWidth];
691 hStrucConsensus = new Hashtable[aWidth];
693 AlignmentAnnotation[] aa = ap.av.getAlignment()
694 .getAlignmentAnnotation();
695 AlignmentAnnotation rnaStruc = null;
696 for (int i = 0; i < aa.length; i++)
698 if (aa[i].getRNAStruc() != null)
705 AlignmentAnnotation rna = ap.av.getAlignment()
706 .getAlignmentAnnotation()[0];
707 StructureFrequency.calculate(alignment.getSequencesArray(), 0,
708 alignment.getWidth(), hStrucConsensus, true, rnaStruc);
709 // TODO AlignmentAnnotation rnaStruc!!!
710 updateAnnotation(true);
711 if (globalColourScheme != null)
713 globalColourScheme.setConsensus(hStrucConsensus);
716 } catch (OutOfMemoryError error)
718 alignment.deleteAnnotation(strucConsensus);
720 strucConsensus = null;
721 hStrucConsensus = null;
722 new OOMWarning("calculating structure consensus", error);
724 UPDATING_STRUC_CONSENSUS = false;
725 updatingStrucConsensus = false;
729 ap.paintAlignment(true);
734 * update the consensus annotation from the sequence profile data using
735 * current visualization settings.
737 public void updateAnnotation()
739 updateAnnotation(false);
742 protected void updateAnnotation(boolean immediate)
744 // TODO: make calls thread-safe, so if another thread calls this method,
745 // it will either return or wait until one calculation is finished.
747 || (!updatingStrucConsensus && strucConsensus != null && hStrucConsensus != null))
749 StructureFrequency.completeConsensus(strucConsensus,
750 hStrucConsensus, 0, hStrucConsensus.length, false,
756 // --------END Structure Conservation
759 * get the consensus sequence as displayed under the PID consensus annotation
762 * @return consensus sequence as a new sequence object
764 public SequenceI getConsensusSeq()
766 if (consensus == null)
768 updateConsensus(null);
770 if (consensus == null)
774 StringBuffer seqs = new StringBuffer();
775 for (int i = 0; i < consensus.annotations.length; i++)
777 if (consensus.annotations[i] != null)
779 if (consensus.annotations[i].description.charAt(0) == '[')
781 seqs.append(consensus.annotations[i].description.charAt(1));
785 seqs.append(consensus.annotations[i].displayCharacter);
790 SequenceI sq = new Sequence("Consensus", seqs.toString());
791 sq.setDescription("Percentage Identity Consensus "
792 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
799 * @return null or the currently selected sequence region
801 public SequenceGroup getSelectionGroup()
803 return selectionGroup;
807 * Set the selection group for this window.
810 * - group holding references to sequences in this alignment view
813 public void setSelectionGroup(SequenceGroup sg)
821 * @return true if conservation based shading is enabled
823 public boolean getConservationSelected()
825 return conservationColourSelected;
832 * enable conservation based shading
834 public void setConservationSelected(boolean b)
836 conservationColourSelected = b;
842 * @return true if percent identity threshold is applied to shading
844 public boolean getAbovePIDThreshold()
846 return abovePIDThreshold;
854 * indicate if percent identity threshold is applied to shading
856 public void setAbovePIDThreshold(boolean b)
858 abovePIDThreshold = b;
864 * @return DOCUMENT ME!
866 public int getStartRes()
874 * @return DOCUMENT ME!
876 public int getEndRes()
884 * @return DOCUMENT ME!
886 public int getStartSeq()
897 public void setGlobalColourScheme(ColourSchemeI cs)
899 globalColourScheme = cs;
905 * @return DOCUMENT ME!
907 public ColourSchemeI getGlobalColourScheme()
909 return globalColourScheme;
918 public void setStartRes(int res)
929 public void setStartSeq(int seq)
940 public void setEndRes(int res)
942 if (res > (alignment.getWidth() - 1))
944 // log.System.out.println(" Corrected res from " + res + " to maximum " +
945 // (alignment.getWidth()-1));
946 res = alignment.getWidth() - 1;
963 public void setEndSeq(int seq)
965 if (seq > alignment.getHeight())
967 seq = alignment.getHeight();
981 * @return DOCUMENT ME!
983 public int getEndSeq()
994 public void setFont(Font f)
998 Container c = new Container();
1000 java.awt.FontMetrics fm = c.getFontMetrics(font);
1001 setCharHeight(fm.getHeight());
1002 setCharWidth(fm.charWidth('M'));
1003 validCharWidth = true;
1009 * @return DOCUMENT ME!
1011 public Font getFont()
1022 public void setCharWidth(int w)
1030 * @return DOCUMENT ME!
1032 public int getCharWidth()
1043 public void setCharHeight(int h)
1045 this.charHeight = h;
1051 * @return DOCUMENT ME!
1053 public int getCharHeight()
1064 public void setWrappedWidth(int w)
1066 this.wrappedWidth = w;
1072 * @return DOCUMENT ME!
1074 public int getWrappedWidth()
1076 return wrappedWidth;
1082 * @return DOCUMENT ME!
1084 public AlignmentI getAlignment()
1095 public void setAlignment(AlignmentI align)
1097 if (alignment != null && alignment.getCodonFrames() != null)
1099 StructureSelectionManager.getStructureSelectionManager(
1100 Desktop.instance).removeMappings(alignment.getCodonFrames());
1102 this.alignment = align;
1103 if (alignment.getCodonFrames() != null)
1105 StructureSelectionManager.getStructureSelectionManager(
1106 Desktop.instance).addMappings(alignment.getCodonFrames());
1116 public void setWrapAlignment(boolean state)
1118 wrapAlignment = state;
1127 public void setShowText(boolean state)
1138 public void setRenderGaps(boolean state)
1146 * @return DOCUMENT ME!
1148 public boolean getColourText()
1150 return showColourText;
1159 public void setColourText(boolean state)
1161 showColourText = state;
1170 public void setShowBoxes(boolean state)
1178 * @return DOCUMENT ME!
1180 public boolean getWrapAlignment()
1182 return wrapAlignment;
1188 * @return DOCUMENT ME!
1190 public boolean getShowText()
1198 * @return DOCUMENT ME!
1200 public boolean getShowBoxes()
1208 * @return DOCUMENT ME!
1210 public char getGapCharacter()
1212 return getAlignment().getGapCharacter();
1221 public void setGapCharacter(char gap)
1223 if (getAlignment() != null)
1225 getAlignment().setGapCharacter(gap);
1235 public void setThreshold(int thresh)
1243 * @return DOCUMENT ME!
1245 public int getThreshold()
1256 public void setIncrement(int inc)
1264 * @return DOCUMENT ME!
1266 public int getIncrement()
1274 * @return DOCUMENT ME!
1276 public ColumnSelection getColumnSelection()
1287 public void setCurrentTree(NJTree tree)
1295 * @return DOCUMENT ME!
1297 public NJTree getCurrentTree()
1308 public void setColourAppliesToAllGroups(boolean b)
1310 colourAppliesToAllGroups = b;
1316 * @return DOCUMENT ME!
1318 public boolean getColourAppliesToAllGroups()
1320 return colourAppliesToAllGroups;
1326 * @return DOCUMENT ME!
1328 public boolean getShowJVSuffix()
1330 return showJVSuffix;
1339 public void setShowJVSuffix(boolean b)
1347 * @return DOCUMENT ME!
1349 public boolean getShowAnnotation()
1351 return showAnnotation;
1360 public void setShowAnnotation(boolean b)
1368 * @return DOCUMENT ME!
1370 public boolean getScaleAboveWrapped()
1372 return scaleAboveWrapped;
1378 * @return DOCUMENT ME!
1380 public boolean getScaleLeftWrapped()
1382 return scaleLeftWrapped;
1388 * @return DOCUMENT ME!
1390 public boolean getScaleRightWrapped()
1392 return scaleRightWrapped;
1401 public void setScaleAboveWrapped(boolean b)
1403 scaleAboveWrapped = b;
1412 public void setScaleLeftWrapped(boolean b)
1414 scaleLeftWrapped = b;
1423 public void setScaleRightWrapped(boolean b)
1425 scaleRightWrapped = b;
1429 * Property change listener for changes in alignment
1434 public void addPropertyChangeListener(
1435 java.beans.PropertyChangeListener listener)
1437 changeSupport.addPropertyChangeListener(listener);
1446 public void removePropertyChangeListener(
1447 java.beans.PropertyChangeListener listener)
1449 changeSupport.removePropertyChangeListener(listener);
1453 * Property change listener for changes in alignment
1462 public void firePropertyChange(String prop, Object oldvalue,
1465 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1468 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1470 ignoreGapsInConsensusCalculation = b;
1471 updateConsensus(ap);
1472 if (globalColourScheme != null)
1474 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1475 ignoreGapsInConsensusCalculation);
1479 public boolean getIgnoreGapsConsensus()
1481 return ignoreGapsInConsensusCalculation;
1484 public void setDataset(boolean b)
1489 public boolean isDataset()
1494 public void hideSelectedColumns()
1496 if (colSel.size() < 1)
1501 colSel.hideSelectedColumns();
1502 setSelectionGroup(null);
1504 hasHiddenColumns = true;
1507 public void hideColumns(int start, int end)
1511 colSel.hideColumns(start);
1515 colSel.hideColumns(start, end);
1518 hasHiddenColumns = true;
1521 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1523 int sSize = sg.getSize();
1529 if (hiddenRepSequences == null)
1531 hiddenRepSequences = new Hashtable();
1534 hiddenRepSequences.put(repSequence, sg);
1536 // Hide all sequences except the repSequence
1537 SequenceI[] seqs = new SequenceI[sSize - 1];
1539 for (int i = 0; i < sSize; i++)
1541 if (sg.getSequenceAt(i) != repSequence)
1543 if (index == sSize - 1)
1548 seqs[index++] = sg.getSequenceAt(i);
1551 sg.setSeqrep(repSequence);
1552 sg.setHidereps(true);
1557 public void hideAllSelectedSeqs()
1559 if (selectionGroup == null || selectionGroup.getSize() < 1)
1564 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1568 setSelectionGroup(null);
1571 public void hideSequence(SequenceI[] seq)
1575 for (int i = 0; i < seq.length; i++)
1577 alignment.getHiddenSequences().hideSequence(seq[i]);
1579 hasHiddenRows = true;
1580 firePropertyChange("alignment", null, alignment.getSequences());
1584 public void showSequence(int index)
1586 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1587 hiddenRepSequences);
1590 if (selectionGroup == null)
1592 selectionGroup = new SequenceGroup();
1593 selectionGroup.setEndRes(alignment.getWidth() - 1);
1596 for (int t = 0; t < tmp.size(); t++)
1598 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1600 firePropertyChange("alignment", null, alignment.getSequences());
1604 if (alignment.getHiddenSequences().getSize() < 1)
1606 hasHiddenRows = false;
1610 public void showColumn(int col)
1612 colSel.revealHiddenColumns(col);
1613 if (colSel.getHiddenColumns() == null)
1615 hasHiddenColumns = false;
1619 public void showAllHiddenColumns()
1621 colSel.revealAllHiddenColumns();
1622 hasHiddenColumns = false;
1625 public void showAllHiddenSeqs()
1627 if (alignment.getHiddenSequences().getSize() > 0)
1629 if (selectionGroup == null)
1631 selectionGroup = new SequenceGroup();
1632 selectionGroup.setEndRes(alignment.getWidth() - 1);
1634 Vector tmp = alignment.getHiddenSequences().showAll(
1635 hiddenRepSequences);
1636 for (int t = 0; t < tmp.size(); t++)
1638 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1640 firePropertyChange("alignment", null, alignment.getSequences());
1642 hasHiddenRows = false;
1643 hiddenRepSequences = null;
1647 public void invertColumnSelection()
1649 colSel.invertColumnSelection(0, alignment.getWidth());
1652 public int adjustForHiddenSeqs(int alignmentIndex)
1654 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1659 * This method returns an array of new SequenceI objects derived from the
1660 * whole alignment or just the current selection with start and end points
1663 * @note if you need references to the actual SequenceI objects in the
1664 * alignment or currently selected then use getSequenceSelection()
1665 * @return selection as new sequenceI objects
1667 public SequenceI[] getSelectionAsNewSequence()
1669 SequenceI[] sequences;
1671 if (selectionGroup == null)
1673 sequences = alignment.getSequencesArray();
1674 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1675 for (int i = 0; i < sequences.length; i++)
1677 sequences[i] = new Sequence(sequences[i], annots); // construct new
1679 // subset of visible
1685 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1692 * get the currently selected sequence objects or all the sequences in the
1695 * @return array of references to sequence objects
1697 public SequenceI[] getSequenceSelection()
1699 SequenceI[] sequences = null;
1700 if (selectionGroup != null)
1702 sequences = selectionGroup.getSequencesInOrder(alignment);
1704 if (sequences == null)
1706 sequences = alignment.getSequencesArray();
1712 * This method returns the visible alignment as text, as seen on the GUI, ie
1713 * if columns are hidden they will not be returned in the result. Use this for
1714 * calculating trees, PCA, redundancy etc on views which contain hidden
1719 public jalview.datamodel.CigarArray getViewAsCigars(
1720 boolean selectedRegionOnly)
1722 return new jalview.datamodel.CigarArray(alignment,
1723 (hasHiddenColumns ? colSel : null),
1724 (selectedRegionOnly ? selectionGroup : null));
1728 * return a compact representation of the current alignment selection to pass
1729 * to an analysis function
1731 * @param selectedOnly
1732 * boolean true to just return the selected view
1733 * @return AlignmentView
1735 public jalview.datamodel.AlignmentView getAlignmentView(
1736 boolean selectedOnly)
1738 return getAlignmentView(selectedOnly, false);
1742 * return a compact representation of the current alignment selection to pass
1743 * to an analysis function
1745 * @param selectedOnly
1746 * boolean true to just return the selected view
1748 * boolean true to annotate the alignment view with groups on the
1749 * alignment (and intersecting with selected region if selectedOnly
1751 * @return AlignmentView
1753 public jalview.datamodel.AlignmentView getAlignmentView(
1754 boolean selectedOnly, boolean markGroups)
1756 return new AlignmentView(alignment, colSel, selectionGroup,
1757 hasHiddenColumns, selectedOnly, markGroups);
1761 * This method returns the visible alignment as text, as seen on the GUI, ie
1762 * if columns are hidden they will not be returned in the result. Use this for
1763 * calculating trees, PCA, redundancy etc on views which contain hidden
1768 public String[] getViewAsString(boolean selectedRegionOnly)
1770 String[] selection = null;
1771 SequenceI[] seqs = null;
1773 int start = 0, end = 0;
1774 if (selectedRegionOnly && selectionGroup != null)
1776 iSize = selectionGroup.getSize();
1777 seqs = selectionGroup.getSequencesInOrder(alignment);
1778 start = selectionGroup.getStartRes();
1779 end = selectionGroup.getEndRes() + 1;
1783 iSize = alignment.getHeight();
1784 seqs = alignment.getSequencesArray();
1785 end = alignment.getWidth();
1788 selection = new String[iSize];
1789 if (hasHiddenColumns)
1791 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1795 for (i = 0; i < iSize; i++)
1797 selection[i] = seqs[i].getSequenceAsString(start, end);
1804 public int[][] getVisibleRegionBoundaries(int min, int max)
1806 Vector regions = new Vector();
1812 if (hasHiddenColumns)
1816 start = colSel.adjustForHiddenColumns(start);
1819 end = colSel.getHiddenBoundaryRight(start);
1830 regions.addElement(new int[]
1833 if (hasHiddenColumns)
1835 start = colSel.adjustForHiddenColumns(end);
1836 start = colSel.getHiddenBoundaryLeft(start) + 1;
1838 } while (end < max);
1840 int[][] startEnd = new int[regions.size()][2];
1842 regions.copyInto(startEnd);
1848 public boolean getShowHiddenMarkers()
1850 return showHiddenMarkers;
1853 public void setShowHiddenMarkers(boolean show)
1855 showHiddenMarkers = show;
1858 public String getSequenceSetId()
1860 if (sequenceSetID == null)
1862 sequenceSetID = alignment.hashCode() + "";
1865 return sequenceSetID;
1869 * unique viewId for synchronizing state with stored Jalview Project
1872 private String viewId = null;
1874 public String getViewId()
1878 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1883 public void alignmentChanged(AlignmentPanel ap)
1887 alignment.padGaps();
1889 if (hconsensus != null && autoCalculateConsensus)
1891 updateConservation(ap);
1893 if (autoCalculateConsensus)
1895 updateConsensus(ap);
1897 if (autoCalculateStrucConsensus)
1899 updateStrucConsensus(ap);
1902 // Reset endRes of groups if beyond alignment width
1903 int alWidth = alignment.getWidth();
1904 Vector groups = alignment.getGroups();
1907 for (int i = 0; i < groups.size(); i++)
1909 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1910 if (sg.getEndRes() > alWidth)
1912 sg.setEndRes(alWidth - 1);
1917 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1919 selectionGroup.setEndRes(alWidth - 1);
1922 resetAllColourSchemes();
1924 // alignment.adjustSequenceAnnotations();
1927 void resetAllColourSchemes()
1929 ColourSchemeI cs = globalColourScheme;
1932 if (cs instanceof ClustalxColourScheme)
1934 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1935 alignment.getWidth());
1938 cs.setConsensus(hconsensus);
1939 if (cs.conservationApplied())
1941 Alignment al = (Alignment) alignment;
1942 Conservation c = new Conservation("All",
1943 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1946 c.verdict(false, ConsPercGaps);
1948 cs.setConservation(c);
1952 int s, sSize = alignment.getGroups().size();
1953 for (s = 0; s < sSize; s++)
1955 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1956 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1958 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1959 .getSequences(hiddenRepSequences), sg.getWidth());
1961 sg.recalcConservation();
1965 public Color getSequenceColour(SequenceI seq)
1967 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1973 return (Color) sequenceColours.get(seq);
1977 public void setSequenceColour(SequenceI seq, Color col)
1979 if (sequenceColours == null)
1981 sequenceColours = new Hashtable();
1986 sequenceColours.remove(seq);
1990 sequenceColours.put(seq, col);
1995 * returns the visible column regions of the alignment
1997 * @param selectedRegionOnly
1998 * true to just return the contigs intersecting with the selected
2002 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
2004 int[] viscontigs = null;
2005 int start = 0, end = 0;
2006 if (selectedRegionOnly && selectionGroup != null)
2008 start = selectionGroup.getStartRes();
2009 end = selectionGroup.getEndRes() + 1;
2013 end = alignment.getWidth();
2015 viscontigs = colSel.getVisibleContigs(start, end);
2020 * get hash of undo and redo list for the alignment
2022 * @return long[] { historyList.hashCode, redoList.hashCode };
2024 public long[] getUndoRedoHash()
2026 if (historyList == null || redoList == null)
2030 { historyList.hashCode(), this.redoList.hashCode() };
2034 * test if a particular set of hashcodes are different to the hashcodes for
2035 * the undo and redo list.
2038 * the stored set of hashcodes as returned by getUndoRedoHash
2039 * @return true if the hashcodes differ (ie the alignment has been edited) or
2040 * the stored hashcode array differs in size
2042 public boolean isUndoRedoHashModified(long[] undoredo)
2044 if (undoredo == null)
2048 long[] cstate = getUndoRedoHash();
2049 if (cstate.length != undoredo.length)
2054 for (int i = 0; i < cstate.length; i++)
2056 if (cstate[i] != undoredo[i])
2064 public boolean getCentreColumnLabels()
2066 return centreColumnLabels;
2069 public void setCentreColumnLabels(boolean centrecolumnlabels)
2071 centreColumnLabels = centrecolumnlabels;
2074 public void updateSequenceIdColours()
2076 Vector groups = alignment.getGroups();
2077 if (sequenceColours == null)
2079 sequenceColours = new Hashtable();
2081 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
2083 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
2084 if (sg.idColour != null)
2086 Vector sqs = sg.getSequences(hiddenRepSequences);
2087 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2089 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2096 * enable or disable the display of Database Cross References in the sequence
2099 public void setShowDbRefs(boolean show)
2106 * @return true if Database References are to be displayed on tooltips.
2108 public boolean isShowDbRefs()
2115 * @return true if Non-positional features are to be displayed on tooltips.
2117 public boolean isShowNpFeats()
2123 * enable or disable the display of Non-Positional sequence features in the
2124 * sequence ID tooltip
2128 public void setShowNpFeats(boolean show)
2135 * @return true if view has hidden rows
2137 public boolean hasHiddenRows()
2139 return hasHiddenRows;
2144 * @return true if view has hidden columns
2146 public boolean hasHiddenColumns()
2148 return hasHiddenColumns;
2152 * when set, view will scroll to show the highlighted position
2154 public boolean followHighlight = true;
2157 * @return true if view should scroll to show the highlighted region of a
2161 public boolean getFollowHighlight()
2163 return followHighlight;
2166 public boolean followSelection = true;
2169 * @return true if view selection should always follow the selections
2170 * broadcast by other selection sources
2172 public boolean getFollowSelection()
2174 return followSelection;
2177 private long sgrouphash = -1, colselhash = -1;
2179 boolean showSeqFeaturesHeight;
2182 * checks current SelectionGroup against record of last hash value, and
2186 * update the record of last hash value
2188 * @return true if SelectionGroup changed since last call (when b is true)
2190 boolean isSelectionGroupChanged(boolean b)
2192 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
2193 : selectionGroup.hashCode();
2194 if (hc != -1 && hc != sgrouphash)
2206 * checks current colsel against record of last hash value, and optionally
2210 * update the record of last hash value
2211 * @return true if colsel changed since last call (when b is true)
2213 boolean isColSelChanged(boolean b)
2215 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
2217 if (hc != -1 && hc != colselhash)
2228 public void sendSelection()
2230 jalview.structure.StructureSelectionManager
2231 .getStructureSelectionManager(Desktop.instance).sendSelection(
2232 new SequenceGroup(getSelectionGroup()),
2233 new ColumnSelection(getColumnSelection()), this);
2236 public void setShowSequenceFeaturesHeight(boolean selected)
2238 showSeqFeaturesHeight = selected;
2241 public boolean getShowSequenceFeaturesHeight()
2243 return showSeqFeaturesHeight;
2246 boolean showUnconserved = false;
2248 public boolean getShowUnconserved()
2250 return showUnconserved;
2253 public void setShowUnconserved(boolean showunconserved)
2255 showUnconserved = showunconserved;
2259 * return the alignPanel containing the given viewport. Use this to get the
2260 * components currently handling the given viewport.
2263 * @return null or an alignPanel guaranteed to have non-null alignFrame
2266 public AlignmentPanel getAlignPanel()
2268 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2269 .getSequenceSetId());
2270 AlignmentPanel ap = null;
2271 for (int p = 0; aps != null && p < aps.length; p++)
2273 if (aps[p].av == this)
2281 public boolean getSortByTree()
2286 public void setSortByTree(boolean sort)
2292 * should conservation rows be shown for groups
2294 boolean showGroupConservation = false;
2297 * should consensus rows be shown for groups
2299 boolean showGroupConsensus = false;
2302 * should consensus profile be rendered by default
2304 public boolean showSequenceLogo = false;
2307 * should consensus histograms be rendered by default
2309 public boolean showConsensusHistogram = true;
2312 * @return the showConsensusProfile
2314 public boolean isShowSequenceLogo()
2316 return showSequenceLogo;
2320 * @param showSequenceLogo
2323 public void setShowSequenceLogo(boolean showSequenceLogo)
2325 if (showSequenceLogo != this.showSequenceLogo)
2327 // TODO: decouple settings setting from calculation when refactoring
2328 // annotation update method from alignframe to viewport
2329 this.showSequenceLogo = showSequenceLogo;
2330 if (consensusThread != null)
2332 consensusThread.updateAnnotation();
2334 if (strucConsensusThread != null)
2336 strucConsensusThread.updateAnnotation();
2339 this.showSequenceLogo = showSequenceLogo;
2343 * @param showConsensusHistogram
2344 * the showConsensusHistogram to set
2346 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2348 this.showConsensusHistogram = showConsensusHistogram;
2352 * @return the showGroupConservation
2354 public boolean isShowGroupConservation()
2356 return showGroupConservation;
2360 * @param showGroupConservation
2361 * the showGroupConservation to set
2363 public void setShowGroupConservation(boolean showGroupConservation)
2365 this.showGroupConservation = showGroupConservation;
2369 * @return the showGroupConsensus
2371 public boolean isShowGroupConsensus()
2373 return showGroupConsensus;
2377 * @param showGroupConsensus
2378 * the showGroupConsensus to set
2380 public void setShowGroupConsensus(boolean showGroupConsensus)
2382 this.showGroupConsensus = showGroupConsensus;
2387 * @return flag to indicate if the consensus histogram should be rendered by
2390 public boolean isShowConsensusHistogram()
2392 return this.showConsensusHistogram;
2396 * synthesize a column selection if none exists so it covers the given
2397 * selection group. if wholewidth is false, no column selection is made if the
2398 * selection group covers the whole alignment width.
2403 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2407 && (sgs = sg.getStartRes()) >= 0
2408 && sg.getStartRes() <= (sge = sg.getEndRes())
2409 && (colSel == null || colSel.getSelected() == null || colSel
2410 .getSelected().size() == 0))
2412 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2419 colSel = new ColumnSelection();
2421 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2423 colSel.addElement(cspos);
2428 public StructureSelectionManager getStructureSelectionManager()
2430 return StructureSelectionManager
2431 .getStructureSelectionManager(Desktop.instance);
2437 * @return a series of SequenceI arrays, one for each PDBEntry, listing which
2438 * sequence in the alignment holds a reference to it
2440 public SequenceI[][] collateForPDB(PDBEntry[] pdbEntries)
2442 ArrayList<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
2443 for (PDBEntry pdb : pdbEntries)
2445 ArrayList<SequenceI> seqs = new ArrayList<SequenceI>();
2446 for (int i = 0; i < alignment.getHeight(); i++)
2448 Vector pdbs = alignment.getSequenceAt(i).getDatasetSequence()
2453 for (int p = 0; p < pdbs.size(); p++)
2455 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
2456 if (p1.getId().equals(pdb.getId()))
2458 if (!seqs.contains(sq = alignment.getSequenceAt(i)))
2465 seqvectors.add(seqs.toArray(new SequenceI[seqs.size()]));
2467 return seqvectors.toArray(new SequenceI[seqvectors.size()][]);