pub fn try_into_sam_record(
        &self,
        reference_assembly: &[fasta::Record],
        reference_sequences: &sam::header::ReferenceSequences,
        compression_header: &CompressionHeader,
    ) -> io::Result<sam::Record> {
        let mut builder = sam::Record::builder();

        let raw_read_name = str::from_utf8(self.read_name())
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;

        if raw_read_name != "*" {
            let read_name = raw_read_name
                .parse()
                .map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;

            builder = builder.set_read_name(read_name);
        }

        builder = builder.set_flags(self.bam_flags());

        if let Some(reference_sequence_name) =
            get_reference_sequence_name(reference_sequences, self.reference_sequence_id())?
        {
            builder = builder.set_reference_sequence_name(reference_sequence_name);
        }

        if let Some(alignment_start) = self.alignment_start() {
            builder = builder.set_position(alignment_start);
        }

        if let Some(mapping_quality) = self.mapping_quality() {
            builder = builder.set_mapping_quality(mapping_quality);
        }

        let cigar = resolve_features(self.features(), self.read_length() as i32);
        builder = builder.set_cigar(cigar);

        if let Some(mate_reference_sequence_name) = get_reference_sequence_name(
            reference_sequences,
            self.next_fragment_reference_sequence_id(),
        )? {
            builder = builder.set_mate_reference_sequence_name(mate_reference_sequence_name);
        }

        if let Some(next_mate_alignment_start) = self.next_mate_alignment_start() {
            builder = builder.set_mate_position(next_mate_alignment_start);
        }

        builder = builder.set_template_length(self.template_size());

        if self.read_length() > 0 {
            let sequence = if let Some(reference_sequence_id) = self.reference_sequence_id() {
                let reference_sequence_record = usize::try_from(i32::from(reference_sequence_id))
                    .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
                    .and_then(|id| {
                        reference_assembly.get(id).ok_or_else(|| {
                            io::Error::new(io::ErrorKind::InvalidData, "missing reference sequence")
                        })
                    })?;

                let raw_bases = resolve_bases(
                    reference_sequence_record,
                    compression_header,
                    self.features(),
                    self.alignment_start().map(i32::from).unwrap_or_default(),
                    self.read_length() as usize,
                );

                bytes_to_sequence(&raw_bases)?
            } else {
                bytes_to_sequence(self.bases())?
            };

            builder = builder.set_sequence(sequence);
        }

        if !self.quality_scores().is_empty() {
            let quality_scores = bytes_to_quality_scores(self.quality_scores())?;
            builder = builder.set_quality_scores(quality_scores);
        }

        if !self.tags().is_empty() {
            let data = tags_to_data(self.tags())?;
            builder = builder.set_data(data);
        }

        builder
            .build()
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
    }
/// Converts this CRAM record to a SAM record.
Converts this CRAM record to a SAM record.
Converts this CRAM record to a SAM record .
pub fn try_into_sam_record(
        &self,
        reference_assembly: &[fasta::Record],
        reference_sequences: &sam::header::ReferenceSequences,
        compression_header: &CompressionHeader,
    ) -> io::Result<sam::Record> {
        let mut builder = sam::Record::builder();
        let raw_read_name = str::from_utf8(self.read_name())
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;
        if raw_read_name != "*" {
            let read_name = raw_read_name
                .parse()
                .map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;
            builder = builder.set_read_name(read_name);
        }
        builder = builder.set_flags(self.bam_flags());
        if let Some(reference_sequence_name) =
            get_reference_sequence_name(reference_sequences, self.reference_sequence_id())?
        {
            builder = builder.set_reference_sequence_name(reference_sequence_name);
        }
        if let Some(alignment_start) = self.alignment_start() {
            builder = builder.set_position(alignment_start);
        }
        if let Some(mapping_quality) = self.mapping_quality() {
            builder = builder.set_mapping_quality(mapping_quality);
        }
        let cigar = resolve_features(self.features(), self.read_length() as i32);
        builder = builder.set_cigar(cigar);
        if let Some(mate_reference_sequence_name) = get_reference_sequence_name(
            reference_sequences,
            self.next_fragment_reference_sequence_id(),
        )? {
            builder = builder.set_mate_reference_sequence_name(mate_reference_sequence_name);
        }
        if let Some(next_mate_alignment_start) = self.next_mate_alignment_start() {
            builder = builder.set_mate_position(next_mate_alignment_start);
        }
        builder = builder.set_template_length(self.template_size());
        if self.read_length() > 0 {
            let sequence = if let Some(reference_sequence_id) = self.reference_sequence_id() {
                let reference_sequence_record = usize::try_from(i32::from(reference_sequence_id))
                    .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
                    .and_then(|id| {
                        reference_assembly.get(id).ok_or_else(|| {
                            io::Error::new(io::ErrorKind::InvalidData, "missing reference sequence")
                        })
                    })?;
                let raw_bases = resolve_bases(
                    reference_sequence_record,
                    compression_header,
                    self.features(),
                    self.alignment_start().map(i32::from).unwrap_or_default(),
                    self.read_length() as usize,
                );
                bytes_to_sequence(&raw_bases)?
            } else {
                bytes_to_sequence(self.bases())?
            };
            builder = builder.set_sequence(sequence);
        }
        if !self.quality_scores().is_empty() {
            let quality_scores = bytes_to_quality_scores(self.quality_scores())?;
            builder = builder.set_quality_scores(quality_scores);
        }
        if !self.tags().is_empty() {
            let data = tags_to_data(self.tags())?;
            builder = builder.set_data(data);
        }
        builder
            .build()
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
    }
