Search in sources :

Example 31 with Haplotype

use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk by broadinstitute.

the class ReferenceConfidenceModelUnitTest method testRefConfidenceWithCalls.

@Test
public void testRefConfidenceWithCalls() {
    final RefConfData xxxdata = new RefConfData("ACGTAACCGGTT", 0);
    final int start = xxxdata.getStart();
    final int stop = xxxdata.getEnd();
    final PloidyModel ploidyModel = new HomogeneousPloidyModel(samples, 2);
    final IndependentSampleGenotypesModel genotypingModel = new IndependentSampleGenotypesModel();
    for (int nReads = 0; nReads < 2; nReads++) {
        final VariantContext vcStart = GATKVariantContextUtils.makeFromAlleles("test", "chr1", start, Arrays.asList("A", "C"));
        final VariantContext vcEnd = GATKVariantContextUtils.makeFromAlleles("test", "chr1", stop, Arrays.asList("A", "C"));
        final VariantContext vcMiddle = GATKVariantContextUtils.makeFromAlleles("test", "chr1", start + 2, Arrays.asList("A", "C"));
        final VariantContext vcDel = GATKVariantContextUtils.makeFromAlleles("test", "chr1", start + 4, Arrays.asList("AAC", "A"));
        final VariantContext vcIns = GATKVariantContextUtils.makeFromAlleles("test", "chr1", start + 8, Arrays.asList("G", "GCG"));
        final List<VariantContext> allCalls = Arrays.asList(vcStart, vcEnd, vcMiddle, vcDel, vcIns);
        for (int n = 1; n <= allCalls.size(); n++) {
            for (final List<VariantContext> calls : Utils.makePermutations(allCalls, n, false)) {
                final RefConfData data = new RefConfData("ACGTAACCGGTT", 0);
                final List<Haplotype> haplotypes = Arrays.asList(data.getRefHap());
                for (int i = 0; i < nReads; i++) {
                    data.getActiveRegion().add(data.makeRead(0, data.getRefLength()));
                }
                final ReadLikelihoods<Haplotype> likelihoods = createDummyStratifiedReadMap(data.getRefHap(), samples, data.getActiveRegion());
                final List<Integer> expectedDPs = Collections.nCopies(data.getActiveRegion().getSpan().size(), nReads);
                final List<VariantContext> contexts = model.calculateRefConfidence(data.getRefHap(), haplotypes, data.getPaddedRefLoc(), data.getActiveRegion(), likelihoods, ploidyModel, calls);
                checkReferenceModelResult(data, contexts, expectedDPs, calls);
            }
        }
    }
}
Also used : IndependentSampleGenotypesModel(org.broadinstitute.hellbender.tools.walkers.genotyper.IndependentSampleGenotypesModel) HomogeneousPloidyModel(org.broadinstitute.hellbender.tools.walkers.genotyper.HomogeneousPloidyModel) VariantContext(htsjdk.variant.variantcontext.VariantContext) HomogeneousPloidyModel(org.broadinstitute.hellbender.tools.walkers.genotyper.HomogeneousPloidyModel) PloidyModel(org.broadinstitute.hellbender.tools.walkers.genotyper.PloidyModel) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 32 with Haplotype

use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk by broadinstitute.

the class AssemblyResultSetUnitTest method testAddManyHaplotypes.

@Test(dataProvider = "assemblyResults")
public void testAddManyHaplotypes(final List<AssemblyResult> assemblyResults, final List<List<Haplotype>> haplotypes) {
    final AssemblyResultSet subject = new AssemblyResultSet();
    for (int i = 0; i < haplotypes.size(); i++) {
        final int haplotypeCountBefore = subject.getHaplotypeCount();
        final List<Haplotype> haplos = haplotypes.get(i);
        final AssemblyResult ar = assemblyResults.get(i);
        for (final Haplotype h : haplos) {
            Assert.assertTrue(subject.add(h, ar));
            Assert.assertFalse(subject.add(h, ar));
            if (h.isReference())
                Assert.assertEquals(subject.getReferenceHaplotype(), h);
        }
        final int haplotypeCountAfter = subject.getHaplotypeCount();
        Assert.assertEquals(haplos.size(), haplotypeCountAfter - haplotypeCountBefore);
        Assert.assertTrue(subject.getMaximumKmerSize() >= ar.getKmerSize());
        Assert.assertTrue(subject.getMinimumKmerSize() <= ar.getKmerSize());
        Assert.assertEquals(subject.getUniqueReadThreadingGraph(ar.getKmerSize()), ar.getThreadingGraph());
    }
}
Also used : Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 33 with Haplotype

