Skip to content

Commit

Permalink
fix scaling for #53 by changing count and scale to f32
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Dec 16, 2024
1 parent 9673d0e commit baeebaa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions gtars/src/uniwig/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub fn create_uniwig_cli() -> Command {
Arg::new("bamscale")
.long("bamscale")
.short('e')
.default_value("1")
.value_parser(clap::value_parser!(i32))
.default_value("1.0")
.value_parser(clap::value_parser!(f32))
.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
Expand Down
22 changes: 11 additions & 11 deletions gtars/src/uniwig/counting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,15 +1247,15 @@ 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,
bam_scale:f32,
) -> Result<(), BAMRecordError> {
let mut write_lock = write_fd.lock().unwrap(); // Acquire lock for writing
let mut writer = BufWriter::new(&mut *write_lock);

let mut coordinate_position = 0;

let mut prev_count: i32 = 0;
let mut count: i32 = 0;
let mut prev_count: f32 = 0.0;
let mut count: f32 = 0.0;

let mut prev_coordinate_value = 0;

Expand Down Expand Up @@ -1343,7 +1343,7 @@ pub fn variable_shifted_bam_to_bw( records: &mut Box<Query<noodles::bgzf::reader
collected_end_sites.push(new_end_site);
}

count += 1;
count += 1.0;
//println!("here is all endsites: {:?}", collected_end_sites);

if adjusted_start_site == prev_coordinate_value {
Expand All @@ -1354,12 +1354,12 @@ pub fn variable_shifted_bam_to_bw( records: &mut Box<Query<noodles::bgzf::reader
//println!("coordinate_position< adjusted_start_site: {} < {} . here is current endsite: {} ", coordinate_position, adjusted_start_site, current_end_site);
while current_end_site == coordinate_position {
//println!("current_end_site == coordinate_position {} = {} adjusted start site: {}", current_end_site, coordinate_position, adjusted_start_site);
count = count - 1;
count = count - 1.0;

//prev_end_site = current_end_site;

if count < 0 {
count = 0;
if count < 0.0 {
count = 0.0;

Check warning on line 1362 in gtars/src/uniwig/counting.rs

View check run for this annotation

Codecov / codecov/patch

gtars/src/uniwig/counting.rs#L1362

Added line #L1362 was not covered by tests
}

if collected_end_sites.last() == None {
Expand Down Expand Up @@ -1390,17 +1390,17 @@ pub fn variable_shifted_bam_to_bw( records: &mut Box<Query<noodles::bgzf::reader
prev_coordinate_value = adjusted_start_site;
}

count = count + 1; // We must add 1 extra value here so that our calculation during the tail as we close out the end sites does not go negative.
count = count + 1.0; // We must add 1 extra value here so that our calculation during the tail as we close out the end sites does not go negative.
// this is because the code above subtracts twice during the INITIAL end site closure. So we are missing one count and need to make it up else we go negative.

while coordinate_position < chrom_size {
// Apply a bound to push the final coordinates otherwise it will become truncated.

while current_end_site == coordinate_position {
count = count - 1;
count = count - 1.0;
//prev_end_site = current_end_site;
if count < 0 {
count = 0;
if count < 0.0 {
count = 0.0;

Check warning on line 1403 in gtars/src/uniwig/counting.rs

View check run for this annotation

Codecov / codecov/patch

gtars/src/uniwig/counting.rs#L1403

Added line #L1403 was not covered by tests
}

if collected_end_sites.last() == None {
Expand Down
10 changes: 5 additions & 5 deletions gtars/src/uniwig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn run_uniwig(matches: &ArgMatches) {
.expect("requires integer value");

let bam_scale = matches
.get_one::<i32>("bamscale")
.get_one::<f32>("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);
Expand Down Expand Up @@ -205,7 +205,7 @@ pub fn uniwig_main(
zoom: i32,
debug: bool,
bam_shift: bool,
bam_scale: i32,
bam_scale: f32,
) -> 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 @@ -645,7 +645,7 @@ fn process_bam(
output_type: &str,
debug: bool,
bam_shift: bool,
bam_scale: i32
bam_scale: f32
) -> Result<(), Box<dyn Error>> {
println!("Begin bam processing workflow...");
let fp_string = filepath.to_string();
Expand Down Expand Up @@ -1088,7 +1088,7 @@ fn process_bw_in_threads(
chrom_sizes_ref_path_string: &String,
sel: &str,
bam_shift:bool,
bam_scale: i32,
bam_scale: f32,
) {
let (reader, writer) = os_pipe::pipe().unwrap();
let write_fd = Arc::new(Mutex::new(writer));
Expand Down Expand Up @@ -1190,7 +1190,7 @@ fn determine_counting_func(
sel_clone: &str,
write_fd: Arc<Mutex<PipeWriter>>,
bam_shift: bool,
bam_scale: i32,
bam_scale: f32,
) -> Result<(), BAMRecordError> {

//let bam_shift: bool = true; // This is to ensure a shifted position workflow is used when doing bams
Expand Down
16 changes: 8 additions & 8 deletions gtars/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ mod tests {
zoom,
false,
true,
1,
1.0,
)
.expect("Uniwig main failed!");

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

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

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

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

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

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

Expand Down

0 comments on commit baeebaa

Please sign in to comment.