X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=a135620ea8c3c7353b57f7159470f665acfdd539;hb=ebb52a433edbbdbd31ab82cbb1c59fc116a72b1d;hp=2f40de403c9756b8725a98d87b9d83d07a32b8f8;hpb=577f505f54fe343e89f581461e780ea8308c20ec;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 2f40de4..a135620 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1,11 +1,12 @@ 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.*; +import jalview.bin.Cache; public class AlignViewport { @@ -15,13 +16,17 @@ 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 showConservation = true; + boolean showQuality = true; + boolean showIdentity = true; boolean colourAppliesToAllGroups = true; ColourSchemeI globalColourScheme = null; @@ -42,47 +47,77 @@ public class AlignViewport 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, - boolean showText, - boolean showBoxes, - boolean wrapAlignment) { + public AlignViewport(AlignmentI al) + { + setAlignment(al); + this.startRes = 0; + this.endRes = al.getWidth()-1; + this.startSeq = 0; + this.endSeq = al.getHeight()-1; - this.startRes = startRes; - this.endRes = endRes; - this.startSeq = startSeq; - this.endSeq = endSeq; + updateFromPreferences(); - this.showScores = showScores; - this.showText = showText; - this.showBoxes = showBoxes; - this.wrapAlignment = wrapAlignment; + } - // og = new AlignmentOutputGenerator(this); + public void updateFromPreferences() + { + String string = Cache.getProperty("SHOW_FULL_ID"); + if(string!=null) + showFullId = Boolean.valueOf(string).booleanValue(); + + string = Cache.getProperty("SHOW_ANNOTATIONS"); + if(string!=null) + showAnnotation = Boolean.valueOf(string).booleanValue(); + + string = Cache.getProperty("SHOW_CONSERVATION"); + if(string!=null) + showConservation = Boolean.valueOf(string).booleanValue(); + string = Cache.getProperty("SHOW_QUALITY"); + if(string!=null) + showQuality = Boolean.valueOf(string).booleanValue(); + string = Cache.getProperty("SHOW_IDENTITY"); + if(string!=null) + showIdentity = Boolean.valueOf(string).booleanValue(); + + string = Cache.getProperty("SHOW_FULL_ID"); + if(string!=null) + showFullId = Boolean.valueOf(string).booleanValue(); + + String fontName = Cache.getProperty("FONT_NAME"); + String fontStyle= Cache.getProperty("FONT_STYLE"); + String fontSize = Cache.getProperty("FONT_SIZE"); + if(fontName!=null && fontStyle!=null && fontSize!=null) + setFont( new Font(fontName,Integer.parseInt(fontStyle),Integer.parseInt(fontSize)) ); + else + setFont( font ); + + string = Cache.getProperty("GAP_SYMBOL"); + if(string!=null) + alignment.setGapCharacter( string.charAt(0) ); + + + // We must set conservation and consensus before setting colour, + // as Blosum and Clustal require this to be done + updateConservation(); + updateConsensus(); + string = Cache.getProperty("DEFAULT_COLOUR"); + if(string!=null) + { + globalColourScheme = ColourSchemeProperty.getColour(alignment, string); + if(globalColourScheme!=null) + globalColourScheme.setConsensus( vconsensus ); + } - setFont( font ); } public void showSequenceFeatures(boolean b) @@ -90,31 +125,141 @@ public class AlignViewport showSequenceFeatures = b; } - public String getVisibleConsensus() + public Vector vconsensus; + AlignmentAnnotation consensus; + AlignmentAnnotation conservation; + AlignmentAnnotation quality; + + public int ConsPercGaps = 25; // JBPNote : This should be a scalable property! + + 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)); + } + + 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); + if(showConservation) + alignment.addAnnotation(conservation); + quality = new AlignmentAnnotation("Quality", + "Alignment Quality based on Blosum62 scores", + qannotations, + cons.qualityRange[0].floatValue(), + cons.qualityRange[1].floatValue(), + 1); + if(showQuality) + alignment.addAnnotation(quality); + } + else { + conservation.annotations = annotations; + quality.annotations = qannotations; + quality.graphMax = cons.qualityRange[1].floatValue(); + } + + } - Vector consensus = new Vector(); - 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); + if(showIdentity) + alignment.addAnnotation(consensus); + } + else + consensus.annotations = annotations; - return consensus; } + public SequenceGroup getSelectionGroup() { return selectionGroup; @@ -178,7 +323,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 +385,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 +416,7 @@ public class AlignViewport public void setShowBoxes(boolean state) { showBoxes = state; } - public boolean getShowScores() { - return showScores; - } + public boolean getWrapAlignment() { return wrapAlignment; } @@ -331,7 +472,6 @@ public class AlignViewport } public void resetSeqLimits(int height) { - setStartSeq(0); setEndSeq(height/getCharHeight()); } public void setCurrentTree(NJTree tree) { @@ -355,5 +495,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; } + }