2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
21 import jalview.analysis.*;
25 import jalview.datamodel.*;
27 import jalview.schemes.*;
40 public class AlignViewport
46 boolean showJVSuffix = true;
47 boolean showText = true;
48 boolean showColourText = false;
49 boolean showBoxes = true;
50 boolean wrapAlignment = false;
51 boolean renderGaps = true;
52 boolean showSequenceFeatures = false;
53 boolean showAnnotation = true;
54 boolean colourAppliesToAllGroups = true;
55 ColourSchemeI globalColourScheme = null;
56 boolean conservationColourSelected = false;
57 boolean abovePIDThreshold = false;
58 SequenceGroup selectionGroup;
61 boolean validCharWidth;
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.PropertyChangeSupport(this);
96 boolean ignoreGapsInConsensusCalculation = false;
98 boolean isDataset = false;
100 boolean antiAlias = false;
102 boolean padGaps = false;
104 Rectangle explodedPosition;
108 String sequenceSetID;
110 boolean gatherViewsHere = false;
112 Stack historyList = new Stack();
113 Stack redoList = new Stack();
115 Hashtable sequenceColours;
117 int thresholdTextColour = 0;
118 Color textColour = Color.black;
119 Color textColour2 = Color.white;
121 boolean rightAlignIds = false;
123 Hashtable hiddenRepSequences;
127 * Creates a new AlignViewport object.
129 * @param al DOCUMENT ME!
131 public AlignViewport(AlignmentI al)
137 * Create a new AlignViewport with hidden regions
138 * @param al AlignmentI
139 * @param hiddenColumns ColumnSelection
141 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) {
143 if (hiddenColumns!=null) {
144 this.colSel = hiddenColumns;
145 if (hiddenColumns.getHiddenColumns() != null)
146 hasHiddenColumns = true;
154 this.endRes = alignment.getWidth() - 1;
156 this.endSeq = alignment.getHeight() - 1;
158 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
160 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
161 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
163 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
165 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
167 padGaps = Cache.getDefault("PAD_GAPS", true);
169 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
170 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;
171 String fontSize = Cache.getDefault("FONT_SIZE", "10");
175 if (fontStyle.equals("bold"))
179 else if (fontStyle.equals("italic"))
184 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
186 alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );
189 // We must set conservation and consensus before setting colour,
190 // as Blosum and Clustal require this to be done
191 if(hconsensus==null && !isDataset)
193 if(!alignment.isNucleotide())
195 conservation = new AlignmentAnnotation("Conservation",
196 "Conservation of total alignment less than " +
197 ConsPercGaps + "% gaps",
198 new Annotation[1], 0f,
200 AlignmentAnnotation.BAR_GRAPH);
201 conservation.hasText = true;
204 if (Cache.getDefault("SHOW_CONSERVATION", true))
206 alignment.addAnnotation(conservation);
209 if (Cache.getDefault("SHOW_QUALITY", true))
211 quality = new AlignmentAnnotation("Quality",
212 "Alignment Quality based on Blosum62 scores",
216 AlignmentAnnotation.BAR_GRAPH);
217 quality.hasText = true;
219 alignment.addAnnotation(quality);
223 consensus = new AlignmentAnnotation("Consensus", "PID",
224 new Annotation[1], 0f, 100f,
225 AlignmentAnnotation.BAR_GRAPH);
226 consensus.hasText = true;
228 if (Cache.getDefault("SHOW_IDENTITY", true))
230 alignment.addAnnotation(consensus);
234 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
236 globalColourScheme = ColourSchemeProperty.getColour(alignment,
237 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
239 if (globalColourScheme instanceof UserColourScheme)
241 globalColourScheme = UserDefinedColours.loadDefaultColours();
242 ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());
245 if (globalColourScheme != null)
247 globalColourScheme.setConsensus(hconsensus);
251 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
259 * @param b DOCUMENT ME!
261 public void setShowSequenceFeatures(boolean b)
263 showSequenceFeatures = b;
266 public boolean getShowSequenceFeatures()
268 return showSequenceFeatures;
273 class ConservationThread extends Thread
276 public ConservationThread(AlignmentPanel ap)
285 updatingConservation = true;
287 while (UPDATING_CONSERVATION)
299 ex.printStackTrace();
303 UPDATING_CONSERVATION = true;
306 int alWidth = alignment.getWidth();
310 Conservation cons = new jalview.analysis.Conservation("All",
311 jalview.schemes.ResidueProperties.propHash, 3,
312 alignment.getSequences(), 0, alWidth -1);
315 cons.verdict(false, ConsPercGaps);
322 char [] sequence = cons.getConsSequence().getSequence();
334 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
343 conservation.annotations = new Annotation[alWidth];
347 quality.graphMax = cons.qualityRange[1].floatValue();
348 quality.annotations = new Annotation[alWidth];
349 qmin = cons.qualityRange[0].floatValue();
350 qmax = cons.qualityRange[1].floatValue();
353 for (int i = 0; i < alWidth; i++)
359 if (Character.isDigit(c))
360 value = (int) (c - '0');
366 float vprop = value - min;
368 conservation.annotations[i] =
369 new Annotation(String.valueOf(c),
370 String.valueOf(value), ' ', value,
371 new Color(minR + (maxR * vprop),
372 minG + (maxG * vprop),
373 minB + (maxB * vprop)));
378 value = ( (Double) cons.quality.get(i)).floatValue();
379 vprop = value - qmin;
381 quality.annotations[i] = new Annotation(" ", String.valueOf(value), ' ',
383 new Color(minR + (maxR * vprop),
384 minG + (maxG * vprop),
385 minB + (maxB * vprop)));
389 catch (OutOfMemoryError error)
391 javax.swing.SwingUtilities.invokeLater(new Runnable()
397 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
398 "Out of memory calculating conservation!!"
400 "\nSee help files for increasing Java Virtual Machine memory."
402 javax.swing.JOptionPane.WARNING_MESSAGE);
409 System.out.println("Conservation calculation: " + error);
414 UPDATING_CONSERVATION = false;
415 updatingConservation = false;
426 ConservationThread conservationThread;
428 ConsensusThread consensusThread;
430 boolean consUpdateNeeded = false;
432 static boolean UPDATING_CONSENSUS = false;
434 static boolean UPDATING_CONSERVATION = false;
436 boolean updatingConsensus = false;
438 boolean updatingConservation = false;
443 public void updateConservation(final AlignmentPanel ap)
445 if (alignment.isNucleotide() || conservation==null)
448 conservationThread = new ConservationThread(ap);
449 conservationThread.start();
455 public void updateConsensus(final AlignmentPanel ap)
457 consensusThread = new ConsensusThread(ap);
458 consensusThread.start();
462 class ConsensusThread extends Thread
465 public ConsensusThread(AlignmentPanel ap)
471 updatingConsensus = true;
472 while (UPDATING_CONSENSUS)
485 ex.printStackTrace();
490 UPDATING_CONSENSUS = true;
494 int aWidth = alignment.getWidth();
498 consensus.annotations = null;
499 consensus.annotations = new Annotation[aWidth];
502 hconsensus = new Hashtable[aWidth];
503 AAFrequency.calculate(alignment.getSequencesArray(),
505 alignment.getWidth(),
508 for (int i = 0; i < aWidth; i++)
511 if (ignoreGapsInConsensusCalculation)
512 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
515 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
518 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
519 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
521 if (maxRes.length() > 1)
523 mouseOver = "[" + maxRes + "] ";
527 mouseOver += ( (int) value + "%");
528 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
532 if (globalColourScheme != null)
533 globalColourScheme.setConsensus(hconsensus);
536 catch (OutOfMemoryError error)
538 alignment.deleteAnnotation(consensus);
542 javax.swing.SwingUtilities.invokeLater(new Runnable()
546 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
547 "Out of memory calculating consensus!!"
549 "\nSee help files for increasing Java Virtual Machine memory."
551 javax.swing.JOptionPane.WARNING_MESSAGE);
555 System.out.println("Consensus calculation: " + error);
558 UPDATING_CONSENSUS = false;
559 updatingConsensus = false;
568 * get the consensus sequence as displayed under the PID consensus annotation row.
569 * @return consensus sequence as a new sequence object
571 public SequenceI getConsensusSeq() {
573 updateConsensus(null);
576 StringBuffer seqs=new StringBuffer();
577 for (int i=0; i<consensus.annotations.length; i++) {
578 if (consensus.annotations[i]!=null) {
579 if (consensus.annotations[i].description.charAt(0) == '[')
580 seqs.append(consensus.annotations[i].description.charAt(1));
582 seqs.append(consensus.annotations[i].displayCharacter);
586 SequenceI sq = new Sequence("Consensus", seqs.toString());
587 sq.setDescription("Percentage Identity Consensus "+((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
593 * @return DOCUMENT ME!
595 public SequenceGroup getSelectionGroup()
597 return selectionGroup;
603 * @param sg DOCUMENT ME!
605 public void setSelectionGroup(SequenceGroup sg)
613 * @return DOCUMENT ME!
615 public boolean getConservationSelected()
617 return conservationColourSelected;
623 * @param b DOCUMENT ME!
625 public void setConservationSelected(boolean b)
627 conservationColourSelected = b;
633 * @return DOCUMENT ME!
635 public boolean getAbovePIDThreshold()
637 return abovePIDThreshold;
643 * @param b DOCUMENT ME!
645 public void setAbovePIDThreshold(boolean b)
647 abovePIDThreshold = b;
653 * @return DOCUMENT ME!
655 public int getStartRes()
663 * @return DOCUMENT ME!
665 public int getEndRes()
673 * @return DOCUMENT ME!
675 public int getStartSeq()
683 * @param cs DOCUMENT ME!
685 public void setGlobalColourScheme(ColourSchemeI cs)
687 globalColourScheme = cs;
693 * @return DOCUMENT ME!
695 public ColourSchemeI getGlobalColourScheme()
697 return globalColourScheme;
703 * @param res DOCUMENT ME!
705 public void setStartRes(int res)
713 * @param seq DOCUMENT ME!
715 public void setStartSeq(int seq)
723 * @param res DOCUMENT ME!
725 public void setEndRes(int res)
727 if (res > (alignment.getWidth() - 1))
729 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
730 res = alignment.getWidth() - 1;
744 * @param seq DOCUMENT ME!
746 public void setEndSeq(int seq)
748 if (seq > alignment.getHeight())
750 seq = alignment.getHeight();
764 * @return DOCUMENT ME!
766 public int getEndSeq()
774 * @param f DOCUMENT ME!
776 public void setFont(Font f)
780 Container c = new Container();
782 java.awt.FontMetrics fm = c.getFontMetrics(font);
783 setCharHeight(fm.getHeight());
784 setCharWidth(fm.charWidth('M'));
785 validCharWidth = true;
791 * @return DOCUMENT ME!
793 public Font getFont()
801 * @param w DOCUMENT ME!
803 public void setCharWidth(int w)
811 * @return DOCUMENT ME!
813 public int getCharWidth()
821 * @param h DOCUMENT ME!
823 public void setCharHeight(int h)
831 * @return DOCUMENT ME!
833 public int getCharHeight()
841 * @param w DOCUMENT ME!
843 public void setWrappedWidth(int w)
845 this.wrappedWidth = w;
851 * @return DOCUMENT ME!
853 public int getWrappedWidth()
862 * @return DOCUMENT ME!
864 public AlignmentI getAlignment()
872 * @param align DOCUMENT ME!
874 public void setAlignment(AlignmentI align)
876 this.alignment = align;
882 * @param state DOCUMENT ME!
884 public void setWrapAlignment(boolean state)
886 wrapAlignment = state;
892 * @param state DOCUMENT ME!
894 public void setShowText(boolean state)
902 * @param state DOCUMENT ME!
904 public void setRenderGaps(boolean state)
912 * @return DOCUMENT ME!
914 public boolean getColourText()
916 return showColourText;
922 * @param state DOCUMENT ME!
924 public void setColourText(boolean state)
926 showColourText = state;
932 * @param state DOCUMENT ME!
934 public void setShowBoxes(boolean state)
942 * @return DOCUMENT ME!
944 public boolean getWrapAlignment()
946 return wrapAlignment;
952 * @return DOCUMENT ME!
954 public boolean getShowText()
962 * @return DOCUMENT ME!
964 public boolean getShowBoxes()
972 * @return DOCUMENT ME!
974 public char getGapCharacter()
976 return getAlignment().getGapCharacter();
982 * @param gap DOCUMENT ME!
984 public void setGapCharacter(char gap)
986 if (getAlignment() != null)
988 getAlignment().setGapCharacter(gap);
995 * @param thresh DOCUMENT ME!
997 public void setThreshold(int thresh)
1005 * @return DOCUMENT ME!
1007 public int getThreshold()
1015 * @param inc DOCUMENT ME!
1017 public void setIncrement(int inc)
1025 * @return DOCUMENT ME!
1027 public int getIncrement()
1036 * @return DOCUMENT ME!
1038 public ColumnSelection getColumnSelection()
1047 * @param tree DOCUMENT ME!
1049 public void setCurrentTree(NJTree tree)
1057 * @return DOCUMENT ME!
1059 public NJTree getCurrentTree()
1067 * @param b DOCUMENT ME!
1069 public void setColourAppliesToAllGroups(boolean b)
1071 colourAppliesToAllGroups = b;
1077 * @return DOCUMENT ME!
1079 public boolean getColourAppliesToAllGroups()
1081 return colourAppliesToAllGroups;
1087 * @return DOCUMENT ME!
1089 public boolean getShowJVSuffix()
1091 return showJVSuffix;
1097 * @param b DOCUMENT ME!
1099 public void setShowJVSuffix(boolean b)
1108 * @return DOCUMENT ME!
1110 public boolean getShowAnnotation()
1112 return showAnnotation;
1118 * @param b DOCUMENT ME!
1120 public void setShowAnnotation(boolean b)
1128 * @return DOCUMENT ME!
1130 public boolean getScaleAboveWrapped()
1132 return scaleAboveWrapped;
1138 * @return DOCUMENT ME!
1140 public boolean getScaleLeftWrapped()
1142 return scaleLeftWrapped;
1148 * @return DOCUMENT ME!
1150 public boolean getScaleRightWrapped()
1152 return scaleRightWrapped;
1158 * @param b DOCUMENT ME!
1160 public void setScaleAboveWrapped(boolean b)
1162 scaleAboveWrapped = b;
1168 * @param b DOCUMENT ME!
1170 public void setScaleLeftWrapped(boolean b)
1172 scaleLeftWrapped = b;
1178 * @param b DOCUMENT ME!
1180 public void setScaleRightWrapped(boolean b)
1182 scaleRightWrapped = b;
1186 * Property change listener for changes in alignment
1188 * @param listener DOCUMENT ME!
1190 public void addPropertyChangeListener(
1191 java.beans.PropertyChangeListener listener)
1193 changeSupport.addPropertyChangeListener(listener);
1199 * @param listener DOCUMENT ME!
1201 public void removePropertyChangeListener(
1202 java.beans.PropertyChangeListener listener)
1204 changeSupport.removePropertyChangeListener(listener);
1208 * Property change listener for changes in alignment
1210 * @param prop DOCUMENT ME!
1211 * @param oldvalue DOCUMENT ME!
1212 * @param newvalue DOCUMENT ME!
1214 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
1216 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1219 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1221 ignoreGapsInConsensusCalculation = b;
1222 updateConsensus(ap);
1223 if(globalColourScheme!=null)
1225 globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);
1229 public boolean getIgnoreGapsConsensus()
1231 return ignoreGapsInConsensusCalculation;
1234 public void setDataset(boolean b)
1239 public boolean isDataset()
1245 public void hideSelectedColumns()
1247 if (colSel.size() < 1)
1250 colSel.hideSelectedColumns();
1251 setSelectionGroup(null);
1253 hasHiddenColumns = true;
1257 public void hideColumns(int start, int end)
1260 colSel.hideColumns(start);
1262 colSel.hideColumns(start, end);
1264 hasHiddenColumns = true;
1267 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1269 int sSize = sg.getSize();
1273 if(hiddenRepSequences==null)
1274 hiddenRepSequences = new Hashtable();
1276 hiddenRepSequences.put(repSequence, sg);
1278 //Hide all sequences except the repSequence
1279 SequenceI [] seqs = new SequenceI[sSize-1];
1281 for(int i=0; i<sSize; i++)
1282 if(sg.getSequenceAt(i)!=repSequence)
1287 seqs[index++] = sg.getSequenceAt(i);
1294 public void hideAllSelectedSeqs()
1296 if (selectionGroup == null)
1299 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1303 setSelectionGroup(null);
1306 public void hideSequence(SequenceI [] seq)
1310 for (int i = 0; i < seq.length; i++)
1312 alignment.getHiddenSequences().hideSequence(seq[i]);
1314 hasHiddenRows = true;
1315 firePropertyChange("alignment", null, alignment.getSequences());
1319 public void showSequence(int index)
1321 Vector tmp = alignment.getHiddenSequences().showSequence(index
1322 , hiddenRepSequences);
1325 if(selectionGroup==null)
1327 selectionGroup = new SequenceGroup();
1328 selectionGroup.setEndRes(alignment.getWidth()-1);
1331 for (int t = 0; t < tmp.size(); t++)
1333 selectionGroup.addSequence(
1334 (SequenceI) tmp.elementAt(t), false
1337 firePropertyChange("alignment", null, alignment.getSequences());
1340 if(alignment.getHiddenSequences().getSize()<1)
1341 hasHiddenRows = false;
1344 public void showColumn(int col)
1346 colSel.revealHiddenColumns(col);
1347 if(colSel.getHiddenColumns()==null)
1348 hasHiddenColumns = false;
1351 public void showAllHiddenColumns()
1353 colSel.revealAllHiddenColumns();
1354 hasHiddenColumns = false;
1357 public void showAllHiddenSeqs()
1359 if(alignment.getHiddenSequences().getSize()>0)
1361 if(selectionGroup==null)
1363 selectionGroup = new SequenceGroup();
1364 selectionGroup.setEndRes(alignment.getWidth()-1);
1366 Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
1367 for(int t=0; t<tmp.size(); t++)
1369 selectionGroup.addSequence(
1370 (SequenceI)tmp.elementAt(t), false
1373 firePropertyChange("alignment", null, alignment.getSequences());
1374 hasHiddenRows = false;
1375 hiddenRepSequences = null;
1381 public void invertColumnSelection()
1383 for(int i=0; i<alignment.getWidth(); i++)
1385 if(colSel.contains(i))
1386 colSel.removeElement(i);
1389 if (!hasHiddenColumns || colSel.isVisible(i))
1391 colSel.addElement(i);
1397 public int adjustForHiddenSeqs(int alignmentIndex)
1399 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
1403 * This method returns the a new SequenceI [] with
1404 * the selection sequence and start and end points adjusted
1407 public SequenceI[] getSelectionAsNewSequence()
1409 SequenceI[] sequences;
1411 if (selectionGroup == null)
1412 sequences = alignment.getSequencesArray();
1414 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1420 * This method returns the visible alignment as text, as
1421 * seen on the GUI, ie if columns are hidden they will not
1422 * be returned in the result.
1423 * Use this for calculating trees, PCA, redundancy etc on views
1424 * which contain hidden columns.
1427 public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)
1429 CigarArray selection=null;
1430 SequenceI [] seqs= null;
1432 int start = 0, end = 0;
1433 if(selectedRegionOnly && selectionGroup!=null)
1435 iSize = selectionGroup.getSize();
1436 seqs = selectionGroup.getSequencesInOrder(alignment);
1437 start = selectionGroup.getStartRes();
1438 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
1442 iSize = alignment.getHeight();
1443 seqs = alignment.getSequencesArray();
1444 end = alignment.getWidth()-1;
1446 SeqCigar[] selseqs = new SeqCigar[iSize];
1447 for(i=0; i<iSize; i++)
1449 selseqs[i] = new SeqCigar(seqs[i], start, end);
1451 selection=new CigarArray(selseqs);
1452 // now construct the CigarArray operations
1453 if (hasHiddenColumns) {
1454 Vector regions = colSel.getHiddenColumns();
1456 int hideStart, hideEnd;
1458 for (int j = 0; last<end & j < regions.size(); j++)
1460 region = (int[]) regions.elementAt(j);
1461 hideStart = region[0];
1462 hideEnd = region[1];
1463 // edit hidden regions to selection range
1464 if(hideStart<last) {
1478 if (hideStart>hideEnd)
1481 * form operations...
1484 selection.addOperation(CigarArray.M, hideStart-last);
1485 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
1488 // Final match if necessary.
1490 selection.addOperation(CigarArray.M, end-last+1);
1492 selection.addOperation(CigarArray.M, end-start+1);
1497 * return a compact representation of the current alignment selection to
1498 * pass to an analysis function
1499 * @param selectedOnly boolean true to just return the selected view
1500 * @return AlignmentView
1502 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {
1504 // this is here because the AlignmentView constructor modifies the CigarArray
1505 // object. Refactoring of Cigar and alignment view representation should
1506 // be done to remove redundancy.
1507 CigarArray aligview = getViewAsCigars(selectedOnly);
1508 if (aligview!=null) {
1509 return new AlignmentView(aligview,
1510 (selectedOnly && selectionGroup!=null) ? selectionGroup.getStartRes() : 0);
1515 * This method returns the visible alignment as text, as
1516 * seen on the GUI, ie if columns are hidden they will not
1517 * be returned in the result.
1518 * Use this for calculating trees, PCA, redundancy etc on views
1519 * which contain hidden columns.
1522 public String [] getViewAsString(boolean selectedRegionOnly)
1524 String [] selection = null;
1525 SequenceI [] seqs= null;
1527 int start = 0, end = 0;
1528 if(selectedRegionOnly && selectionGroup!=null)
1530 iSize = selectionGroup.getSize();
1531 seqs = selectionGroup.getSequencesInOrder(alignment);
1532 start = selectionGroup.getStartRes();
1533 end = selectionGroup.getEndRes()+1;
1537 iSize = alignment.getHeight();
1538 seqs = alignment.getSequencesArray();
1539 end = alignment.getWidth();
1542 selection = new String[iSize];
1543 if (hasHiddenColumns) {
1544 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1546 for(i=0; i<iSize; i++)
1548 selection[i] = seqs[i].getSequenceAsString(start, end);
1555 public boolean getShowHiddenMarkers()
1557 return showHiddenMarkers;
1560 public void setShowHiddenMarkers(boolean show)
1562 showHiddenMarkers = show;
1565 public String getSequenceSetId()
1567 if(sequenceSetID==null)
1568 sequenceSetID = alignment.hashCode()+"";
1570 return sequenceSetID;
1573 public void alignmentChanged(AlignmentPanel ap)
1576 alignment.padGaps();
1578 if (hconsensus != null && autoCalculateConsensus)
1580 updateConsensus(ap);
1581 updateConservation(ap);
1584 //Reset endRes of groups if beyond alignment width
1585 int alWidth = alignment.getWidth();
1586 Vector groups = alignment.getGroups();
1589 for(int i=0; i<groups.size(); i++)
1591 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
1592 if(sg.getEndRes()>alWidth)
1593 sg.setEndRes(alWidth-1);
1597 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
1598 selectionGroup.setEndRes(alWidth-1);
1600 resetAllColourSchemes();
1602 alignment.adjustSequenceAnnotations();
1606 void resetAllColourSchemes()
1608 ColourSchemeI cs = globalColourScheme;
1611 if (cs instanceof ClustalxColourScheme)
1613 ( (ClustalxColourScheme) cs).
1614 resetClustalX(alignment.getSequences(),
1615 alignment.getWidth());
1618 cs.setConsensus(hconsensus);
1619 if (cs.conservationApplied())
1621 Alignment al = (Alignment) alignment;
1622 Conservation c = new Conservation("All",
1623 ResidueProperties.propHash, 3,
1624 al.getSequences(), 0,
1627 c.verdict(false, ConsPercGaps);
1629 cs.setConservation(c);
1633 int s, sSize = alignment.getGroups().size();
1634 for(s=0; s<sSize; s++)
1636 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
1637 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1639 ((ClustalxColourScheme)sg.cs).resetClustalX(
1640 sg.getSequences(hiddenRepSequences), sg.getWidth());
1642 sg.recalcConservation();
1647 public Color getSequenceColour(SequenceI seq)
1649 if(sequenceColours==null || !sequenceColours.containsKey(seq))
1652 return (Color)sequenceColours.get(seq);
1655 public void setSequenceColour(SequenceI seq, Color col)
1657 if(sequenceColours==null)
1658 sequenceColours = new Hashtable();
1661 sequenceColours.remove(seq);
1663 sequenceColours.put(seq, col);