X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=7fd746127eacd37f5c314def3b16c276386a7a18;hb=e7ed63f1ea56432246a6ed1553f0fe56d26f56ea;hp=1324c1ecc40fe43c01619e902185787a41913333;hpb=1ecf6419aba86993b3c223bf5ec0fa79427baf85;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 1324c1e..7fd7461 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1,9 +1,10 @@ package jalview.gui; import java.awt.*; -import jalview.io.*; +import jalview.analysis.*; import jalview.analysis.NJTree; import jalview.datamodel.*; +import jalview.schemes.*; import java.util.*; public class AlignViewport @@ -14,118 +15,228 @@ public class AlignViewport int startSeq; int endSeq; - boolean showScores; - boolean showText; - boolean showColourText; - boolean showBoxes; - boolean wrapAlignment; + boolean showFullId = false; + boolean showText=true; + boolean showColourText=false; + boolean showBoxes=true; + boolean wrapAlignment=false; + boolean renderGaps = true; + boolean showSequenceFeatures = false; + boolean showAnnotation = true; - boolean groupEdit = false; + boolean colourAppliesToAllGroups = true; + ColourSchemeI globalColourScheme = null; + boolean conservationColourSelected = false; + boolean abovePIDThreshold = false; - RendererI renderer = new SequenceRenderer(); + SequenceGroup selectionGroup = new SequenceGroup(); + + RendererI renderer = new SequenceRenderer(this); int charHeight; - double charWidth; + int charWidth; int chunkWidth; int chunkHeight; - Color backgroundColour; - Font font = new Font("SansSerif",Font.PLAIN,10); AlignmentI alignment; - Selection sel = new Selection(); ColumnSelection colSel = new ColumnSelection(); - OutputGenerator og; - - String visibleConsensus; - int threshold; int increment; NJTree currentTree = null; - int window = 50; - int baseline = 30; - - Vector kmers; - - public AlignViewport(AlignmentI da, - boolean showScores, - boolean showText, - boolean showBoxes, - boolean wrapAlignment) { - this(0,da.getWidth()-1,0,da.getHeight()-1,showScores, - showText, - showBoxes, - wrapAlignment); + boolean scaleAboveWrapped = false; + boolean scaleLeftWrapped = true; + boolean scaleRightWrapped = true; - setAlignment(da); - } - public AlignViewport(int startRes, int endRes, - int startSeq, int endSeq, - boolean showScores, + public AlignViewport(AlignmentI al, boolean showText, boolean showBoxes, boolean wrapAlignment) { - this.startRes = startRes; - this.endRes = endRes; - this.startSeq = startSeq; - this.endSeq = endSeq; - - this.showScores = showScores; - this.showText = showText; - this.showBoxes = showBoxes; + this.startRes = 0; + this.endRes = al.getWidth()-1; + this.startSeq = 0; + this.endSeq = al.getHeight()-1; + this.showText = showText; + this.showBoxes = showBoxes; this.wrapAlignment = wrapAlignment; - // og = new AlignmentOutputGenerator(this); - + setAlignment(al); setFont( font ); } - public AlignViewport(int startRes, int endRes, - int startSeq, int endSeq, - boolean showScores, - boolean showText, - boolean showBoxes, - boolean wrapAlignment, - Color backgroundColour) { - this(startRes,endRes,startSeq,endSeq,showScores,showText,showBoxes,wrapAlignment); + public void showSequenceFeatures(boolean b) + { + showSequenceFeatures = b; + } - this.backgroundColour = backgroundColour; - } + public Vector vconsensus; + AlignmentAnnotation consensus; + AlignmentAnnotation conservation; + AlignmentAnnotation quality; + public int ConsPercGaps = 25; // JBPNote : This should be a scalable property! - public String getVisibleConsensus() + public void updateConservation() { - return visibleConsensus; - } + 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) + "", + "Conservation graph", ' ', 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)); + } - Vector consensus = new Vector(); + 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() + 1); + alignment.addAnnotation(conservation); + quality = new AlignmentAnnotation("Quality", + "Alignment Quality based on Blosum62 scores", + qannotations, + cons.qualityRange[0].floatValue(), + cons.qualityRange[1].floatValue(), + 1); + alignment.addAnnotation(quality); + } + else { + conservation.annotations = annotations; + quality.annotations = qannotations; + } - public Vector getConsensus(boolean recalculate) + + } + + public void updateConsensus() { - if(recalculate || consensus.size()<1) + 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 { - consensus = alignment.getAAFrequency(); - StringBuffer sb = new StringBuffer(); - Hashtable hash = null; - for (int i = 0; i < consensus.size(); i++) - { - hash = (Hashtable) consensus.elementAt(i); - sb.append(hash.get("maxResidue").toString().charAt(0)); - } - visibleConsensus = sb.toString(); + Vector temp = alignment.getAAFrequency(); + vconsensus.clear(); + Enumeration e = temp.elements(); + while(e.hasMoreElements()) + { + vconsensus.add(e.nextElement()); + } + } + Hashtable hash = null; + for (int i = 0; i2) + { + mouseOver = "["+maxRes+"] "; + maxRes = "+ "; + } + + mouseOver += (int)value+"%"; + annotations[i] = new Annotation(maxRes, mouseOver, ' ', value); + } + if(consensus==null) + { + consensus = new AlignmentAnnotation("% Identity", + "PID", annotations, 0f, 100f, 1); + alignment.addAnnotation(consensus); + } + else + consensus.annotations = annotations; - return consensus; } + 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; } @@ -138,6 +249,16 @@ public class AlignViewport return startSeq; } + public void setGlobalColourScheme(ColourSchemeI cs) + { + globalColourScheme = cs; + } + + public ColourSchemeI getGlobalColourScheme() + { + return globalColourScheme; + } + public void setStartRes(int res) { this.startRes = res; @@ -148,7 +269,7 @@ public class AlignViewport public void setEndRes(int res) { if (res > alignment.getWidth()-1) { System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1)); - res = alignment.getWidth() -1; + res = alignment.getWidth()-1; } if (res < 0) { res = 0; @@ -180,10 +301,10 @@ public class AlignViewport public Font getFont() { return font; } - public void setCharWidth(double w) { + public void setCharWidth(int w) { this.charWidth = w; } - public double getCharWidth() { + public int getCharWidth() { return charWidth; } public void setCharHeight(int h) { @@ -210,9 +331,7 @@ public class AlignViewport public void setAlignment(AlignmentI align) { this.alignment = align; } - public void setShowScores(boolean state) { - showScores = state; - } + public void setWrapAlignment(boolean state) { wrapAlignment = state; } @@ -220,6 +339,16 @@ public class AlignViewport showText = state; } + public void setRenderGaps(boolean state){ + renderGaps = state; + if(renderer instanceof SequenceRenderer) + { + SequenceRenderer sr = (SequenceRenderer)renderer; + sr.renderGaps(state); + } + } + + public boolean getColourText() { return showColourText; @@ -233,9 +362,7 @@ public class AlignViewport public void setShowBoxes(boolean state) { showBoxes = state; } - public boolean getShowScores() { - return showScores; - } + public boolean getWrapAlignment() { return wrapAlignment; } @@ -245,19 +372,11 @@ public class AlignViewport public boolean getShowBoxes() { return showBoxes; } - // public CommandParser getCommandLog() { - /// return log; - // } - public boolean getGroupEdit() { - return groupEdit; - } - public void setGroupEdit(boolean state) { - groupEdit = state; - } - public String getGapCharacter() { + + public char getGapCharacter() { return getAlignment().getGapCharacter(); } - public void setGapCharacter(String gap) { + public void setGapCharacter(char gap) { if (getAlignment() != null) { getAlignment().setGapCharacter(gap); } @@ -293,17 +412,12 @@ public class AlignViewport } return -1; } - public Selection getSelection() { - return sel; - } + public ColumnSelection getColumnSelection() { return colSel; } - public OutputGenerator getOutputGenerator() { - return og; - } + public void resetSeqLimits(int height) { - setStartSeq(0); setEndSeq(height/getCharHeight()); } public void setCurrentTree(NJTree tree) { @@ -320,27 +434,50 @@ public class AlignViewport public RendererI getRenderer() { return renderer; } - public int getPIDWindow() { - return window; - } - public void setPIDWindow(int window) { - this.window = window; - } - public int getPIDBaseline() { - return baseline; - } - public void setPIDBaseline(int baseline) { - this.baseline = baseline; - } + public void setColourAppliesToAllGroups(boolean b) + { colourAppliesToAllGroups = b; } - public void setKmers(Vector kmers) { - this.kmers = kmers; - } + public boolean getColourAppliesToAllGroups() + {return colourAppliesToAllGroups; } - public Vector getKmers() { - return this.kmers; - } + public boolean getShowFullId() + { + return showFullId; + } + + public void setShowFullId(boolean b) + { + showFullId = 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; } }