Search in sources :

Example 81 with GATKException

use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.

the class BwaAndMarkDuplicatesPipelineSpark method runTool.

@Override
protected void runTool(final JavaSparkContext ctx) {
    try (final BwaSparkEngine engine = new BwaSparkEngine(ctx, indexImageFile, getHeaderForReads(), getReferenceSequenceDictionary())) {
        final JavaRDD<GATKRead> alignedReads = engine.align(getReads());
        final JavaRDD<GATKRead> markedReadsWithOD = MarkDuplicatesSpark.mark(alignedReads, engine.getHeader(), duplicatesScoringStrategy, new OpticalDuplicateFinder(), getRecommendedNumReducers());
        final JavaRDD<GATKRead> markedReads = MarkDuplicatesSpark.cleanupTemporaryAttributes(markedReadsWithOD);
        try {
            ReadsSparkSink.writeReads(ctx, output, referenceArguments.getReferenceFile().getAbsolutePath(), markedReads, engine.getHeader(), shardedOutput ? ReadsWriteFormat.SHARDED : ReadsWriteFormat.SINGLE, getRecommendedNumReducers());
        } catch (IOException e) {
            throw new GATKException("unable to write bam: " + e);
        }
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) OpticalDuplicateFinder(org.broadinstitute.hellbender.utils.read.markduplicates.OpticalDuplicateFinder) BwaSparkEngine(org.broadinstitute.hellbender.tools.spark.bwa.BwaSparkEngine) IOException(java.io.IOException) GATKException(org.broadinstitute.hellbender.exceptions.GATKException)

Example 82 with GATKException

use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.

the class AlignedAssemblyOrExcuse method writeSAMFile.

/**
     * write a SAM file containing records for each aligned contig
     */
static void writeSAMFile(final String samFile, final SAMFileHeader header, final List<AlignedAssemblyOrExcuse> alignedAssemblyOrExcuseList) {
    try (final OutputStream os = BucketUtils.createFile(samFile)) {
        final SAMTextWriter writer = new SAMTextWriter(os);
        writer.setSortOrder(SAMFileHeader.SortOrder.queryname, true);
        writer.setHeader(header);
        final List<String> refNames = getRefNames(header);
        alignedAssemblyOrExcuseList.stream().filter(AlignedAssemblyOrExcuse::isNotFailure).flatMap(aa -> aa.toSAMStreamForAlignmentsOfThisAssembly(header, refNames)).forEach(writer::addAlignment);
        writer.finish();
    } catch (final IOException ioe) {
        throw new GATKException("Can't write SAM file of aligned contigs.", ioe);
    }
}
Also used : IntStream(java.util.stream.IntStream) Output(com.esotericsoftware.kryo.io.Output) java.util(java.util) SAMFileHeader(htsjdk.samtools.SAMFileHeader) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) BwaMemAlignment(org.broadinstitute.hellbender.utils.bwa.BwaMemAlignment) Kryo(com.esotericsoftware.kryo.Kryo) BufferedOutputStream(java.io.BufferedOutputStream) FermiLiteAssembly(org.broadinstitute.hellbender.utils.fermi.FermiLiteAssembly) BucketUtils(org.broadinstitute.hellbender.utils.gcs.BucketUtils) Input(com.esotericsoftware.kryo.io.Input) SAMTextWriter(htsjdk.samtools.SAMTextWriter) OutputStreamWriter(java.io.OutputStreamWriter) OutputStream(java.io.OutputStream) DefaultSerializer(com.esotericsoftware.kryo.DefaultSerializer) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) SAMRecord(htsjdk.samtools.SAMRecord) Stream(java.util.stream.Stream) Contig(org.broadinstitute.hellbender.utils.fermi.FermiLiteAssembly.Contig) PipelineOptions(com.google.cloud.dataflow.sdk.options.PipelineOptions) Utils(org.broadinstitute.hellbender.utils.Utils) BwaMemAlignmentUtils(org.broadinstitute.hellbender.utils.bwa.BwaMemAlignmentUtils) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) Connection(org.broadinstitute.hellbender.utils.fermi.FermiLiteAssembly.Connection) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) SAMTextWriter(htsjdk.samtools.SAMTextWriter) IOException(java.io.IOException) GATKException(org.broadinstitute.hellbender.exceptions.GATKException)

Example 83 with GATKException

use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.

the class AlignedAssemblyOrExcuse method writeIntervalFile.

/**
     * write a file describing each interval
     */
