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;
202 conservation.autoCalculated = true;
205 if (Cache.getDefault("SHOW_CONSERVATION", true))
207 alignment.addAnnotation(conservation);
210 if (Cache.getDefault("SHOW_QUALITY", true))
212 quality = new AlignmentAnnotation("Quality",
213 "Alignment Quality based on Blosum62 scores",
217 AlignmentAnnotation.BAR_GRAPH);
218 quality.hasText = true;
219 quality.autoCalculated = true;
221 alignment.addAnnotation(quality);
225 consensus = new AlignmentAnnotation("Consensus", "PID",
226 new Annotation[1], 0f, 100f,
227 AlignmentAnnotation.BAR_GRAPH);
228 consensus.hasText = true;
229 consensus.autoCalculated = true;
231 if (Cache.getDefault("SHOW_IDENTITY", true))
233 alignment.addAnnotation(consensus);
237 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
239 globalColourScheme = ColourSchemeProperty.getColour(alignment,
240 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
242 if (globalColourScheme instanceof UserColourScheme)
244 globalColourScheme = UserDefinedColours.loadDefaultColours();
245 ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());
248 if (globalColourScheme != null)
250 globalColourScheme.setConsensus(hconsensus);
254 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;
276 class ConservationThread extends Thread
279 public ConservationThread(AlignmentPanel ap)
288 updatingConservation = true;
290 while (UPDATING_CONSERVATION)
302 ex.printStackTrace();
306 UPDATING_CONSERVATION = true;
309 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))
363 value = (int) (c - '0');
369 float vprop = value - min;
371 conservation.annotations[i] =
372 new Annotation(String.valueOf(c),
373 String.valueOf(value), ' ', value,
374 new Color(minR + (maxR * vprop),
375 minG + (maxG * vprop),
376 minB + (maxB * vprop)));
381 value = ( (Double) cons.quality.get(i)).floatValue();
382 vprop = value - qmin;
384 quality.annotations[i] = new Annotation(" ", String.valueOf(value), ' ',
386 new Color(minR + (maxR * vprop),
387 minG + (maxG * vprop),
388 minB + (maxB * vprop)));
392 catch (OutOfMemoryError error)
394 javax.swing.SwingUtilities.invokeLater(new Runnable()
400 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
401 "Out of memory calculating conservation!!"
403 "\nSee help files for increasing Java Virtual Machine memory."
405 javax.swing.JOptionPane.WARNING_MESSAGE);
412 System.out.println("Conservation calculation: " + error);
417 UPDATING_CONSERVATION = false;
418 updatingConservation = false;
429 ConservationThread conservationThread;
431 ConsensusThread consensusThread;
433 boolean consUpdateNeeded = false;
435 static boolean UPDATING_CONSENSUS = false;
437 static boolean UPDATING_CONSERVATION = false;
439 boolean updatingConsensus = false;
441 boolean updatingConservation = false;
446 public void updateConservation(final AlignmentPanel ap)
448 if (alignment.isNucleotide() || conservation==null)
451 conservationThread = new ConservationThread(ap);
452 conservationThread.start();
458 public void updateConsensus(final AlignmentPanel ap)
460 consensusThread = new ConsensusThread(ap);
461 consensusThread.start();
465 class ConsensusThread extends Thread
468 public ConsensusThread(AlignmentPanel ap)
474 updatingConsensus = true;
475 while (UPDATING_CONSENSUS)
488 ex.printStackTrace();
493 UPDATING_CONSENSUS = true;
497 int aWidth = alignment.getWidth();
501 consensus.annotations = null;
502 consensus.annotations = new Annotation[aWidth];
505 hconsensus = new Hashtable[aWidth];
506 AAFrequency.calculate(alignment.getSequencesArray(),
508 alignment.getWidth(),
511 for (int i = 0; i < aWidth; i++)
514 if (ignoreGapsInConsensusCalculation)
515 value = ( (Float) hconsensus[i].get(AAFrequency.PID_NOGAPS)).
518 value = ( (Float) hconsensus[i].get(AAFrequency.PID_GAPS)).
521 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE).toString();
522 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE) + " ";
524 if (maxRes.length() > 1)
526 mouseOver = "[" + maxRes + "] ";
530 mouseOver += ( (int) value + "%");
531 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
535 if (globalColourScheme != null)
536 globalColourScheme.setConsensus(hconsensus);
539 catch (OutOfMemoryError error)
541 alignment.deleteAnnotation(consensus);
545 javax.swing.SwingUtilities.invokeLater(new Runnable()
549 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
550 "Out of memory calculating consensus!!"
552 "\nSee help files for increasing Java Virtual Machine memory."
554 javax.swing.JOptionPane.WARNING_MESSAGE);
558 System.out.println("Consensus calculation: " + error);
561 UPDATING_CONSENSUS = false;
562 updatingConsensus = false;
571 * get the consensus sequence as displayed under the PID consensus annotation row.
572 * @return consensus sequence as a new sequence object
574 public SequenceI getConsensusSeq() {
576 updateConsensus(null);
579 StringBuffer seqs=new StringBuffer();
580 for (int i=0; i<consensus.annotations.length; i++) {
581 if (consensus.annotations[i]!=null) {
582 if (consensus.annotations[i].description.charAt(0) == '[')
583 seqs.append(consensus.annotations[i].description.charAt(1));
585 seqs.append(consensus.annotations[i].displayCharacter);
589 SequenceI sq = new Sequence("Consensus", seqs.toString());
590 sq.setDescription("Percentage Identity Consensus "+((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
596 * @return DOCUMENT ME!
598 public SequenceGroup getSelectionGroup()
600 return selectionGroup;
606 * @param sg DOCUMENT ME!
608 public void setSelectionGroup(SequenceGroup sg)
616 * @return DOCUMENT ME!
618 public boolean getConservationSelected()
620 return conservationColourSelected;
626 * @param b DOCUMENT ME!
628 public void setConservationSelected(boolean b)
630 conservationColourSelected = b;
636 * @return DOCUMENT ME!
638 public boolean getAbovePIDThreshold()
640 return abovePIDThreshold;
646 * @param b DOCUMENT ME!
648 public void setAbovePIDThreshold(boolean b)
650 abovePIDThreshold = b;
656 * @return DOCUMENT ME!
658 public int getStartRes()
666 * @return DOCUMENT ME!
668 public int getEndRes()
676 * @return DOCUMENT ME!
678 public int getStartSeq()
686 * @param cs DOCUMENT ME!
688 public void setGlobalColourScheme(ColourSchemeI cs)
690 globalColourScheme = cs;
696 * @return DOCUMENT ME!
698 public ColourSchemeI getGlobalColourScheme()
700 return globalColourScheme;
706 * @param res DOCUMENT ME!
708 public void setStartRes(int res)
716 * @param seq DOCUMENT ME!
718 public void setStartSeq(int seq)
726 * @param res DOCUMENT ME!
728 public void setEndRes(int res)
730 if (res > (alignment.getWidth() - 1))
732 // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
733 res = alignment.getWidth() - 1;
747 * @param seq DOCUMENT ME!
749 public void setEndSeq(int seq)
751 if (seq > alignment.getHeight())
753 seq = alignment.getHeight();
767 * @return DOCUMENT ME!
769 public int getEndSeq()
777 * @param f DOCUMENT ME!
779 public void setFont(Font f)
783 Container c = new Container();
785 java.awt.FontMetrics fm = c.getFontMetrics(font);
786 setCharHeight(fm.getHeight());
787 setCharWidth(fm.charWidth('M'));
788 validCharWidth = true;
794 * @return DOCUMENT ME!
796 public Font getFont()
804 * @param w DOCUMENT ME!
806 public void setCharWidth(int w)
814 * @return DOCUMENT ME!
816 public int getCharWidth()
824 * @param h DOCUMENT ME!
826 public void setCharHeight(int h)
834 * @return DOCUMENT ME!
836 public int getCharHeight()
844 * @param w DOCUMENT ME!
846 public void setWrappedWidth(int w)
848 this.wrappedWidth = w;
854 * @return DOCUMENT ME!
856 public int getWrappedWidth()
865 * @return DOCUMENT ME!
867 public AlignmentI getAlignment()
875 * @param align DOCUMENT ME!
877 public void setAlignment(AlignmentI align)
879 this.alignment = align;
885 * @param state DOCUMENT ME!
887 public void setWrapAlignment(boolean state)
889 wrapAlignment = state;
895 * @param state DOCUMENT ME!
897 public void setShowText(boolean state)
905 * @param state DOCUMENT ME!
907 public void setRenderGaps(boolean state)
915 * @return DOCUMENT ME!
917 public boolean getColourText()
919 return showColourText;
925 * @param state DOCUMENT ME!
927 public void setColourText(boolean state)
929 showColourText = state;
935 * @param state DOCUMENT ME!
937 public void setShowBoxes(boolean state)
945 * @return DOCUMENT ME!
947 public boolean getWrapAlignment()
949 return wrapAlignment;
955 * @return DOCUMENT ME!
957 public boolean getShowText()
965 * @return DOCUMENT ME!
967 public boolean getShowBoxes()
975 * @return DOCUMENT ME!
977 public char getGapCharacter()
979 return getAlignment().getGapCharacter();
985 * @param gap DOCUMENT ME!
987 public void setGapCharacter(char gap)
989 if (getAlignment() != null)
991 getAlignment().setGapCharacter(gap);
998 * @param thresh DOCUMENT ME!
1000 public void setThreshold(int thresh)
1008 * @return DOCUMENT ME!
1010 public int getThreshold()
1018 * @param inc DOCUMENT ME!
1020 public void setIncrement(int inc)
1028 * @return DOCUMENT ME!
1030 public int getIncrement()
1039 * @return DOCUMENT ME!
1041 public ColumnSelection getColumnSelection()
1050 * @param tree DOCUMENT ME!
1052 public void setCurrentTree(NJTree tree)
1060 * @return DOCUMENT ME!
1062 public NJTree getCurrentTree()
1070 * @param b DOCUMENT ME!
1072 public void setColourAppliesToAllGroups(boolean b)
1074 colourAppliesToAllGroups = b;
1080 * @return DOCUMENT ME!
1082 public boolean getColourAppliesToAllGroups()
1084 return colourAppliesToAllGroups;
1090 * @return DOCUMENT ME!
1092 public boolean getShowJVSuffix()
1094 return showJVSuffix;
1100 * @param b DOCUMENT ME!
1102 public void setShowJVSuffix(boolean b)
1111 * @return DOCUMENT ME!
1113 public boolean getShowAnnotation()
1115 return showAnnotation;
1121 * @param b DOCUMENT ME!
1123 public void setShowAnnotation(boolean b)
1131 * @return DOCUMENT ME!
1133 public boolean getScaleAboveWrapped()
1135 return scaleAboveWrapped;
1141 * @return DOCUMENT ME!
1143 public boolean getScaleLeftWrapped()
1145 return scaleLeftWrapped;
1151 * @return DOCUMENT ME!
1153 public boolean getScaleRightWrapped()
1155 return scaleRightWrapped;
1161 * @param b DOCUMENT ME!
1163 public void setScaleAboveWrapped(boolean b)
1165 scaleAboveWrapped = b;
1171 * @param b DOCUMENT ME!
1173 public void setScaleLeftWrapped(boolean b)
1175 scaleLeftWrapped = b;
1181 * @param b DOCUMENT ME!
1183 public void setScaleRightWrapped(boolean b)
1185 scaleRightWrapped = b;
1189 * Property change listener for changes in alignment
1191 * @param listener DOCUMENT ME!
1193 public void addPropertyChangeListener(
1194 java.beans.PropertyChangeListener listener)
1196 changeSupport.addPropertyChangeListener(listener);
1202 * @param listener DOCUMENT ME!
1204 public void removePropertyChangeListener(
1205 java.beans.PropertyChangeListener listener)
1207 changeSupport.removePropertyChangeListener(listener);
1211 * Property change listener for changes in alignment
1213 * @param prop DOCUMENT ME!
1214 * @param oldvalue DOCUMENT ME!
1215 * @param newvalue DOCUMENT ME!
1217 public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
1219 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1222 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1224 ignoreGapsInConsensusCalculation = b;
1225 updateConsensus(ap);
1226 if(globalColourScheme!=null)
1228 globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);
1232 public boolean getIgnoreGapsConsensus()
1234 return ignoreGapsInConsensusCalculation;
1237 public void setDataset(boolean b)
1242 public boolean isDataset()
1248 public void hideSelectedColumns()
1250 if (colSel.size() < 1)
1253 colSel.hideSelectedColumns();
1254 setSelectionGroup(null);
1256 hasHiddenColumns = true;
1260 public void hideColumns(int start, int end)
1263 colSel.hideColumns(start);
1265 colSel.hideColumns(start, end);
1267 hasHiddenColumns = true;
1270 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1272 int sSize = sg.getSize();
1276 if(hiddenRepSequences==null)
1277 hiddenRepSequences = new Hashtable();
1279 hiddenRepSequences.put(repSequence, sg);
1281 //Hide all sequences except the repSequence
1282 SequenceI [] seqs = new SequenceI[sSize-1];
1284 for(int i=0; i<sSize; i++)
1285 if(sg.getSequenceAt(i)!=repSequence)
1290 seqs[index++] = sg.getSequenceAt(i);
1297 public void hideAllSelectedSeqs()
1299 if (selectionGroup == null)
1302 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1306 setSelectionGroup(null);
1309 public void hideSequence(SequenceI [] seq)
1313 for (int i = 0; i < seq.length; i++)
1315 alignment.getHiddenSequences().hideSequence(seq[i]);
1317 hasHiddenRows = true;
1318 firePropertyChange("alignment", null, alignment.getSequences());
1322 public void showSequence(int index)
1324 Vector tmp = alignment.getHiddenSequences().showSequence(index
1325 , hiddenRepSequences);
1328 if(selectionGroup==null)
1330 selectionGroup = new SequenceGroup();
1331 selectionGroup.setEndRes(alignment.getWidth()-1);
1334 for (int t = 0; t < tmp.size(); t++)
1336 selectionGroup.addSequence(
1337 (SequenceI) tmp.elementAt(t), false
1340 firePropertyChange("alignment", null, alignment.getSequences());
1343 if(alignment.getHiddenSequences().getSize()<1)
1344 hasHiddenRows = false;
1347 public void showColumn(int col)
1349 colSel.revealHiddenColumns(col);
1350 if(colSel.getHiddenColumns()==null)
1351 hasHiddenColumns = false;
1354 public void showAllHiddenColumns()
1356 colSel.revealAllHiddenColumns();
1357 hasHiddenColumns = false;
1360 public void showAllHiddenSeqs()
1362 if(alignment.getHiddenSequences().getSize()>0)
1364 if(selectionGroup==null)
1366 selectionGroup = new SequenceGroup();
1367 selectionGroup.setEndRes(alignment.getWidth()-1);
1369 Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
1370 for(int t=0; t<tmp.size(); t++)
1372 selectionGroup.addSequence(
1373 (SequenceI)tmp.elementAt(t), false
1376 firePropertyChange("alignment", null, alignment.getSequences());
1377 hasHiddenRows = false;
1378 hiddenRepSequences = null;
1384 public void invertColumnSelection()
1386 for(int i=0; i<alignment.getWidth(); i++)
1388 if(colSel.contains(i))
1389 colSel.removeElement(i);
1392 if (!hasHiddenColumns || colSel.isVisible(i))
1394 colSel.addElement(i);
1400 public int adjustForHiddenSeqs(int alignmentIndex)
1402 return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
1406 * This method returns the a new SequenceI [] with
1407 * the selection sequence and start and end points adjusted
1410 public SequenceI[] getSelectionAsNewSequence()
1412 SequenceI[] sequences;
1414 if (selectionGroup == null)
1415 sequences = alignment.getSequencesArray();
1417 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1423 * This method returns the visible alignment as text, as
1424 * seen on the GUI, ie if columns are hidden they will not
1425 * be returned in the result.
1426 * Use this for calculating trees, PCA, redundancy etc on views
1427 * which contain hidden columns.
1430 public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)
1432 CigarArray selection=null;
1433 SequenceI [] seqs= null;
1435 int start = 0, end = 0;
1436 if(selectedRegionOnly && selectionGroup!=null)
1438 iSize = selectionGroup.getSize();
1439 seqs = selectionGroup.getSequencesInOrder(alignment);
1440 start = selectionGroup.getStartRes();
1441 end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
1445 iSize = alignment.getHeight();
1446 seqs = alignment.getSequencesArray();
1447 end = alignment.getWidth()-1;
1449 SeqCigar[] selseqs = new SeqCigar[iSize];
1450 for(i=0; i<iSize; i++)
1452 selseqs[i] = new SeqCigar(seqs[i], start, end);
1454 selection=new CigarArray(selseqs);
1455 // now construct the CigarArray operations
1456 if (hasHiddenColumns) {
1457 Vector regions = colSel.getHiddenColumns();
1459 int hideStart, hideEnd;
1461 for (int j = 0; last<end & j < regions.size(); j++)
1463 region = (int[]) regions.elementAt(j);
1464 hideStart = region[0];
1465 hideEnd = region[1];
1466 // edit hidden regions to selection range
1467 if(hideStart<last) {
1481 if (hideStart>hideEnd)
1484 * form operations...
1487 selection.addOperation(CigarArray.M, hideStart-last);
1488 selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
1491 // Final match if necessary.
1493 selection.addOperation(CigarArray.M, end-last+1);
1495 selection.addOperation(CigarArray.M, end-start+1);
1500 * return a compact representation of the current alignment selection to
1501 * pass to an analysis function
1502 * @param selectedOnly boolean true to just return the selected view
1503 * @return AlignmentView
1505 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {
1507 // this is here because the AlignmentView constructor modifies the CigarArray
1508 // object. Refactoring of Cigar and alignment view representation should
1509 // be done to remove redundancy.
1510 CigarArray aligview = getViewAsCigars(selectedOnly);
1511 if (aligview!=null) {
1512 return new AlignmentView(aligview,
1513 (selectedOnly && selectionGroup!=null) ? selectionGroup.getStartRes() : 0);
1518 * This method returns the visible alignment as text, as
1519 * seen on the GUI, ie if columns are hidden they will not
1520 * be returned in the result.
1521 * Use this for calculating trees, PCA, redundancy etc on views
1522 * which contain hidden columns.
1525 public String [] getViewAsString(boolean selectedRegionOnly)
1527 String [] selection = null;
1528 SequenceI [] seqs= null;
1530 int start = 0, end = 0;
1531 if(selectedRegionOnly && selectionGroup!=null)
1533 iSize = selectionGroup.getSize();
1534 seqs = selectionGroup.getSequencesInOrder(alignment);
1535 start = selectionGroup.getStartRes();
1536 end = selectionGroup.getEndRes()+1;
1540 iSize = alignment.getHeight();
1541 seqs = alignment.getSequencesArray();
1542 end = alignment.getWidth();
1545 selection = new String[iSize];
1546 if (hasHiddenColumns) {
1547 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1549 for(i=0; i<iSize; i++)
1551 selection[i] = seqs[i].getSequenceAsString(start, end);
1558 public boolean getShowHiddenMarkers()
1560 return showHiddenMarkers;
1563 public void setShowHiddenMarkers(boolean show)
1565 showHiddenMarkers = show;
1568 public String getSequenceSetId()
1570 if(sequenceSetID==null)
1571 sequenceSetID = alignment.hashCode()+"";
1573 return sequenceSetID;
1576 public void alignmentChanged(AlignmentPanel ap)
1579 alignment.padGaps();
1581 if (hconsensus != null && autoCalculateConsensus)
1583 updateConsensus(ap);
1584 updateConservation(ap);
1587 //Reset endRes of groups if beyond alignment width
1588 int alWidth = alignment.getWidth();
1589 Vector groups = alignment.getGroups();
1592 for(int i=0; i<groups.size(); i++)
1594 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
1595 if(sg.getEndRes()>alWidth)
1596 sg.setEndRes(alWidth-1);
1600 if(selectionGroup!=null && selectionGroup.getEndRes()>alWidth)
1601 selectionGroup.setEndRes(alWidth-1);
1603 resetAllColourSchemes();
1605 // alignment.adjustSequenceAnnotations();
1609 void resetAllColourSchemes()
1611 ColourSchemeI cs = globalColourScheme;
1614 if (cs instanceof ClustalxColourScheme)
1616 ( (ClustalxColourScheme) cs).
1617 resetClustalX(alignment.getSequences(),
1618 alignment.getWidth());
1621 cs.setConsensus(hconsensus);
1622 if (cs.conservationApplied())
1624 Alignment al = (Alignment) alignment;
1625 Conservation c = new Conservation("All",
1626 ResidueProperties.propHash, 3,
1627 al.getSequences(), 0,
1630 c.verdict(false, ConsPercGaps);
1632 cs.setConservation(c);
1636 int s, sSize = alignment.getGroups().size();
1637 for(s=0; s<sSize; s++)
1639 SequenceGroup sg = (SequenceGroup)alignment.getGroups().elementAt(s);
1640 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1642 ((ClustalxColourScheme)sg.cs).resetClustalX(
1643 sg.getSequences(hiddenRepSequences), sg.getWidth());
1645 sg.recalcConservation();
1650 public Color getSequenceColour(SequenceI seq)
1652 if(sequenceColours==null || !sequenceColours.containsKey(seq))
1655 return (Color)sequenceColours.get(seq);
1658 public void setSequenceColour(SequenceI seq, Color col)
1660 if(sequenceColours==null)
1661 sequenceColours = new Hashtable();
1664 sequenceColours.remove(seq);
1666 sequenceColours.put(seq, col);