More BaseCounts optimizations for RR.

This commit is contained in:
Eric Banks 2012-10-17 00:55:44 -04:00
parent 19e2b5f0d5
commit 33df1afe0e
1 changed files with 3 additions and 13 deletions

View File

@ -167,13 +167,9 @@ import java.util.Map;
*/ */
@Ensures({"result >=0.0", "result<= 1.0"}) @Ensures({"result >=0.0", "result<= 1.0"})
public double baseCountProportion(final BaseIndex baseIndex) { public double baseCountProportion(final BaseIndex baseIndex) {
final int total = totalCount(); return (totalCount == 0) ? 0.0 : (double)counts.get(baseIndex) / (double)totalCount;
if (total == 0)
return 0.0;
return (double) counts.get(baseIndex) / total;
} }
@Ensures("result != null") @Ensures("result != null")
public String toString() { public String toString() {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
@ -239,11 +235,7 @@ import java.util.Map;
@Ensures("result >=0") @Ensures("result >=0")
public int totalCountWithoutIndels() { public int totalCountWithoutIndels() {
int sum = 0; return totalCount - counts.get(BaseIndex.D) - counts.get(BaseIndex.I);
for (Map.Entry<BaseIndex, Integer> entry : counts.entrySet())
if (entry.getKey().isNucleotide())
sum += entry.getValue();
return sum;
} }
/** /**
@ -256,9 +248,7 @@ import java.util.Map;
@Ensures({"result >=0.0", "result<= 1.0"}) @Ensures({"result >=0.0", "result<= 1.0"})
public double baseCountProportionWithoutIndels(final BaseIndex index) { public double baseCountProportionWithoutIndels(final BaseIndex index) {
final int total = totalCountWithoutIndels(); final int total = totalCountWithoutIndels();
if (total == 0) return (total == 0) ? 0.0 : (double)counts.get(index) / (double)total;
return 0.0;
return (double) counts.get(index) / total;
} }
public Object[] countsArray() { public Object[] countsArray() {