public static void writeIntervalFile(final String intervalFile, final SAMFileHeader header, final List<SVInterval> intervals, final List<AlignedAssemblyOrExcuse> intervalDispositions) {
    final Map<Integer, AlignedAssemblyOrExcuse> resultsMap = new HashMap<>();
    intervalDispositions.forEach(alignedAssemblyOrExcuse -> resultsMap.put(alignedAssemblyOrExcuse.getAssemblyId(), alignedAssemblyOrExcuse));
    try (final OutputStreamWriter writer = new OutputStreamWriter(new BufferedOutputStream(BucketUtils.createFile(intervalFile)))) {
        final List<SAMSequenceRecord> contigs = header.getSequenceDictionary().getSequences();
        final int nIntervals = intervals.size();
        for (int intervalId = 0; intervalId != nIntervals; ++intervalId) {
            final SVInterval interval = intervals.get(intervalId);
            final String seqName = contigs.get(interval.getContig()).getSequenceName();
            final AlignedAssemblyOrExcuse alignedAssemblyOrExcuse = resultsMap.get(intervalId);
            final String disposition;
            if (alignedAssemblyOrExcuse == null) {
                disposition = "unknown";
            } else if (alignedAssemblyOrExcuse.getErrorMessage() != null) {
                disposition = alignedAssemblyOrExcuse.getErrorMessage();
            } else {
                disposition = "produced " + alignedAssemblyOrExcuse.getAssembly().getNContigs() + " contigs";
            }
            writer.write(intervalId + "\t" + seqName + ":" + interval.getStart() + "-" + interval.getEnd() + "\t" + disposition + "\n");
        }
    } catch (final IOException ioe) {
        throw new GATKException("Can't write intervals file " + intervalFile, ioe);
    }
}
Also used : SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) IOException(java.io.IOException) OutputStreamWriter(java.io.OutputStreamWriter) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 84 with GATKException

use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk by broadinstitute.

the class ParallelCopyGCSDirectoryIntoHDFSSpark method readChunkToHdfs.

private static final Tuple2<Integer, String> readChunkToHdfs(final String inputGCSPathFinal, final long chunkSize, final Integer chunkNum, final String outputDirectory) {
    final Path gcsPath = IOUtils.getPath(inputGCSPathFinal);
    final String basename = gcsPath.getName(gcsPath.getNameCount() - 1).toString();
    org.apache.hadoop.fs.Path outputPath = new org.apache.hadoop.fs.Path(outputDirectory);
    final String chunkPath = outputPath + "/" + basename + ".chunk." + chunkNum;
    try (SeekableByteChannel channel = Files.newByteChannel(gcsPath);
        final OutputStream outputStream = new BufferedOutputStream(BucketUtils.createFile(chunkPath))) {
        final long start = chunkSize * (long) chunkNum;
        channel.position(start);
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect((int) Math.min(SIXTY_FOUR_MIB, chunkSize));
        long bytesRead = 0;
        while (channel.read(byteBuffer) > 0) {
            byteBuffer.flip();
            while (byteBuffer.hasRemaining() && bytesRead < chunkSize) {
                byte b = byteBuffer.get();
                outputStream.write(b);
                bytesRead++;
            }
            if (bytesRead == chunkSize) {
                break;
            }
            if (bytesRead > chunkSize) {
                throw new GATKException("Encountered an unknown error condition and read too many bytes; output file may be corrupt");
            }
            byteBuffer.clear();
        }
    } catch (IOException e) {
        throw new GATKException(e.getMessage() + "; inputGCSPathFinal = " + inputGCSPathFinal, e);
    }
    return new Tuple2<>(chunkNum, chunkPath);
}
Also used : Path(java.nio.file.Path) ByteBuffer(java.nio.ByteBuffer) SeekableByteChannel(java.nio.channels.SeekableByteChannel) Tuple2(scala.Tuple2) GATKException(org.broadinstitute.hellbender.exceptions.GATKException)

Example 85 with GATKException

use of org.broadinstitute.hellbender.exceptions.GATKException in project gatk-protected by broadinstitute.

the class CombineReadCounts method createMergeTemporalFile.

private File createMergeTemporalFile() {
    final File result;
    try {
        result = File.createTempFile("read-count-merge", ".tab");
    } catch (final IOException e) {
        throw new GATKException("Could not create temporal merge file", e);
    }
    result.deleteOnExit();
    return result;
}
Also used : GATKException(org.broadinstitute.hellbender.exceptions.GATKException)

Aggregations

GATKException (org.broadinstitute.hellbender.exceptions.GATKException)96 IOException (java.io.IOException)19 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)13 CigarElement (htsjdk.samtools.CigarElement)12 ArrayList (java.util.ArrayList)10 UserException (org.broadinstitute.hellbender.exceptions.UserException)10 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)8 Cigar (htsjdk.samtools.Cigar)7 File (java.io.File)6 SAMFileHeader (htsjdk.samtools.SAMFileHeader)5 OutputStream (java.io.OutputStream)5 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Utils (org.broadinstitute.hellbender.utils.Utils)4 Tuple2 (scala.Tuple2)4 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)3 BufferedOutputStream (java.io.BufferedOutputStream)3 InputStream (java.io.InputStream)3 BigInteger (java.math.BigInteger)3 java.util (java.util)3