use of org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount in project gatk-protected by broadinstitute.
the class CalculatePulldownPhasePosteriors method calculatePhasePosteriors.
@VisibleForTesting
protected static AllelicCountWithPhasePosteriorsCollection calculatePhasePosteriors(final AllelicCountCollection counts, final List<SimpleInterval> segments, final AlleleFractionState state, final AllelicPanelOfNormals allelicPoN) {
final TargetCollection<SimpleInterval> segmentTargetCollection = new HashedListTargetCollection<>(segments);
final AllelicCountWithPhasePosteriorsCollection countsWithPhasePosteriors = new AllelicCountWithPhasePosteriorsCollection();
for (final AllelicCount count : counts.getCounts()) {
final int segmentIndex = segmentTargetCollection.index(count.getInterval());
if (segmentIndex < 0) {
throw new UserException.EmptyIntersection(String.format("The AllelicCount at %s is not located within one of the input segments.", count.getInterval()));
}
final AlleleFractionGlobalParameters parameters = state.globalParameters();
final double minorFraction = state.segmentMinorFraction(segmentIndex);
final double refMinorLogProb = AlleleFractionLikelihoods.hetLogLikelihood(parameters, minorFraction, count, AlleleFractionIndicator.REF_MINOR, allelicPoN);
final double altMinorLogProb = AlleleFractionLikelihoods.hetLogLikelihood(parameters, minorFraction, count, AlleleFractionIndicator.ALT_MINOR, allelicPoN);
final double outlierLogProb = AlleleFractionLikelihoods.hetLogLikelihood(parameters, minorFraction, count, AlleleFractionIndicator.OUTLIER, allelicPoN);
final AllelicCountWithPhasePosteriors countWithPhasePosteriors = new AllelicCountWithPhasePosteriors(count, refMinorLogProb, altMinorLogProb, outlierLogProb);
countsWithPhasePosteriors.add(countWithPhasePosteriors);
}
return countsWithPhasePosteriors;
}
use of org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount in project gatk by broadinstitute.
the class SNPSegmenterUnitTest method testAllelicFractionBasedSegmentation.
/**
* Tests that segments are correctly determined using allelic counts from SNP sites.
* Segment-mean and target-number columns from expected segment file are not checked.
*/
@Test
public void testAllelicFractionBasedSegmentation() {
final String sampleName = "test";
final File snpFile = new File(TEST_SUB_DIR, "snps-simplified-for-allelic-fraction-segmentation.tsv");
final List<AllelicCount> snpCounts = new AllelicCountCollection(snpFile).getCounts();
final TargetCollection<AllelicCount> snps = new HashedListTargetCollection<>(snpCounts);
final File resultFile = createTempFile("snp-segmenter-test-result", ".seg");
SNPSegmenter.writeSegmentFile(snps, sampleName, resultFile);
final File expectedFile = new File(TEST_SUB_DIR, "snp-segmenter-test-expected.seg");
Assert.assertTrue(resultFile.exists(), "SNPSegmenterTest output was not written to temp file: " + resultFile);
final List<SimpleInterval> result = SegmentUtils.readIntervalsFromSegmentFile(resultFile);
final List<SimpleInterval> expected = SegmentUtils.readIntervalsFromSegmentFile(expectedFile);
Assert.assertEquals(result, expected);
}
use of org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount in project gatk by broadinstitute.
the class AlleleFractionLikelihoodsUnitTest method testRefMinor.
//ALT_MINOR <--> REF_MINOR is equivalent to f <--> 1 - f
@Test
public void testRefMinor() {
//pi is just a prefactor so we don't need to test it thoroughly here
final double pi = 0.01;
for (final double f : Arrays.asList(0.1, 0.2, 0.3)) {
for (final double mean : Arrays.asList(0.9, 1.0, 1.1)) {
for (final double variance : Arrays.asList(0.02, 0.01)) {
final AlleleFractionGlobalParameters parameters = new AlleleFractionGlobalParameters(mean, variance, pi);
for (final int a : Arrays.asList(1, 10, 20)) {
//alt count
for (final int r : Arrays.asList(1, 10, 20)) {
//ref count
final AllelicCount count = new AllelicCount(DUMMY, r, a);
final double altMinorLk = AlleleFractionLikelihoods.hetLogLikelihood(parameters, f, count, AlleleFractionIndicator.ALT_MINOR);
final double refMinorLk = AlleleFractionLikelihoods.hetLogLikelihood(parameters, 1 - f, count, AlleleFractionIndicator.REF_MINOR);
Assert.assertEquals(altMinorLk, refMinorLk, 1e-10);
}
}
}
}
}
}
use of org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount in project gatk by broadinstitute.
the class AlleleFractionLikelihoodsUnitTest method testHetLogLikelihoodOutlierProbabilityDependence.
@Test
public void testHetLogLikelihoodOutlierProbabilityDependence() {
final AllelicCount count = new AllelicCount(DUMMY, 11, 37);
final double f = 0.25;
final double mean = 1.0;
final double variance = 0.01;
final double pi1 = 0.1;
final double pi2 = 0.2;
final double pi3 = 0.3;
final AlleleFractionGlobalParameters parameters1 = new AlleleFractionGlobalParameters(mean, variance, pi1);
final AlleleFractionGlobalParameters parameters2 = new AlleleFractionGlobalParameters(mean, variance, pi2);
final AlleleFractionGlobalParameters parameters3 = new AlleleFractionGlobalParameters(mean, variance, pi3);
final double lk1 = AlleleFractionLikelihoods.hetLogLikelihood(parameters1, f, count, AlleleFractionIndicator.ALT_MINOR);
final double lk2 = AlleleFractionLikelihoods.hetLogLikelihood(parameters2, f, count, AlleleFractionIndicator.ALT_MINOR);
final double lk3 = AlleleFractionLikelihoods.hetLogLikelihood(parameters3, f, count, AlleleFractionIndicator.ALT_MINOR);
Assert.assertEquals(lk2 - lk1, log(1 - pi2) - log(1 - pi1), EPSILON);
Assert.assertEquals(lk3 - lk2, log(1 - pi3) - log(1 - pi2), EPSILON);
}
use of org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount in project gatk by broadinstitute.
the class AlleleFractionDataUnitTest method testData.
@Test
public void testData() {
final List<AllelicCount> ac = new ArrayList<>();
final List<SimpleInterval> segments = new ArrayList<>();
// segment 0: hets 0-2
segments.add(new SimpleInterval("chr", 1, 5));
ac.add(new AllelicCount(new SimpleInterval("chr", 1, 1), 0, 5));
ac.add(new AllelicCount(new SimpleInterval("chr", 2, 2), 5, 0));
ac.add(new AllelicCount(new SimpleInterval("chr", 3, 3), 5, 5));
// segment 1: hets 3-4
segments.add(new SimpleInterval("chr", 10, 15));
ac.add(new AllelicCount(new SimpleInterval("chr", 10, 10), 1, 1));
ac.add(new AllelicCount(new SimpleInterval("chr", 11, 11), 2, 2));
final Genome genome = new Genome(AlleleFractionSimulatedData.TRIVIAL_TARGETS, ac);
final SegmentedGenome segmentedGenome = new SegmentedGenome(segments, genome);
final AlleleFractionData dc = new AlleleFractionData(segmentedGenome);
Assert.assertEquals(dc.getNumSegments(), 2);
Assert.assertEquals(dc.getRefCount(0), 0);
Assert.assertEquals(dc.getAltCount(0), 5);
Assert.assertEquals(dc.getReadCount(2), 10);
Assert.assertEquals(dc.getReadCount(3), 2);
Assert.assertEquals(dc.getRefCount(4), 2);
Assert.assertEquals(dc.getAltCount(4), 2);
Assert.assertEquals(dc.getAllelicCount(0).getAltReadCount(), 5);
Assert.assertEquals(dc.getAllelicCount(1).getAltReadCount(), 0);
Assert.assertEquals(dc.getAllelicCount(3).getRefReadCount(), 1);
Assert.assertEquals(dc.getAllelicCount(4).getRefReadCount(), 2);
Assert.assertEquals(dc.getCountsInSegment(0).get(1).getRefReadCount(), 5);
Assert.assertEquals(dc.getCountsInSegment(0).get(1).getAltReadCount(), 0);
final List<Integer> hetsInSegment0 = dc.getHetsInSegment(0);
Assert.assertEquals(hetsInSegment0.size(), 3);
Assert.assertEquals((int) hetsInSegment0.get(0), 0);
Assert.assertEquals((int) hetsInSegment0.get(2), 2);
final List<Integer> hetsInSegment1 = dc.getHetsInSegment(1);
Assert.assertEquals(hetsInSegment1.size(), 2);
Assert.assertEquals((int) hetsInSegment1.get(0), 3);
Assert.assertEquals((int) hetsInSegment1.get(1), 4);
}
Aggregations