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);
353 // 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
354 consensus = new AlignmentAnnotation("Consensus", "PID",
355 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
356 consensus.hasText = true;
357 consensus.autoCalculated = true;
359 if (Cache.getDefault("SHOW_IDENTITY", true))
361 alignment.addAnnotation(consensus);
365 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
367 globalColourScheme = ColourSchemeProperty.getColour(alignment,
368 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
370 if (globalColourScheme instanceof UserColourScheme)
372 globalColourScheme = UserDefinedColours.loadDefaultColours();
373 ((UserColourScheme) globalColourScheme).setThreshold(0,
374 getIgnoreGapsConsensus());
377 if (globalColourScheme != null)
379 globalColourScheme.setConsensus(hconsensus);
383 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
384 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED", false);
385 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
392 * features are displayed if true
394 public void setShowSequenceFeatures(boolean b)
396 showSequenceFeatures = b;
399 public boolean getShowSequenceFeatures()
401 return showSequenceFeatures;
404 ConservationThread conservationThread;
406 ConsensusThread consensusThread;
408 boolean consUpdateNeeded = false;
410 static boolean UPDATING_CONSENSUS = false;
412 static boolean UPDATING_CONSERVATION = false;
414 boolean updatingConsensus = false;
416 boolean updatingConservation = false;
419 * centre columnar annotation labels in displayed alignment annotation TODO:
420 * add to jalviewXML and annotation display settings
422 boolean centreColumnLabels = false;
424 private boolean showdbrefs;
426 private boolean shownpfeats;
429 * consensus annotation includes all percentage for all symbols in column
431 private boolean includeAllConsensusSymbols=true;
434 * trigger update of conservation annotation
436 public void updateConservation(final AlignmentPanel ap)
438 // see note in mantis : issue number 8585
439 if (alignment.isNucleotide() || conservation == null || !autoCalculateConsensus)
444 conservationThread = new ConservationThread(this, ap);
445 conservationThread.start();
449 * trigger update of consensus annotation
451 public void updateConsensus(final AlignmentPanel ap)
453 // see note in mantis : issue number 8585
454 if (consensus == null || !autoCalculateConsensus)
458 consensusThread = new ConsensusThread(ap);
459 consensusThread.start();
462 class ConsensusThread extends Thread
466 public ConsensusThread(AlignmentPanel ap)
473 updatingConsensus = true;
474 while (UPDATING_CONSENSUS)
480 ap.paintAlignment(false);
484 } catch (Exception ex)
486 ex.printStackTrace();
490 UPDATING_CONSENSUS = true;
494 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
503 consensus.annotations = null;
504 consensus.annotations = new Annotation[aWidth];
506 hconsensus = new Hashtable[aWidth];
507 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
508 .getWidth(), hconsensus, includeAllConsensusSymbols);
509 AAFrequency.completeConsensus(consensus,hconsensus,0,aWidth,ignoreGapsInConsensusCalculation, includeAllConsensusSymbols);
511 if (globalColourScheme != null)
513 globalColourScheme.setConsensus(hconsensus);
516 } catch (OutOfMemoryError error)
518 alignment.deleteAnnotation(consensus);
522 new OOMWarning("calculating consensus", error);
524 UPDATING_CONSENSUS = false;
525 updatingConsensus = false;
529 ap.paintAlignment(true);
535 * get the consensus sequence as displayed under the PID consensus annotation
538 * @return consensus sequence as a new sequence object
540 public SequenceI getConsensusSeq()
542 if (consensus == null)
544 updateConsensus(null);
546 if (consensus == null)
550 StringBuffer seqs = new StringBuffer();
551 for (int i = 0; i < consensus.annotations.length; i++)
553 if (consensus.annotations[i] != null)
555 if (consensus.annotations[i].description.charAt(0) == '[')
557 seqs.append(consensus.annotations[i].description.charAt(1));
561 seqs.append(consensus.annotations[i].displayCharacter);
566 SequenceI sq = new Sequence("Consensus", seqs.toString());
567 sq.setDescription("Percentage Identity Consensus "
568 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
575 * @return DOCUMENT ME!
577 public SequenceGroup getSelectionGroup()
579 return selectionGroup;
588 public void setSelectionGroup(SequenceGroup sg)
596 * @return DOCUMENT ME!
598 public boolean getConservationSelected()
600 return conservationColourSelected;
609 public void setConservationSelected(boolean b)
611 conservationColourSelected = b;
617 * @return DOCUMENT ME!
619 public boolean getAbovePIDThreshold()
621 return abovePIDThreshold;
630 public void setAbovePIDThreshold(boolean b)
632 abovePIDThreshold = b;
638 * @return DOCUMENT ME!
640 public int getStartRes()
648 * @return DOCUMENT ME!
650 public int getEndRes()
658 * @return DOCUMENT ME!
660 public int getStartSeq()
671 public void setGlobalColourScheme(ColourSchemeI cs)
673 globalColourScheme = cs;
679 * @return DOCUMENT ME!
681 public ColourSchemeI getGlobalColourScheme()
683 return globalColourScheme;
692 public void setStartRes(int res)
703 public void setStartSeq(int seq)
714 public void setEndRes(int res)
716 if (res > (alignment.getWidth() - 1))
718 // log.System.out.println(" Corrected res from " + res + " to maximum " +
719 // (alignment.getWidth()-1));
720 res = alignment.getWidth() - 1;
737 public void setEndSeq(int seq)
739 if (seq > alignment.getHeight())
741 seq = alignment.getHeight();
755 * @return DOCUMENT ME!
757 public int getEndSeq()
768 public void setFont(Font f)
772 Container c = new Container();
774 java.awt.FontMetrics fm = c.getFontMetrics(font);
775 setCharHeight(fm.getHeight());
776 setCharWidth(fm.charWidth('M'));
777 validCharWidth = true;
783 * @return DOCUMENT ME!
785 public Font getFont()
796 public void setCharWidth(int w)
804 * @return DOCUMENT ME!
806 public int getCharWidth()
817 public void setCharHeight(int h)
825 * @return DOCUMENT ME!
827 public int getCharHeight()
838 public void setWrappedWidth(int w)
840 this.wrappedWidth = w;
846 * @return DOCUMENT ME!
848 public int getWrappedWidth()
856 * @return DOCUMENT ME!
858 public AlignmentI getAlignment()
869 public void setAlignment(AlignmentI align)
871 if (alignment != null && alignment.getCodonFrames() != null)
873 StructureSelectionManager.getStructureSelectionManager()
874 .removeMappings(alignment.getCodonFrames());
876 this.alignment = align;
877 if (alignment.getCodonFrames() != null)
879 StructureSelectionManager.getStructureSelectionManager().addMappings(
880 alignment.getCodonFrames());
890 public void setWrapAlignment(boolean state)
892 wrapAlignment = state;
901 public void setShowText(boolean state)
912 public void setRenderGaps(boolean state)
920 * @return DOCUMENT ME!
922 public boolean getColourText()
924 return showColourText;
933 public void setColourText(boolean state)
935 showColourText = state;
944 public void setShowBoxes(boolean state)
952 * @return DOCUMENT ME!
954 public boolean getWrapAlignment()
956 return wrapAlignment;
962 * @return DOCUMENT ME!
964 public boolean getShowText()
972 * @return DOCUMENT ME!
974 public boolean getShowBoxes()
982 * @return DOCUMENT ME!
984 public char getGapCharacter()
986 return getAlignment().getGapCharacter();
995 public void setGapCharacter(char gap)
997 if (getAlignment() != null)
999 getAlignment().setGapCharacter(gap);
1009 public void setThreshold(int thresh)
1017 * @return DOCUMENT ME!
1019 public int getThreshold()
1030 public void setIncrement(int inc)
1038 * @return DOCUMENT ME!
1040 public int getIncrement()
1048 * @return DOCUMENT ME!
1050 public ColumnSelection getColumnSelection()
1061 public void setCurrentTree(NJTree tree)
1069 * @return DOCUMENT ME!
1071 public NJTree getCurrentTree()
1082 public void setColourAppliesToAllGroups(boolean b)
1084 colourAppliesToAllGroups = b;
1090 * @return DOCUMENT ME!
1092 public boolean getColourAppliesToAllGroups()
1094 return colourAppliesToAllGroups;
1100 * @return DOCUMENT ME!
1102 public boolean getShowJVSuffix()
1104 return showJVSuffix;
1113 public void setShowJVSuffix(boolean b)
1121 * @return DOCUMENT ME!
1123 public boolean getShowAnnotation()
1125 return showAnnotation;
1134 public void setShowAnnotation(boolean b)
1142 * @return DOCUMENT ME!
1144 public boolean getScaleAboveWrapped()
1146 return scaleAboveWrapped;
1152 * @return DOCUMENT ME!
1154 public boolean getScaleLeftWrapped()
1156 return scaleLeftWrapped;
1162 * @return DOCUMENT ME!
1164 public boolean getScaleRightWrapped()
1166 return scaleRightWrapped;
1175 public void setScaleAboveWrapped(boolean b)
1177 scaleAboveWrapped = b;
1186 public void setScaleLeftWrapped(boolean b)
1188 scaleLeftWrapped = b;
1197 public void setScaleRightWrapped(boolean b)
1199 scaleRightWrapped = b;
1203 * Property change listener for changes in alignment
1208 public void addPropertyChangeListener(
1209 java.beans.PropertyChangeListener listener)
1211 changeSupport.addPropertyChangeListener(listener);
1220 public void removePropertyChangeListener(
1221 java.beans.PropertyChangeListener listener)
1223 changeSupport.removePropertyChangeListener(listener);
1227 * Property change listener for changes in alignment
1236 public void firePropertyChange(String prop, Object oldvalue,
1239 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1242 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1244 ignoreGapsInConsensusCalculation = b;
1245 updateConsensus(ap);
1246 if (globalColourScheme != null)
1248 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1249 ignoreGapsInConsensusCalculation);
1253 public boolean getIgnoreGapsConsensus()
1255 return ignoreGapsInConsensusCalculation;
1258 public void setDataset(boolean b)
1263 public boolean isDataset()
1268 public void hideSelectedColumns()
1270 if (colSel.size() < 1)
1275 colSel.hideSelectedColumns();
1276 setSelectionGroup(null);
1278 hasHiddenColumns = true;
1281 public void hideColumns(int start, int end)
1285 colSel.hideColumns(start);
1289 colSel.hideColumns(start, end);
1292 hasHiddenColumns = true;
1295 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1297 int sSize = sg.getSize();
1303 if (hiddenRepSequences == null)
1305 hiddenRepSequences = new Hashtable();
1308 hiddenRepSequences.put(repSequence, sg);
1310 // Hide all sequences except the repSequence
1311 SequenceI[] seqs = new SequenceI[sSize - 1];
1313 for (int i = 0; i < sSize; i++)
1315 if (sg.getSequenceAt(i) != repSequence)
1317 if (index == sSize - 1)
1322 seqs[index++] = sg.getSequenceAt(i);
1325 sg.setSeqrep(repSequence);
1326 sg.setHidereps(true);
1331 public void hideAllSelectedSeqs()
1333 if (selectionGroup == null || selectionGroup.getSize() < 1)
1338 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1342 setSelectionGroup(null);
1345 public void hideSequence(SequenceI[] seq)
1349 for (int i = 0; i < seq.length; i++)
1351 alignment.getHiddenSequences().hideSequence(seq[i]);
1353 hasHiddenRows = true;
1354 firePropertyChange("alignment", null, alignment.getSequences());
1358 public void showSequence(int index)
1360 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1361 hiddenRepSequences);
1364 if (selectionGroup == null)
1366 selectionGroup = new SequenceGroup();
1367 selectionGroup.setEndRes(alignment.getWidth() - 1);
1370 for (int t = 0; t < tmp.size(); t++)
1372 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1374 firePropertyChange("alignment", null, alignment.getSequences());
1378 if (alignment.getHiddenSequences().getSize() < 1)
1380 hasHiddenRows = false;
1384 public void showColumn(int col)
1386 colSel.revealHiddenColumns(col);
1387 if (colSel.getHiddenColumns() == null)
1389 hasHiddenColumns = false;
1393 public void showAllHiddenColumns()
1395 colSel.revealAllHiddenColumns();
1396 hasHiddenColumns = false;
1399 public void showAllHiddenSeqs()
1401 if (alignment.getHiddenSequences().getSize() > 0)
1403 if (selectionGroup == null)
1405 selectionGroup = new SequenceGroup();
1406 selectionGroup.setEndRes(alignment.getWidth() - 1);
1408 Vector tmp = alignment.getHiddenSequences().showAll(
1409 hiddenRepSequences);
1410 for (int t = 0; t < tmp.size(); t++)
1412 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1414 firePropertyChange("alignment", null, alignment.getSequences());
1416 hasHiddenRows = false;
1417 hiddenRepSequences = null;
1421 public void invertColumnSelection()
1423 colSel.invertColumnSelection(0, alignment.getWidth());
1426 public int adjustForHiddenSeqs(int alignmentIndex)
1428 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1433 * This method returns an array of new SequenceI objects derived from the
1434 * whole alignment or just the current selection with start and end points
1437 * @note if you need references to the actual SequenceI objects in the
1438 * alignment or currently selected then use getSequenceSelection()
1439 * @return selection as new sequenceI objects
1441 public SequenceI[] getSelectionAsNewSequence()
1443 SequenceI[] sequences;
1445 if (selectionGroup == null)
1447 sequences = alignment.getSequencesArray();
1448 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1449 for (int i = 0; i < sequences.length; i++)
1451 sequences[i] = new Sequence(sequences[i], annots); // construct new
1453 // subset of visible
1459 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1466 * get the currently selected sequence objects or all the sequences in the
1469 * @return array of references to sequence objects
1471 public SequenceI[] getSequenceSelection()
1473 SequenceI[] sequences=null;
1474 if (selectionGroup!=null)
1476 sequences = selectionGroup.getSequencesInOrder(alignment);
1478 if (sequences == null)
1480 sequences = alignment.getSequencesArray();
1486 * This method returns the visible alignment as text, as seen on the GUI, ie
1487 * if columns are hidden they will not be returned in the result. Use this for
1488 * calculating trees, PCA, redundancy etc on views which contain hidden
1493 public jalview.datamodel.CigarArray getViewAsCigars(
1494 boolean selectedRegionOnly)
1496 CigarArray selection = null;
1497 SequenceI[] seqs = null;
1499 int start = 0, end = 0;
1500 if (selectedRegionOnly && selectionGroup != null)
1502 iSize = selectionGroup.getSize();
1503 seqs = selectionGroup.getSequencesInOrder(alignment);
1504 start = selectionGroup.getStartRes();
1505 end = selectionGroup.getEndRes(); // inclusive for start and end in
1506 // SeqCigar constructor
1510 iSize = alignment.getHeight();
1511 seqs = alignment.getSequencesArray();
1512 end = alignment.getWidth() - 1;
1514 SeqCigar[] selseqs = new SeqCigar[iSize];
1515 for (i = 0; i < iSize; i++)
1517 selseqs[i] = new SeqCigar(seqs[i], start, end);
1519 selection = new CigarArray(selseqs);
1520 // now construct the CigarArray operations
1521 if (hasHiddenColumns)
1523 Vector regions = colSel.getHiddenColumns();
1525 int hideStart, hideEnd;
1527 for (int j = 0; last < end & j < regions.size(); j++)
1529 region = (int[]) regions.elementAt(j);
1530 hideStart = region[0];
1531 hideEnd = region[1];
1532 // edit hidden regions to selection range
1533 if (hideStart < last)
1545 if (hideStart > end)
1555 if (hideStart > hideEnd)
1560 * form operations...
1562 if (last < hideStart)
1564 selection.addOperation(CigarArray.M, hideStart - last);
1566 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1569 // Final match if necessary.
1572 selection.addOperation(CigarArray.M, end - last + 1);
1577 selection.addOperation(CigarArray.M, end - start + 1);
1583 * return a compact representation of the current alignment selection to pass
1584 * to an analysis function
1586 * @param selectedOnly
1587 * boolean true to just return the selected view
1588 * @return AlignmentView
1590 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1593 // this is here because the AlignmentView constructor modifies the
1595 // object. Refactoring of Cigar and alignment view representation should
1596 // be done to remove redundancy.
1597 CigarArray aligview = getViewAsCigars(selectedOnly);
1598 if (aligview != null)
1600 return new AlignmentView(aligview,
1601 (selectedOnly && selectionGroup != null) ? selectionGroup
1602 .getStartRes() : 0);
1608 * This method returns the visible alignment as text, as seen on the GUI, ie
1609 * if columns are hidden they will not be returned in the result. Use this for
1610 * calculating trees, PCA, redundancy etc on views which contain hidden
1615 public String[] getViewAsString(boolean selectedRegionOnly)
1617 String[] selection = null;
1618 SequenceI[] seqs = null;
1620 int start = 0, end = 0;
1621 if (selectedRegionOnly && selectionGroup != null)
1623 iSize = selectionGroup.getSize();
1624 seqs = selectionGroup.getSequencesInOrder(alignment);
1625 start = selectionGroup.getStartRes();
1626 end = selectionGroup.getEndRes() + 1;
1630 iSize = alignment.getHeight();
1631 seqs = alignment.getSequencesArray();
1632 end = alignment.getWidth();
1635 selection = new String[iSize];
1636 if (hasHiddenColumns)
1638 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1642 for (i = 0; i < iSize; i++)
1644 selection[i] = seqs[i].getSequenceAsString(start, end);
1651 public int[][] getVisibleRegionBoundaries(int min, int max)
1653 Vector regions = new Vector();
1659 if (hasHiddenColumns)
1663 start = colSel.adjustForHiddenColumns(start);
1666 end = colSel.getHiddenBoundaryRight(start);
1677 regions.addElement(new int[]
1680 if (hasHiddenColumns)
1682 start = colSel.adjustForHiddenColumns(end);
1683 start = colSel.getHiddenBoundaryLeft(start) + 1;
1685 } while (end < max);
1687 int[][] startEnd = new int[regions.size()][2];
1689 regions.copyInto(startEnd);
1695 public boolean getShowHiddenMarkers()
1697 return showHiddenMarkers;
1700 public void setShowHiddenMarkers(boolean show)
1702 showHiddenMarkers = show;
1705 public String getSequenceSetId()
1707 if (sequenceSetID == null)
1709 sequenceSetID = alignment.hashCode() + "";
1712 return sequenceSetID;
1715 * unique viewId for synchronizing state with stored Jalview Project
1718 private String viewId=null;
1721 public String getViewId()
1725 viewId = this.getSequenceSetId()+"."+this.hashCode()+"";
1730 public void alignmentChanged(AlignmentPanel ap)
1734 alignment.padGaps();
1736 if (hconsensus != null && autoCalculateConsensus)
1738 updateConservation(ap);
1740 if (autoCalculateConsensus)
1742 updateConsensus(ap);
1745 // Reset endRes of groups if beyond alignment width
1746 int alWidth = alignment.getWidth();
1747 Vector groups = alignment.getGroups();
1750 for (int i = 0; i < groups.size(); i++)
1752 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1753 if (sg.getEndRes() > alWidth)
1755 sg.setEndRes(alWidth - 1);
1760 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1762 selectionGroup.setEndRes(alWidth - 1);
1765 resetAllColourSchemes();
1767 // alignment.adjustSequenceAnnotations();
1770 void resetAllColourSchemes()
1772 ColourSchemeI cs = globalColourScheme;
1775 if (cs instanceof ClustalxColourScheme)
1777 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1778 alignment.getWidth());
1781 cs.setConsensus(hconsensus);
1782 if (cs.conservationApplied())
1784 Alignment al = (Alignment) alignment;
1785 Conservation c = new Conservation("All",
1786 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1789 c.verdict(false, ConsPercGaps);
1791 cs.setConservation(c);
1795 int s, sSize = alignment.getGroups().size();
1796 for (s = 0; s < sSize; s++)
1798 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1799 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1801 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1802 .getSequences(hiddenRepSequences), sg.getWidth());
1804 sg.recalcConservation();
1808 public Color getSequenceColour(SequenceI seq)
1810 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1816 return (Color) sequenceColours.get(seq);
1820 public void setSequenceColour(SequenceI seq, Color col)
1822 if (sequenceColours == null)
1824 sequenceColours = new Hashtable();
1829 sequenceColours.remove(seq);
1833 sequenceColours.put(seq, col);
1838 * returns the visible column regions of the alignment
1840 * @param selectedRegionOnly
1841 * true to just return the contigs intersecting with the
1845 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1847 int[] viscontigs = null;
1848 int start = 0, end = 0;
1849 if (selectedRegionOnly && selectionGroup != null)
1851 start = selectionGroup.getStartRes();
1852 end = selectionGroup.getEndRes() + 1;
1856 end = alignment.getWidth();
1858 viscontigs = colSel.getVisibleContigs(start, end);
1863 * get hash of undo and redo list for the alignment
1865 * @return long[] { historyList.hashCode, redoList.hashCode };
1867 public long[] getUndoRedoHash()
1869 if (historyList == null || redoList == null)
1873 { historyList.hashCode(), this.redoList.hashCode() };
1877 * test if a particular set of hashcodes are different to the hashcodes for
1878 * the undo and redo list.
1881 * the stored set of hashcodes as returned by getUndoRedoHash
1882 * @return true if the hashcodes differ (ie the alignment has been edited) or
1883 * the stored hashcode array differs in size
1885 public boolean isUndoRedoHashModified(long[] undoredo)
1887 if (undoredo == null)
1891 long[] cstate = getUndoRedoHash();
1892 if (cstate.length != undoredo.length)
1897 for (int i = 0; i < cstate.length; i++)
1899 if (cstate[i] != undoredo[i])
1907 public boolean getCentreColumnLabels()
1909 return centreColumnLabels;
1912 public void setCentreColumnLabels(boolean centrecolumnlabels)
1914 centreColumnLabels = centrecolumnlabels;
1917 public void updateSequenceIdColours()
1919 Vector groups = alignment.getGroups();
1920 if (sequenceColours == null)
1922 sequenceColours = new Hashtable();
1924 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1926 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1927 if (sg.idColour != null)
1929 Vector sqs = sg.getSequences(hiddenRepSequences);
1930 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1932 sequenceColours.put(sqs.elementAt(s), sg.idColour);
1939 * enable or disable the display of Database Cross References in the sequence ID tooltip
1941 public void setShowDbRefs(boolean show)
1948 * @return true if Database References are to be displayed on tooltips.
1950 public boolean isShowDbRefs()
1957 * @return true if Non-positional features are to be displayed on tooltips.
1959 public boolean isShowNpFeats()
1964 * enable or disable the display of Non-Positional sequence features in the sequence ID tooltip
1967 public void setShowNpFeats(boolean show)
1973 * @return true if view has hidden rows
1975 public boolean hasHiddenRows()
1977 return hasHiddenRows;
1981 * @return true if view has hidden columns
1983 public boolean hasHiddenColumns()
1985 return hasHiddenColumns;
1988 * when set, view will scroll to show the highlighted position
1990 public boolean followHighlight=true;
1992 * @return true if view should scroll to show the highlighted region of a sequence
1995 public boolean getFollowHighlight() {
1996 return followHighlight;
1998 public boolean followSelection=true;
2000 * @return true if view selection should always follow the selections broadcast by other selection sources
2002 public boolean getFollowSelection() {
2003 return followSelection;
2005 private long sgrouphash=-1,colselhash=-1;
2007 boolean showSeqFeaturesHeight;
2009 * checks current SelectionGroup against record of last hash value, and updates record.
2010 * @return true if SelectionGroup changed since last call
2012 boolean isSelectionGroupChanged() {
2013 int hc=(selectionGroup==null) ? -1 : selectionGroup.hashCode();
2022 * checks current colsel against record of last hash value, and updates record.
2023 * @return true if colsel changed since last call
2025 boolean isColSelChanged() {
2026 int hc=(colSel==null) ? -1 : colSel.hashCode();
2034 public void sendSelection()
2036 jalview.structure.StructureSelectionManager.getStructureSelectionManager().sendSelection(new SequenceGroup(getSelectionGroup()), new ColumnSelection(getColumnSelection()), this);
2038 public void setShowSequenceFeaturesHeight(boolean selected)
2040 showSeqFeaturesHeight = selected;
2042 public boolean getShowSequenceFeaturesHeight()
2044 return showSeqFeaturesHeight;
2046 boolean showUnconserved=false;
2047 public boolean getShowUnconserved()
2049 return showUnconserved;
2051 public void setShowUnconserved(boolean showunconserved)
2053 showUnconserved=showunconserved;
2056 * return the alignPanel containing the given viewport. Use this to get the
2057 * components currently handling the given viewport.
2059 * @return null or an alignPanel guaranteed to have non-null alignFrame reference
2061 public AlignmentPanel getAlignPanel()
2063 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this.getSequenceSetId());
2064 AlignmentPanel ap=null;
2065 for (int p=0;aps!=null && p<aps.length; p++)
2067 if (aps[p].av == this)
2074 public boolean getSortByTree()
2078 public void setSortByTree(boolean sort) {
2082 * should conservation rows be shown for groups
2084 boolean showGroupConservation = false;
2086 * should consensus rows be shown for groups
2088 boolean showGroupConsensus = false;
2091 * @return the showGroupConservation
2093 public boolean isShowGroupConservation()
2095 return showGroupConservation;
2098 * @param showGroupConservation the showGroupConservation to set
2100 public void setShowGroupConservation(boolean showGroupConservation)
2102 this.showGroupConservation = showGroupConservation;
2105 * @return the showGroupConsensus
2107 public boolean isShowGroupConsensus()
2109 return showGroupConsensus;
2112 * @param showGroupConsensus the showGroupConsensus to set
2114 public void setShowGroupConsensus(boolean showGroupConsensus)
2116 this.showGroupConsensus = showGroupConsensus;
2119 * @return the includeAllConsensusSymbols
2121 public boolean isIncludeAllConsensusSymbols()
2123 return includeAllConsensusSymbols;
2126 * @param includeAllConsensusSymbols the includeAllConsensusSymbols to set
2128 public void setIncludeAllConsensusSymbols(boolean includeAllConsensusSymbols)
2130 this.includeAllConsensusSymbols = includeAllConsensusSymbols;