use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk by broadinstitute.

the class AssemblyResultSetUnitTest method trimmingData.

@DataProvider(name = "trimmingData")
public Iterator<Object[]> trimmingData() {
    final AssemblyRegion activeRegion = new AssemblyRegion(new SimpleInterval("1", 1000, 1100), 25, header);
    final int length = activeRegion.getExtendedSpan().size();
    // keep it prepoducible by fixing the seed to lucky 13.
    final RandomDNA rnd = new RandomDNA(13);
    final AssemblyRegionTestDataSet actd = new AssemblyRegionTestDataSet(10, new String(rnd.nextBases(length)), new String[] { "Civar:*1T*" }, new String[0], new byte[0], new byte[0], new byte[0]);
    final List<Haplotype> haplotypes = actd.haplotypeList();
    for (final Haplotype h : haplotypes) h.setGenomeLocation(activeRegion.getExtendedSpan());
    final ReadThreadingGraph rtg = new ReadThreadingGraph(10);
    for (final Haplotype h : haplotypes) rtg.addSequence("seq-" + Math.abs(h.hashCode()), h.getBases(), h.isReference());
    final SeqGraph seqGraph = rtg.toSequenceGraph();
    final AssemblyResult ar = new AssemblyResult(AssemblyResult.Status.ASSEMBLED_SOME_VARIATION, seqGraph, rtg);
    final Map<Haplotype, AssemblyResult> result = new HashMap<>();
    for (final Haplotype h : haplotypes) result.put(h, ar);
    return Collections.singleton(new Object[] { result, activeRegion }).iterator();
}
Also used : ReadThreadingGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.ReadThreadingGraph) TestingReadThreadingGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.TestingReadThreadingGraph) SeqGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.SeqGraph) RandomDNA(org.broadinstitute.hellbender.utils.RandomDNA) AssemblyRegion(org.broadinstitute.hellbender.engine.AssemblyRegion) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) DataProvider(org.testng.annotations.DataProvider)

Example 34 with Haplotype

use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk by broadinstitute.

the class AssemblyResultSetUnitTest method assemblyResults.

