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);
}
}
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;
}
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();
}
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());
}
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);
}
Aggregations