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)
237 hasHiddenColumns = true;
243 * New viewport with hidden columns and an existing sequence set id
245 * @param hiddenColumns
246 * @param seqsetid (may be null)
248 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, String seqsetid)
250 this(al,hiddenColumns,seqsetid,null);
253 * New viewport with hidden columns and an existing sequence set id and viewid
255 * @param hiddenColumns
256 * @param seqsetid (may be null)
257 * @param viewid (may be null)
259 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, String seqsetid, String viewid)
261 sequenceSetID = seqsetid;
263 // TODO remove these once 2.4.VAMSAS release finished
264 if (Cache.log!=null && Cache.log.isDebugEnabled() && seqsetid!=null) { Cache.log.debug("Setting viewport's sequence set id : "+sequenceSetID); }
265 if (Cache.log!=null && Cache.log.isDebugEnabled() && viewId!=null) { Cache.log.debug("Setting viewport's view id : "+viewId); }
267 if (hiddenColumns != null)
269 this.colSel = hiddenColumns;
270 if (hiddenColumns.getHiddenColumns() != null)
272 hasHiddenColumns = true;
281 this.endRes = alignment.getWidth() - 1;
283 this.endSeq = alignment.getHeight() - 1;
285 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
287 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
288 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
290 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
291 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
292 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
294 padGaps = Cache.getDefault("PAD_GAPS", true);
295 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP",true);
296 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP",true);
298 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
299 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
300 String fontSize = Cache.getDefault("FONT_SIZE", "10");
302 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
306 if (fontStyle.equals("bold"))
310 else if (fontStyle.equals("italic"))
315 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
318 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
320 // We must set conservation and consensus before setting colour,
321 // as Blosum and Clustal require this to be done
322 if (hconsensus == null && !isDataset)
324 if (!alignment.isNucleotide())
326 conservation = new AlignmentAnnotation("Conservation",
327 "Conservation of total alignment less than " + ConsPercGaps
328 + "% gaps", new Annotation[1], 0f, 11f,
329 AlignmentAnnotation.BAR_GRAPH);
330 conservation.hasText = true;
331 conservation.autoCalculated = true;
333 if (Cache.getDefault("SHOW_CONSERVATION", true))
335 alignment.addAnnotation(conservation);
338 if (Cache.getDefault("SHOW_QUALITY", true))
340 quality = new AlignmentAnnotation("Quality",
341 "Alignment Quality based on Blosum62 scores",
342 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
343 quality.hasText = true;
344 quality.autoCalculated = true;
346 alignment.addAnnotation(quality);
349 // 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
350 consensus = new AlignmentAnnotation("Consensus", "PID",
351 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
352 consensus.hasText = true;
353 consensus.autoCalculated = true;
355 if (Cache.getDefault("SHOW_IDENTITY", true))
357 alignment.addAnnotation(consensus);
361 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
363 globalColourScheme = ColourSchemeProperty.getColour(alignment,
364 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
366 if (globalColourScheme instanceof UserColourScheme)
368 globalColourScheme = UserDefinedColours.loadDefaultColours();
369 ((UserColourScheme) globalColourScheme).setThreshold(0,
370 getIgnoreGapsConsensus());
373 if (globalColourScheme != null)
375 globalColourScheme.setConsensus(hconsensus);
379 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
380 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED", false);
381 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
388 * features are displayed if true
390 public void setShowSequenceFeatures(boolean b)
392 showSequenceFeatures = b;
395 public boolean getShowSequenceFeatures()
397 return showSequenceFeatures;
400 ConservationThread conservationThread;
402 ConsensusThread consensusThread;
404 boolean consUpdateNeeded = false;
406 static boolean UPDATING_CONSENSUS = false;
408 static boolean UPDATING_CONSERVATION = false;
410 boolean updatingConsensus = false;
412 boolean updatingConservation = false;
415 * centre columnar annotation labels in displayed alignment annotation TODO:
416 * add to jalviewXML and annotation display settings
418 boolean centreColumnLabels = false;
420 private boolean showdbrefs;
422 private boolean shownpfeats;
425 * consensus annotation includes all percentage for all symbols in column
427 private boolean includeAllConsensusSymbols=true;
430 * trigger update of conservation annotation
432 public void updateConservation(final AlignmentPanel ap)
434 // see note in mantis : issue number 8585
435 if (alignment.isNucleotide() || conservation == null || !autoCalculateConsensus)
440 conservationThread = new ConservationThread(this, ap);
441 conservationThread.start();
445 * trigger update of consensus annotation
447 public void updateConsensus(final AlignmentPanel ap)
449 // see note in mantis : issue number 8585
450 if (consensus == null || !autoCalculateConsensus)
454 consensusThread = new ConsensusThread(ap);
455 consensusThread.start();
458 class ConsensusThread extends Thread
462 public ConsensusThread(AlignmentPanel ap)
469 updatingConsensus = true;
470 while (UPDATING_CONSENSUS)
476 ap.paintAlignment(false);
480 } catch (Exception ex)
482 ex.printStackTrace();
486 UPDATING_CONSENSUS = true;
490 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
499 consensus.annotations = null;
500 consensus.annotations = new Annotation[aWidth];
502 hconsensus = new Hashtable[aWidth];
503 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
504 .getWidth(), hconsensus, includeAllConsensusSymbols);
505 AAFrequency.completeConsensus(consensus,hconsensus,0,aWidth,ignoreGapsInConsensusCalculation, includeAllConsensusSymbols);
507 if (globalColourScheme != null)
509 globalColourScheme.setConsensus(hconsensus);
512 } catch (OutOfMemoryError error)
514 alignment.deleteAnnotation(consensus);
518 new OOMWarning("calculating consensus", error);
520 UPDATING_CONSENSUS = false;
521 updatingConsensus = false;
525 ap.paintAlignment(true);
531 * get the consensus sequence as displayed under the PID consensus annotation
534 * @return consensus sequence as a new sequence object
536 public SequenceI getConsensusSeq()
538 if (consensus == null)
540 updateConsensus(null);
542 if (consensus == null)
546 StringBuffer seqs = new StringBuffer();
547 for (int i = 0; i < consensus.annotations.length; i++)
549 if (consensus.annotations[i] != null)
551 if (consensus.annotations[i].description.charAt(0) == '[')
553 seqs.append(consensus.annotations[i].description.charAt(1));
557 seqs.append(consensus.annotations[i].displayCharacter);
562 SequenceI sq = new Sequence("Consensus", seqs.toString());
563 sq.setDescription("Percentage Identity Consensus "
564 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
571 * @return DOCUMENT ME!
573 public SequenceGroup getSelectionGroup()
575 return selectionGroup;
584 public void setSelectionGroup(SequenceGroup sg)
592 * @return DOCUMENT ME!
594 public boolean getConservationSelected()
596 return conservationColourSelected;
605 public void setConservationSelected(boolean b)
607 conservationColourSelected = b;
613 * @return DOCUMENT ME!
615 public boolean getAbovePIDThreshold()
617 return abovePIDThreshold;
626 public void setAbovePIDThreshold(boolean b)
628 abovePIDThreshold = b;
634 * @return DOCUMENT ME!
636 public int getStartRes()
644 * @return DOCUMENT ME!
646 public int getEndRes()
654 * @return DOCUMENT ME!
656 public int getStartSeq()
667 public void setGlobalColourScheme(ColourSchemeI cs)
669 globalColourScheme = cs;
675 * @return DOCUMENT ME!
677 public ColourSchemeI getGlobalColourScheme()
679 return globalColourScheme;
688 public void setStartRes(int res)
699 public void setStartSeq(int seq)
710 public void setEndRes(int res)
712 if (res > (alignment.getWidth() - 1))
714 // log.System.out.println(" Corrected res from " + res + " to maximum " +
715 // (alignment.getWidth()-1));
716 res = alignment.getWidth() - 1;
733 public void setEndSeq(int seq)
735 if (seq > alignment.getHeight())
737 seq = alignment.getHeight();
751 * @return DOCUMENT ME!
753 public int getEndSeq()
764 public void setFont(Font f)
768 Container c = new Container();
770 java.awt.FontMetrics fm = c.getFontMetrics(font);
771 setCharHeight(fm.getHeight());
772 setCharWidth(fm.charWidth('M'));
773 validCharWidth = true;
779 * @return DOCUMENT ME!
781 public Font getFont()
792 public void setCharWidth(int w)
800 * @return DOCUMENT ME!
802 public int getCharWidth()
813 public void setCharHeight(int h)
821 * @return DOCUMENT ME!
823 public int getCharHeight()
834 public void setWrappedWidth(int w)
836 this.wrappedWidth = w;
842 * @return DOCUMENT ME!
844 public int getWrappedWidth()
852 * @return DOCUMENT ME!
854 public AlignmentI getAlignment()
865 public void setAlignment(AlignmentI align)
867 if (alignment != null && alignment.getCodonFrames() != null)
869 StructureSelectionManager.getStructureSelectionManager()
870 .removeMappings(alignment.getCodonFrames());
872 this.alignment = align;
873 if (alignment.getCodonFrames() != null)
875 StructureSelectionManager.getStructureSelectionManager().addMappings(
876 alignment.getCodonFrames());
886 public void setWrapAlignment(boolean state)
888 wrapAlignment = state;
897 public void setShowText(boolean state)
908 public void setRenderGaps(boolean state)
916 * @return DOCUMENT ME!
918 public boolean getColourText()
920 return showColourText;
929 public void setColourText(boolean state)
931 showColourText = state;
940 public void setShowBoxes(boolean state)
948 * @return DOCUMENT ME!
950 public boolean getWrapAlignment()
952 return wrapAlignment;
958 * @return DOCUMENT ME!
960 public boolean getShowText()
968 * @return DOCUMENT ME!
970 public boolean getShowBoxes()
978 * @return DOCUMENT ME!
980 public char getGapCharacter()
982 return getAlignment().getGapCharacter();
991 public void setGapCharacter(char gap)
993 if (getAlignment() != null)
995 getAlignment().setGapCharacter(gap);
1005 public void setThreshold(int thresh)
1013 * @return DOCUMENT ME!
1015 public int getThreshold()
1026 public void setIncrement(int inc)
1034 * @return DOCUMENT ME!
1036 public int getIncrement()
1044 * @return DOCUMENT ME!
1046 public ColumnSelection getColumnSelection()
1057 public void setCurrentTree(NJTree tree)
1065 * @return DOCUMENT ME!
1067 public NJTree getCurrentTree()
1078 public void setColourAppliesToAllGroups(boolean b)
1080 colourAppliesToAllGroups = b;
1086 * @return DOCUMENT ME!
1088 public boolean getColourAppliesToAllGroups()
1090 return colourAppliesToAllGroups;
1096 * @return DOCUMENT ME!
1098 public boolean getShowJVSuffix()
1100 return showJVSuffix;
1109 public void setShowJVSuffix(boolean b)
1117 * @return DOCUMENT ME!
1119 public boolean getShowAnnotation()
1121 return showAnnotation;
1130 public void setShowAnnotation(boolean b)
1138 * @return DOCUMENT ME!
1140 public boolean getScaleAboveWrapped()
1142 return scaleAboveWrapped;
1148 * @return DOCUMENT ME!
1150 public boolean getScaleLeftWrapped()
1152 return scaleLeftWrapped;
1158 * @return DOCUMENT ME!
1160 public boolean getScaleRightWrapped()
1162 return scaleRightWrapped;
1171 public void setScaleAboveWrapped(boolean b)
1173 scaleAboveWrapped = b;
1182 public void setScaleLeftWrapped(boolean b)
1184 scaleLeftWrapped = b;
1193 public void setScaleRightWrapped(boolean b)
1195 scaleRightWrapped = b;
1199 * Property change listener for changes in alignment
1204 public void addPropertyChangeListener(
1205 java.beans.PropertyChangeListener listener)
1207 changeSupport.addPropertyChangeListener(listener);
1216 public void removePropertyChangeListener(
1217 java.beans.PropertyChangeListener listener)
1219 changeSupport.removePropertyChangeListener(listener);
1223 * Property change listener for changes in alignment
1232 public void firePropertyChange(String prop, Object oldvalue,
1235 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1238 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1240 ignoreGapsInConsensusCalculation = b;
1241 updateConsensus(ap);
1242 if (globalColourScheme != null)
1244 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1245 ignoreGapsInConsensusCalculation);
1249 public boolean getIgnoreGapsConsensus()
1251 return ignoreGapsInConsensusCalculation;
1254 public void setDataset(boolean b)
1259 public boolean isDataset()
1264 public void hideSelectedColumns()
1266 if (colSel.size() < 1)
1271 colSel.hideSelectedColumns();
1272 setSelectionGroup(null);
1274 hasHiddenColumns = true;
1277 public void hideColumns(int start, int end)
1281 colSel.hideColumns(start);
1285 colSel.hideColumns(start, end);
1288 hasHiddenColumns = true;
1291 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1293 int sSize = sg.getSize();
1299 if (hiddenRepSequences == null)
1301 hiddenRepSequences = new Hashtable();
1304 hiddenRepSequences.put(repSequence, sg);
1306 // Hide all sequences except the repSequence
1307 SequenceI[] seqs = new SequenceI[sSize - 1];
1309 for (int i = 0; i < sSize; i++)
1311 if (sg.getSequenceAt(i) != repSequence)
1313 if (index == sSize - 1)
1318 seqs[index++] = sg.getSequenceAt(i);
1321 sg.setSeqrep(repSequence);
1322 sg.setHidereps(true);
1327 public void hideAllSelectedSeqs()
1329 if (selectionGroup == null || selectionGroup.getSize() < 1)
1334 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1338 setSelectionGroup(null);
1341 public void hideSequence(SequenceI[] seq)
1345 for (int i = 0; i < seq.length; i++)
1347 alignment.getHiddenSequences().hideSequence(seq[i]);
1349 hasHiddenRows = true;
1350 firePropertyChange("alignment", null, alignment.getSequences());
1354 public void showSequence(int index)
1356 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1357 hiddenRepSequences);
1360 if (selectionGroup == null)
1362 selectionGroup = new SequenceGroup();
1363 selectionGroup.setEndRes(alignment.getWidth() - 1);
1366 for (int t = 0; t < tmp.size(); t++)
1368 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1370 firePropertyChange("alignment", null, alignment.getSequences());
1374 if (alignment.getHiddenSequences().getSize() < 1)
1376 hasHiddenRows = false;
1380 public void showColumn(int col)
1382 colSel.revealHiddenColumns(col);
1383 if (colSel.getHiddenColumns() == null)
1385 hasHiddenColumns = false;
1389 public void showAllHiddenColumns()
1391 colSel.revealAllHiddenColumns();
1392 hasHiddenColumns = false;
1395 public void showAllHiddenSeqs()
1397 if (alignment.getHiddenSequences().getSize() > 0)
1399 if (selectionGroup == null)
1401 selectionGroup = new SequenceGroup();
1402 selectionGroup.setEndRes(alignment.getWidth() - 1);
1404 Vector tmp = alignment.getHiddenSequences().showAll(
1405 hiddenRepSequences);
1406 for (int t = 0; t < tmp.size(); t++)
1408 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1410 firePropertyChange("alignment", null, alignment.getSequences());
1412 hasHiddenRows = false;
1413 hiddenRepSequences = null;
1417 public void invertColumnSelection()
1419 colSel.invertColumnSelection(0, alignment.getWidth());
1422 public int adjustForHiddenSeqs(int alignmentIndex)
1424 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1429 * This method returns an array of new SequenceI objects derived from the
1430 * whole alignment or just the current selection with start and end points
1433 * @note if you need references to the actual SequenceI objects in the
1434 * alignment or currently selected then use getSequenceSelection()
1435 * @return selection as new sequenceI objects
1437 public SequenceI[] getSelectionAsNewSequence()
1439 SequenceI[] sequences;
1441 if (selectionGroup == null)
1443 sequences = alignment.getSequencesArray();
1444 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1445 for (int i = 0; i < sequences.length; i++)
1447 sequences[i] = new Sequence(sequences[i], annots); // construct new
1449 // subset of visible
1455 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1462 * get the currently selected sequence objects or all the sequences in the
1465 * @return array of references to sequence objects
1467 public SequenceI[] getSequenceSelection()
1469 SequenceI[] sequences=null;
1470 if (selectionGroup!=null)
1472 sequences = selectionGroup.getSequencesInOrder(alignment);
1474 if (sequences == null)
1476 sequences = alignment.getSequencesArray();
1482 * This method returns the visible alignment as text, as seen on the GUI, ie
1483 * if columns are hidden they will not be returned in the result. Use this for
1484 * calculating trees, PCA, redundancy etc on views which contain hidden
1489 public jalview.datamodel.CigarArray getViewAsCigars(
1490 boolean selectedRegionOnly)
1492 CigarArray selection = null;
1493 SequenceI[] seqs = null;
1495 int start = 0, end = 0;
1496 if (selectedRegionOnly && selectionGroup != null)
1498 iSize = selectionGroup.getSize();
1499 seqs = selectionGroup.getSequencesInOrder(alignment);
1500 start = selectionGroup.getStartRes();
1501 end = selectionGroup.getEndRes(); // inclusive for start and end in
1502 // SeqCigar constructor
1506 iSize = alignment.getHeight();
1507 seqs = alignment.getSequencesArray();
1508 end = alignment.getWidth() - 1;
1510 SeqCigar[] selseqs = new SeqCigar[iSize];
1511 for (i = 0; i < iSize; i++)
1513 selseqs[i] = new SeqCigar(seqs[i], start, end);
1515 selection = new CigarArray(selseqs);
1516 // now construct the CigarArray operations
1517 if (hasHiddenColumns)
1519 Vector regions = colSel.getHiddenColumns();
1521 int hideStart, hideEnd;
1523 for (int j = 0; last < end & j < regions.size(); j++)
1525 region = (int[]) regions.elementAt(j);
1526 hideStart = region[0];
1527 hideEnd = region[1];
1528 // edit hidden regions to selection range
1529 if (hideStart < last)
1541 if (hideStart > end)
1551 if (hideStart > hideEnd)
1556 * form operations...
1558 if (last < hideStart)
1560 selection.addOperation(CigarArray.M, hideStart - last);
1562 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1565 // Final match if necessary.
1568 selection.addOperation(CigarArray.M, end - last + 1);
1573 selection.addOperation(CigarArray.M, end - start + 1);
1579 * return a compact representation of the current alignment selection to pass
1580 * to an analysis function
1582 * @param selectedOnly
1583 * boolean true to just return the selected view
1584 * @return AlignmentView
1586 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1589 // this is here because the AlignmentView constructor modifies the
1591 // object. Refactoring of Cigar and alignment view representation should
1592 // be done to remove redundancy.
1593 CigarArray aligview = getViewAsCigars(selectedOnly);
1594 if (aligview != null)
1596 return new AlignmentView(aligview,
1597 (selectedOnly && selectionGroup != null) ? selectionGroup
1598 .getStartRes() : 0);
1604 * This method returns the visible alignment as text, as seen on the GUI, ie
1605 * if columns are hidden they will not be returned in the result. Use this for
1606 * calculating trees, PCA, redundancy etc on views which contain hidden
1611 public String[] getViewAsString(boolean selectedRegionOnly)
1613 String[] selection = null;
1614 SequenceI[] seqs = null;
1616 int start = 0, end = 0;
1617 if (selectedRegionOnly && selectionGroup != null)
1619 iSize = selectionGroup.getSize();
1620 seqs = selectionGroup.getSequencesInOrder(alignment);
1621 start = selectionGroup.getStartRes();
1622 end = selectionGroup.getEndRes() + 1;
1626 iSize = alignment.getHeight();
1627 seqs = alignment.getSequencesArray();
1628 end = alignment.getWidth();
1631 selection = new String[iSize];
1632 if (hasHiddenColumns)
1634 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1638 for (i = 0; i < iSize; i++)
1640 selection[i] = seqs[i].getSequenceAsString(start, end);
1647 public int[][] getVisibleRegionBoundaries(int min, int max)
1649 Vector regions = new Vector();
1655 if (hasHiddenColumns)
1659 start = colSel.adjustForHiddenColumns(start);
1662 end = colSel.getHiddenBoundaryRight(start);
1673 regions.addElement(new int[]
1676 if (hasHiddenColumns)
1678 start = colSel.adjustForHiddenColumns(end);
1679 start = colSel.getHiddenBoundaryLeft(start) + 1;
1681 } while (end < max);
1683 int[][] startEnd = new int[regions.size()][2];
1685 regions.copyInto(startEnd);
1691 public boolean getShowHiddenMarkers()
1693 return showHiddenMarkers;
1696 public void setShowHiddenMarkers(boolean show)
1698 showHiddenMarkers = show;
1701 public String getSequenceSetId()
1703 if (sequenceSetID == null)
1705 sequenceSetID = alignment.hashCode() + "";
1708 return sequenceSetID;
1711 * unique viewId for synchronizing state with stored Jalview Project
1714 private String viewId=null;
1717 public String getViewId()
1721 viewId = this.getSequenceSetId()+"."+this.hashCode()+"";
1726 public void alignmentChanged(AlignmentPanel ap)
1730 alignment.padGaps();
1732 if (hconsensus != null && autoCalculateConsensus)
1734 updateConservation(ap);
1736 if (autoCalculateConsensus)
1738 updateConsensus(ap);
1741 // Reset endRes of groups if beyond alignment width
1742 int alWidth = alignment.getWidth();
1743 Vector groups = alignment.getGroups();
1746 for (int i = 0; i < groups.size(); i++)
1748 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1749 if (sg.getEndRes() > alWidth)
1751 sg.setEndRes(alWidth - 1);
1756 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1758 selectionGroup.setEndRes(alWidth - 1);
1761 resetAllColourSchemes();
1763 // alignment.adjustSequenceAnnotations();
1766 void resetAllColourSchemes()
1768 ColourSchemeI cs = globalColourScheme;
1771 if (cs instanceof ClustalxColourScheme)
1773 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1774 alignment.getWidth());
1777 cs.setConsensus(hconsensus);
1778 if (cs.conservationApplied())
1780 Alignment al = (Alignment) alignment;
1781 Conservation c = new Conservation("All",
1782 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1785 c.verdict(false, ConsPercGaps);
1787 cs.setConservation(c);
1791 int s, sSize = alignment.getGroups().size();
1792 for (s = 0; s < sSize; s++)
1794 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1795 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1797 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1798 .getSequences(hiddenRepSequences), sg.getWidth());
1800 sg.recalcConservation();
1804 public Color getSequenceColour(SequenceI seq)
1806 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1812 return (Color) sequenceColours.get(seq);
1816 public void setSequenceColour(SequenceI seq, Color col)
1818 if (sequenceColours == null)
1820 sequenceColours = new Hashtable();
1825 sequenceColours.remove(seq);
1829 sequenceColours.put(seq, col);
1834 * returns the visible column regions of the alignment
1836 * @param selectedRegionOnly
1837 * true to just return the contigs intersecting with the
1841 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1843 int[] viscontigs = null;
1844 int start = 0, end = 0;
1845 if (selectedRegionOnly && selectionGroup != null)
1847 start = selectionGroup.getStartRes();
1848 end = selectionGroup.getEndRes() + 1;
1852 end = alignment.getWidth();
1854 viscontigs = colSel.getVisibleContigs(start, end);
1859 * get hash of undo and redo list for the alignment
1861 * @return long[] { historyList.hashCode, redoList.hashCode };
1863 public long[] getUndoRedoHash()
1865 if (historyList == null || redoList == null)
1869 { historyList.hashCode(), this.redoList.hashCode() };
1873 * test if a particular set of hashcodes are different to the hashcodes for
1874 * the undo and redo list.
1877 * the stored set of hashcodes as returned by getUndoRedoHash
1878 * @return true if the hashcodes differ (ie the alignment has been edited) or
1879 * the stored hashcode array differs in size
1881 public boolean isUndoRedoHashModified(long[] undoredo)
1883 if (undoredo == null)
1887 long[] cstate = getUndoRedoHash();
1888 if (cstate.length != undoredo.length)
1893 for (int i = 0; i < cstate.length; i++)
1895 if (cstate[i] != undoredo[i])
1903 public boolean getCentreColumnLabels()
1905 return centreColumnLabels;
1908 public void setCentreColumnLabels(boolean centrecolumnlabels)
1910 centreColumnLabels = centrecolumnlabels;
1913 public void updateSequenceIdColours()
1915 Vector groups = alignment.getGroups();
1916 if (sequenceColours == null)
1918 sequenceColours = new Hashtable();
1920 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1922 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1923 if (sg.idColour != null)
1925 Vector sqs = sg.getSequences(hiddenRepSequences);
1926 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1928 sequenceColours.put(sqs.elementAt(s), sg.idColour);
1935 * enable or disable the display of Database Cross References in the sequence ID tooltip
1937 public void setShowDbRefs(boolean show)
1944 * @return true if Database References are to be displayed on tooltips.
1946 public boolean isShowDbRefs()
1953 * @return true if Non-positional features are to be displayed on tooltips.
1955 public boolean isShowNpFeats()
1960 * enable or disable the display of Non-Positional sequence features in the sequence ID tooltip
1963 public void setShowNpFeats(boolean show)
1969 * @return true if view has hidden rows
1971 public boolean hasHiddenRows()
1973 return hasHiddenRows;
1977 * @return true if view has hidden columns
1979 public boolean hasHiddenColumns()
1981 return hasHiddenColumns;
1984 * when set, view will scroll to show the highlighted position
1986 public boolean followHighlight=true;
1988 * @return true if view should scroll to show the highlighted region of a sequence
1991 public boolean getFollowHighlight() {
1992 return followHighlight;
1994 public boolean followSelection=true;
1996 * @return true if view selection should always follow the selections broadcast by other selection sources
1998 public boolean getFollowSelection() {
1999 return followSelection;
2001 private long sgrouphash=-1,colselhash=-1;
2003 boolean showSeqFeaturesHeight;
2005 * checks current SelectionGroup against record of last hash value, and updates record.
2006 * @return true if SelectionGroup changed since last call
2008 boolean isSelectionGroupChanged() {
2009 int hc=(selectionGroup==null) ? -1 : selectionGroup.hashCode();
2018 * checks current colsel against record of last hash value, and updates record.
2019 * @return true if colsel changed since last call
2021 boolean isColSelChanged() {
2022 int hc=(colSel==null) ? -1 : colSel.hashCode();
2030 public void sendSelection()
2032 jalview.structure.StructureSelectionManager.getStructureSelectionManager().sendSelection(new SequenceGroup(getSelectionGroup()), new ColumnSelection(getColumnSelection()), this);
2034 public void setShowSequenceFeaturesHeight(boolean selected)
2036 showSeqFeaturesHeight = selected;
2038 public boolean getShowSequenceFeaturesHeight()
2040 return showSeqFeaturesHeight;
2042 boolean showUnconserved=false;
2043 public boolean getShowUnconserved()
2045 return showUnconserved;
2047 public void setShowUnconserved(boolean showunconserved)
2049 showUnconserved=showunconserved;
2052 * return the alignPanel containing the given viewport. Use this to get the
2053 * components currently handling the given viewport.
2055 * @return null or an alignPanel guaranteed to have non-null alignFrame reference
2057 public AlignmentPanel getAlignPanel()
2059 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this.getSequenceSetId());
2060 AlignmentPanel ap=null;
2061 for (int p=0;aps!=null && p<aps.length; p++)
2063 if (aps[p].av == this)
2070 public boolean getSortByTree()
2074 public void setSortByTree(boolean sort) {
2078 * should conservation rows be shown for groups
2080 boolean showGroupConservation = false;
2082 * should consensus rows be shown for groups
2084 boolean showGroupConsensus = false;
2087 * @return the showGroupConservation
2089 public boolean isShowGroupConservation()
2091 return showGroupConservation;
2094 * @param showGroupConservation the showGroupConservation to set
2096 public void setShowGroupConservation(boolean showGroupConservation)
2098 this.showGroupConservation = showGroupConservation;
2101 * @return the showGroupConsensus
2103 public boolean isShowGroupConsensus()
2105 return showGroupConsensus;
2108 * @param showGroupConsensus the showGroupConsensus to set
2110 public void setShowGroupConsensus(boolean showGroupConsensus)
2112 this.showGroupConsensus = showGroupConsensus;
2115 * @return the includeAllConsensusSymbols
2117 public boolean isIncludeAllConsensusSymbols()
2119 return includeAllConsensusSymbols;
2122 * @param includeAllConsensusSymbols the includeAllConsensusSymbols to set
2124 public void setIncludeAllConsensusSymbols(boolean includeAllConsensusSymbols)
2126 this.includeAllConsensusSymbols = includeAllConsensusSymbols;