Java Code Examples for htsjdk.variant.variantcontext.Genotype#isHomVar()

The following examples show how to use htsjdk.variant.variantcontext.Genotype#isHomVar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VariantContextSingletonFilter.java    From Drop-seq with MIT License 6 votes vote down vote up
@Override
/**
 * For each variant context, look at the genotypes of the samples, and count the number of samples that have
 * an alternate allele.  If that number of samples!=1, return true to filter this record.
 * @param rec
 * @return
 */
public boolean filterOut(final VariantContext rec) {
	GenotypesContext gc = rec.getGenotypes();
	Iterator<Genotype> iter = gc.iterator();
	int count=0;
	while (iter.hasNext()) {
		Genotype g = iter.next();
		// boolean isHet = g.isHet();
		// boolean homRef = g.isHomRef();

		if (hetVarOnly & g.isHomVar())
			return true; // filter when het only and observe hom_var.
		if (g.isHet() || g.isHomVar())
			count++;
	}
	if (count==1) return false;
	return true;
}
 
Example 2
Source File: CallingMetricAccumulator.java    From picard with MIT License 6 votes vote down vote up
private void updateDetailMetric(final VariantCallingDetailMetrics metric,
                                final Genotype genotype,
                                final VariantContext vc,
                                final boolean hasSingletonSample) {
    updateSummaryMetric(metric, genotype, vc, hasSingletonSample);

    if (genotype != null && !vc.isFiltered()) {
        if (genotype.getGQ() == 0) {
            ++metric.TOTAL_GQ0_VARIANTS;
        }
        if (genotype.isHet()) {
            ++metric.numHets;
        } else if (genotype.isHomVar()) {
            ++metric.numHomVar;
        }
    }
}
 
Example 3
Source File: MendelianViolation.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Evaluate the genotypes of mom, dad, and child to detect Mendelian violations
 *
 * @param gMom
 * @param gDad
 * @param gChild
 * @return true if the three genotypes represent a Mendelian violation; false otherwise
 */
public static boolean isViolation(final Genotype gMom, final Genotype gDad, final Genotype gChild) {
    if (gChild.isNoCall()){ //cannot possibly be a violation is child is no call
        return false;
    }
    if(gMom.isHomRef() && gDad.isHomRef() && gChild.isHomRef()) {
        return false;
    }

    //1 parent is no "call
    if(!gMom.isCalled()){
        return (gDad.isHomRef() && gChild.isHomVar()) || (gDad.isHomVar() && gChild.isHomRef());
    }
    else if(!gDad.isCalled()){
        return (gMom.isHomRef() && gChild.isHomVar()) || (gMom.isHomVar() && gChild.isHomRef());
    }
    //Both parents have genotype information
    final Allele childRef = gChild.getAlleles().get(0);
    return !(gMom.getAlleles().contains(childRef) && gDad.getAlleles().contains(gChild.getAlleles().get(1)) ||
        gMom.getAlleles().contains(gChild.getAlleles().get(1)) && gDad.getAlleles().contains(childRef));
}
 
Example 4
Source File: FastaAlternateReferenceMaker.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the IUPAC encoding for the given genotype or the reference base if not possible
 *
 * @param genotype  the genotype to encode
 * @return non-null, non-empty String of bases
 */
private String getIUPACBase(final Genotype genotype) {
    Utils.nonNull(genotype, () -> "The genotype is null for sample " + iupacSample);

    // If we have a spanning deletion, if both alleles are spanning deletions, use the empty allele. Otherwise, use the allele that is not a
    // spanning deletion.
    if ( genotype.getAlleles().contains(Allele.SPAN_DEL) ) {
        if ( genotype.isHomVar() ) {
            return EMPTY_BASE;
        } else {
            return genotype.getAllele(0).equals(Allele.SPAN_DEL) ? genotype.getAllele(1).getBaseString() : genotype.getAllele(0).getBaseString();
        }
    }

    if ( !genotype.isHet() ) {
        return genotype.getAllele(0).getBaseString();
    }

    final byte allele1 = genotype.getAllele(0).getBases()[0];
    final byte allele2 = genotype.getAllele(1).getBases()[0];
    return new String(new byte[] {BaseUtils.basesToIUPAC(allele1, allele2)});
}
 
