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;
64 boolean seqNameItalics;
66 ColumnSelection colSel = new ColumnSelection();
69 NJTree currentTree = null;
70 boolean scaleAboveWrapped = false;
71 boolean scaleLeftWrapped = true;
72 boolean scaleRightWrapped = true;
73 boolean hasHiddenColumns = false;
74 boolean hasHiddenRows = false;
75 boolean showHiddenMarkers = true;
77 boolean cursorMode = false;
79 // The following vector holds the features which are
80 // currently visible, in the correct order or rendering
81 Hashtable featuresDisplayed = null;
85 public Hashtable [] hconsensus;
86 AlignmentAnnotation consensus;
87 AlignmentAnnotation conservation;
88 AlignmentAnnotation quality;
89 boolean autoCalculateConsensus = true;
92 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
94 // JBPNote Prolly only need this in the applet version.
95 private java.beans.PropertyChangeSupport changeSupport = new java.beans.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) {
144 if (hiddenColumns!=null) {
145 this.colSel = hiddenColumns;
146 if (hiddenColumns.getHiddenColumns() != null)
147 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) );
192 // We must set conservation and consensus before setting colour,
193 // as Blosum and Clustal require this to be done
194 if(hconsensus==null && !isDataset)
196 if(!alignment.isNucleotide())
198 conservation = new AlignmentAnnotation("Conservation",
199 "Conservation of total alignment less than " +
200 ConsPercGaps + "% gaps",
201 new Annotation[1], 0f,
203 AlignmentAnnotation.BAR_GRAPH);
204 conservation.hasText = true;
205 conservation.autoCalculated = true;
208 if (Cache.getDefault("SHOW_CONSERVATION", true))
210 alignment.addAnnotation(conservation);
213 if (Cache.getDefault("SHOW_QUALITY", true))
215 quality = new AlignmentAnnotation("Quality",
216 "Alignment Quality based on Blosum62 scores",
220 AlignmentAnnotation.BAR_GRAPH);
221 quality.hasText = true;
222 quality.autoCalculated = true;
224 alignment.addAnnotation(quality);
228 consensus = new AlignmentAnnotation("Consensus", "PID",
229 new Annotation[1], 0f, 100f,
230 AlignmentAnnotation.BAR_GRAPH);
231 consensus.hasText = true;
232 consensus.autoCalculated = true;
234 if (Cache.getDefault("SHOW_IDENTITY", true))
236 alignment.addAnnotation(consensus);
240 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
242 globalColourScheme = ColourSchemeProperty.getColour(alignment,
243 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
245 if (globalColourScheme instanceof UserColourScheme)
247 globalColourScheme = UserDefinedColours.loadDefaultColours();
248 ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());
251 if (globalColourScheme != null)
253 globalColourScheme.setConsensus(hconsensus);
257 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
265 * @param b DOCUMENT ME!
267 public void setShowSequenceFeatures(boolean b)
269 showSequenceFeatures = b;
272 public boolean getShowSequenceFeatures()
274 return showSequenceFeatures;
279 class ConservationThread extends Thread
282 public ConservationThread(AlignmentPanel ap)
291 updatingConservation = true;
293 while (UPDATING_CONSERVATION)
305 ex.printStackTrace();
309 UPDATING_CONSERVATION = true;
312 int alWidth = alignment.getWidth();
316 Conservation cons = new jalview.analysis.Conservation("All",
317 jalview.schemes.ResidueProperties.propHash, 3,
318 alignment.getSequences(), 0, alWidth -1);
321 cons.verdict(false, ConsPercGaps);
328 char [] sequence = cons.getConsSequence().getSequence();
340 maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
349 conservation.annotations = new Annotation[alWidth];
353 quality.graphMax = cons.qualityRange[1].floatValue();
354 quality.annotations = new Annotation[alWidth];
355 qmin = cons.qualityRange[0].floatValue();
356 qmax = cons.qualityRange[1].floatValue();
359 for (int i = 0; i < alWidth; i++)
365 if (Character.isDigit(c))
366 value = (int) (c - '0');
372 float vprop = value - min;
374 conservation.annotations[i] =
375 new Annotation(String.valueOf(c),
376 String.valueOf(value), ' ', value,
377 new Color(minR + (maxR * vprop),
378 minG + (maxG * vprop),
379 minB + (maxB * vprop)));
384 value = ( (Double) cons.quality.get(i)).floatValue();
385 vprop = value - qmin;
387 quality.annotations[i] = new Annotation(" ", String.valueOf(value), ' ',
389 new Color(minR + (maxR * vprop),
390 minG + (maxG * vprop),
391 minB + (maxB * vprop)));
395 catch (OutOfMemoryError error)
397 javax.swing.SwingUtilities.invokeLater(new Runnable()
403 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
404 "Out of memory calculating conservation!!"
406 "\nSee help files for increasing Java Virtual Machine memory."
408 javax.swing.JOptionPane.WARNING_MESSAGE);
415 System.out.println("Conservation calculation: " + error);
420 UPDATING_CONSERVATION = false;
421 updatingConservation = false;
432 ConservationThread conservationThread;
434 ConsensusThread consensusThread;
436 boolean consUpdateNeeded = false;
438 static boolean UPDATING_CONSENSUS = false;
440 static boolean UPDATING_CONSERVATION = false;
442 boolean updatingConsensus = false;
444 boolean updatingConservation = false;
449 public void updateConservation(final AlignmentPanel ap)
451 if (alignment.isNucleotide() || conservation==null)
454 conservationThread = new ConservationThread(ap);
455 conservationThread.start();
461 public void updateConsensus(final AlignmentPanel ap)
463 consensusThread = new ConsensusThread(ap);
464 consensusThread.start();
468 class ConsensusThread extends Thread
471 public ConsensusThread(AlignmentPanel ap)
477 updatingConsensus = true;
478 while (UPDATING_CONSENSUS)
491 ex.printStackTrace();
496 UPDATING_CONSENSUS = true;
500 int aWidth = alignment.getWidth();
504 consensus.annotations = null;
505 consensus.annotations = new Annotation[aWidth];
508 hconsensus = new Hashtable[aWidth];
509 AAFrequency.calculate(alignment.getSequencesArray(),
511 alignment.getWidth(),
514 for (int i = 0; i < aWidth; i++)
517 if (ignoreGapsInConsensusCalculation)
518 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
521 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
524 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
525 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
527 if (maxRes.length() > 1)
529 mouseOver = "[" + maxRes + "] ";
533 mouseOver += ( (int) value + "%");
534 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
538 if (globalColourScheme != null)
539 globalColourScheme.setConsensus(hconsensus);
542 catch (OutOfMemoryError error)
544 alignment.deleteAnnotation(consensus);
548 javax.swing.SwingUtilities.invokeLater(new Runnable()
552 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
553 "Out of memory calculating consensus!!"
555 "\nSee help files for increasing Java Virtual Machine memory."
557 javax.swing.JOptionPane.WARNING_MESSAGE);
561 System.out.println("Consensus calculation: " + error);
564 UPDATING_CONSENSUS = false;
565 updatingConsensus = false;
574 * get the consensus sequence as displayed under the PID consensus annotation row.
575 * @return consensus sequence as a new sequence object
577 public SequenceI getConsensusSeq() {
579 updateConsensus(null);
582 StringBuffer seqs=new StringBuffer();
583 for (int i=0; i<consensus.annotations.length; i++) {
584 if (consensus.annotations[i]!=null) {
585 if (consensus.annotations[i].description.charAt(0) == '[')
586 seqs.append(consensus.annotations[i].description.charAt(1));
588 seqs.append(consensus.annotations[i].displayCharacter);
592 SequenceI sq = new Sequence("Consensus", seqs.toString());
593 sq.setDescription("Percentage Identity Consensus "+((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
599 * @return DOCUMENT ME!
601 public SequenceGroup getSelectionGroup()
603 return selectionGroup;
609 * @param sg DOCUMENT ME!
611 public void setSelectionGroup(SequenceGroup sg)
619 * @return DOCUMENT ME!
621 public boolean getConservationSelected()
623 return conservationColourSelected;
629 * @param b DOCUMENT ME!
631 public void setConservationSelected(boolean b)
633 conservationColourSelected = b;
639 * @return DOCUMENT ME!
641 public boolean getAbovePIDThreshold()
643 return abovePIDThreshold;
649 * @param b DOCUMENT ME!
651 public void setAbovePIDThreshold(boolean b)
653 abovePIDThreshold = b;
659 * @return DOCUMENT ME!
661 public int getStartRes()
669 * @return DOCUMENT ME!
671 public int getEndRes()
679 * @return DOCUMENT ME!
681 public int getStartSeq()
689 * @param cs DOCUMENT ME!
691 public void setGlobalColourScheme(ColourSchemeI cs)
693 globalColourScheme = cs;
699 * @return DOCUMENT ME!
701 public ColourSchemeI getGlobalColourScheme()
703 return globalColourScheme;
709 * @param res DOCUMENT ME!
711 public void setStartRes(int res)
719 * @param seq DOCUMENT ME!
721 public void setStartSeq(int seq)
729 * @param res DOCUMENT ME!
731 public void setEndRes(int res)
733 if (res > (alignment.getWidth() - 1))
735 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
736 res = alignment.getWidth() - 1;
750 * @param seq DOCUMENT ME!
752 public void setEndSeq(int seq)
754 if (seq > alignment.getHeight())
756 seq = alignment.getHeight();
770 * @return DOCUMENT ME!
772 public int getEndSeq()
780 * @param f DOCUMENT ME!
782 public void setFont(Font f)
786 Container c = new Container();
788 java.awt.FontMetrics fm = c.getFontMetrics(font);
789 setCharHeight(fm.getHeight());
790 setCharWidth(fm.charWidth('M'));
791 validCharWidth = true;
797 * @return DOCUMENT ME!
799 public Font getFont()
807 * @param w DOCUMENT ME!
809 public void setCharWidth(int w)
817 * @return DOCUMENT ME!
819 public int getCharWidth()
827 * @param h DOCUMENT ME!
829 public void setCharHeight(int h)
837 * @return DOCUMENT ME!
839 public int getCharHeight()
847 * @param w DOCUMENT ME!
849 public void setWrappedWidth(int w)
851 this.wrappedWidth = w;
857 * @return DOCUMENT ME!
859 public int getWrappedWidth()
868 * @return DOCUMENT ME!
870 public AlignmentI getAlignment()
878 * @param align DOCUMENT ME!
880 public void setAlignment(AlignmentI align)
882 this.alignment = align;
888 * @param state DOCUMENT ME!
890 public void setWrapAlignment(boolean state)
892 wrapAlignment = state;
898 * @param state DOCUMENT ME!
900 public void setShowText(boolean state)
908 * @param state DOCUMENT ME!
910 public void setRenderGaps(boolean state)
918 * @return DOCUMENT ME!
920 public boolean getColourText()
922 return showColourText;
928 * @param state DOCUMENT ME!
930 public void setColourText(boolean state)
932 showColourText = state;
938 * @param state DOCUMENT ME!
940 public void setShowBoxes(boolean state)
948 * @return DOCUMENT ME!
950 public boolean getWrapAlignment()
952 return wrapAlignment;
958 * @return DOCUMENT ME!
960 public boolean getShowText()
968 * @return DOCUMENT ME!
970 public boolean getShowBoxes()
978 * @return DOCUMENT ME!
980 public char getGapCharacter()
982 return getAlignment().getGapCharacter();
988 * @param gap DOCUMENT ME!
990 public void setGapCharacter(char gap)
992 if (getAlignment() != null)
994 getAlignment().setGapCharacter(gap);
1001 * @param thresh DOCUMENT ME!
1003 public void setThreshold(int thresh)
1011 * @return DOCUMENT ME!
1013 public int getThreshold()
1021 * @param inc DOCUMENT ME!
1023 public void setIncrement(int inc)
1031 * @return DOCUMENT ME!
1033 public int getIncrement()
1042 * @return DOCUMENT ME!
1044 public ColumnSelection getColumnSelection()
1053 * @param tree DOCUMENT ME!
1055 public void setCurrentTree(NJTree tree)
1063 * @return DOCUMENT ME!
1065 public NJTree getCurrentTree()
1073 * @param b DOCUMENT ME!
1075 public void setColourAppliesToAllGroups(boolean b)
1077 colourAppliesToAllGroups = b;
1083 * @return DOCUMENT ME!
1085 public boolean getColourAppliesToAllGroups()
1087 return colourAppliesToAllGroups;
1093 * @return DOCUMENT ME!
1095 public boolean getShowJVSuffix()
1097 return showJVSuffix;
1103 * @param b DOCUMENT ME!
1105 public void setShowJVSuffix(boolean b)
1114 * @return DOCUMENT ME!
1116 public boolean getShowAnnotation()
1118 return showAnnotation;
1124 * @param b DOCUMENT ME!
1126 public void setShowAnnotation(boolean b)
1134 * @return DOCUMENT ME!
1136 public boolean getScaleAboveWrapped()
1138 return scaleAboveWrapped;
1144 * @return DOCUMENT ME!
1146 public boolean getScaleLeftWrapped()
1148 return scaleLeftWrapped;
1154 * @return DOCUMENT ME!
1156 public boolean getScaleRightWrapped()
1158 return scaleRightWrapped;
1164 * @param b DOCUMENT ME!
1166 public void setScaleAboveWrapped(boolean b)
1168 scaleAboveWrapped = b;
1174 * @param b DOCUMENT ME!
1176 public void setScaleLeftWrapped(boolean b)
1178 scaleLeftWrapped = b;
1184 * @param b DOCUMENT ME!
1186 public void setScaleRightWrapped(boolean b)
1188 scaleRightWrapped = b;
1192 * Property change listener for changes in alignment
1194 * @param listener DOCUMENT ME!
1196 public void addPropertyChangeListener(
1197 java.beans.PropertyChangeListener listener)
1199 changeSupport.addPropertyChangeListener(listener);
1205 * @param listener DOCUMENT ME!
1207 public void removePropertyChangeListener(
1208 java.beans.PropertyChangeListener listener)
1210 changeSupport.removePropertyChangeListener(listener);
1214 * Property change listener for changes in alignment
1216 * @param prop DOCUMENT ME!
1217 * @param oldvalue DOCUMENT ME!
1218 * @param newvalue DOCUMENT ME!
1220 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
1222 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1225 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1227 ignoreGapsInConsensusCalculation = b;
1228 updateConsensus(ap);
1229 if(globalColourScheme!=null)
1231 globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);
1235 public boolean getIgnoreGapsConsensus()
1237 return ignoreGapsInConsensusCalculation;
1240 public void setDataset(boolean b)
1245 public boolean isDataset()
1251 public void hideSelectedColumns()
1253 if (colSel.size() < 1)
1256 colSel.hideSelectedColumns();
1257 setSelectionGroup(null);
1259 hasHiddenColumns = true;
1263 public void hideColumns(int start, int end)
1266 colSel.hideColumns(start);
1268 colSel.hideColumns(start, end);
1270 hasHiddenColumns = true;
1273 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1275 int sSize = sg.getSize();
1279 if(hiddenRepSequences==null)
1280 hiddenRepSequences = new Hashtable();
1282 hiddenRepSequences.put(repSequence, sg);
1284 //Hide all sequences except the repSequence
1285 SequenceI [] seqs = new SequenceI[sSize-1];
1287 for(int i=0; i<sSize; i++)
1288 if(sg.getSequenceAt(i)!=repSequence)
1293 seqs[index++] = sg.getSequenceAt(i);
1300 public void hideAllSelectedSeqs()
1302 if (selectionGroup == null)
1305 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1309 setSelectionGroup(null);
1312 public void hideSequence(SequenceI [] seq)
1316 for (int i = 0; i < seq.length; i++)
1318 alignment.getHiddenSequences().hideSequence(seq[i]);
1320 hasHiddenRows = true;
1321 firePropertyChange("alignment", null, alignment.getSequences());
1325 public void showSequence(int index)
1327 Vector tmp = alignment.getHiddenSequences().showSequence(index
1328 , hiddenRepSequences);
1331 if(selectionGroup==null)
1333 selectionGroup = new SequenceGroup();
1334 selectionGroup.setEndRes(alignment.getWidth()-1);
1337 for (int t = 0; t < tmp.size(); t++)
1339 selectionGroup.addSequence(
1340 (SequenceI) tmp.elementAt(t), false
1343 firePropertyChange("alignment", null, alignment.getSequences());
1346 if(alignment.getHiddenSequences().getSize()<1)
1347 hasHiddenRows = false;
1350 public void showColumn(int col)
1352 colSel.revealHiddenColumns(col);
1353 if(colSel.getHiddenColumns()==null)
1354 hasHiddenColumns = false;
1357 public void showAllHiddenColumns()
1359 colSel.revealAllHiddenColumns();
1360 hasHiddenColumns = false;
1363 public void showAllHiddenSeqs()
1365 if(alignment.getHiddenSequences().getSize()>0)
1367 if(selectionGroup==null)
1369 selectionGroup = new SequenceGroup();
1370 selectionGroup.setEndRes(alignment.getWidth()-1);
1372 Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
1373 for(int t=0; t<tmp.size(); t++)
1375 selectionGroup.addSequence(
1376 (SequenceI)tmp.elementAt(t), false
1379 firePropertyChange("alignment", null, alignment.getSequences());
1380 hasHiddenRows = false;
1381 hiddenRepSequences = null;
1387 public void invertColumnSelection()
1389 for(int i=0; i<alignment.getWidth(); i++)
1391 if(colSel.contains(i))
1392 colSel.removeElement(i);
1395 if (!hasHiddenColumns || colSel.isVisible(i))
1397 colSel.addElement(i);
1403 public int adjustForHiddenSeqs(int alignmentIndex)
1405 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
1409 * This method returns the a new SequenceI [] with
1410 * the selection sequence and start and end points adjusted
1413 public SequenceI[] getSelectionAsNewSequence()
1415 SequenceI[] sequences;
1417 if (selectionGroup == null)
1418 sequences = alignment.getSequencesArray();
1420 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1426 * This method returns the visible alignment as text, as
1427 * seen on the GUI, ie if columns are hidden they will not
1428 * be returned in the result.
1429 * Use this for calculating trees, PCA, redundancy etc on views
1430 * which contain hidden columns.
1433 public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)
1435 CigarArray selection=null;
1436 SequenceI [] seqs= null;
1438 int start = 0, end = 0;
1439 if(selectedRegionOnly && selectionGroup!=null)
1441 iSize = selectionGroup.getSize();
1442 seqs = selectionGroup.getSequencesInOrder(alignment);
1443 start = selectionGroup.getStartRes();
1444 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
1448 iSize = alignment.getHeight();
1449 seqs = alignment.getSequencesArray();
1450 end = alignment.getWidth()-1;
1452 SeqCigar[] selseqs = new SeqCigar[iSize];
1453 for(i=0; i<iSize; i++)
1455 selseqs[i] = new SeqCigar(seqs[i], start, end);
1457 selection=new CigarArray(selseqs);
1458 // now construct the CigarArray operations
1459 if (hasHiddenColumns) {
1460 Vector regions = colSel.getHiddenColumns();
1462 int hideStart, hideEnd;
1464 for (int j = 0; last<end & j < regions.size(); j++)
1466 region = (int[]) regions.elementAt(j);
1467 hideStart = region[0];
1468 hideEnd = region[1];
1469 // edit hidden regions to selection range
1470 if(hideStart<last) {
1484 if (hideStart>hideEnd)
1487 * form operations...
1490 selection.addOperation(CigarArray.M, hideStart-last);
1491 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
1494 // Final match if necessary.
1496 selection.addOperation(CigarArray.M, end-last+1);
1498 selection.addOperation(CigarArray.M, end-start+1);
1503 * return a compact representation of the current alignment selection to
1504 * pass to an analysis function
1505 * @param selectedOnly boolean true to just return the selected view
1506 * @return AlignmentView
1508 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {
1510 // this is here because the AlignmentView constructor modifies the CigarArray
1511 // object. Refactoring of Cigar and alignment view representation should
1512 // be done to remove redundancy.
1513 CigarArray aligview = getViewAsCigars(selectedOnly);
1514 if (aligview!=null) {
1515 return new AlignmentView(aligview,
1516 (selectedOnly && selectionGroup!=null) ? selectionGroup.getStartRes() : 0);
1521 * This method returns the visible alignment as text, as
1522 * seen on the GUI, ie if columns are hidden they will not
1523 * be returned in the result.
1524 * Use this for calculating trees, PCA, redundancy etc on views
1525 * which contain hidden columns.
1528 public String [] getViewAsString(boolean selectedRegionOnly)
1530 String [] selection = null;
1531 SequenceI [] seqs= null;
1533 int start = 0, end = 0;
1534 if(selectedRegionOnly && selectionGroup!=null)
1536 iSize = selectionGroup.getSize();
1537 seqs = selectionGroup.getSequencesInOrder(alignment);
1538 start = selectionGroup.getStartRes();
1539 end = selectionGroup.getEndRes()+1;
1543 iSize = alignment.getHeight();
1544 seqs = alignment.getSequencesArray();
1545 end = alignment.getWidth();
1548 selection = new String[iSize];
1549 if (hasHiddenColumns) {
1550 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1552 for(i=0; i<iSize; i++)
1554 selection[i] = seqs[i].getSequenceAsString(start, end);
1561 public boolean getShowHiddenMarkers()
1563 return showHiddenMarkers;
1566 public void setShowHiddenMarkers(boolean show)
1568 showHiddenMarkers = show;
1571 public String getSequenceSetId()
1573 if(sequenceSetID==null)
1574 sequenceSetID = alignment.hashCode()+"";
1576 return sequenceSetID;
1579 public void alignmentChanged(AlignmentPanel ap)
1582 alignment.padGaps();
1584 if (hconsensus != null && autoCalculateConsensus)
1586 updateConsensus(ap);
1587 updateConservation(ap);
1590 //Reset endRes of groups if beyond alignment width
1591 int alWidth = alignment.getWidth();
1592 Vector groups = alignment.getGroups();
1595 for(int i=0; i<groups.size(); i++)
1597 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
1598 if(sg.getEndRes()>alWidth)
1599 sg.setEndRes(alWidth-1);
1603 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
1604 selectionGroup.setEndRes(alWidth-1);
1606 resetAllColourSchemes();
1608 // alignment.adjustSequenceAnnotations();
1612 void resetAllColourSchemes()
1614 ColourSchemeI cs = globalColourScheme;
1617 if (cs instanceof ClustalxColourScheme)
1619 ( (ClustalxColourScheme) cs).
1620 resetClustalX(alignment.getSequences(),
1621 alignment.getWidth());
1624 cs.setConsensus(hconsensus);
1625 if (cs.conservationApplied())
1627 Alignment al = (Alignment) alignment;
1628 Conservation c = new Conservation("All",
1629 ResidueProperties.propHash, 3,
1630 al.getSequences(), 0,
1633 c.verdict(false, ConsPercGaps);
1635 cs.setConservation(c);
1639 int s, sSize = alignment.getGroups().size();
1640 for(s=0; s<sSize; s++)
1642 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
1643 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1645 ((ClustalxColourScheme)sg.cs).resetClustalX(
1646 sg.getSequences(hiddenRepSequences), sg.getWidth());
1648 sg.recalcConservation();
1653 public Color getSequenceColour(SequenceI seq)
1655 if(sequenceColours==null || !sequenceColours.containsKey(seq))
1658 return (Color)sequenceColours.get(seq);
1661 public void setSequenceColour(SequenceI seq, Color col)
1663 if(sequenceColours==null)
1664 sequenceColours = new Hashtable();
1667 sequenceColours.remove(seq);
1669 sequenceColours.put(seq, col);