@DataProvider(name = "assemblyResults")
public Iterator<Object[]> assemblyResults() {
    final int size = THREE_KS_GRAPH_AND_HAPLOTYPES.length * (1 + TEN_KS_GRAPH_AND_HAPLOTYPES.length);
    final Object[][] result = new Object[size][];
    for (int i = 0; i < THREE_KS_GRAPH_AND_HAPLOTYPES.length; i++) {
        final ReadThreadingGraph rtg = new TestingReadThreadingGraph((String) THREE_KS_GRAPH_AND_HAPLOTYPES[i][0]);
        final AssemblyResult ar = new AssemblyResult(AssemblyResult.Status.ASSEMBLED_SOME_VARIATION, rtg.toSequenceGraph(), rtg);
        final Object[] haplotypeStrings = (Object[]) THREE_KS_GRAPH_AND_HAPLOTYPES[i][1];
        final Haplotype[] haplotypes = new Haplotype[haplotypeStrings.length];
        for (int j = 0; j < haplotypeStrings.length; j++) {
            haplotypes[j] = new Haplotype(((String) haplotypeStrings[j]).getBytes(), j == 0);
            haplotypes[j].setGenomeLocation(genomeLocParser.createGenomeLoc("1", 1, haplotypes[j].length() + 1));
        }
        result[i] = new Object[] { Collections.singletonList(ar), Arrays.asList(Arrays.asList(haplotypes)) };
        for (int j = 0; j < TEN_KS_GRAPH_AND_HAPLOTYPES.length; j++) {
            final ReadThreadingGraph rtg10 = new TestingReadThreadingGraph((String) TEN_KS_GRAPH_AND_HAPLOTYPES[j][0]);
            final AssemblyResult ar10 = new AssemblyResult(AssemblyResult.Status.ASSEMBLED_SOME_VARIATION, rtg10.toSequenceGraph(), rtg10);
            final Object[] haplotypeStrings10 = (Object[]) TEN_KS_GRAPH_AND_HAPLOTYPES[j][1];
            final Haplotype[] haplotype10 = new Haplotype[haplotypeStrings10.length];
            for (int k = 0; k < haplotypeStrings10.length; k++) {
                haplotype10[k] = new Haplotype(((String) haplotypeStrings10[k]).getBytes(), false);
                haplotype10[k].setGenomeLocation(genomeLocParser.createGenomeLoc("1", 1, haplotype10[k].length() + 1));
            }
            result[THREE_KS_GRAPH_AND_HAPLOTYPES.length + i * TEN_KS_GRAPH_AND_HAPLOTYPES.length + j] = new Object[] { Arrays.asList(ar, ar10), Arrays.asList(Arrays.asList(haplotypes), Arrays.asList(haplotype10)) };
        }
    }
    return Arrays.asList(result).iterator();
}
Also used : ReadThreadingGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.ReadThreadingGraph) TestingReadThreadingGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.TestingReadThreadingGraph) TestingReadThreadingGraph(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.TestingReadThreadingGraph) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) DataProvider(org.testng.annotations.DataProvider)

Example 35 with Haplotype

use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk by broadinstitute.

the class HaplotypeSizeAndBaseComparatorUnitTest method testComparison.

@Test
public void testComparison() {
    // desired ordering is by size first, subordered by lexacographic relationship between bases
    final List<String> rawStrings = Arrays.asList("A", "C", "AC", "CC", "CT", "AAT", "ACT", "GAT", "ACGT");
    final List<String> lexStrings = new ArrayList<>(rawStrings);
    for (final List<String> seqs : Utils.makePermutations(lexStrings, lexStrings.size(), false)) {
        final List<Haplotype> haps = new ArrayList<>(seqs.size());
        for (final String seq : seqs) {
            haps.add(new Haplotype(seq.getBytes(), false));
        }
        Collections.sort(haps, Haplotype.SIZE_AND_BASE_ORDER);
        for (int i = 0; i < lexStrings.size(); i++) Assert.assertEquals(haps.get(i).getBaseString(), lexStrings.get(i), "Failed sort " + haps + " expected " + lexStrings);
    }
}
Also used : ArrayList(java.util.ArrayList) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

Haplotype (org.broadinstitute.hellbender.utils.haplotype.Haplotype)88 Test (org.testng.annotations.Test)31 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)28 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)28 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)12 DataProvider (org.testng.annotations.DataProvider)10 VariantContext (htsjdk.variant.variantcontext.VariantContext)9 KBestHaplotype (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype)8 ArrayList (java.util.ArrayList)7 Cigar (htsjdk.samtools.Cigar)6 AssemblyRegion (org.broadinstitute.hellbender.engine.AssemblyRegion)6 HomogeneousPloidyModel (org.broadinstitute.hellbender.tools.walkers.genotyper.HomogeneousPloidyModel)6 IndependentSampleGenotypesModel (org.broadinstitute.hellbender.tools.walkers.genotyper.IndependentSampleGenotypesModel)6 PloidyModel (org.broadinstitute.hellbender.tools.walkers.genotyper.PloidyModel)6 ReadThreadingGraph (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.ReadThreadingGraph)6 SampleList (org.broadinstitute.hellbender.utils.genotyper.SampleList)6 EventMap (org.broadinstitute.hellbender.utils.haplotype.EventMap)6 CigarElement (htsjdk.samtools.CigarElement)4 Allele (htsjdk.variant.variantcontext.Allele)4 File (java.io.File)4