*/
package jalview.util;
-import jalview.datamodel.SequenceI;
-
import java.util.ArrayList;
import java.util.List;
+import jalview.datamodel.SequenceI;
+
/**
* Assorted methods for analysing or comparing sequences.
*/
{
private static final int EIGHTY_FIVE = 85;
+ private static final int NINETY_NINE = 99;
+
private static final int TO_UPPER_CASE = 'a' - 'A';
public static final char GAP_SPACE = ' ';
*/
public static final boolean isGap(char c)
{
- return (c == GAP_DASH || c == GAP_DOT || c == GAP_SPACE) ? true : false;
+ return c == GAP_DASH || c == GAP_DOT || c == GAP_SPACE;
}
/**
long ntCount = 0;
long aaCount = 0;
long nCount = 0;
+ long ntaCount = 0;
int len = seq.getLength();
for (int i = 0; i < len; i++)
{
char c = seq.getCharAt(i);
- if (isNucleotide(c) || isX(c))
+ if (isNucleotide(c))
{
ntCount++;
}
{
nCount++;
}
+ else
+ {
+ if (isNucleotideAmbiguity(c))
+ {
+ ntaCount++;
+ }
+ }
}
}
/*
}
else
{
+ // check for very large proportion of nucleotide and all ambiguity codes
+ if ((ntCount + nCount + ntaCount) * 100 >= NINETY_NINE
+ * (ntCount + aaCount))
+ {
+ return ntCount > 0;
+ }
return false;
}
}
*/
public static boolean isNucleotide(char c)
{
- if ('a' <= c && c <= 'z')
- {
- c -= TO_UPPER_CASE;
- }
- switch (c)
+ return isNucleotide(c, false);
+ }
+
+ public static boolean isNucleotide(char c, boolean countAmbiguity)
+ {
+ char C = Character.toUpperCase(c);
+ switch (C)
{
case 'A':
case 'C':
case 'U':
return true;
}
+ if (countAmbiguity)
+ {
+ boolean ambiguity = isNucleotideAmbiguity(C);
+ if (ambiguity)
+ return true;
+ }
return false;
}
- public static boolean isN(char c)
+ public static boolean isNucleotideAmbiguity(char c)
{
- switch (c)
+ switch (Character.toUpperCase(c))
{
- case 'N':
- case 'n':
+ case 'I':
+ case 'X':
+ case 'R':
+ case 'Y':
+ case 'W':
+ case 'S':
+ case 'M':
+ case 'K':
+ case 'B':
+ case 'H':
+ case 'D':
+ case 'V':
return true;
+ case 'N': // not counting N as nucleotide
}
return false;
}
+ public static boolean isN(char c)
+ {
+ return 'n' == Character.toLowerCase(c);
+ }
+
public static boolean isX(char c)
{
- switch (c)
- {
- case 'X':
- case 'x':
- return true;
- }
- return false;
+ return 'x' == Character.toLowerCase(c);
}
/**
public static boolean isSameResidue(char c1, char c2,
boolean caseSensitive)
{
- if (caseSensitive)
- {
- return (c1 == c2);
- }
- else
- {
- return Character.toUpperCase(c1) == Character.toUpperCase(c2);
- }
+ return caseSensitive ? c1 == c2
+ : Character.toUpperCase(c1) == Character.toUpperCase(c2);
}
}