Search in sources :

Example 1 with SAMTextWriter

use of htsjdk.samtools.SAMTextWriter 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)

Aggregations

DefaultSerializer (com.esotericsoftware.kryo.DefaultSerializer)1 Kryo (com.esotericsoftware.kryo.Kryo)1 Input (com.esotericsoftware.kryo.io.Input)1 Output (com.esotericsoftware.kryo.io.Output)1 PipelineOptions (com.google.cloud.dataflow.sdk.options.PipelineOptions)1 SAMFileHeader (htsjdk.samtools.SAMFileHeader)1 SAMRecord (htsjdk.samtools.SAMRecord)1 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)1 SAMTextWriter (htsjdk.samtools.SAMTextWriter)1 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 GATKException (org.broadinstitute.hellbender.exceptions.GATKException)1 Utils (org.broadinstitute.hellbender.utils.Utils)1 BwaMemAlignment (org.broadinstitute.hellbender.utils.bwa.BwaMemAlignment)1