From 90925a374cc14797c3e353f30af938a2eec025a8 Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 14 Apr 2005 09:14:19 +0000 Subject: [PATCH] added quality calculation from Jalview118, and scale dependent colouring of conservation and quality histograms. Obvious for loop optimizations have also been applied. --- src/jalview/gui/AlignViewport.java | 73 ++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 3627020..5535dbb 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -77,55 +77,78 @@ public class AlignViewport AlignmentAnnotation consensus; AlignmentAnnotation conservation; + AlignmentAnnotation quality; + public void updateConservation() { - Annotation [] annotations = new Annotation[alignment.getWidth()]; - + int percGaps = 100; // JBPNote : This should be a scalable property! Conservation cons = new jalview.analysis.Conservation("All", - jalview.schemes.ResidueProperties.propHash, 3, + jalview.schemes.ResidueProperties.propHash, 1, alignment.getSequences(), 0, alignment.getWidth()); cons.calculate(); - cons.verdict(false, 100); + 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 = 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(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("Quality", - "Quality of total alignment", + conservation = new AlignmentAnnotation("Conservation", + "Conservation of total alignment less than "+percGaps+"% gaps", annotations, - cons.qualityRange[0].floatValue(), - cons.qualityRange[1].floatValue(), 1); + 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 + else { conservation.annotations = annotations; + quality.annotations = qannotations; + } + } @@ -135,7 +158,7 @@ public class AlignViewport Vector cons = alignment.getAAFrequency(); Hashtable hash = null; - for (int i = 0; i < alignment.getWidth(); i++) + for (int i = 0, alWidth=alignment.getWidth(); 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; -- 1.7.10.2