Skip to content

Commit

Permalink
bam/examples/reheader: Add self program record
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Apr 12, 2024
1 parent 0421db9 commit f23008d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions noodles-bam/examples/bam_reheader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,30 @@
use std::{env, io};

use noodles_bam as bam;
use noodles_sam::header::record::value::{
map::{builder::BuildError, program::tag, Program},
Map,
};

fn build_self_program() -> Result<Map<Program>, BuildError> {
let args = env::args().collect::<Vec<_>>().join(" ");

Map::builder()
.insert(tag::NAME, env!("CARGO_BIN_NAME"))
.insert(tag::VERSION, env!("CARGO_PKG_VERSION"))
.insert(tag::COMMAND_LINE, args)
.build()
}

fn main() -> io::Result<()> {
fn main() -> Result<(), Box<dyn std::error::Error>> {
let src = env::args().nth(1).expect("missing src");

let mut reader = bam::io::reader::Builder.build_from_path(src)?;

let mut header = reader.read_header()?;

let pg = build_self_program()?;
header.programs_mut().add("noodles", pg)?;

header.add_comment("a comment added by noodles-bam");

let stdout = io::stdout().lock();
Expand Down

0 comments on commit f23008d

Please sign in to comment.