use of org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountWithPhasePosteriorsCollection in project gatk 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.AllelicCountWithPhasePosteriorsCollection in project gatk-protected by broadinstitute.
the class CalculatePulldownPhasePosteriorsIntegrationTest method testRun.
private void testRun(final String[] arguments, final String outputFileName) {
runCommandLine(arguments);
//only check that file is created and can be read as an AllelicCountWithPhasePosteriorsCollection,
//do not check for correctness of results (which is tested by testCalculatePhasePosteriors)
final File outputFile = new File(outputFileName);
Assert.assertTrue(outputFile.isFile(), outputFile.getAbsolutePath() + " is not a file.");
Assert.assertTrue(outputFile.length() > 0);
try {
//check that file has:
// - at least two lines and all either start with "#" or contain at least one "\t"
// - at least two lines with tab (column names + 1 SNP)
final List<String> outputLines = FileUtils.readLines(outputFile);
Assert.assertTrue(outputLines.size() >= 2);
Assert.assertEquals(outputLines.stream().filter(l -> l.contains("\t") || l.startsWith("#")).count(), outputLines.size());
Assert.assertTrue(outputLines.stream().filter(l -> l.split("\t").length > 2 && !l.startsWith("#")).count() > 2, "File: " + outputFile + " does not seem to have at least one SNP and a header.");
final AllelicCountWithPhasePosteriorsCollection counts = new AllelicCountWithPhasePosteriorsCollection(outputFile);
} catch (final Exception e) {
Assert.fail("Could not create AllelicCountWithPhasePosteriorsCollection from file: " + outputFile, e);
}
}
use of org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountWithPhasePosteriorsCollection 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;
}
Aggregations