* @param letters
* @return
*/
- public static final boolean areNucleotide(char[][] letters)
+ static final boolean areNucleotide(char[][] letters)
{
int ntCount = 0;
int aaCount = 0;
// 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++;
}
}
/**
+ * 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