Skip to content

Commit

Permalink
add bamscale argument for #53
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Dec 13, 2024
1 parent f26bfed commit 3685f94
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
9 changes: 9 additions & 0 deletions gtars/src/uniwig/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ pub fn create_uniwig_cli() -> Command {
.help("Integer value for stepsize")
.required(true),
)
.arg(
Arg::new("bamscale")
.long("bamscale")
.short('e')
.default_value("1")
.value_parser(clap::value_parser!(i32))
.help("Integer for scaling bam read values, default is 1")
.required(false),
)

Check warning on line 58 in gtars/src/uniwig/cli.rs

View check run for this annotation

Codecov / codecov/patch

gtars/src/uniwig/cli.rs#L50-L58

Added lines #L50 - L58 were not covered by tests
.arg(
Arg::new("fileheader")
.long("fileheader")
Expand Down
5 changes: 3 additions & 2 deletions gtars/src/uniwig/counting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,7 @@ pub fn variable_shifted_bam_to_bw( records: &mut Box<Query<noodles::bgzf::reader
chromosome_name: &String,
out_sel: &str,
write_fd: Arc<Mutex<PipeWriter>>,
bam_scale:i32,
) -> Result<(), BAMRecordError> {
let mut write_lock = write_fd.lock().unwrap(); // Acquire lock for writing
let mut writer = BufWriter::new(&mut *write_lock);
Expand Down Expand Up @@ -1372,7 +1373,7 @@ pub fn variable_shifted_bam_to_bw( records: &mut Box<Query<noodles::bgzf::reader
if count != prev_count {
let single_line = format!(
"{}\t{}\t{}\t{}\n",
chromosome_name, bg_prev_coord, coordinate_position, prev_count
chromosome_name, bg_prev_coord, coordinate_position, prev_count/bam_scale
);
writer.write_all(single_line.as_bytes())?;
writer.flush()?;
Expand Down Expand Up @@ -1412,7 +1413,7 @@ pub fn variable_shifted_bam_to_bw( records: &mut Box<Query<noodles::bgzf::reader
if count != prev_count {
let single_line = format!(
"{}\t{}\t{}\t{}\n",
chromosome_name, bg_prev_coord, coordinate_position, prev_count
chromosome_name, bg_prev_coord, coordinate_position, prev_count/bam_scale
);
writer.write_all(single_line.as_bytes())?;
writer.flush()?;
Expand Down
20 changes: 18 additions & 2 deletions gtars/src/uniwig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ pub fn run_uniwig(matches: &ArgMatches) {
.get_one::<i32>("threads")
.expect("requires integer value");

let bam_scale = matches
.get_one::<i32>("bamscale")
.expect("requires int value");

Check warning on line 155 in gtars/src/uniwig/mod.rs

View check run for this annotation

Codecov / codecov/patch

gtars/src/uniwig/mod.rs#L152-L155

Added lines #L152 - L155 were not covered by tests
let score = matches.get_one::<bool>("score").unwrap_or_else(|| &false);
let bam_shift = matches.get_one::<bool>("no-bamshift").unwrap_or_else(|| &true);

Check warning on line 157 in gtars/src/uniwig/mod.rs

View check run for this annotation

Codecov / codecov/patch

gtars/src/uniwig/mod.rs#L157

Added line #L157 was not covered by tests

Expand Down Expand Up @@ -176,6 +180,7 @@ pub fn run_uniwig(matches: &ArgMatches) {
*zoom,
*debug,
*bam_shift,
*bam_scale,

Check warning on line 183 in gtars/src/uniwig/mod.rs

View check run for this annotation

Codecov / codecov/patch

gtars/src/uniwig/mod.rs#L182-L183

Added lines #L182 - L183 were not covered by tests
)
.expect("Uniwig failed.");
}
Expand All @@ -200,6 +205,7 @@ pub fn uniwig_main(
zoom: i32,
debug: bool,
bam_shift: bool,
bam_scale: i32,
) -> Result<(), Box<dyn Error>> {
// Must create a Rayon thread pool in which to run our iterators
let pool = rayon::ThreadPoolBuilder::new()
Expand Down Expand Up @@ -789,6 +795,7 @@ pub fn uniwig_main(
output_type,
debug,
bam_shift,
bam_scale,
);
}

Expand Down Expand Up @@ -819,6 +826,7 @@ fn process_bam(
output_type: &str,
debug: bool,
bam_shift: bool,
bam_scale: i32
) -> Result<(), Box<dyn Error>> {
println!("Begin bam processing workflow...");
let fp_string = filepath.to_string();
Expand Down Expand Up @@ -910,6 +918,7 @@ fn process_bam(
&chrom_sizes_ref_path_string,
"start",
bam_shift,
bam_scale,

Check warning on line 921 in gtars/src/uniwig/mod.rs

View check run for this annotation

Codecov / codecov/patch

gtars/src/uniwig/mod.rs#L920-L921

Added lines #L920 - L921 were not covered by tests
);
}
&"end" => {
Expand All @@ -925,6 +934,7 @@ fn process_bam(
&chrom_sizes_ref_path_string,
"end",
bam_shift,
bam_scale,

Check warning on line 937 in gtars/src/uniwig/mod.rs

View check run for this annotation

Codecov / codecov/patch

gtars/src/uniwig/mod.rs#L936-L937

Added lines #L936 - L937 were not covered by tests
);
}
&"core" => {
Expand All @@ -939,7 +949,8 @@ fn process_bam(
&fp_string,
&chrom_sizes_ref_path_string,
"core",
bam_shift
bam_shift,
bam_scale,
);

}

Check warning on line 956 in gtars/src/uniwig/mod.rs

View check run for this annotation

Codecov / codecov/patch

gtars/src/uniwig/mod.rs#L952-L956

Added lines #L952 - L956 were not covered by tests
Expand All @@ -955,7 +966,8 @@ fn process_bam(
&fp_string,
&chrom_sizes_ref_path_string,
"shift",
bam_shift
bam_shift,
bam_scale,
);

}
Expand Down Expand Up @@ -1257,6 +1269,7 @@ fn process_bw_in_threads(
chrom_sizes_ref_path_string: &String,
sel: &str,
bam_shift:bool,
bam_scale: i32,
) {
let (reader, writer) = os_pipe::pipe().unwrap();
let write_fd = Arc::new(Mutex::new(writer));
Expand Down Expand Up @@ -1293,6 +1306,7 @@ fn process_bw_in_threads(
sel_clone.as_str(),
write_fd,
bam_shift,
bam_scale,
) {
Ok(_) => {
//eprintln!("Processing successful for {}", chromosome_string_cloned);
Expand Down Expand Up @@ -1357,6 +1371,7 @@ fn determine_counting_func(
sel_clone: &str,
write_fd: Arc<Mutex<PipeWriter>>,
bam_shift: bool,
bam_scale: i32,
) -> Result<(), BAMRecordError> {

//let bam_shift: bool = true; // This is to ensure a shifted position workflow is used when doing bams
Expand All @@ -1375,6 +1390,7 @@ fn determine_counting_func(
&chromosome_string_cloned,
sel_clone,
write_fd,
bam_scale,
) {
Ok(_) => Ok(()),
Err(err) => {
Expand Down
8 changes: 8 additions & 0 deletions gtars/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ mod tests {
zoom,
false,
true,
1,
)
.expect("Uniwig main failed!");

Expand Down Expand Up @@ -442,6 +443,7 @@ mod tests {
zoom,
false,
true,
1,
)
.expect("Uniwig main failed!");

Expand Down Expand Up @@ -488,6 +490,7 @@ mod tests {
zoom,
false,
true,
1,
)
.expect("Uniwig main failed!");

Expand Down Expand Up @@ -534,6 +537,7 @@ mod tests {
zoom,
false,
true,
1,
)
.expect("Uniwig main failed!");
Ok(())
Expand Down Expand Up @@ -599,6 +603,7 @@ mod tests {
zoom,
false,
true,
1,
);

assert!(result.is_ok());
Expand Down Expand Up @@ -666,6 +671,7 @@ mod tests {
zoom,
false,
true,
1,
);

assert!(result.is_ok());
Expand Down Expand Up @@ -779,6 +785,7 @@ mod tests {
zoom,
false,
true,
1,
);

assert!(result.is_ok());
Expand Down Expand Up @@ -887,6 +894,7 @@ mod tests {
zoom,
false,
true,
1,
)
.expect("Uniwig main failed!");

Expand Down

0 comments on commit 3685f94

Please sign in to comment.