X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FResidueCount.java;h=4ca4c807e291ce5fbf9e3e10c737823b742c3bc9;hb=45d7b8f24253fa1c49977feedfe8a0f2f7cea85e;hp=612969f1cfbb62c9086c24f2d422bd327ec49d9d;hpb=28d2a0b7dde7f6751d9e063fc2e11da065d284a4;p=jalview.git diff --git a/src/jalview/datamodel/ResidueCount.java b/src/jalview/datamodel/ResidueCount.java index 612969f..4ca4c80 100644 --- a/src/jalview/datamodel/ResidueCount.java +++ b/src/jalview/datamodel/ResidueCount.java @@ -25,6 +25,8 @@ import jalview.util.Format; import jalview.util.QuickSort; import jalview.util.SparseCount; +import java.util.List; + /** * A class to count occurrences of residues in a profile, optimised for speed * and memory footprint. @@ -70,7 +72,7 @@ public class ResidueCount */ private static final String AAS = "ACDEFGHIKLMNPQRSTUVWXY"; - private static final int GAP_COUNT = 0; + static final int GAP_COUNT = 0; /* * fast lookup tables holding the index into our count @@ -148,6 +150,24 @@ public class ResidueCount } /** + * A constructor that counts frequency of all symbols (including gaps) in the + * sequences (not case-sensitive) + * + * @param sequences + */ + public ResidueCount(List sequences) + { + this(); + for (SequenceI seq : sequences) + { + for (int i = 0; i < seq.getLength(); i++) + { + add(seq.getCharAt(i)); + } + } + } + + /** * Increments the count for the given character. The supplied character may be * upper or lower case but counts are for the upper case only. Gap characters * (space, ., -) are all counted together. @@ -212,7 +232,12 @@ public class ResidueCount counts[offset] = (short) ++newValue; } } - maxCount = Math.max(maxCount, newValue); + + if (offset != GAP_COUNT) + { + // update modal residue count + maxCount = Math.max(maxCount, newValue); + } return newValue; } @@ -301,15 +326,7 @@ public class ResidueCount */ public int addGap() { - int newValue; - if (useIntCounts) - { - newValue = ++intCounts[GAP_COUNT]; - } - else - { - newValue = ++counts[GAP_COUNT]; - } + int newValue = increment(GAP_COUNT); return newValue; } @@ -641,15 +658,17 @@ public class ResidueCount return sb.toString(); } - public int getTotalCount() + /** + * Answers the total count for all symbols (excluding gaps) + * + * @return + */ + public int getTotalResidueCount() { int total = 0; for (char symbol : this.getSymbolCounts().symbols) { - if (!Comparison.isGap(symbol)) - { - total += getCount(symbol); - } + total += getCount(symbol); } return total; }