Search in sources :

Example 56 with Haplotype

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

the class AlignmentUtilsUnitTest method testReadAlignedToRefComplexAlignment.

@Test(dataProvider = "ComplexReadAlignedToRef")
public void testReadAlignedToRefComplexAlignment(final int testIndex, final GATKRead read, final String reference, final Haplotype haplotype, final int expectedMaxMismatches) throws Exception {
    final GATKRead alignedRead = AlignmentUtils.createReadAlignedToRef(read, haplotype, new Haplotype(reference.getBytes(), true), 1, true);
    if (alignedRead != null) {
        final int mismatches = AlignmentUtils.getMismatchCount(alignedRead, reference.getBytes(), alignedRead.getStart() - 1).numMismatches;
        Assert.assertTrue(mismatches <= expectedMaxMismatches, "Alignment of read to ref looks broken.  Expected at most " + expectedMaxMismatches + " but saw " + mismatches + " for readBases " + new String(read.getBases()) + " with cigar " + read.getCigar() + " reference " + reference + " haplotype " + haplotype + " with cigar " + haplotype.getCigar() + " aligned read cigar " + alignedRead.getCigar().toString() + " @ " + alignedRead.getStart());
    }
}
Also used : Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) Test(org.testng.annotations.Test)

Example 57 with Haplotype

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

the class HaplotypeCallerGenotypingEngineUnitTest method makeCreateHaplotypeMappingData.

@DataProvider(name = "CreateHaplotypeMappingProvider")
public Object[][] makeCreateHaplotypeMappingData() {
    List<Object[]> tests = new ArrayList<Object[]>();
    final Set<Haplotype> haplotypes = new HashSet<>();
    final Allele ref = Allele.create("A", true);
    final Allele altC = Allele.create("C", false);
    final Allele altT = Allele.create("T", false);
    final Haplotype AtoC1 = new Haplotype("AACAA".getBytes());
    final VariantContext vc1 = new VariantContextBuilder().chr("20").start(3).stop(3).alleles(Arrays.asList(ref, altC)).make();
    AtoC1.setEventMap(new EventMap(Arrays.asList(vc1)));
    AtoC1.getEventMap().put(3, vc1);
    haplotypes.add(AtoC1);
    final Haplotype AtoC2 = new Haplotype("AAACA".getBytes());
    final VariantContext vc2 = new VariantContextBuilder().chr("20").start(4).stop(4).alleles(Arrays.asList(ref, altT)).make();
    AtoC2.setEventMap(new EventMap(Arrays.asList(vc2)));
    AtoC2.getEventMap().put(4, vc2);
    haplotypes.add(AtoC2);
    tests.add(new Object[] { vc1, haplotypes, AtoC1 });
    tests.add(new Object[] { vc2, haplotypes, AtoC2 });
    tests.add(new Object[] { new VariantContextBuilder().chr("20").start(1).stop(1).alleles(Arrays.asList(ref, altT)).make(), haplotypes, null });
    return tests.toArray(new Object[][] {});
}
Also used : Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) EventMap(org.broadinstitute.hellbender.utils.haplotype.EventMap) DataProvider(org.testng.annotations.DataProvider)

Example 58 with Haplotype

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

the class HaplotypeCallerGenotypingEngineUnitTest method testReduceNumberOfAlternativeAllelesBasedOnHaplotypesScores.

