From: Jim Procter Date: Tue, 29 Sep 2020 14:26:34 +0000 (+0100) Subject: JAL-3760 refactor nucleotide proportion test to per-sequence and return false if... X-Git-Tag: Develop-2_11_2_0-d20201215~21 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4728b1bd60655ad9f269438e505e70f23c9c83f3;p=jalview.git JAL-3760 refactor nucleotide proportion test to per-sequence and return false if any sequence appears protein-like --- diff --git a/src/jalview/util/Comparison.java b/src/jalview/util/Comparison.java index d4fc233..286bfb2 100644 --- a/src/jalview/util/Comparison.java +++ b/src/jalview/util/Comparison.java @@ -268,7 +268,38 @@ public class Comparison */ public static final boolean isNucleotide(SequenceI seq) { - return isNucleotide(new SequenceI[] { seq }); + if (seq==null) + { + return false; + } + long ntCount = 0; + long aaCount = 0; + + int len = seq.getLength(); + for (int i = 0; i < len; i++) + { + char c = seq.getCharAt(i); + if (isNucleotide(c)) + { + ntCount++; + } + else if (!isGap(c)) + { + aaCount++; + } + } + /* + * Check for nucleotide count > 85% of total count (in a form that evades + * int / float conversion or divide by zero). + */ + if (ntCount * 100 > EIGHTY_FIVE * (ntCount + aaCount)) + { + return true; + } + else + { + return false; + } } /** @@ -285,45 +316,23 @@ public class Comparison { return false; } - - int ntCount = 0; - int aaCount = 0; + // true if we have seen a nucleotide sequence + boolean na=false; for (SequenceI seq : seqs) { if (seq == null) { continue; } + na=true; // TODO could possibly make an informed guess just from the first sequence // to save a lengthy calculation - int len = seq.getLength(); - for (int i = 0; i < len; i++) - { - char c = seq.getCharAt(i); - if (isNucleotide(c)) - { - ntCount++; - } - else if (!isGap(c)) - { - aaCount++; - } + if (seq.isProtein()) { + // if even one looks like protein, the alignment is protein + return false; } } - - /* - * Check for nucleotide count > 85% of total count (in a form that evades - * int / float conversion or divide by zero). - */ - if (ntCount * 100 > EIGHTY_FIVE * (ntCount + aaCount)) - { - return true; - } - else - { - return false; - } - + return na; } /**