Search in sources :

Example 1 with SampleList

use of org.broadinstitute.hellbender.utils.genotyper.SampleList in project gatk by broadinstitute.

the class GenotypingDataUnitTest method testInstantiation.

@Test(dataProvider = "ploidyAndMaximumAlleleAndReadCountsData")
public void testInstantiation(final int[] ploidies, final int[] readCounts) {
    final ReadLikelihoods<Allele> likelihoods = ReadLikelihoodsUnitTester.readLikelihoods(2, readCounts);
    final SampleList sampleList = likelihoods;
    final PloidyModel ploidyModel = new HeterogeneousPloidyModel(sampleList, ploidies);
    final GenotypingData<Allele> data = new GenotypingData<>(ploidyModel, likelihoods);
    Assert.assertEquals(data.asListOfAlleles(), likelihoods.asListOfAlleles());
    Assert.assertEquals(data.asListOfSamples(), likelihoods.asListOfSamples());
    Assert.assertEquals(data.readLikelihoods(), likelihoods);
    Assert.assertEquals(data.ploidyModel(), ploidyModel);
    for (int i = 0; i < data.numberOfSamples(); i++) {
        Assert.assertEquals(data.indexOfSample(data.getSample(i)), i);
    }
    for (int i = 0; i < data.numberOfAlleles(); i++) {
        Assert.assertEquals(data.indexOfAllele(data.getAllele(i)), i);
    }
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) Test(org.testng.annotations.Test)

Example 2 with SampleList

use of org.broadinstitute.hellbender.utils.genotyper.SampleList in project gatk by broadinstitute.

the class ReferenceConfidenceModelUnitTest method splitReadsBySample.

public static Map<String, List<GATKRead>> splitReadsBySample(final SampleList samplesList, final Collection<GATKRead> reads, final SAMFileHeader header) {
    final Map<String, List<GATKRead>> returnMap = new HashMap<>();
    final int sampleCount = samplesList.numberOfSamples();
    for (int i = 0; i < sampleCount; i++) {
        returnMap.put(samplesList.getSample(i), new ArrayList<>());
    }
    for (final GATKRead read : reads) {
        returnMap.get(ReadUtils.getSampleName(read, header)).add(read);
    }
    return returnMap;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) IndexedAlleleList(org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList)

Example 3 with SampleList

use of org.broadinstitute.hellbender.utils.genotyper.SampleList in project gatk-protected by broadinstitute.

the class PairHMMLikelihoodCalculationEngineUnitTest method testComputeLikelihoods.

@Test
public void testComputeLikelihoods() {
    final LikelihoodEngineArgumentCollection LEAC = new LikelihoodEngineArgumentCollection();
    PairHMMLikelihoodCalculationEngine.writeLikelihoodsToFile = true;
    final ReadLikelihoodCalculationEngine lce = new PairHMMLikelihoodCalculationEngine((byte) SAMUtils.MAX_PHRED_SCORE, new PairHMMNativeArguments(), PairHMM.Implementation.LOGLESS_CACHING, MathUtils.logToLog10(QualityUtils.qualToErrorProbLog10(LEAC.phredScaledGlobalReadMismappingRate)), PairHMMLikelihoodCalculationEngine.PCRErrorModel.CONSERVATIVE);
    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 > v2, "matching haplotype should have a higher likelihood");
    lce.close();
    new File(PairHMMLikelihoodCalculationEngine.LIKELIHOODS_FILENAME).delete();
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) PairHMMNativeArguments(org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) Haplotype(org.broadinstitute.hellbender.utils.haplotype.Haplotype) File(java.io.File) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) IndexedSampleList(org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 4 with SampleList

use of org.broadinstitute.hellbender.utils.genotyper.SampleList in project gatk by broadinstitute.

the class BaseQualityRankSumTestUnitTest method testEmptyIfNoGenotypes.

@Test
public void testEmptyIfNoGenotypes() throws Exception {
    final BaseQualityRankSumTest ann = new BaseQualityRankSumTest();
    final List<GATKRead> reads = Collections.emptyList();
    final Map<String, List<GATKRead>> readsBySample = ImmutableMap.of(SAMPLE_1, reads);
    final SampleList sampleList = new IndexedSampleList(Arrays.asList(SAMPLE_1));
    final AlleleList<Allele> alleleList = new IndexedAlleleList<>(Arrays.asList(Allele.NO_CALL));
    final ReadLikelihoods<Allele> likelihoods = new ReadLikelihoods<>(sampleList, alleleList, readsBySample);
    final Map<String, Object> annotate = ann.annotate(null, when(mock(VariantContext.class).getGenotypesOrderedByName()).thenReturn(Collections.<Genotype>emptyList()).getMock(), likelihoods);
    Assert.assertTrue(annotate.isEmpty());
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) List(java.util.List) AS_BaseQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_BaseQualityRankSumTest) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) AS_BaseQualityRankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_BaseQualityRankSumTest) Test(org.testng.annotations.Test) AS_RankSumTest(org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_RankSumTest)

