use of htsjdk.variant.variantcontext.VariantContext in project gatk by broadinstitute.
the class AnnotateVcfWithExpectedAlleleFractionIntegrationTest method test.
// run with made-up mixing fractions and the doctored 2-sample version of DREAM challenge sample 4
// described in {@link CalculateMixingFractionsIntegrationTest}
@Test
public void test() {
final File table = createTempFile("mixing", ".table");
final File outputVcf = createTempFile("output", ".vcf");
//as in the input vcf
final String sample1 = "SAMPLE1";
//as in the input vcf
final String sample2 = "SAMPLE2";
final double fraction1 = 0.4;
final double fraction2 = 0.6;
MixingFraction.writeMixingFractions(Arrays.asList(new MixingFraction(sample1, fraction1), new MixingFraction(sample2, fraction2)), table);
final String[] arguments = { "-" + StandardArgumentDefinitions.VARIANT_SHORT_NAME, INPUT_VCF.getAbsolutePath(), "-" + AnnotateVcfWithExpectedAlleleFraction.MIXING_FRACTIONS_TABLE_NAME, table.getAbsolutePath(), "-" + StandardArgumentDefinitions.OUTPUT_SHORT_NAME, outputVcf.getAbsolutePath() };
runCommandLine(arguments);
final List<VariantContext> input = StreamSupport.stream(new FeatureDataSource<VariantContext>(INPUT_VCF).spliterator(), false).collect(Collectors.toList());
final List<VariantContext> output = StreamSupport.stream(new FeatureDataSource<VariantContext>(outputVcf).spliterator(), false).collect(Collectors.toList());
Assert.assertEquals(input.size(), output.size());
final List<String> inputKeys = input.stream().map(vc -> keyForVariant(vc)).collect(Collectors.toList());
final List<String> outputKeys = output.stream().map(vc -> keyForVariant(vc)).collect(Collectors.toList());
Assert.assertEquals(inputKeys, outputKeys);
final List<Double> alleleFractions = output.stream().map(vc -> vc.getAttributeAsDouble(AnnotateVcfWithExpectedAlleleFraction.EXPECTED_ALLELE_FRACTION_NAME, -1)).collect(Collectors.toList());
// the first few -- 0.2 is sample1 is het, 0.3 is sample 2 is het, 0.5 if both are het
final List<Double> firstSeveralAlleleFractionsByHand = Arrays.asList(0.2, 0.2, 0.3, 0.2, 0.3, 0.5, 0.3, 0.2, 0.3, 0.3);
Assert.assertEquals(alleleFractions.subList(0, firstSeveralAlleleFractionsByHand.size()), firstSeveralAlleleFractionsByHand);
// hom var + het
Assert.assertEquals(alleleFractions.get(16), 0.7);
// het + hom var
Assert.assertEquals(alleleFractions.get(18), 0.8);
//both hom ref
Assert.assertEquals(alleleFractions.get(26), 0.0);
}
use of htsjdk.variant.variantcontext.VariantContext in project gatk by broadinstitute.
the class EventMapUnitTest method testBlockSubstitutionsData.
/**
* Example testng test using MyDataProvider
*/
@Test(dataProvider = "BlockSubstitutionsData")
public void testBlockSubstitutionsData(final String refBases, final String haplotypeBases, final String cigar, final VariantContext expectedBlock) {
final Haplotype hap = new Haplotype(haplotypeBases.getBytes(), false, 0, TextCigarCodec.decode(cigar));
final GenomeLoc loc = new UnvalidatingGenomeLoc(CHR, 0, 1, refBases.length());
final EventMap ee = new EventMap(hap, refBases.getBytes(), loc, NAME);
ee.replaceClumpedEventsWithBlockSubstitutions();
Assert.assertEquals(ee.getNumberOfEvents(), 1);
final VariantContext actual = ee.getVariantContexts().iterator().next();
Assert.assertTrue(GATKVariantContextUtils.equalSites(actual, expectedBlock), "Failed with " + actual);
}
use of htsjdk.variant.variantcontext.VariantContext in project gatk-protected by broadinstitute.
the class FilterByOrientationBias method apply.
/**
* Just adds the Pre Adapter Q annotation to the variant and creates a new variant.
*
* Note: the writing of the VCF is not done here, since we need to aggregate once we have OxoQ scores.
* Note: No variant is dropped, if no additional annotation was needed, then the original format field is
* preserved
* @param variant See {@link VariantWalker}
* @param readsContext See {@link VariantWalker}
* @param referenceContext See {@link VariantWalker}
* @param featureContext See {@link VariantWalker}
*/
@Override
public void apply(VariantContext variant, ReadsContext readsContext, ReferenceContext referenceContext, FeatureContext featureContext) {
final VariantContext updatedVariant = OrientationBiasFilterer.annotateVariantContextWithPreprocessingValues(variant, relevantTransitions, transitionToPreAdapterScoreMap);
firstPassVariants.add(updatedVariant);
// See onTraversalSuccess for the actual filtering.
}
use of htsjdk.variant.variantcontext.VariantContext in project gatk by broadinstitute.
the class FilterByOrientationBias method apply.
/**
* Just adds the Pre Adapter Q annotation to the variant and creates a new variant.
*
* Note: the writing of the VCF is not done here, since we need to aggregate once we have OxoQ scores.
* Note: No variant is dropped, if no additional annotation was needed, then the original format field is
* preserved
* @param variant See {@link VariantWalker}
* @param readsContext See {@link VariantWalker}
* @param referenceContext See {@link VariantWalker}
* @param featureContext See {@link VariantWalker}
*/
@Override
public void apply(VariantContext variant, ReadsContext readsContext, ReferenceContext referenceContext, FeatureContext featureContext) {
final VariantContext updatedVariant = OrientationBiasFilterer.annotateVariantContextWithPreprocessingValues(variant, relevantTransitions, transitionToPreAdapterScoreMap);
firstPassVariants.add(updatedVariant);
// See onTraversalSuccess for the actual filtering.
}
use of htsjdk.variant.variantcontext.VariantContext in project gatk by broadinstitute.
the class FilterByOrientationBias method onTraversalSuccess.
@Override
public Object onTraversalSuccess() {
logger.info("Tagging whether genotypes are in one of the artifact modes.");
// Calculate how many artifacts need to be cut
double fdrThreshold = 0.01;
final List<VariantContext> finalVariants = OrientationBiasFilterer.annotateVariantContextsWithFilterResults(fdrThreshold, relevantTransitions, firstPassVariants, transitionToPreAdapterScoreMap);
logger.info("Writing variants to VCF...");
finalVariants.forEach(vcfWriter::add);
logger.info("Writing a simple summary table...");
List<String> sampleNames = new ArrayList<>();
if (finalVariants.size() != 0) {
sampleNames = finalVariants.get(0).getSampleNamesOrderedByName();
}
final List<Pair<String, Transition>> sampleTransitionCombinations = new ArrayList<>();
for (Transition relevantTransition : relevantTransitions) {
for (String sampleName : sampleNames) {
sampleTransitionCombinations.add(Pair.of(sampleName, relevantTransition));
}
}
OrientationBiasUtils.writeOrientationBiasSummaryTable(sampleTransitionCombinations, finalVariants, transitionToPreAdapterScoreMap, new File(outputFile.getAbsolutePath() + SUMMARY_FILE_SUFFIX));
return null;
}
Aggregations