X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FResidueCount.java;h=047b7e782a9780ab4dac81ad93203debfc4d83df;hb=daa1765ab2101480a724b92a3f3e7dee662ba943;hp=3e3a9666ddf2061e6d19e9f9fb30ca22b63136e2;hpb=5776cb3b3d74f3c3d3d791d56287d8d78e46b01b;p=jalview.git diff --git a/src/jalview/datamodel/ResidueCount.java b/src/jalview/datamodel/ResidueCount.java index 3e3a966..047b7e7 100644 --- a/src/jalview/datamodel/ResidueCount.java +++ b/src/jalview/datamodel/ResidueCount.java @@ -25,9 +25,12 @@ 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. + * * @author gmcarstairs * */ @@ -147,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. @@ -447,8 +468,8 @@ public class ResidueCount { if (intCounts[i] == count) { - modal.append(isNucleotide ? NUCS.charAt(i - 1) : AAS - .charAt(i - 1)); + modal.append( + isNucleotide ? NUCS.charAt(i - 1) : AAS.charAt(i - 1)); } } } @@ -458,8 +479,8 @@ public class ResidueCount { if (counts[i] == count) { - modal.append(isNucleotide ? NUCS.charAt(i - 1) : AAS - .charAt(i - 1)); + modal.append( + isNucleotide ? NUCS.charAt(i - 1) : AAS.charAt(i - 1)); } } } @@ -492,7 +513,8 @@ public class ResidueCount * * @return */ - public int size() { + public int size() + { int size = 0; if (useIntCounts) { @@ -546,8 +568,8 @@ public class ResidueCount { if (intCounts[i] > 0) { - char symbol = isNucleotide ? NUCS.charAt(i - 1) : AAS - .charAt(i - 1); + char symbol = isNucleotide ? NUCS.charAt(i - 1) + : AAS.charAt(i - 1); symbols[j] = symbol; values[j] = intCounts[i]; j++; @@ -560,8 +582,8 @@ public class ResidueCount { if (counts[i] > 0) { - char symbol = isNucleotide ? NUCS.charAt(i - 1) : AAS - .charAt(i - 1); + char symbol = isNucleotide ? NUCS.charAt(i - 1) + : AAS.charAt(i - 1); symbols[j] = symbol; values[j] = counts[i]; j++; @@ -638,4 +660,19 @@ public class ResidueCount sb.append("]"); return sb.toString(); } + + /** + * Answers the total count for all symbols (excluding gaps) + * + * @return + */ + public int getTotalResidueCount() + { + int total = 0; + for (char symbol : this.getSymbolCounts().symbols) + { + total += getCount(symbol); + } + return total; + } }