Special case the situation where we have ploidy == 0 (no GT values) to implicitly assume we have diploid samples

-- numLikelihoods no longer allows even ploidy == 0 in requires
-- VCFCompoundHeaderLine handles the case where ploidy == 0 => implicit ploidy == 2
This commit is contained in:
Mark DePristo 2012-06-28 10:04:15 -04:00
parent 064cc56335
commit 734bb5366b
2 changed files with 11 additions and 11 deletions

View File

@ -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() {

View File

@ -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