Skip to content

Commit

Permalink
feat(extract): add program information to BAM header
Browse files Browse the repository at this point in the history
  • Loading branch information
cauliyang committed Nov 1, 2023
1 parent c54226a commit 583a36f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ codegen-units = 1

[dependencies]
anyhow = { version = "1.0" }
clap = { version = "4.4.7", features = ["wrap_help", "derive", "color"] }
clap = { version = "4.4.7", features = [
"wrap_help",
"derive",
"color",
"cargo",
] }
clap-verbosity-flag = "2.1.0"
colored = "2"
env_logger = "0.10"
Expand Down
16 changes: 13 additions & 3 deletions src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use noodles_sam::{
record::ReadName,
};

use clap::crate_version;
use std::path::PathBuf;

fn writer(file: Option<&PathBuf>, is_bam: bool) -> Result<Box<dyn sam::AlignmentWriter>> {
Expand Down Expand Up @@ -55,12 +56,21 @@ where
{
let read_names = read_read_names(read_ids)?;

let mut reader = bam::reader::Builder.build_from_path(bam_file)?;
let mut reader = bam::reader::Builder.build_from_path(&bam_file)?;
let mut header = reader.read_header()?;

let program = Map::<Program>::new();
let program = Map::<Program>::builder()
.set_name("rboss")
.set_version(crate_version!())
.set_command_line(format!(
"rboss extract {} {} {}",
read_ids,
bam_file.as_ref().to_string_lossy(),
if is_bam { "-b" } else { "" }
))
.build()?;

header.add_comment("extracted with noodles");
header.programs_mut().insert(String::from("rboss"), program);

let mut writer = writer(None, is_bam)?;

Expand Down

0 comments on commit 583a36f

Please sign in to comment.