X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=5535dbbaf3bbb5690e0dba43835e47134b7ebcfa;hb=90925a374cc14797c3e353f30af938a2eec025a8;hp=7719f024b8ed750bea0db1900adc0a288e46b416;hpb=f4e3be3ba13e6a575140983b46ac84e919184eee;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 7719f02..5535dbb 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1,7 +1,7 @@ package jalview.gui; import java.awt.*; -import jalview.io.*; +import jalview.analysis.*; import jalview.analysis.NJTree; import jalview.datamodel.*; import jalview.schemes.*; @@ -15,20 +15,21 @@ public class AlignViewport int startSeq; int endSeq; - boolean showScores=false; + 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 colourAppliesToAllGroups = true; ColourSchemeI globalColourScheme = null; boolean conservationColourSelected = false; boolean abovePIDThreshold = false; - SequenceGroup rubberbandGroup = null; + SequenceGroup selectionGroup = new SequenceGroup(); RendererI renderer = new SequenceRenderer(this); @@ -40,49 +41,32 @@ public class AlignViewport Font font = new Font("SansSerif",Font.PLAIN,10); AlignmentI alignment; - Selection sel = new Selection(this); ColumnSelection colSel = new ColumnSelection(); - String visibleConsensus; - int threshold; int increment; NJTree currentTree = null; + boolean scaleAboveWrapped = false; + boolean scaleLeftWrapped = true; + boolean scaleRightWrapped = true; - 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); - - 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 ); } @@ -91,41 +75,158 @@ public class AlignViewport showSequenceFeatures = b; } + AlignmentAnnotation consensus; + AlignmentAnnotation conservation; + AlignmentAnnotation quality; + + public void updateConservation() + { + int percGaps = 100; // JBPNote : This should be a scalable property! + Conservation cons = new jalview.analysis.Conservation("All", + jalview.schemes.ResidueProperties.propHash, 1, + alignment.getSequences(), 0, + alignment.getWidth()); + cons.calculate(); + cons.verdict(false, percGaps); + 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(sequence.charAt(i) + "", + new 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 "+percGaps+"% 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 void updateConsensus() + { + Annotation [] annotations = new Annotation[alignment.getWidth()]; + + Vector cons = alignment.getAAFrequency(); + Hashtable hash = null; + for (int i = 0, alWidth=alignment.getWidth(); 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; + + } + public String getVisibleConsensus() { return visibleConsensus; } - Vector consensus = new Vector(); + String visibleConsensus; + Vector consensusV = new Vector(); public Vector getConsensus(boolean recalculate) { - if(recalculate || consensus.size()<1) + if(recalculate || consensusV.size()<1) { - consensus = alignment.getAAFrequency(); + consensusV = alignment.getAAFrequency(); StringBuffer sb = new StringBuffer(); Hashtable hash = null; - for (int i = 0; i < consensus.size(); i++) + for (int i = 0, sz=consensusV.size(); i < sz; i++) { - hash = (Hashtable) consensus.elementAt(i); + hash = (Hashtable) consensusV.elementAt(i); sb.append(hash.get("maxResidue").toString().charAt(0)); } visibleConsensus = sb.toString(); } - return consensus; + return consensusV; } - public SequenceGroup getRubberbandGroup() + + public SequenceGroup getSelectionGroup() { - return rubberbandGroup; + return selectionGroup; } - public void setRubberbandGroup(SequenceGroup sg) + public void setSelectionGroup(SequenceGroup sg) { - rubberbandGroup = sg; + selectionGroup = sg; } + public boolean getConservationSelected() { return conservationColourSelected; @@ -178,7 +279,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; @@ -240,9 +341,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; } @@ -273,9 +372,7 @@ public class AlignViewport public void setShowBoxes(boolean state) { showBoxes = state; } - public boolean getShowScores() { - return showScores; - } + public boolean getWrapAlignment() { return wrapAlignment; } @@ -325,15 +422,12 @@ public class AlignViewport } return -1; } - public Selection getSelection() { - return sel; - } + public ColumnSelection getColumnSelection() { return colSel; } public void resetSeqLimits(int height) { - setStartSeq(0); setEndSeq(height/getCharHeight()); } public void setCurrentTree(NJTree tree) { @@ -357,5 +451,43 @@ public class AlignViewport public boolean getColourAppliesToAllGroups() {return colourAppliesToAllGroups; } + 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; } + }