pub fn try_into_sam_record ( & self , reference_assembly : & [ fasta :: Record ] , reference_sequences : & sam :: header :: ReferenceSequences , compression_header : & CompressionHeader , ) -> io :: Result < sam :: Record > { let mut builder = sam :: Record :: builder ( ) ; let raw_read_name = str :: from_utf8 ( self . read_name ( ) ) . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: InvalidInput , e ) ) ? ; if raw_read_name != " " { let read_name = raw_read_name . parse ( ) . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: InvalidInput , e ) ) ? ; builder = builder . set_read_name ( read_name ) ; } builder = builder . set_flags ( self . bam_flags ( ) ) ; if let Some ( reference_sequence_name ) = get_reference_sequence_name ( reference_sequences , self . reference_sequence_id ( ) ) ? { builder = builder . set_reference_sequence_name ( reference_sequence_name ) ; } if let Some ( alignment_start ) = self . alignment_start ( ) { builder = builder . set_position ( alignment_start ) ; } if let Some ( mapping_quality ) = self . mapping_quality ( ) { builder = builder . set_mapping_quality ( mapping_quality ) ; } let cigar = resolve_features ( self . features ( ) , self . read_length ( ) as i32 ) ; builder = builder . set_cigar ( cigar ) ; if let Some ( mate_reference_sequence_name ) = get_reference_sequence_name ( reference_sequences , self . next_fragment_reference_sequence_id ( ) , ) ? { builder = builder . set_mate_reference_sequence_name ( mate_reference_sequence_name ) ; } if let Some ( next_mate_alignment_start ) = self . next_mate_alignment_start ( ) { builder = builder . set_mate_position ( next_mate_alignment_start ) ; } builder = builder . set_template_length ( self . template_size ( ) ) ; if self . read_length ( ) > 0 { let sequence = if let Some ( reference_sequence_id ) = self . reference_sequence_id ( ) { let reference_sequence_record = usize :: try_from ( i32 :: from ( reference_sequence_id ) ) . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: InvalidData , e ) ) . and_then ( | id | { reference_assembly . get ( id ) . ok_or_else ( | | { io :: Error :: new ( io :: ErrorKind :: InvalidData , " " ) } ) } ) ? ; let raw_bases = resolve_bases ( reference_sequence_record , compression_header , self . features ( ) , self . alignment_start ( ) . map ( i32 :: from ) . unwrap_or_default ( ) , self . read_length ( ) as usize , ) ; bytes_to_sequence ( & raw_bases ) ? } else { bytes_to_sequence ( self . bases ( ) ) ? } ; builder = builder . set_sequence ( sequence ) ; } if ! self . quality_scores ( ) . is_empty ( ) { let quality_scores = bytes_to_quality_scores ( self . quality_scores ( ) ) ? ; builder = builder . set_quality_scores ( quality_scores ) ; } if ! self . tags ( ) . is_empty ( ) { let data = tags_to_data ( self . tags ( ) ) ? ; builder = builder . set_data ( data ) ; } builder . build ( ) . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: InvalidData , e ) ) }
Converts this CRAM record to a SAM record.
Converts this CRAM record to a SAM record .
&self
reference_assembly
&[fasta::Record]
reference_sequences
&sam::header::ReferenceSequences
compression_header
&CompressionHeader
&self
reference_assembly
&[fasta::Record]
reference_sequences
&sam::header::ReferenceSequences
compression_header
&CompressionHeader