Search in sources :

Example 1 with AssemblyRegion

use of org.broadinstitute.hellbender.engine.AssemblyRegion in project gatk-protected 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 2 with AssemblyRegion

use of org.broadinstitute.hellbender.engine.AssemblyRegion in project gatk by broadinstitute.

the class ActivityProfileUnitTest method testActiveRegionCutTests.

@Test(dataProvider = "ActiveRegionCutTests")
public void testActiveRegionCutTests(final int minRegionSize, final int maxRegionSize, final int expectedRegionSize, final List<Double> probs) {
    final ActivityProfile profile = new ActivityProfile(MAX_PROB_PROPAGATION_DISTANCE, ACTIVE_PROB_THRESHOLD, header);
    final String contig = genomeLocParser.getSequenceDictionary().getSequences().get(0).getSequenceName();
    for (int i = 0; i <= maxRegionSize + profile.getMaxProbPropagationDistance(); i++) {
        final GenomeLoc loc = genomeLocParser.createGenomeLoc(contig, i + 1);
        final double prob = i < probs.size() ? probs.get(i) : 0.0;
        final ActivityProfileState state = new ActivityProfileState(new SimpleInterval(loc), prob);
        profile.add(state);
    }
    final List<AssemblyRegion> regions = profile.popReadyAssemblyRegions(0, minRegionSize, maxRegionSize, false);
    Assert.assertTrue(regions.size() >= 1, "Should only be one regions for this test");
    final AssemblyRegion region = regions.get(0);
    Assert.assertEquals(region.getSpan().getStart(), 1, "Region should start at 1");
    Assert.assertEquals(region.getSpan().size(), expectedRegionSize, "Incorrect region size; cut must have been incorrect");
}
Also used : AssemblyRegion(org.broadinstitute.hellbender.engine.AssemblyRegion) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 3 with AssemblyRegion

use of org.broadinstitute.hellbender.engine.AssemblyRegion in project gatk by broadinstitute.

the class ActivityProfileUnitTest method assertGoodRegions.

private AssemblyRegion assertGoodRegions(final int start, final List<AssemblyRegion> regions, final int maxRegionSize, AssemblyRegion lastRegion, final List<Boolean> probs, final List<Boolean> seenSites) {
    for (final AssemblyRegion region : regions) {
        Assert.assertTrue(region.getSpan().size() > 0, "Region " + region + " has a bad size");
        Assert.assertTrue(region.getSpan().size() <= maxRegionSize, "Region " + region + " has a bad size: it's big than the max region size " + maxRegionSize);
        if (lastRegion != null) {
            Assert.assertTrue(region.getSpan().getStart() == lastRegion.getSpan().getEnd() + 1, "Region " + region + " doesn't start immediately after previous region" + lastRegion);
        }
        // check that all active bases are actually active
        final int regionOffset = region.getSpan().getStart() - start;
        Assert.assertTrue(regionOffset >= 0 && regionOffset < probs.size(), "Region " + region + " has a bad offset w.r.t. start");
        for (int j = 0; j < region.getSpan().size(); j++) {
            final int siteOffset = j + regionOffset;
            Assert.assertEquals(region.isActive(), probs.get(siteOffset).booleanValue());
            Assert.assertFalse(seenSites.get(siteOffset), "Site " + j + " in " + region + " was seen already");
            seenSites.set(siteOffset, true);
        }
        lastRegion = region;
    }
    return lastRegion;
}
Also used : AssemblyRegion(org.broadinstitute.hellbender.engine.AssemblyRegion)

Example 4 with AssemblyRegion

use of org.broadinstitute.hellbender.engine.AssemblyRegion in project gatk-protected by broadinstitute.

the class ReadThreadingAssemblerUnitTest method assemble.

private List<Haplotype> assemble(final ReadThreadingAssembler assembler, final byte[] refBases, final SimpleInterval loc, final List<GATKRead> reads) {
    final Haplotype refHaplotype = new Haplotype(refBases, true);
    final Cigar c = new Cigar();
    c.add(new CigarElement(refHaplotype.getBases().length, CigarOperator.M));
    refHaplotype.setCigar(c);
    final AssemblyRegion activeRegion = new AssemblyRegion(loc, null, true, 0, header);
    activeRegion.addAll(reads);
    //        logger.warn("Assembling " + activeRegion + " with " + engine);
    final AssemblyResultSet assemblyResultSet = assembler.runLocalAssembly(activeRegion, refHaplotype, refBases, loc, Collections.<VariantContext>emptyList(), null, header);
    return assemblyResultSet.getHaplotypeList();
}
Also used : Cigar(htsjdk.samtools.Cigar) AssemblyRegion(org.broadinstitute.hellbender.engine.AssemblyRegion) AssemblyResultSet(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.AssemblyResultSet) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) KBestHaplotype(org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype) CigarElement(htsjdk.samtools.CigarElement)

Example 5 with AssemblyRegion

use of org.broadinstitute.hellbender.engine.AssemblyRegion 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)

Aggregations

AssemblyRegion (org.broadinstitute.hellbender.engine.AssemblyRegion)13 Haplotype (org.broadinstitute.hellbender.utils.haplotype.Haplotype)8 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)7 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)4 Test (org.testng.annotations.Test)4 Cigar (htsjdk.samtools.Cigar)2 CigarElement (htsjdk.samtools.CigarElement)2 SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 SAMFileWriter (htsjdk.samtools.SAMFileWriter)2 ReferenceSequenceFile (htsjdk.samtools.reference.ReferenceSequenceFile)2 Locatable (htsjdk.samtools.util.Locatable)2 VariantContext (htsjdk.variant.variantcontext.VariantContext)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Logger (org.apache.logging.log4j.Logger)2 UserException (org.broadinstitute.hellbender.exceptions.UserException)2 AssemblyResultSet (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.AssemblyResultSet)2 KBestHaplotype (org.broadinstitute.hellbender.tools.walkers.haplotypecaller.graphs.KBestHaplotype)2