2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 * Jalview - A Sequence Alignment Editor and Viewer
21 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * as published by the Free Software Foundation; either version 2
26 * of the License, or (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
43 import jalview.analysis.*;
47 import jalview.datamodel.*;
49 import jalview.schemes.*;
50 import jalview.structure.SelectionSource;
51 import jalview.structure.StructureSelectionManager;
59 public class AlignViewport implements SelectionSource
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;
133 // The following vector holds the features which are
134 // currently visible, in the correct order or rendering
135 Hashtable featuresDisplayed = null;
138 public Hashtable[] hconsensus;
140 AlignmentAnnotation consensus;
142 AlignmentAnnotation conservation;
144 AlignmentAnnotation quality;
145 AlignmentAnnotation[] groupConsensus;
146 AlignmentAnnotation[] groupConservation;
148 boolean autoCalculateConsensus = true;
151 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
153 // JBPNote Prolly only need this in the applet version.
154 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
157 boolean ignoreGapsInConsensusCalculation = false;
159 boolean isDataset = false;
161 boolean antiAlias = false;
163 boolean padGaps = false;
165 Rectangle explodedPosition;
169 String sequenceSetID;
171 boolean gatherViewsHere = false;
173 Stack historyList = new Stack();
175 Stack redoList = new Stack();
177 Hashtable sequenceColours;
179 int thresholdTextColour = 0;
181 Color textColour = Color.black;
183 Color textColour2 = Color.white;
185 boolean rightAlignIds = false;
187 Hashtable hiddenRepSequences;
192 * Creates a new AlignViewport object.
194 * @param al alignment to view
196 public AlignViewport(AlignmentI al)
202 * Create a new AlignViewport object with a specific sequence set ID
204 * @param seqsetid (may be null - but potential for ambiguous constructor exception)
206 public AlignViewport(AlignmentI al, String seqsetid)
208 this(al,seqsetid,null);
210 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
212 sequenceSetID = seqsetid;
214 // TODO remove these once 2.4.VAMSAS release finished
215 if (Cache.log!=null && Cache.log.isDebugEnabled() && seqsetid!=null) { Cache.log.debug("Setting viewport's sequence set id : "+sequenceSetID); }
216 if (Cache.log!=null && Cache.log.isDebugEnabled() && viewId!=null) { Cache.log.debug("Setting viewport's view id : "+viewId); }
222 * Create a new AlignViewport with hidden regions
226 * @param hiddenColumns
229 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
232 if (hiddenColumns != null)
234 this.colSel = hiddenColumns;
235 if (hiddenColumns.getHiddenColumns() != null && hiddenColumns.getHiddenColumns().size()>0)
237 hasHiddenColumns = true;
239 hasHiddenColumns = false;
245 * New viewport with hidden columns and an existing sequence set id
247 * @param hiddenColumns
248 * @param seqsetid (may be null)
250 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, String seqsetid)
252 this(al,hiddenColumns,seqsetid,null);
255 * New viewport with hidden columns and an existing sequence set id and viewid
257 * @param hiddenColumns
258 * @param seqsetid (may be null)
259 * @param viewid (may be null)
261 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, String seqsetid, String viewid)
263 sequenceSetID = seqsetid;
265 // TODO remove these once 2.4.VAMSAS release finished
266 if (Cache.log!=null && Cache.log.isDebugEnabled() && seqsetid!=null) { Cache.log.debug("Setting viewport's sequence set id : "+sequenceSetID); }
267 if (Cache.log!=null && Cache.log.isDebugEnabled() && viewId!=null) { Cache.log.debug("Setting viewport's view id : "+viewId); }
269 if (hiddenColumns != null)
271 this.colSel = hiddenColumns;
272 if (hiddenColumns.getHiddenColumns() != null && hiddenColumns.getHiddenColumns().size()>0)
274 hasHiddenColumns = true;
276 hasHiddenColumns = false;
285 this.endRes = alignment.getWidth() - 1;
287 this.endSeq = alignment.getHeight() - 1;
289 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
291 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
292 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
294 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
295 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
296 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
298 padGaps = Cache.getDefault("PAD_GAPS", true);
299 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP",true);
300 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP",true);
302 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
303 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
304 String fontSize = Cache.getDefault("FONT_SIZE", "10");
306 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
310 if (fontStyle.equals("bold"))
314 else if (fontStyle.equals("italic"))
319 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
322 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
324 // We must set conservation and consensus before setting colour,
325 // as Blosum and Clustal require this to be done
326 if (hconsensus == null && !isDataset)
328 if (!alignment.isNucleotide())
330 conservation = new AlignmentAnnotation("Conservation",
331 "Conservation of total alignment less than " + ConsPercGaps
332 + "% gaps", new Annotation[1], 0f, 11f,
333 AlignmentAnnotation.BAR_GRAPH);
334 conservation.hasText = true;
335 conservation.autoCalculated = true;
337 if (Cache.getDefault("SHOW_CONSERVATION", true))
339 alignment.addAnnotation(conservation);
342 if (Cache.getDefault("SHOW_QUALITY", true))
344 quality = new AlignmentAnnotation("Quality",
345 "Alignment Quality based on Blosum62 scores",
346 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
347 quality.hasText = true;
348 quality.autoCalculated = true;
350 alignment.addAnnotation(quality);
352 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION", false);
358 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true);
359 showConsensusProfile = Cache.getDefault("SHOW_CONSENSUS_PROFILE", false);
360 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
361 // TODO: add menu option action that nulls or creates consensus object depending on if the user wants to see the annotation or not in a specific alignment
362 consensus = new AlignmentAnnotation("Consensus", "PID",
363 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
364 consensus.hasText = true;
365 consensus.autoCalculated = true;
367 if (Cache.getDefault("SHOW_IDENTITY", true))
369 alignment.addAnnotation(consensus);
373 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
375 globalColourScheme = ColourSchemeProperty.getColour(alignment,
376 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
378 if (globalColourScheme instanceof UserColourScheme)
380 globalColourScheme = UserDefinedColours.loadDefaultColours();
381 ((UserColourScheme) globalColourScheme).setThreshold(0,
382 getIgnoreGapsConsensus());
385 if (globalColourScheme != null)
387 globalColourScheme.setConsensus(hconsensus);
391 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
392 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED", false);
393 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
400 * features are displayed if true
402 public void setShowSequenceFeatures(boolean b)
404 showSequenceFeatures = b;
407 public boolean getShowSequenceFeatures()
409 return showSequenceFeatures;
412 ConservationThread conservationThread;
414 ConsensusThread consensusThread;
416 boolean consUpdateNeeded = false;
418 static boolean UPDATING_CONSENSUS = false;
420 static boolean UPDATING_CONSERVATION = false;
422 boolean updatingConsensus = false;
424 boolean updatingConservation = false;
427 * centre columnar annotation labels in displayed alignment annotation TODO:
428 * add to jalviewXML and annotation display settings
430 boolean centreColumnLabels = false;
432 private boolean showdbrefs;
434 private boolean shownpfeats;
437 * consensus annotation includes all percentage for all symbols in column
439 private boolean includeAllConsensusSymbols=true;
442 * trigger update of conservation annotation
444 public void updateConservation(final AlignmentPanel ap)
446 // see note in mantis : issue number 8585
447 if (alignment.isNucleotide() || conservation == null || !autoCalculateConsensus)
452 conservationThread = new ConservationThread(this, ap);
453 conservationThread.start();
457 * trigger update of consensus annotation
459 public void updateConsensus(final AlignmentPanel ap)
461 // see note in mantis : issue number 8585
462 if (consensus == null || !autoCalculateConsensus)
466 consensusThread = new ConsensusThread(ap);
467 consensusThread.start();
470 class ConsensusThread extends Thread
474 public ConsensusThread(AlignmentPanel ap)
481 updatingConsensus = true;
482 while (UPDATING_CONSENSUS)
488 ap.paintAlignment(false);
492 } catch (Exception ex)
494 ex.printStackTrace();
498 UPDATING_CONSENSUS = true;
502 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
511 consensus.annotations = null;
512 consensus.annotations = new Annotation[aWidth];
514 hconsensus = new Hashtable[aWidth];
515 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
516 .getWidth(), hconsensus, includeAllConsensusSymbols);
517 AAFrequency.completeConsensus(consensus,hconsensus,0,aWidth,ignoreGapsInConsensusCalculation, includeAllConsensusSymbols);
519 if (globalColourScheme != null)
521 globalColourScheme.setConsensus(hconsensus);
524 } catch (OutOfMemoryError error)
526 alignment.deleteAnnotation(consensus);
530 new OOMWarning("calculating consensus", error);
532 UPDATING_CONSENSUS = false;
533 updatingConsensus = false;
537 ap.paintAlignment(true);
543 * get the consensus sequence as displayed under the PID consensus annotation
546 * @return consensus sequence as a new sequence object
548 public SequenceI getConsensusSeq()
550 if (consensus == null)
552 updateConsensus(null);
554 if (consensus == null)
558 StringBuffer seqs = new StringBuffer();
559 for (int i = 0; i < consensus.annotations.length; i++)
561 if (consensus.annotations[i] != null)
563 if (consensus.annotations[i].description.charAt(0) == '[')
565 seqs.append(consensus.annotations[i].description.charAt(1));
569 seqs.append(consensus.annotations[i].displayCharacter);
574 SequenceI sq = new Sequence("Consensus", seqs.toString());
575 sq.setDescription("Percentage Identity Consensus "
576 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
583 * @return DOCUMENT ME!
585 public SequenceGroup getSelectionGroup()
587 return selectionGroup;
596 public void setSelectionGroup(SequenceGroup sg)
604 * @return DOCUMENT ME!
606 public boolean getConservationSelected()
608 return conservationColourSelected;
617 public void setConservationSelected(boolean b)
619 conservationColourSelected = b;
625 * @return DOCUMENT ME!
627 public boolean getAbovePIDThreshold()
629 return abovePIDThreshold;
638 public void setAbovePIDThreshold(boolean b)
640 abovePIDThreshold = b;
646 * @return DOCUMENT ME!
648 public int getStartRes()
656 * @return DOCUMENT ME!
658 public int getEndRes()
666 * @return DOCUMENT ME!
668 public int getStartSeq()
679 public void setGlobalColourScheme(ColourSchemeI cs)
681 globalColourScheme = cs;
687 * @return DOCUMENT ME!
689 public ColourSchemeI getGlobalColourScheme()
691 return globalColourScheme;
700 public void setStartRes(int res)
711 public void setStartSeq(int seq)
722 public void setEndRes(int res)
724 if (res > (alignment.getWidth() - 1))
726 // log.System.out.println(" Corrected res from " + res + " to maximum " +
727 // (alignment.getWidth()-1));
728 res = alignment.getWidth() - 1;
745 public void setEndSeq(int seq)
747 if (seq > alignment.getHeight())
749 seq = alignment.getHeight();
763 * @return DOCUMENT ME!
765 public int getEndSeq()
776 public void setFont(Font f)
780 Container c = new Container();
782 java.awt.FontMetrics fm = c.getFontMetrics(font);
783 setCharHeight(fm.getHeight());
784 setCharWidth(fm.charWidth('M'));
785 validCharWidth = true;
791 * @return DOCUMENT ME!
793 public Font getFont()
804 public void setCharWidth(int w)
812 * @return DOCUMENT ME!
814 public int getCharWidth()
825 public void setCharHeight(int h)
833 * @return DOCUMENT ME!
835 public int getCharHeight()
846 public void setWrappedWidth(int w)
848 this.wrappedWidth = w;
854 * @return DOCUMENT ME!
856 public int getWrappedWidth()
864 * @return DOCUMENT ME!
866 public AlignmentI getAlignment()
877 public void setAlignment(AlignmentI align)
879 if (alignment != null && alignment.getCodonFrames() != null)
881 StructureSelectionManager.getStructureSelectionManager()
882 .removeMappings(alignment.getCodonFrames());
884 this.alignment = align;
885 if (alignment.getCodonFrames() != null)
887 StructureSelectionManager.getStructureSelectionManager().addMappings(
888 alignment.getCodonFrames());
898 public void setWrapAlignment(boolean state)
900 wrapAlignment = state;
909 public void setShowText(boolean state)
920 public void setRenderGaps(boolean state)
928 * @return DOCUMENT ME!
930 public boolean getColourText()
932 return showColourText;
941 public void setColourText(boolean state)
943 showColourText = state;
952 public void setShowBoxes(boolean state)
960 * @return DOCUMENT ME!
962 public boolean getWrapAlignment()
964 return wrapAlignment;
970 * @return DOCUMENT ME!
972 public boolean getShowText()
980 * @return DOCUMENT ME!
982 public boolean getShowBoxes()
990 * @return DOCUMENT ME!
992 public char getGapCharacter()
994 return getAlignment().getGapCharacter();
1003 public void setGapCharacter(char gap)
1005 if (getAlignment() != null)
1007 getAlignment().setGapCharacter(gap);
1017 public void setThreshold(int thresh)
1025 * @return DOCUMENT ME!
1027 public int getThreshold()
1038 public void setIncrement(int inc)
1046 * @return DOCUMENT ME!
1048 public int getIncrement()
1056 * @return DOCUMENT ME!
1058 public ColumnSelection getColumnSelection()
1069 public void setCurrentTree(NJTree tree)
1077 * @return DOCUMENT ME!
1079 public NJTree getCurrentTree()
1090 public void setColourAppliesToAllGroups(boolean b)
1092 colourAppliesToAllGroups = b;
1098 * @return DOCUMENT ME!
1100 public boolean getColourAppliesToAllGroups()
1102 return colourAppliesToAllGroups;
1108 * @return DOCUMENT ME!
1110 public boolean getShowJVSuffix()
1112 return showJVSuffix;
1121 public void setShowJVSuffix(boolean b)
1129 * @return DOCUMENT ME!
1131 public boolean getShowAnnotation()
1133 return showAnnotation;
1142 public void setShowAnnotation(boolean b)
1150 * @return DOCUMENT ME!
1152 public boolean getScaleAboveWrapped()
1154 return scaleAboveWrapped;
1160 * @return DOCUMENT ME!
1162 public boolean getScaleLeftWrapped()
1164 return scaleLeftWrapped;
1170 * @return DOCUMENT ME!
1172 public boolean getScaleRightWrapped()
1174 return scaleRightWrapped;
1183 public void setScaleAboveWrapped(boolean b)
1185 scaleAboveWrapped = b;
1194 public void setScaleLeftWrapped(boolean b)
1196 scaleLeftWrapped = b;
1205 public void setScaleRightWrapped(boolean b)
1207 scaleRightWrapped = b;
1211 * Property change listener for changes in alignment
1216 public void addPropertyChangeListener(
1217 java.beans.PropertyChangeListener listener)
1219 changeSupport.addPropertyChangeListener(listener);
1228 public void removePropertyChangeListener(
1229 java.beans.PropertyChangeListener listener)
1231 changeSupport.removePropertyChangeListener(listener);
1235 * Property change listener for changes in alignment
1244 public void firePropertyChange(String prop, Object oldvalue,
1247 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1250 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1252 ignoreGapsInConsensusCalculation = b;
1253 updateConsensus(ap);
1254 if (globalColourScheme != null)
1256 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1257 ignoreGapsInConsensusCalculation);
1261 public boolean getIgnoreGapsConsensus()
1263 return ignoreGapsInConsensusCalculation;
1266 public void setDataset(boolean b)
1271 public boolean isDataset()
1276 public void hideSelectedColumns()
1278 if (colSel.size() < 1)
1283 colSel.hideSelectedColumns();
1284 setSelectionGroup(null);
1286 hasHiddenColumns = true;
1289 public void hideColumns(int start, int end)
1293 colSel.hideColumns(start);
1297 colSel.hideColumns(start, end);
1300 hasHiddenColumns = true;
1303 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1305 int sSize = sg.getSize();
1311 if (hiddenRepSequences == null)
1313 hiddenRepSequences = new Hashtable();
1316 hiddenRepSequences.put(repSequence, sg);
1318 // Hide all sequences except the repSequence
1319 SequenceI[] seqs = new SequenceI[sSize - 1];
1321 for (int i = 0; i < sSize; i++)
1323 if (sg.getSequenceAt(i) != repSequence)
1325 if (index == sSize - 1)
1330 seqs[index++] = sg.getSequenceAt(i);
1333 sg.setSeqrep(repSequence);
1334 sg.setHidereps(true);
1339 public void hideAllSelectedSeqs()
1341 if (selectionGroup == null || selectionGroup.getSize() < 1)
1346 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1350 setSelectionGroup(null);
1353 public void hideSequence(SequenceI[] seq)
1357 for (int i = 0; i < seq.length; i++)
1359 alignment.getHiddenSequences().hideSequence(seq[i]);
1361 hasHiddenRows = true;
1362 firePropertyChange("alignment", null, alignment.getSequences());
1366 public void showSequence(int index)
1368 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1369 hiddenRepSequences);
1372 if (selectionGroup == null)
1374 selectionGroup = new SequenceGroup();
1375 selectionGroup.setEndRes(alignment.getWidth() - 1);
1378 for (int t = 0; t < tmp.size(); t++)
1380 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1382 firePropertyChange("alignment", null, alignment.getSequences());
1386 if (alignment.getHiddenSequences().getSize() < 1)
1388 hasHiddenRows = false;
1392 public void showColumn(int col)
1394 colSel.revealHiddenColumns(col);
1395 if (colSel.getHiddenColumns() == null)
1397 hasHiddenColumns = false;
1401 public void showAllHiddenColumns()
1403 colSel.revealAllHiddenColumns();
1404 hasHiddenColumns = false;
1407 public void showAllHiddenSeqs()
1409 if (alignment.getHiddenSequences().getSize() > 0)
1411 if (selectionGroup == null)
1413 selectionGroup = new SequenceGroup();
1414 selectionGroup.setEndRes(alignment.getWidth() - 1);
1416 Vector tmp = alignment.getHiddenSequences().showAll(
1417 hiddenRepSequences);
1418 for (int t = 0; t < tmp.size(); t++)
1420 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1422 firePropertyChange("alignment", null, alignment.getSequences());
1424 hasHiddenRows = false;
1425 hiddenRepSequences = null;
1429 public void invertColumnSelection()
1431 colSel.invertColumnSelection(0, alignment.getWidth());
1434 public int adjustForHiddenSeqs(int alignmentIndex)
1436 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1441 * This method returns an array of new SequenceI objects derived from the
1442 * whole alignment or just the current selection with start and end points
1445 * @note if you need references to the actual SequenceI objects in the
1446 * alignment or currently selected then use getSequenceSelection()
1447 * @return selection as new sequenceI objects
1449 public SequenceI[] getSelectionAsNewSequence()
1451 SequenceI[] sequences;
1453 if (selectionGroup == null)
1455 sequences = alignment.getSequencesArray();
1456 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1457 for (int i = 0; i < sequences.length; i++)
1459 sequences[i] = new Sequence(sequences[i], annots); // construct new
1461 // subset of visible
1467 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1474 * get the currently selected sequence objects or all the sequences in the
1477 * @return array of references to sequence objects
1479 public SequenceI[] getSequenceSelection()
1481 SequenceI[] sequences=null;
1482 if (selectionGroup!=null)
1484 sequences = selectionGroup.getSequencesInOrder(alignment);
1486 if (sequences == null)
1488 sequences = alignment.getSequencesArray();
1494 * This method returns the visible alignment as text, as seen on the GUI, ie
1495 * if columns are hidden they will not be returned in the result. Use this for
1496 * calculating trees, PCA, redundancy etc on views which contain hidden
1501 public jalview.datamodel.CigarArray getViewAsCigars(
1502 boolean selectedRegionOnly)
1504 CigarArray selection = null;
1505 SequenceI[] seqs = null;
1507 int start = 0, end = 0;
1508 if (selectedRegionOnly && selectionGroup != null)
1510 iSize = selectionGroup.getSize();
1511 seqs = selectionGroup.getSequencesInOrder(alignment);
1512 start = selectionGroup.getStartRes();
1513 end = selectionGroup.getEndRes(); // inclusive for start and end in
1514 // SeqCigar constructor
1518 iSize = alignment.getHeight();
1519 seqs = alignment.getSequencesArray();
1520 end = alignment.getWidth() - 1;
1522 SeqCigar[] selseqs = new SeqCigar[iSize];
1523 for (i = 0; i < iSize; i++)
1525 selseqs[i] = new SeqCigar(seqs[i], start, end);
1527 selection = new CigarArray(selseqs);
1528 // now construct the CigarArray operations
1529 if (hasHiddenColumns)
1531 Vector regions = colSel.getHiddenColumns();
1533 int hideStart, hideEnd;
1535 for (int j = 0; last < end & j < regions.size(); j++)
1537 region = (int[]) regions.elementAt(j);
1538 hideStart = region[0];
1539 hideEnd = region[1];
1540 // edit hidden regions to selection range
1541 if (hideStart < last)
1553 if (hideStart > end)
1563 if (hideStart > hideEnd)
1568 * form operations...
1570 if (last < hideStart)
1572 selection.addOperation(CigarArray.M, hideStart - last);
1574 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1577 // Final match if necessary.
1580 selection.addOperation(CigarArray.M, end - last + 1);
1585 selection.addOperation(CigarArray.M, end - start + 1);
1591 * return a compact representation of the current alignment selection to pass
1592 * to an analysis function
1594 * @param selectedOnly
1595 * boolean true to just return the selected view
1596 * @return AlignmentView
1598 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1601 // this is here because the AlignmentView constructor modifies the
1603 // object. Refactoring of Cigar and alignment view representation should
1604 // be done to remove redundancy.
1605 CigarArray aligview = getViewAsCigars(selectedOnly);
1606 if (aligview != null)
1608 return new AlignmentView(aligview,
1609 (selectedOnly && selectionGroup != null) ? selectionGroup
1610 .getStartRes() : 0);
1616 * This method returns the visible alignment as text, as seen on the GUI, ie
1617 * if columns are hidden they will not be returned in the result. Use this for
1618 * calculating trees, PCA, redundancy etc on views which contain hidden
1623 public String[] getViewAsString(boolean selectedRegionOnly)
1625 String[] selection = null;
1626 SequenceI[] seqs = null;
1628 int start = 0, end = 0;
1629 if (selectedRegionOnly && selectionGroup != null)
1631 iSize = selectionGroup.getSize();
1632 seqs = selectionGroup.getSequencesInOrder(alignment);
1633 start = selectionGroup.getStartRes();
1634 end = selectionGroup.getEndRes() + 1;
1638 iSize = alignment.getHeight();
1639 seqs = alignment.getSequencesArray();
1640 end = alignment.getWidth();
1643 selection = new String[iSize];
1644 if (hasHiddenColumns)
1646 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1650 for (i = 0; i < iSize; i++)
1652 selection[i] = seqs[i].getSequenceAsString(start, end);
1659 public int[][] getVisibleRegionBoundaries(int min, int max)
1661 Vector regions = new Vector();
1667 if (hasHiddenColumns)
1671 start = colSel.adjustForHiddenColumns(start);
1674 end = colSel.getHiddenBoundaryRight(start);
1685 regions.addElement(new int[]
1688 if (hasHiddenColumns)
1690 start = colSel.adjustForHiddenColumns(end);
1691 start = colSel.getHiddenBoundaryLeft(start) + 1;
1693 } while (end < max);
1695 int[][] startEnd = new int[regions.size()][2];
1697 regions.copyInto(startEnd);
1703 public boolean getShowHiddenMarkers()
1705 return showHiddenMarkers;
1708 public void setShowHiddenMarkers(boolean show)
1710 showHiddenMarkers = show;
1713 public String getSequenceSetId()
1715 if (sequenceSetID == null)
1717 sequenceSetID = alignment.hashCode() + "";
1720 return sequenceSetID;
1723 * unique viewId for synchronizing state with stored Jalview Project
1726 private String viewId=null;
1729 public String getViewId()
1733 viewId = this.getSequenceSetId()+"."+this.hashCode()+"";
1738 public void alignmentChanged(AlignmentPanel ap)
1742 alignment.padGaps();
1744 if (hconsensus != null && autoCalculateConsensus)
1746 updateConservation(ap);
1748 if (autoCalculateConsensus)
1750 updateConsensus(ap);
1753 // Reset endRes of groups if beyond alignment width
1754 int alWidth = alignment.getWidth();
1755 Vector groups = alignment.getGroups();
1758 for (int i = 0; i < groups.size(); i++)
1760 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1761 if (sg.getEndRes() > alWidth)
1763 sg.setEndRes(alWidth - 1);
1768 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1770 selectionGroup.setEndRes(alWidth - 1);
1773 resetAllColourSchemes();
1775 // alignment.adjustSequenceAnnotations();
1778 void resetAllColourSchemes()
1780 ColourSchemeI cs = globalColourScheme;
1783 if (cs instanceof ClustalxColourScheme)
1785 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1786 alignment.getWidth());
1789 cs.setConsensus(hconsensus);
1790 if (cs.conservationApplied())
1792 Alignment al = (Alignment) alignment;
1793 Conservation c = new Conservation("All",
1794 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1797 c.verdict(false, ConsPercGaps);
1799 cs.setConservation(c);
1803 int s, sSize = alignment.getGroups().size();
1804 for (s = 0; s < sSize; s++)
1806 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1807 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1809 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1810 .getSequences(hiddenRepSequences), sg.getWidth());
1812 sg.recalcConservation();
1816 public Color getSequenceColour(SequenceI seq)
1818 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1824 return (Color) sequenceColours.get(seq);
1828 public void setSequenceColour(SequenceI seq, Color col)
1830 if (sequenceColours == null)
1832 sequenceColours = new Hashtable();
1837 sequenceColours.remove(seq);
1841 sequenceColours.put(seq, col);
1846 * returns the visible column regions of the alignment
1848 * @param selectedRegionOnly
1849 * true to just return the contigs intersecting with the
1853 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1855 int[] viscontigs = null;
1856 int start = 0, end = 0;
1857 if (selectedRegionOnly && selectionGroup != null)
1859 start = selectionGroup.getStartRes();
1860 end = selectionGroup.getEndRes() + 1;
1864 end = alignment.getWidth();
1866 viscontigs = colSel.getVisibleContigs(start, end);
1871 * get hash of undo and redo list for the alignment
1873 * @return long[] { historyList.hashCode, redoList.hashCode };
1875 public long[] getUndoRedoHash()
1877 if (historyList == null || redoList == null)
1881 { historyList.hashCode(), this.redoList.hashCode() };
1885 * test if a particular set of hashcodes are different to the hashcodes for
1886 * the undo and redo list.
1889 * the stored set of hashcodes as returned by getUndoRedoHash
1890 * @return true if the hashcodes differ (ie the alignment has been edited) or
1891 * the stored hashcode array differs in size
1893 public boolean isUndoRedoHashModified(long[] undoredo)
1895 if (undoredo == null)
1899 long[] cstate = getUndoRedoHash();
1900 if (cstate.length != undoredo.length)
1905 for (int i = 0; i < cstate.length; i++)
1907 if (cstate[i] != undoredo[i])
1915 public boolean getCentreColumnLabels()
1917 return centreColumnLabels;
1920 public void setCentreColumnLabels(boolean centrecolumnlabels)
1922 centreColumnLabels = centrecolumnlabels;
1925 public void updateSequenceIdColours()
1927 Vector groups = alignment.getGroups();
1928 if (sequenceColours == null)
1930 sequenceColours = new Hashtable();
1932 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1934 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1935 if (sg.idColour != null)
1937 Vector sqs = sg.getSequences(hiddenRepSequences);
1938 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1940 sequenceColours.put(sqs.elementAt(s), sg.idColour);
1947 * enable or disable the display of Database Cross References in the sequence ID tooltip
1949 public void setShowDbRefs(boolean show)
1956 * @return true if Database References are to be displayed on tooltips.
1958 public boolean isShowDbRefs()
1965 * @return true if Non-positional features are to be displayed on tooltips.
1967 public boolean isShowNpFeats()
1972 * enable or disable the display of Non-Positional sequence features in the sequence ID tooltip
1975 public void setShowNpFeats(boolean show)
1981 * @return true if view has hidden rows
1983 public boolean hasHiddenRows()
1985 return hasHiddenRows;
1989 * @return true if view has hidden columns
1991 public boolean hasHiddenColumns()
1993 return hasHiddenColumns;
1996 * when set, view will scroll to show the highlighted position
1998 public boolean followHighlight=true;
2000 * @return true if view should scroll to show the highlighted region of a sequence
2003 public boolean getFollowHighlight() {
2004 return followHighlight;
2006 public boolean followSelection=true;
2008 * @return true if view selection should always follow the selections broadcast by other selection sources
2010 public boolean getFollowSelection() {
2011 return followSelection;
2013 private long sgrouphash=-1,colselhash=-1;
2015 boolean showSeqFeaturesHeight;
2017 * checks current SelectionGroup against record of last hash value, and updates record.
2018 * @return true if SelectionGroup changed since last call
2020 boolean isSelectionGroupChanged() {
2021 int hc=(selectionGroup==null) ? -1 : selectionGroup.hashCode();
2030 * checks current colsel against record of last hash value, and updates record.
2031 * @return true if colsel changed since last call
2033 boolean isColSelChanged() {
2034 int hc=(colSel==null) ? -1 : colSel.hashCode();
2042 public void sendSelection()
2044 jalview.structure.StructureSelectionManager.getStructureSelectionManager().sendSelection(new SequenceGroup(getSelectionGroup()), new ColumnSelection(getColumnSelection()), this);
2046 public void setShowSequenceFeaturesHeight(boolean selected)
2048 showSeqFeaturesHeight = selected;
2050 public boolean getShowSequenceFeaturesHeight()
2052 return showSeqFeaturesHeight;
2054 boolean showUnconserved=false;
2055 public boolean getShowUnconserved()
2057 return showUnconserved;
2059 public void setShowUnconserved(boolean showunconserved)
2061 showUnconserved=showunconserved;
2064 * return the alignPanel containing the given viewport. Use this to get the
2065 * components currently handling the given viewport.
2067 * @return null or an alignPanel guaranteed to have non-null alignFrame reference
2069 public AlignmentPanel getAlignPanel()
2071 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this.getSequenceSetId());
2072 AlignmentPanel ap=null;
2073 for (int p=0;aps!=null && p<aps.length; p++)
2075 if (aps[p].av == this)
2082 public boolean getSortByTree()
2086 public void setSortByTree(boolean sort) {
2090 * should conservation rows be shown for groups
2092 boolean showGroupConservation = false;
2094 * should consensus rows be shown for groups
2096 boolean showGroupConsensus = false;
2098 * should consensus profile be rendered by default
2100 public boolean showConsensusProfile = false;
2102 * should consensus histograms be rendered by default
2104 public boolean showConsensusHistogram = true;
2106 * @return the showConsensusProfile
2108 public boolean isShowConsensusProfile()
2110 return showConsensusProfile;
2113 * @param showConsensusProfile the showConsensusProfile to set
2115 public void setShowConsensusProfile(boolean showConsensusProfile)
2117 this.showConsensusProfile = showConsensusProfile;
2120 * @param showConsensusHistogram the showConsensusHistogram to set
2122 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2124 this.showConsensusHistogram = showConsensusHistogram;
2128 * @return the showGroupConservation
2130 public boolean isShowGroupConservation()
2132 return showGroupConservation;
2135 * @param showGroupConservation the showGroupConservation to set
2137 public void setShowGroupConservation(boolean showGroupConservation)
2139 this.showGroupConservation = showGroupConservation;
2142 * @return the showGroupConsensus
2144 public boolean isShowGroupConsensus()
2146 return showGroupConsensus;
2149 * @param showGroupConsensus the showGroupConsensus to set
2151 public void setShowGroupConsensus(boolean showGroupConsensus)
2153 this.showGroupConsensus = showGroupConsensus;
2156 * @return the includeAllConsensusSymbols
2158 public boolean isIncludeAllConsensusSymbols()
2160 return includeAllConsensusSymbols;
2163 * @param includeAllConsensusSymbols the includeAllConsensusSymbols to set
2165 public void setIncludeAllConsensusSymbols(boolean includeAllConsensusSymbols)
2167 this.includeAllConsensusSymbols = includeAllConsensusSymbols;
2172 * @return flag to indicate if the consensus histogram should be rendered by default
2174 public boolean isShowConsensusHistogram()
2176 return this.showConsensusHistogram;