First, thank you to all the contributors for this awesome rust crate :)
Sadly, I'm struggling with some basic BAM file editing...
Below is a minimal example:
fn main()
{
let mut reader = bam::io::reader::Builder::default().build_from_path(input_path)?;
let mut writer = bam::io::writer::Builder::default().build_from_path(output_path)?;
let header = reader.read_header()?;
writer.write_header(&header)?;
for result in reader.record_bufs(&header) {
let mut record = result?;
let tag = record.data().get(tag_name).unwrap();
let mbc = match tag {
noodles::sam::alignment::record_buf::data::field::Value::String(val) => {
format!("{}", val)
}
_ = { String::from("") }
};
*record.name_mut() = Some(noodles::sam::alignment::record_buf::Name::from(
format!("{:?}{}", record.name(), mbc).as_bytes(),
));
writer.write_record(&header, record);
}
Here, record is of type RecordBuf, since according to what I found this is the only way to mutate BAM records (see this closed issue you answered a while ago https://github.com/zaeleus/noodles/issues/258)
Now, how can I write these modified records into a bam file? I found no way to turn RecordBuf into Record in the documentation.
Hello !
First, thank you to all the contributors for this awesome rust crate :)
Sadly, I'm struggling with some basic BAM file editing... Below is a minimal example:
Here, record is of type RecordBuf, since according to what I found this is the only way to mutate BAM records (see this closed issue you answered a while ago https://github.com/zaeleus/noodles/issues/258)
Now, how can I write these modified records into a bam file? I found no way to turn RecordBuf into Record in the documentation.
Thank you for your time!