Example 5
Source File: AnnotateVcfWithExpectedAlleleFraction.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static double weight(final Genotype genotype) {
    if (genotype.isHomVar()) {
        return 1.0;
    } else if (genotype.isHet()) {
        return 0.5;
    } else {
        return 0.0;
    }
}
 
Example 6
Source File: AnnotateVcfWithExpectedAlleleFraction.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static double weight(final Genotype genotype) {
    if (genotype.isHomVar()) {
        return 1.0;
    } else if (genotype.isHet()) {
        return 0.5;
    } else {
        return 0.0;
    }
}
 
Example 7
Source File: QualByDepth.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static int getDepth(final GenotypesContext genotypes, final AlleleLikelihoods<GATKRead, Allele> likelihoods) {
    int depth = 0;
    int ADrestrictedDepth = 0;

    for ( final Genotype genotype : genotypes ) {
        // we care only about variant calls with likelihoods
        if ( !genotype.isHet() && !genotype.isHomVar() ) {
            continue;
        }

        // if we have the AD values for this sample, let's make sure that the variant depth is greater than 1!
        if ( genotype.hasAD() ) {
            final int[] AD = genotype.getAD();
            final int totalADdepth = (int) MathUtils.sum(AD);
            if ( totalADdepth != 0 ) {
                if (totalADdepth - AD[0] > 1) {
                    ADrestrictedDepth += totalADdepth;
                }
                depth += totalADdepth;
                continue;
            }
        }
        // if there is no AD value or it is a dummy value, we want to look to other means to get the depth
        if (likelihoods != null) {
            depth += likelihoods.sampleEvidenceCount(likelihoods.indexOfSample(genotype.getSampleName()));
        } else if ( genotype.hasDP() ) {
            depth += genotype.getDP();
        }
    }

    // if the AD-restricted depth is a usable value (i.e. not zero), then we should use that one going forward
    if ( ADrestrictedDepth > 0 ) {
        depth = ADrestrictedDepth;
    }
    return depth;
}
 
Example 8
Source File: ArraysCallingMetricAccumulator.java    From picard with MIT License 4 votes vote down vote up
private void updateDetailMetric(final CollectArraysVariantCallingMetrics.ArraysVariantCallingDetailMetrics metric,
                                final Genotype genotype,
                                final VariantContext vc,
                                final boolean hasSingletonSample) {
    metric.NUM_ASSAYS++;
    if (!vc.isFiltered() || vc.getCommonInfo().getFilters().contains(InfiniumVcfFields.DUPE)) {
        metric.NUM_NON_FILTERED_ASSAYS++;
        if (genotype.isCalled()) {
            metric.NUM_CALLS++;
            String gtA = (String) genotype.getExtendedAttribute(InfiniumVcfFields.GTA, genotype.getGenotypeString());
            if (!gtA.equals(VCFConstants.EMPTY_GENOTYPE)) {
                metric.NUM_AUTOCALL_CALLS++;
            }
        } else {
            metric.NUM_NO_CALLS++;
        }

        if (vc.isSNP()) {
            // Biallelic SNPs
            final boolean isInDbSnp = dbsnp.snps.isDbSnpSite(vc.getContig(), vc.getStart());

            metric.NUM_SNPS++;

            if (isInDbSnp) {
                metric.NUM_IN_DB_SNP++;
            }
        } else if (vc.isIndel()) {
            metric.NUM_INDELS++;
        }

        if (hasSingletonSample) {
            metric.NUM_SINGLETONS++;
        }

        if (genotype.isHet()) {
            metric.numHets++;
        } else if (genotype.isHomVar()) {
            metric.numHomVar++;
        }
    } else {
        metric.NUM_FILTERED_ASSAYS++;
        if (vc.getCommonInfo().getFilters().contains(InfiniumVcfFields.ZEROED_OUT_ASSAY)) {
            // A "zeroed-out SNP".  Marked as unusable/uncallable
            metric.NUM_ZEROED_OUT_ASSAYS++;
        }
    }
}