X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=a7d433c2656f3977cc87f08a8f6bbbc49438ed0d;hb=0306c5b7a2aa4cc232ad0590a8ef285022eabd51;hp=43f6aff8aa90fc53922e5c2d479806102b5e7ac5;hpb=59a81cfb8e64c68d882182601663d82016f1a866;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 43f6aff..a7d433c 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -6,6 +6,7 @@ import jalview.analysis.NJTree; import jalview.datamodel.*; import jalview.schemes.*; import java.util.*; +import jalview.bin.Cache; public class AlignViewport { @@ -23,6 +24,9 @@ public class AlignViewport boolean renderGaps = true; boolean showSequenceFeatures = false; boolean showAnnotation = true; + boolean showConservation = true; + boolean showQuality = true; + boolean showIdentity = true; boolean colourAppliesToAllGroups = true; ColourSchemeI globalColourScheme = null; @@ -31,7 +35,6 @@ public class AlignViewport SequenceGroup selectionGroup = new SequenceGroup(); - RendererI renderer = new SequenceRenderer(this); int charHeight; int charWidth; @@ -48,22 +51,59 @@ public class AlignViewport NJTree currentTree = null; + boolean scaleAboveWrapped = false; + boolean scaleLeftWrapped = true; + boolean scaleRightWrapped = true; - public AlignViewport(AlignmentI al, - 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.showText = showText; - this.showBoxes = showBoxes; - this.wrapAlignment = wrapAlignment; - setAlignment(al); - setFont( font ); + updateFromPreferences(); + + } + + public void updateFromPreferences() + { + showFullId = Preferences.showFullId; + showAnnotation = Preferences.showAnnotation; + showConservation = Preferences.showConservation; + showQuality = Preferences.showQuality; + showIdentity = Preferences.showIdentity; + showFullId = Preferences.showFullId; + String fontName = Preferences.fontName; + String fontStyle = Preferences.fontStyle; + String fontSize = Cache.getProperty("FONT_SIZE"); + if (fontName != null && fontStyle != null && fontSize != null) + { + int style = 0; + if(fontStyle.equals("bold")) + style = 1; + else if(fontStyle.equals("italic")) + style = 2; + setFont(new Font(fontName, style, Integer.parseInt(fontSize))); + } + else + setFont(font); + + alignment.setGapCharacter(Preferences.gapSymbol); + + // We must set conservation and consensus before setting colour, + // as Blosum and Clustal require this to be done + updateConservation(); + updateConsensus(); + if(Preferences.defaultColour!=null) + { + globalColourScheme = ColourSchemeProperty.getColour(alignment, Preferences.defaultColour); + if(globalColourScheme!=null) + globalColourScheme.setConsensus( vconsensus ); + } + } public void showSequenceFeatures(boolean b) @@ -71,57 +111,85 @@ public class AlignViewport showSequenceFeatures = b; } + public Vector vconsensus; AlignmentAnnotation consensus; AlignmentAnnotation conservation; + AlignmentAnnotation quality; + + public int ConsPercGaps = 25; // JBPNote : This should be a scalable property! + public void updateConservation() { - Annotation [] annotations = new Annotation[alignment.getWidth()]; - Conservation cons = new jalview.analysis.Conservation("All", jalview.schemes.ResidueProperties.propHash, 3, alignment.getSequences(), 0, - alignment.getWidth()); + alignment.getWidth()-1); cons.calculate(); - cons.verdict(false, 100); + 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 = 0f; + minG = 0.0f; minB = 0f; - maxR = 1.0f-minR; maxG=0.9f-minG; maxB=0f-minB; // scalable range for colouring - float min = cons.qualityRange[0].floatValue(); - float max = cons.qualityRange[1].floatValue(); + 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 < alignment.getWidth(); i++) + for (int i = 0; i < alWidth; i++) { float value = 0; try - { - //value = Integer.parseInt(sequence.charAt(i) + ""); - value = ((Double) cons.quality.get(i)).floatValue(); - } + { + value = Integer.parseInt(sequence.charAt(i) + ""); + } catch (Exception ex) - { - if (sequence.charAt(i) == '*') value = 10; - } + { + 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, minB+maxB*vprop, minB+maxB*vprop)); + "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", + "Conservation of total alignment less than "+ConsPercGaps+"% gaps", annotations, - cons.qualityRange[0].floatValue(), - cons.qualityRange[1].floatValue(), 1); + 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 + else { conservation.annotations = annotations; + quality.annotations = qannotations; + quality.graphMax = cons.qualityRange[1].floatValue(); + } + } @@ -129,11 +197,25 @@ public class AlignViewport { Annotation [] annotations = new Annotation[alignment.getWidth()]; - Vector cons = alignment.getAAFrequency(); + // 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++) + for (int i = 0; i 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; @@ -324,11 +381,6 @@ public class AlignViewport public void setRenderGaps(boolean state){ renderGaps = state; - if(renderer instanceof SequenceRenderer) - { - SequenceRenderer sr = (SequenceRenderer)renderer; - sr.renderGaps(state); - } } @@ -410,14 +462,6 @@ public class AlignViewport return currentTree; } - public void setRenderer(RendererI rend) { - this.renderer = rend; - } - - public RendererI getRenderer() { - return renderer; - } - public void setColourAppliesToAllGroups(boolean b) { colourAppliesToAllGroups = b; } @@ -444,4 +488,23 @@ public class AlignViewport 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; } + + }