Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make HaplotypeCaller genotype and output spanning deletions #4963

Merged
merged 14 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ && noAllelesOrFirstAlleleIsNotNonRef(outputAlternativeAlleles.alleles)) {
return limitedContext ? null : estimateReferenceConfidence(vc, stratifiedContexts, AFpriors[INDEX_FOR_AC_EQUALS_1], true, probOfAtLeastOneAltAllele);
}

// return a null call if we aren't forcing site emission and the only alt allele is a spanning deletion
if (! forceSiteEmission()
&& outputAlternativeAlleles.alleles.size() == 1
&& Allele.SPAN_DEL.equals(outputAlternativeAlleles.alleles.get(0))) {
return null;
}

// start constructing the resulting VC
final List<Allele> outputAlleles = outputAlternativeAlleles.outputAlleles(vc.getReference());
final VariantContextBuilder builder = new VariantContextBuilder(callSourceString(), vc.getContig(), vc.getStart(), vc.getEnd(), outputAlleles);
Expand Down Expand Up @@ -508,8 +515,8 @@ protected final VariantCallContext emptyCallContext(final FeatureContext feature
VariantContext vc;

if ( configuration.genotypingOutputMode == GenotypingOutputMode.GENOTYPE_GIVEN_ALLELES ) {
final VariantContext ggaVc = GenotypingGivenAllelesUtils.composeGivenAllelesVariantContextFromRod(features,
rawContext.getLocation(), false, configuration.genotypeFilteredAlleles, logger, configuration.alleles);
final VariantContext ggaVc = GenotypingGivenAllelesUtils.composeGivenAllelesVariantContextFromVariantList(features,
rawContext.getLocation(), configuration.genotypeFilteredAlleles, configuration.alleles);
if (ggaVc == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,65 @@
package org.broadinstitute.hellbender.tools.walkers.genotyper;

import com.google.common.annotations.VisibleForTesting;
import htsjdk.samtools.util.Locatable;
import htsjdk.variant.variantcontext.VariantContext;
import org.apache.logging.log4j.Logger;
import org.broadinstitute.hellbender.engine.FeatureContext;
import org.broadinstitute.hellbender.engine.FeatureInput;
import org.broadinstitute.hellbender.utils.SimpleInterval;
import org.broadinstitute.hellbender.utils.Utils;
import org.broadinstitute.hellbender.utils.variant.GATKVariantContextUtils;

import java.util.List;
import java.util.stream.Collectors;

import static org.broadinstitute.hellbender.utils.variant.GATKVariantContextUtils.FilteredRecordMergeType.KEEP_IF_ANY_UNFILTERED;
import static org.broadinstitute.hellbender.utils.variant.GATKVariantContextUtils.FilteredRecordMergeType.KEEP_UNCONDITIONAL;

/**
* Compendium of utils to work in GENOTYPE_GIVEN_ALLELES mode.
*/
public final class GenotypingGivenAllelesUtils {

/**
* Composes the given allele variant-context providing information about the rods and reference location.
* Composes the given allele variant-context providing information about the given variant alleles and reference location.
* @param tracker the meta data tracker.
* @param loc the query location.
* @param snpsOnly whether we only should consider SNP variation.
* @param keepFiltered whether to include filtered variants
* @param logger where to output warnings.
* @param allelesBinding the target variation context binding containing the given alleles.
* @return never {@code null}
*/
public static VariantContext composeGivenAllelesVariantContextFromRod(final FeatureContext tracker,
final Locatable loc,
final boolean snpsOnly,
final boolean keepFiltered,
final Logger logger,
final FeatureInput<VariantContext> allelesBinding) {
public static VariantContext composeGivenAllelesVariantContextFromVariantList(final FeatureContext tracker,
final Locatable loc,
final boolean keepFiltered,
final FeatureInput<VariantContext> allelesBinding) {
Utils.nonNull(tracker, "tracker may not be null");
Utils.nonNull(loc, "location may not be null");
Utils.nonNull(allelesBinding, "alleles binding may not be null");
VariantContext vc = null;

// search for usable record
for ( final VariantContext rodVc : tracker.getValues(allelesBinding, new SimpleInterval(loc)) ) {
if ( rodVc != null && (keepFiltered || rodVc.isNotFiltered()) && (! snpsOnly || rodVc.isSNP() )) {
if ( vc == null ) {
vc = rodVc;
} else {
if (logger != null) {
logger.warn("Multiple valid VCF records detected in the alleles input file at site "
+ loc + ", only considering the first record");
}
}
}

final List<VariantContext> variantContextsInFeatureContext = tracker.getValues(allelesBinding, new SimpleInterval(loc));
return composeGivenAllelesVariantContextFromVariantList(variantContextsInFeatureContext, loc, keepFiltered);
}

@VisibleForTesting
protected static VariantContext composeGivenAllelesVariantContextFromVariantList(final List<VariantContext> variantContextsInFeatureContext,
final Locatable loc,
final boolean keepFiltered) {
final List<VariantContext> vcsAtLoc = variantContextsInFeatureContext
.stream()
.filter(vc -> vc.getStart() == loc.getStart() &&
(keepFiltered || vc.isNotFiltered()))
.collect(Collectors.toList());


if (vcsAtLoc.isEmpty()) {
return null;
}
final List<String> haplotypeSources = vcsAtLoc.stream().map(VariantContext::getSource).collect(Collectors.toList());
final VariantContext mergedVc = GATKVariantContextUtils.simpleMerge(vcsAtLoc, haplotypeSources,
keepFiltered ? KEEP_UNCONDITIONAL : KEEP_IF_ANY_UNFILTERED,
GATKVariantContextUtils.GenotypeMergeType.PRIORITIZE, false, false, null, false, false);

return vc;
return mergedVc;
}

}
Loading