Skip to content

How to update an existing tag in a BAM record? #240

Answered by zaeleus
ghuls asked this question in Q&A
Discussion options

You must be logged in to vote

As @d-cameron mentioned, bam::Record is immutable. sam::alignment::RecordBuf is the mutable form of an alignment record. You can convert a bam::Record to a sam::alignment::RecordBuf using RecordBuf::try_from_alignment_record.

for result in reader.records() {
    let record = result?;
    let mut record_buf = RecordBuf::try_from_alignment_record(&header, &record)?;
    // ...
}

Alternatively, the reader supports reading records as record buffers via Reader::read_record_buf and Reader::record_bufs.

Here's a full example:

// cargo add [email protected] --features bam,sam

use std::{env, io};

use noodles::{
    bam,
    sam::{
        self,
        alignment::{io::Write, record::data::field::Tag,

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@zaeleus
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by ghuls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
3 participants