X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FAAFrequency.java;h=08a3f52c87492c3cc86d9424edc9ffb674fdc7ba;hb=6fb502e4a8749d1d98f5442c3b8156ab47996b77;hp=50b1b4b3bac0c06def14a0fd471a4fe17c535f6e;hpb=59d682209891099d46b960509907c79e3fb276fe;p=jalview.git diff --git a/src/jalview/analysis/AAFrequency.java b/src/jalview/analysis/AAFrequency.java index 50b1b4b..08a3f52 100755 --- a/src/jalview/analysis/AAFrequency.java +++ b/src/jalview/analysis/AAFrequency.java @@ -19,6 +19,7 @@ package jalview.analysis; import java.util.*; +import jalview.util.Format; import jalview.datamodel.*; /** @@ -90,7 +91,7 @@ public class AAFrequency Hashtable residueHash; int maxCount, nongap, i, j, v, jSize = sequences.length; String maxResidue; - char c; + char c='-'; float percentage; int[] values = new int[255]; @@ -104,7 +105,7 @@ public class AAFrequency maxResidue = ""; nongap = 0; values = new int[255]; - + for (j = 0; j < jSize; j++) { if (sequences[j] == null) @@ -142,8 +143,11 @@ public class AAFrequency values['-']++; } } - - for (v = 'A'; v < 'Z'; v++) + if (jSize==1) + { + maxResidue = String.valueOf(c); + maxCount=1; + } else {for (v = 'A'; v < 'Z'; v++) { if (values[v] < 2 || values[v] < maxCount) { @@ -160,7 +164,7 @@ public class AAFrequency } maxCount = values[v]; } - + } if (maxResidue.length() == 0) { maxResidue = "-"; @@ -177,8 +181,10 @@ public class AAFrequency percentage = ((float) maxCount * 100) / jSize; residueHash.put(PID_GAPS, new Float(percentage)); - percentage = ((float) maxCount * 100) / nongap; - residueHash.put(PID_NOGAPS, new Float(percentage)); + if (nongap>0) { + percentage = ((float) maxCount * 100) / nongap; + residueHash.put(PID_NOGAPS, new Float(percentage)); + } result[i] = residueHash; } } @@ -194,14 +200,15 @@ public class AAFrequency * @param width * @param ignoreGapsInConsensusCalculation * @param includeAllConsSymbols + * @param nseq */ public static void completeConsensus(AlignmentAnnotation consensus, Hashtable[] hconsensus, int iStart, int width, boolean ignoreGapsInConsensusCalculation, - boolean includeAllConsSymbols) + boolean includeAllConsSymbols, long nseq) { completeConsensus(consensus, hconsensus, iStart, width, - ignoreGapsInConsensusCalculation, includeAllConsSymbols, null); // new + ignoreGapsInConsensusCalculation, includeAllConsSymbols, null, nseq); // new // char[] // { 'A', 'C', 'G', 'T', 'U' }); } @@ -209,7 +216,7 @@ public class AAFrequency public static void completeConsensus(AlignmentAnnotation consensus, Hashtable[] hconsensus, int iStart, int width, boolean ignoreGapsInConsensusCalculation, - boolean includeAllConsSymbols, char[] alphabet) + boolean includeAllConsSymbols, char[] alphabet, long nseq) { float tval, value; if (consensus == null || consensus.annotations == null @@ -219,6 +226,23 @@ public class AAFrequency // initialised properly return; } + String fmtstr="%3.1f"; + int precision=0; + while (nseq>=10) { + precision++; + nseq/=10; + } + final Format fmt; + if (precision>1) + { + //if (precision>2) + { + fmtstr = "%"+(2+precision)+"."+(precision)+"f"; + } + fmt = new Format(fmtstr); + } else { + fmt = null; + } for (int i = iStart; i < width; i++) { Hashtable hci; @@ -229,7 +253,6 @@ public class AAFrequency consensus.annotations[i] = null; continue; } - value = 0; Float fv; if (ignoreGapsInConsensusCalculation) @@ -265,7 +288,7 @@ public class AAFrequency tval = profile[0][alphabet[c]] * 100f / profile[1][ignoreGapsInConsensusCalculation ? 1 : 0]; mouseOver += ((c == 0) ? "" : "; ") + alphabet[c] + " " - + ((int) tval) + "%"; + + ((fmt!=null) ? fmt.form(tval) : ((int) tval)) + "%"; } } else @@ -288,7 +311,7 @@ public class AAFrequency * 100f / profile[1][ignoreGapsInConsensusCalculation ? 1 : 0]; mouseOver += ((p == 0) ? "" : "; ") + ((char[]) ca[c])[0] - + " " + ((int) tval) + "%"; + + " " + ((fmt!=null) ? fmt.form(tval) : ((int) tval)) + "%"; p++; } @@ -298,7 +321,7 @@ public class AAFrequency } else { - mouseOver += ((int) value + "%"); + mouseOver += ((fmt!=null) ? fmt.form(value) : ((int) value)) + "%"; } consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ', value);