Search in sources :

Example 1 with HiddenStateSegmentRecordWriter

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

the class CoverageModelEMWorkspace method writeCopyRatioPosteriors.

/**
     * Saves copy-ratio-related posteriors to disk.
     *
     * TODO github/gatk-protected issue #855 -- write local copy ratio posteriors as well
     *
     * @param outputPath the output path
     */
protected void writeCopyRatioPosteriors(final String outputPath) {
    logger.info("Saving copy ratio posteriors...");
    final List<List<HiddenStateSegmentRecord<STATE, Target>>> segments = getCopyRatioSegments();
    final String segmentsPath = new File(outputPath, CoverageModelGlobalConstants.COPY_RATIO_SEGMENTS_SUBDIR).getAbsolutePath();
    createOutputPath(segmentsPath);
    sampleIndexStream().forEach(si -> {
        final File segmentsFile = new File(segmentsPath, processedSampleNameList.get(si) + ".seg");
        try (final HiddenStateSegmentRecordWriter<STATE, Target> segWriter = new HiddenStateSegmentRecordWriter<>(segmentsFile)) {
            segWriter.writeAllRecords(segments.get(si));
        } catch (final IOException ex) {
            throw new UserException.CouldNotCreateOutputFile(segmentsFile, "Could not create copy ratio segments file");
        }
    });
    /* write the Viterbi copy number chains as a sample-target matrix */
    if (config.extendedPosteriorOutputEnabled()) {
        final File copyRatioViterbiFile = new File(outputPath, CoverageModelGlobalConstants.COPY_RATIO_VITERBI_FILENAME);
        final List<String> targetNames = processedReadCounts.targets().stream().map(Target::getName).collect(Collectors.toList());
        Nd4jIOUtils.writeNDArrayMatrixToTextFile(getViterbiAsNDArray(segments), copyRatioViterbiFile, "VITERBI_COPY_RATIO_CHAIN", targetNames, processedSampleNameList);
    }
}
Also used : HiddenStateSegmentRecordWriter(org.broadinstitute.hellbender.utils.hmm.segmentation.HiddenStateSegmentRecordWriter) IOException(java.io.IOException) UserException(org.broadinstitute.hellbender.exceptions.UserException) File(java.io.File)

Example 2 with HiddenStateSegmentRecordWriter

use of org.broadinstitute.hellbender.utils.hmm.segmentation.HiddenStateSegmentRecordWriter in project gatk-protected by broadinstitute.

the class CoverageModelEMWorkspace method writeCopyRatioPosteriors.

/**
     * Saves copy-ratio-related posteriors to disk.
     *
     * TODO github/gatk-protected issue #855 -- write local copy ratio posteriors as well
     *
     * @param outputPath the output path
     */
protected void writeCopyRatioPosteriors(final String outputPath) {
    logger.info("Saving copy ratio posteriors...");
    final List<List<HiddenStateSegmentRecord<STATE, Target>>> segments = getCopyRatioSegments();
    final String segmentsPath = new File(outputPath, CoverageModelGlobalConstants.COPY_RATIO_SEGMENTS_SUBDIR).getAbsolutePath();
    createOutputPath(segmentsPath);
    sampleIndexStream().forEach(si -> {
        final File segmentsFile = new File(segmentsPath, processedSampleNameList.get(si) + ".seg");
        try (final HiddenStateSegmentRecordWriter<STATE, Target> segWriter = new HiddenStateSegmentRecordWriter<>(segmentsFile)) {
            segWriter.writeAllRecords(segments.get(si));
        } catch (final IOException ex) {
            throw new UserException.CouldNotCreateOutputFile(segmentsFile, "Could not create copy ratio segments file");
        }
    });
    /* write the Viterbi copy number chains as a sample-target matrix */
    if (config.extendedPosteriorOutputEnabled()) {
        final File copyRatioViterbiFile = new File(outputPath, CoverageModelGlobalConstants.COPY_RATIO_VITERBI_FILENAME);
        final List<String> targetNames = processedReadCounts.targets().stream().map(Target::getName).collect(Collectors.toList());
        Nd4jIOUtils.writeNDArrayMatrixToTextFile(getViterbiAsNDArray(segments), copyRatioViterbiFile, "VITERBI_COPY_RATIO_CHAIN", targetNames, processedSampleNameList);
    }
}
Also used : HiddenStateSegmentRecordWriter(org.broadinstitute.hellbender.utils.hmm.segmentation.HiddenStateSegmentRecordWriter) IOException(java.io.IOException) UserException(org.broadinstitute.hellbender.exceptions.UserException) File(java.io.File)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 UserException (org.broadinstitute.hellbender.exceptions.UserException)2 HiddenStateSegmentRecordWriter (org.broadinstitute.hellbender.utils.hmm.segmentation.HiddenStateSegmentRecordWriter)2