Search in sources :

Example 16 with HiddenStateSegmentRecord

use of org.broadinstitute.hellbender.utils.hmm.segmentation.HiddenStateSegmentRecord in project gatk by broadinstitute.

the class ConvertGSVariantsToSegmentsIntegrationTest method composeExpectedSegments.

private List<HiddenStateSegmentRecord<CopyNumberTriState, Target>> composeExpectedSegments(final File vcf, final TargetCollection<Target> targets) throws IOException {
    final VCFFileReader reader = new VCFFileReader(vcf, false);
    final List<HiddenStateSegmentRecord<CopyNumberTriState, Target>> result = new ArrayList<>();
    reader.iterator().forEachRemaining(vc -> {
        final int targetCount = targets.indexRange(vc).size();
        for (final Genotype genotype : vc.getGenotypes()) {
            final int cn = Integer.parseInt(genotype.getExtendedAttribute("CN").toString());
            final double[] cnp = Stream.of(genotype.getExtendedAttribute("CNP").toString().replaceAll("\\[\\]", "").split(",")).mapToDouble(Double::parseDouble).toArray();
            final double cnpSum = MathUtils.approximateLog10SumLog10(cnp);
            final CopyNumberTriState call = expectedCall(cn);
            final double exactLog10Prob = expectedExactLog10(call, cnp);
            final HiddenStateSegment<CopyNumberTriState, Target> expectedSegment = new HiddenStateSegment<>(new SimpleInterval(vc), targetCount, Double.parseDouble(genotype.getExtendedAttribute("CNF").toString()), 0.000, call, -10.0 * exactLog10Prob, Double.NaN, Double.NaN, Double.NaN, -10.0 * (cnp[ConvertGSVariantsToSegments.NEUTRAL_COPY_NUMBER_DEFAULT] - cnpSum));
            result.add(new HiddenStateSegmentRecord<>(genotype.getSampleName(), expectedSegment));
        }
    });
    return result;
}
Also used : VCFFileReader(htsjdk.variant.vcf.VCFFileReader) ArrayList(java.util.ArrayList) Genotype(htsjdk.variant.variantcontext.Genotype) Target(org.broadinstitute.hellbender.tools.exome.Target) CopyNumberTriState(org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState) HiddenStateSegment(org.broadinstitute.hellbender.utils.hmm.segmentation.HiddenStateSegment) HiddenStateSegmentRecord(org.broadinstitute.hellbender.utils.hmm.segmentation.HiddenStateSegmentRecord) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval)

Aggregations

HiddenStateSegmentRecord (org.broadinstitute.hellbender.utils.hmm.segmentation.HiddenStateSegmentRecord)16 File (java.io.File)12 IOException (java.io.IOException)12 java.util (java.util)10 Collectors (java.util.stream.Collectors)10 IntStream (java.util.stream.IntStream)10 Target (org.broadinstitute.hellbender.tools.exome.Target)10 CopyNumberTriState (org.broadinstitute.hellbender.tools.exome.germlinehmm.CopyNumberTriState)10 GATKProtectedMathUtils (org.broadinstitute.hellbender.utils.GATKProtectedMathUtils)10 Genotype (htsjdk.variant.variantcontext.Genotype)8 UserException (org.broadinstitute.hellbender.exceptions.UserException)8 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 Sets (com.google.common.collect.Sets)6 BiFunction (java.util.function.BiFunction)6 Predicate (java.util.function.Predicate)6 Stream (java.util.stream.Stream)6 Nonnull (javax.annotation.Nonnull)6 Nullable (javax.annotation.Nullable)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)6