@Test
public void testReduceNumberOfAlternativeAllelesBasedOnHaplotypesScores() {
    // first have a list of alleles, one ref, several alt
    final Allele ref = Allele.create("A", true);
    final Allele altC = Allele.create("C", false);
    final Allele altT = Allele.create("T", false);
    final Allele altT2 = Allele.create("TT", false);
    final Allele altG = Allele.create("G", false);
    // then create several haplotypes, assign ad-hoc scores
    final Haplotype hapRef = new Haplotype("AAAAA".getBytes());
    hapRef.setScore(Double.MAX_VALUE);
    // test case when both same best score and second best score are the same
    final Haplotype hapT = new Haplotype("TAAAA".getBytes());
    hapT.setScore(-2.0);
    final Haplotype hapTAnother = new Haplotype("TAAAT".getBytes());
    hapTAnother.setScore(-3.0);
    final Haplotype hapT2 = new Haplotype("TTAAA".getBytes());
    hapT2.setScore(-2.0);
    final Haplotype hapT2Another = new Haplotype("TTAAT".getBytes());
    hapT2Another.setScore(-3.0);
    final Haplotype hapC = new Haplotype("CAAAA".getBytes());
    hapC.setScore(-3.0);
    // for case when there's tie in highest haplotype score
    final Haplotype hapG = new Haplotype("GAAAA".getBytes());
    hapG.setScore(-3.0);
    final Haplotype hapGAnother = new Haplotype("GAAAG".getBytes());
    hapGAnother.setScore(-5.0);
    final Map<Allele, List<Haplotype>> alleleMapper = new LinkedHashMap<>();
    alleleMapper.put(ref, Arrays.asList(hapRef));
    alleleMapper.put(altC, Arrays.asList(hapC));
    alleleMapper.put(altT, Arrays.asList(hapT, hapTAnother));
    alleleMapper.put(altT2, Arrays.asList(hapT2, hapT2Another));
    alleleMapper.put(altG, Arrays.asList(hapG, hapGAnother));
    List<Allele> allelesToKeep = HaplotypeCallerGenotypingEngine.whichAllelesToKeepBasedonHapScores(alleleMapper, 5);
    Assert.assertEquals(allelesToKeep.size(), 5);
    Iterator<Allele> it = allelesToKeep.iterator();
    Assert.assertEquals(it.next(), ref);
    Assert.assertEquals(it.next(), altC);
    Assert.assertEquals(it.next(), altT);
    Assert.assertEquals(it.next(), altT2);
    Assert.assertEquals(it.next(), altG);
    allelesToKeep = HaplotypeCallerGenotypingEngine.whichAllelesToKeepBasedonHapScores(alleleMapper, 4);
    Assert.assertEquals(allelesToKeep.size(), 4);
    it = allelesToKeep.iterator();
    Assert.assertEquals(it.next(), ref);
    Assert.assertEquals(it.next(), altT);
    Assert.assertEquals(it.next(), altT2);
    Assert.assertEquals(it.next(), altG);
    allelesToKeep = HaplotypeCallerGenotypingEngine.whichAllelesToKeepBasedonHapScores(alleleMapper, 3);
    Assert.assertEquals(allelesToKeep.size(), 3);
    it = allelesToKeep.iterator();
    Assert.assertEquals(it.next(), ref);
    Assert.assertEquals(it.next(), altT);
    Assert.assertEquals(it.next(), altT2);
    allelesToKeep = HaplotypeCallerGenotypingEngine.whichAllelesToKeepBasedonHapScores(alleleMapper, 2);
    Assert.assertEquals(allelesToKeep.size(), 2);
    it = allelesToKeep.iterator();
    Assert.assertEquals(it.next(), ref);
    Assert.assertEquals(it.next(), altT);
    allelesToKeep = HaplotypeCallerGenotypingEngine.whichAllelesToKeepBasedonHapScores(alleleMapper, 1);
    Assert.assertEquals(allelesToKeep.size(), 1);
    it = allelesToKeep.iterator();
    Assert.assertEquals(it.next(), ref);
}
Also used : Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 59 with Haplotype

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

Example 60 with Haplotype

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

the class RandomLikelihoodCalculationEngineUnitTest method testComputeLikelihoods.

@Test
public void testComputeLikelihoods() {
    final ReadLikelihoodCalculationEngine lce = new RandomLikelihoodCalculationEngine();
    final Map<String, List<GATKRead>> perSampleReadList = new HashMap<>();
    final int n = 10;
    final GATKRead read1 = ArtificialReadUtils.createArtificialRead(TextCigarCodec.decode(n + "M"));
    read1.setMappingQuality(60);
    final String sample1 = "sample1";
    perSampleReadList.put(sample1, Arrays.asList(read1));
    final SampleList samples = new IndexedSampleList(sample1);
    final AssemblyResultSet assemblyResultSet = new AssemblyResultSet();
    final byte[] bases = Strings.repeat("A", n + 1).getBytes();
    final Haplotype hap1 = new Haplotype(bases, true);
    hap1.setGenomeLocation(read1);
    assemblyResultSet.add(hap1);
    final byte[] basesModified = bases;
    //different bases
    basesModified[5] = 'C';
    final Haplotype hap2 = new Haplotype(basesModified, false);
    //use same loc
    hap2.setGenomeLocation(read1);
    assemblyResultSet.add(hap2);
    final ReadLikelihoods<Haplotype> likes = lce.computeReadLikelihoods(assemblyResultSet, samples, perSampleReadList);
    final LikelihoodMatrix<Haplotype> mtx = likes.sampleMatrix(0);
    Assert.assertEquals(mtx.numberOfAlleles(), 2);
    Assert.assertEquals(mtx.numberOfReads(), 1);
    final double v1 = mtx.get(0, 0);
    final double v2 = mtx.get(1, 0);
    Assert.assertTrue(v1 < 0);
    Assert.assertTrue(v2 < 0);
    lce.close();
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) HashMap(java.util.HashMap) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) List(java.util.List) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) 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