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

        let raw_read_name = self
            .read_name()
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))
            .and_then(|c_read_name| {
                c_read_name
                    .to_str()
                    .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.flags());

        if let Some(reference_sequence) =
            self.reference_sequence(reference_sequences).transpose()?
        {
            builder = builder.set_reference_sequence_name(reference_sequence.name().clone());
        }

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

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

        let cigar = self.cigar().try_into()?;
        builder = builder.set_cigar(cigar);

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

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

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

        if !self.sequence().is_empty() {
            builder = builder.set_sequence(self.sequence().into());
        }

        if !self.quality_scores().is_empty() {
            let quality_scores = self
                .quality_scores()
                .try_into()
                .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;

            builder = builder.set_quality_scores(quality_scores);
        }

        let data = self
            .data()
            .try_into()
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;

        builder = builder.set_data(data);

        builder
            .build()
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
    }
/// Converts this record to a SAM record.
///
/// # Examples
///
/// ```
/// # use std::io;
/// use noodles_bam as bam;
/// use noodles_sam as sam;
///
/// let reference_sequences = sam::header::ReferenceSequences::default();
///
/// let record = bam::Record::default();
/// let sam_record = record.try_into_sam_record(&reference_sequences)?;
///
/// assert_eq!(sam_record, sam::Record::default());
/// # Ok::<(), io::Error>(())
/// ```
Converts this record to a SAM record.
Converts this record to a SAM record .
pub fn try_into_sam_record(
        &self,
        reference_sequences: &sam::header::ReferenceSequences,
    ) -> io::Result<sam::Record> {
        let mut builder = sam::Record::builder();
        let raw_read_name = self
            .read_name()
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))
            .and_then(|c_read_name| {
                c_read_name
                    .to_str()
                    .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.flags());
        if let Some(reference_sequence) =
            self.reference_sequence(reference_sequences).transpose()?
        {
            builder = builder.set_reference_sequence_name(reference_sequence.name().clone());
        }
        if let Some(position) = self.position() {
            builder = builder.set_position(position);
        }
        if let Some(mapping_quality) = self.mapping_quality() {
            builder = builder.set_mapping_quality(mapping_quality);
        }
        let cigar = self.cigar().try_into()?;
        builder = builder.set_cigar(cigar);
        if let Some(mate_reference_sequence_name) =
            get_reference_sequence_name(reference_sequences, self.mate_reference_sequence_id())?
        {
            builder = builder.set_mate_reference_sequence_name(mate_reference_sequence_name);
        }
        if let Some(mate_position) = self.mate_position() {
            builder = builder.set_mate_position(mate_position);
        }
        builder = builder.set_template_length(self.template_length());
        if !self.sequence().is_empty() {
            builder = builder.set_sequence(self.sequence().into());
        }
        if !self.quality_scores().is_empty() {
            let quality_scores = self
                .quality_scores()
                .try_into()
                .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
            builder = builder.set_quality_scores(quality_scores);
        }
        let data = self
            .data()
            .try_into()
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
        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_sequences : & sam :: header :: ReferenceSequences , ) -> io :: Result < sam :: Record > { let mut builder = sam :: Record :: builder ( ) ; let raw_read_name = self . read_name ( ) . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: InvalidInput , e ) ) . and_then ( | c_read_name | { c_read_name . to_str ( ) . 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 . flags ( ) ) ; if let Some ( reference_sequence ) = self . reference_sequence ( reference_sequences ) . transpose ( ) ? { builder = builder . set_reference_sequence_name ( reference_sequence . name ( ) . clone ( ) ) ; } if let Some ( position ) = self . position ( ) { builder = builder . set_position ( position ) ; } if let Some ( mapping_quality ) = self . mapping_quality ( ) { builder = builder . set_mapping_quality ( mapping_quality ) ; } let cigar = self . cigar ( ) . try_into ( ) ? ; builder = builder . set_cigar ( cigar ) ; if let Some ( mate_reference_sequence_name ) = get_reference_sequence_name ( reference_sequences , self . mate_reference_sequence_id ( ) ) ? { builder = builder . set_mate_reference_sequence_name ( mate_reference_sequence_name ) ; } if let Some ( mate_position ) = self . mate_position ( ) { builder = builder . set_mate_position ( mate_position ) ; } builder = builder . set_template_length ( self . template_length ( ) ) ; if ! self . sequence ( ) . is_empty ( ) { builder = builder . set_sequence ( self . sequence ( ) . into ( ) ) ; } if ! self . quality_scores ( ) . is_empty ( ) { let quality_scores = self . quality_scores ( ) . try_into ( ) . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: InvalidData , e ) ) ? ; builder = builder . set_quality_scores ( quality_scores ) ; } let data = self . data ( ) . try_into ( ) . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: InvalidData , e ) ) ? ; builder = builder . set_data ( data ) ; builder . build ( ) . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: InvalidData , e ) ) }
Converts this record to a SAM record.
Converts this record to a SAM record .
&self
reference_sequences
&sam::header::ReferenceSequences
&self
reference_sequences
&sam::header::ReferenceSequences
examples
None
use std::io;
use noodles_bam as bam;
use noodles_sam as sam.

let reference_sequences = sam::header::ReferenceSequences::default().

let record = bam::Record::default();
let sam_record = record.try_into_sam_record(&reference_sequences)?.

assert_eq!(sam_record, sam::Record::default()).
use noodles_bam as bam ; use noodles_sam as sam . let reference_sequences = sam :: header :: ReferenceSequences :: default () . let record = bam :: Record :: default () ; let sam_record = record . try_into_sam_record ( &reference_sequences ) ? . assert_eq! ( sam_record sam :: Record :: default () ) .
ok::<(), io::error>(())
None