diff --git a/gtars/src/uniwig/counting.rs b/gtars/src/uniwig/counting.rs index f5bcdf4..1165c9f 100644 --- a/gtars/src/uniwig/counting.rs +++ b/gtars/src/uniwig/counting.rs @@ -34,9 +34,7 @@ pub fn start_end_counts( chrom_size: i32, smoothsize: i32, stepsize: i32, - shift: i32, ) -> (Vec, Vec) { - //let vin_iter = starts_vector.iter(); let mut v_coordinate_positions: Vec = Vec::new(); // these are the final coordinates after any adjustments let mut v_coord_counts: Vec = Vec::new(); // u8 stores 0:255 This may be insufficient. u16 max is 65535 @@ -55,7 +53,7 @@ pub fn start_end_counts( adjusted_start_site = starts_vector[0]; // get first coordinate position - adjusted_start_site.0 = adjusted_start_site.0 - smoothsize + shift; + adjusted_start_site.0 = adjusted_start_site.0 - smoothsize; current_end_site = adjusted_start_site; current_end_site.0 = adjusted_start_site.0 + 1 + smoothsize * 2; @@ -74,7 +72,7 @@ pub fn start_end_counts( coordinate_value = *coord; adjusted_start_site = coordinate_value; - adjusted_start_site.0 = coordinate_value.0 - smoothsize + shift; + adjusted_start_site.0 = coordinate_value.0 - smoothsize; let current_score = adjusted_start_site.1; @@ -164,7 +162,6 @@ pub fn core_counts( ends_vector: &[(i32, i32)], chrom_size: i32, stepsize: i32, - shift: i32, ) -> (Vec, Vec) { let mut v_coordinate_positions: Vec = Vec::new(); // these are the final coordinates after any adjustments let mut v_coord_counts: Vec = Vec::new(); // u8 stores 0:255 This may be insufficient. u16 max is 65535 @@ -184,7 +181,7 @@ pub fn core_counts( current_start_site = starts_vector[0]; // get first coordinate position current_end_site = ends_vector[0]; - current_start_site.0 = current_start_site.0 + shift; + current_start_site.0 = current_start_site.0; if current_start_site.0 < 1 { current_start_site.0 = 1; @@ -201,7 +198,7 @@ pub fn core_counts( current_start_site = coordinate_value; - current_start_site.0 = current_start_site.0 + shift; + current_start_site.0 = current_start_site.0; let current_score = current_start_site.1; count += current_score; diff --git a/gtars/src/uniwig/mod.rs b/gtars/src/uniwig/mod.rs index 17c996e..38803c0 100644 --- a/gtars/src/uniwig/mod.rs +++ b/gtars/src/uniwig/mod.rs @@ -191,8 +191,8 @@ pub fn run_uniwig(matches: &ArgMatches) { } /// Ensures that the start position is at a minimum equal to `1` -fn clamped_start_position(start: i32, smoothsize: i32) -> i32 { - std::cmp::max(1, start - smoothsize) +fn clamped_start_position(start: i32, smoothsize: i32, wig_shift:i32) -> i32 { + std::cmp::max(1, start - smoothsize + wig_shift) } /// Ensure that the start position is at a minimum equal to `0` fn clamped_start_position_zero_pos(start: i32, smoothsize: i32) -> i32 { @@ -222,7 +222,6 @@ pub fn uniwig_main( .build() .unwrap(); - let mut wig_shift: i32 = 0; // This will be set to 1 when writing to wiggle files, else always set to 0 // Determine Input File Type let input_filetype = FileType::from_str(filetype.to_lowercase().as_str()); @@ -258,9 +257,6 @@ pub fn uniwig_main( if output_type == "bedgraph" || output_type == "bw" || output_type == "bigwig" { output_type = "bedGraph" // we must create bedgraphs first before creating bigwig files } - if output_type == "wig" { - wig_shift = 1; - } // Pare down chromosomes if necessary let mut final_chromosomes = @@ -299,7 +295,6 @@ pub fn uniwig_main( current_chrom_size, smoothsize, stepsize, - wig_shift, ); match output_type { @@ -322,6 +317,7 @@ pub fn uniwig_main( clamped_start_position( primary_start.0, smoothsize, + 1 //must shift wiggle starts and core by 1 since it is 1 based ), stepsize, current_chrom_size, @@ -390,7 +386,6 @@ pub fn uniwig_main( current_chrom_size, smoothsize, stepsize, - wig_shift, ); match output_type { "file" => { @@ -411,6 +406,7 @@ pub fn uniwig_main( clamped_start_position( primary_end.0, smoothsize, + 0, ), ); write_to_bed_graph_file( @@ -432,6 +428,7 @@ pub fn uniwig_main( clamped_start_position( primary_end.0, smoothsize, + 0, // ends already 1 based, do not shift further ), stepsize, current_chrom_size, @@ -450,6 +447,7 @@ pub fn uniwig_main( clamped_start_position( primary_end.0, smoothsize, + 0 ), stepsize, meta_data_file_names[1].clone(), @@ -468,6 +466,7 @@ pub fn uniwig_main( clamped_start_position( primary_end.0, smoothsize, + 0 ), stepsize, meta_data_file_names[1].clone(), @@ -481,7 +480,6 @@ pub fn uniwig_main( &chromosome.ends, current_chrom_size, stepsize, - wig_shift, ); match output_type { "file" => { @@ -499,7 +497,10 @@ pub fn uniwig_main( let count_info: (Vec, Vec, Vec) = compress_counts( &mut core_results, - primary_start.0, + clamped_start_position_zero_pos( + primary_start.0, + 0, + ), ); write_to_bed_graph_file( &count_info, @@ -517,7 +518,7 @@ pub fn uniwig_main( &core_results.0, file_name.clone(), chrom_name.clone(), - clamped_start_position(primary_start.0, 0), + clamped_start_position(primary_start.0, 0,1), //starts are 1 based must be shifted by 1 stepsize, current_chrom_size, ); @@ -531,7 +532,10 @@ pub fn uniwig_main( &core_results.0, file_name.clone(), chrom_name.clone(), - primary_start.0, + clamped_start_position_zero_pos( + primary_start.0, + 0, + ), stepsize, meta_data_file_names[2].clone(), ); @@ -546,7 +550,10 @@ pub fn uniwig_main( &core_results.0, file_name.clone(), chrom_name.clone(), - primary_start.0, + clamped_start_position_zero_pos( + primary_start.0, + 0, + ), stepsize, meta_data_file_names[2].clone(), ); diff --git a/gtars/tests/data/out/_core.wig b/gtars/tests/data/out/_core.wig index 81ae5e9..7142f6c 100644 --- a/gtars/tests/data/out/_core.wig +++ b/gtars/tests/data/out/_core.wig @@ -1,9 +1,10 @@ -fixedStep chrom=chr1 start=2 step=1 +fixedStep chrom=chr1 start=3 step=1 2 2 3 +4 +2 2 -1 2 1 1 diff --git a/gtars/tests/data/out/_end.wig b/gtars/tests/data/out/_end.wig index f3119c1..306e8c4 100644 --- a/gtars/tests/data/out/_end.wig +++ b/gtars/tests/data/out/_end.wig @@ -12,4 +12,5 @@ fixedStep chrom=chr1 start=5 step=1 0 0 0 +0 0 \ No newline at end of file diff --git a/gtars/tests/data/out/_start.wig b/gtars/tests/data/out/_start.wig index b08c334..a8481c0 100644 --- a/gtars/tests/data/out/_start.wig +++ b/gtars/tests/data/out/_start.wig @@ -1,4 +1,4 @@ -fixedStep chrom=chr1 start=1 step=1 +fixedStep chrom=chr1 start=2 step=1 2 2 3 @@ -16,4 +16,5 @@ fixedStep chrom=chr1 start=1 step=1 0 0 0 +0 0 \ No newline at end of file diff --git a/gtars/tests/test.rs b/gtars/tests/test.rs index e197edc..e869197 100644 --- a/gtars/tests/test.rs +++ b/gtars/tests/test.rs @@ -486,7 +486,6 @@ mod tests { &chromosome.ends, current_chrom_size, stepsize, - 0, ); } } @@ -507,7 +506,6 @@ mod tests { current_chrom_size, smooth_size, stepsize, - 0, ); } } @@ -675,8 +673,10 @@ mod tests { let tempbedpath = format!("{}{}", path_to_crate, "/tests/data/test5.bed"); let combinedbedpath = tempbedpath.as_str(); + //let combinedbedpath = "/home/drc/Downloads/unwig_testing_19dec2024/input/dummy4.bed"; let chromsizerefpath = combinedbedpath; + //let chromsizerefpath = "/home/drc/Downloads/unwig_testing_19dec2024/input/dummy.chrom.sizes"; let tempdir = tempfile::tempdir().unwrap(); let path = PathBuf::from(&tempdir.path()); @@ -685,8 +685,12 @@ mod tests { let bwfileheader_path = path.into_os_string().into_string().unwrap(); let bwfileheader = bwfileheader_path.as_str(); - let smoothsize: i32 = 5; + //let bwfileheader = "/home/drc/Downloads/unwig_testing_19dec2024/output/npy_output/"; + //let bwfileheader = "/home/drc/Downloads/unwig_testing_19dec2024/output/wig_output/"; + + let smoothsize: i32 = 2; let output_type = "npy"; + //let output_type = "wig"; let filetype = "bed"; let num_threads = 6; let score = false;