-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
- */\r
-\r
-package jalview.appletgui;\r
-\r
-import java.util.*;\r
-\r
-import java.awt.*;\r
-\r
-import jalview.analysis.*;\r
-import jalview.bin.*;\r
-import jalview.datamodel.*;\r
-import jalview.schemes.*;\r
-\r
-public class AlignViewport\r
-{\r
- int startRes;\r
- int endRes;\r
-\r
- int startSeq;\r
- int endSeq;\r
-\r
-\r
- boolean cursorMode = false;\r
-\r
- boolean showJVSuffix = true;\r
- boolean showText = true;\r
- boolean showColourText = false;\r
- boolean showBoxes = true;\r
- boolean wrapAlignment = false;\r
- boolean renderGaps = true;\r
- boolean showSequenceFeatures = false;\r
- boolean showAnnotation = true;\r
- boolean showConservation = true;\r
- boolean showQuality = true;\r
- boolean showConsensus = true;\r
-\r
- boolean colourAppliesToAllGroups = true;\r
- ColourSchemeI globalColourScheme = null;\r
- boolean conservationColourSelected = false;\r
- boolean abovePIDThreshold = false;\r
-\r
- SequenceGroup selectionGroup;\r
-\r
- int charHeight;\r
- int charWidth;\r
- int wrappedWidth;\r
-\r
- Font font = new Font("SansSerif", Font.PLAIN, 10);\r
- boolean validCharWidth = true;\r
- AlignmentI alignment;\r
-\r
- ColumnSelection colSel = new ColumnSelection();\r
-\r
- int threshold;\r
- int increment;\r
-\r
- NJTree currentTree = null;\r
-\r
- boolean scaleAboveWrapped = true;\r
- boolean scaleLeftWrapped = true;\r
- boolean scaleRightWrapped = true;\r
-\r
- // The following vector holds the features which are\r
- // currently visible, in the correct order or rendering\r
- Hashtable featuresDisplayed;\r
-\r
- boolean hasHiddenColumns = false;\r
- boolean hasHiddenRows = false;\r
- boolean showHiddenMarkers = true;\r
-\r
-\r
- public Vector vconsensus;\r
- AlignmentAnnotation consensus;\r
- AlignmentAnnotation conservation;\r
- AlignmentAnnotation quality;\r
-\r
- boolean autocalculateConsensus = true;\r
-\r
- public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!\r
-\r
- private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);\r
-\r
- boolean ignoreGapsInConsensusCalculation = false;\r
-\r
- jalview.bin.JalviewLite applet;\r
-\r
- boolean MAC = false;\r
-\r
- public AlignViewport(AlignmentI al, JalviewLite applet)\r
- {\r
- this.applet = applet;\r
- setAlignment(al);\r
- this.startRes = 0;\r
- this.endRes = al.getWidth() - 1;\r
- this.startSeq = 0;\r
- this.endSeq = al.getHeight() - 1;\r
- setFont(font);\r
-\r
- if(System.getProperty("os.name").startsWith("Mac"))\r
- MAC = true;\r
-\r
- if (applet != null)\r
- {\r
- String param = applet.getParameter("showFullId");\r
- if (param != null)\r
- {\r
- showJVSuffix = Boolean.valueOf(param).booleanValue();\r
- }\r
-\r
- param = applet.getParameter("showAnnotation");\r
- if (param != null)\r
- {\r
- showAnnotation = Boolean.valueOf(param).booleanValue();\r
- }\r
-\r
- param = applet.getParameter("showConservation");\r
- if (param != null)\r
- {\r
- showConservation = Boolean.valueOf(param).booleanValue();\r
- }\r
-\r
- param = applet.getParameter("showQuality");\r
- if (param != null)\r
- {\r
- showQuality = Boolean.valueOf(param).booleanValue();\r
- }\r
-\r
- param = applet.getParameter("showConsensus");\r
- if (param != null)\r
- {\r
- showConsensus = Boolean.valueOf(param).booleanValue();\r
- }\r
- }\r
- // We must set conservation and consensus before setting colour,\r
- // as Blosum and Clustal require this to be done\r
- updateConservation();\r
- updateConsensus();\r
-\r
-\r
- if (applet != null)\r
- {\r
- String colour = applet.getParameter("defaultColour");\r
-\r
- if(colour == null)\r
- {\r
- colour = applet.getParameter("userDefinedColour");\r
- if(colour !=null)\r
- colour = "User Defined";\r
- }\r
-\r
- if(colour != null)\r
- {\r
- globalColourScheme = ColourSchemeProperty.getColour(alignment, colour);\r
- if (globalColourScheme != null)\r
- {\r
- globalColourScheme.setConsensus(vconsensus);\r
- }\r
- }\r
-\r
- if(applet.getParameter("userDefinedColour")!=null)\r
- {\r
- ((UserColourScheme)globalColourScheme).parseAppletParameter(\r
- applet.getParameter("userDefinedColour"));\r
- }\r
-\r
-\r
- }\r
- }\r
-\r
- public void showSequenceFeatures(boolean b)\r
- {\r
- showSequenceFeatures = b;\r
- }\r
-\r
- public boolean getShowSequenceFeatures()\r
- {\r
- return showSequenceFeatures;\r
- }\r
-\r
-\r
- public void updateConservation()\r
- {\r
- if(alignment.isNucleotide())\r
- return;\r
-\r
- Conservation cons = new jalview.analysis.Conservation("All",\r
- jalview.schemes.ResidueProperties.propHash, 3,\r
- alignment.getSequences(), 0,\r
- alignment.getWidth() - 1);\r
- cons.calculate();\r
- cons.verdict(false, ConsPercGaps);\r
- cons.findQuality();\r
- int alWidth = alignment.getWidth();\r
- Annotation[] annotations = new Annotation[alWidth];\r
- Annotation[] qannotations = new Annotation[alWidth];\r
- String sequence = cons.getConsSequence().getSequence();\r
- float minR, minG, minB, maxR, maxG, maxB;\r
- minR = 0.3f;\r
- minG = 0.0f;\r
- minB = 0f;\r
- maxR = 1.0f - minR;\r
- maxG = 0.9f - minG;\r
- maxB = 0f - minB; // scalable range for colouring both Conservation and Quality\r
- float min = 0f;\r
- float max = 11f;\r
- float qmin = cons.qualityRange[0].floatValue();\r
- float qmax = cons.qualityRange[1].floatValue();\r
-\r
- for (int i = 0; i < alWidth; i++)\r
- {\r
- float value = 0;\r
- try\r
- {\r
- value = Integer.parseInt(sequence.charAt(i) + "");\r
- }\r
- catch (Exception ex)\r
- {\r
- if (sequence.charAt(i) == '*')\r
- {\r
- value = 11;\r
- }\r
- if (sequence.charAt(i) == '+')\r
- {\r
- value = 10;\r
- }\r
- }\r
- float vprop = value - min;\r
- vprop /= max;\r
-\r
- annotations[i] = new Annotation(sequence.charAt(i) + "",\r
- "", ' ', value,\r
- new Color(minR + maxR * vprop,\r
- minG + maxG * vprop,\r
- minB + maxB * vprop));\r
- // Quality calc\r
- value = ( (Double) cons.quality.elementAt(i)).floatValue();\r
- vprop = value - qmin;\r
- vprop /= qmax;\r
- qannotations[i] = new Annotation(" ",\r
- String.valueOf(value), ' ', value,\r
- new\r
- Color(minR + maxR * vprop,\r
- minG + maxG * vprop,\r
- minB + maxB * vprop));\r
- }\r
-\r
- if (conservation == null)\r
- {\r
- conservation = new AlignmentAnnotation("Conservation",\r
- "Conservation of total alignment less than " +\r
- ConsPercGaps + "% gaps",\r
- annotations,\r
- 0f, // cons.qualityRange[0].floatValue(),\r
- 11f, // cons.qualityRange[1].floatValue()\r
- AlignmentAnnotation.BAR_GRAPH);\r
- if (showConservation)\r
- {\r
- alignment.addAnnotation(conservation);\r
- }\r
- quality = new AlignmentAnnotation("Quality",\r
- "Alignment Quality based on Blosum62 scores",\r
- qannotations,\r
- cons.qualityRange[0].floatValue(),\r
- cons.qualityRange[1].floatValue(),\r
- AlignmentAnnotation.BAR_GRAPH);\r
- if (showQuality)\r
- {\r
- alignment.addAnnotation(quality);\r
- }\r
- }\r
- else\r
- {\r
- conservation.annotations = annotations;\r
- quality.annotations = qannotations;\r
- quality.graphMax = cons.qualityRange[1].floatValue();\r
- }\r
-\r
- }\r
-\r
- public void updateConsensus()\r
- {\r
- Annotation[] annotations = new Annotation[alignment.getWidth()];\r
-\r
- // this routine prevents vconsensus becoming a new object each time\r
- // consenus is calculated. Important for speed of Blosum62\r
- // and PID colouring of alignment\r
- if (vconsensus == null)\r
- {\r
- vconsensus = alignment.getAAFrequency();\r
- }\r
- else\r
- {\r
- Vector temp = alignment.getAAFrequency();\r
- vconsensus.removeAllElements();\r
- Enumeration e = temp.elements();\r
- while (e.hasMoreElements())\r
- {\r
- vconsensus.addElement(e.nextElement());\r
- }\r
- }\r
- Hashtable hash = null;\r
- for (int i = 0; i < alignment.getWidth(); i++)\r
- {\r
- hash = (Hashtable) vconsensus.elementAt(i);\r
- float value = 0;\r
- if(ignoreGapsInConsensusCalculation)\r
- value = ((Float)hash.get("pid_nogaps")).floatValue();\r
- else\r
- value = ((Float)hash.get("pid_gaps")).floatValue();\r
-\r
- String maxRes = hash.get("maxResidue").toString();\r
- String mouseOver = hash.get("maxResidue") + " ";\r
- if (maxRes.length() > 1)\r
- {\r
- mouseOver = "[" + maxRes + "] ";\r
- maxRes = "+";\r
- }\r
-\r
-\r
- mouseOver += (int) value + "%";\r
- annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);\r
-\r
- }\r
-\r
- if (consensus == null)\r
- {\r
- consensus = new AlignmentAnnotation("Consensus",\r
- "PID", annotations, 0f, 100f, AlignmentAnnotation.BAR_GRAPH);\r
- if (showConsensus)\r
- {\r
- alignment.addAnnotation(consensus);\r
- }\r
- }\r
- else\r
- {\r
- consensus.annotations = annotations;\r
- }\r
-\r
- if(globalColourScheme!=null)\r
- globalColourScheme.setConsensus(vconsensus);\r
-\r
- }\r
-\r
- public SequenceGroup getSelectionGroup()\r
- {\r
- return selectionGroup;\r
- }\r
-\r
- public void setSelectionGroup(SequenceGroup sg)\r
- {\r
- selectionGroup = sg;\r
- }\r
-\r
- public boolean getConservationSelected()\r
- {\r
- return conservationColourSelected;\r
- }\r
-\r
- public void setConservationSelected(boolean b)\r
- {\r
- conservationColourSelected = b;\r
- }\r
-\r
- public boolean getAbovePIDThreshold()\r
- {\r
- return abovePIDThreshold;\r
- }\r
-\r
- public void setAbovePIDThreshold(boolean b)\r
- {\r
- abovePIDThreshold = b;\r
- }\r
-\r
- public int getStartRes()\r
- {\r
- return startRes;\r
- }\r
-\r
- public int getEndRes()\r
- {\r
- return endRes;\r
- }\r
-\r
- public int getStartSeq()\r
- {\r
- return startSeq;\r
- }\r
-\r
- public void setGlobalColourScheme(ColourSchemeI cs)\r
- {\r
- globalColourScheme = cs;\r
- }\r
-\r
- public ColourSchemeI getGlobalColourScheme()\r
- {\r
- return globalColourScheme;\r
- }\r
-\r
- public void setStartRes(int res)\r
- {\r
- this.startRes = res;\r
- }\r
-\r
- public void setStartSeq(int seq)\r
- {\r
- this.startSeq = seq;\r
- }\r
-\r
- public void setEndRes(int res)\r
- {\r
- if (res > alignment.getWidth() - 1)\r
- {\r
- // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));\r
- res = alignment.getWidth() - 1;\r
- }\r
- if (res < 0)\r
- {\r
- res = 0;\r
- }\r
- this.endRes = res;\r
- }\r
-\r
- public void setEndSeq(int seq)\r
- {\r
- if (seq > alignment.getHeight())\r
- {\r
- seq = alignment.getHeight();\r
- }\r
- if (seq < 0)\r
- {\r
- seq = 0;\r
- }\r
- this.endSeq = seq;\r
- }\r
-\r
- public int getEndSeq()\r
- {\r
- return endSeq;\r
- }\r
-\r
- java.awt.Frame nullFrame;\r
- public void setFont(Font f)\r
- {\r
- font = f;\r
- if(nullFrame == null)\r
- {\r
- nullFrame = new java.awt.Frame();\r
- nullFrame.addNotify();\r
- }\r
-\r
- java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);\r
- setCharHeight(fm.getHeight());\r
- charWidth = fm.charWidth('M');\r
- }\r
-\r
- public Font getFont()\r
- {\r
- return font;\r
- }\r
-\r
- public int getCharWidth()\r
- {\r
- return charWidth;\r
- }\r
-\r
- public void setCharHeight(int h)\r
- {\r
- this.charHeight = h;\r
- }\r
-\r
- public int getCharHeight()\r
- {\r
- return charHeight;\r
- }\r
-\r
- public void setWrappedWidth(int w)\r
- {\r
- this.wrappedWidth = w;\r
- }\r
-\r
- public int getwrappedWidth()\r
- {\r
- return wrappedWidth;\r
- }\r
-\r
- public AlignmentI getAlignment()\r
- {\r
- return alignment;\r
- }\r
-\r
- public void setAlignment(AlignmentI align)\r
- {\r
- this.alignment = align;\r
- }\r
-\r
- public void setWrapAlignment(boolean state)\r
- {\r
- wrapAlignment = state;\r
- }\r
-\r
- public void setShowText(boolean state)\r
- {\r
- showText = state;\r
- }\r
-\r
- public void setRenderGaps(boolean state)\r
- {\r
- renderGaps = state;\r
- }\r
-\r
- public boolean getColourText()\r
- {\r
- return showColourText;\r
- }\r
-\r
- public void setColourText(boolean state)\r
- {\r
- showColourText = state;\r
- }\r
-\r
- public void setShowBoxes(boolean state)\r
- {\r
- showBoxes = state;\r
- }\r
-\r
- public boolean getWrapAlignment()\r
- {\r
- return wrapAlignment;\r
- }\r
-\r
- public boolean getShowText()\r
- {\r
- return showText;\r
- }\r
-\r
- public boolean getShowBoxes()\r
- {\r
- return showBoxes;\r
- }\r
-\r
- public char getGapCharacter()\r
- {\r
- return getAlignment().getGapCharacter();\r
- }\r
-\r
- public void setGapCharacter(char gap)\r
- {\r
- if (getAlignment() != null)\r
- {\r
- getAlignment().setGapCharacter(gap);\r
- }\r
- }\r
-\r
- public void setThreshold(int thresh)\r
- {\r
- threshold = thresh;\r
- }\r
-\r
- public int getThreshold()\r
- {\r
- return threshold;\r
- }\r
-\r
- public void setIncrement(int inc)\r
- {\r
- increment = inc;\r
- }\r
-\r
- public int getIncrement()\r
- {\r
- return increment;\r
- }\r
-\r
- public void setHiddenColumns(ColumnSelection colsel)\r
- {\r
- this.colSel = colsel;\r
- if(colSel.getHiddenColumns()!=null)\r
- hasHiddenColumns = true;\r
- }\r
-\r
- public ColumnSelection getColumnSelection()\r
- {\r
- return colSel;\r
- }\r
-\r
- public void resetSeqLimits(int height)\r
- {\r
- setEndSeq(height / getCharHeight());\r
- }\r
-\r
- public void setCurrentTree(NJTree tree)\r
- {\r
- currentTree = tree;\r
- }\r
-\r
- public NJTree getCurrentTree()\r
- {\r
- return currentTree;\r
- }\r
-\r
- public void setColourAppliesToAllGroups(boolean b)\r
- {\r
- colourAppliesToAllGroups = b;\r
- }\r
-\r
- public boolean getColourAppliesToAllGroups()\r
- {\r
- return colourAppliesToAllGroups;\r
- }\r
-\r
- public boolean getShowJVSuffix()\r
- {\r
- return showJVSuffix;\r
- }\r
-\r
- public void setShowJVSuffix(boolean b)\r
- {\r
- showJVSuffix = b;\r
- }\r
-\r
- public boolean getShowAnnotation()\r
- {\r
- return showAnnotation;\r
- }\r
-\r
- public void setShowAnnotation(boolean b)\r
- {\r
- showAnnotation = b;\r
- }\r
-\r
- public boolean getScaleAboveWrapped()\r
- {\r
- return scaleAboveWrapped;\r
- }\r
-\r
- public boolean getScaleLeftWrapped()\r
- {\r
- return scaleLeftWrapped;\r
- }\r
-\r
- public boolean getScaleRightWrapped()\r
- {\r
- return scaleRightWrapped;\r
- }\r
-\r
- public void setScaleAboveWrapped(boolean b)\r
- {\r
- scaleAboveWrapped = b;\r
- }\r
-\r
- public void setScaleLeftWrapped(boolean b)\r
- {\r
- scaleLeftWrapped = b;\r
- }\r
-\r
- public void setScaleRightWrapped(boolean b)\r
- {\r
- scaleRightWrapped = b;\r
- }\r
-\r
- public void setIgnoreGapsConsensus(boolean b)\r
- {\r
- ignoreGapsInConsensusCalculation = b;\r
- updateConsensus();\r
- if (globalColourScheme!=null)\r
- {\r
- globalColourScheme.setThreshold(globalColourScheme.getThreshold(),\r
- ignoreGapsInConsensusCalculation);\r
-\r
- }\r
- }\r
-\r
- /**\r
- * Property change listener for changes in alignment\r
- *\r
- * @param listener DOCUMENT ME!\r
- */\r
- public void addPropertyChangeListener(\r
- java.beans.PropertyChangeListener listener)\r
- {\r
- changeSupport.addPropertyChangeListener(listener);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param listener DOCUMENT ME!\r
- */\r
- public void removePropertyChangeListener(\r
- java.beans.PropertyChangeListener listener)\r
- {\r
- changeSupport.removePropertyChangeListener(listener);\r
- }\r
-\r
- /**\r
- * Property change listener for changes in alignment\r
- *\r
- * @param prop DOCUMENT ME!\r
- * @param oldvalue DOCUMENT ME!\r
- * @param newvalue DOCUMENT ME!\r
- */\r
- public void firePropertyChange(String prop, Object oldvalue, Object newvalue)\r
- {\r
- changeSupport.firePropertyChange(prop, oldvalue, newvalue);\r
- }\r
-\r
-\r
-\r
- public boolean getIgnoreGapsConsensus()\r
- {\r
- return ignoreGapsInConsensusCalculation;\r
- }\r
- public void hideSelectedColumns()\r
- {\r
- if (colSel.size() < 1)\r
- return;\r
-\r
- colSel.hideSelectedColumns();\r
- setSelectionGroup(null);\r
-\r
- hasHiddenColumns = true;\r
- }\r
-\r
- public void invertColumnSelection()\r
- {\r
- int column;\r
- for (int i = 0; i < alignment.getWidth(); i++)\r
- {\r
- column = i;\r
-\r
- if (colSel.contains(column))\r
- colSel.removeElement(column);\r
- else\r
- colSel.addElement(column);\r
-\r
- }\r
- }\r
-\r
-\r
- public void hideColumns(int start, int end)\r
- {\r
- if(start==end)\r
- colSel.hideColumns(start);\r
- else\r
- colSel.hideColumns(start, end);\r
-\r
- hasHiddenColumns = true;\r
- }\r
-\r
- public void hideSequence(SequenceI seq)\r
- {\r
- if(seq!=null)\r
- {\r
- alignment.getHiddenSequences().hideSequence(seq);\r
- hasHiddenRows = true;\r
- firePropertyChange("alignment", null, alignment.getSequences());\r
- }\r
- }\r
-\r
- public void hideAllSelectedSeqs()\r
- {\r
- if (selectionGroup == null)\r
- return;\r
-\r
- SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);\r
-\r
- for (int i = 0; i < seqs.length; i++)\r
- {\r
- alignment.getHiddenSequences().hideSequence(seqs[i]);\r
- }\r
- firePropertyChange("alignment", null, alignment.getSequences());\r
- hasHiddenRows = true;\r
- setSelectionGroup(null);\r
- }\r
-\r
- public void showColumn(int col)\r
- {\r
- colSel.revealHiddenColumns(col);\r
- if(colSel.getHiddenColumns()==null)\r
- hasHiddenColumns = false;\r
- }\r
-\r
- public void showAllHiddenColumns()\r
- {\r
- colSel.revealAllHiddenColumns();\r
- hasHiddenColumns = false;\r
- }\r
-\r
- public void showAllHiddenSeqs()\r
- {\r
- if(alignment.getHiddenSequences().getSize()>0)\r
- {\r
- if(selectionGroup==null)\r
- {\r
- selectionGroup = new SequenceGroup();\r
- selectionGroup.setEndRes(alignment.getWidth()-1);\r
- }\r
- Vector tmp = alignment.getHiddenSequences().showAll();\r
- for(int t=0; t<tmp.size(); t++)\r
- {\r
- selectionGroup.addSequence(\r
- (SequenceI)tmp.elementAt(t), false\r
- );\r
- }\r
- firePropertyChange("alignment", null, alignment.getSequences());\r
- hasHiddenRows = false;\r
- }\r
- }\r
-\r
- public int adjustForHiddenSeqs(int alignmentIndex)\r
- {\r
- return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);\r
- }\r
-\r
- /**\r
- * This method returns the a new SequenceI [] with\r
- * the selection sequence and start and end points adjusted\r
- * @return String[]\r
- */\r
- public SequenceI[] getSelectionAsNewSequence()\r
- {\r
- SequenceI[] sequences;\r
-\r
- if (selectionGroup == null)\r
- sequences = alignment.getSequencesArray();\r
- else\r
- sequences = selectionGroup.getSelectionAsNewSequences(alignment);\r
-\r
- return sequences;\r
- }\r
-\r
- /**\r
- * This method returns the visible alignment as text, as\r
- * seen on the GUI, ie if columns are hidden they will not\r
- * be returned in the result.\r
- * Use this for calculating trees, PCA, redundancy etc on views\r
- * which contain hidden columns.\r
- * @return String[]\r
- */\r
- public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)\r
- {\r
- CigarArray selection=null;\r
- SequenceI [] seqs= null;\r
- int i, iSize;\r
- int start = 0, end = 0;\r
- if(selectedRegionOnly && selectionGroup!=null)\r
- {\r
- iSize = selectionGroup.getSize(false);\r
- seqs = selectionGroup.getSequencesInOrder(alignment);\r
- start = selectionGroup.getStartRes();\r
- end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor\r
- }\r
- else\r
- {\r
- iSize = alignment.getHeight();\r
- seqs = alignment.getSequencesArray();\r
- end = alignment.getWidth()-1;\r
- }\r
- SeqCigar[] selseqs = new SeqCigar[iSize];\r
- for(i=0; i<iSize; i++)\r
- {\r
- selseqs[i] = new SeqCigar(seqs[i], start, end);\r
- }\r
- selection=new CigarArray(selseqs);\r
- // now construct the CigarArray operations\r
- if (hasHiddenColumns) {\r
- Vector regions = colSel.getHiddenColumns();\r
- int [] region;\r
- int hideStart, hideEnd;\r
- int last=start;\r
- for (int j = 0; last<end & j < regions.size(); j++)\r
- {\r
- region = (int[]) regions.elementAt(j);\r
- hideStart = region[0];\r
- hideEnd = region[1];\r
- // edit hidden regions to selection range\r
- if(hideStart<last) {\r
- if (hideEnd > last)\r
- {\r
- hideStart = last;\r
- } else\r
- continue;\r
- }\r
-\r
- if (hideStart>end)\r
- break;\r
-\r
- if (hideEnd>end)\r
- hideEnd=end;\r
-\r
- if (hideStart>hideEnd)\r
- break;\r
- /**\r
- * form operations...\r
- */\r
- if (last<hideStart)\r
- selection.addOperation(CigarArray.M, hideStart-last);\r
- selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);\r
- last = hideEnd+1;\r
- }\r
- // Final match if necessary.\r
- if (last<end)\r
- selection.addOperation(CigarArray.M, end-last);\r
- } else {\r
- selection.addOperation(CigarArray.M, end-start);\r
- }\r
- return selection;\r
- }\r
- /**\r
- * return a compact representation of the current alignment selection to\r
- * pass to an analysis function\r
- * @param selectedOnly boolean true to just return the selected view\r
- * @return AlignmentView\r
- */\r
- jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {\r
- // JBPNote:\r
- // this is here because the AlignmentView constructor modifies the CigarArray\r
- // object. Refactoring of Cigar and alignment view representation should\r
- // be done to remove redundancy.\r
- CigarArray aligview = getViewAsCigars(selectedOnly);\r
- if (aligview!=null)\r
- return new AlignmentView(aligview);\r
- return null;\r
- }\r
- /**\r
- * This method returns the visible alignment as text, as\r
- * seen on the GUI, ie if columns are hidden they will not\r
- * be returned in the result.\r
- * Use this for calculating trees, PCA, redundancy etc on views\r
- * which contain hidden columns.\r
- * @return String[]\r
- */\r
- public String [] getViewAsString(boolean selectedRegionOnly)\r
- {\r
- String [] selection = null;\r
- SequenceI [] seqs= null;\r
- int i, iSize;\r
- int start = 0, end = 0;\r
- if(selectedRegionOnly && selectionGroup!=null)\r
- {\r
- iSize = selectionGroup.getSize(false);\r
- seqs = selectionGroup.getSequencesInOrder(alignment);\r
- start = selectionGroup.getStartRes();\r
- end = selectionGroup.getEndRes()+1;\r
- }\r
- else\r
- {\r
- iSize = alignment.getHeight();\r
- seqs = alignment.getSequencesArray();\r
- end = alignment.getWidth();\r
- }\r
-\r
- selection = new String[iSize];\r
-\r
-\r
- for(i=0; i<iSize; i++)\r
- {\r
- if (hasHiddenColumns)\r
- {\r
- StringBuffer visibleSeq = new StringBuffer();\r
- Vector regions = colSel.getHiddenColumns();\r
-\r
- int blockStart = start, blockEnd=end;\r
- int [] region;\r
- int hideStart, hideEnd;\r
-\r
- for (int j = 0; j < regions.size(); j++)\r
- {\r
- region = (int[]) regions.elementAt(j);\r
- hideStart = region[0];\r
- hideEnd = region[1];\r
-\r
- if(hideStart < start)\r
- {\r
- continue;\r
- }\r
-\r
- blockStart = Math.min(blockStart, hideEnd+1);\r
- blockEnd = Math.min(blockEnd, hideStart);\r
-\r
- if(blockStart>blockEnd)\r
- {\r
- break;\r
- }\r
-\r
-\r
- visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));\r
-\r
- blockStart = hideEnd+1;\r
- blockEnd = end;\r
- }\r
-\r
- if(end>blockStart)\r
- visibleSeq.append(seqs[i].getSequence(blockStart, end));\r
-\r
- selection[i] = visibleSeq.toString();\r
- }\r
- else\r
- {\r
- selection[i] = seqs[i].getSequence(start, end);\r
- }\r
- }\r
-\r
- return selection;\r
- }\r
-\r
- public boolean getShowHiddenMarkers()\r
- {\r
- return showHiddenMarkers;\r
- }\r
-\r
- public void setShowHiddenMarkers(boolean show)\r
- {\r
- showHiddenMarkers = show;\r
- }\r
-\r
-\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.util.*;
+
+import java.awt.*;
+
+import jalview.analysis.*;
+import jalview.bin.*;
+import jalview.datamodel.*;
+import jalview.schemes.*;
+
+public class AlignViewport
+{
+ int startRes;
+ int endRes;
+
+ int startSeq;
+ int endSeq;
+
+
+ boolean cursorMode = false;
+
+ boolean showJVSuffix = true;
+ boolean showText = true;
+ boolean showColourText = false;
+ boolean showBoxes = true;
+ boolean wrapAlignment = false;
+ boolean renderGaps = true;
+ boolean showSequenceFeatures = false;
+ boolean showAnnotation = true;
+ boolean showConservation = true;
+ boolean showQuality = true;
+ boolean showConsensus = true;
+
+ boolean colourAppliesToAllGroups = true;
+ ColourSchemeI globalColourScheme = null;
+ boolean conservationColourSelected = false;
+ boolean abovePIDThreshold = false;
+
+ SequenceGroup selectionGroup;
+
+ int charHeight;
+ int charWidth;
+ int wrappedWidth;
+
+ Font font = new Font("SansSerif", Font.PLAIN, 10);
+ boolean validCharWidth = true;
+ AlignmentI alignment;
+
+ ColumnSelection colSel = new ColumnSelection();
+
+ int threshold;
+ int increment;
+
+ NJTree currentTree = null;
+
+ boolean scaleAboveWrapped = true;
+ boolean scaleLeftWrapped = true;
+ boolean scaleRightWrapped = true;
+
+ // The following vector holds the features which are
+ // currently visible, in the correct order or rendering
+ Hashtable featuresDisplayed;
+
+ boolean hasHiddenColumns = false;
+ boolean hasHiddenRows = false;
+ boolean showHiddenMarkers = true;
+
+
+ public Vector vconsensus;
+ AlignmentAnnotation consensus;
+ AlignmentAnnotation conservation;
+ AlignmentAnnotation quality;
+
+ boolean autocalculateConsensus = true;
+
+ public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
+
+ private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
+
+ boolean ignoreGapsInConsensusCalculation = false;
+
+ jalview.bin.JalviewLite applet;
+
+ boolean MAC = false;
+
+ public AlignViewport(AlignmentI al, JalviewLite applet)
+ {
+ this.applet = applet;
+ setAlignment(al);
+ this.startRes = 0;
+ this.endRes = al.getWidth() - 1;
+ this.startSeq = 0;
+ this.endSeq = al.getHeight() - 1;
+ setFont(font);
+
+ if(System.getProperty("os.name").startsWith("Mac"))
+ MAC = true;
+
+ if (applet != null)
+ {
+ String param = applet.getParameter("showFullId");
+ if (param != null)
+ {
+ showJVSuffix = Boolean.valueOf(param).booleanValue();
+ }
+
+ param = applet.getParameter("showAnnotation");
+ if (param != null)
+ {
+ showAnnotation = Boolean.valueOf(param).booleanValue();
+ }
+
+ param = applet.getParameter("showConservation");
+ if (param != null)
+ {
+ showConservation = Boolean.valueOf(param).booleanValue();
+ }
+
+ param = applet.getParameter("showQuality");
+ if (param != null)
+ {
+ showQuality = Boolean.valueOf(param).booleanValue();
+ }
+
+ param = applet.getParameter("showConsensus");
+ if (param != null)
+ {
+ showConsensus = Boolean.valueOf(param).booleanValue();
+ }
+ }
+ // We must set conservation and consensus before setting colour,
+ // as Blosum and Clustal require this to be done
+ updateConservation();
+ updateConsensus();
+
+
+ if (applet != null)
+ {
+ String colour = applet.getParameter("defaultColour");
+
+ if(colour == null)
+ {
+ colour = applet.getParameter("userDefinedColour");
+ if(colour !=null)
+ colour = "User Defined";
+ }
+
+ if(colour != null)
+ {
+ globalColourScheme = ColourSchemeProperty.getColour(alignment, colour);
+ if (globalColourScheme != null)
+ {
+ globalColourScheme.setConsensus(vconsensus);
+ }
+ }
+
+ if(applet.getParameter("userDefinedColour")!=null)
+ {
+ ((UserColourScheme)globalColourScheme).parseAppletParameter(
+ applet.getParameter("userDefinedColour"));
+ }
+
+
+ }
+ }
+
+ public void showSequenceFeatures(boolean b)
+ {
+ showSequenceFeatures = b;
+ }
+
+ public boolean getShowSequenceFeatures()
+ {
+ return showSequenceFeatures;
+ }
+
+
+ public void updateConservation()
+ {
+ if(alignment.isNucleotide())
+ return;
+
+ Conservation cons = new jalview.analysis.Conservation("All",
+ jalview.schemes.ResidueProperties.propHash, 3,
+ alignment.getSequences(), 0,
+ alignment.getWidth() - 1);
+ cons.calculate();
+ cons.verdict(false, ConsPercGaps);
+ cons.findQuality();
+ int alWidth = alignment.getWidth();
+ Annotation[] annotations = new Annotation[alWidth];
+ Annotation[] qannotations = new Annotation[alWidth];
+ String sequence = cons.getConsSequence().getSequence();
+ float minR, minG, minB, maxR, maxG, maxB;
+ minR = 0.3f;
+ minG = 0.0f;
+ minB = 0f;
+ maxR = 1.0f - minR;
+ maxG = 0.9f - minG;
+ maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
+ float min = 0f;
+ float max = 11f;
+ float qmin = cons.qualityRange[0].floatValue();
+ float qmax = cons.qualityRange[1].floatValue();
+
+ for (int i = 0; i < alWidth; i++)
+ {
+ float value = 0;
+ try
+ {
+ value = Integer.parseInt(sequence.charAt(i) + "");
+ }
+ catch (Exception ex)
+ {
+ if (sequence.charAt(i) == '*')
+ {
+ value = 11;
+ }
+ if (sequence.charAt(i) == '+')
+ {
+ value = 10;
+ }
+ }
+ float vprop = value - min;
+ vprop /= max;
+
+ annotations[i] = new Annotation(sequence.charAt(i) + "",
+ "", ' ', value,
+ new Color(minR + maxR * vprop,
+ minG + maxG * vprop,
+ minB + maxB * vprop));
+ // Quality calc
+ value = ( (Double) cons.quality.elementAt(i)).floatValue();
+ vprop = value - qmin;
+ vprop /= qmax;
+ qannotations[i] = new Annotation(" ",
+ String.valueOf(value), ' ', value,
+ new
+ Color(minR + maxR * vprop,
+ minG + maxG * vprop,
+ minB + maxB * vprop));
+ }
+
+ if (conservation == null)
+ {
+ conservation = new AlignmentAnnotation("Conservation",
+ "Conservation of total alignment less than " +
+ ConsPercGaps + "% gaps",
+ annotations,
+ 0f, // cons.qualityRange[0].floatValue(),
+ 11f, // cons.qualityRange[1].floatValue()
+ AlignmentAnnotation.BAR_GRAPH);
+ if (showConservation)
+ {
+ alignment.addAnnotation(conservation);
+ }
+ quality = new AlignmentAnnotation("Quality",
+ "Alignment Quality based on Blosum62 scores",
+ qannotations,
+ cons.qualityRange[0].floatValue(),
+ cons.qualityRange[1].floatValue(),
+ AlignmentAnnotation.BAR_GRAPH);
+ if (showQuality)
+ {
+ alignment.addAnnotation(quality);
+ }
+ }
+ else
+ {
+ conservation.annotations = annotations;
+ quality.annotations = qannotations;
+ quality.graphMax = cons.qualityRange[1].floatValue();
+ }
+
+ }
+
+ public void updateConsensus()
+ {
+ Annotation[] annotations = new Annotation[alignment.getWidth()];
+
+ // this routine prevents vconsensus becoming a new object each time
+ // consenus is calculated. Important for speed of Blosum62
+ // and PID colouring of alignment
+ if (vconsensus == null)
+ {
+ vconsensus = alignment.getAAFrequency();
+ }
+ else
+ {
+ Vector temp = alignment.getAAFrequency();
+ vconsensus.removeAllElements();
+ Enumeration e = temp.elements();
+ while (e.hasMoreElements())
+ {
+ vconsensus.addElement(e.nextElement());
+ }
+ }
+ Hashtable hash = null;
+ for (int i = 0; i < alignment.getWidth(); i++)
+ {
+ hash = (Hashtable) vconsensus.elementAt(i);
+ float value = 0;
+ if(ignoreGapsInConsensusCalculation)
+ value = ((Float)hash.get("pid_nogaps")).floatValue();
+ else
+ value = ((Float)hash.get("pid_gaps")).floatValue();
+
+ String maxRes = hash.get("maxResidue").toString();
+ String mouseOver = hash.get("maxResidue") + " ";
+ if (maxRes.length() > 1)
+ {
+ mouseOver = "[" + maxRes + "] ";
+ maxRes = "+";
+ }
+
+
+ mouseOver += (int) value + "%";
+ annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
+
+ }
+
+ if (consensus == null)
+ {
+ consensus = new AlignmentAnnotation("Consensus",
+ "PID", annotations, 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
+ if (showConsensus)
+ {
+ alignment.addAnnotation(consensus);
+ }
+ }
+ else
+ {
+ consensus.annotations = annotations;
+ }
+
+ if(globalColourScheme!=null)
+ globalColourScheme.setConsensus(vconsensus);
+
+ }
+ /**
+ * get the consensus sequence as displayed under the PID consensus annotation row.
+ * @return consensus sequence as a new sequence object
+ */
+ /**
+ * get the consensus sequence as displayed under the PID consensus annotation row.
+ * @return consensus sequence as a new sequence object
+ */
+ public SequenceI getConsensusSeq() {
+ if (consensus==null)
+ updateConsensus();
+ if (consensus==null)
+ return null;
+ StringBuffer seqs=new StringBuffer();
+ for (int i=0; i<consensus.annotations.length; i++) {
+ if (consensus.annotations[i]!=null) {
+ if (consensus.annotations[i].description.charAt(0) == '[')
+ seqs.append(consensus.annotations[i].description.charAt(1));
+ else
+ seqs.append(consensus.annotations[i].displayCharacter);
+ }
+ }
+ SequenceI sq = new Sequence("Consensus", seqs.toString());
+ sq.setDescription("Percentage Identity Consensus "+((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
+ return sq;
+ }
+ public SequenceGroup getSelectionGroup()
+ {
+ return selectionGroup;
+ }
+
+ public void setSelectionGroup(SequenceGroup sg)
+ {
+ selectionGroup = sg;
+ }
+
+ public boolean getConservationSelected()
+ {
+ return conservationColourSelected;
+ }
+
+ public void setConservationSelected(boolean b)
+ {
+ conservationColourSelected = b;
+ }
+
+ public boolean getAbovePIDThreshold()
+ {
+ return abovePIDThreshold;
+ }
+
+ public void setAbovePIDThreshold(boolean b)
+ {
+ abovePIDThreshold = b;
+ }
+
+ public int getStartRes()
+ {
+ return startRes;
+ }
+
+ public int getEndRes()
+ {
+ return endRes;
+ }
+
+ public int getStartSeq()
+ {
+ return startSeq;
+ }
+
+ public void setGlobalColourScheme(ColourSchemeI cs)
+ {
+ globalColourScheme = cs;
+ }
+
+ public ColourSchemeI getGlobalColourScheme()
+ {
+ return globalColourScheme;
+ }
+
+ public void setStartRes(int res)
+ {
+ this.startRes = res;
+ }
+
+ public void setStartSeq(int seq)
+ {
+ this.startSeq = seq;
+ }
+
+ public void setEndRes(int res)
+ {
+ if (res > alignment.getWidth() - 1)
+ {
+ // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
+ res = alignment.getWidth() - 1;
+ }
+ if (res < 0)
+ {
+ res = 0;
+ }
+ this.endRes = res;
+ }
+
+ public void setEndSeq(int seq)
+ {
+ if (seq > alignment.getHeight())
+ {
+ seq = alignment.getHeight();
+ }
+ if (seq < 0)
+ {
+ seq = 0;
+ }
+ this.endSeq = seq;
+ }
+
+ public int getEndSeq()
+ {
+ return endSeq;
+ }
+
+ java.awt.Frame nullFrame;
+ public void setFont(Font f)
+ {
+ font = f;
+ if(nullFrame == null)
+ {
+ nullFrame = new java.awt.Frame();
+ nullFrame.addNotify();
+ }
+
+ java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
+ setCharHeight(fm.getHeight());
+ charWidth = fm.charWidth('M');
+ }
+
+ public Font getFont()
+ {
+ return font;
+ }
+
+ public int getCharWidth()
+ {
+ return charWidth;
+ }
+
+ public void setCharHeight(int h)
+ {
+ this.charHeight = h;
+ }
+
+ public int getCharHeight()
+ {
+ return charHeight;
+ }
+
+ public void setWrappedWidth(int w)
+ {
+ this.wrappedWidth = w;
+ }
+
+ public int getwrappedWidth()
+ {
+ return wrappedWidth;
+ }
+
+ public AlignmentI getAlignment()
+ {
+ return alignment;
+ }
+
+ public void setAlignment(AlignmentI align)
+ {
+ this.alignment = align;
+ }
+
+ public void setWrapAlignment(boolean state)
+ {
+ wrapAlignment = state;
+ }
+
+ public void setShowText(boolean state)
+ {
+ showText = state;
+ }
+
+ public void setRenderGaps(boolean state)
+ {
+ renderGaps = state;
+ }
+
+ public boolean getColourText()
+ {
+ return showColourText;
+ }
+
+ public void setColourText(boolean state)
+ {
+ showColourText = state;
+ }
+
+ public void setShowBoxes(boolean state)
+ {
+ showBoxes = state;
+ }
+
+ public boolean getWrapAlignment()
+ {
+ return wrapAlignment;
+ }
+
+ public boolean getShowText()
+ {
+ return showText;
+ }
+
+ public boolean getShowBoxes()
+ {
+ return showBoxes;
+ }
+
+ public char getGapCharacter()
+ {
+ return getAlignment().getGapCharacter();
+ }
+
+ public void setGapCharacter(char gap)
+ {
+ if (getAlignment() != null)
+ {
+ getAlignment().setGapCharacter(gap);
+ }
+ }
+
+ public void setThreshold(int thresh)
+ {
+ threshold = thresh;
+ }
+
+ public int getThreshold()
+ {
+ return threshold;
+ }
+
+ public void setIncrement(int inc)
+ {
+ increment = inc;
+ }
+
+ public int getIncrement()
+ {
+ return increment;
+ }
+
+ public void setHiddenColumns(ColumnSelection colsel)
+ {
+ this.colSel = colsel;
+ if(colSel.getHiddenColumns()!=null)
+ hasHiddenColumns = true;
+ }
+
+ public ColumnSelection getColumnSelection()
+ {
+ return colSel;
+ }
+
+ public void resetSeqLimits(int height)
+ {
+ setEndSeq(height / getCharHeight());
+ }
+
+ public void setCurrentTree(NJTree tree)
+ {
+ currentTree = tree;
+ }
+
+ public NJTree getCurrentTree()
+ {
+ return currentTree;
+ }
+
+ public void setColourAppliesToAllGroups(boolean b)
+ {
+ colourAppliesToAllGroups = b;
+ }
+
+ public boolean getColourAppliesToAllGroups()
+ {
+ return colourAppliesToAllGroups;
+ }
+
+ public boolean getShowJVSuffix()
+ {
+ return showJVSuffix;
+ }
+
+ public void setShowJVSuffix(boolean b)
+ {
+ showJVSuffix = b;
+ }
+
+ public boolean getShowAnnotation()
+ {
+ return showAnnotation;
+ }
+
+ public void setShowAnnotation(boolean b)
+ {
+ showAnnotation = b;
+ }
+
+ public boolean getScaleAboveWrapped()
+ {
+ return scaleAboveWrapped;
+ }
+
+ public boolean getScaleLeftWrapped()
+ {
+ return scaleLeftWrapped;
+ }
+
+ public boolean getScaleRightWrapped()
+ {
+ return scaleRightWrapped;
+ }
+
+ public void setScaleAboveWrapped(boolean b)
+ {
+ scaleAboveWrapped = b;
+ }
+
+ public void setScaleLeftWrapped(boolean b)
+ {
+ scaleLeftWrapped = b;
+ }
+
+ public void setScaleRightWrapped(boolean b)
+ {
+ scaleRightWrapped = b;
+ }
+
+ public void setIgnoreGapsConsensus(boolean b)
+ {
+ ignoreGapsInConsensusCalculation = b;
+ updateConsensus();
+ if (globalColourScheme!=null)
+ {
+ globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
+ ignoreGapsInConsensusCalculation);
+
+ }
+ }
+
+ /**
+ * Property change listener for changes in alignment
+ *
+ * @param listener DOCUMENT ME!
+ */
+ public void addPropertyChangeListener(
+ java.beans.PropertyChangeListener listener)
+ {
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param listener DOCUMENT ME!
+ */
+ public void removePropertyChangeListener(
+ java.beans.PropertyChangeListener listener)
+ {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * Property change listener for changes in alignment
+ *
+ * @param prop DOCUMENT ME!
+ * @param oldvalue DOCUMENT ME!
+ * @param newvalue DOCUMENT ME!
+ */
+ public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
+ {
+ changeSupport.firePropertyChange(prop, oldvalue, newvalue);
+ }
+
+
+
+ public boolean getIgnoreGapsConsensus()
+ {
+ return ignoreGapsInConsensusCalculation;
+ }
+ public void hideSelectedColumns()
+ {
+ if (colSel.size() < 1)
+ return;
+
+ colSel.hideSelectedColumns();
+ setSelectionGroup(null);
+
+ hasHiddenColumns = true;
+ }
+
+ public void invertColumnSelection()
+ {
+ int column;
+ for (int i = 0; i < alignment.getWidth(); i++)
+ {
+ column = i;
+
+ if (colSel.contains(column))
+ colSel.removeElement(column);
+ else
+ colSel.addElement(column);
+
+ }
+ }
+
+
+ public void hideColumns(int start, int end)
+ {
+ if(start==end)
+ colSel.hideColumns(start);
+ else
+ colSel.hideColumns(start, end);
+
+ hasHiddenColumns = true;
+ }
+
+ public void hideSequence(SequenceI seq)
+ {
+ if(seq!=null)
+ {
+ alignment.getHiddenSequences().hideSequence(seq);
+ hasHiddenRows = true;
+ firePropertyChange("alignment", null, alignment.getSequences());
+ }
+ }
+
+ public void hideAllSelectedSeqs()
+ {
+ if (selectionGroup == null)
+ return;
+
+ SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
+
+ for (int i = 0; i < seqs.length; i++)
+ {
+ alignment.getHiddenSequences().hideSequence(seqs[i]);
+ }
+ firePropertyChange("alignment", null, alignment.getSequences());
+ hasHiddenRows = true;
+ setSelectionGroup(null);
+ }
+
+ public void showColumn(int col)
+ {
+ colSel.revealHiddenColumns(col);
+ if(colSel.getHiddenColumns()==null)
+ hasHiddenColumns = false;
+ }
+
+ public void showAllHiddenColumns()
+ {
+ colSel.revealAllHiddenColumns();
+ hasHiddenColumns = false;
+ }
+
+ public void showAllHiddenSeqs()
+ {
+ if(alignment.getHiddenSequences().getSize()>0)
+ {
+ if(selectionGroup==null)
+ {
+ selectionGroup = new SequenceGroup();
+ selectionGroup.setEndRes(alignment.getWidth()-1);
+ }
+ Vector tmp = alignment.getHiddenSequences().showAll();
+ for(int t=0; t<tmp.size(); t++)
+ {
+ selectionGroup.addSequence(
+ (SequenceI)tmp.elementAt(t), false
+ );
+ }
+ firePropertyChange("alignment", null, alignment.getSequences());
+ hasHiddenRows = false;
+ }
+ }
+
+ public int adjustForHiddenSeqs(int alignmentIndex)
+ {
+ return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
+ }
+
+ /**
+ * This method returns the a new SequenceI [] with
+ * the selection sequence and start and end points adjusted
+ * @return String[]
+ */
+ public SequenceI[] getSelectionAsNewSequence()
+ {
+ SequenceI[] sequences;
+
+ if (selectionGroup == null)
+ sequences = alignment.getSequencesArray();
+ else
+ sequences = selectionGroup.getSelectionAsNewSequences(alignment);
+
+ return sequences;
+ }
+
+ /**
+ * This method returns the visible alignment as text, as
+ * seen on the GUI, ie if columns are hidden they will not
+ * be returned in the result.
+ * Use this for calculating trees, PCA, redundancy etc on views
+ * which contain hidden columns.
+ * @return String[]
+ */
+ public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)
+ {
+ CigarArray selection=null;
+ SequenceI [] seqs= null;
+ int i, iSize;
+ int start = 0, end = 0;
+ if(selectedRegionOnly && selectionGroup!=null)
+ {
+ iSize = selectionGroup.getSize(false);
+ seqs = selectionGroup.getSequencesInOrder(alignment);
+ start = selectionGroup.getStartRes();
+ end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
+ }
+ else
+ {
+ iSize = alignment.getHeight();
+ seqs = alignment.getSequencesArray();
+ end = alignment.getWidth()-1;
+ }
+ SeqCigar[] selseqs = new SeqCigar[iSize];
+ for(i=0; i<iSize; i++)
+ {
+ selseqs[i] = new SeqCigar(seqs[i], start, end);
+ }
+ selection=new CigarArray(selseqs);
+ // now construct the CigarArray operations
+ if (hasHiddenColumns) {
+ Vector regions = colSel.getHiddenColumns();
+ int [] region;
+ int hideStart, hideEnd;
+ int last=start;
+ for (int j = 0; last<end & j < regions.size(); j++)
+ {
+ region = (int[]) regions.elementAt(j);
+ hideStart = region[0];
+ hideEnd = region[1];
+ // edit hidden regions to selection range
+ if(hideStart<last) {
+ if (hideEnd > last)
+ {
+ hideStart = last;
+ } else
+ continue;
+ }
+
+ if (hideStart>end)
+ break;
+
+ if (hideEnd>end)
+ hideEnd=end;
+
+ if (hideStart>hideEnd)
+ break;
+ /**
+ * form operations...
+ */
+ if (last<hideStart)
+ selection.addOperation(CigarArray.M, hideStart-last);
+ selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
+ last = hideEnd+1;
+ }
+ // Final match if necessary.
+ if (last<end)
+ selection.addOperation(CigarArray.M, end-last);
+ } else {
+ selection.addOperation(CigarArray.M, end-start);
+ }
+ return selection;
+ }
+ /**
+ * return a compact representation of the current alignment selection to
+ * pass to an analysis function
+ * @param selectedOnly boolean true to just return the selected view
+ * @return AlignmentView
+ */
+ jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {
+ // JBPNote:
+ // this is here because the AlignmentView constructor modifies the CigarArray
+ // object. Refactoring of Cigar and alignment view representation should
+ // be done to remove redundancy.
+ CigarArray aligview = getViewAsCigars(selectedOnly);
+ if (aligview!=null)
+ return new AlignmentView(aligview);
+ return null;
+ }
+ /**
+ * This method returns the visible alignment as text, as
+ * seen on the GUI, ie if columns are hidden they will not
+ * be returned in the result.
+ * Use this for calculating trees, PCA, redundancy etc on views
+ * which contain hidden columns.
+ * @return String[]
+ */
+ public String [] getViewAsString(boolean selectedRegionOnly)
+ {
+ String [] selection = null;
+ SequenceI [] seqs= null;
+ int i, iSize;
+ int start = 0, end = 0;
+ if(selectedRegionOnly && selectionGroup!=null)
+ {
+ iSize = selectionGroup.getSize(false);
+ seqs = selectionGroup.getSequencesInOrder(alignment);
+ start = selectionGroup.getStartRes();
+ end = selectionGroup.getEndRes()+1;
+ }
+ else
+ {
+ iSize = alignment.getHeight();
+ seqs = alignment.getSequencesArray();
+ end = alignment.getWidth();
+ }
+
+ selection = new String[iSize];
+
+
+ for(i=0; i<iSize; i++)
+ {
+ if (hasHiddenColumns)
+ {
+ StringBuffer visibleSeq = new StringBuffer();
+ Vector regions = colSel.getHiddenColumns();
+
+ int blockStart = start, blockEnd=end;
+ int [] region;
+ int hideStart, hideEnd;
+
+ for (int j = 0; j < regions.size(); j++)
+ {
+ region = (int[]) regions.elementAt(j);
+ hideStart = region[0];
+ hideEnd = region[1];
+
+ if(hideStart < start)
+ {
+ continue;
+ }
+
+ blockStart = Math.min(blockStart, hideEnd+1);
+ blockEnd = Math.min(blockEnd, hideStart);
+
+ if(blockStart>blockEnd)
+ {
+ break;
+ }
+
+
+ visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
+
+ blockStart = hideEnd+1;
+ blockEnd = end;
+ }
+
+ if(end>blockStart)
+ visibleSeq.append(seqs[i].getSequence(blockStart, end));
+
+ selection[i] = visibleSeq.toString();
+ }
+ else
+ {
+ selection[i] = seqs[i].getSequence(start, end);
+ }
+ }
+
+ return selection;
+ }
+
+ public boolean getShowHiddenMarkers()
+ {
+ return showHiddenMarkers;
+ }
+
+ public void setShowHiddenMarkers(boolean show)
+ {
+ showHiddenMarkers = show;
+ }
+
+
+}
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
- */\r
-\r
-package jalview.appletgui;\r
-\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-\r
-import jalview.datamodel.*;\r
-\r
-public class AnnotationLabels\r
- extends Panel implements ActionListener\r
-{\r
- boolean active = false;\r
- AlignmentPanel ap;\r
- AlignViewport av;\r
- boolean resizing = false;\r
- int oldY, mouseX;\r
- static String ADDNEW = "Add new row";\r
- static String HIDE = "Hide this row";\r
- static String DELETE = "Delete this row";\r
- static String SHOWALL = "Show all hidden rows";\r
- static String OUTPUT_TEXT = "Show Values In Textbox";\r
- int selectedRow = 0;\r
- int scrollOffset = 0;\r
-\r
- public AnnotationLabels(AlignmentPanel ap)\r
- {\r
- this.ap = ap;\r
- this.av = ap.av;\r
- setLayout(null);\r
- addMouseListener(new MouseAdapter()\r
- {\r
- public void mousePressed(MouseEvent evt)\r
- {\r
- doMousePressed(evt);\r
- }\r
- });\r
- }\r
-\r
- public AnnotationLabels(AlignViewport av)\r
-{\r
- this.av = av;\r
-}\r
-\r
-\r
- public void setScrollOffset(int y)\r
- {\r
- scrollOffset = y;\r
- repaint();\r
- }\r
-\r
- public void actionPerformed(ActionEvent evt)\r
- {\r
- AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
-\r
- if (evt.getActionCommand().equals(HIDE))\r
- {\r
- aa[selectedRow].visible = false;\r
- }\r
- else if (evt.getActionCommand().equals(SHOWALL))\r
- {\r
- for (int i = 0; i < aa.length; i++)\r
- {\r
- aa[i].visible = true;\r
- }\r
- }\r
- else if (evt.getActionCommand().equals(OUTPUT_TEXT))\r
- {\r
- CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);\r
- Frame frame = new Frame();\r
- frame.add(cap);\r
- jalview.bin.JalviewLite.addFrame(frame,\r
- ap.alignFrame.getTitle() + " - " +\r
- aa[selectedRow].label, 500, 100);\r
- cap.setText(aa[selectedRow].toString());\r
- }\r
-\r
- ap.annotationPanel.adjustPanelHeight();\r
- setSize(getSize().width, ap.annotationPanel.getSize().height);\r
- ap.validate();\r
- ap.repaint();\r
- }\r
-\r
- public void doMousePressed(MouseEvent evt)\r
- {\r
- int y = evt.getY() - scrollOffset;\r
- AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
- int height = 0;\r
- for (int i = 0; i < aa.length; i++)\r
- {\r
- if (!aa[i].visible)\r
- {\r
- continue;\r
- }\r
-\r
- height += aa[i].height;\r
- if (y < height)\r
- {\r
- selectedRow = i;\r
- break;\r
- }\r
- }\r
-\r
- PopupMenu pop = new PopupMenu("Annotations");\r
- MenuItem item = new MenuItem(HIDE);\r
- item.addActionListener(this);\r
- pop.add(item);\r
- item = new MenuItem(SHOWALL);\r
- item.addActionListener(this);\r
- pop.add(item);\r
- this.add(pop);\r
- item = new MenuItem(OUTPUT_TEXT);\r
- item.addActionListener(this);\r
- pop.add(item);\r
-\r
- if (aa[selectedRow].label.equals("Consensus"))\r
- {\r
- pop.addSeparator();\r
- final CheckboxMenuItem cbmi = new CheckboxMenuItem(\r
- "Ignore Gaps In Consensus",\r
- ap.av.getIgnoreGapsConsensus());\r
-\r
- cbmi.addItemListener(new ItemListener()\r
- {\r
- public void itemStateChanged(ItemEvent e)\r
- {\r
- ap.av.setIgnoreGapsConsensus(cbmi.getState());\r
- ap.repaint();\r
- }\r
- });\r
- pop.add(cbmi);\r
- }\r
-\r
- pop.show(this, evt.getX(), evt.getY());\r
-\r
- }\r
-\r
- public void paint(Graphics g)\r
- {\r
- drawComponent(g, getSize().width);\r
- }\r
-\r
- public void drawComponent(Graphics g, int width)\r
- {\r
- g.setFont(av.getFont());\r
- FontMetrics fm = g.getFontMetrics(av.getFont());\r
- g.setColor(Color.white);\r
- g.fillRect(0, 0, getSize().width, getSize().height);\r
-\r
- g.translate(0, scrollOffset);\r
- g.setColor(Color.black);\r
-\r
- AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
- int y = g.getFont().getSize();\r
- int x = 0;\r
-\r
- if (aa != null)\r
- {\r
- for (int i = 0; i < aa.length; i++)\r
- {\r
- if (!aa[i].visible)\r
- {\r
- continue;\r
- }\r
-\r
- x = width - fm.stringWidth(aa[i].label) - 3;\r
-\r
- if (aa[i].graph>0)\r
- {\r
- y += (aa[i].height / 3);\r
- }\r
-\r
- g.drawString(aa[i].label, x, y);\r
-\r
- if (aa[i].graph>0)\r
- {\r
- y += (2 * aa[i].height / 3);\r
- }\r
- else\r
- {\r
- y += aa[i].height;\r
- }\r
- }\r
- }\r
- }\r
-\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.Vector;
+
+import jalview.datamodel.*;
+
+public class AnnotationLabels
+ extends Panel implements ActionListener
+{
+ boolean active = false;
+ AlignmentPanel ap;
+ AlignViewport av;
+ boolean resizing = false;
+ int oldY, mouseX;
+ static String ADDNEW = "Add new row";
+ static String HIDE = "Hide this row";
+ static String DELETE = "Delete this row";
+ static String SHOWALL = "Show all hidden rows";
+ static String OUTPUT_TEXT = "Show Values In Textbox";
+ static String COPYCONS_SEQ = "Copy Consensus Sequence";
+
+ int selectedRow = 0;
+ int scrollOffset = 0;
+
+ public AnnotationLabels(AlignmentPanel ap)
+ {
+ this.ap = ap;
+ this.av = ap.av;
+ setLayout(null);
+ addMouseListener(new MouseAdapter()
+ {
+ public void mousePressed(MouseEvent evt)
+ {
+ doMousePressed(evt);
+ }
+ });
+ }
+
+ public AnnotationLabels(AlignViewport av)
+{
+ this.av = av;
+}
+
+
+ public void setScrollOffset(int y)
+ {
+ scrollOffset = y;
+ repaint();
+ }
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+
+ if (evt.getActionCommand().equals(HIDE))
+ {
+ aa[selectedRow].visible = false;
+ }
+ else if (evt.getActionCommand().equals(SHOWALL))
+ {
+ for (int i = 0; i < aa.length; i++)
+ {
+ aa[i].visible = true;
+ }
+ }
+ else if (evt.getActionCommand().equals(OUTPUT_TEXT))
+ {
+ CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
+ Frame frame = new Frame();
+ frame.add(cap);
+ jalview.bin.JalviewLite.addFrame(frame,
+ ap.alignFrame.getTitle() + " - " +
+ aa[selectedRow].label, 500, 100);
+ cap.setText(aa[selectedRow].toString());
+ }
+ else if (evt.getActionCommand().equals(COPYCONS_SEQ))
+ {
+ SequenceI cons=av.getConsensusSeq();
+ if (cons!=null)
+ copy_annotseqtoclipboard(cons);
+
+ }
+ ap.annotationPanel.adjustPanelHeight();
+ setSize(getSize().width, ap.annotationPanel.getSize().height);
+ ap.validate();
+ ap.repaint();
+ }
+
+ public void doMousePressed(MouseEvent evt)
+ {
+ int y = evt.getY() - scrollOffset;
+ AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
+ int height = 0;
+ for (int i = 0; i < aa.length; i++)
+ {
+ if (!aa[i].visible)
+ {
+ continue;
+ }
+
+ height += aa[i].height;
+ if (y < height)
+ {
+ selectedRow = i;
+ break;
+ }
+ }
+
+ PopupMenu pop = new PopupMenu("Annotations");
+ MenuItem item = new MenuItem(HIDE);
+ item.addActionListener(this);
+ pop.add(item);
+ item = new MenuItem(SHOWALL);
+ item.addActionListener(this);
+ pop.add(item);
+ this.add(pop);
+ item = new MenuItem(OUTPUT_TEXT);
+ item.addActionListener(this);
+ pop.add(item);
+
+ if (aa[selectedRow].label.equals("Consensus"))
+ {
+ pop.addSeparator();
+ final CheckboxMenuItem cbmi = new CheckboxMenuItem(
+ "Ignore Gaps In Consensus",
+ ap.av.getIgnoreGapsConsensus());
+
+ cbmi.addItemListener(new ItemListener()
+ {
+ public void itemStateChanged(ItemEvent e)
+ {
+ ap.av.setIgnoreGapsConsensus(cbmi.getState());
+ ap.repaint();
+ }
+ });
+ pop.add(cbmi);
+ final MenuItem cpcons=new MenuItem(COPYCONS_SEQ);
+ cpcons.addActionListener(this);
+ pop.add(cpcons);
+ }
+
+ pop.show(this, evt.getX(), evt.getY());
+
+ }
+/**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void copy_annotseqtoclipboard(SequenceI sq)
+ {
+ if (sq==null || sq.getLength()<1)
+ return;
+ jalview.appletgui.AlignFrame.copiedSequences = new StringBuffer();
+ jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t" +
+ sq.getStart() + "\t" +
+ sq.getEnd() + "\t" +
+ sq.getSequence() + "\n");
+ if (av.hasHiddenColumns)
+ {
+ jalview.appletgui.AlignFrame.copiedHiddenColumns=new Vector();
+ for(int i=0; i<av.getColumnSelection().getHiddenColumns().size(); i++)
+ {
+ int[] region = (int[])
+ av.getColumnSelection().getHiddenColumns().elementAt(i);
+
+ jalview.appletgui.AlignFrame.copiedHiddenColumns.addElement(new int[]{region[0],
+ region[1]});
+ }
+ }
+ }
+
+ public void paint(Graphics g)
+ {
+ drawComponent(g, getSize().width);
+ }
+
+ public void drawComponent(Graphics g, int width)
+ {
+ g.setFont(av.getFont());
+ FontMetrics fm = g.getFontMetrics(av.getFont());
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getSize().width, getSize().height);
+
+ g.translate(0, scrollOffset);
+ g.setColor(Color.black);
+
+ AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+ int y = g.getFont().getSize();
+ int x = 0;
+
+ if (aa != null)
+ {
+ for (int i = 0; i < aa.length; i++)
+ {
+ if (!aa[i].visible)
+ {
+ continue;
+ }
+
+ x = width - fm.stringWidth(aa[i].label) - 3;
+
+ if (aa[i].graph>0)
+ {
+ y += (aa[i].height / 3);
+ }
+
+ g.drawString(aa[i].label, x, y);
+
+ if (aa[i].graph>0)
+ {
+ y += (2 * aa[i].height / 3);
+ }
+ else
+ {
+ y += aa[i].height;
+ }
+ }
+ }
+ }
+
+}
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
- */\r
-package jalview.datamodel;\r
-\r
-import jalview.util.ShiftList;\r
-\r
-import java.util.*;\r
-\r
-/**\r
- * NOTE: Columns are zero based.\r
- */\r
-public class ColumnSelection\r
-{\r
- Vector selected = new Vector();\r
-\r
- //Vector of int [] {startCol, endCol}\r
- Vector hiddenColumns;\r
-\r
- /**\r
- * Add a column to the selection\r
- *\r
- * @param col index of column\r
- */\r
- public void addElement(int col)\r
- {\r
- Integer column = new Integer(col);\r
- if (!selected.contains(column))\r
- {\r
- selected.addElement(column);\r
- }\r
- }\r
-\r
- /**\r
- * clears column selection\r
- */\r
- public void clear()\r
- {\r
- selected.removeAllElements();\r
- }\r
-\r
- /**\r
- * removes col from selection\r
- *\r
- * @param col index of column to be removed\r
- */\r
- public void removeElement(int col)\r
- {\r
- Integer colInt = new Integer(col);\r
-\r
- if (selected.contains(colInt))\r
- {\r
- selected.removeElement(colInt);\r
- }\r
- }\r
-\r
- /**\r
- * removes a range of columns from the selection\r
- * @param start int - first column in range to be removed\r
- * @param end int - last col\r
- */\r
- public void removeElements(int start, int end)\r
- {\r
- Integer colInt;\r
- for(int i=start; i<end; i++)\r
- {\r
- colInt = new Integer(i);\r
- if (selected.contains(colInt))\r
- {\r
- selected.removeElement(colInt);\r
- }\r
- }\r
- }\r
- /**\r
- *\r
- * @return Vector containing selected columns as Integers\r
- */\r
- public Vector getSelected()\r
- {\r
- return selected;\r
- }\r
-\r
- /**\r
- *\r
- * @param col index to search for in column selection\r
- *\r
- * @return true if Integer(col) is in selection.\r
- */\r
- public boolean contains(int col)\r
- {\r
- return selected.contains(new Integer(col));\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param i DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int columnAt(int i)\r
- {\r
- return ((Integer) selected.elementAt(i)).intValue();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int size()\r
- {\r
- return selected.size();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getMax()\r
- {\r
- int max = -1;\r
-\r
- for (int i = 0; i < selected.size(); i++)\r
- {\r
- if (columnAt(i) > max)\r
- {\r
- max = columnAt(i);\r
- }\r
- }\r
-\r
- return max;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getMin()\r
- {\r
- int min = 1000000000;\r
-\r
- for (int i = 0; i < selected.size(); i++)\r
- {\r
- if (columnAt(i) < min)\r
- {\r
- min = columnAt(i);\r
- }\r
- }\r
-\r
- return min;\r
- }\r
-\r
-\r
- /**\r
- * propagate shift in alignment columns to column selection\r
- *\r
- * @param start beginning of edit\r
- * @param left shift in edit (+ve for removal, or -ve for inserts)\r
- */\r
- public void compensateForEdit(int start, int change)\r
- {\r
- for (int i = 0; i < size(); i++)\r
- {\r
- int temp = columnAt(i);\r
-\r
- if (temp >= start)\r
- {\r
- selected.setElementAt(new Integer(temp - change), i);\r
- }\r
- }\r
-\r
- if(hiddenColumns!=null)\r
- {\r
- for(int i=0; i<hiddenColumns.size(); i++)\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(i);\r
- if(region[0] > start)\r
- {\r
- region[0] -= change;\r
- region[1] -= change;\r
- }\r
- if(region[0]<0)\r
- region[0] = 0;\r
- if(region[1] <0)\r
- region[1] = 0;\r
- }\r
- }\r
- }\r
- /**\r
- * propagate shift in alignment columns to column selection\r
- * special version of compensateForEdit - allowing for edits within hidden regions\r
- * @param start beginning of edit\r
- * @param left shift in edit (+ve for removal, or -ve for inserts)\r
- */\r
- private void compensateForDelEdits(int start, int change)\r
- {\r
- for (int i = 0; i < size(); i++)\r
- {\r
- int temp = columnAt(i);\r
-\r
- if (temp >= start)\r
- {\r
- selected.setElementAt(new Integer(temp - change), i);\r
- }\r
- }\r
-\r
- if(hiddenColumns!=null)\r
- {\r
- for(int i=0; i<hiddenColumns.size(); i++)\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(i);\r
- if(region[0] >= start)\r
- {\r
- region[0] -= change;\r
- }\r
- if (region[1]>= start) {\r
- region[1] -=change;\r
- }\r
- if (region[1]<region[0]) {\r
- hiddenColumns.removeElementAt(i--);\r
- }\r
-\r
- if(region[0]<0)\r
- region[0] = 0;\r
- if(region[1] <0)\r
- region[1] = 0;\r
- }\r
- }\r
- }\r
- /**\r
- * Adjust hidden column boundaries based on a series of column\r
- * additions or deletions in visible regions.\r
- * @param shiftrecord\r
- * @return\r
- */\r
- public ShiftList compensateForEdits(ShiftList shiftrecord) {\r
- if (shiftrecord!=null) {\r
- Vector shifts = shiftrecord.shifts;\r
- if (shifts!=null && shifts.size()>0) {\r
- int shifted=0;\r
- for (int i=0,j=shifts.size(); i<j; i++) {\r
- int[] sh = (int[]) shifts.elementAt(i);\r
- //compensateForEdit(shifted+sh[0], sh[1]);\r
- compensateForDelEdits(shifted+sh[0], sh[1]);\r
- shifted-=sh[1];\r
- }\r
- }\r
- return shiftrecord.getInverse();\r
- }\r
- return null;\r
- }\r
- /**\r
- * removes intersection of position,length ranges in deletions\r
- * from the start,end regions marked in intervals.\r
- * @param deletions\r
- * @param intervals\r
- * @return\r
- */\r
- private boolean pruneIntervalVector(Vector deletions, Vector intervals) {\r
- boolean pruned=false;\r
- int i=0,j=intervals.size()-1, s=0, t=deletions.size()-1;\r
- int hr[]=(int[]) intervals.elementAt(i);\r
- int sr[]=(int[]) deletions.elementAt(s);\r
- while (i<=j && s<=t) {\r
- boolean trailinghn=hr[1]>=sr[0];\r
- if (!trailinghn) {\r
- if (i<j)\r
- hr=(int[]) intervals.elementAt(++i);\r
- else\r
- i++;\r
- continue;\r
- }\r
- int endshift=sr[0]+sr[1]; // deletion ranges - -ve means an insert\r
- if (endshift<hr[0] || endshift<sr[0]) { // leadinghc disjoint or not a deletion\r
- if (s<t)\r
- sr=(int[]) deletions.elementAt(++s);\r
- else\r
- s++;\r
- continue;\r
- }\r
- boolean leadinghn=hr[0]>=sr[0];\r
- boolean leadinghc=hr[0]<endshift;\r
- boolean trailinghc=hr[1]<endshift;\r
- if (leadinghn) {\r
- if (trailinghc) {// deleted hidden region.\r
- intervals.removeElementAt(i);\r
- pruned=true;\r
- j--;\r
- if (i<=j)\r
- hr=(int[]) intervals.elementAt(i);\r
- continue;\r
- }\r
- if (leadinghc) {\r
- hr[0]=endshift; // clip c terminal region\r
- leadinghn=!leadinghn;\r
- pruned=true;\r
- }\r
- }\r
- if (!leadinghn) {\r
- if (trailinghc) {\r
- if (trailinghn) {\r
- hr[1]=sr[0]-1;\r
- pruned=true;\r
- }\r
- } else {\r
- // sr contained in hr\r
- if (s<t)\r
- sr=(int[]) deletions.elementAt(++s);\r
- else\r
- s++;\r
- continue;\r
- }\r
- }\r
- }\r
- return pruned; // true if any interval was removed or modified by operations.\r
- }\r
- private boolean pruneColumnList(Vector deletion, Vector list) {\r
- int s=0,t=deletion.size();\r
- int[] sr=(int[])list.elementAt(s++);\r
- boolean pruned=false;\r
- int i=0, j=list.size();\r
- while (i<j && s<=t) {\r
- int c=((Integer)list.elementAt(i++)).intValue();\r
- if (sr[0]<=c) {\r
- if (sr[1]+sr[0]>=c) { // sr[1] -ve means inseriton.\r
- list.removeElementAt(--i);\r
- j--;\r
- } else {\r
- if (s<t)\r
- sr = (int[])deletion.elementAt(s);\r
- s++;\r
- }\r
- }\r
- }\r
- return pruned;\r
- }\r
- /**\r
- * remove any hiddenColumns or selected columns and shift remaining\r
- * based on a series of position, range deletions.\r
- * @param deletions\r
- */\r
- public void pruneDeletions(ShiftList deletions) {\r
- if (deletions!=null) {\r
- Vector shifts=deletions.shifts;\r
- if (shifts!=null && shifts.size()>0) {\r
- // delete any intervals intersecting.\r
- if (hiddenColumns!=null) {\r
- pruneIntervalVector(shifts, hiddenColumns);\r
- if (hiddenColumns!=null && hiddenColumns.size()==0) {\r
- hiddenColumns=null;\r
- }\r
- }\r
- if (selected!=null && selected.size()>0) {\r
- pruneColumnList(shifts, selected);\r
- if (selected!=null && selected.size()==0)\r
- selected=null;\r
- }\r
- // and shift the rest.\r
- this.compensateForEdits(deletions);\r
- }\r
- }\r
- }\r
- /**\r
- * This Method is used to return all the HiddenColumn regions\r
- * less than the given index.\r
- * @param end int\r
- * @return Vector\r
- */\r
- public Vector getHiddenColumns()\r
- {\r
- return hiddenColumns;\r
- }\r
- /**\r
- * Return absolute column index for a visible column index\r
- * @param column int column index in alignment view\r
- * @return alignment column index for column\r
- */\r
- public int adjustForHiddenColumns(int column)\r
- {\r
- int result = column;\r
- if (hiddenColumns != null)\r
- {\r
- for (int i = 0; i < hiddenColumns.size(); i++)\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(i);\r
- if (result >= region[0])\r
- {\r
- result += region[1] - region[0] + 1;\r
- }\r
- }\r
- }\r
- return result;\r
- }\r
-\r
- /**\r
- * Use this method to find out where a visible column is in the alignment\r
- * when hidden columns exist\r
- * @param hiddenColumn int\r
- * @return int\r
- */\r
- public int findColumnPosition(int hiddenColumn)\r
- {\r
- int result = hiddenColumn;\r
- if (hiddenColumns != null)\r
- {\r
- int index = 0;\r
- int gaps = 0;\r
- do\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(index);\r
- if (hiddenColumn > region[1])\r
- {\r
- result -= region[1]+1-region[0];\r
- }\r
- index++;\r
- }\r
- while (index < hiddenColumns.size());\r
-\r
- result -= gaps;\r
- }\r
-\r
- return result;\r
- }\r
-\r
- /**\r
- * Use this method to determine where the next hiddenRegion starts\r
- */\r
- public int findHiddenRegionPosition(int hiddenRegion)\r
- {\r
- int result = 0;\r
- if (hiddenColumns != null)\r
- {\r
- int index = 0;\r
- int gaps = 0;\r
- do\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(index);\r
- if(hiddenRegion==0)\r
- {\r
- return region[0];\r
- }\r
-\r
- gaps += region[1] +1 - region[0];\r
- result = region[1] +1;\r
- index++;\r
- }\r
- while(index < hiddenRegion+1);\r
-\r
- result -= gaps;\r
- }\r
-\r
- return result;\r
- }\r
-\r
- /**\r
- * THis method returns the rightmost limit of a\r
- * region of an alignment with hidden columns.\r
- * In otherwords, the next hidden column.\r
- * @param index int\r
- */\r
- public int getHiddenBoundaryRight(int alPos)\r
- {\r
- if (hiddenColumns != null)\r
- {\r
- int index = 0;\r
- do\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(index);\r
- if(alPos < region[0])\r
- return region[0];\r
-\r
- index++;\r
- }\r
- while(index < hiddenColumns.size());\r
- }\r
-\r
- return alPos;\r
-\r
- }\r
- /**\r
- * THis method returns the rightmost limit of a\r
- * region of an alignment with hidden columns.\r
- * In otherwords, the next hidden column.\r
- * @param index int\r
- */\r
- public int getHiddenBoundaryLeft(int alPos)\r
- {\r
- if (hiddenColumns != null)\r
- {\r
- int index = hiddenColumns.size()-1;\r
- do\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(index);\r
- if(alPos > region[1])\r
- return region[1];\r
-\r
- index--;\r
- }\r
- while(index >-1);\r
- }\r
-\r
- return alPos;\r
-\r
- }\r
-\r
- public void hideSelectedColumns()\r
- {\r
- while (size() > 0)\r
- {\r
- int column = ( (Integer) getSelected().firstElement()).intValue();\r
- hideColumns(column);\r
- }\r
-\r
- }\r
-\r
- public void hideColumns(int start, int end)\r
- {\r
- if(hiddenColumns==null)\r
- hiddenColumns = new Vector();\r
-\r
- boolean added = false;\r
- boolean overlap = false;\r
-\r
- for (int i = 0; i < hiddenColumns.size(); i++)\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(i);\r
- if ( start<=region[1] && end>=region[0])\r
- {\r
- hiddenColumns.removeElementAt(i);\r
- overlap = true;\r
- break;\r
- }\r
- else if (end < region[0] && start < region[0])\r
- {\r
- hiddenColumns.insertElementAt(new int[]\r
- {start, end}, i);\r
- added = true;\r
- break;\r
- }\r
- }\r
-\r
- if(overlap)\r
- {\r
- hideColumns(start, end);\r
- }\r
- else if (!added)\r
- hiddenColumns.addElement(new int[] {start, end});\r
-\r
- }\r
-\r
- /**\r
- * This method will find a range of selected columns\r
- * around the column specified\r
- * @param res int\r
- */\r
- public void hideColumns(int col)\r
- {\r
- // First find out range of columns to hide\r
- int min = col, max = col+1;\r
- while( contains(min) )\r
- { removeElement(min); min --; }\r
-\r
- while( contains(max) )\r
- { removeElement(max); max ++; }\r
-\r
- min++; max--;\r
-\r
- hideColumns(min, max);\r
- }\r
-\r
- public void revealAllHiddenColumns()\r
- {\r
- if(hiddenColumns!=null)\r
- {\r
- for (int i = 0; i < hiddenColumns.size(); i++)\r
- {\r
- int[] region = (int[]) hiddenColumns.elementAt(i);\r
- for (int j = region[0]; j < region[1]+1; j++)\r
- {\r
- addElement(j);\r
- }\r
- }\r
- }\r
-\r
- hiddenColumns = null;\r
- }\r
-\r
- public void revealHiddenColumns(int res)\r
- {\r
- for(int i=0; i<hiddenColumns.size(); i++)\r
- {\r
- int [] region = (int[])hiddenColumns.elementAt(i);\r
- if( res == region[0])\r
- {\r
- for (int j = region[0]; j < region[1]+1; j++)\r
- {\r
- addElement(j);\r
- }\r
-\r
- hiddenColumns.removeElement(region);\r
- break;\r
- }\r
- }\r
- if(hiddenColumns.size()==0)\r
- hiddenColumns = null;\r
- }\r
-\r
- public boolean isVisible(int column)\r
- {\r
- for(int i=0; i<hiddenColumns.size(); i++)\r
- {\r
- int [] region = (int[])hiddenColumns.elementAt(i);\r
- if( column >= region[0] && column <= region[1])\r
- {\r
- return false;\r
- }\r
- }\r
- return true;\r
- }\r
- /**\r
- * Copy constructor\r
- * @param copy\r
- */\r
- public ColumnSelection(ColumnSelection copy) {\r
- if (copy!=null) {\r
- if (copy.selected!=null) {\r
- selected = new Vector();\r
- for (int i=0,j=copy.selected.size(); i<j; i++) {\r
- selected.setElementAt( ((Integer) copy.selected.elementAt(i)), i);\r
- }\r
- }\r
- if (copy.hiddenColumns!=null) {\r
- hiddenColumns=new Vector();\r
- for (int i=0,j=copy.hiddenColumns.size(); i<j; i++) {\r
- int[] rh,cp;\r
- rh = (int[])copy.hiddenColumns.elementAt(i);\r
- if (rh!=null) {\r
- cp = new int[rh.length];\r
- System.arraycopy(rh, 0, cp, 0, rh.length);\r
- hiddenColumns.setElementAt(cp, i);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * ColumnSelection\r
- */\r
- public ColumnSelection()\r
- {\r
- }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.datamodel;
+
+import jalview.util.ShiftList;
+
+import java.util.*;
+
+/**
+ * NOTE: Columns are zero based.
+ */
+public class ColumnSelection
+{
+ Vector selected = new Vector();
+
+ //Vector of int [] {startCol, endCol}
+ Vector hiddenColumns;
+
+ /**
+ * Add a column to the selection
+ *
+ * @param col index of column
+ */
+ public void addElement(int col)
+ {
+ Integer column = new Integer(col);
+ if (!selected.contains(column))
+ {
+ selected.addElement(column);
+ }
+ }
+
+ /**
+ * clears column selection
+ */
+ public void clear()
+ {
+ selected.removeAllElements();
+ }
+
+ /**
+ * removes col from selection
+ *
+ * @param col index of column to be removed
+ */
+ public void removeElement(int col)
+ {
+ Integer colInt = new Integer(col);
+
+ if (selected.contains(colInt))
+ {
+ selected.removeElement(colInt);
+ }
+ }
+
+ /**
+ * removes a range of columns from the selection
+ * @param start int - first column in range to be removed
+ * @param end int - last col
+ */
+ public void removeElements(int start, int end)
+ {
+ Integer colInt;
+ for(int i=start; i<end; i++)
+ {
+ colInt = new Integer(i);
+ if (selected.contains(colInt))
+ {
+ selected.removeElement(colInt);
+ }
+ }
+ }
+ /**
+ *
+ * @return Vector containing selected columns as Integers
+ */
+ public Vector getSelected()
+ {
+ return selected;
+ }
+
+ /**
+ *
+ * @param col index to search for in column selection
+ *
+ * @return true if Integer(col) is in selection.
+ */
+ public boolean contains(int col)
+ {
+ return selected.contains(new Integer(col));
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int columnAt(int i)
+ {
+ return ((Integer) selected.elementAt(i)).intValue();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int size()
+ {
+ return selected.size();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getMax()
+ {
+ int max = -1;
+
+ for (int i = 0; i < selected.size(); i++)
+ {
+ if (columnAt(i) > max)
+ {
+ max = columnAt(i);
+ }
+ }
+
+ return max;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getMin()
+ {
+ int min = 1000000000;
+
+ for (int i = 0; i < selected.size(); i++)
+ {
+ if (columnAt(i) < min)
+ {
+ min = columnAt(i);
+ }
+ }
+
+ return min;
+ }
+
+
+ /**
+ * propagate shift in alignment columns to column selection
+ *
+ * @param start beginning of edit
+ * @param left shift in edit (+ve for removal, or -ve for inserts)
+ */
+ public void compensateForEdit(int start, int change)
+ {
+ for (int i = 0; i < size(); i++)
+ {
+ int temp = columnAt(i);
+
+ if (temp >= start)
+ {
+ selected.setElementAt(new Integer(temp - change), i);
+ }
+ }
+
+ if(hiddenColumns!=null)
+ {
+ for(int i=0; i<hiddenColumns.size(); i++)
+ {
+ int[] region = (int[]) hiddenColumns.elementAt(i);
+ if(region[0] > start)
+ {
+ region[0] -= change;
+ region[1] -= change;
+ }
+ if(region[0]<0)
+ region[0] = 0;
+ if(region[1] <0)
+ region[1] = 0;
+ }
+ }
+ }
+ /**
+ * propagate shift in alignment columns to column selection
+ * special version of compensateForEdit - allowing for edits within hidden regions
+ * @param start beginning of edit
+ * @param left shift in edit (+ve for removal, or -ve for inserts)
+ */
+ private void compensateForDelEdits(int start, int change)
+ {
+ for (int i = 0; i < size(); i++)
+ {
+ int temp = columnAt(i);
+
+ if (temp >= start)
+ {
+ selected.setElementAt(new Integer(temp - change), i);
+ }
+ }
+
+ if(hiddenColumns!=null)
+ {
+ for(int i=0; i<hiddenColumns.size(); i++)
+ {
+ int[] region = (int[]) hiddenColumns.elementAt(i);
+ if(region[0] >= start)
+ {
+ region[0] -= change;
+ }
+ if (region[1]>= start) {
+ region[1] -=change;
+ }
+ if (region[1]<region[0]) {
+ hiddenColumns.removeElementAt(i--);
+ }
+
+ if(region[0]<0)
+ region[0] = 0;
+ if(region[1] <0)
+ region[1] = 0;
+ }
+ }
+ }
+ /**
+ * Adjust hidden column boundaries based on a series of column
+ * additions or deletions in visible regions.
+ * @param shiftrecord
+ * @return
+ */
+ public ShiftList compensateForEdits(ShiftList shiftrecord) {
+ if (shiftrecord!=null) {
+ Vector shifts = shiftrecord.shifts;
+ if (shifts!=null && shifts.size()>0) {
+ int shifted=0;
+ for (int i=0,j=shifts.size(); i<j; i++) {
+ int[] sh = (int[]) shifts.elementAt(i);
+ //compensateForEdit(shifted+sh[0], sh[1]);
+ compensateForDelEdits(shifted+sh[0], sh[1]);
+ shifted-=sh[1];
+ }
+ }
+ return shiftrecord.getInverse();
+ }
+ return null;
+ }
+ /**
+ * removes intersection of position,length ranges in deletions
+ * from the start,end regions marked in intervals.
+ * @param deletions
+ * @param intervals
+ * @return
+ */
+ private boolean pruneIntervalVector(Vector deletions, Vector intervals) {
+ boolean pruned=false;
+ int i=0,j=intervals.size()-1, s=0, t=deletions.size()-1;
+ int hr[]=(int[]) intervals.elementAt(i);
+ int sr[]=(int[]) deletions.elementAt(s);
+ while (i<=j && s<=t) {
+ boolean trailinghn=hr[1]>=sr[0];
+ if (!trailinghn) {
+ if (i<j)
+ hr=(int[]) intervals.elementAt(++i);
+ else
+ i++;
+ continue;
+ }
+ int endshift=sr[0]+sr[1]; // deletion ranges - -ve means an insert
+ if (endshift<hr[0] || endshift<sr[0]) { // leadinghc disjoint or not a deletion
+ if (s<t)
+ sr=(int[]) deletions.elementAt(++s);
+ else
+ s++;
+ continue;
+ }
+ boolean leadinghn=hr[0]>=sr[0];
+ boolean leadinghc=hr[0]<endshift;
+ boolean trailinghc=hr[1]<endshift;
+ if (leadinghn) {
+ if (trailinghc) {// deleted hidden region.
+ intervals.removeElementAt(i);
+ pruned=true;
+ j--;
+ if (i<=j)
+ hr=(int[]) intervals.elementAt(i);
+ continue;
+ }
+ if (leadinghc) {
+ hr[0]=endshift; // clip c terminal region
+ leadinghn=!leadinghn;
+ pruned=true;
+ }
+ }
+ if (!leadinghn) {
+ if (trailinghc) {
+ if (trailinghn) {
+ hr[1]=sr[0]-1;
+ pruned=true;
+ }
+ } else {
+ // sr contained in hr
+ if (s<t)
+ sr=(int[]) deletions.elementAt(++s);
+ else
+ s++;
+ continue;
+ }
+ }
+ }
+ return pruned; // true if any interval was removed or modified by operations.
+ }
+ private boolean pruneColumnList(Vector deletion, Vector list) {
+ int s=0,t=deletion.size();
+ int[] sr=(int[])list.elementAt(s++);
+ boolean pruned=false;
+ int i=0, j=list.size();
+ while (i<j && s<=t) {
+ int c=((Integer)list.elementAt(i++)).intValue();
+ if (sr[0]<=c) {
+ if (sr[1]+sr[0]>=c) { // sr[1] -ve means inseriton.
+ list.removeElementAt(--i);
+ j--;
+ } else {
+ if (s<t)
+ sr = (int[])deletion.elementAt(s);
+ s++;
+ }
+ }
+ }
+ return pruned;
+ }
+ /**
+ * remove any hiddenColumns or selected columns and shift remaining
+ * based on a series of position, range deletions.
+ * @param deletions
+ */
+ public void pruneDeletions(ShiftList deletions) {
+ if (deletions!=null) {
+ Vector shifts=deletions.shifts;
+ if (shifts!=null && shifts.size()>0) {
+ // delete any intervals intersecting.
+ if (hiddenColumns!=null) {
+ pruneIntervalVector(shifts, hiddenColumns);
+ if (hiddenColumns!=null && hiddenColumns.size()==0) {
+ hiddenColumns=null;
+ }
+ }
+ if (selected!=null && selected.size()>0) {
+ pruneColumnList(shifts, selected);
+ if (selected!=null && selected.size()==0)
+ selected=null;
+ }
+ // and shift the rest.
+ this.compensateForEdits(deletions);
+ }
+ }
+ }
+ /**
+ * This Method is used to return all the HiddenColumn regions
+ * less than the given index.
+ * @param end int
+ * @return Vector
+ */
+ public Vector getHiddenColumns()
+ {
+ return hiddenColumns;
+ }
+ /**
+ * Return absolute column index for a visible column index
+ * @param column int column index in alignment view
+ * @return alignment column index for column
+ */
+ public int adjustForHiddenColumns(int column)
+ {
+ int result = column;
+ if (hiddenColumns != null)
+ {
+ for (int i = 0; i < hiddenColumns.size(); i++)
+ {
+ int[] region = (int[]) hiddenColumns.elementAt(i);
+ if (result >= region[0])
+ {
+ result += region[1] - region[0] + 1;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Use this method to find out where a visible column is in the alignment
+ * when hidden columns exist
+ * @param hiddenColumn int
+ * @return int
+ */
+ public int findColumnPosition(int hiddenColumn)
+ {
+ int result = hiddenColumn;
+ if (hiddenColumns != null)
+ {
+ int index = 0;
+ int gaps = 0;
+ do
+ {
+ int[] region = (int[]) hiddenColumns.elementAt(index);
+ if (hiddenColumn > region[1])
+ {
+ result -= region[1]+1-region[0];
+ }
+ index++;
+ }
+ while (index < hiddenColumns.size());
+
+ result -= gaps;
+ }
+
+ return result;
+ }
+
+ /**
+ * Use this method to determine where the next hiddenRegion starts
+ */
+ public int findHiddenRegionPosition(int hiddenRegion)
+ {
+ int result = 0;
+ if (hiddenColumns != null)
+ {
+ int index = 0;
+ int gaps = 0;
+ do
+ {
+ int[] region = (int[]) hiddenColumns.elementAt(index);
+ if(hiddenRegion==0)
+ {
+ return region[0];
+ }
+
+ gaps += region[1] +1 - region[0];
+ result = region[1] +1;
+ index++;
+ }
+ while(index < hiddenRegion+1);
+
+ result -= gaps;
+ }
+
+ return result;
+ }
+
+ /**
+ * THis method returns the rightmost limit of a
+ * region of an alignment with hidden columns.
+ * In otherwords, the next hidden column.
+ * @param index int
+ */
+ public int getHiddenBoundaryRight(int alPos)
+ {
+ if (hiddenColumns != null)
+ {
+ int index = 0;
+ do
+ {
+ int[] region = (int[]) hiddenColumns.elementAt(index);
+ if(alPos < region[0])
+ return region[0];
+
+ index++;
+ }
+ while(index < hiddenColumns.size());
+ }
+
+ return alPos;
+
+ }
+ /**
+ * THis method returns the rightmost limit of a
+ * region of an alignment with hidden columns.
+ * In otherwords, the next hidden column.
+ * @param index int
+ */
+ public int getHiddenBoundaryLeft(int alPos)
+ {
+ if (hiddenColumns != null)
+ {
+ int index = hiddenColumns.size()-1;
+ do
+ {
+ int[] region = (int[]) hiddenColumns.elementAt(index);
+ if(alPos > region[1])
+ return region[1];
+
+ index--;
+ }
+ while(index >-1);
+ }
+
+ return alPos;
+
+ }
+
+ public void hideSelectedColumns()
+ {
+ while (size() > 0)
+ {
+ int column = ( (Integer) getSelected().firstElement()).intValue();
+ hideColumns(column);
+ }
+
+ }
+
+ public void hideColumns(int start, int end)
+ {
+ if(hiddenColumns==null)
+ hiddenColumns = new Vector();
+
+ boolean added = false;
+ boolean overlap = false;
+
+ for (int i = 0; i < hiddenColumns.size(); i++)
+ {
+ int[] region = (int[]) hiddenColumns.elementAt(i);
+ if ( start<=region[1] && end>=region[0])
+ {
+ hiddenColumns.removeElementAt(i);
+ overlap = true;
+ break;
+ }
+ else if (end < region[0] && start < region[0])
+ {
+ hiddenColumns.insertElementAt(new int[]
+ {start, end}, i);
+ added = true;
+ break;
+ }
+ }
+
+ if(overlap)
+ {
+ hideColumns(start, end);
+ }
+ else if (!added)
+ hiddenColumns.addElement(new int[] {start, end});
+
+ }
+
+ /**
+ * This method will find a range of selected columns
+ * around the column specified
+ * @param res int
+ */
+ public void hideColumns(int col)
+ {
+ // First find out range of columns to hide
+ int min = col, max = col+1;
+ while( contains(min) )
+ { removeElement(min); min --; }
+
+ while( contains(max) )
+ { removeElement(max); max ++; }
+
+ min++; max--;
+
+ hideColumns(min, max);
+ }
+
+ public void revealAllHiddenColumns()
+ {
+ if(hiddenColumns!=null)
+ {
+ for (int i = 0; i < hiddenColumns.size(); i++)
+ {
+ int[] region = (int[]) hiddenColumns.elementAt(i);
+ for (int j = region[0]; j < region[1]+1; j++)
+ {
+ addElement(j);
+ }
+ }
+ }
+
+ hiddenColumns = null;
+ }
+
+ public void revealHiddenColumns(int res)
+ {
+ for(int i=0; i<hiddenColumns.size(); i++)
+ {
+ int [] region = (int[])hiddenColumns.elementAt(i);
+ if( res == region[0])
+ {
+ for (int j = region[0]; j < region[1]+1; j++)
+ {
+ addElement(j);
+ }
+
+ hiddenColumns.removeElement(region);
+ break;
+ }
+ }
+ if(hiddenColumns.size()==0)
+ hiddenColumns = null;
+ }
+
+ public boolean isVisible(int column)
+ {
+ for(int i=0; i<hiddenColumns.size(); i++)
+ {
+ int [] region = (int[])hiddenColumns.elementAt(i);
+ if( column >= region[0] && column <= region[1])
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ /**
+ * Copy constructor
+ * @param copy
+ */
+ public ColumnSelection(ColumnSelection copy) {
+ if (copy!=null) {
+ if (copy.selected!=null) {
+ selected = new Vector();
+ for (int i=0,j=copy.selected.size(); i<j; i++) {
+ selected.setElementAt( ((Integer) copy.selected.elementAt(i)), i);
+ }
+ }
+ if (copy.hiddenColumns!=null) {
+ hiddenColumns=new Vector();
+ for (int i=0,j=copy.hiddenColumns.size(); i<j; i++) {
+ int[] rh,cp;
+ rh = (int[])copy.hiddenColumns.elementAt(i);
+ if (rh!=null) {
+ cp = new int[rh.length];
+ System.arraycopy(rh, 0, cp, 0, rh.length);
+ hiddenColumns.setElementAt(cp, i);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * ColumnSelection
+ */
+ public ColumnSelection()
+ {
+ }
+
+ public String[] getVisibleSequenceStrings(int start, int end, SequenceI[] seqs) {
+ int i,iSize=seqs.length;
+ String selection[] = new String[iSize];
+ if (hiddenColumns!=null && hiddenColumns.size()>0)
+ {
+ for (i=0; i<iSize; i++) {
+ StringBuffer visibleSeq = new StringBuffer();
+ Vector regions = getHiddenColumns();
+
+ int blockStart = start, blockEnd=end;
+ int [] region;
+ int hideStart, hideEnd;
+
+ for (int j = 0; j < regions.size(); j++)
+ {
+ region = (int[]) regions.elementAt(j);
+ hideStart = region[0];
+ hideEnd = region[1];
+
+ if(hideStart < start)
+ {
+ continue;
+ }
+
+ blockStart = Math.min(blockStart, hideEnd+1);
+ blockEnd = Math.min(blockEnd, hideStart);
+
+ if(blockStart>blockEnd)
+ {
+ break;
+ }
+
+
+ visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
+
+ blockStart = hideEnd+1;
+ blockEnd = end;
+ }
+
+ if(end>blockStart)
+ visibleSeq.append(seqs[i].getSequence(blockStart, end));
+
+ selection[i] = visibleSeq.toString();
+ }
+ }
+ else
+ {
+ for(i=0; i<iSize; i++)
+ {
+ selection[i] = seqs[i].getSequence(start, end);
+ }
+ }
+
+ return selection;
+ }
+
+}
- /*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
- */\r
-package jalview.gui;\r
-\r
-import jalview.analysis.*;\r
-\r
-import jalview.bin.*;\r
-\r
-import jalview.datamodel.*;\r
-\r
-import jalview.schemes.*;\r
-\r
-import java.awt.*;\r
-\r
-import java.util.*;\r
-\r
-\r
-/**\r
- * DOCUMENT ME!\r
- *\r
- * @author $author$\r
- * @version $Revision$\r
- */\r
-public class AlignViewport\r
-{\r
- int startRes;\r
- int endRes;\r
- int startSeq;\r
- int endSeq;\r
- boolean showJVSuffix = true;\r
- boolean showText = true;\r
- boolean showColourText = false;\r
- boolean showBoxes = true;\r
- boolean wrapAlignment = false;\r
- boolean renderGaps = true;\r
- boolean showSequenceFeatures = false;\r
- boolean showAnnotation = true;\r
- boolean showConservation = true;\r
- boolean showQuality = true;\r
- boolean showIdentity = true;\r
- boolean colourAppliesToAllGroups = true;\r
- ColourSchemeI globalColourScheme = null;\r
- boolean conservationColourSelected = false;\r
- boolean abovePIDThreshold = false;\r
- SequenceGroup selectionGroup;\r
- int charHeight;\r
- int charWidth;\r
- boolean validCharWidth;\r
- int wrappedWidth;\r
- Font font;\r
- AlignmentI alignment;\r
- ColumnSelection colSel = new ColumnSelection();\r
- int threshold;\r
- int increment;\r
- NJTree currentTree = null;\r
- boolean scaleAboveWrapped = false;\r
- boolean scaleLeftWrapped = true;\r
- boolean scaleRightWrapped = true;\r
- boolean hasHiddenColumns = false;\r
- boolean hasHiddenRows = false;\r
- boolean showHiddenMarkers = true;\r
-\r
- boolean cursorMode = false;\r
-\r
- // The following vector holds the features which are\r
- // currently visible, in the correct order or rendering\r
- Hashtable featuresDisplayed = null;\r
-\r
-\r
- /** DOCUMENT ME!! */\r
- public Vector vconsensus;\r
- AlignmentAnnotation consensus;\r
- AlignmentAnnotation conservation;\r
- AlignmentAnnotation quality;\r
- boolean autoCalculateConsensus = true;\r
-\r
- /** DOCUMENT ME!! */\r
- public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!\r
-\r
- // JBPNote Prolly only need this in the applet version.\r
- private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);\r
-\r
- boolean ignoreGapsInConsensusCalculation = false;\r
-\r
- boolean isDataset = false;\r
-\r
- boolean antiAlias = false;\r
-\r
- boolean padGaps = false;\r
-\r
-\r
- public AlignViewport(AlignmentI al, boolean dataset)\r
- {\r
- isDataset = dataset;\r
- setAlignment(al);\r
- init();\r
- }\r
- /**\r
- * Creates a new AlignViewport object.\r
- *\r
- * @param al DOCUMENT ME!\r
- */\r
- public AlignViewport(AlignmentI al)\r
- {\r
- setAlignment(al);\r
- init();\r
- }\r
- /**\r
- * Create a new AlignViewport with hidden regions\r
- * @param al AlignmentI\r
- * @param hiddenColumns ColumnSelection\r
- */\r
- public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) {\r
- setAlignment(al);\r
- if (hiddenColumns!=null) {\r
- this.colSel = hiddenColumns;\r
- if (hiddenColumns.getHiddenColumns() != null)\r
- hasHiddenColumns = true;\r
- }\r
- init();\r
- }\r
-\r
- void init()\r
- {\r
- this.startRes = 0;\r
- this.endRes = alignment.getWidth() - 1;\r
- this.startSeq = 0;\r
- this.endSeq = alignment.getHeight() - 1;\r
-\r
- antiAlias = Cache.getDefault("ANTI_ALIAS", false);\r
-\r
- showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);\r
- showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);\r
- showConservation = Cache.getDefault("SHOW_CONSERVATION", true);\r
-\r
- showQuality = Cache.getDefault("SHOW_QUALITY", true);\r
- showIdentity = Cache.getDefault("SHOW_IDENTITY", true);\r
-\r
- autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);\r
-\r
- padGaps = Cache.getDefault("PAD_GAPS", false);\r
-\r
- String fontName = Cache.getDefault("FONT_NAME", "SansSerif");\r
- String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;\r
- String fontSize = Cache.getDefault("FONT_SIZE", "10");\r
-\r
- int style = 0;\r
-\r
- if (fontStyle.equals("bold"))\r
- {\r
- style = 1;\r
- }\r
- else if (fontStyle.equals("italic"))\r
- {\r
- style = 2;\r
- }\r
-\r
- setFont(new Font(fontName, style, Integer.parseInt(fontSize)));\r
-\r
-\r
- alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );\r
-\r
-\r
- // We must set conservation and consensus before setting colour,\r
- // as Blosum and Clustal require this to be done\r
- if(vconsensus==null && !isDataset)\r
- {\r
- updateConservation();\r
- updateConsensus();\r
- }\r
-\r
- if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)\r
- {\r
- globalColourScheme = ColourSchemeProperty.getColour(alignment,\r
- jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));\r
-\r
- if (globalColourScheme instanceof UserColourScheme)\r
- {\r
- globalColourScheme = UserDefinedColours.loadDefaultColours();\r
- ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());\r
- }\r
-\r
- if (globalColourScheme != null)\r
- {\r
- globalColourScheme.setConsensus(vconsensus);\r
- }\r
- }\r
- }\r
-\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param b DOCUMENT ME!\r
- */\r
- public void setShowSequenceFeatures(boolean b)\r
- {\r
- showSequenceFeatures = b;\r
- }\r
-\r
- public boolean getShowSequenceFeatures()\r
- {\r
- return showSequenceFeatures;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- */\r
- public void updateConservation()\r
- {\r
- if(alignment.isNucleotide())\r
- return;\r
-\r
- try{\r
- Conservation cons = new jalview.analysis.Conservation("All",\r
- jalview.schemes.ResidueProperties.propHash, 3,\r
- alignment.getSequences(), 0, alignment.getWidth() - 1);\r
- cons.calculate();\r
- cons.verdict(false, ConsPercGaps);\r
- cons.findQuality();\r
-\r
- int alWidth = alignment.getWidth();\r
- Annotation[] annotations = new Annotation[alWidth];\r
- Annotation[] qannotations = new Annotation[alWidth];\r
- String sequence = cons.getConsSequence().getSequence();\r
- float minR;\r
- float minG;\r
- float minB;\r
- float maxR;\r
- float maxG;\r
- float maxB;\r
- minR = 0.3f;\r
- minG = 0.0f;\r
- minB = 0f;\r
- maxR = 1.0f - minR;\r
- maxG = 0.9f - minG;\r
- maxB = 0f - minB; // scalable range for colouring both Conservation and Quality\r
-\r
- float min = 0f;\r
- float max = 11f;\r
- float qmin = cons.qualityRange[0].floatValue();\r
- float qmax = cons.qualityRange[1].floatValue();\r
-\r
- for (int i = 0; i < alWidth; i++)\r
- {\r
- float value = 0;\r
-\r
- try\r
- {\r
- value = Integer.parseInt(sequence.charAt(i) + "");\r
- }\r
- catch (Exception ex)\r
- {\r
- if (sequence.charAt(i) == '*')\r
- {\r
- value = 11;\r
- }\r
-\r
- if (sequence.charAt(i) == '+')\r
- {\r
- value = 10;\r
- }\r
- }\r
-\r
- float vprop = value - min;\r
- vprop /= max;\r
- annotations[i] = new Annotation(sequence.charAt(i) + "",\r
- String.valueOf(value), ' ', value,\r
- new Color(minR + (maxR * vprop),\r
- minG + (maxG * vprop),\r
- minB + (maxB * vprop)));\r
-\r
- // Quality calc\r
- value = ( (Double) cons.quality.get(i)).floatValue();\r
- vprop = value - qmin;\r
- vprop /= qmax;\r
- qannotations[i] = new Annotation(" ", String.valueOf(value), ' ',\r
- value,\r
- new Color(minR + (maxR * vprop),\r
- minG + (maxG * vprop),\r
- minB + (maxB * vprop)));\r
- }\r
-\r
- if (conservation == null)\r
- {\r
- conservation = new AlignmentAnnotation("Conservation",\r
- "Conservation of total alignment less than " +\r
- ConsPercGaps + "% gaps",\r
- annotations, 0f, // cons.qualityRange[0].floatValue(),\r
- 11f, // cons.qualityRange[1].floatValue()\r
- AlignmentAnnotation.BAR_GRAPH);\r
-\r
- if (showConservation)\r
- {\r
- alignment.addAnnotation(conservation);\r
- }\r
-\r
- quality = new AlignmentAnnotation("Quality",\r
- "Alignment Quality based on Blosum62 scores",\r
- qannotations,\r
- cons.qualityRange[0].floatValue(),\r
- cons.qualityRange[1].floatValue(),\r
- AlignmentAnnotation.BAR_GRAPH);\r
-\r
- if (showQuality)\r
- {\r
- alignment.addAnnotation(quality);\r
- }\r
- }\r
- else\r
- {\r
- conservation.annotations = annotations;\r
- quality.annotations = qannotations;\r
- quality.graphMax = cons.qualityRange[1].floatValue();\r
- }\r
- }\r
- catch (OutOfMemoryError error)\r
- {\r
- javax.swing.SwingUtilities.invokeLater(new Runnable()\r
- {\r
- public void run()\r
- {\r
- javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
- "Out of memory calculating conservation!!"\r
- +\r
- "\nSee help files for increasing Java Virtual Machine memory."\r
- , "Out of memory",\r
- javax.swing.JOptionPane.WARNING_MESSAGE);\r
- }\r
- });\r
-\r
- System.out.println("Conservation calculation: " + error);\r
- System.gc();\r
-\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- */\r
- public void updateConsensus()\r
- {\r
- try{\r
- Annotation[] annotations = new Annotation[alignment.getWidth()];\r
-\r
- // this routine prevents vconsensus becoming a new object each time\r
- // consenus is calculated. Important for speed of Blosum62\r
- // and PID colouring of alignment\r
- if (vconsensus == null)\r
- {\r
- vconsensus = alignment.getAAFrequency();\r
- }\r
- else\r
- {\r
- Vector temp = alignment.getAAFrequency();\r
- vconsensus.clear();\r
-\r
- Enumeration e = temp.elements();\r
-\r
- while (e.hasMoreElements())\r
- {\r
- vconsensus.add(e.nextElement());\r
- }\r
- }\r
-\r
- Hashtable hash = null;\r
-\r
- for (int i = 0; i < alignment.getWidth(); i++)\r
- {\r
- hash = (Hashtable) vconsensus.elementAt(i);\r
-\r
- float value = 0;\r
- if (ignoreGapsInConsensusCalculation)\r
- value = ( (Float) hash.get("pid_nogaps")).floatValue();\r
- else\r
- value = ( (Float) hash.get("pid_gaps")).floatValue();\r
-\r
- String maxRes = hash.get("maxResidue").toString();\r
- String mouseOver = hash.get("maxResidue") + " ";\r
-\r
- if (maxRes.length() > 1)\r
- {\r
- mouseOver = "[" + maxRes + "] ";\r
- maxRes = "+";\r
- }\r
-\r
- mouseOver += ( (int) value + "%");\r
- annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);\r
- }\r
-\r
- if (consensus == null)\r
- {\r
- consensus = new AlignmentAnnotation("Consensus", "PID",\r
- annotations, 0f, 100f,AlignmentAnnotation.BAR_GRAPH);\r
-\r
- if (showIdentity)\r
- {\r
- alignment.addAnnotation(consensus);\r
- }\r
- }\r
- else\r
- {\r
- consensus.annotations = annotations;\r
- }\r
-\r
- if (globalColourScheme != null)\r
- globalColourScheme.setConsensus(vconsensus);\r
-\r
- }catch(OutOfMemoryError error)\r
- {\r
- javax.swing.SwingUtilities.invokeLater(new Runnable()\r
- {\r
- public void run()\r
- {\r
- javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
- "Out of memory calc45ulating consensus!!"\r
- +\r
- "\nSee help files for increasing Java Virtual Machine memory."\r
- , "Out of memory",\r
- javax.swing.JOptionPane.WARNING_MESSAGE);\r
- }\r
- });\r
-\r
-\r
- System.out.println("Consensus calculation: " + error);\r
- System.gc();\r
- }\r
-\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public SequenceGroup getSelectionGroup()\r
- {\r
- return selectionGroup;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param sg DOCUMENT ME!\r
- */\r
- public void setSelectionGroup(SequenceGroup sg)\r
- {\r
- selectionGroup = sg;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public boolean getConservationSelected()\r
- {\r
- return conservationColourSelected;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param b DOCUMENT ME!\r
- */\r
- public void setConservationSelected(boolean b)\r
- {\r
- conservationColourSelected = b;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public boolean getAbovePIDThreshold()\r
- {\r
- return abovePIDThreshold;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param b DOCUMENT ME!\r
- */\r
- public void setAbovePIDThreshold(boolean b)\r
- {\r
- abovePIDThreshold = b;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getStartRes()\r
- {\r
- return startRes;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getEndRes()\r
- {\r
- return endRes;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getStartSeq()\r
- {\r
- return startSeq;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param cs DOCUMENT ME!\r
- */\r
- public void setGlobalColourScheme(ColourSchemeI cs)\r
- {\r
- globalColourScheme = cs;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public ColourSchemeI getGlobalColourScheme()\r
- {\r
- return globalColourScheme;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param res DOCUMENT ME!\r
- */\r
- public void setStartRes(int res)\r
- {\r
- this.startRes = res;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param seq DOCUMENT ME!\r
- */\r
- public void setStartSeq(int seq)\r
- {\r
- this.startSeq = seq;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param res DOCUMENT ME!\r
- */\r
- public void setEndRes(int res)\r
- {\r
- if (res > (alignment.getWidth() - 1))\r
- {\r
- // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));\r
- res = alignment.getWidth() - 1;\r
- }\r
-\r
- if (res < 0)\r
- {\r
- res = 0;\r
- }\r
-\r
- this.endRes = res;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param seq DOCUMENT ME!\r
- */\r
- public void setEndSeq(int seq)\r
- {\r
- if (seq > alignment.getHeight())\r
- {\r
- seq = alignment.getHeight();\r
- }\r
-\r
- if (seq < 0)\r
- {\r
- seq = 0;\r
- }\r
-\r
- this.endSeq = seq;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getEndSeq()\r
- {\r
- return endSeq;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param f DOCUMENT ME!\r
- */\r
- public void setFont(Font f)\r
- {\r
- font = f;\r
-\r
- Container c = new Container();\r
-\r
- java.awt.FontMetrics fm = c.getFontMetrics(font);\r
- setCharHeight(fm.getHeight());\r
- setCharWidth(fm.charWidth('M'));\r
- validCharWidth = true;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public Font getFont()\r
- {\r
- return font;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param w DOCUMENT ME!\r
- */\r
- public void setCharWidth(int w)\r
- {\r
- this.charWidth = w;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getCharWidth()\r
- {\r
- return charWidth;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param h DOCUMENT ME!\r
- */\r
- public void setCharHeight(int h)\r
- {\r
- this.charHeight = h;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getCharHeight()\r
- {\r
- return charHeight;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param w DOCUMENT ME!\r
- */\r
- public void setWrappedWidth(int w)\r
- {\r
- this.wrappedWidth = w;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getWrappedWidth()\r
- {\r
- return wrappedWidth;\r
- }\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public AlignmentI getAlignment()\r
- {\r
- return alignment;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param align DOCUMENT ME!\r
- */\r
- public void setAlignment(AlignmentI align)\r
- {\r
- this.alignment = align;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param state DOCUMENT ME!\r
- */\r
- public void setWrapAlignment(boolean state)\r
- {\r
- wrapAlignment = state;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param state DOCUMENT ME!\r
- */\r
- public void setShowText(boolean state)\r
- {\r
- showText = state;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param state DOCUMENT ME!\r
- */\r
- public void setRenderGaps(boolean state)\r
- {\r
- renderGaps = state;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public boolean getColourText()\r
- {\r
- return showColourText;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param state DOCUMENT ME!\r
- */\r
- public void setColourText(boolean state)\r
- {\r
- showColourText = state;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param state DOCUMENT ME!\r
- */\r
- public void setShowBoxes(boolean state)\r
- {\r
- showBoxes = state;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public boolean getWrapAlignment()\r
- {\r
- return wrapAlignment;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public boolean getShowText()\r
- {\r
- return showText;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public boolean getShowBoxes()\r
- {\r
- return showBoxes;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public char getGapCharacter()\r
- {\r
- return getAlignment().getGapCharacter();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param gap DOCUMENT ME!\r
- */\r
- public void setGapCharacter(char gap)\r
- {\r
- if (getAlignment() != null)\r
- {\r
- getAlignment().setGapCharacter(gap);\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param thresh DOCUMENT ME!\r
- */\r
- public void setThreshold(int thresh)\r
- {\r
- threshold = thresh;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getThreshold()\r
- {\r
- return threshold;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param inc DOCUMENT ME!\r
- */\r
- public void setIncrement(int inc)\r
- {\r
- increment = inc;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public int getIncrement()\r
- {\r
- return increment;\r
- }\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public ColumnSelection getColumnSelection()\r
- {\r
- return colSel;\r
- }\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param tree DOCUMENT ME!\r
- */\r
- public void setCurrentTree(NJTree tree)\r
- {\r
- currentTree = tree;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public NJTree getCurrentTree()\r
- {\r
- return currentTree;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param b DOCUMENT ME!\r
- */\r
- public void setColourAppliesToAllGroups(boolean b)\r
- {\r
- colourAppliesToAllGroups = b;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public boolean getColourAppliesToAllGroups()\r
- {\r
- return colourAppliesToAllGroups;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public boolean getShowJVSuffix()\r
- {\r
- return showJVSuffix;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param b DOCUMENT ME!\r
- */\r
- public void setShowJVSuffix(boolean b)\r
- {\r
- showJVSuffix = b;\r
- }\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public boolean getShowAnnotation()\r
- {\r
- return showAnnotation;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param b DOCUMENT ME!\r
- */\r
- public void setShowAnnotation(boolean b)\r
- {\r
- showAnnotation = b;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public boolean getScaleAboveWrapped()\r
- {\r
- return scaleAboveWrapped;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public boolean getScaleLeftWrapped()\r
- {\r
- return scaleLeftWrapped;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public boolean getScaleRightWrapped()\r
- {\r
- return scaleRightWrapped;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param b DOCUMENT ME!\r
- */\r
- public void setScaleAboveWrapped(boolean b)\r
- {\r
- scaleAboveWrapped = b;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param b DOCUMENT ME!\r
- */\r
- public void setScaleLeftWrapped(boolean b)\r
- {\r
- scaleLeftWrapped = b;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param b DOCUMENT ME!\r
- */\r
- public void setScaleRightWrapped(boolean b)\r
- {\r
- scaleRightWrapped = b;\r
- }\r
-\r
- /**\r
- * Property change listener for changes in alignment\r
- *\r
- * @param listener DOCUMENT ME!\r
- */\r
- public void addPropertyChangeListener(\r
- java.beans.PropertyChangeListener listener)\r
- {\r
- changeSupport.addPropertyChangeListener(listener);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param listener DOCUMENT ME!\r
- */\r
- public void removePropertyChangeListener(\r
- java.beans.PropertyChangeListener listener)\r
- {\r
- changeSupport.removePropertyChangeListener(listener);\r
- }\r
-\r
- /**\r
- * Property change listener for changes in alignment\r
- *\r
- * @param prop DOCUMENT ME!\r
- * @param oldvalue DOCUMENT ME!\r
- * @param newvalue DOCUMENT ME!\r
- */\r
- public void firePropertyChange(String prop, Object oldvalue, Object newvalue)\r
- {\r
- changeSupport.firePropertyChange(prop, oldvalue, newvalue);\r
- }\r
-\r
- public void setIgnoreGapsConsensus(boolean b)\r
- {\r
- ignoreGapsInConsensusCalculation = b;\r
- updateConsensus();\r
- if(globalColourScheme!=null)\r
- {\r
- globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);\r
- }\r
- }\r
-\r
- public boolean getIgnoreGapsConsensus()\r
- {\r
- return ignoreGapsInConsensusCalculation;\r
- }\r
-\r
- public void setDataset(boolean b)\r
- {\r
- isDataset = b;\r
- }\r
-\r
- public boolean isDataset()\r
- {\r
- return isDataset;\r
- }\r
-\r
-\r
- public void hideSelectedColumns()\r
- {\r
- if (colSel.size() < 1)\r
- return;\r
-\r
- colSel.hideSelectedColumns();\r
- setSelectionGroup(null);\r
-\r
- hasHiddenColumns = true;\r
- }\r
-\r
-\r
- public void hideColumns(int start, int end)\r
- {\r
- if(start==end)\r
- colSel.hideColumns(start);\r
- else\r
- colSel.hideColumns(start, end);\r
-\r
- hasHiddenColumns = true;\r
- }\r
-\r
- public void hideAllSelectedSeqs()\r
- {\r
- if (selectionGroup == null)\r
- return;\r
-\r
- SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);\r
-\r
- for (int i = 0; i < seqs.length; i++)\r
- {\r
- alignment.getHiddenSequences().hideSequence(seqs[i]);\r
- }\r
- firePropertyChange("alignment", null, alignment.getSequences());\r
- hasHiddenRows = true;\r
- setSelectionGroup(null);\r
- }\r
-\r
- public void hideSequence(SequenceI seq)\r
- {\r
- if(seq!=null)\r
- {\r
- alignment.getHiddenSequences().hideSequence(seq);\r
- hasHiddenRows = true;\r
- firePropertyChange("alignment", null, alignment.getSequences());\r
- }\r
- }\r
-\r
- public void showSequence(int index)\r
- {\r
- Vector tmp = alignment.getHiddenSequences().showSequence(index);\r
- if(tmp.size()>0)\r
- {\r
- if(selectionGroup==null)\r
- {\r
- selectionGroup = new SequenceGroup();\r
- selectionGroup.setEndRes(alignment.getWidth()-1);\r
- }\r
-\r
- for (int t = 0; t < tmp.size(); t++)\r
- {\r
- selectionGroup.addSequence(\r
- (SequenceI) tmp.elementAt(t), false\r
- );\r
- }\r
- firePropertyChange("alignment", null, alignment.getSequences());\r
- }\r
-\r
- if(alignment.getHiddenSequences().getSize()<1)\r
- hasHiddenRows = false;\r
- }\r
-\r
- public void showColumn(int col)\r
- {\r
- colSel.revealHiddenColumns(col);\r
- if(colSel.getHiddenColumns()==null)\r
- hasHiddenColumns = false;\r
- }\r
-\r
- public void showAllHiddenColumns()\r
- {\r
- colSel.revealAllHiddenColumns();\r
- hasHiddenColumns = false;\r
- }\r
-\r
- public void showAllHiddenSeqs()\r
- {\r
- if(alignment.getHiddenSequences().getSize()>0)\r
- {\r
- if(selectionGroup==null)\r
- {\r
- selectionGroup = new SequenceGroup();\r
- selectionGroup.setEndRes(alignment.getWidth()-1);\r
- }\r
- Vector tmp = alignment.getHiddenSequences().showAll();\r
- for(int t=0; t<tmp.size(); t++)\r
- {\r
- selectionGroup.addSequence(\r
- (SequenceI)tmp.elementAt(t), false\r
- );\r
- }\r
- firePropertyChange("alignment", null, alignment.getSequences());\r
- hasHiddenRows = false;\r
- }\r
- }\r
-\r
- public void invertColumnSelection()\r
- {\r
- int column;\r
- for(int i=0; i<alignment.getWidth(); i++)\r
- {\r
- column = i;\r
-\r
- if(colSel.contains(column))\r
- colSel.removeElement(column);\r
- else\r
- colSel.addElement(column);\r
-\r
- }\r
-\r
- }\r
-\r
- public int adjustForHiddenSeqs(int alignmentIndex)\r
- {\r
- return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);\r
- }\r
-\r
- /**\r
- * This method returns the a new SequenceI [] with\r
- * the selection sequence and start and end points adjusted\r
- * @return String[]\r
- */\r
- public SequenceI[] getSelectionAsNewSequence()\r
- {\r
- SequenceI[] sequences;\r
-\r
- if (selectionGroup == null)\r
- sequences = alignment.getSequencesArray();\r
- else\r
- sequences = selectionGroup.getSelectionAsNewSequences(alignment);\r
-\r
- return sequences;\r
- }\r
-\r
- /**\r
- * This method returns the visible alignment as text, as\r
- * seen on the GUI, ie if columns are hidden they will not\r
- * be returned in the result.\r
- * Use this for calculating trees, PCA, redundancy etc on views\r
- * which contain hidden columns.\r
- * @return String[]\r
- */\r
- public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)\r
- {\r
- CigarArray selection=null;\r
- SequenceI [] seqs= null;\r
- int i, iSize;\r
- int start = 0, end = 0;\r
- if(selectedRegionOnly && selectionGroup!=null)\r
- {\r
- iSize = selectionGroup.getSize(false);\r
- seqs = selectionGroup.getSequencesInOrder(alignment);\r
- start = selectionGroup.getStartRes();\r
- end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor\r
- }\r
- else\r
- {\r
- iSize = alignment.getHeight();\r
- seqs = alignment.getSequencesArray();\r
- end = alignment.getWidth()-1;\r
- }\r
- SeqCigar[] selseqs = new SeqCigar[iSize];\r
- for(i=0; i<iSize; i++)\r
- {\r
- selseqs[i] = new SeqCigar(seqs[i], start, end);\r
- }\r
- selection=new CigarArray(selseqs);\r
- // now construct the CigarArray operations\r
- if (hasHiddenColumns) {\r
- Vector regions = colSel.getHiddenColumns();\r
- int [] region;\r
- int hideStart, hideEnd;\r
- int last=start;\r
- for (int j = 0; last<end & j < regions.size(); j++)\r
- {\r
- region = (int[]) regions.elementAt(j);\r
- hideStart = region[0];\r
- hideEnd = region[1];\r
- // edit hidden regions to selection range\r
- if(hideStart<last) {\r
- if (hideEnd > last)\r
- {\r
- hideStart = last;\r
- } else\r
- continue;\r
- }\r
-\r
- if (hideStart>end)\r
- break;\r
-\r
- if (hideEnd>end)\r
- hideEnd=end;\r
-\r
- if (hideStart>hideEnd)\r
- break;\r
- /**\r
- * form operations...\r
- */\r
- if (last<hideStart)\r
- selection.addOperation(CigarArray.M, hideStart-last);\r
- selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);\r
- last = hideEnd+1;\r
- }\r
- // Final match if necessary.\r
- if (last<end)\r
- selection.addOperation(CigarArray.M, end-last);\r
- } else {\r
- selection.addOperation(CigarArray.M, end-start);\r
- }\r
- return selection;\r
- }\r
- /**\r
- * return a compact representation of the current alignment selection to\r
- * pass to an analysis function\r
- * @param selectedOnly boolean true to just return the selected view\r
- * @return AlignmentView\r
- */\r
- jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {\r
- // JBPNote:\r
- // this is here because the AlignmentView constructor modifies the CigarArray\r
- // object. Refactoring of Cigar and alignment view representation should\r
- // be done to remove redundancy.\r
- CigarArray aligview = getViewAsCigars(selectedOnly);\r
- if (aligview!=null)\r
- return new AlignmentView(aligview);\r
- return null;\r
- }\r
- /**\r
- * This method returns the visible alignment as text, as\r
- * seen on the GUI, ie if columns are hidden they will not\r
- * be returned in the result.\r
- * Use this for calculating trees, PCA, redundancy etc on views\r
- * which contain hidden columns.\r
- * @return String[]\r
- */\r
- public String [] getViewAsString(boolean selectedRegionOnly)\r
- {\r
- String [] selection = null;\r
- SequenceI [] seqs= null;\r
- int i, iSize;\r
- int start = 0, end = 0;\r
- if(selectedRegionOnly && selectionGroup!=null)\r
- {\r
- iSize = selectionGroup.getSize(false);\r
- seqs = selectionGroup.getSequencesInOrder(alignment);\r
- start = selectionGroup.getStartRes();\r
- end = selectionGroup.getEndRes()+1;\r
- }\r
- else\r
- {\r
- iSize = alignment.getHeight();\r
- seqs = alignment.getSequencesArray();\r
- end = alignment.getWidth();\r
- }\r
-\r
- selection = new String[iSize];\r
-\r
-\r
- for(i=0; i<iSize; i++)\r
- {\r
- if (hasHiddenColumns)\r
- {\r
- StringBuffer visibleSeq = new StringBuffer();\r
- Vector regions = colSel.getHiddenColumns();\r
-\r
- int blockStart = start, blockEnd=end;\r
- int [] region;\r
- int hideStart, hideEnd;\r
-\r
- for (int j = 0; j < regions.size(); j++)\r
- {\r
- region = (int[]) regions.elementAt(j);\r
- hideStart = region[0];\r
- hideEnd = region[1];\r
-\r
- if(hideStart < start)\r
- {\r
- continue;\r
- }\r
-\r
- blockStart = Math.min(blockStart, hideEnd+1);\r
- blockEnd = Math.min(blockEnd, hideStart);\r
-\r
- if(blockStart>blockEnd)\r
- {\r
- break;\r
- }\r
-\r
-\r
- visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));\r
-\r
- blockStart = hideEnd+1;\r
- blockEnd = end;\r
- }\r
-\r
- if(end>blockStart)\r
- visibleSeq.append(seqs[i].getSequence(blockStart, end));\r
-\r
- selection[i] = visibleSeq.toString();\r
- }\r
- else\r
- {\r
- selection[i] = seqs[i].getSequence(start, end);\r
- }\r
- }\r
-\r
- return selection;\r
- }\r
-\r
- public boolean getShowHiddenMarkers()\r
- {\r
- return showHiddenMarkers;\r
- }\r
-\r
- public void setShowHiddenMarkers(boolean show)\r
- {\r
- showHiddenMarkers = show;\r
- }\r
-}\r
+ /*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.gui;
+
+import jalview.analysis.*;
+
+import jalview.bin.*;
+
+import jalview.datamodel.*;
+
+import jalview.schemes.*;
+
+import java.awt.*;
+
+import java.util.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class AlignViewport
+{
+ int startRes;
+ int endRes;
+ int startSeq;
+ int endSeq;
+ boolean showJVSuffix = true;
+ boolean showText = true;
+ boolean showColourText = false;
+ boolean showBoxes = true;
+ boolean wrapAlignment = false;
+ boolean renderGaps = true;
+ boolean showSequenceFeatures = false;
+ boolean showAnnotation = true;
+ boolean showConservation = true;
+ boolean showQuality = true;
+ boolean showIdentity = true;
+ boolean colourAppliesToAllGroups = true;
+ ColourSchemeI globalColourScheme = null;
+ boolean conservationColourSelected = false;
+ boolean abovePIDThreshold = false;
+ SequenceGroup selectionGroup;
+ int charHeight;
+ int charWidth;
+ boolean validCharWidth;
+ int wrappedWidth;
+ Font font;
+ AlignmentI alignment;
+ ColumnSelection colSel = new ColumnSelection();
+ int threshold;
+ int increment;
+ NJTree currentTree = null;
+ boolean scaleAboveWrapped = false;
+ boolean scaleLeftWrapped = true;
+ boolean scaleRightWrapped = true;
+ boolean hasHiddenColumns = false;
+ boolean hasHiddenRows = false;
+ boolean showHiddenMarkers = true;
+
+ boolean cursorMode = false;
+
+ // The following vector holds the features which are
+ // currently visible, in the correct order or rendering
+ Hashtable featuresDisplayed = null;
+
+
+ /** DOCUMENT ME!! */
+ public Vector vconsensus;
+ AlignmentAnnotation consensus;
+ AlignmentAnnotation conservation;
+ AlignmentAnnotation quality;
+ boolean autoCalculateConsensus = true;
+
+ /** DOCUMENT ME!! */
+ public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
+
+ // JBPNote Prolly only need this in the applet version.
+ private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);
+
+ boolean ignoreGapsInConsensusCalculation = false;
+
+ boolean isDataset = false;
+
+ boolean antiAlias = false;
+
+ boolean padGaps = false;
+
+
+ public AlignViewport(AlignmentI al, boolean dataset)
+ {
+ isDataset = dataset;
+ setAlignment(al);
+ init();
+ }
+ /**
+ * Creates a new AlignViewport object.
+ *
+ * @param al DOCUMENT ME!
+ */
+ public AlignViewport(AlignmentI al)
+ {
+ setAlignment(al);
+ init();
+ }
+ /**
+ * Create a new AlignViewport with hidden regions
+ * @param al AlignmentI
+ * @param hiddenColumns ColumnSelection
+ */
+ public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) {
+ setAlignment(al);
+ if (hiddenColumns!=null) {
+ this.colSel = hiddenColumns;
+ if (hiddenColumns.getHiddenColumns() != null)
+ hasHiddenColumns = true;
+ }
+ init();
+ }
+
+ void init()
+ {
+ this.startRes = 0;
+ this.endRes = alignment.getWidth() - 1;
+ this.startSeq = 0;
+ this.endSeq = alignment.getHeight() - 1;
+
+ antiAlias = Cache.getDefault("ANTI_ALIAS", false);
+
+ showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
+ showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
+ showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
+
+ showQuality = Cache.getDefault("SHOW_QUALITY", true);
+ showIdentity = Cache.getDefault("SHOW_IDENTITY", true);
+
+ autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
+
+ padGaps = Cache.getDefault("PAD_GAPS", false);
+
+ String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
+ String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;
+ String fontSize = Cache.getDefault("FONT_SIZE", "10");
+
+ int style = 0;
+
+ if (fontStyle.equals("bold"))
+ {
+ style = 1;
+ }
+ else if (fontStyle.equals("italic"))
+ {
+ style = 2;
+ }
+
+ setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
+
+
+ alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );
+
+
+ // We must set conservation and consensus before setting colour,
+ // as Blosum and Clustal require this to be done
+ if(vconsensus==null && !isDataset)
+ {
+ updateConservation();
+ updateConsensus();
+ }
+
+ if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
+ {
+ globalColourScheme = ColourSchemeProperty.getColour(alignment,
+ jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
+
+ if (globalColourScheme instanceof UserColourScheme)
+ {
+ globalColourScheme = UserDefinedColours.loadDefaultColours();
+ ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());
+ }
+
+ if (globalColourScheme != null)
+ {
+ globalColourScheme.setConsensus(vconsensus);
+ }
+ }
+ }
+
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setShowSequenceFeatures(boolean b)
+ {
+ showSequenceFeatures = b;
+ }
+
+ public boolean getShowSequenceFeatures()
+ {
+ return showSequenceFeatures;
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void updateConservation()
+ {
+ if(alignment.isNucleotide())
+ return;
+
+ try{
+ Conservation cons = new jalview.analysis.Conservation("All",
+ jalview.schemes.ResidueProperties.propHash, 3,
+ alignment.getSequences(), 0, alignment.getWidth() - 1);
+ cons.calculate();
+ cons.verdict(false, ConsPercGaps);
+ cons.findQuality();
+
+ int alWidth = alignment.getWidth();
+ Annotation[] annotations = new Annotation[alWidth];
+ Annotation[] qannotations = new Annotation[alWidth];
+ String sequence = cons.getConsSequence().getSequence();
+ float minR;
+ float minG;
+ float minB;
+ float maxR;
+ float maxG;
+ float maxB;
+ minR = 0.3f;
+ minG = 0.0f;
+ minB = 0f;
+ maxR = 1.0f - minR;
+ maxG = 0.9f - minG;
+ maxB = 0f - minB; // scalable range for colouring both Conservation and Quality
+
+ float min = 0f;
+ float max = 11f;
+ float qmin = cons.qualityRange[0].floatValue();
+ float qmax = cons.qualityRange[1].floatValue();
+
+ for (int i = 0; i < alWidth; i++)
+ {
+ float value = 0;
+
+ try
+ {
+ value = Integer.parseInt(sequence.charAt(i) + "");
+ }
+ catch (Exception ex)
+ {
+ if (sequence.charAt(i) == '*')
+ {
+ value = 11;
+ }
+
+ if (sequence.charAt(i) == '+')
+ {
+ value = 10;
+ }
+ }
+
+ float vprop = value - min;
+ vprop /= max;
+ annotations[i] = new Annotation(sequence.charAt(i) + "",
+ String.valueOf(value), ' ', value,
+ new Color(minR + (maxR * vprop),
+ minG + (maxG * vprop),
+ minB + (maxB * vprop)));
+
+ // Quality calc
+ value = ( (Double) cons.quality.get(i)).floatValue();
+ vprop = value - qmin;
+ vprop /= qmax;
+ qannotations[i] = new Annotation(" ", String.valueOf(value), ' ',
+ value,
+ new Color(minR + (maxR * vprop),
+ minG + (maxG * vprop),
+ minB + (maxB * vprop)));
+ }
+
+ if (conservation == null)
+ {
+ conservation = new AlignmentAnnotation("Conservation",
+ "Conservation of total alignment less than " +
+ ConsPercGaps + "% gaps",
+ annotations, 0f, // cons.qualityRange[0].floatValue(),
+ 11f, // cons.qualityRange[1].floatValue()
+ AlignmentAnnotation.BAR_GRAPH);
+
+ if (showConservation)
+ {
+ alignment.addAnnotation(conservation);
+ }
+
+ quality = new AlignmentAnnotation("Quality",
+ "Alignment Quality based on Blosum62 scores",
+ qannotations,
+ cons.qualityRange[0].floatValue(),
+ cons.qualityRange[1].floatValue(),
+ AlignmentAnnotation.BAR_GRAPH);
+
+ if (showQuality)
+ {
+ alignment.addAnnotation(quality);
+ }
+ }
+ else
+ {
+ conservation.annotations = annotations;
+ quality.annotations = qannotations;
+ quality.graphMax = cons.qualityRange[1].floatValue();
+ }
+ }
+ catch (OutOfMemoryError error)
+ {
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Out of memory calculating conservation!!"
+ +
+ "\nSee help files for increasing Java Virtual Machine memory."
+ , "Out of memory",
+ javax.swing.JOptionPane.WARNING_MESSAGE);
+ }
+ });
+
+ System.out.println("Conservation calculation: " + error);
+ System.gc();
+
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ public void updateConsensus()
+ {
+ try{
+ Annotation[] annotations = new Annotation[alignment.getWidth()];
+
+ // this routine prevents vconsensus becoming a new object each time
+ // consenus is calculated. Important for speed of Blosum62
+ // and PID colouring of alignment
+ if (vconsensus == null)
+ {
+ vconsensus = alignment.getAAFrequency();
+ }
+ else
+ {
+ Vector temp = alignment.getAAFrequency();
+ vconsensus.clear();
+
+ Enumeration e = temp.elements();
+
+ while (e.hasMoreElements())
+ {
+ vconsensus.add(e.nextElement());
+ }
+ }
+
+ Hashtable hash = null;
+
+ for (int i = 0; i < alignment.getWidth(); i++)
+ {
+ hash = (Hashtable) vconsensus.elementAt(i);
+
+ float value = 0;
+ if (ignoreGapsInConsensusCalculation)
+ value = ( (Float) hash.get("pid_nogaps")).floatValue();
+ else
+ value = ( (Float) hash.get("pid_gaps")).floatValue();
+
+ String maxRes = hash.get("maxResidue").toString();
+ String mouseOver = hash.get("maxResidue") + " ";
+
+ if (maxRes.length() > 1)
+ {
+ mouseOver = "[" + maxRes + "] ";
+ maxRes = "+";
+ }
+
+ mouseOver += ( (int) value + "%");
+ annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);
+ }
+
+ if (consensus == null)
+ {
+ consensus = new AlignmentAnnotation("Consensus", "PID",
+ annotations, 0f, 100f,AlignmentAnnotation.BAR_GRAPH);
+
+ if (showIdentity)
+ {
+ alignment.addAnnotation(consensus);
+ }
+ }
+ else
+ {
+ consensus.annotations = annotations;
+ }
+
+ if (globalColourScheme != null)
+ globalColourScheme.setConsensus(vconsensus);
+
+ }catch(OutOfMemoryError error)
+ {
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Out of memory calculating consensus!!"
+ +
+ "\nSee help files for increasing Java Virtual Machine memory."
+ , "Out of memory",
+ javax.swing.JOptionPane.WARNING_MESSAGE);
+ }
+ });
+
+
+ System.out.println("Consensus calculation: " + error);
+ System.gc();
+ }
+
+ }
+ /**
+ * get the consensus sequence as displayed under the PID consensus annotation row.
+ * @return consensus sequence as a new sequence object
+ */
+ public SequenceI getConsensusSeq() {
+ if (consensus==null)
+ updateConsensus();
+ if (consensus==null)
+ return null;
+ StringBuffer seqs=new StringBuffer();
+ for (int i=0; i<consensus.annotations.length; i++) {
+ if (consensus.annotations[i]!=null) {
+ if (consensus.annotations[i].description.charAt(0) == '[')
+ seqs.append(consensus.annotations[i].description.charAt(1));
+ else
+ seqs.append(consensus.annotations[i].displayCharacter);
+ }
+ }
+ SequenceI sq = new Sequence("Consensus", seqs.toString());
+ sq.setDescription("Percentage Identity Consensus "+((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
+ return sq;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public SequenceGroup getSelectionGroup()
+ {
+ return selectionGroup;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param sg DOCUMENT ME!
+ */
+ public void setSelectionGroup(SequenceGroup sg)
+ {
+ selectionGroup = sg;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getConservationSelected()
+ {
+ return conservationColourSelected;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setConservationSelected(boolean b)
+ {
+ conservationColourSelected = b;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getAbovePIDThreshold()
+ {
+ return abovePIDThreshold;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setAbovePIDThreshold(boolean b)
+ {
+ abovePIDThreshold = b;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getStartRes()
+ {
+ return startRes;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getEndRes()
+ {
+ return endRes;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getStartSeq()
+ {
+ return startSeq;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param cs DOCUMENT ME!
+ */
+ public void setGlobalColourScheme(ColourSchemeI cs)
+ {
+ globalColourScheme = cs;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public ColourSchemeI getGlobalColourScheme()
+ {
+ return globalColourScheme;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param res DOCUMENT ME!
+ */
+ public void setStartRes(int res)
+ {
+ this.startRes = res;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param seq DOCUMENT ME!
+ */
+ public void setStartSeq(int seq)
+ {
+ this.startSeq = seq;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param res DOCUMENT ME!
+ */
+ public void setEndRes(int res)
+ {
+ if (res > (alignment.getWidth() - 1))
+ {
+ // log.System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1));
+ res = alignment.getWidth() - 1;
+ }
+
+ if (res < 0)
+ {
+ res = 0;
+ }
+
+ this.endRes = res;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param seq DOCUMENT ME!
+ */
+ public void setEndSeq(int seq)
+ {
+ if (seq > alignment.getHeight())
+ {
+ seq = alignment.getHeight();
+ }
+
+ if (seq < 0)
+ {
+ seq = 0;
+ }
+
+ this.endSeq = seq;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getEndSeq()
+ {
+ return endSeq;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param f DOCUMENT ME!
+ */
+ public void setFont(Font f)
+ {
+ font = f;
+
+ Container c = new Container();
+
+ java.awt.FontMetrics fm = c.getFontMetrics(font);
+ setCharHeight(fm.getHeight());
+ setCharWidth(fm.charWidth('M'));
+ validCharWidth = true;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Font getFont()
+ {
+ return font;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param w DOCUMENT ME!
+ */
+ public void setCharWidth(int w)
+ {
+ this.charWidth = w;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getCharWidth()
+ {
+ return charWidth;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param h DOCUMENT ME!
+ */
+ public void setCharHeight(int h)
+ {
+ this.charHeight = h;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getCharHeight()
+ {
+ return charHeight;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param w DOCUMENT ME!
+ */
+ public void setWrappedWidth(int w)
+ {
+ this.wrappedWidth = w;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getWrappedWidth()
+ {
+ return wrappedWidth;
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public AlignmentI getAlignment()
+ {
+ return alignment;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param align DOCUMENT ME!
+ */
+ public void setAlignment(AlignmentI align)
+ {
+ this.alignment = align;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setWrapAlignment(boolean state)
+ {
+ wrapAlignment = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setShowText(boolean state)
+ {
+ showText = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setRenderGaps(boolean state)
+ {
+ renderGaps = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getColourText()
+ {
+ return showColourText;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setColourText(boolean state)
+ {
+ showColourText = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param state DOCUMENT ME!
+ */
+ public void setShowBoxes(boolean state)
+ {
+ showBoxes = state;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getWrapAlignment()
+ {
+ return wrapAlignment;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getShowText()
+ {
+ return showText;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getShowBoxes()
+ {
+ return showBoxes;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public char getGapCharacter()
+ {
+ return getAlignment().getGapCharacter();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param gap DOCUMENT ME!
+ */
+ public void setGapCharacter(char gap)
+ {
+ if (getAlignment() != null)
+ {
+ getAlignment().setGapCharacter(gap);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param thresh DOCUMENT ME!
+ */
+ public void setThreshold(int thresh)
+ {
+ threshold = thresh;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getThreshold()
+ {
+ return threshold;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param inc DOCUMENT ME!
+ */
+ public void setIncrement(int inc)
+ {
+ increment = inc;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public int getIncrement()
+ {
+ return increment;
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public ColumnSelection getColumnSelection()
+ {
+ return colSel;
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param tree DOCUMENT ME!
+ */
+ public void setCurrentTree(NJTree tree)
+ {
+ currentTree = tree;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public NJTree getCurrentTree()
+ {
+ return currentTree;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setColourAppliesToAllGroups(boolean b)
+ {
+ colourAppliesToAllGroups = b;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getColourAppliesToAllGroups()
+ {
+ return colourAppliesToAllGroups;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getShowJVSuffix()
+ {
+ return showJVSuffix;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setShowJVSuffix(boolean b)
+ {
+ showJVSuffix = b;
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getShowAnnotation()
+ {
+ return showAnnotation;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setShowAnnotation(boolean b)
+ {
+ showAnnotation = b;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getScaleAboveWrapped()
+ {
+ return scaleAboveWrapped;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getScaleLeftWrapped()
+ {
+ return scaleLeftWrapped;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getScaleRightWrapped()
+ {
+ return scaleRightWrapped;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setScaleAboveWrapped(boolean b)
+ {
+ scaleAboveWrapped = b;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setScaleLeftWrapped(boolean b)
+ {
+ scaleLeftWrapped = b;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setScaleRightWrapped(boolean b)
+ {
+ scaleRightWrapped = b;
+ }
+
+ /**
+ * Property change listener for changes in alignment
+ *
+ * @param listener DOCUMENT ME!
+ */
+ public void addPropertyChangeListener(
+ java.beans.PropertyChangeListener listener)
+ {
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param listener DOCUMENT ME!
+ */
+ public void removePropertyChangeListener(
+ java.beans.PropertyChangeListener listener)
+ {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+
+ /**
+ * Property change listener for changes in alignment
+ *
+ * @param prop DOCUMENT ME!
+ * @param oldvalue DOCUMENT ME!
+ * @param newvalue DOCUMENT ME!
+ */
+ public void firePropertyChange(String prop, Object oldvalue, Object newvalue)
+ {
+ changeSupport.firePropertyChange(prop, oldvalue, newvalue);
+ }
+
+ public void setIgnoreGapsConsensus(boolean b)
+ {
+ ignoreGapsInConsensusCalculation = b;
+ updateConsensus();
+ if(globalColourScheme!=null)
+ {
+ globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);
+ }
+ }
+
+ public boolean getIgnoreGapsConsensus()
+ {
+ return ignoreGapsInConsensusCalculation;
+ }
+
+ public void setDataset(boolean b)
+ {
+ isDataset = b;
+ }
+
+ public boolean isDataset()
+ {
+ return isDataset;
+ }
+
+
+ public void hideSelectedColumns()
+ {
+ if (colSel.size() < 1)
+ return;
+
+ colSel.hideSelectedColumns();
+ setSelectionGroup(null);
+
+ hasHiddenColumns = true;
+ }
+
+
+ public void hideColumns(int start, int end)
+ {
+ if(start==end)
+ colSel.hideColumns(start);
+ else
+ colSel.hideColumns(start, end);
+
+ hasHiddenColumns = true;
+ }
+
+ public void hideAllSelectedSeqs()
+ {
+ if (selectionGroup == null)
+ return;
+
+ SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
+
+ for (int i = 0; i < seqs.length; i++)
+ {
+ alignment.getHiddenSequences().hideSequence(seqs[i]);
+ }
+ firePropertyChange("alignment", null, alignment.getSequences());
+ hasHiddenRows = true;
+ setSelectionGroup(null);
+ }
+
+ public void hideSequence(SequenceI seq)
+ {
+ if(seq!=null)
+ {
+ alignment.getHiddenSequences().hideSequence(seq);
+ hasHiddenRows = true;
+ firePropertyChange("alignment", null, alignment.getSequences());
+ }
+ }
+
+ public void showSequence(int index)
+ {
+ Vector tmp = alignment.getHiddenSequences().showSequence(index);
+ if(tmp.size()>0)
+ {
+ if(selectionGroup==null)
+ {
+ selectionGroup = new SequenceGroup();
+ selectionGroup.setEndRes(alignment.getWidth()-1);
+ }
+
+ for (int t = 0; t < tmp.size(); t++)
+ {
+ selectionGroup.addSequence(
+ (SequenceI) tmp.elementAt(t), false
+ );
+ }
+ firePropertyChange("alignment", null, alignment.getSequences());
+ }
+
+ if(alignment.getHiddenSequences().getSize()<1)
+ hasHiddenRows = false;
+ }
+
+ public void showColumn(int col)
+ {
+ colSel.revealHiddenColumns(col);
+ if(colSel.getHiddenColumns()==null)
+ hasHiddenColumns = false;
+ }
+
+ public void showAllHiddenColumns()
+ {
+ colSel.revealAllHiddenColumns();
+ hasHiddenColumns = false;
+ }
+
+ public void showAllHiddenSeqs()
+ {
+ if(alignment.getHiddenSequences().getSize()>0)
+ {
+ if(selectionGroup==null)
+ {
+ selectionGroup = new SequenceGroup();
+ selectionGroup.setEndRes(alignment.getWidth()-1);
+ }
+ Vector tmp = alignment.getHiddenSequences().showAll();
+ for(int t=0; t<tmp.size(); t++)
+ {
+ selectionGroup.addSequence(
+ (SequenceI)tmp.elementAt(t), false
+ );
+ }
+ firePropertyChange("alignment", null, alignment.getSequences());
+ hasHiddenRows = false;
+ }
+ }
+
+ public void invertColumnSelection()
+ {
+ int column;
+ for(int i=0; i<alignment.getWidth(); i++)
+ {
+ column = i;
+
+ if(colSel.contains(column))
+ colSel.removeElement(column);
+ else
+ colSel.addElement(column);
+
+ }
+
+ }
+
+ public int adjustForHiddenSeqs(int alignmentIndex)
+ {
+ return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
+ }
+
+ /**
+ * This method returns the a new SequenceI [] with
+ * the selection sequence and start and end points adjusted
+ * @return String[]
+ */
+ public SequenceI[] getSelectionAsNewSequence()
+ {
+ SequenceI[] sequences;
+
+ if (selectionGroup == null)
+ sequences = alignment.getSequencesArray();
+ else
+ sequences = selectionGroup.getSelectionAsNewSequences(alignment);
+
+ return sequences;
+ }
+
+ /**
+ * This method returns the visible alignment as text, as
+ * seen on the GUI, ie if columns are hidden they will not
+ * be returned in the result.
+ * Use this for calculating trees, PCA, redundancy etc on views
+ * which contain hidden columns.
+ * @return String[]
+ */
+ public jalview.datamodel.CigarArray getViewAsCigars(boolean selectedRegionOnly)
+ {
+ CigarArray selection=null;
+ SequenceI [] seqs= null;
+ int i, iSize;
+ int start = 0, end = 0;
+ if(selectedRegionOnly && selectionGroup!=null)
+ {
+ iSize = selectionGroup.getSize(false);
+ seqs = selectionGroup.getSequencesInOrder(alignment);
+ start = selectionGroup.getStartRes();
+ end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
+ }
+ else
+ {
+ iSize = alignment.getHeight();
+ seqs = alignment.getSequencesArray();
+ end = alignment.getWidth()-1;
+ }
+ SeqCigar[] selseqs = new SeqCigar[iSize];
+ for(i=0; i<iSize; i++)
+ {
+ selseqs[i] = new SeqCigar(seqs[i], start, end);
+ }
+ selection=new CigarArray(selseqs);
+ // now construct the CigarArray operations
+ if (hasHiddenColumns) {
+ Vector regions = colSel.getHiddenColumns();
+ int [] region;
+ int hideStart, hideEnd;
+ int last=start;
+ for (int j = 0; last<end & j < regions.size(); j++)
+ {
+ region = (int[]) regions.elementAt(j);
+ hideStart = region[0];
+ hideEnd = region[1];
+ // edit hidden regions to selection range
+ if(hideStart<last) {
+ if (hideEnd > last)
+ {
+ hideStart = last;
+ } else
+ continue;
+ }
+
+ if (hideStart>end)
+ break;
+
+ if (hideEnd>end)
+ hideEnd=end;
+
+ if (hideStart>hideEnd)
+ break;
+ /**
+ * form operations...
+ */
+ if (last<hideStart)
+ selection.addOperation(CigarArray.M, hideStart-last);
+ selection.addOperation(CigarArray.D, 1+hideEnd-hideStart);
+ last = hideEnd+1;
+ }
+ // Final match if necessary.
+ if (last<end)
+ selection.addOperation(CigarArray.M, end-last);
+ } else {
+ selection.addOperation(CigarArray.M, end-start);
+ }
+ return selection;
+ }
+ /**
+ * return a compact representation of the current alignment selection to
+ * pass to an analysis function
+ * @param selectedOnly boolean true to just return the selected view
+ * @return AlignmentView
+ */
+ jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly) {
+ // JBPNote:
+ // this is here because the AlignmentView constructor modifies the CigarArray
+ // object. Refactoring of Cigar and alignment view representation should
+ // be done to remove redundancy.
+ CigarArray aligview = getViewAsCigars(selectedOnly);
+ if (aligview!=null)
+ return new AlignmentView(aligview);
+ return null;
+ }
+ /**
+ * This method returns the visible alignment as text, as
+ * seen on the GUI, ie if columns are hidden they will not
+ * be returned in the result.
+ * Use this for calculating trees, PCA, redundancy etc on views
+ * which contain hidden columns.
+ * @return String[]
+ */
+ public String [] getViewAsString(boolean selectedRegionOnly)
+ {
+ String [] selection = null;
+ SequenceI [] seqs= null;
+ int i, iSize;
+ int start = 0, end = 0;
+ if(selectedRegionOnly && selectionGroup!=null)
+ {
+ iSize = selectionGroup.getSize(false);
+ seqs = selectionGroup.getSequencesInOrder(alignment);
+ start = selectionGroup.getStartRes();
+ end = selectionGroup.getEndRes()+1;
+ }
+ else
+ {
+ iSize = alignment.getHeight();
+ seqs = alignment.getSequencesArray();
+ end = alignment.getWidth();
+ }
+
+ selection = new String[iSize];
+ if (hasHiddenColumns) {
+ selection = colSel.getVisibleSequenceStrings(start, end, seqs);
+ } else {
+ for(i=0; i<iSize; i++)
+ {
+ selection[i] = seqs[i].getSequence(start, end);
+ }
+
+ }
+ return selection;
+ }
+
+ public boolean getShowHiddenMarkers()
+ {
+ return showHiddenMarkers;
+ }
+
+ public void setShowHiddenMarkers(boolean show)
+ {
+ showHiddenMarkers = show;
+ }
+}
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
- */\r
-package jalview.gui;\r
-\r
-import jalview.datamodel.*;\r
-\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-import java.awt.image.*;\r
-\r
-import javax.swing.*;\r
-\r
-\r
-/**\r
- * DOCUMENT ME!\r
- *\r
- * @author $author$\r
- * @version $Revision$\r
- */\r
-public class AnnotationLabels extends JPanel implements MouseListener,\r
- MouseMotionListener, ActionListener\r
-{\r
- static String ADDNEW = "Add New Row";\r
- static String HIDE = "Hide This Row";\r
- static String DELETE = "Delete This Row";\r
- static String SHOWALL = "Show All Hidden Rows";\r
- static String OUTPUT_TEXT = "Export Annotation";\r
- boolean resizePanel = false;\r
- Image image;\r
- AlignmentPanel ap;\r
- AlignViewport av;\r
- boolean resizing = false;\r
- MouseEvent dragEvent;\r
- int oldY;\r
- int selectedRow;\r
- int scrollOffset = 0;\r
- Font font = new Font("Arial", Font.PLAIN, 11);\r
-\r
-\r
- /**\r
- * Creates a new AnnotationLabels object.\r
- *\r
- * @param ap DOCUMENT ME!\r
- */\r
- public AnnotationLabels(AlignmentPanel ap)\r
- {\r
- this.ap = ap;\r
- av = ap.av;\r
-\r
- java.net.URL url = getClass().getResource("/images/idwidth.gif");\r
- Image temp = null;\r
-\r
- if (url != null)\r
- {\r
- temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);\r
- }\r
-\r
- try\r
- {\r
- MediaTracker mt = new MediaTracker(this);\r
- mt.addImage(temp, 0);\r
- mt.waitForID(0);\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
-\r
- BufferedImage bi = new BufferedImage(temp.getHeight(this),\r
- temp.getWidth(this), BufferedImage.TYPE_INT_RGB);\r
- Graphics2D g = (Graphics2D) bi.getGraphics();\r
- g.rotate(Math.toRadians(90));\r
- g.drawImage(temp, 0, -bi.getWidth(this), this);\r
- image = (Image) bi;\r
-\r
- addMouseListener(this);\r
- addMouseMotionListener(this);\r
- }\r
-\r
- public AnnotationLabels(AlignViewport av)\r
- {\r
- this.av = av;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param y DOCUMENT ME!\r
- */\r
- public void setScrollOffset(int y)\r
- {\r
- scrollOffset = y;\r
- repaint();\r
- }\r
-\r
- void getSelectedRow(int y)\r
- {\r
- int height = 0;\r
- AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
-\r
- if(aa!=null)\r
- {\r
- for (int i = 0; i < aa.length; i++)\r
- {\r
- if (!aa[i].visible)\r
- {\r
- continue;\r
- }\r
-\r
- height += aa[i].height;\r
-\r
- if (y < height)\r
- {\r
- selectedRow = i;\r
-\r
- break;\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void actionPerformed(ActionEvent evt)\r
- {\r
- int dif = 0;\r
- AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
-\r
- if (evt.getActionCommand().equals(ADDNEW))\r
- {\r
- String label = JOptionPane.showInputDialog(this,\r
- "Label for annotation");\r
-\r
- if (label == null)\r
- {\r
- label = "";\r
- }\r
-\r
- AlignmentAnnotation newAnnotation = new AlignmentAnnotation(label,\r
- "New description",\r
- new Annotation[ap.av.alignment.getWidth()]);\r
-\r
- ap.av.alignment.addAnnotation(newAnnotation);\r
- ap.av.alignment.setAnnotationIndex(newAnnotation, 0);\r
- if (aa != null)\r
- dif = aa[aa.length - 1].height;\r
- }\r
- else if (evt.getActionCommand().equals(HIDE))\r
- {\r
- aa[selectedRow].visible = false;\r
-\r
- if (aa[selectedRow].label.equals("Conservation"))\r
- {\r
- ap.av.showConservation = false;\r
- }\r
-\r
- if (aa[selectedRow].label.equals("Quality"))\r
- {\r
- ap.av.showQuality = false;\r
- }\r
-\r
- if (aa[selectedRow].label.equals("Consensus"))\r
- {\r
- ap.av.showIdentity = false;\r
- }\r
-\r
- dif = aa[selectedRow].height * -1;\r
- }\r
- else if (evt.getActionCommand().equals(DELETE))\r
- {\r
- ap.av.alignment.deleteAnnotation(aa[selectedRow]);\r
- dif = aa[selectedRow].height * -1;\r
- }\r
- else if (evt.getActionCommand().equals(SHOWALL))\r
- {\r
- for (int i = 0; i < aa.length; i++)\r
- {\r
- if (!aa[i].visible)\r
- {\r
- dif += aa[i].height;\r
- aa[i].visible = true;\r
- }\r
- }\r
- }\r
- else if (evt.getActionCommand().equals(OUTPUT_TEXT))\r
- {\r
- new AnnotationExporter().exportAnnotations(\r
- ap,\r
- new AlignmentAnnotation[]\r
- {aa[selectedRow]}\r
- );\r
- }\r
-\r
-\r
- ap.annotationPanel.adjustPanelHeight();\r
- ap.annotationScroller.validate();\r
- ap.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void mousePressed(MouseEvent evt)\r
- {\r
- getSelectedRow(evt.getY() - scrollOffset);\r
- oldY = evt.getY();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void mouseReleased(MouseEvent evt)\r
- {\r
- int start = selectedRow;\r
- getSelectedRow(evt.getY() - scrollOffset);\r
- int end = selectedRow;\r
-\r
- if(start!=end)\r
- {\r
- //Swap these annotations\r
- AlignmentAnnotation startAA = ap.av.alignment.getAlignmentAnnotation()[start];\r
- AlignmentAnnotation endAA = ap.av.alignment.getAlignmentAnnotation()[end];\r
-\r
-\r
- ap.av.alignment.getAlignmentAnnotation()[end] = startAA;\r
- ap.av.alignment.getAlignmentAnnotation()[start] = endAA;\r
- }\r
-\r
- resizePanel = false;\r
- dragEvent = null;\r
- repaint();\r
- ap.annotationPanel.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void mouseEntered(MouseEvent evt)\r
- {\r
- if(evt.getY()<10)\r
- {\r
- resizePanel = true;\r
- repaint();\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void mouseExited(MouseEvent evt)\r
- {\r
- if(dragEvent == null)\r
- {\r
- resizePanel = false;\r
- repaint();\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void mouseDragged(MouseEvent evt)\r
- {\r
- dragEvent = evt;\r
-\r
- if (resizePanel)\r
- {\r
- Dimension d = ap.annotationScroller.getPreferredSize();\r
- int dif = evt.getY() - oldY;\r
-\r
- dif /= ap.av.charHeight;\r
- dif *= ap.av.charHeight;\r
-\r
- if ( (d.height - dif) > 20)\r
- {\r
- ap.annotationScroller.setPreferredSize(new Dimension(d.width,\r
- d.height - dif));\r
- d = ap.annotationSpaceFillerHolder.getPreferredSize();\r
- ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(\r
- d.width, d.height - dif));\r
- ap.repaint();\r
- }\r
-\r
- ap.addNotify();\r
- }\r
- else\r
- repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void mouseMoved(MouseEvent evt)\r
- {\r
- resizePanel = evt.getY()<10;\r
-\r
- repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void mouseClicked(MouseEvent evt)\r
- {\r
- if(!SwingUtilities.isRightMouseButton(evt))\r
- return;\r
-\r
- AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
-\r
- if ((aa == null) || (aa.length == 0))\r
- {\r
- JPopupMenu pop = new JPopupMenu("Annotations");\r
- JMenuItem item = new JMenuItem(ADDNEW);\r
- item.addActionListener(this);\r
- pop.add(item);\r
- pop.show(this, evt.getX(), evt.getY());\r
-\r
- return;\r
- }\r
-\r
-\r
- JPopupMenu pop = new JPopupMenu("Annotations");\r
- JMenuItem item = new JMenuItem(ADDNEW);\r
- item.addActionListener(this);\r
- pop.add(item);\r
- item = new JMenuItem(HIDE);\r
- item.addActionListener(this);\r
- pop.add(item);\r
- item = new JMenuItem(DELETE);\r
- item.addActionListener(this);\r
- pop.add(item);\r
- item = new JMenuItem(SHOWALL);\r
- item.addActionListener(this);\r
- pop.add(item);\r
- item = new JMenuItem(OUTPUT_TEXT);\r
- item.addActionListener(this);\r
- pop.add(item);\r
-\r
- if (aa[selectedRow].label.equals("Consensus"))\r
- {\r
- pop.addSeparator();\r
- final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(\r
- "Ignore Gaps In Consensus",\r
- ap.av.getIgnoreGapsConsensus());\r
- cbmi.addActionListener(new ActionListener()\r
- {public void actionPerformed(ActionEvent e)\r
- {\r
- ap.av.setIgnoreGapsConsensus(cbmi.getState());\r
- ap.repaint();\r
- }\r
- });\r
- pop.add(cbmi);\r
-\r
- }\r
-\r
- pop.show(this, evt.getX(), evt.getY());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param g1 DOCUMENT ME!\r
- */\r
- public void paintComponent(Graphics g)\r
- {\r
-\r
- int width = getWidth();\r
- if(width==0)\r
- width = ap.calculateIdWidth().width + 4;\r
-\r
- Graphics2D g2 = (Graphics2D) g;\r
- if(av.antiAlias)\r
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
- RenderingHints.VALUE_ANTIALIAS_ON);\r
-\r
- drawComponent(g2, width);\r
-\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param g DOCUMENT ME!\r
- */\r
- public void drawComponent(Graphics g, int width)\r
- {\r
- if(av.getFont().getSize()<10)\r
- g.setFont(font);\r
- else\r
- g.setFont(av.getFont());\r
-\r
- FontMetrics fm = g.getFontMetrics(g.getFont());\r
- g.setColor(Color.white);\r
- g.fillRect(0, 0, getWidth(), getHeight());\r
-\r
- g.translate(0, scrollOffset);\r
- g.setColor(Color.black);\r
-\r
- AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
- int fontHeight = g.getFont().getSize();\r
- int y = fontHeight;\r
- int x = 0;\r
- int graphExtras = 0;\r
-\r
-\r
-\r
- if (aa != null)\r
- {\r
- for (int i = 0; i < aa.length; i++)\r
- {\r
- if (!aa[i].visible)\r
- {\r
- continue;\r
- }\r
-\r
- x = width - fm.stringWidth(aa[i].label) - 3;\r
-\r
- if (aa[i].graph>0 && aa[i].graphHeight>0)\r
- {\r
- graphExtras = y;\r
-\r
- y += (aa[i].height / 3);\r
-\r
- if(aa[i].graphGroup<0)\r
- graphExtras = y + fontHeight;\r
- }\r
-\r
- if(aa[i].graphGroup>-1)\r
- {\r
- int groupSize = 0;\r
- for (int gg = 0; gg < aa.length; gg++)\r
- {\r
- if (aa[gg].graphGroup == aa[i].graphGroup)\r
- groupSize++;\r
- }\r
-\r
- if(groupSize * (fontHeight+8) < aa[i].height)\r
- graphExtras += (aa[i].height -( groupSize * (fontHeight+8)) )/2;\r
-\r
- for(int gg=0; gg<aa.length; gg++)\r
- {\r
- if(aa[gg].graphGroup==aa[i].graphGroup)\r
- {\r
- x = width - fm.stringWidth(aa[gg].label) - 3;\r
- g.drawString(aa[gg].label, x, graphExtras );\r
- if(aa[gg].annotations[0]!=null)\r
- g.setColor(aa[gg].annotations[0].colour);\r
-\r
- g.drawLine( x, graphExtras+3,\r
- x+fm.stringWidth(aa[gg].label),\r
- graphExtras+3);\r
-\r
- g.setColor(Color.black);\r
- graphExtras += fontHeight+8;\r
- }\r
- }\r
- }\r
- else\r
- g.drawString(aa[i].label, x, y);\r
-\r
- if (aa[i].graph>0)\r
- {\r
- /* if (aa[i].graphLines != null)\r
- {\r
- for (int gl = 0; gl < aa[i].graphLines.size(); gl++)\r
- {\r
- x = width - fm.stringWidth(aa[i].getGraphLine(gl).label) - 3;\r
- g.drawString(aa[i].getGraphLine(gl).label, x, graphExtras);\r
- g.setColor(aa[i].getGraphLine(gl).colour);\r
- Graphics2D g2 = (Graphics2D) g;\r
- g2.setStroke(new BasicStroke(1,\r
- BasicStroke.CAP_SQUARE,\r
- BasicStroke.JOIN_ROUND, 3f,\r
- new float[]\r
- {5f, 3f}, 0f));\r
-\r
- graphExtras += 3;\r
-\r
- g.drawLine(x, graphExtras,\r
- x+fm.stringWidth(aa[i].label),\r
- graphExtras);\r
- g2.setStroke(new BasicStroke());\r
- }\r
- }*/\r
- y += ((2 * aa[i].height) / 3);\r
- }\r
- else\r
- {\r
- y += aa[i].height;\r
- }\r
- }\r
- }\r
-\r
- if (resizePanel)\r
- {\r
- g.drawImage(image, 2, 0 - scrollOffset, this);\r
- }\r
- else if (dragEvent != null && aa!=null)\r
- {\r
- g.setColor(Color.lightGray);\r
- g.drawString(aa[selectedRow].label, dragEvent.getX(), dragEvent.getY() - scrollOffset);\r
- }\r
-\r
-\r
- if ((aa == null) || (aa.length < 1))\r
- {\r
- g.drawString("Right click", 2, 8);\r
- g.drawString("to add annotation", 2, 18);\r
- }\r
- }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.gui;
+
+import jalview.datamodel.*;
+import jalview.io.FormatAdapter;
+
+import java.awt.*;
+import java.awt.datatransfer.StringSelection;
+import java.awt.event.*;
+import java.awt.image.*;
+import java.util.Vector;
+
+import javax.swing.*;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class AnnotationLabels extends JPanel implements MouseListener,
+ MouseMotionListener, ActionListener
+{
+ static String ADDNEW = "Add New Row";
+ static String HIDE = "Hide This Row";
+ static String DELETE = "Delete This Row";
+ static String SHOWALL = "Show All Hidden Rows";
+ static String OUTPUT_TEXT = "Export Annotation";
+ static String COPYCONS_SEQ = "Copy Consensus Sequence";
+ boolean resizePanel = false;
+ Image image;
+ AlignmentPanel ap;
+ AlignViewport av;
+ boolean resizing = false;
+ MouseEvent dragEvent;
+ int oldY;
+ int selectedRow;
+ int scrollOffset = 0;
+ Font font = new Font("Arial", Font.PLAIN, 11);
+
+
+ /**
+ * Creates a new AnnotationLabels object.
+ *
+ * @param ap DOCUMENT ME!
+ */
+ public AnnotationLabels(AlignmentPanel ap)
+ {
+ this.ap = ap;
+ av = ap.av;
+
+ java.net.URL url = getClass().getResource("/images/idwidth.gif");
+ Image temp = null;
+
+ if (url != null)
+ {
+ temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);
+ }
+
+ try
+ {
+ MediaTracker mt = new MediaTracker(this);
+ mt.addImage(temp, 0);
+ mt.waitForID(0);
+ }
+ catch (Exception ex)
+ {
+ }
+
+ BufferedImage bi = new BufferedImage(temp.getHeight(this),
+ temp.getWidth(this), BufferedImage.TYPE_INT_RGB);
+ Graphics2D g = (Graphics2D) bi.getGraphics();
+ g.rotate(Math.toRadians(90));
+ g.drawImage(temp, 0, -bi.getWidth(this), this);
+ image = (Image) bi;
+
+ addMouseListener(this);
+ addMouseMotionListener(this);
+ }
+
+ public AnnotationLabels(AlignViewport av)
+ {
+ this.av = av;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param y DOCUMENT ME!
+ */
+ public void setScrollOffset(int y)
+ {
+ scrollOffset = y;
+ repaint();
+ }
+
+ void getSelectedRow(int y)
+ {
+ int height = 0;
+ AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
+
+ if(aa!=null)
+ {
+ for (int i = 0; i < aa.length; i++)
+ {
+ if (!aa[i].visible)
+ {
+ continue;
+ }
+
+ height += aa[i].height;
+
+ if (y < height)
+ {
+ selectedRow = i;
+
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt DOCUMENT ME!
+ */
+ public void actionPerformed(ActionEvent evt)
+ {
+ int dif = 0;
+ AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
+
+ if (evt.getActionCommand().equals(ADDNEW))
+ {
+ String label = JOptionPane.showInputDialog(this,
+ "Label for annotation");
+
+ if (label == null)
+ {
+ label = "";
+ }
+
+ AlignmentAnnotation newAnnotation = new AlignmentAnnotation(label,
+ "New description",
+ new Annotation[ap.av.alignment.getWidth()]);
+
+ ap.av.alignment.addAnnotation(newAnnotation);
+ ap.av.alignment.setAnnotationIndex(newAnnotation, 0);
+ if (aa != null)
+ dif = aa[aa.length - 1].height;
+ }
+ else if (evt.getActionCommand().equals(HIDE))
+ {
+ aa[selectedRow].visible = false;
+
+ if (aa[selectedRow].label.equals("Conservation"))
+ {
+ ap.av.showConservation = false;
+ }
+
+ if (aa[selectedRow].label.equals("Quality"))
+ {
+ ap.av.showQuality = false;
+ }
+
+ if (aa[selectedRow].label.equals("Consensus"))
+ {
+ ap.av.showIdentity = false;
+ }
+
+ dif = aa[selectedRow].height * -1;
+ }
+ else if (evt.getActionCommand().equals(DELETE))
+ {
+ ap.av.alignment.deleteAnnotation(aa[selectedRow]);
+ dif = aa[selectedRow].height * -1;
+ }
+ else if (evt.getActionCommand().equals(SHOWALL))
+ {
+ for (int i = 0; i < aa.length; i++)
+ {
+ if (!aa[i].visible)
+ {
+ dif += aa[i].height;
+ aa[i].visible = true;
+ }
+ }
+ }
+ else if (evt.getActionCommand().equals(OUTPUT_TEXT))
+ {
+ new AnnotationExporter().exportAnnotations(
+ ap,
+ new AlignmentAnnotation[]
+ {aa[selectedRow]}
+ );
+ }
+ else if (evt.getActionCommand().equals(COPYCONS_SEQ))
+ {
+ SequenceI cons=av.getConsensusSeq();
+ if (cons!=null)
+ copy_annotseqtoclipboard(cons);
+
+ }
+
+ ap.annotationPanel.adjustPanelHeight();
+ ap.annotationScroller.validate();
+ ap.repaint();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt DOCUMENT ME!
+ */
+ public void mousePressed(MouseEvent evt)
+ {
+ getSelectedRow(evt.getY() - scrollOffset);
+ oldY = evt.getY();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt DOCUMENT ME!
+ */
+ public void mouseReleased(MouseEvent evt)
+ {
+ int start = selectedRow;
+ getSelectedRow(evt.getY() - scrollOffset);
+ int end = selectedRow;
+
+ if(start!=end)
+ {
+ //Swap these annotations
+ AlignmentAnnotation startAA = ap.av.alignment.getAlignmentAnnotation()[start];
+ AlignmentAnnotation endAA = ap.av.alignment.getAlignmentAnnotation()[end];
+
+
+ ap.av.alignment.getAlignmentAnnotation()[end] = startAA;
+ ap.av.alignment.getAlignmentAnnotation()[start] = endAA;
+ }
+
+ resizePanel = false;
+ dragEvent = null;
+ repaint();
+ ap.annotationPanel.repaint();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt DOCUMENT ME!
+ */
+ public void mouseEntered(MouseEvent evt)
+ {
+ if(evt.getY()<10)
+ {
+ resizePanel = true;
+ repaint();
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt DOCUMENT ME!
+ */
+ public void mouseExited(MouseEvent evt)
+ {
+ if(dragEvent == null)
+ {
+ resizePanel = false;
+ repaint();
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt DOCUMENT ME!
+ */
+ public void mouseDragged(MouseEvent evt)
+ {
+ dragEvent = evt;
+
+ if (resizePanel)
+ {
+ Dimension d = ap.annotationScroller.getPreferredSize();
+ int dif = evt.getY() - oldY;
+
+ dif /= ap.av.charHeight;
+ dif *= ap.av.charHeight;
+
+ if ( (d.height - dif) > 20)
+ {
+ ap.annotationScroller.setPreferredSize(new Dimension(d.width,
+ d.height - dif));
+ d = ap.annotationSpaceFillerHolder.getPreferredSize();
+ ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(
+ d.width, d.height - dif));
+ ap.repaint();
+ }
+
+ ap.addNotify();
+ }
+ else
+ repaint();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt DOCUMENT ME!
+ */
+ public void mouseMoved(MouseEvent evt)
+ {
+ resizePanel = evt.getY()<10;
+
+ repaint();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt DOCUMENT ME!
+ */
+ public void mouseClicked(MouseEvent evt)
+ {
+ if(!SwingUtilities.isRightMouseButton(evt))
+ return;
+
+ AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
+
+ if ((aa == null) || (aa.length == 0))
+ {
+ JPopupMenu pop = new JPopupMenu("Annotations");
+ JMenuItem item = new JMenuItem(ADDNEW);
+ item.addActionListener(this);
+ pop.add(item);
+ pop.show(this, evt.getX(), evt.getY());
+
+ return;
+ }
+
+
+ JPopupMenu pop = new JPopupMenu("Annotations");
+ JMenuItem item = new JMenuItem(ADDNEW);
+ item.addActionListener(this);
+ pop.add(item);
+ item = new JMenuItem(HIDE);
+ item.addActionListener(this);
+ pop.add(item);
+ item = new JMenuItem(DELETE);
+ item.addActionListener(this);
+ pop.add(item);
+ item = new JMenuItem(SHOWALL);
+ item.addActionListener(this);
+ pop.add(item);
+ item = new JMenuItem(OUTPUT_TEXT);
+ item.addActionListener(this);
+ pop.add(item);
+ // annotation object should be typed
+ if (aa[selectedRow].label.equals("Consensus"))
+ {
+ pop.addSeparator();
+ final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
+ "Ignore Gaps In Consensus",
+ ap.av.getIgnoreGapsConsensus());
+ cbmi.addActionListener(new ActionListener()
+ {public void actionPerformed(ActionEvent e)
+ {
+ ap.av.setIgnoreGapsConsensus(cbmi.getState());
+ ap.repaint();
+ }
+ });
+ pop.add(cbmi);
+ final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
+ consclipbrd.addActionListener(this);
+ pop.add(consclipbrd);
+ }
+
+ pop.show(this, evt.getX(), evt.getY());
+ }
+ /**
+ * do a single sequence copy to jalview and the system clipboard
+ *
+ * @param sq sequence to be copied to clipboard
+ */
+ protected void copy_annotseqtoclipboard(SequenceI sq)
+ {
+ SequenceI [] seqs = new SequenceI[] { sq };
+ String[] omitHidden = null;
+ SequenceI [] dseqs=new SequenceI[] { sq.getDatasetSequence()};
+ if (dseqs[0]==null) {
+ dseqs[0] = new Sequence(sq);
+ dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(jalview.util.Comparison.GapChars, sq.getSequence()));
+ sq.setDatasetSequence(dseqs[0]);
+ }
+ Alignment ds=new Alignment(dseqs);
+ if (av.hasHiddenColumns)
+ {
+ omitHidden = av.getColumnSelection().getVisibleSequenceStrings(0, sq.getLength(), seqs);
+ }
+
+ String output = new FormatAdapter().formatSequences(
+ "Fasta",
+ seqs,
+ omitHidden);
+
+
+ Toolkit.getDefaultToolkit().getSystemClipboard()
+ .setContents(new StringSelection(output), Desktop.instance);
+
+ Vector hiddenColumns = null;
+ if(av.hasHiddenColumns)
+ {
+ hiddenColumns =new Vector();
+ for(int i=0; i<av.getColumnSelection().getHiddenColumns().size(); i++)
+ {
+ int[] region = (int[])
+ av.getColumnSelection().getHiddenColumns().elementAt(i);
+
+ hiddenColumns.addElement(new int[]{region[0],
+ region[1]});
+ }
+ }
+
+ Desktop.jalviewClipboard = new Object[]{ seqs,
+ ds, // what is the dataset of a consensus sequence ? need to flag sequence as special.
+ hiddenColumns};
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param g1 DOCUMENT ME!
+ */
+ public void paintComponent(Graphics g)
+ {
+
+ int width = getWidth();
+ if(width==0)
+ width = ap.calculateIdWidth().width + 4;
+
+ Graphics2D g2 = (Graphics2D) g;
+ if(av.antiAlias)
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ drawComponent(g2, width);
+
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param g DOCUMENT ME!
+ */
+ public void drawComponent(Graphics g, int width)
+ {
+ if(av.getFont().getSize()<10)
+ g.setFont(font);
+ else
+ g.setFont(av.getFont());
+
+ FontMetrics fm = g.getFontMetrics(g.getFont());
+ g.setColor(Color.white);
+ g.fillRect(0, 0, getWidth(), getHeight());
+
+ g.translate(0, scrollOffset);
+ g.setColor(Color.black);
+
+ AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
+ int fontHeight = g.getFont().getSize();
+ int y = fontHeight;
+ int x = 0;
+ int graphExtras = 0;
+
+
+
+ if (aa != null)
+ {
+ for (int i = 0; i < aa.length; i++)
+ {
+ if (!aa[i].visible)
+ {
+ continue;
+ }
+
+ x = width - fm.stringWidth(aa[i].label) - 3;
+
+ if (aa[i].graph>0 && aa[i].graphHeight>0)
+ {
+ graphExtras = y;
+
+ y += (aa[i].height / 3);
+
+ if(aa[i].graphGroup<0)
+ graphExtras = y + fontHeight;
+ }
+
+ if(aa[i].graphGroup>-1)
+ {
+ int groupSize = 0;
+ for (int gg = 0; gg < aa.length; gg++)
+ {
+ if (aa[gg].graphGroup == aa[i].graphGroup)
+ groupSize++;
+ }
+
+ if(groupSize * (fontHeight+8) < aa[i].height)
+ graphExtras += (aa[i].height -( groupSize * (fontHeight+8)) )/2;
+
+ for(int gg=0; gg<aa.length; gg++)
+ {
+ if(aa[gg].graphGroup==aa[i].graphGroup)
+ {
+ x = width - fm.stringWidth(aa[gg].label) - 3;
+ g.drawString(aa[gg].label, x, graphExtras );
+ if(aa[gg].annotations[0]!=null)
+ g.setColor(aa[gg].annotations[0].colour);
+
+ g.drawLine( x, graphExtras+3,
+ x+fm.stringWidth(aa[gg].label),
+ graphExtras+3);
+
+ g.setColor(Color.black);
+ graphExtras += fontHeight+8;
+ }
+ }
+ }
+ else
+ g.drawString(aa[i].label, x, y);
+
+ if (aa[i].graph>0)
+ {
+ /* if (aa[i].graphLines != null)
+ {
+ for (int gl = 0; gl < aa[i].graphLines.size(); gl++)
+ {
+ x = width - fm.stringWidth(aa[i].getGraphLine(gl).label) - 3;
+ g.drawString(aa[i].getGraphLine(gl).label, x, graphExtras);
+ g.setColor(aa[i].getGraphLine(gl).colour);
+ Graphics2D g2 = (Graphics2D) g;
+ g2.setStroke(new BasicStroke(1,
+ BasicStroke.CAP_SQUARE,
+ BasicStroke.JOIN_ROUND, 3f,
+ new float[]
+ {5f, 3f}, 0f));
+
+ graphExtras += 3;
+
+ g.drawLine(x, graphExtras,
+ x+fm.stringWidth(aa[i].label),
+ graphExtras);
+ g2.setStroke(new BasicStroke());
+ }
+ }*/
+ y += ((2 * aa[i].height) / 3);
+ }
+ else
+ {
+ y += aa[i].height;
+ }
+ }
+ }
+
+ if (resizePanel)
+ {
+ g.drawImage(image, 2, 0 - scrollOffset, this);
+ }
+ else if (dragEvent != null && aa!=null)
+ {
+ g.setColor(Color.lightGray);
+ g.drawString(aa[selectedRow].label, dragEvent.getX(), dragEvent.getY() - scrollOffset);
+ }
+
+
+ if ((aa == null) || (aa.length < 1))
+ {
+ g.drawString("Right click", 2, 8);
+ g.drawString("to add annotation", 2, 18);
+ }
+ }
+}