Search in sources :

Example 71 with Haplotype

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

the class AssemblyResultSetUnitTest method testTrimTo.

@Test(dataProvider = "trimmingData")
public void testTrimTo(final Map<Haplotype, AssemblyResult> haplotypesAndResultSets, final AssemblyRegion original) {
    final AssemblyResultSet subject = new AssemblyResultSet();
    for (final Map.Entry<Haplotype, AssemblyResult> entry : haplotypesAndResultSets.entrySet()) subject.add(entry.getKey(), entry.getValue());
    subject.setRegionForGenotyping(original);
    final SimpleInterval originalLocation = original.getExtendedSpan();
    final int length = originalLocation.size();
    final SimpleInterval newLocation = new SimpleInterval(originalLocation.getContig(), originalLocation.getStart() + length / 2, originalLocation.getEnd() - length / 2);
    final AssemblyRegion newRegion = original.trim(newLocation);
    final Map<Haplotype, Haplotype> originalHaplotypesByTrimmed = new HashMap<>(haplotypesAndResultSets.size());
    for (final Haplotype h : haplotypesAndResultSets.keySet()) originalHaplotypesByTrimmed.put(h.trim(newRegion.getExtendedSpan()), h);
    final AssemblyResultSet trimmed = subject.trimTo(newRegion);
    Assert.assertFalse(subject.wasTrimmed());
    Assert.assertTrue(trimmed.wasTrimmed());
    for (final Haplotype h : trimmed.getHaplotypeList()) {
        Assert.assertEquals(h.getGenomeLocation(), newLocation);
        Assert.assertEquals(h.getBases().length, newLocation.size());
    }
}
Also used : AssemblyRegion(org.broadinstitute.hellbender.engine.AssemblyRegion) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 72 with Haplotype

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

the class AssemblyResultSetUnitTest method testAddReferenceHaplotype.

@Test
public void testAddReferenceHaplotype() {
    final Haplotype ref = new Haplotype("ACGT".getBytes(), true);
    ref.setGenomeLocation(genomeLocParser.createGenomeLoc("1", 1, ref.length() + 1));
    final AssemblyResultSet subject = new AssemblyResultSet();
    Assert.assertTrue(subject.add(ref));
    Assert.assertFalse(subject.add(ref));
    Assert.assertEquals(subject.getReferenceHaplotype(), ref);
    Assert.assertEquals(subject.getHaplotypeCount(), 1);
    Assert.assertEquals(subject.getHaplotypeList().size(), 1);
}
Also used : Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 73 with Haplotype

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

the class AssemblyRegionTestDataSet method haplotypeList.

public List<Haplotype> haplotypeList() {
    if (haplotypeList == null) {
        final List<Haplotype> result = new ArrayList<>(haplotypeCigars.length);
        final String reference = this.reference;
        for (final String cigar : haplotypeCigars) {
            if (cigar.matches("^Civar:.*$")) {
                stringRepresentation = cigar.substring(6);
                result.addAll(expandAllHaplotypeCombinations(cigar.substring(6), reference));
            } else if (cigar.matches("^.*\\d+.*$")) {
                result.add(cigarToHaplotype(reference, cigar, 0, true));
            } else {
                final Haplotype h = new Haplotype(cigar.getBytes());
                h.setGenomeLocation(genomeLocParser.createGenomeLoc("chr1", 1, reference.length()));
                result.add(h);
            }
        }
        haplotypeList = result;
    }
    return haplotypeList;
}
Also used : ArrayList(java.util.ArrayList) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype)

Example 74 with Haplotype

use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk-protected 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 75 with Haplotype

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

the class ReadThreadingAssemblerUnitTest method testSimpleAssembly.

@Test(dataProvider = "SimpleAssemblyTestData")
public void testSimpleAssembly(final String name, final ReadThreadingAssembler assembler, final SimpleInterval loc, final String ref, final String alt) {
    final byte[] refBases = ref.getBytes();
    final byte[] altBases = alt.getBytes();
    final List<GATKRead> reads = new LinkedList<>();
    for (int i = 0; i < 20; i++) {
        final byte[] bases = altBases.clone();
        final byte[] quals = Utils.dupBytes((byte) 30, altBases.length);
        final String cigar = altBases.length + "M";
        final GATKRead read = ArtificialReadUtils.createArtificialRead(header, loc.getContig(), loc.getContig(), loc.getStart(), bases, quals, cigar);
        reads.add(read);
    }
    final Haplotype refHaplotype = new Haplotype(refBases, true);
    final Haplotype altHaplotype = new Haplotype(altBases, false);
    final List<Haplotype> haplotypes = assemble(assembler, refBases, loc, reads);
    Assert.assertTrue(haplotypes.size() > 0, "Failed to find ref haplotype");
    Assert.assertEquals(haplotypes.get(0), refHaplotype);
    Assert.assertEquals(haplotypes.size(), 2, "Failed to find single alt haplotype");
    Assert.assertEquals(haplotypes.get(1), altHaplotype);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) KBestHaplotype(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype) 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