X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FComparison.java;fp=src%2Fjalview%2Futil%2FComparison.java;h=5605a53b111b5049444219d8127d32e52fad39c6;hb=99d5f1d805e530f23a53dad4484d44ecd0fbfdf3;hp=8902e2ce4433aa173361d2c36711af0afc0383c7;hpb=e6134bccddc2c7faad28fad1a4e77ccd0ceb3d84;p=jalview.git diff --git a/src/jalview/util/Comparison.java b/src/jalview/util/Comparison.java index 8902e2c..5605a53 100644 --- a/src/jalview/util/Comparison.java +++ b/src/jalview/util/Comparison.java @@ -286,7 +286,7 @@ public class Comparison * @param letters * @return */ - public static final boolean areNucleotide(char[][] letters) + static final boolean areNucleotide(char[][] letters) { int ntCount = 0; int aaCount = 0; @@ -300,16 +300,11 @@ public class Comparison // to save a lengthy calculation for (char c : seq) { - if ('a' <= c && c <= 'z') - { - c -= TO_UPPER_CASE; - } - - if (c == 'A' || c == 'G' || c == 'C' || c == 'T' || c == 'U') + if (isNucleotide(c)) { ntCount++; } - else if (!Comparison.isGap(c)) + else if (!isGap(c)) { aaCount++; } @@ -332,6 +327,59 @@ public class Comparison } /** + * Answers true if the character is one of aAcCgGtTuU + * + * @param c + * @return + */ + public static boolean isNucleotide(char c) + { + if ('a' <= c && c <= 'z') + { + c -= TO_UPPER_CASE; + } + + switch (c) + { + case 'A': + case 'C': + case 'G': + case 'T': + case 'U': + return true; + } + return false; + } + + /** + * Answers true if every character in the string is one of aAcCgGtTuU, or + * (optionally) a gap character (dot, dash, space), else false + * + * @param s + * @param allowGaps + * @return + */ + public static boolean isNucleotideSequence(String s, boolean allowGaps) + { + if (s == null) + { + return false; + } + for (int i = 0; i < s.length(); i++) + { + char c = s.charAt(i); + if (!isNucleotide(c)) + { + if (!allowGaps || !isGap(c)) + { + return false; + } + } + } + return true; + } + + /** * Convenience overload of isNucleotide * * @param seqs