diff --git a/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCFCompoundHeaderLine.java b/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCFCompoundHeaderLine.java index 6f9a8f5e6..667de3dea 100755 --- a/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCFCompoundHeaderLine.java +++ b/public/java/src/org/broadinstitute/sting/utils/codecs/vcf/VCFCompoundHeaderLine.java @@ -75,22 +75,24 @@ public abstract class VCFCompoundHeaderLine extends VCFHeaderLine implements VCF * If the count is a fixed count, return that. For example, a field with size of 1 in the header returns 1 * If the count is of type A, return vc.getNAlleles - 1 * If the count is of type G, return the expected number of genotypes given the number of alleles in VC and the - * max ploidy among all samples + * max ploidy among all samples. Note that if the max ploidy of the VC is 0 (there's no GT information + * at all, then implicitly assume diploid samples when computing G values. * If the count is UNBOUNDED return -1 * * @param vc * @return */ public int getCount(final VariantContext vc) { - int myCount; switch ( countType ) { - case INTEGER: myCount = count; break; - case UNBOUNDED: myCount = -1; break; - case A: myCount = vc.getNAlleles() - 1; break; - case G: myCount = GenotypeLikelihoods.numLikelihoods(vc.getNAlleles(), vc.getMaxPloidy()); break; - default: throw new ReviewedStingException("Unknown count type: " + countType); + case INTEGER: return count; + case UNBOUNDED: return -1; + case A: return vc.getNAlleles() - 1; + case G: + final int ploidy = vc.getMaxPloidy(); + return GenotypeLikelihoods.numLikelihoods(vc.getNAlleles(), ploidy == 0 ? 2 : ploidy); + default: + throw new ReviewedStingException("Unknown count type: " + countType); } - return myCount; } public void setNumberToUnbounded() { diff --git a/public/java/src/org/broadinstitute/sting/utils/variantcontext/GenotypeLikelihoods.java b/public/java/src/org/broadinstitute/sting/utils/variantcontext/GenotypeLikelihoods.java index bb4a5abb9..d644eda7d 100755 --- a/public/java/src/org/broadinstitute/sting/utils/variantcontext/GenotypeLikelihoods.java +++ b/public/java/src/org/broadinstitute/sting/utils/variantcontext/GenotypeLikelihoods.java @@ -363,13 +363,11 @@ public class GenotypeLikelihoods { * S(N,1) = N (only way to have N integers add up to 1 is all-zeros except one element with a one. There are N of these vectors) * S(1,P) = 1 (only way to have 1 integer add to P is with that integer P itself). * - * note that in the case where ploidy == 0 we assume that the ploidy actually == 2 - * * @param numAlleles Number of alleles (including ref) * @param ploidy Ploidy, or number of chromosomes in set * @return Number of likelihood elements we need to hold. */ - @Requires({"ploidy >= 0", "numAlleles > 0"}) + @Requires({"ploidy > 0", "numAlleles > 0"}) @Ensures("result > 0") public static int numLikelihoods(final int numAlleles, final int ploidy) { if ( numAlleles < NUM_LIKELIHOODS_CACHE_N_ALLELES