2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
25 import jalview.analysis.*;
29 import jalview.datamodel.*;
31 import jalview.schemes.*;
39 public class AlignViewport
45 boolean showJVSuffix = true;
46 boolean showText = true;
47 boolean showColourText = false;
48 boolean showBoxes = true;
49 boolean wrapAlignment = false;
50 boolean renderGaps = true;
51 boolean showSequenceFeatures = false;
52 boolean showAnnotation = true;
53 boolean colourAppliesToAllGroups = true;
54 ColourSchemeI globalColourScheme = null;
55 boolean conservationColourSelected = false;
56 boolean abovePIDThreshold = false;
57 SequenceGroup selectionGroup;
60 boolean validCharWidth;
63 boolean seqNameItalics;
65 ColumnSelection colSel = new ColumnSelection();
68 NJTree currentTree = null;
69 boolean scaleAboveWrapped = false;
70 boolean scaleLeftWrapped = true;
71 boolean scaleRightWrapped = true;
72 boolean hasHiddenColumns = false;
73 boolean hasHiddenRows = false;
74 boolean showHiddenMarkers = true;
76 boolean cursorMode = false;
78 // The following vector holds the features which are
79 // currently visible, in the correct order or rendering
80 Hashtable featuresDisplayed = null;
84 public Hashtable [] hconsensus;
85 AlignmentAnnotation consensus;
86 AlignmentAnnotation conservation;
87 AlignmentAnnotation quality;
88 boolean autoCalculateConsensus = true;
91 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
93 // JBPNote Prolly only need this in the applet version.
94 private java.beans.PropertyChangeSupport changeSupport = new java.beans.
95 PropertyChangeSupport(this);
97 boolean ignoreGapsInConsensusCalculation = false;
99 boolean isDataset = false;
101 boolean antiAlias = false;
103 boolean padGaps = false;
105 Rectangle explodedPosition;
109 String sequenceSetID;
111 boolean gatherViewsHere = false;
113 Stack historyList = new Stack();
114 Stack redoList = new Stack();
116 Hashtable sequenceColours;
118 int thresholdTextColour = 0;
119 Color textColour = Color.black;
120 Color textColour2 = Color.white;
122 boolean rightAlignIds = false;
124 Hashtable hiddenRepSequences;
128 * Creates a new AlignViewport object.
130 * @param al DOCUMENT ME!
132 public AlignViewport(AlignmentI al)
138 * Create a new AlignViewport with hidden regions
139 * @param al AlignmentI
140 * @param hiddenColumns ColumnSelection
142 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
145 if (hiddenColumns != null)
147 this.colSel = hiddenColumns;
148 if (hiddenColumns.getHiddenColumns() != null)
150 hasHiddenColumns = true;
159 this.endRes = alignment.getWidth() - 1;
161 this.endSeq = alignment.getHeight() - 1;
163 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
165 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
166 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
168 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
170 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
172 padGaps = Cache.getDefault("PAD_GAPS", true);
174 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
175 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;
176 String fontSize = Cache.getDefault("FONT_SIZE", "10");
178 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
182 if (fontStyle.equals("bold"))
186 else if (fontStyle.equals("italic"))
191 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
193 alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );
196 // We must set conservation and consensus before setting colour,
197 // as Blosum and Clustal require this to be done
198 if(hconsensus==null && !isDataset)
200 if(!alignment.isNucleotide())
202 conservation = new AlignmentAnnotation("Conservation",
203 "Conservation of total alignment less than " +
204 ConsPercGaps + "% gaps",
205 new Annotation[1], 0f,
207 AlignmentAnnotation.BAR_GRAPH);
208 conservation.hasText = true;
209 conservation.autoCalculated=true;
212 if (Cache.getDefault("SHOW_CONSERVATION", true))
214 alignment.addAnnotation(conservation);
217 if (Cache.getDefault("SHOW_QUALITY", true))
219 quality = new AlignmentAnnotation("Quality",
220 "Alignment Quality based on Blosum62 scores",
224 AlignmentAnnotation.BAR_GRAPH);
225 quality.hasText = true;
226 quality.autoCalculated=true;
228 alignment.addAnnotation(quality);
232 consensus = new AlignmentAnnotation("Consensus", "PID",
233 new Annotation[1], 0f, 100f,
234 AlignmentAnnotation.BAR_GRAPH);
235 consensus.hasText = true;
236 consensus.autoCalculated=true;
238 if (Cache.getDefault("SHOW_IDENTITY", true))
240 alignment.addAnnotation(consensus);
244 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
246 globalColourScheme = ColourSchemeProperty.getColour(alignment,
247 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
249 if (globalColourScheme instanceof UserColourScheme)
251 globalColourScheme = UserDefinedColours.loadDefaultColours();
252 ( (UserColourScheme) globalColourScheme).setThreshold(0,
253 getIgnoreGapsConsensus());
256 if (globalColourScheme != null)
258 globalColourScheme.setConsensus(hconsensus);
262 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
270 * @param b DOCUMENT ME!
272 public void setShowSequenceFeatures(boolean b)
274 showSequenceFeatures = b;
277 public boolean getShowSequenceFeatures()
279 return showSequenceFeatures;
282 class ConservationThread
286 public ConservationThread(AlignmentPanel ap)
295 updatingConservation = true;
297 while (UPDATING_CONSERVATION)
303 ap.paintAlignment(true);
309 ex.printStackTrace();
313 UPDATING_CONSERVATION = true;
316 int alWidth = alignment.getWidth();
322 Conservation cons = new jalview.analysis.Conservation("All",
323 jalview.schemes.ResidueProperties.propHash, 3,
324 alignment.getSequences(), 0, alWidth -1);
327 cons.verdict(false, ConsPercGaps);
334 char [] sequence = cons.getConsSequence().getSequence();
346 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
355 conservation.annotations = new Annotation[alWidth];
359 quality.graphMax = cons.qualityRange[1].floatValue();
360 quality.annotations = new Annotation[alWidth];
361 qmin = cons.qualityRange[0].floatValue();
362 qmax = cons.qualityRange[1].floatValue();
365 for (int i = 0; i < alWidth; i++)
371 if (Character.isDigit(c))
373 value = (int) (c - '0');
384 float vprop = value - min;
386 conservation.annotations[i] =
387 new Annotation(String.valueOf(c),
388 String.valueOf(value), ' ', value,
389 new Color(minR + (maxR * vprop),
390 minG + (maxG * vprop),
391 minB + (maxB * vprop)));
396 value = ( (Double) cons.quality.get(i)).floatValue();
397 vprop = value - qmin;
399 quality.annotations[i] = new Annotation(" ", String.valueOf(value),
402 new Color(minR + (maxR * vprop),
403 minG + (maxG * vprop),
404 minB + (maxB * vprop)));
408 catch (OutOfMemoryError error)
410 javax.swing.SwingUtilities.invokeLater(new Runnable()
416 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
417 "Out of memory calculating conservation!!"
419 "\nSee help files for increasing Java Virtual Machine memory."
421 javax.swing.JOptionPane.WARNING_MESSAGE);
428 System.out.println("Conservation calculation: " + error);
433 UPDATING_CONSERVATION = false;
434 updatingConservation = false;
438 ap.paintAlignment(true);
445 ConservationThread conservationThread;
447 ConsensusThread consensusThread;
449 boolean consUpdateNeeded = false;
451 static boolean UPDATING_CONSENSUS = false;
453 static boolean UPDATING_CONSERVATION = false;
455 boolean updatingConsensus = false;
457 boolean updatingConservation = false;
462 public void updateConservation(final AlignmentPanel ap)
464 if (alignment.isNucleotide() || conservation==null)
469 conservationThread = new ConservationThread(ap);
470 conservationThread.start();
476 public void updateConsensus(final AlignmentPanel ap)
478 consensusThread = new ConsensusThread(ap);
479 consensusThread.start();
482 class ConsensusThread
486 public ConsensusThread(AlignmentPanel ap)
492 updatingConsensus = true;
493 while (UPDATING_CONSENSUS)
499 ap.paintAlignment(true);
506 ex.printStackTrace();
511 UPDATING_CONSENSUS = true;
515 int aWidth = alignment.getWidth();
521 consensus.annotations = null;
522 consensus.annotations = new Annotation[aWidth];
525 hconsensus = new Hashtable[aWidth];
526 AAFrequency.calculate(alignment.getSequencesArray(),
528 alignment.getWidth(),
531 for (int i = 0; i < aWidth; i++)
534 if (ignoreGapsInConsensusCalculation)
536 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
541 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
545 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
546 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
548 if (maxRes.length() > 1)
550 mouseOver = "[" + maxRes + "] ";
554 mouseOver += ( (int) value + "%");
555 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
560 if (globalColourScheme != null)
562 globalColourScheme.setConsensus(hconsensus);
566 catch (OutOfMemoryError error)
568 alignment.deleteAnnotation(consensus);
572 javax.swing.SwingUtilities.invokeLater(new Runnable()
576 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
577 "Out of memory calculating consensus!!"
579 "\nSee help files for increasing Java Virtual Machine memory."
581 javax.swing.JOptionPane.WARNING_MESSAGE);
585 System.out.println("Consensus calculation: " + error);
588 UPDATING_CONSENSUS = false;
589 updatingConsensus = false;
593 ap.paintAlignment(true);
598 * get the consensus sequence as displayed under the PID consensus annotation row.
599 * @return consensus sequence as a new sequence object
601 public SequenceI getConsensusSeq()
605 updateConsensus(null);
611 StringBuffer seqs=new StringBuffer();
612 for (int i = 0; i < consensus.annotations.length; i++)
614 if (consensus.annotations[i] != null)
616 if (consensus.annotations[i].description.charAt(0) == '[')
618 seqs.append(consensus.annotations[i].description.charAt(1));
622 seqs.append(consensus.annotations[i].displayCharacter);
627 SequenceI sq = new Sequence("Consensus", seqs.toString());
628 sq.setDescription("Percentage Identity Consensus " +
629 ( (ignoreGapsInConsensusCalculation) ? " without gaps" :
636 * @return DOCUMENT ME!
638 public SequenceGroup getSelectionGroup()
640 return selectionGroup;
646 * @param sg DOCUMENT ME!
648 public void setSelectionGroup(SequenceGroup sg)
656 * @return DOCUMENT ME!
658 public boolean getConservationSelected()
660 return conservationColourSelected;
666 * @param b DOCUMENT ME!
668 public void setConservationSelected(boolean b)
670 conservationColourSelected = b;
676 * @return DOCUMENT ME!
678 public boolean getAbovePIDThreshold()
680 return abovePIDThreshold;
686 * @param b DOCUMENT ME!
688 public void setAbovePIDThreshold(boolean b)
690 abovePIDThreshold = b;
696 * @return DOCUMENT ME!
698 public int getStartRes()
706 * @return DOCUMENT ME!
708 public int getEndRes()
716 * @return DOCUMENT ME!
718 public int getStartSeq()
726 * @param cs DOCUMENT ME!
728 public void setGlobalColourScheme(ColourSchemeI cs)
730 globalColourScheme = cs;
736 * @return DOCUMENT ME!
738 public ColourSchemeI getGlobalColourScheme()
740 return globalColourScheme;
746 * @param res DOCUMENT ME!
748 public void setStartRes(int res)
756 * @param seq DOCUMENT ME!
758 public void setStartSeq(int seq)
766 * @param res DOCUMENT ME!
768 public void setEndRes(int res)
770 if (res > (alignment.getWidth() - 1))
772 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
773 res = alignment.getWidth() - 1;
787 * @param seq DOCUMENT ME!
789 public void setEndSeq(int seq)
791 if (seq > alignment.getHeight())
793 seq = alignment.getHeight();
807 * @return DOCUMENT ME!
809 public int getEndSeq()
817 * @param f DOCUMENT ME!
819 public void setFont(Font f)
823 Container c = new Container();
825 java.awt.FontMetrics fm = c.getFontMetrics(font);
826 setCharHeight(fm.getHeight());
827 setCharWidth(fm.charWidth('M'));
828 validCharWidth = true;
834 * @return DOCUMENT ME!
836 public Font getFont()
844 * @param w DOCUMENT ME!
846 public void setCharWidth(int w)
854 * @return DOCUMENT ME!
856 public int getCharWidth()
864 * @param h DOCUMENT ME!
866 public void setCharHeight(int h)
874 * @return DOCUMENT ME!
876 public int getCharHeight()
884 * @param w DOCUMENT ME!
886 public void setWrappedWidth(int w)
888 this.wrappedWidth = w;
894 * @return DOCUMENT ME!
896 public int getWrappedWidth()
905 * @return DOCUMENT ME!
907 public AlignmentI getAlignment()
915 * @param align DOCUMENT ME!
917 public void setAlignment(AlignmentI align)
919 this.alignment = align;
925 * @param state DOCUMENT ME!
927 public void setWrapAlignment(boolean state)
929 wrapAlignment = state;
935 * @param state DOCUMENT ME!
937 public void setShowText(boolean state)
945 * @param state DOCUMENT ME!
947 public void setRenderGaps(boolean state)
955 * @return DOCUMENT ME!
957 public boolean getColourText()
959 return showColourText;
965 * @param state DOCUMENT ME!
967 public void setColourText(boolean state)
969 showColourText = state;
975 * @param state DOCUMENT ME!
977 public void setShowBoxes(boolean state)
985 * @return DOCUMENT ME!
987 public boolean getWrapAlignment()
989 return wrapAlignment;
995 * @return DOCUMENT ME!
997 public boolean getShowText()
1005 * @return DOCUMENT ME!
1007 public boolean getShowBoxes()
1015 * @return DOCUMENT ME!
1017 public char getGapCharacter()
1019 return getAlignment().getGapCharacter();
1025 * @param gap DOCUMENT ME!
1027 public void setGapCharacter(char gap)
1029 if (getAlignment() != null)
1031 getAlignment().setGapCharacter(gap);
1038 * @param thresh DOCUMENT ME!
1040 public void setThreshold(int thresh)
1048 * @return DOCUMENT ME!
1050 public int getThreshold()
1058 * @param inc DOCUMENT ME!
1060 public void setIncrement(int inc)
1068 * @return DOCUMENT ME!
1070 public int getIncrement()
1079 * @return DOCUMENT ME!
1081 public ColumnSelection getColumnSelection()
1090 * @param tree DOCUMENT ME!
1092 public void setCurrentTree(NJTree tree)
1100 * @return DOCUMENT ME!
1102 public NJTree getCurrentTree()
1110 * @param b DOCUMENT ME!
1112 public void setColourAppliesToAllGroups(boolean b)
1114 colourAppliesToAllGroups = b;
1120 * @return DOCUMENT ME!
1122 public boolean getColourAppliesToAllGroups()
1124 return colourAppliesToAllGroups;
1130 * @return DOCUMENT ME!
1132 public boolean getShowJVSuffix()
1134 return showJVSuffix;
1140 * @param b DOCUMENT ME!
1142 public void setShowJVSuffix(boolean b)
1151 * @return DOCUMENT ME!
1153 public boolean getShowAnnotation()
1155 return showAnnotation;
1161 * @param b DOCUMENT ME!
1163 public void setShowAnnotation(boolean b)
1171 * @return DOCUMENT ME!
1173 public boolean getScaleAboveWrapped()
1175 return scaleAboveWrapped;
1181 * @return DOCUMENT ME!
1183 public boolean getScaleLeftWrapped()
1185 return scaleLeftWrapped;
1191 * @return DOCUMENT ME!
1193 public boolean getScaleRightWrapped()
1195 return scaleRightWrapped;
1201 * @param b DOCUMENT ME!
1203 public void setScaleAboveWrapped(boolean b)
1205 scaleAboveWrapped = b;
1211 * @param b DOCUMENT ME!
1213 public void setScaleLeftWrapped(boolean b)
1215 scaleLeftWrapped = b;
1221 * @param b DOCUMENT ME!
1223 public void setScaleRightWrapped(boolean b)
1225 scaleRightWrapped = b;
1229 * Property change listener for changes in alignment
1231 * @param listener DOCUMENT ME!
1233 public void addPropertyChangeListener(
1234 java.beans.PropertyChangeListener listener)
1236 changeSupport.addPropertyChangeListener(listener);
1242 * @param listener DOCUMENT ME!
1244 public void removePropertyChangeListener(
1245 java.beans.PropertyChangeListener listener)
1247 changeSupport.removePropertyChangeListener(listener);
1251 * Property change listener for changes in alignment
1253 * @param prop DOCUMENT ME!
1254 * @param oldvalue DOCUMENT ME!
1255 * @param newvalue DOCUMENT ME!
1257 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
1259 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1262 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1264 ignoreGapsInConsensusCalculation = b;
1265 updateConsensus(ap);
1266 if(globalColourScheme!=null)
1268 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1269 ignoreGapsInConsensusCalculation);
1273 public boolean getIgnoreGapsConsensus()
1275 return ignoreGapsInConsensusCalculation;
1278 public void setDataset(boolean b)
1283 public boolean isDataset()
1289 public void hideSelectedColumns()
1291 if (colSel.size() < 1)
1296 colSel.hideSelectedColumns();
1297 setSelectionGroup(null);
1299 hasHiddenColumns = true;
1303 public void hideColumns(int start, int end)
1307 colSel.hideColumns(start);
1311 colSel.hideColumns(start, end);
1314 hasHiddenColumns = true;
1317 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1319 int sSize = sg.getSize();
1325 if(hiddenRepSequences==null)
1327 hiddenRepSequences = new Hashtable();
1330 hiddenRepSequences.put(repSequence, sg);
1332 //Hide all sequences except the repSequence
1333 SequenceI [] seqs = new SequenceI[sSize-1];
1335 for(int i=0; i<sSize; i++)
1337 if(sg.getSequenceAt(i)!=repSequence)
1344 seqs[index++] = sg.getSequenceAt(i);
1352 public void hideAllSelectedSeqs()
1354 if (selectionGroup == null || selectionGroup.getSize()<1)
1359 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1363 setSelectionGroup(null);
1366 public void hideSequence(SequenceI [] seq)
1370 for (int i = 0; i < seq.length; i++)
1372 alignment.getHiddenSequences().hideSequence(seq[i]);
1374 hasHiddenRows = true;
1375 firePropertyChange("alignment", null, alignment.getSequences());
1379 public void showSequence(int index)
1381 Vector tmp = alignment.getHiddenSequences().showSequence(index
1382 , hiddenRepSequences);
1385 if(selectionGroup==null)
1387 selectionGroup = new SequenceGroup();
1388 selectionGroup.setEndRes(alignment.getWidth()-1);
1391 for (int t = 0; t < tmp.size(); t++)
1393 selectionGroup.addSequence(
1394 (SequenceI) tmp.elementAt(t), false
1397 firePropertyChange("alignment", null, alignment.getSequences());
1400 if(alignment.getHiddenSequences().getSize()<1)
1402 hasHiddenRows = false;
1406 public void showColumn(int col)
1408 colSel.revealHiddenColumns(col);
1409 if(colSel.getHiddenColumns()==null)
1411 hasHiddenColumns = false;
1415 public void showAllHiddenColumns()
1417 colSel.revealAllHiddenColumns();
1418 hasHiddenColumns = false;
1421 public void showAllHiddenSeqs()
1423 if(alignment.getHiddenSequences().getSize()>0)
1425 if(selectionGroup==null)
1427 selectionGroup = new SequenceGroup();
1428 selectionGroup.setEndRes(alignment.getWidth()-1);
1430 Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
1431 for(int t=0; t<tmp.size(); t++)
1433 selectionGroup.addSequence(
1434 (SequenceI)tmp.elementAt(t), false
1437 firePropertyChange("alignment", null, alignment.getSequences());
1438 hasHiddenRows = false;
1439 hiddenRepSequences = null;
1445 public void invertColumnSelection()
1447 for(int i=0; i<alignment.getWidth(); i++)
1449 if(colSel.contains(i))
1451 colSel.removeElement(i);
1455 if (!hasHiddenColumns || colSel.isVisible(i))
1457 colSel.addElement(i);
1463 public int adjustForHiddenSeqs(int alignmentIndex)
1465 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
1469 * This method returns an array of new SequenceI objects
1470 * derived from the whole alignment or just the current
1471 * selection with start and end points adjusted
1472 * @note if you need references to the actual SequenceI objects in the alignment or currently selected then use getSequenceSelection()
1475 public SequenceI[] getSelectionAsNewSequence()
1477 SequenceI[] sequences;
1479 if (selectionGroup == null)
1481 sequences = alignment.getSequencesArray();
1482 for (int i=0; i<sequences.length; i++)
1484 sequences[i] = new Sequence(sequences[i]); // construct new sequence
1489 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1495 * get the currently selected sequence objects or all the sequences in the alignment.
1496 * @return array of references to sequence objects
1498 public SequenceI[] getSequenceSelection()
1500 SequenceI[] sequences;
1501 if (selectionGroup==null)
1503 sequences = alignment.getSequencesArray();
1507 sequences = selectionGroup.getSequencesInOrder(alignment);
1512 * This method returns the visible alignment as text, as
1513 * seen on the GUI, ie if columns are hidden they will not
1514 * be returned in the result.
1515 * Use this for calculating trees, PCA, redundancy etc on views
1516 * which contain hidden columns.
1519 public jalview.datamodel.CigarArray getViewAsCigars(boolean
1522 CigarArray selection=null;
1523 SequenceI [] seqs= null;
1525 int start = 0, end = 0;
1526 if(selectedRegionOnly && selectionGroup!=null)
1528 iSize = selectionGroup.getSize();
1529 seqs = selectionGroup.getSequencesInOrder(alignment);
1530 start = selectionGroup.getStartRes();
1531 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
1535 iSize = alignment.getHeight();
1536 seqs = alignment.getSequencesArray();
1537 end = alignment.getWidth()-1;
1539 SeqCigar[] selseqs = new SeqCigar[iSize];
1540 for(i=0; i<iSize; i++)
1542 selseqs[i] = new SeqCigar(seqs[i], start, end);
1544 selection=new CigarArray(selseqs);
1545 // now construct the CigarArray operations
1546 if (hasHiddenColumns)
1548 Vector regions = colSel.getHiddenColumns();
1550 int hideStart, hideEnd;
1552 for (int j = 0; last<end & j < regions.size(); j++)
1554 region = (int[]) regions.elementAt(j);
1555 hideStart = region[0];
1556 hideEnd = region[1];
1557 // edit hidden regions to selection range
1558 if (hideStart < last)
1580 if (hideStart>hideEnd)
1585 * form operations...
1589 selection.addOperation(CigarArray.M, hideStart-last);
1591 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
1594 // Final match if necessary.
1597 selection.addOperation(CigarArray.M, end-last+1);
1602 selection.addOperation(CigarArray.M, end-start+1);
1607 * return a compact representation of the current alignment selection to
1608 * pass to an analysis function
1609 * @param selectedOnly boolean true to just return the selected view
1610 * @return AlignmentView
1612 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1615 // this is here because the AlignmentView constructor modifies the CigarArray
1616 // object. Refactoring of Cigar and alignment view representation should
1617 // be done to remove redundancy.
1618 CigarArray aligview = getViewAsCigars(selectedOnly);
1619 if (aligview != null)
1621 return new AlignmentView(aligview,
1622 (selectedOnly && selectionGroup != null) ?
1623 selectionGroup.getStartRes() : 0);
1628 * This method returns the visible alignment as text, as
1629 * seen on the GUI, ie if columns are hidden they will not
1630 * be returned in the result.
1631 * Use this for calculating trees, PCA, redundancy etc on views
1632 * which contain hidden columns.
1635 public String [] getViewAsString(boolean selectedRegionOnly)
1637 String [] selection = null;
1638 SequenceI [] seqs= null;
1640 int start = 0, end = 0;
1641 if(selectedRegionOnly && selectionGroup!=null)
1643 iSize = selectionGroup.getSize();
1644 seqs = selectionGroup.getSequencesInOrder(alignment);
1645 start = selectionGroup.getStartRes();
1646 end = selectionGroup.getEndRes()+1;
1650 iSize = alignment.getHeight();
1651 seqs = alignment.getSequencesArray();
1652 end = alignment.getWidth();
1655 selection = new String[iSize];
1656 if (hasHiddenColumns)
1658 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1662 for(i=0; i<iSize; i++)
1664 selection[i] = seqs[i].getSequenceAsString(start, end);
1671 public int [][] getVisibleRegionBoundaries(int min, int max)
1673 Vector regions = new Vector();
1679 if (hasHiddenColumns)
1683 start = colSel.adjustForHiddenColumns(start);
1686 end = colSel.getHiddenBoundaryRight(start);
1697 regions.addElement(new int[]
1700 if (hasHiddenColumns)
1702 start = colSel.adjustForHiddenColumns(end);
1703 start = colSel.getHiddenBoundaryLeft(start) + 1;
1708 int[][] startEnd = new int[regions.size()][2];
1710 regions.copyInto(startEnd);
1716 public boolean getShowHiddenMarkers()
1718 return showHiddenMarkers;
1721 public void setShowHiddenMarkers(boolean show)
1723 showHiddenMarkers = show;
1726 public String getSequenceSetId()
1728 if(sequenceSetID==null)
1730 sequenceSetID = alignment.hashCode()+"";
1733 return sequenceSetID;
1736 public void alignmentChanged(AlignmentPanel ap)
1740 alignment.padGaps();
1743 if (hconsensus != null && autoCalculateConsensus)
1745 updateConsensus(ap);
1746 updateConservation(ap);
1749 //Reset endRes of groups if beyond alignment width
1750 int alWidth = alignment.getWidth();
1751 Vector groups = alignment.getGroups();
1754 for(int i=0; i<groups.size(); i++)
1756 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
1757 if(sg.getEndRes()>alWidth)
1759 sg.setEndRes(alWidth-1);
1764 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
1766 selectionGroup.setEndRes(alWidth-1);
1769 resetAllColourSchemes();
1771 // alignment.adjustSequenceAnnotations();
1775 void resetAllColourSchemes()
1777 ColourSchemeI cs = globalColourScheme;
1780 if (cs instanceof ClustalxColourScheme)
1782 ( (ClustalxColourScheme) cs).
1783 resetClustalX(alignment.getSequences(),
1784 alignment.getWidth());
1787 cs.setConsensus(hconsensus);
1788 if (cs.conservationApplied())
1790 Alignment al = (Alignment) alignment;
1791 Conservation c = new Conservation("All",
1792 ResidueProperties.propHash, 3,
1793 al.getSequences(), 0,
1796 c.verdict(false, ConsPercGaps);
1798 cs.setConservation(c);
1802 int s, sSize = alignment.getGroups().size();
1803 for(s=0; s<sSize; s++)
1805 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
1806 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1808 ((ClustalxColourScheme)sg.cs).resetClustalX(
1809 sg.getSequences(hiddenRepSequences), sg.getWidth());
1811 sg.recalcConservation();
1816 public Color getSequenceColour(SequenceI seq)
1818 if(sequenceColours==null || !sequenceColours.containsKey(seq))
1824 return (Color)sequenceColours.get(seq);
1828 public void setSequenceColour(SequenceI seq, Color col)
1830 if(sequenceColours==null)
1832 sequenceColours = new Hashtable();
1837 sequenceColours.remove(seq);
1841 sequenceColours.put(seq, col);
1845 * returns the visible column regions of the alignment
1846 * @param selectedRegionOnly true to just return the contigs intersecting with the selected area
1849 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly) {
1850 int[] viscontigs=null;
1851 int start = 0, end = 0;
1852 if(selectedRegionOnly && selectionGroup!=null)
1854 start = selectionGroup.getStartRes();
1855 end = selectionGroup.getEndRes()+1;
1859 end = alignment.getWidth();
1861 viscontigs = colSel.getVisibleContigs(start, end);