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;
134 * Keys are the feature types which are
135 * currently visible. Note: Values are not used!
137 Hashtable featuresDisplayed = null;
140 public Hashtable[] hconsensus;
142 AlignmentAnnotation consensus;
144 AlignmentAnnotation conservation;
146 AlignmentAnnotation quality;
147 AlignmentAnnotation[] groupConsensus;
148 AlignmentAnnotation[] groupConservation;
150 boolean autoCalculateConsensus = true;
153 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
155 // JBPNote Prolly only need this in the applet version.
156 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
159 boolean ignoreGapsInConsensusCalculation = false;
161 boolean isDataset = false;
163 boolean antiAlias = false;
165 boolean padGaps = false;
167 Rectangle explodedPosition;
171 String sequenceSetID;
173 boolean gatherViewsHere = false;
175 Stack historyList = new Stack();
177 Stack redoList = new Stack();
179 Hashtable sequenceColours;
181 int thresholdTextColour = 0;
183 Color textColour = Color.black;
185 Color textColour2 = Color.white;
187 boolean rightAlignIds = false;
189 Hashtable hiddenRepSequences;
194 * Creates a new AlignViewport object.
196 * @param al alignment to view
198 public AlignViewport(AlignmentI al)
204 * Create a new AlignViewport object with a specific sequence set ID
206 * @param seqsetid (may be null - but potential for ambiguous constructor exception)
208 public AlignViewport(AlignmentI al, String seqsetid)
210 this(al,seqsetid,null);
212 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
214 sequenceSetID = seqsetid;
216 // TODO remove these once 2.4.VAMSAS release finished
217 if (Cache.log!=null && Cache.log.isDebugEnabled() && seqsetid!=null) { Cache.log.debug("Setting viewport's sequence set id : "+sequenceSetID); }
218 if (Cache.log!=null && Cache.log.isDebugEnabled() && viewId!=null) { Cache.log.debug("Setting viewport's view id : "+viewId); }
224 * Create a new AlignViewport with hidden regions
228 * @param hiddenColumns
231 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
234 if (hiddenColumns != null)
236 this.colSel = hiddenColumns;
237 if (hiddenColumns.getHiddenColumns() != null && hiddenColumns.getHiddenColumns().size()>0)
239 hasHiddenColumns = true;
241 hasHiddenColumns = false;
247 * New viewport with hidden columns and an existing sequence set id
249 * @param hiddenColumns
250 * @param seqsetid (may be null)
252 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, String seqsetid)
254 this(al,hiddenColumns,seqsetid,null);
257 * New viewport with hidden columns and an existing sequence set id and viewid
259 * @param hiddenColumns
260 * @param seqsetid (may be null)
261 * @param viewid (may be null)
263 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, String seqsetid, String viewid)
265 sequenceSetID = seqsetid;
267 // TODO remove these once 2.4.VAMSAS release finished
268 if (Cache.log!=null && Cache.log.isDebugEnabled() && seqsetid!=null) { Cache.log.debug("Setting viewport's sequence set id : "+sequenceSetID); }
269 if (Cache.log!=null && Cache.log.isDebugEnabled() && viewId!=null) { Cache.log.debug("Setting viewport's view id : "+viewId); }
271 if (hiddenColumns != null)
273 this.colSel = hiddenColumns;
274 if (hiddenColumns.getHiddenColumns() != null && hiddenColumns.getHiddenColumns().size()>0)
276 hasHiddenColumns = true;
278 hasHiddenColumns = false;
287 this.endRes = alignment.getWidth() - 1;
289 this.endSeq = alignment.getHeight() - 1;
291 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
293 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
294 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
296 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
297 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
298 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
300 padGaps = Cache.getDefault("PAD_GAPS", true);
301 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP",true);
302 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP",true);
304 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
305 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
306 String fontSize = Cache.getDefault("FONT_SIZE", "10");
308 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
312 if (fontStyle.equals("bold"))
316 else if (fontStyle.equals("italic"))
321 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
324 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
326 // We must set conservation and consensus before setting colour,
327 // as Blosum and Clustal require this to be done
328 if (hconsensus == null && !isDataset)
330 if (!alignment.isNucleotide())
332 conservation = new AlignmentAnnotation("Conservation",
333 "Conservation of total alignment less than " + ConsPercGaps
334 + "% gaps", new Annotation[1], 0f, 11f,
335 AlignmentAnnotation.BAR_GRAPH);
336 conservation.hasText = true;
337 conservation.autoCalculated = true;
339 if (Cache.getDefault("SHOW_CONSERVATION", true))
341 alignment.addAnnotation(conservation);
344 if (Cache.getDefault("SHOW_QUALITY", true))
346 quality = new AlignmentAnnotation("Quality",
347 "Alignment Quality based on Blosum62 scores",
348 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
349 quality.hasText = true;
350 quality.autoCalculated = true;
352 alignment.addAnnotation(quality);
354 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION", false);
360 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true);
361 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
362 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
363 // 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
364 consensus = new AlignmentAnnotation("Consensus", "PID",
365 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
366 consensus.hasText = true;
367 consensus.autoCalculated = true;
369 if (Cache.getDefault("SHOW_IDENTITY", true))
371 alignment.addAnnotation(consensus);
375 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
377 globalColourScheme = ColourSchemeProperty.getColour(alignment,
378 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
380 if (globalColourScheme instanceof UserColourScheme)
382 globalColourScheme = UserDefinedColours.loadDefaultColours();
383 ((UserColourScheme) globalColourScheme).setThreshold(0,
384 getIgnoreGapsConsensus());
387 if (globalColourScheme != null)
389 globalColourScheme.setConsensus(hconsensus);
393 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
394 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED", false);
395 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
402 * features are displayed if true
404 public void setShowSequenceFeatures(boolean b)
406 showSequenceFeatures = b;
409 public boolean getShowSequenceFeatures()
411 return showSequenceFeatures;
414 ConservationThread conservationThread;
416 ConsensusThread consensusThread;
418 boolean consUpdateNeeded = false;
420 static boolean UPDATING_CONSENSUS = false;
422 static boolean UPDATING_CONSERVATION = false;
424 boolean updatingConsensus = false;
426 boolean updatingConservation = false;
429 * centre columnar annotation labels in displayed alignment annotation TODO:
430 * add to jalviewXML and annotation display settings
432 boolean centreColumnLabels = false;
434 private boolean showdbrefs;
436 private boolean shownpfeats;
439 * consensus annotation includes all percentage for all symbols in column
441 private boolean includeAllConsensusSymbols=true;
444 * trigger update of conservation annotation
446 public void updateConservation(final AlignmentPanel ap)
448 // see note in mantis : issue number 8585
449 if (alignment.isNucleotide() || conservation == null || !autoCalculateConsensus)
454 conservationThread = new ConservationThread(this, ap);
455 conservationThread.start();
459 * trigger update of consensus annotation
461 public void updateConsensus(final AlignmentPanel ap)
463 // see note in mantis : issue number 8585
464 if (consensus == null || !autoCalculateConsensus)
468 consensusThread = new ConsensusThread(ap);
469 consensusThread.start();
472 class ConsensusThread extends Thread
476 public ConsensusThread(AlignmentPanel ap)
483 updatingConsensus = true;
484 while (UPDATING_CONSENSUS)
490 ap.paintAlignment(false);
494 } catch (Exception ex)
496 ex.printStackTrace();
500 UPDATING_CONSENSUS = true;
504 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
513 consensus.annotations = null;
514 consensus.annotations = new Annotation[aWidth];
516 hconsensus = new Hashtable[aWidth];
517 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
518 .getWidth(), hconsensus, includeAllConsensusSymbols);
519 AAFrequency.completeConsensus(consensus,hconsensus,0,aWidth,ignoreGapsInConsensusCalculation, includeAllConsensusSymbols);
521 if (globalColourScheme != null)
523 globalColourScheme.setConsensus(hconsensus);
526 } catch (OutOfMemoryError error)
528 alignment.deleteAnnotation(consensus);
532 new OOMWarning("calculating consensus", error);
534 UPDATING_CONSENSUS = false;
535 updatingConsensus = false;
539 ap.paintAlignment(true);
545 * get the consensus sequence as displayed under the PID consensus annotation
548 * @return consensus sequence as a new sequence object
550 public SequenceI getConsensusSeq()
552 if (consensus == null)
554 updateConsensus(null);
556 if (consensus == null)
560 StringBuffer seqs = new StringBuffer();
561 for (int i = 0; i < consensus.annotations.length; i++)
563 if (consensus.annotations[i] != null)
565 if (consensus.annotations[i].description.charAt(0) == '[')
567 seqs.append(consensus.annotations[i].description.charAt(1));
571 seqs.append(consensus.annotations[i].displayCharacter);
576 SequenceI sq = new Sequence("Consensus", seqs.toString());
577 sq.setDescription("Percentage Identity Consensus "
578 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
585 * @return DOCUMENT ME!
587 public SequenceGroup getSelectionGroup()
589 return selectionGroup;
598 public void setSelectionGroup(SequenceGroup sg)
606 * @return DOCUMENT ME!
608 public boolean getConservationSelected()
610 return conservationColourSelected;
619 public void setConservationSelected(boolean b)
621 conservationColourSelected = b;
627 * @return DOCUMENT ME!
629 public boolean getAbovePIDThreshold()
631 return abovePIDThreshold;
640 public void setAbovePIDThreshold(boolean b)
642 abovePIDThreshold = b;
648 * @return DOCUMENT ME!
650 public int getStartRes()
658 * @return DOCUMENT ME!
660 public int getEndRes()
668 * @return DOCUMENT ME!
670 public int getStartSeq()
681 public void setGlobalColourScheme(ColourSchemeI cs)
683 globalColourScheme = cs;
689 * @return DOCUMENT ME!
691 public ColourSchemeI getGlobalColourScheme()
693 return globalColourScheme;
702 public void setStartRes(int res)
713 public void setStartSeq(int seq)
724 public void setEndRes(int res)
726 if (res > (alignment.getWidth() - 1))
728 // log.System.out.println(" Corrected res from " + res + " to maximum " +
729 // (alignment.getWidth()-1));
730 res = alignment.getWidth() - 1;
747 public void setEndSeq(int seq)
749 if (seq > alignment.getHeight())
751 seq = alignment.getHeight();
765 * @return DOCUMENT ME!
767 public int getEndSeq()
778 public void setFont(Font f)
782 Container c = new Container();
784 java.awt.FontMetrics fm = c.getFontMetrics(font);
785 setCharHeight(fm.getHeight());
786 setCharWidth(fm.charWidth('M'));
787 validCharWidth = true;
793 * @return DOCUMENT ME!
795 public Font getFont()
806 public void setCharWidth(int w)
814 * @return DOCUMENT ME!
816 public int getCharWidth()
827 public void setCharHeight(int h)
835 * @return DOCUMENT ME!
837 public int getCharHeight()
848 public void setWrappedWidth(int w)
850 this.wrappedWidth = w;
856 * @return DOCUMENT ME!
858 public int getWrappedWidth()
866 * @return DOCUMENT ME!
868 public AlignmentI getAlignment()
879 public void setAlignment(AlignmentI align)
881 if (alignment != null && alignment.getCodonFrames() != null)
883 StructureSelectionManager.getStructureSelectionManager()
884 .removeMappings(alignment.getCodonFrames());
886 this.alignment = align;
887 if (alignment.getCodonFrames() != null)
889 StructureSelectionManager.getStructureSelectionManager().addMappings(
890 alignment.getCodonFrames());
900 public void setWrapAlignment(boolean state)
902 wrapAlignment = state;
911 public void setShowText(boolean state)
922 public void setRenderGaps(boolean state)
930 * @return DOCUMENT ME!
932 public boolean getColourText()
934 return showColourText;
943 public void setColourText(boolean state)
945 showColourText = state;
954 public void setShowBoxes(boolean state)
962 * @return DOCUMENT ME!
964 public boolean getWrapAlignment()
966 return wrapAlignment;
972 * @return DOCUMENT ME!
974 public boolean getShowText()
982 * @return DOCUMENT ME!
984 public boolean getShowBoxes()
992 * @return DOCUMENT ME!
994 public char getGapCharacter()
996 return getAlignment().getGapCharacter();
1005 public void setGapCharacter(char gap)
1007 if (getAlignment() != null)
1009 getAlignment().setGapCharacter(gap);
1019 public void setThreshold(int thresh)
1027 * @return DOCUMENT ME!
1029 public int getThreshold()
1040 public void setIncrement(int inc)
1048 * @return DOCUMENT ME!
1050 public int getIncrement()
1058 * @return DOCUMENT ME!
1060 public ColumnSelection getColumnSelection()
1071 public void setCurrentTree(NJTree tree)
1079 * @return DOCUMENT ME!
1081 public NJTree getCurrentTree()
1092 public void setColourAppliesToAllGroups(boolean b)
1094 colourAppliesToAllGroups = b;
1100 * @return DOCUMENT ME!
1102 public boolean getColourAppliesToAllGroups()
1104 return colourAppliesToAllGroups;
1110 * @return DOCUMENT ME!
1112 public boolean getShowJVSuffix()
1114 return showJVSuffix;
1123 public void setShowJVSuffix(boolean b)
1131 * @return DOCUMENT ME!
1133 public boolean getShowAnnotation()
1135 return showAnnotation;
1144 public void setShowAnnotation(boolean b)
1152 * @return DOCUMENT ME!
1154 public boolean getScaleAboveWrapped()
1156 return scaleAboveWrapped;
1162 * @return DOCUMENT ME!
1164 public boolean getScaleLeftWrapped()
1166 return scaleLeftWrapped;
1172 * @return DOCUMENT ME!
1174 public boolean getScaleRightWrapped()
1176 return scaleRightWrapped;
1185 public void setScaleAboveWrapped(boolean b)
1187 scaleAboveWrapped = b;
1196 public void setScaleLeftWrapped(boolean b)
1198 scaleLeftWrapped = b;
1207 public void setScaleRightWrapped(boolean b)
1209 scaleRightWrapped = b;
1213 * Property change listener for changes in alignment
1218 public void addPropertyChangeListener(
1219 java.beans.PropertyChangeListener listener)
1221 changeSupport.addPropertyChangeListener(listener);
1230 public void removePropertyChangeListener(
1231 java.beans.PropertyChangeListener listener)
1233 changeSupport.removePropertyChangeListener(listener);
1237 * Property change listener for changes in alignment
1246 public void firePropertyChange(String prop, Object oldvalue,
1249 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1252 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1254 ignoreGapsInConsensusCalculation = b;
1255 updateConsensus(ap);
1256 if (globalColourScheme != null)
1258 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1259 ignoreGapsInConsensusCalculation);
1263 public boolean getIgnoreGapsConsensus()
1265 return ignoreGapsInConsensusCalculation;
1268 public void setDataset(boolean b)
1273 public boolean isDataset()
1278 public void hideSelectedColumns()
1280 if (colSel.size() < 1)
1285 colSel.hideSelectedColumns();
1286 setSelectionGroup(null);
1288 hasHiddenColumns = true;
1291 public void hideColumns(int start, int end)
1295 colSel.hideColumns(start);
1299 colSel.hideColumns(start, end);
1302 hasHiddenColumns = true;
1305 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1307 int sSize = sg.getSize();
1313 if (hiddenRepSequences == null)
1315 hiddenRepSequences = new Hashtable();
1318 hiddenRepSequences.put(repSequence, sg);
1320 // Hide all sequences except the repSequence
1321 SequenceI[] seqs = new SequenceI[sSize - 1];
1323 for (int i = 0; i < sSize; i++)
1325 if (sg.getSequenceAt(i) != repSequence)
1327 if (index == sSize - 1)
1332 seqs[index++] = sg.getSequenceAt(i);
1335 sg.setSeqrep(repSequence);
1336 sg.setHidereps(true);
1341 public void hideAllSelectedSeqs()
1343 if (selectionGroup == null || selectionGroup.getSize() < 1)
1348 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1352 setSelectionGroup(null);
1355 public void hideSequence(SequenceI[] seq)
1359 for (int i = 0; i < seq.length; i++)
1361 alignment.getHiddenSequences().hideSequence(seq[i]);
1363 hasHiddenRows = true;
1364 firePropertyChange("alignment", null, alignment.getSequences());
1368 public void showSequence(int index)
1370 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1371 hiddenRepSequences);
1374 if (selectionGroup == null)
1376 selectionGroup = new SequenceGroup();
1377 selectionGroup.setEndRes(alignment.getWidth() - 1);
1380 for (int t = 0; t < tmp.size(); t++)
1382 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1384 firePropertyChange("alignment", null, alignment.getSequences());
1388 if (alignment.getHiddenSequences().getSize() < 1)
1390 hasHiddenRows = false;
1394 public void showColumn(int col)
1396 colSel.revealHiddenColumns(col);
1397 if (colSel.getHiddenColumns() == null)
1399 hasHiddenColumns = false;
1403 public void showAllHiddenColumns()
1405 colSel.revealAllHiddenColumns();
1406 hasHiddenColumns = false;
1409 public void showAllHiddenSeqs()
1411 if (alignment.getHiddenSequences().getSize() > 0)
1413 if (selectionGroup == null)
1415 selectionGroup = new SequenceGroup();
1416 selectionGroup.setEndRes(alignment.getWidth() - 1);
1418 Vector tmp = alignment.getHiddenSequences().showAll(
1419 hiddenRepSequences);
1420 for (int t = 0; t < tmp.size(); t++)
1422 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1424 firePropertyChange("alignment", null, alignment.getSequences());
1426 hasHiddenRows = false;
1427 hiddenRepSequences = null;
1431 public void invertColumnSelection()
1433 colSel.invertColumnSelection(0, alignment.getWidth());
1436 public int adjustForHiddenSeqs(int alignmentIndex)
1438 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1443 * This method returns an array of new SequenceI objects derived from the
1444 * whole alignment or just the current selection with start and end points
1447 * @note if you need references to the actual SequenceI objects in the
1448 * alignment or currently selected then use getSequenceSelection()
1449 * @return selection as new sequenceI objects
1451 public SequenceI[] getSelectionAsNewSequence()
1453 SequenceI[] sequences;
1455 if (selectionGroup == null)
1457 sequences = alignment.getSequencesArray();
1458 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1459 for (int i = 0; i < sequences.length; i++)
1461 sequences[i] = new Sequence(sequences[i], annots); // construct new
1463 // subset of visible
1469 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1476 * get the currently selected sequence objects or all the sequences in the
1479 * @return array of references to sequence objects
1481 public SequenceI[] getSequenceSelection()
1483 SequenceI[] sequences=null;
1484 if (selectionGroup!=null)
1486 sequences = selectionGroup.getSequencesInOrder(alignment);
1488 if (sequences == null)
1490 sequences = alignment.getSequencesArray();
1496 * This method returns the visible alignment as text, as seen on the GUI, ie
1497 * if columns are hidden they will not be returned in the result. Use this for
1498 * calculating trees, PCA, redundancy etc on views which contain hidden
1503 public jalview.datamodel.CigarArray getViewAsCigars(
1504 boolean selectedRegionOnly)
1506 CigarArray selection = null;
1507 SequenceI[] seqs = null;
1509 int start = 0, end = 0;
1510 if (selectedRegionOnly && selectionGroup != null)
1512 iSize = selectionGroup.getSize();
1513 seqs = selectionGroup.getSequencesInOrder(alignment);
1514 start = selectionGroup.getStartRes();
1515 end = selectionGroup.getEndRes(); // inclusive for start and end in
1516 // SeqCigar constructor
1520 iSize = alignment.getHeight();
1521 seqs = alignment.getSequencesArray();
1522 end = alignment.getWidth() - 1;
1524 SeqCigar[] selseqs = new SeqCigar[iSize];
1525 for (i = 0; i < iSize; i++)
1527 selseqs[i] = new SeqCigar(seqs[i], start, end);
1529 selection = new CigarArray(selseqs);
1530 // now construct the CigarArray operations
1531 if (hasHiddenColumns)
1533 Vector regions = colSel.getHiddenColumns();
1535 int hideStart, hideEnd;
1537 for (int j = 0; last < end & j < regions.size(); j++)
1539 region = (int[]) regions.elementAt(j);
1540 hideStart = region[0];
1541 hideEnd = region[1];
1542 // edit hidden regions to selection range
1543 if (hideStart < last)
1555 if (hideStart > end)
1565 if (hideStart > hideEnd)
1570 * form operations...
1572 if (last < hideStart)
1574 selection.addOperation(CigarArray.M, hideStart - last);
1576 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1579 // Final match if necessary.
1582 selection.addOperation(CigarArray.M, end - last + 1);
1587 selection.addOperation(CigarArray.M, end - start + 1);
1593 * return a compact representation of the current alignment selection to pass
1594 * to an analysis function
1596 * @param selectedOnly
1597 * boolean true to just return the selected view
1598 * @return AlignmentView
1600 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1603 // this is here because the AlignmentView constructor modifies the
1605 // object. Refactoring of Cigar and alignment view representation should
1606 // be done to remove redundancy.
1607 CigarArray aligview = getViewAsCigars(selectedOnly);
1608 if (aligview != null)
1610 return new AlignmentView(aligview,
1611 (selectedOnly && selectionGroup != null) ? selectionGroup
1612 .getStartRes() : 0);
1618 * This method returns the visible alignment as text, as seen on the GUI, ie
1619 * if columns are hidden they will not be returned in the result. Use this for
1620 * calculating trees, PCA, redundancy etc on views which contain hidden
1625 public String[] getViewAsString(boolean selectedRegionOnly)
1627 String[] selection = null;
1628 SequenceI[] seqs = null;
1630 int start = 0, end = 0;
1631 if (selectedRegionOnly && selectionGroup != null)
1633 iSize = selectionGroup.getSize();
1634 seqs = selectionGroup.getSequencesInOrder(alignment);
1635 start = selectionGroup.getStartRes();
1636 end = selectionGroup.getEndRes() + 1;
1640 iSize = alignment.getHeight();
1641 seqs = alignment.getSequencesArray();
1642 end = alignment.getWidth();
1645 selection = new String[iSize];
1646 if (hasHiddenColumns)
1648 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1652 for (i = 0; i < iSize; i++)
1654 selection[i] = seqs[i].getSequenceAsString(start, end);
1661 public int[][] getVisibleRegionBoundaries(int min, int max)
1663 Vector regions = new Vector();
1669 if (hasHiddenColumns)
1673 start = colSel.adjustForHiddenColumns(start);
1676 end = colSel.getHiddenBoundaryRight(start);
1687 regions.addElement(new int[]
1690 if (hasHiddenColumns)
1692 start = colSel.adjustForHiddenColumns(end);
1693 start = colSel.getHiddenBoundaryLeft(start) + 1;
1695 } while (end < max);
1697 int[][] startEnd = new int[regions.size()][2];
1699 regions.copyInto(startEnd);
1705 public boolean getShowHiddenMarkers()
1707 return showHiddenMarkers;
1710 public void setShowHiddenMarkers(boolean show)
1712 showHiddenMarkers = show;
1715 public String getSequenceSetId()
1717 if (sequenceSetID == null)
1719 sequenceSetID = alignment.hashCode() + "";
1722 return sequenceSetID;
1725 * unique viewId for synchronizing state with stored Jalview Project
1728 private String viewId=null;
1731 public String getViewId()
1735 viewId = this.getSequenceSetId()+"."+this.hashCode()+"";
1740 public void alignmentChanged(AlignmentPanel ap)
1744 alignment.padGaps();
1746 if (hconsensus != null && autoCalculateConsensus)
1748 updateConservation(ap);
1750 if (autoCalculateConsensus)
1752 updateConsensus(ap);
1755 // Reset endRes of groups if beyond alignment width
1756 int alWidth = alignment.getWidth();
1757 Vector groups = alignment.getGroups();
1760 for (int i = 0; i < groups.size(); i++)
1762 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1763 if (sg.getEndRes() > alWidth)
1765 sg.setEndRes(alWidth - 1);
1770 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1772 selectionGroup.setEndRes(alWidth - 1);
1775 resetAllColourSchemes();
1777 // alignment.adjustSequenceAnnotations();
1780 void resetAllColourSchemes()
1782 ColourSchemeI cs = globalColourScheme;
1785 if (cs instanceof ClustalxColourScheme)
1787 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1788 alignment.getWidth());
1791 cs.setConsensus(hconsensus);
1792 if (cs.conservationApplied())
1794 Alignment al = (Alignment) alignment;
1795 Conservation c = new Conservation("All",
1796 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1799 c.verdict(false, ConsPercGaps);
1801 cs.setConservation(c);
1805 int s, sSize = alignment.getGroups().size();
1806 for (s = 0; s < sSize; s++)
1808 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1809 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1811 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1812 .getSequences(hiddenRepSequences), sg.getWidth());
1814 sg.recalcConservation();
1818 public Color getSequenceColour(SequenceI seq)
1820 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1826 return (Color) sequenceColours.get(seq);
1830 public void setSequenceColour(SequenceI seq, Color col)
1832 if (sequenceColours == null)
1834 sequenceColours = new Hashtable();
1839 sequenceColours.remove(seq);
1843 sequenceColours.put(seq, col);
1848 * returns the visible column regions of the alignment
1850 * @param selectedRegionOnly
1851 * true to just return the contigs intersecting with the
1855 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1857 int[] viscontigs = null;
1858 int start = 0, end = 0;
1859 if (selectedRegionOnly && selectionGroup != null)
1861 start = selectionGroup.getStartRes();
1862 end = selectionGroup.getEndRes() + 1;
1866 end = alignment.getWidth();
1868 viscontigs = colSel.getVisibleContigs(start, end);
1873 * get hash of undo and redo list for the alignment
1875 * @return long[] { historyList.hashCode, redoList.hashCode };
1877 public long[] getUndoRedoHash()
1879 if (historyList == null || redoList == null)
1883 { historyList.hashCode(), this.redoList.hashCode() };
1887 * test if a particular set of hashcodes are different to the hashcodes for
1888 * the undo and redo list.
1891 * the stored set of hashcodes as returned by getUndoRedoHash
1892 * @return true if the hashcodes differ (ie the alignment has been edited) or
1893 * the stored hashcode array differs in size
1895 public boolean isUndoRedoHashModified(long[] undoredo)
1897 if (undoredo == null)
1901 long[] cstate = getUndoRedoHash();
1902 if (cstate.length != undoredo.length)
1907 for (int i = 0; i < cstate.length; i++)
1909 if (cstate[i] != undoredo[i])
1917 public boolean getCentreColumnLabels()
1919 return centreColumnLabels;
1922 public void setCentreColumnLabels(boolean centrecolumnlabels)
1924 centreColumnLabels = centrecolumnlabels;
1927 public void updateSequenceIdColours()
1929 Vector groups = alignment.getGroups();
1930 if (sequenceColours == null)
1932 sequenceColours = new Hashtable();
1934 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1936 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1937 if (sg.idColour != null)
1939 Vector sqs = sg.getSequences(hiddenRepSequences);
1940 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1942 sequenceColours.put(sqs.elementAt(s), sg.idColour);
1949 * enable or disable the display of Database Cross References in the sequence ID tooltip
1951 public void setShowDbRefs(boolean show)
1958 * @return true if Database References are to be displayed on tooltips.
1960 public boolean isShowDbRefs()
1967 * @return true if Non-positional features are to be displayed on tooltips.
1969 public boolean isShowNpFeats()
1974 * enable or disable the display of Non-Positional sequence features in the sequence ID tooltip
1977 public void setShowNpFeats(boolean show)
1983 * @return true if view has hidden rows
1985 public boolean hasHiddenRows()
1987 return hasHiddenRows;
1991 * @return true if view has hidden columns
1993 public boolean hasHiddenColumns()
1995 return hasHiddenColumns;
1998 * when set, view will scroll to show the highlighted position
2000 public boolean followHighlight=true;
2002 * @return true if view should scroll to show the highlighted region of a sequence
2005 public boolean getFollowHighlight() {
2006 return followHighlight;
2008 public boolean followSelection=true;
2010 * @return true if view selection should always follow the selections broadcast by other selection sources
2012 public boolean getFollowSelection() {
2013 return followSelection;
2015 private long sgrouphash=-1,colselhash=-1;
2017 boolean showSeqFeaturesHeight;
2019 * checks current SelectionGroup against record of last hash value, and updates record.
2020 * @return true if SelectionGroup changed since last call
2022 boolean isSelectionGroupChanged() {
2023 int hc=(selectionGroup==null) ? -1 : selectionGroup.hashCode();
2032 * checks current colsel against record of last hash value, and updates record.
2033 * @return true if colsel changed since last call
2035 boolean isColSelChanged() {
2036 int hc=(colSel==null) ? -1 : colSel.hashCode();
2044 public void sendSelection()
2046 jalview.structure.StructureSelectionManager.getStructureSelectionManager().sendSelection(new SequenceGroup(getSelectionGroup()), new ColumnSelection(getColumnSelection()), this);
2048 public void setShowSequenceFeaturesHeight(boolean selected)
2050 showSeqFeaturesHeight = selected;
2052 public boolean getShowSequenceFeaturesHeight()
2054 return showSeqFeaturesHeight;
2056 boolean showUnconserved=false;
2057 public boolean getShowUnconserved()
2059 return showUnconserved;
2061 public void setShowUnconserved(boolean showunconserved)
2063 showUnconserved=showunconserved;
2066 * return the alignPanel containing the given viewport. Use this to get the
2067 * components currently handling the given viewport.
2069 * @return null or an alignPanel guaranteed to have non-null alignFrame reference
2071 public AlignmentPanel getAlignPanel()
2073 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this.getSequenceSetId());
2074 AlignmentPanel ap=null;
2075 for (int p=0;aps!=null && p<aps.length; p++)
2077 if (aps[p].av == this)
2084 public boolean getSortByTree()
2088 public void setSortByTree(boolean sort) {
2092 * should conservation rows be shown for groups
2094 boolean showGroupConservation = false;
2096 * should consensus rows be shown for groups
2098 boolean showGroupConsensus = false;
2100 * should consensus profile be rendered by default
2102 public boolean showSequenceLogo = false;
2104 * should consensus histograms be rendered by default
2106 public boolean showConsensusHistogram = true;
2108 * @return the showConsensusProfile
2110 public boolean isShowSequenceLogo()
2112 return showSequenceLogo;
2115 * @param showSequenceLogo the new value
2117 public void setShowSequenceLogo(boolean showSequenceLogo)
2119 this.showSequenceLogo = showSequenceLogo;
2122 * @param showConsensusHistogram the showConsensusHistogram to set
2124 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2126 this.showConsensusHistogram = showConsensusHistogram;
2130 * @return the showGroupConservation
2132 public boolean isShowGroupConservation()
2134 return showGroupConservation;
2137 * @param showGroupConservation the showGroupConservation to set
2139 public void setShowGroupConservation(boolean showGroupConservation)
2141 this.showGroupConservation = showGroupConservation;
2144 * @return the showGroupConsensus
2146 public boolean isShowGroupConsensus()
2148 return showGroupConsensus;
2151 * @param showGroupConsensus the showGroupConsensus to set
2153 public void setShowGroupConsensus(boolean showGroupConsensus)
2155 this.showGroupConsensus = showGroupConsensus;
2158 * @return the includeAllConsensusSymbols
2160 public boolean isIncludeAllConsensusSymbols()
2162 return includeAllConsensusSymbols;
2165 * @param includeAllConsensusSymbols the includeAllConsensusSymbols to set
2167 public void setIncludeAllConsensusSymbols(boolean includeAllConsensusSymbols)
2169 this.includeAllConsensusSymbols = includeAllConsensusSymbols;
2174 * @return flag to indicate if the consensus histogram should be rendered by default
2176 public boolean isShowConsensusHistogram()
2178 return this.showConsensusHistogram;