2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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.StructureSelectionManager;
58 public class AlignViewport
64 boolean showJVSuffix = true;
65 boolean showText = true;
66 boolean showColourText = false;
67 boolean showBoxes = true;
68 boolean wrapAlignment = false;
69 boolean renderGaps = true;
70 boolean showSequenceFeatures = false;
71 boolean showAnnotation = true;
72 boolean colourAppliesToAllGroups = true;
73 ColourSchemeI globalColourScheme = null;
74 boolean conservationColourSelected = false;
75 boolean abovePIDThreshold = false;
76 SequenceGroup selectionGroup;
79 boolean validCharWidth;
82 boolean seqNameItalics;
84 ColumnSelection colSel = new ColumnSelection();
87 NJTree currentTree = null;
88 boolean scaleAboveWrapped = false;
89 boolean scaleLeftWrapped = true;
90 boolean scaleRightWrapped = true;
91 boolean hasHiddenColumns = false;
92 boolean hasHiddenRows = false;
93 boolean showHiddenMarkers = true;
95 boolean cursorMode = false;
97 // The following vector holds the features which are
98 // currently visible, in the correct order or rendering
99 Hashtable featuresDisplayed = null;
103 public Hashtable [] hconsensus;
104 AlignmentAnnotation consensus;
105 AlignmentAnnotation conservation;
106 AlignmentAnnotation quality;
107 boolean autoCalculateConsensus = true;
110 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
112 // JBPNote Prolly only need this in the applet version.
113 private java.beans.PropertyChangeSupport changeSupport = new java.beans.
114 PropertyChangeSupport(this);
116 boolean ignoreGapsInConsensusCalculation = false;
118 boolean isDataset = false;
120 boolean antiAlias = false;
122 boolean padGaps = false;
124 Rectangle explodedPosition;
128 String sequenceSetID;
130 boolean gatherViewsHere = false;
132 Stack historyList = new Stack();
133 Stack redoList = new Stack();
135 Hashtable sequenceColours;
137 int thresholdTextColour = 0;
138 Color textColour = Color.black;
139 Color textColour2 = Color.white;
141 boolean rightAlignIds = false;
143 Hashtable hiddenRepSequences;
147 * Creates a new AlignViewport object.
149 * @param al DOCUMENT ME!
151 public AlignViewport(AlignmentI al)
157 * Create a new AlignViewport with hidden regions
158 * @param al AlignmentI
159 * @param hiddenColumns ColumnSelection
161 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
164 if (hiddenColumns != null)
166 this.colSel = hiddenColumns;
167 if (hiddenColumns.getHiddenColumns() != null)
169 hasHiddenColumns = true;
178 this.endRes = alignment.getWidth() - 1;
180 this.endSeq = alignment.getHeight() - 1;
182 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
184 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
185 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
187 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
188 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
189 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
191 padGaps = Cache.getDefault("PAD_GAPS", true);
193 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
194 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;
195 String fontSize = Cache.getDefault("FONT_SIZE", "10");
197 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
201 if (fontStyle.equals("bold"))
205 else if (fontStyle.equals("italic"))
210 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
212 alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );
215 // We must set conservation and consensus before setting colour,
216 // as Blosum and Clustal require this to be done
217 if(hconsensus==null && !isDataset)
219 if(!alignment.isNucleotide())
221 conservation = new AlignmentAnnotation("Conservation",
222 "Conservation of total alignment less than " +
223 ConsPercGaps + "% gaps",
224 new Annotation[1], 0f,
226 AlignmentAnnotation.BAR_GRAPH);
227 conservation.hasText = true;
228 conservation.autoCalculated=true;
231 if (Cache.getDefault("SHOW_CONSERVATION", true))
233 alignment.addAnnotation(conservation);
236 if (Cache.getDefault("SHOW_QUALITY", true))
238 quality = new AlignmentAnnotation("Quality",
239 "Alignment Quality based on Blosum62 scores",
243 AlignmentAnnotation.BAR_GRAPH);
244 quality.hasText = true;
245 quality.autoCalculated=true;
247 alignment.addAnnotation(quality);
251 consensus = new AlignmentAnnotation("Consensus", "PID",
252 new Annotation[1], 0f, 100f,
253 AlignmentAnnotation.BAR_GRAPH);
254 consensus.hasText = true;
255 consensus.autoCalculated=true;
257 if (Cache.getDefault("SHOW_IDENTITY", true))
259 alignment.addAnnotation(consensus);
263 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
265 globalColourScheme = ColourSchemeProperty.getColour(alignment,
266 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
268 if (globalColourScheme instanceof UserColourScheme)
270 globalColourScheme = UserDefinedColours.loadDefaultColours();
271 ( (UserColourScheme) globalColourScheme).setThreshold(0,
272 getIgnoreGapsConsensus());
275 if (globalColourScheme != null)
277 globalColourScheme.setConsensus(hconsensus);
281 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
289 * @param b DOCUMENT ME!
291 public void setShowSequenceFeatures(boolean b)
293 showSequenceFeatures = b;
296 public boolean getShowSequenceFeatures()
298 return showSequenceFeatures;
301 class ConservationThread
305 public ConservationThread(AlignmentPanel ap)
314 updatingConservation = true;
316 while (UPDATING_CONSERVATION)
322 ap.paintAlignment(false);
328 ex.printStackTrace();
332 UPDATING_CONSERVATION = true;
335 int alWidth = alignment.getWidth();
341 Conservation cons = new jalview.analysis.Conservation("All",
342 jalview.schemes.ResidueProperties.propHash, 3,
343 alignment.getSequences(), 0, alWidth -1);
346 cons.verdict(false, ConsPercGaps);
353 char [] sequence = cons.getConsSequence().getSequence();
365 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
374 conservation.annotations = new Annotation[alWidth];
378 quality.graphMax = cons.qualityRange[1].floatValue();
379 quality.annotations = new Annotation[alWidth];
380 qmin = cons.qualityRange[0].floatValue();
381 qmax = cons.qualityRange[1].floatValue();
384 for (int i = 0; i < alWidth; i++)
390 if (Character.isDigit(c))
392 value = (int) (c - '0');
403 float vprop = value - min;
405 conservation.annotations[i] =
406 new Annotation(String.valueOf(c),
407 String.valueOf(value), ' ', value,
408 new Color(minR + (maxR * vprop),
409 minG + (maxG * vprop),
410 minB + (maxB * vprop)));
415 value = ( (Double) cons.quality.get(i)).floatValue();
416 vprop = value - qmin;
418 quality.annotations[i] = new Annotation(" ", String.valueOf(value),
421 new Color(minR + (maxR * vprop),
422 minG + (maxG * vprop),
423 minB + (maxB * vprop)));
427 catch (OutOfMemoryError error)
429 javax.swing.SwingUtilities.invokeLater(new Runnable()
435 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
436 "Out of memory calculating conservation!!"
438 "\nSee help files for increasing Java Virtual Machine memory."
440 javax.swing.JOptionPane.WARNING_MESSAGE);
447 System.out.println("Conservation calculation: " + error);
452 UPDATING_CONSERVATION = false;
453 updatingConservation = false;
457 ap.paintAlignment(true);
464 ConservationThread conservationThread;
466 ConsensusThread consensusThread;
468 boolean consUpdateNeeded = false;
470 static boolean UPDATING_CONSENSUS = false;
472 static boolean UPDATING_CONSERVATION = false;
474 boolean updatingConsensus = false;
476 boolean updatingConservation = false;
478 * centre columnar annotation labels in displayed alignment annotation
479 * TODO: add to jalviewXML and annotation display settings
481 boolean centreColumnLabels=false;
484 * trigger update of conservation annotation
486 public void updateConservation(final AlignmentPanel ap)
488 if (alignment.isNucleotide() || conservation==null)
493 conservationThread = new ConservationThread(ap);
494 conservationThread.start();
498 * trigger update of consensus annotation
500 public void updateConsensus(final AlignmentPanel ap)
502 consensusThread = new ConsensusThread(ap);
503 consensusThread.start();
506 class ConsensusThread
510 public ConsensusThread(AlignmentPanel ap)
516 updatingConsensus = true;
517 while (UPDATING_CONSENSUS)
523 ap.paintAlignment(false);
530 ex.printStackTrace();
535 UPDATING_CONSENSUS = true;
539 int aWidth = (alignment!=null) ? alignment.getWidth() : 0; // null pointer possibility here.
545 consensus.annotations = null;
546 consensus.annotations = new Annotation[aWidth];
549 hconsensus = new Hashtable[aWidth];
550 AAFrequency.calculate(alignment.getSequencesArray(),
552 alignment.getWidth(),
555 for (int i = 0; i < aWidth; i++)
558 if (ignoreGapsInConsensusCalculation)
560 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
565 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
569 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
570 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
572 if (maxRes.length() > 1)
574 mouseOver = "[" + maxRes + "] ";
578 mouseOver += ( (int) value + "%");
579 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
584 if (globalColourScheme != null)
586 globalColourScheme.setConsensus(hconsensus);
590 catch (OutOfMemoryError error)
592 alignment.deleteAnnotation(consensus);
596 javax.swing.SwingUtilities.invokeLater(new Runnable()
600 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
601 "Out of memory calculating consensus!!"
603 "\nSee help files for increasing Java Virtual Machine memory."
605 javax.swing.JOptionPane.WARNING_MESSAGE);
609 System.out.println("Consensus calculation: " + error);
612 UPDATING_CONSENSUS = false;
613 updatingConsensus = false;
617 ap.paintAlignment(true);
622 * get the consensus sequence as displayed under the PID consensus annotation row.
623 * @return consensus sequence as a new sequence object
625 public SequenceI getConsensusSeq()
629 updateConsensus(null);
635 StringBuffer seqs=new StringBuffer();
636 for (int i = 0; i < consensus.annotations.length; i++)
638 if (consensus.annotations[i] != null)
640 if (consensus.annotations[i].description.charAt(0) == '[')
642 seqs.append(consensus.annotations[i].description.charAt(1));
646 seqs.append(consensus.annotations[i].displayCharacter);
651 SequenceI sq = new Sequence("Consensus", seqs.toString());
652 sq.setDescription("Percentage Identity Consensus " +
653 ( (ignoreGapsInConsensusCalculation) ? " without gaps" :
660 * @return DOCUMENT ME!
662 public SequenceGroup getSelectionGroup()
664 return selectionGroup;
670 * @param sg DOCUMENT ME!
672 public void setSelectionGroup(SequenceGroup sg)
680 * @return DOCUMENT ME!
682 public boolean getConservationSelected()
684 return conservationColourSelected;
690 * @param b DOCUMENT ME!
692 public void setConservationSelected(boolean b)
694 conservationColourSelected = b;
700 * @return DOCUMENT ME!
702 public boolean getAbovePIDThreshold()
704 return abovePIDThreshold;
710 * @param b DOCUMENT ME!
712 public void setAbovePIDThreshold(boolean b)
714 abovePIDThreshold = b;
720 * @return DOCUMENT ME!
722 public int getStartRes()
730 * @return DOCUMENT ME!
732 public int getEndRes()
740 * @return DOCUMENT ME!
742 public int getStartSeq()
750 * @param cs DOCUMENT ME!
752 public void setGlobalColourScheme(ColourSchemeI cs)
754 globalColourScheme = cs;
760 * @return DOCUMENT ME!
762 public ColourSchemeI getGlobalColourScheme()
764 return globalColourScheme;
770 * @param res DOCUMENT ME!
772 public void setStartRes(int res)
780 * @param seq DOCUMENT ME!
782 public void setStartSeq(int seq)
790 * @param res DOCUMENT ME!
792 public void setEndRes(int res)
794 if (res > (alignment.getWidth() - 1))
796 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
797 res = alignment.getWidth() - 1;
811 * @param seq DOCUMENT ME!
813 public void setEndSeq(int seq)
815 if (seq > alignment.getHeight())
817 seq = alignment.getHeight();
831 * @return DOCUMENT ME!
833 public int getEndSeq()
841 * @param f DOCUMENT ME!
843 public void setFont(Font f)
847 Container c = new Container();
849 java.awt.FontMetrics fm = c.getFontMetrics(font);
850 setCharHeight(fm.getHeight());
851 setCharWidth(fm.charWidth('M'));
852 validCharWidth = true;
858 * @return DOCUMENT ME!
860 public Font getFont()
868 * @param w DOCUMENT ME!
870 public void setCharWidth(int w)
878 * @return DOCUMENT ME!
880 public int getCharWidth()
888 * @param h DOCUMENT ME!
890 public void setCharHeight(int h)
898 * @return DOCUMENT ME!
900 public int getCharHeight()
908 * @param w DOCUMENT ME!
910 public void setWrappedWidth(int w)
912 this.wrappedWidth = w;
918 * @return DOCUMENT ME!
920 public int getWrappedWidth()
929 * @return DOCUMENT ME!
931 public AlignmentI getAlignment()
939 * @param align DOCUMENT ME!
941 public void setAlignment(AlignmentI align)
943 if (alignment!=null && alignment.getCodonFrames()!=null)
945 StructureSelectionManager.getStructureSelectionManager().removeMappings(alignment.getCodonFrames());
947 this.alignment = align;
948 if (alignment.getCodonFrames()!=null)
950 StructureSelectionManager.getStructureSelectionManager().addMappings(alignment.getCodonFrames());
957 * @param state DOCUMENT ME!
959 public void setWrapAlignment(boolean state)
961 wrapAlignment = state;
967 * @param state DOCUMENT ME!
969 public void setShowText(boolean state)
977 * @param state DOCUMENT ME!
979 public void setRenderGaps(boolean state)
987 * @return DOCUMENT ME!
989 public boolean getColourText()
991 return showColourText;
997 * @param state DOCUMENT ME!
999 public void setColourText(boolean state)
1001 showColourText = state;
1007 * @param state DOCUMENT ME!
1009 public void setShowBoxes(boolean state)
1017 * @return DOCUMENT ME!
1019 public boolean getWrapAlignment()
1021 return wrapAlignment;
1027 * @return DOCUMENT ME!
1029 public boolean getShowText()
1037 * @return DOCUMENT ME!
1039 public boolean getShowBoxes()
1047 * @return DOCUMENT ME!
1049 public char getGapCharacter()
1051 return getAlignment().getGapCharacter();
1057 * @param gap DOCUMENT ME!
1059 public void setGapCharacter(char gap)
1061 if (getAlignment() != null)
1063 getAlignment().setGapCharacter(gap);
1070 * @param thresh DOCUMENT ME!
1072 public void setThreshold(int thresh)
1080 * @return DOCUMENT ME!
1082 public int getThreshold()
1090 * @param inc DOCUMENT ME!
1092 public void setIncrement(int inc)
1100 * @return DOCUMENT ME!
1102 public int getIncrement()
1111 * @return DOCUMENT ME!
1113 public ColumnSelection getColumnSelection()
1122 * @param tree DOCUMENT ME!
1124 public void setCurrentTree(NJTree tree)
1132 * @return DOCUMENT ME!
1134 public NJTree getCurrentTree()
1142 * @param b DOCUMENT ME!
1144 public void setColourAppliesToAllGroups(boolean b)
1146 colourAppliesToAllGroups = b;
1152 * @return DOCUMENT ME!
1154 public boolean getColourAppliesToAllGroups()
1156 return colourAppliesToAllGroups;
1162 * @return DOCUMENT ME!
1164 public boolean getShowJVSuffix()
1166 return showJVSuffix;
1172 * @param b DOCUMENT ME!
1174 public void setShowJVSuffix(boolean b)
1183 * @return DOCUMENT ME!
1185 public boolean getShowAnnotation()
1187 return showAnnotation;
1193 * @param b DOCUMENT ME!
1195 public void setShowAnnotation(boolean b)
1203 * @return DOCUMENT ME!
1205 public boolean getScaleAboveWrapped()
1207 return scaleAboveWrapped;
1213 * @return DOCUMENT ME!
1215 public boolean getScaleLeftWrapped()
1217 return scaleLeftWrapped;
1223 * @return DOCUMENT ME!
1225 public boolean getScaleRightWrapped()
1227 return scaleRightWrapped;
1233 * @param b DOCUMENT ME!
1235 public void setScaleAboveWrapped(boolean b)
1237 scaleAboveWrapped = b;
1243 * @param b DOCUMENT ME!
1245 public void setScaleLeftWrapped(boolean b)
1247 scaleLeftWrapped = b;
1253 * @param b DOCUMENT ME!
1255 public void setScaleRightWrapped(boolean b)
1257 scaleRightWrapped = b;
1261 * Property change listener for changes in alignment
1263 * @param listener DOCUMENT ME!
1265 public void addPropertyChangeListener(
1266 java.beans.PropertyChangeListener listener)
1268 changeSupport.addPropertyChangeListener(listener);
1274 * @param listener DOCUMENT ME!
1276 public void removePropertyChangeListener(
1277 java.beans.PropertyChangeListener listener)
1279 changeSupport.removePropertyChangeListener(listener);
1283 * Property change listener for changes in alignment
1285 * @param prop DOCUMENT ME!
1286 * @param oldvalue DOCUMENT ME!
1287 * @param newvalue DOCUMENT ME!
1289 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
1291 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1294 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1296 ignoreGapsInConsensusCalculation = b;
1297 updateConsensus(ap);
1298 if(globalColourScheme!=null)
1300 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1301 ignoreGapsInConsensusCalculation);
1305 public boolean getIgnoreGapsConsensus()
1307 return ignoreGapsInConsensusCalculation;
1310 public void setDataset(boolean b)
1315 public boolean isDataset()
1321 public void hideSelectedColumns()
1323 if (colSel.size() < 1)
1328 colSel.hideSelectedColumns();
1329 setSelectionGroup(null);
1331 hasHiddenColumns = true;
1335 public void hideColumns(int start, int end)
1339 colSel.hideColumns(start);
1343 colSel.hideColumns(start, end);
1346 hasHiddenColumns = true;
1349 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1351 int sSize = sg.getSize();
1357 if(hiddenRepSequences==null)
1359 hiddenRepSequences = new Hashtable();
1362 hiddenRepSequences.put(repSequence, sg);
1364 //Hide all sequences except the repSequence
1365 SequenceI [] seqs = new SequenceI[sSize-1];
1367 for(int i=0; i<sSize; i++)
1369 if(sg.getSequenceAt(i)!=repSequence)
1376 seqs[index++] = sg.getSequenceAt(i);
1384 public void hideAllSelectedSeqs()
1386 if (selectionGroup == null || selectionGroup.getSize()<1)
1391 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1395 setSelectionGroup(null);
1398 public void hideSequence(SequenceI [] seq)
1402 for (int i = 0; i < seq.length; i++)
1404 alignment.getHiddenSequences().hideSequence(seq[i]);
1406 hasHiddenRows = true;
1407 firePropertyChange("alignment", null, alignment.getSequences());
1411 public void showSequence(int index)
1413 Vector tmp = alignment.getHiddenSequences().showSequence(index
1414 , hiddenRepSequences);
1417 if(selectionGroup==null)
1419 selectionGroup = new SequenceGroup();
1420 selectionGroup.setEndRes(alignment.getWidth()-1);
1423 for (int t = 0; t < tmp.size(); t++)
1425 selectionGroup.addSequence(
1426 (SequenceI) tmp.elementAt(t), false
1429 firePropertyChange("alignment", null, alignment.getSequences());
1432 if(alignment.getHiddenSequences().getSize()<1)
1434 hasHiddenRows = false;
1438 public void showColumn(int col)
1440 colSel.revealHiddenColumns(col);
1441 if(colSel.getHiddenColumns()==null)
1443 hasHiddenColumns = false;
1447 public void showAllHiddenColumns()
1449 colSel.revealAllHiddenColumns();
1450 hasHiddenColumns = false;
1453 public void showAllHiddenSeqs()
1455 if(alignment.getHiddenSequences().getSize()>0)
1457 if(selectionGroup==null)
1459 selectionGroup = new SequenceGroup();
1460 selectionGroup.setEndRes(alignment.getWidth()-1);
1462 Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
1463 for(int t=0; t<tmp.size(); t++)
1465 selectionGroup.addSequence(
1466 (SequenceI)tmp.elementAt(t), false
1469 firePropertyChange("alignment", null, alignment.getSequences());
1470 hasHiddenRows = false;
1471 hiddenRepSequences = null;
1477 public void invertColumnSelection()
1479 colSel.invertColumnSelection(0,alignment.getWidth());
1482 public int adjustForHiddenSeqs(int alignmentIndex)
1484 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
1488 * This method returns an array of new SequenceI objects
1489 * derived from the whole alignment or just the current
1490 * selection with start and end points adjusted
1491 * @note if you need references to the actual SequenceI objects in the alignment or currently selected then use getSequenceSelection()
1492 * @return selection as new sequenceI objects
1494 public SequenceI[] getSelectionAsNewSequence()
1496 SequenceI[] sequences;
1498 if (selectionGroup == null)
1500 sequences = alignment.getSequencesArray();
1501 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1502 for (int i=0; i<sequences.length; i++)
1504 sequences[i] = new Sequence(sequences[i], annots); // construct new sequence with subset of visible annotation
1509 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1516 * get the currently selected sequence objects or all the sequences in the alignment.
1517 * @return array of references to sequence objects
1519 public SequenceI[] getSequenceSelection()
1521 SequenceI[] sequences;
1522 if (selectionGroup==null)
1524 sequences = alignment.getSequencesArray();
1528 sequences = selectionGroup.getSequencesInOrder(alignment);
1533 * This method returns the visible alignment as text, as
1534 * seen on the GUI, ie if columns are hidden they will not
1535 * be returned in the result.
1536 * Use this for calculating trees, PCA, redundancy etc on views
1537 * which contain hidden columns.
1540 public jalview.datamodel.CigarArray getViewAsCigars(boolean
1543 CigarArray selection=null;
1544 SequenceI [] seqs= null;
1546 int start = 0, end = 0;
1547 if(selectedRegionOnly && selectionGroup!=null)
1549 iSize = selectionGroup.getSize();
1550 seqs = selectionGroup.getSequencesInOrder(alignment);
1551 start = selectionGroup.getStartRes();
1552 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
1556 iSize = alignment.getHeight();
1557 seqs = alignment.getSequencesArray();
1558 end = alignment.getWidth()-1;
1560 SeqCigar[] selseqs = new SeqCigar[iSize];
1561 for(i=0; i<iSize; i++)
1563 selseqs[i] = new SeqCigar(seqs[i], start, end);
1565 selection=new CigarArray(selseqs);
1566 // now construct the CigarArray operations
1567 if (hasHiddenColumns)
1569 Vector regions = colSel.getHiddenColumns();
1571 int hideStart, hideEnd;
1573 for (int j = 0; last<end & j < regions.size(); j++)
1575 region = (int[]) regions.elementAt(j);
1576 hideStart = region[0];
1577 hideEnd = region[1];
1578 // edit hidden regions to selection range
1579 if (hideStart < last)
1601 if (hideStart>hideEnd)
1606 * form operations...
1610 selection.addOperation(CigarArray.M, hideStart-last);
1612 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
1615 // Final match if necessary.
1618 selection.addOperation(CigarArray.M, end-last+1);
1623 selection.addOperation(CigarArray.M, end-start+1);
1628 * return a compact representation of the current alignment selection to
1629 * pass to an analysis function
1630 * @param selectedOnly boolean true to just return the selected view
1631 * @return AlignmentView
1633 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1636 // this is here because the AlignmentView constructor modifies the CigarArray
1637 // object. Refactoring of Cigar and alignment view representation should
1638 // be done to remove redundancy.
1639 CigarArray aligview = getViewAsCigars(selectedOnly);
1640 if (aligview != null)
1642 return new AlignmentView(aligview,
1643 (selectedOnly && selectionGroup != null) ?
1644 selectionGroup.getStartRes() : 0);
1649 * This method returns the visible alignment as text, as
1650 * seen on the GUI, ie if columns are hidden they will not
1651 * be returned in the result.
1652 * Use this for calculating trees, PCA, redundancy etc on views
1653 * which contain hidden columns.
1656 public String [] getViewAsString(boolean selectedRegionOnly)
1658 String [] selection = null;
1659 SequenceI [] seqs= null;
1661 int start = 0, end = 0;
1662 if(selectedRegionOnly && selectionGroup!=null)
1664 iSize = selectionGroup.getSize();
1665 seqs = selectionGroup.getSequencesInOrder(alignment);
1666 start = selectionGroup.getStartRes();
1667 end = selectionGroup.getEndRes()+1;
1671 iSize = alignment.getHeight();
1672 seqs = alignment.getSequencesArray();
1673 end = alignment.getWidth();
1676 selection = new String[iSize];
1677 if (hasHiddenColumns)
1679 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1683 for(i=0; i<iSize; i++)
1685 selection[i] = seqs[i].getSequenceAsString(start, end);
1692 public int [][] getVisibleRegionBoundaries(int min, int max)
1694 Vector regions = new Vector();
1700 if (hasHiddenColumns)
1704 start = colSel.adjustForHiddenColumns(start);
1707 end = colSel.getHiddenBoundaryRight(start);
1718 regions.addElement(new int[]
1721 if (hasHiddenColumns)
1723 start = colSel.adjustForHiddenColumns(end);
1724 start = colSel.getHiddenBoundaryLeft(start) + 1;
1729 int[][] startEnd = new int[regions.size()][2];
1731 regions.copyInto(startEnd);
1737 public boolean getShowHiddenMarkers()
1739 return showHiddenMarkers;
1742 public void setShowHiddenMarkers(boolean show)
1744 showHiddenMarkers = show;
1747 public String getSequenceSetId()
1749 if(sequenceSetID==null)
1751 sequenceSetID = alignment.hashCode()+"";
1754 return sequenceSetID;
1757 public void alignmentChanged(AlignmentPanel ap)
1761 alignment.padGaps();
1764 if (hconsensus != null && autoCalculateConsensus)
1766 updateConsensus(ap);
1767 updateConservation(ap);
1770 //Reset endRes of groups if beyond alignment width
1771 int alWidth = alignment.getWidth();
1772 Vector groups = alignment.getGroups();
1775 for(int i=0; i<groups.size(); i++)
1777 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
1778 if(sg.getEndRes()>alWidth)
1780 sg.setEndRes(alWidth-1);
1785 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
1787 selectionGroup.setEndRes(alWidth-1);
1790 resetAllColourSchemes();
1792 // alignment.adjustSequenceAnnotations();
1796 void resetAllColourSchemes()
1798 ColourSchemeI cs = globalColourScheme;
1801 if (cs instanceof ClustalxColourScheme)
1803 ( (ClustalxColourScheme) cs).
1804 resetClustalX(alignment.getSequences(),
1805 alignment.getWidth());
1808 cs.setConsensus(hconsensus);
1809 if (cs.conservationApplied())
1811 Alignment al = (Alignment) alignment;
1812 Conservation c = new Conservation("All",
1813 ResidueProperties.propHash, 3,
1814 al.getSequences(), 0,
1817 c.verdict(false, ConsPercGaps);
1819 cs.setConservation(c);
1823 int s, sSize = alignment.getGroups().size();
1824 for(s=0; s<sSize; s++)
1826 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
1827 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1829 ((ClustalxColourScheme)sg.cs).resetClustalX(
1830 sg.getSequences(hiddenRepSequences), sg.getWidth());
1832 sg.recalcConservation();
1837 public Color getSequenceColour(SequenceI seq)
1839 if(sequenceColours==null || !sequenceColours.containsKey(seq))
1845 return (Color)sequenceColours.get(seq);
1849 public void setSequenceColour(SequenceI seq, Color col)
1851 if(sequenceColours==null)
1853 sequenceColours = new Hashtable();
1858 sequenceColours.remove(seq);
1862 sequenceColours.put(seq, col);
1866 * returns the visible column regions of the alignment
1867 * @param selectedRegionOnly true to just return the contigs intersecting with the selected area
1870 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly) {
1871 int[] viscontigs=null;
1872 int start = 0, end = 0;
1873 if(selectedRegionOnly && selectionGroup!=null)
1875 start = selectionGroup.getStartRes();
1876 end = selectionGroup.getEndRes()+1;
1880 end = alignment.getWidth();
1882 viscontigs = colSel.getVisibleContigs(start, end);
1886 * get hash of undo and redo list for the alignment
1887 * @return long[] { historyList.hashCode, redoList.hashCode };
1889 public long[] getUndoRedoHash()
1891 if (historyList==null || redoList==null)
1892 return new long[] { -1, -1};
1893 return new long[] { historyList.hashCode(), this.redoList.hashCode() };
1896 * test if a particular set of hashcodes are different to the hashcodes for the undo and redo list.
1897 * @param undoredo the stored set of hashcodes as returned by getUndoRedoHash
1898 * @return true if the hashcodes differ (ie the alignment has been edited) or the stored hashcode array differs in size
1900 public boolean isUndoRedoHashModified(long[] undoredo)
1906 long[] cstate = getUndoRedoHash();
1907 if (cstate.length!=undoredo.length)
1910 for (int i=0; i<cstate.length; i++)
1912 if (cstate[i]!=undoredo[i])
1920 public boolean getCentreColumnLabels()
1922 return centreColumnLabels;
1924 public void setCentreColumnLabels(boolean centrecolumnlabels)
1926 centreColumnLabels = centrecolumnlabels;
1928 public void updateSequenceIdColours()
1930 Vector groups = alignment.getGroups();
1931 if (sequenceColours==null)
1933 sequenceColours = new Hashtable();
1935 for (int ig=0,igSize=groups.size(); ig<igSize; ig++)
1937 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1938 if (sg.idColour!=null)
1940 Vector sqs = sg.getSequences(hiddenRepSequences);
1941 for (int s=0,sSize=sqs.size();s<sSize;s++)
1943 sequenceColours.put(sqs.elementAt(s), sg.idColour);