Example 5 with SampleList

use of org.broadinstitute.hellbender.utils.genotyper.SampleList in project gatk by broadinstitute.

the class ReadPositionUnitTest method test.

@Test
public void test() {
    final SAMFileHeader SAM_HEADER = ArtificialReadUtils.createArtificialSamHeader(10, 0, 1000);
    final List<Allele> alleles = Arrays.asList(Allele.create((byte) 'A', true), Allele.create((byte) 'C', false));
    final AlleleList<Allele> alleleList = new IndexedAlleleList<>(alleles);
    final int chromosomeIndex = 5;
    // variant is a SNP at position 20
    final int variantSite = 20;
    final VariantContext vc = new VariantContextBuilder("source", Integer.toString(chromosomeIndex), variantSite, variantSite, alleles).make();
    final SampleList sampleList = new IndexedSampleList("SAMPLE");
    //7 length-12 reads
    final Map<String, List<GATKRead>> readMap = new LinkedHashMap<>();
    final List<GATKRead> reads = new ArrayList<>();
    final int[] positionsOfSiteWithinReads = new int[] { 1, 2, 2, 3, 10, 10, 11 };
    final int[] alignmentStarts = Arrays.stream(positionsOfSiteWithinReads).map(n -> variantSite - n).toArray();
    for (int r = 0; r < positionsOfSiteWithinReads.length; r++) {
        final GATKRead read = ArtificialReadUtils.createArtificialRead(SAM_HEADER, "RRR00" + r, chromosomeIndex, alignmentStarts[r], "ACGTACGTACGT".getBytes(), new byte[] { 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 }, "12M");
        read.setMappingQuality(60);
        reads.add(read);
    }
    readMap.put("SAMPLE", reads);
    final ReadLikelihoods<Allele> likelihoods = new ReadLikelihoods<>(sampleList, alleleList, readMap);
    //we will make the first four reads ref (median position = 2) and the last three alt (median position 10, hence
    // median distance from end = 1)
    final LikelihoodMatrix<Allele> matrix = likelihoods.sampleMatrix(0);
    // log likelihoods are initialized to 0, so we can "turn on" a read for a particular allele by setting the
    // (allele, read) entry to 10
    matrix.set(0, 0, 10);
    matrix.set(0, 1, 10);
    matrix.set(0, 2, 10);
    matrix.set(0, 3, 10);
    matrix.set(1, 4, 10);
    matrix.set(1, 5, 10);
    matrix.set(1, 6, 10);
    final ReadPosition rp = new ReadPosition();
    final GenotypeBuilder gb = new GenotypeBuilder(DUMMY_GENOTYPE);
    rp.annotate(null, vc, DUMMY_GENOTYPE, gb, likelihoods);
    final Genotype g = gb.make();
    final int[] medianRefAndAltPositions = (int[]) g.getExtendedAttribute(ReadPosition.KEY);
    Assert.assertEquals(medianRefAndAltPositions[0], 2);
    Assert.assertEquals(medianRefAndAltPositions[1], 1);
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) java.util(java.util) ArtificialReadUtils(org.broadinstitute.hellbender.utils.read.ArtificialReadUtils) Assert(org.testng.Assert) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) Test(org.testng.annotations.Test) htsjdk.variant.variantcontext(htsjdk.variant.variantcontext) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMFileHeader(htsjdk.samtools.SAMFileHeader) org.broadinstitute.hellbender.utils.genotyper(org.broadinstitute.hellbender.utils.genotyper) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) SampleList(org.broadinstitute.hellbender.utils.genotyper.SampleList) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

SampleList (org.broadinstitute.hellbender.utils.genotyper.SampleList)15 IndexedSampleList (org.broadinstitute.hellbender.utils.genotyper.IndexedSampleList)10 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)9 Test (org.testng.annotations.Test)8 List (java.util.List)4 Haplotype (org.broadinstitute.hellbender.utils.haplotype.Haplotype)4 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)4 IndexedAlleleList (org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList)3 SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 htsjdk.variant.variantcontext (htsjdk.variant.variantcontext)2 File (java.io.File)2 java.util (java.util)2 HashMap (java.util.HashMap)2 PairHMMNativeArguments (org.broadinstitute.gatk.nativebindings.pairhmm.PairHMMNativeArguments)2 GeneralPloidyFailOverAFCalculatorProvider (org.broadinstitute.hellbender.tools.walkers.genotyper.afcalc.GeneralPloidyFailOverAFCalculatorProvider)2 org.broadinstitute.hellbender.utils.genotyper (org.broadinstitute.hellbender.utils.genotyper)2 ArtificialReadUtils (org.broadinstitute.hellbender.utils.read.ArtificialReadUtils)2 Assert (org.testng.Assert)2 Allele (htsjdk.variant.variantcontext.Allele)1 ArrayList (java.util.ArrayList)1