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.*;
27 import jalview.datamodel.*;
28 import jalview.schemes.*;
36 public class AlignViewport
42 boolean showJVSuffix = true;
43 boolean showText = true;
44 boolean showColourText = false;
45 boolean showBoxes = true;
46 boolean wrapAlignment = false;
47 boolean renderGaps = true;
48 boolean showSequenceFeatures = false;
49 boolean showAnnotation = true;
50 boolean colourAppliesToAllGroups = true;
51 ColourSchemeI globalColourScheme = null;
52 boolean conservationColourSelected = false;
53 boolean abovePIDThreshold = false;
54 SequenceGroup selectionGroup;
57 boolean validCharWidth;
60 boolean seqNameItalics;
62 ColumnSelection colSel = new ColumnSelection();
65 NJTree currentTree = null;
66 boolean scaleAboveWrapped = false;
67 boolean scaleLeftWrapped = true;
68 boolean scaleRightWrapped = true;
69 boolean hasHiddenColumns = false;
70 boolean hasHiddenRows = false;
71 boolean showHiddenMarkers = true;
73 boolean cursorMode = false;
75 // The following vector holds the features which are
76 // currently visible, in the correct order or rendering
77 Hashtable featuresDisplayed = null;
80 public Hashtable[] hconsensus;
81 AlignmentAnnotation consensus;
82 AlignmentAnnotation conservation;
83 AlignmentAnnotation quality;
84 boolean autoCalculateConsensus = true;
87 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
89 // JBPNote Prolly only need this in the applet version.
90 private java.beans.PropertyChangeSupport changeSupport = new java.beans.
91 PropertyChangeSupport(this);
93 boolean ignoreGapsInConsensusCalculation = false;
95 boolean isDataset = false;
97 boolean antiAlias = false;
99 boolean padGaps = false;
101 Rectangle explodedPosition;
105 String sequenceSetID;
107 boolean gatherViewsHere = false;
109 Stack historyList = new Stack();
110 Stack redoList = new Stack();
112 Hashtable sequenceColours;
114 int thresholdTextColour = 0;
115 Color textColour = Color.black;
116 Color textColour2 = Color.white;
118 boolean rightAlignIds = false;
120 Hashtable hiddenRepSequences;
123 * Creates a new AlignViewport object.
125 * @param al DOCUMENT ME!
127 public AlignViewport(AlignmentI al)
134 * Create a new AlignViewport with hidden regions
135 * @param al AlignmentI
136 * @param hiddenColumns ColumnSelection
138 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
141 if (hiddenColumns != null)
143 this.colSel = hiddenColumns;
144 if (hiddenColumns.getHiddenColumns() != null)
146 hasHiddenColumns = true;
155 this.endRes = alignment.getWidth() - 1;
157 this.endSeq = alignment.getHeight() - 1;
159 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
161 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
162 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
164 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
166 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
168 padGaps = Cache.getDefault("PAD_GAPS", true);
170 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
171 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
172 String fontSize = Cache.getDefault("FONT_SIZE", "10");
174 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
178 if (fontStyle.equals("bold"))
182 else if (fontStyle.equals("italic"))
187 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
189 alignment.setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
191 // We must set conservation and consensus before setting colour,
192 // as Blosum and Clustal require this to be done
193 if (hconsensus == null && !isDataset)
195 if (!alignment.isNucleotide())
197 conservation = new AlignmentAnnotation("Conservation",
198 "Conservation of total alignment less than " +
199 ConsPercGaps + "% gaps",
200 new Annotation[1], 0f,
202 AlignmentAnnotation.BAR_GRAPH);
203 conservation.hasText = true;
204 conservation.autoCalculated = true;
206 if (Cache.getDefault("SHOW_CONSERVATION", true))
208 alignment.addAnnotation(conservation);
211 if (Cache.getDefault("SHOW_QUALITY", true))
213 quality = new AlignmentAnnotation("Quality",
214 "Alignment Quality based on Blosum62 scores",
218 AlignmentAnnotation.BAR_GRAPH);
219 quality.hasText = true;
220 quality.autoCalculated = true;
222 alignment.addAnnotation(quality);
226 consensus = new AlignmentAnnotation("Consensus", "PID",
227 new Annotation[1], 0f, 100f,
228 AlignmentAnnotation.BAR_GRAPH);
229 consensus.hasText = true;
230 consensus.autoCalculated = true;
232 if (Cache.getDefault("SHOW_IDENTITY", true))
234 alignment.addAnnotation(consensus);
238 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
240 globalColourScheme = ColourSchemeProperty.getColour(alignment,
241 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
243 if (globalColourScheme instanceof UserColourScheme)
245 globalColourScheme = UserDefinedColours.loadDefaultColours();
246 ( (UserColourScheme) globalColourScheme).setThreshold(0,
247 getIgnoreGapsConsensus());
250 if (globalColourScheme != null)
252 globalColourScheme.setConsensus(hconsensus);
256 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
262 * @param b DOCUMENT ME!
264 public void setShowSequenceFeatures(boolean b)
266 showSequenceFeatures = b;
269 public boolean getShowSequenceFeatures()
271 return showSequenceFeatures;
274 class ConservationThread
278 public ConservationThread(AlignmentPanel ap)
287 updatingConservation = true;
289 while (UPDATING_CONSERVATION)
301 ex.printStackTrace();
305 UPDATING_CONSERVATION = true;
307 int alWidth = alignment.getWidth();
313 Conservation cons = new jalview.analysis.Conservation("All",
314 jalview.schemes.ResidueProperties.propHash, 3,
315 alignment.getSequences(), 0, alWidth - 1);
318 cons.verdict(false, ConsPercGaps);
325 char[] sequence = cons.getConsSequence().getSequence();
337 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
346 conservation.annotations = new Annotation[alWidth];
350 quality.graphMax = cons.qualityRange[1].floatValue();
351 quality.annotations = new Annotation[alWidth];
352 qmin = cons.qualityRange[0].floatValue();
353 qmax = cons.qualityRange[1].floatValue();
356 for (int i = 0; i < alWidth; i++)
362 if (Character.isDigit(c))
364 value = (int) (c - '0');
375 float vprop = value - min;
377 conservation.annotations[i] =
378 new Annotation(String.valueOf(c),
379 String.valueOf(value), ' ', value,
380 new Color(minR + (maxR * vprop),
381 minG + (maxG * vprop),
382 minB + (maxB * vprop)));
387 value = ( (Double) cons.quality.get(i)).floatValue();
388 vprop = value - qmin;
390 quality.annotations[i] = new Annotation(" ", String.valueOf(value),
393 new Color(minR + (maxR * vprop),
394 minG + (maxG * vprop),
395 minB + (maxB * vprop)));
399 catch (OutOfMemoryError error)
401 javax.swing.SwingUtilities.invokeLater(new Runnable()
406 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
407 "Out of memory calculating conservation!!"
409 "\nSee help files for increasing Java Virtual Machine memory."
411 javax.swing.JOptionPane.WARNING_MESSAGE);
418 System.out.println("Conservation calculation: " + error);
423 UPDATING_CONSERVATION = false;
424 updatingConservation = false;
434 ConservationThread conservationThread;
436 ConsensusThread consensusThread;
438 boolean consUpdateNeeded = false;
440 static boolean UPDATING_CONSENSUS = false;
442 static boolean UPDATING_CONSERVATION = false;
444 boolean updatingConsensus = false;
446 boolean updatingConservation = false;
451 public void updateConservation(final AlignmentPanel ap)
453 if (alignment.isNucleotide() || conservation == null)
458 conservationThread = new ConservationThread(ap);
459 conservationThread.start();
465 public void updateConsensus(final AlignmentPanel ap)
467 consensusThread = new ConsensusThread(ap);
468 consensusThread.start();
471 class ConsensusThread
475 public ConsensusThread(AlignmentPanel ap)
482 updatingConsensus = true;
483 while (UPDATING_CONSENSUS)
496 ex.printStackTrace();
500 UPDATING_CONSENSUS = true;
504 int aWidth = alignment.getWidth();
510 consensus.annotations = null;
511 consensus.annotations = new Annotation[aWidth];
513 hconsensus = new Hashtable[aWidth];
514 AAFrequency.calculate(alignment.getSequencesArray(),
516 alignment.getWidth(),
519 for (int i = 0; i < aWidth; i++)
522 if (ignoreGapsInConsensusCalculation)
524 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
529 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
533 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
534 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
536 if (maxRes.length() > 1)
538 mouseOver = "[" + maxRes + "] ";
542 mouseOver += ( (int) value + "%");
543 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
547 if (globalColourScheme != null)
549 globalColourScheme.setConsensus(hconsensus);
553 catch (OutOfMemoryError error)
555 alignment.deleteAnnotation(consensus);
559 javax.swing.SwingUtilities.invokeLater(new Runnable()
563 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
564 "Out of memory calculating consensus!!"
566 "\nSee help files for increasing Java Virtual Machine memory."
568 javax.swing.JOptionPane.WARNING_MESSAGE);
572 System.out.println("Consensus calculation: " + error);
575 UPDATING_CONSENSUS = false;
576 updatingConsensus = false;
586 * get the consensus sequence as displayed under the PID consensus annotation row.
587 * @return consensus sequence as a new sequence object
589 public SequenceI getConsensusSeq()
591 if (consensus == null)
593 updateConsensus(null);
595 if (consensus == null)
599 StringBuffer seqs = new StringBuffer();
600 for (int i = 0; i < consensus.annotations.length; i++)
602 if (consensus.annotations[i] != null)
604 if (consensus.annotations[i].description.charAt(0) == '[')
606 seqs.append(consensus.annotations[i].description.charAt(1));
610 seqs.append(consensus.annotations[i].displayCharacter);
615 SequenceI sq = new Sequence("Consensus", seqs.toString());
616 sq.setDescription("Percentage Identity Consensus " +
617 ( (ignoreGapsInConsensusCalculation) ? " without gaps" :
625 * @return DOCUMENT ME!
627 public SequenceGroup getSelectionGroup()
629 return selectionGroup;
635 * @param sg DOCUMENT ME!
637 public void setSelectionGroup(SequenceGroup sg)
645 * @return DOCUMENT ME!
647 public boolean getConservationSelected()
649 return conservationColourSelected;
655 * @param b DOCUMENT ME!
657 public void setConservationSelected(boolean b)
659 conservationColourSelected = b;
665 * @return DOCUMENT ME!
667 public boolean getAbovePIDThreshold()
669 return abovePIDThreshold;
675 * @param b DOCUMENT ME!
677 public void setAbovePIDThreshold(boolean b)
679 abovePIDThreshold = b;
685 * @return DOCUMENT ME!
687 public int getStartRes()
695 * @return DOCUMENT ME!
697 public int getEndRes()
705 * @return DOCUMENT ME!
707 public int getStartSeq()
715 * @param cs DOCUMENT ME!
717 public void setGlobalColourScheme(ColourSchemeI cs)
719 globalColourScheme = cs;
725 * @return DOCUMENT ME!
727 public ColourSchemeI getGlobalColourScheme()
729 return globalColourScheme;
735 * @param res DOCUMENT ME!
737 public void setStartRes(int res)
745 * @param seq DOCUMENT ME!
747 public void setStartSeq(int seq)
755 * @param res DOCUMENT ME!
757 public void setEndRes(int res)
759 if (res > (alignment.getWidth() - 1))
761 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
762 res = alignment.getWidth() - 1;
776 * @param seq DOCUMENT ME!
778 public void setEndSeq(int seq)
780 if (seq > alignment.getHeight())
782 seq = alignment.getHeight();
796 * @return DOCUMENT ME!
798 public int getEndSeq()
806 * @param f DOCUMENT ME!
808 public void setFont(Font f)
812 Container c = new Container();
814 java.awt.FontMetrics fm = c.getFontMetrics(font);
815 setCharHeight(fm.getHeight());
816 setCharWidth(fm.charWidth('M'));
817 validCharWidth = true;
823 * @return DOCUMENT ME!
825 public Font getFont()
833 * @param w DOCUMENT ME!
835 public void setCharWidth(int w)
843 * @return DOCUMENT ME!
845 public int getCharWidth()
853 * @param h DOCUMENT ME!
855 public void setCharHeight(int h)
863 * @return DOCUMENT ME!
865 public int getCharHeight()
873 * @param w DOCUMENT ME!
875 public void setWrappedWidth(int w)
877 this.wrappedWidth = w;
883 * @return DOCUMENT ME!
885 public int getWrappedWidth()
893 * @return DOCUMENT ME!
895 public AlignmentI getAlignment()
903 * @param align DOCUMENT ME!
905 public void setAlignment(AlignmentI align)
907 this.alignment = align;
913 * @param state DOCUMENT ME!
915 public void setWrapAlignment(boolean state)
917 wrapAlignment = state;
923 * @param state DOCUMENT ME!
925 public void setShowText(boolean state)
933 * @param state DOCUMENT ME!
935 public void setRenderGaps(boolean state)
943 * @return DOCUMENT ME!
945 public boolean getColourText()
947 return showColourText;
953 * @param state DOCUMENT ME!
955 public void setColourText(boolean state)
957 showColourText = state;
963 * @param state DOCUMENT ME!
965 public void setShowBoxes(boolean state)
973 * @return DOCUMENT ME!
975 public boolean getWrapAlignment()
977 return wrapAlignment;
983 * @return DOCUMENT ME!
985 public boolean getShowText()
993 * @return DOCUMENT ME!
995 public boolean getShowBoxes()
1003 * @return DOCUMENT ME!
1005 public char getGapCharacter()
1007 return getAlignment().getGapCharacter();
1013 * @param gap DOCUMENT ME!
1015 public void setGapCharacter(char gap)
1017 if (getAlignment() != null)
1019 getAlignment().setGapCharacter(gap);
1026 * @param thresh DOCUMENT ME!
1028 public void setThreshold(int thresh)
1036 * @return DOCUMENT ME!
1038 public int getThreshold()
1046 * @param inc DOCUMENT ME!
1048 public void setIncrement(int inc)
1056 * @return DOCUMENT ME!
1058 public int getIncrement()
1066 * @return DOCUMENT ME!
1068 public ColumnSelection getColumnSelection()
1076 * @param tree DOCUMENT ME!
1078 public void setCurrentTree(NJTree tree)
1086 * @return DOCUMENT ME!
1088 public NJTree getCurrentTree()
1096 * @param b DOCUMENT ME!
1098 public void setColourAppliesToAllGroups(boolean b)
1100 colourAppliesToAllGroups = b;
1106 * @return DOCUMENT ME!
1108 public boolean getColourAppliesToAllGroups()
1110 return colourAppliesToAllGroups;
1116 * @return DOCUMENT ME!
1118 public boolean getShowJVSuffix()
1120 return showJVSuffix;
1126 * @param b DOCUMENT ME!
1128 public void setShowJVSuffix(boolean b)
1136 * @return DOCUMENT ME!
1138 public boolean getShowAnnotation()
1140 return showAnnotation;
1146 * @param b DOCUMENT ME!
1148 public void setShowAnnotation(boolean b)
1156 * @return DOCUMENT ME!
1158 public boolean getScaleAboveWrapped()
1160 return scaleAboveWrapped;
1166 * @return DOCUMENT ME!
1168 public boolean getScaleLeftWrapped()
1170 return scaleLeftWrapped;
1176 * @return DOCUMENT ME!
1178 public boolean getScaleRightWrapped()
1180 return scaleRightWrapped;
1186 * @param b DOCUMENT ME!
1188 public void setScaleAboveWrapped(boolean b)
1190 scaleAboveWrapped = b;
1196 * @param b DOCUMENT ME!
1198 public void setScaleLeftWrapped(boolean b)
1200 scaleLeftWrapped = b;
1206 * @param b DOCUMENT ME!
1208 public void setScaleRightWrapped(boolean b)
1210 scaleRightWrapped = b;
1214 * Property change listener for changes in alignment
1216 * @param listener DOCUMENT ME!
1218 public void addPropertyChangeListener(
1219 java.beans.PropertyChangeListener listener)
1221 changeSupport.addPropertyChangeListener(listener);
1227 * @param listener DOCUMENT ME!
1229 public void removePropertyChangeListener(
1230 java.beans.PropertyChangeListener listener)
1232 changeSupport.removePropertyChangeListener(listener);
1236 * Property change listener for changes in alignment
1238 * @param prop DOCUMENT ME!
1239 * @param oldvalue DOCUMENT ME!
1240 * @param newvalue DOCUMENT ME!
1242 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
1244 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1247 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1249 ignoreGapsInConsensusCalculation = b;
1250 updateConsensus(ap);
1251 if (globalColourScheme != null)
1253 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1254 ignoreGapsInConsensusCalculation);
1258 public boolean getIgnoreGapsConsensus()
1260 return ignoreGapsInConsensusCalculation;
1263 public void setDataset(boolean b)
1268 public boolean isDataset()
1273 public void hideSelectedColumns()
1275 if (colSel.size() < 1)
1280 colSel.hideSelectedColumns();
1281 setSelectionGroup(null);
1283 hasHiddenColumns = true;
1286 public void hideColumns(int start, int end)
1290 colSel.hideColumns(start);
1294 colSel.hideColumns(start, end);
1297 hasHiddenColumns = true;
1300 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1302 int sSize = sg.getSize();
1308 if (hiddenRepSequences == null)
1310 hiddenRepSequences = new Hashtable();
1313 hiddenRepSequences.put(repSequence, sg);
1315 //Hide all sequences except the repSequence
1316 SequenceI[] seqs = new SequenceI[sSize - 1];
1318 for (int i = 0; i < sSize; i++)
1320 if (sg.getSequenceAt(i) != repSequence)
1322 if (index == sSize - 1)
1327 seqs[index++] = sg.getSequenceAt(i);
1335 public void hideAllSelectedSeqs()
1337 if (selectionGroup == null)
1342 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1346 setSelectionGroup(null);
1349 public void hideSequence(SequenceI[] seq)
1353 for (int i = 0; i < seq.length; i++)
1355 alignment.getHiddenSequences().hideSequence(seq[i]);
1357 hasHiddenRows = true;
1358 firePropertyChange("alignment", null, alignment.getSequences());
1362 public void showSequence(int index)
1364 Vector tmp = alignment.getHiddenSequences().showSequence(index
1365 , hiddenRepSequences);
1368 if (selectionGroup == null)
1370 selectionGroup = new SequenceGroup();
1371 selectionGroup.setEndRes(alignment.getWidth() - 1);
1374 for (int t = 0; t < tmp.size(); t++)
1376 selectionGroup.addSequence(
1377 (SequenceI) tmp.elementAt(t), false
1380 firePropertyChange("alignment", null, alignment.getSequences());
1383 if (alignment.getHiddenSequences().getSize() < 1)
1385 hasHiddenRows = false;
1389 public void showColumn(int col)
1391 colSel.revealHiddenColumns(col);
1392 if (colSel.getHiddenColumns() == null)
1394 hasHiddenColumns = false;
1398 public void showAllHiddenColumns()
1400 colSel.revealAllHiddenColumns();
1401 hasHiddenColumns = false;
1404 public void showAllHiddenSeqs()
1406 if (alignment.getHiddenSequences().getSize() > 0)
1408 if (selectionGroup == null)
1410 selectionGroup = new SequenceGroup();
1411 selectionGroup.setEndRes(alignment.getWidth() - 1);
1413 Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
1414 for (int t = 0; t < tmp.size(); t++)
1416 selectionGroup.addSequence(
1417 (SequenceI) tmp.elementAt(t), false
1420 firePropertyChange("alignment", null, alignment.getSequences());
1421 hasHiddenRows = false;
1422 hiddenRepSequences = null;
1426 public void invertColumnSelection()
1428 for (int i = 0; i < alignment.getWidth(); i++)
1430 if (colSel.contains(i))
1432 colSel.removeElement(i);
1436 if (!hasHiddenColumns || colSel.isVisible(i))
1438 colSel.addElement(i);
1444 public int adjustForHiddenSeqs(int alignmentIndex)
1446 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
1450 * This method returns the a new SequenceI [] with
1451 * the selection sequence and start and end points adjusted
1454 public SequenceI[] getSelectionAsNewSequence()
1456 SequenceI[] sequences;
1458 if (selectionGroup == null)
1460 sequences = alignment.getSequencesArray();
1464 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1471 * This method returns the visible alignment as text, as
1472 * seen on the GUI, ie if columns are hidden they will not
1473 * be returned in the result.
1474 * Use this for calculating trees, PCA, redundancy etc on views
1475 * which contain hidden columns.
1478 public jalview.datamodel.CigarArray getViewAsCigars(boolean
1481 CigarArray selection = null;
1482 SequenceI[] seqs = null;
1484 int start = 0, end = 0;
1485 if (selectedRegionOnly && selectionGroup != null)
1487 iSize = selectionGroup.getSize();
1488 seqs = selectionGroup.getSequencesInOrder(alignment);
1489 start = selectionGroup.getStartRes();
1490 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
1494 iSize = alignment.getHeight();
1495 seqs = alignment.getSequencesArray();
1496 end = alignment.getWidth() - 1;
1498 SeqCigar[] selseqs = new SeqCigar[iSize];
1499 for (i = 0; i < iSize; i++)
1501 selseqs[i] = new SeqCigar(seqs[i], start, end);
1503 selection = new CigarArray(selseqs);
1504 // now construct the CigarArray operations
1505 if (hasHiddenColumns)
1507 Vector regions = colSel.getHiddenColumns();
1509 int hideStart, hideEnd;
1511 for (int j = 0; last < end & j < regions.size(); j++)
1513 region = (int[]) regions.elementAt(j);
1514 hideStart = region[0];
1515 hideEnd = region[1];
1516 // edit hidden regions to selection range
1517 if (hideStart < last)
1529 if (hideStart > end)
1539 if (hideStart > hideEnd)
1544 * form operations...
1546 if (last < hideStart)
1548 selection.addOperation(CigarArray.M, hideStart - last);
1550 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1553 // Final match if necessary.
1556 selection.addOperation(CigarArray.M, end - last + 1);
1561 selection.addOperation(CigarArray.M, end - start + 1);
1567 * return a compact representation of the current alignment selection to
1568 * pass to an analysis function
1569 * @param selectedOnly boolean true to just return the selected view
1570 * @return AlignmentView
1572 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1575 // this is here because the AlignmentView constructor modifies the CigarArray
1576 // object. Refactoring of Cigar and alignment view representation should
1577 // be done to remove redundancy.
1578 CigarArray aligview = getViewAsCigars(selectedOnly);
1579 if (aligview != null)
1581 return new AlignmentView(aligview,
1582 (selectedOnly && selectionGroup != null) ?
1583 selectionGroup.getStartRes() : 0);
1589 * This method returns the visible alignment as text, as
1590 * seen on the GUI, ie if columns are hidden they will not
1591 * be returned in the result.
1592 * Use this for calculating trees, PCA, redundancy etc on views
1593 * which contain hidden columns.
1596 public String[] getViewAsString(boolean selectedRegionOnly)
1598 String[] selection = null;
1599 SequenceI[] seqs = null;
1601 int start = 0, end = 0;
1602 if (selectedRegionOnly && selectionGroup != null)
1604 iSize = selectionGroup.getSize();
1605 seqs = selectionGroup.getSequencesInOrder(alignment);
1606 start = selectionGroup.getStartRes();
1607 end = selectionGroup.getEndRes() + 1;
1611 iSize = alignment.getHeight();
1612 seqs = alignment.getSequencesArray();
1613 end = alignment.getWidth();
1616 selection = new String[iSize];
1617 if (hasHiddenColumns)
1619 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1623 for (i = 0; i < iSize; i++)
1625 selection[i] = seqs[i].getSequenceAsString(start, end);
1632 public boolean getShowHiddenMarkers()
1634 return showHiddenMarkers;
1637 public void setShowHiddenMarkers(boolean show)
1639 showHiddenMarkers = show;
1642 public String getSequenceSetId()
1644 if (sequenceSetID == null)
1646 sequenceSetID = alignment.hashCode() + "";
1649 return sequenceSetID;
1652 public void alignmentChanged(AlignmentPanel ap)
1656 alignment.padGaps();
1659 if (hconsensus != null && autoCalculateConsensus)
1661 updateConsensus(ap);
1662 updateConservation(ap);
1665 //Reset endRes of groups if beyond alignment width
1666 int alWidth = alignment.getWidth();
1667 Vector groups = alignment.getGroups();
1670 for (int i = 0; i < groups.size(); i++)
1672 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1673 if (sg.getEndRes() > alWidth)
1675 sg.setEndRes(alWidth - 1);
1680 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1682 selectionGroup.setEndRes(alWidth - 1);
1685 resetAllColourSchemes();
1687 // alignment.adjustSequenceAnnotations();
1690 void resetAllColourSchemes()
1692 ColourSchemeI cs = globalColourScheme;
1695 if (cs instanceof ClustalxColourScheme)
1697 ( (ClustalxColourScheme) cs).
1698 resetClustalX(alignment.getSequences(),
1699 alignment.getWidth());
1702 cs.setConsensus(hconsensus);
1703 if (cs.conservationApplied())
1705 Alignment al = (Alignment) alignment;
1706 Conservation c = new Conservation("All",
1707 ResidueProperties.propHash, 3,
1708 al.getSequences(), 0,
1711 c.verdict(false, ConsPercGaps);
1713 cs.setConservation(c);
1717 int s, sSize = alignment.getGroups().size();
1718 for (s = 0; s < sSize; s++)
1720 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1721 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1723 ( (ClustalxColourScheme) sg.cs).resetClustalX(
1724 sg.getSequences(hiddenRepSequences), sg.getWidth());
1726 sg.recalcConservation();
1730 public Color getSequenceColour(SequenceI seq)
1732 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1738 return (Color) sequenceColours.get(seq);
1742 public void setSequenceColour(SequenceI seq, Color col)
1744 if (sequenceColours == null)
1746 sequenceColours = new Hashtable();
1751 sequenceColours.remove(seq);
1755 sequenceColours.put(seq, col);