Search in sources :

Example 1 with MixingFraction

use of org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction in project gatk-protected 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);
}
Also used : Arrays(java.util.Arrays) StandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) Collectors(java.util.stream.Collectors) File(java.io.File) AnnotateVcfWithExpectedAlleleFraction(org.broadinstitute.hellbender.tools.walkers.validation.AnnotateVcfWithExpectedAlleleFraction) List(java.util.List) MixingFraction(org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction) Assert(org.testng.Assert) FeatureDataSource(org.broadinstitute.hellbender.engine.FeatureDataSource) VariantContext(htsjdk.variant.variantcontext.VariantContext) StreamSupport(java.util.stream.StreamSupport) VariantContext(htsjdk.variant.variantcontext.VariantContext) File(java.io.File) MixingFraction(org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 2 with MixingFraction

use of org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction in project gatk-protected by broadinstitute.

the class CalculateMixingFractionsIntegrationTest method test.

/**
     * The DREAM challenge 4th sample simulates a tumor with subclonal populations of 50% and 35%.  We pretend
     * here that it is actually a mixture of two samples, and we doctored the corresponding such that every variant with allele fraction
     * of roughly 50%/2 = 25% is a het from one sample and every variant with allele fraction roughly 35%/2 is a het from the other
     * sample.  Therefore, the unnormalized mixing fractions should come out to about 0.5 and 0.35, and the normalized fractions
     * should be roughly 0.59 and 0.41.
     *
     * However, when you actually check in IGV, variants cluster into allele fractions of roughly 10% and roughly 25%, which yields
     * normalized mixing fractions of about 30% and 70%, as we in fact obtain.
     */
@Test
public void test() {
    final File outputTable = createTempFile("mixing", ".table");
    final String[] arguments = { "-" + StandardArgumentDefinitions.VARIANT_SHORT_NAME, INPUT_VCF.getAbsolutePath(), "-" + StandardArgumentDefinitions.INPUT_SHORT_NAME, INPUT_BAM.getAbsolutePath(), "-" + StandardArgumentDefinitions.OUTPUT_SHORT_NAME, outputTable.getAbsolutePath() };
    runCommandLine(arguments);
    final List<MixingFraction> mixing = MixingFraction.readMixingFractions(outputTable);
    final Map<String, Double> result = mixing.stream().collect(Collectors.toMap(MixingFraction::getSample, MixingFraction::getMixingFraction));
    Assert.assertEquals(result.get("SAMPLE1"), 0.31, 0.02);
    Assert.assertEquals(result.get("SAMPLE2"), 0.69, 0.02);
}
Also used : File(java.io.File) MixingFraction(org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 3 with MixingFraction

use of org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction in project gatk-protected by broadinstitute.

the class MixingFractionUnitTest method testMixingfraction.

@Test
public void testMixingfraction() {
    final String sample = "SAMPLE";
    final double fraction = 0.15;
    final MixingFraction mixingFraction = new MixingFraction(sample, fraction);
    Assert.assertEquals(mixingFraction.getSample(), sample);
    Assert.assertEquals(mixingFraction.getMixingFraction(), fraction);
}
Also used : MixingFraction(org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction) Test(org.testng.annotations.Test)

Example 4 with MixingFraction

use of org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction in project gatk by broadinstitute.

the class MixingFractionUnitTest method testMixingfraction.

@Test
public void testMixingfraction() {
    final String sample = "SAMPLE";
    final double fraction = 0.15;
    final MixingFraction mixingFraction = new MixingFraction(sample, fraction);
    Assert.assertEquals(mixingFraction.getSample(), sample);
    Assert.assertEquals(mixingFraction.getMixingFraction(), fraction);
}
Also used : MixingFraction(org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction) Test(org.testng.annotations.Test)

Example 5 with MixingFraction

use of org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction in project gatk by broadinstitute.

the class MixingFractionUnitTest method testIO.

@Test
public void testIO() throws IOException {
    Utils.resetRandomGenerator();
    final File file = File.createTempFile("mixing_fractions", ".table");
    final String sample1 = "SAMPLE1";
    final double fraction1 = 0.15;
    final String sample2 = "SAMPLE2";
    final double fraction2 = 0.17;
    final List<MixingFraction> original = Arrays.asList(new MixingFraction(sample1, fraction1), new MixingFraction(sample2, fraction2));
    MixingFraction.writeMixingFractions(original, file);
    final List<MixingFraction> copy = MixingFraction.readMixingFractions(file);
    Assert.assertEquals(original.size(), copy.size());
    new IndexRange(0, original.size()).forEach(n -> {
        Assert.assertEquals(original.get(n).getSample(), copy.get(n).getSample());
        Assert.assertEquals(original.get(n).getMixingFraction(), copy.get(n).getMixingFraction());
    });
}
Also used : IndexRange(org.broadinstitute.hellbender.utils.IndexRange) File(java.io.File) MixingFraction(org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction) Test(org.testng.annotations.Test)

Aggregations

MixingFraction (org.broadinstitute.hellbender.tools.walkers.validation.MixingFraction)8 Test (org.testng.annotations.Test)8 File (java.io.File)6 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)4 VariantContext (htsjdk.variant.variantcontext.VariantContext)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 StreamSupport (java.util.stream.StreamSupport)2 StandardArgumentDefinitions (org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions)2 FeatureDataSource (org.broadinstitute.hellbender.engine.FeatureDataSource)2 AnnotateVcfWithExpectedAlleleFraction (org.broadinstitute.hellbender.tools.walkers.validation.AnnotateVcfWithExpectedAlleleFraction)2 IndexRange (org.broadinstitute.hellbender.utils.IndexRange)2 Assert (org.testng.Assert)2