Search in sources :

Example 6 with AllelicCountWithPhasePosteriorsCollection

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;
}
Also used : AllelicCountWithPhasePosteriorsCollection(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountWithPhasePosteriorsCollection) AllelicCountWithPhasePosteriors(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountWithPhasePosteriors) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) AllelicCount(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with AllelicCountWithPhasePosteriorsCollection

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);
    }
}
Also used : ExomeStandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.ExomeStandardArgumentDefinitions) Arrays(java.util.Arrays) AllelicCountWithPhasePosteriors(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountWithPhasePosteriors) Iterator(java.util.Iterator) AlleleFractionIndicator(org.broadinstitute.hellbender.tools.exome.allelefraction.AlleleFractionIndicator) FileUtils(org.apache.commons.io.FileUtils) StandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions) Test(org.testng.annotations.Test) AllelicCountWithPhasePosteriorsCollection(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountWithPhasePosteriorsCollection) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest) File(java.io.File) List(java.util.List) AlleleFractionState(org.broadinstitute.hellbender.tools.exome.allelefraction.AlleleFractionState) Assert(org.testng.Assert) AlleleFractionSimulatedData(org.broadinstitute.hellbender.tools.exome.allelefraction.AlleleFractionSimulatedData) AllelicPanelOfNormals(org.broadinstitute.hellbender.tools.pon.allelic.AllelicPanelOfNormals) AllelicCountCollection(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountCollection) Collections(java.util.Collections) AllelicCountWithPhasePosteriorsCollection(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountWithPhasePosteriorsCollection) File(java.io.File)

Example 8 with AllelicCountWithPhasePosteriorsCollection

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;
}
Also used : AllelicCountWithPhasePosteriorsCollection(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountWithPhasePosteriorsCollection) AllelicCountWithPhasePosteriors(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountWithPhasePosteriors) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) AllelicCount(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

AllelicCountWithPhasePosteriorsCollection (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountWithPhasePosteriorsCollection)8 AllelicCountCollection (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountCollection)6 AllelicCountWithPhasePosteriors (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountWithPhasePosteriors)6 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)4 AlleleFractionIndicator (org.broadinstitute.hellbender.tools.exome.allelefraction.AlleleFractionIndicator)4 AlleleFractionSimulatedData (org.broadinstitute.hellbender.tools.exome.allelefraction.AlleleFractionSimulatedData)4 AlleleFractionState (org.broadinstitute.hellbender.tools.exome.allelefraction.AlleleFractionState)4 AllelicPanelOfNormals (org.broadinstitute.hellbender.tools.pon.allelic.AllelicPanelOfNormals)4 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)4 Test (org.testng.annotations.Test)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 File (java.io.File)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2 FileUtils (org.apache.commons.io.FileUtils)2 HDF5Library (org.broadinstitute.hdf5.HDF5Library)2 ExomeStandardArgumentDefinitions (org.broadinstitute.hellbender.cmdline.ExomeStandardArgumentDefinitions)2 StandardArgumentDefinitions (org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions)2