From 39a036faded2afde49395e0fe20e64b7a78aabb8 Mon Sep 17 00:00:00 2001 From: noam teyssier <22600644+noamteyssier@users.noreply.github.com> Date: Fri, 9 Feb 2024 10:26:08 -0800 Subject: [PATCH] fix: update subtract tests to follow inheritance rules of scores. remove score types from generic --- src/commands/flank.rs | 34 +++++++++++++++++--- src/commands/random.rs | 6 ++-- src/commands/shift.rs | 17 ++++++++-- src/io/iter.rs | 2 +- src/io/read/bed12.rs | 2 +- src/io/read/bed6.rs | 2 +- src/types/mod.rs | 9 +++--- src/types/translate/rename.rs | 4 +-- tests/subtract.rs | 60 +++++++++++++++++++---------------- 9 files changed, 89 insertions(+), 47 deletions(-) diff --git a/src/commands/flank.rs b/src/commands/flank.rs index 660bc1d..cd57742 100644 --- a/src/commands/flank.rs +++ b/src/commands/flank.rs @@ -135,7 +135,7 @@ mod testing { #[test] fn test_flank_left_bed6() { - let iv = Bed6::new(1, 100, 400, 1, 2, Strand::default()); + let iv = Bed6::new(1, 100, 400, 1, 2.into(), Strand::default()); let left = left_flank(iv, 50).unwrap(); assert_eq!(left.start(), 50); assert_eq!(left.end(), 100); @@ -146,7 +146,20 @@ mod testing { #[test] fn test_flank_left_bed12() { - let iv = Bed12::new(1, 100, 400, 1, 2, Strand::default(), 3, 4, 5, 6, 7, 8); + let iv = Bed12::new( + 1, + 100, + 400, + 1, + 2.into(), + Strand::default(), + 3, + 4, + 5, + 6, + 7, + 8, + ); let left = left_flank(iv, 50).unwrap(); assert_eq!(left.start(), 50); assert_eq!(left.end(), 100); @@ -187,7 +200,7 @@ mod testing { #[test] fn test_flank_right_bed6() { - let iv = Bed6::new(1, 100, 400, 1, 2, Strand::default()); + let iv = Bed6::new(1, 100, 400, 1, 2.into(), Strand::default()); let right = right_flank(iv, 50, None).unwrap(); assert_eq!(right.start(), 400); assert_eq!(right.end(), 450); @@ -198,7 +211,20 @@ mod testing { #[test] fn test_flank_right_bed12() { - let iv = Bed12::new(1, 100, 400, 1, 2, Strand::default(), 3, 4, 5, 6, 7, 8); + let iv = Bed12::new( + 1, + 100, + 400, + 1, + 2.into(), + Strand::default(), + 3, + 4, + 5, + 6, + 7, + 8, + ); let right = right_flank(iv, 50, None).unwrap(); assert_eq!(right.start(), 400); assert_eq!(right.end(), 450); diff --git a/src/commands/random.rs b/src/commands/random.rs index c467181..731bbd0 100644 --- a/src/commands/random.rs +++ b/src/commands/random.rs @@ -4,7 +4,7 @@ use crate::{ types::{Genome, InputFormat, NumericBed12, NumericBed3, NumericBed4, NumericBed6, Translater}, }; use anyhow::Result; -use bedrs::Strand; +use bedrs::{Score, Strand}; use rand::Rng; use std::io::Write; @@ -123,7 +123,7 @@ pub fn random_bed6(args: RandomArgs, writer: W) -> Result<()> { (c, x, y, s) }) // build the interval - .map(|(c, x, y, s)| NumericBed6::new(c, x, y, 0, 0.0, s)); + .map(|(c, x, y, s)| NumericBed6::new(c, x, y, 0, Score::Empty, s)); write_records_iter_with(interval_gen, writer, genome_sizes.translater())?; @@ -175,7 +175,7 @@ pub fn random_bed12(args: RandomArgs, writer: W) -> Result<()> { (c, x, y, t, u, s) }) // build the interval - .map(|(c, x, y, t, u, s)| NumericBed12::new(c, x, y, 0, 0.0, s, t, u, 0, 0, 0, 0)); + .map(|(c, x, y, t, u, s)| NumericBed12::new(c, x, y, 0, Score::Empty, s, t, u, 0, 0, 0, 0)); write_records_iter_with(interval_gen, writer, genome_sizes.translater())?; diff --git a/src/commands/shift.rs b/src/commands/shift.rs index be7e3e6..174636f 100644 --- a/src/commands/shift.rs +++ b/src/commands/shift.rs @@ -162,7 +162,7 @@ mod testing { #[test] fn test_shift_bed6() { - let iv = Bed6::new(1, 100, 200, 1, 2, Strand::default()); + let iv = Bed6::new(1, 100, 200, 1, 2.into(), Strand::default()); let si = shift_interval(iv, 50.0, false, None); assert_eq!(si.start(), 150); assert_eq!(si.end(), 250); @@ -173,7 +173,20 @@ mod testing { #[test] fn test_shift_bed12() { - let iv = Bed12::new(1, 100, 400, 1, 2, Strand::default(), 3, 4, 5, 6, 7, 8); + let iv = Bed12::new( + 1, + 100, + 400, + 1, + 2.into(), + Strand::default(), + 3, + 4, + 5, + 6, + 7, + 8, + ); let si = shift_interval(iv, 50.0, false, None); assert_eq!(si.start(), 150); assert_eq!(si.end(), 450); diff --git a/src/io/iter.rs b/src/io/iter.rs index 3264e5c..961a251 100644 --- a/src/io/iter.rs +++ b/src/io/iter.rs @@ -77,7 +77,7 @@ impl<'a, 'b, R: Read> Iterator for NamedIter<'a, 'b, R, NumericBed6> { record.start(), record.end(), *name_idx, - *record.score(), + record.score(), record.strand().unwrap_or_default(), ); Some(iv) diff --git a/src/io/read/bed12.rs b/src/io/read/bed12.rs index 11d9e0e..748883b 100644 --- a/src/io/read/bed12.rs +++ b/src/io/read/bed12.rs @@ -90,7 +90,7 @@ fn convert_bed12_set(reader: R, translater: &mut SplitTranslater) -> Re record.start(), record.end(), name_int, - *record.score(), + record.score(), record.strand().unwrap_or_default(), record.thick_start(), record.thick_end(), diff --git a/src/io/read/bed6.rs b/src/io/read/bed6.rs index caebae9..5f30ffc 100644 --- a/src/io/read/bed6.rs +++ b/src/io/read/bed6.rs @@ -77,7 +77,7 @@ fn convert_bed6_set(reader: R, translater: &mut SplitTranslater) -> Res record.start(), record.end(), name_int, - *record.score(), + record.score(), record.strand().unwrap_or_default(), ); set.insert(interval); diff --git a/src/types/mod.rs b/src/types/mod.rs index 8814562..f51d62d 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -19,13 +19,12 @@ pub type NumericBed4 = Bed4; pub type NamedBed4<'a> = Bed4<&'a str, usize, &'a str>; pub type Bed4Set = IntervalContainer; -pub type NumericBed6 = Bed6; -pub type NamedBed6<'a> = Bed6<&'a str, usize, &'a str, f64>; +pub type NumericBed6 = Bed6; +pub type NamedBed6<'a> = Bed6<&'a str, usize, &'a str>; pub type Bed6Set = IntervalContainer; -pub type NumericBed12 = Bed12; -pub type NamedBed12<'a> = - Bed12<&'a str, usize, &'a str, f64, usize, usize, &'a str, &'a str, &'a str>; +pub type NumericBed12 = Bed12; +pub type NamedBed12<'a> = Bed12<&'a str, usize, &'a str, usize, usize, &'a str, &'a str, &'a str>; pub type Bed12Set = IntervalContainer; pub type NumericMetaInterval = MetaInterval; diff --git a/src/types/translate/rename.rs b/src/types/translate/rename.rs index bc91b00..ec0fc1c 100644 --- a/src/types/translate/rename.rs +++ b/src/types/translate/rename.rs @@ -35,7 +35,7 @@ impl<'a> Rename<'a, NumericBed6, NamedBed6<'a>> for Renamer { iv.start(), iv.end(), name, - *iv.score(), + iv.score(), iv.strand().unwrap_or_default(), ) } @@ -52,7 +52,7 @@ impl<'a> Rename<'a, NumericBed12, NamedBed12<'a>> for Renamer { iv.start(), iv.end(), name, - *iv.score(), + iv.score(), iv.strand().unwrap_or_default(), iv.thick_start(), iv.thick_end(), diff --git a/tests/subtract.rs b/tests/subtract.rs index 0499120..40cc7a1 100644 --- a/tests/subtract.rs +++ b/tests/subtract.rs @@ -23,7 +23,7 @@ mod testing { .iter() .map(|(chr, start, end, name, score, strand)| { format!( - "{}\t{}\t{}\t{}\t{:.1}\t{}\n", + "{}\t{}\t{}\t{}\t{:.3}\t{}\n", chr, start, end, name, score, strand ) }) @@ -52,7 +52,7 @@ mod testing { block_starts, )| { format!( - "{}\t{}\t{}\t{}\t{:.1}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n", + "{}\t{}\t{}\t{}\t{:.3}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n", chr, start, end, @@ -114,12 +114,12 @@ mod testing { .output()?; let expected = vec![ - (1, 100, 120, 0, 0.0, '+'), - (1, 125, 150, 0, 0.0, '+'), - (1, 160, 300, 0, 0.0, '+'), - (1, 400, 460, 0, 0.0, '+'), - (1, 470, 475, 0, 0.0, '+'), - (1, 500, 550, 0, 0.0, '+'), + (1, 100, 120, 0, '.', '+'), + (1, 125, 150, 0, '.', '+'), + (1, 160, 300, 0, '.', '+'), + (1, 400, 460, 0, '.', '+'), + (1, 470, 475, 0, '.', '+'), + (1, 500, 550, 0, '.', '+'), ]; let expected_str = build_expected_str_bed6(&expected); assert_eq!(output.stdout, expected_str.as_bytes()); @@ -141,12 +141,12 @@ mod testing { .output()?; let expected = vec![ - (1, 100, 120, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), - (1, 125, 150, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), - (1, 160, 300, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), - (1, 400, 460, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), - (1, 470, 475, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), - (1, 500, 550, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), + (1, 100, 120, 0, ".", '+', 0, 0, 0, 0, 0, 0), + (1, 125, 150, 0, ".", '+', 0, 0, 0, 0, 0, 0), + (1, 160, 300, 0, ".", '+', 0, 0, 0, 0, 0, 0), + (1, 400, 460, 0, ".", '+', 0, 0, 0, 0, 0, 0), + (1, 470, 475, 0, ".", '+', 0, 0, 0, 0, 0, 0), + (1, 500, 550, 0, ".", '+', 0, 0, 0, 0, 0, 0), ]; let expected_str = build_expected_str_bed12(&expected); assert_eq!(output.stdout, expected_str.as_bytes()); @@ -198,13 +198,13 @@ mod testing { .output()?; let expected = vec![ - (1, 100, 120, 0, 0.0, '+'), - (1, 125, 150, 0, 0.0, '+'), - (1, 160, 200, 0, 0.0, '+'), - (1, 200, 300, 0, 0.0, '+'), - (1, 400, 460, 0, 0.0, '+'), - (1, 470, 475, 0, 0.0, '+'), - (1, 500, 550, 0, 0.0, '+'), + (1, 100, 120, 0, ".", '+'), + (1, 125, 150, 0, ".", '+'), + (1, 160, 200, 0, ".", '+'), + (1, 200, 300, 0, "0.0", '+'), + (1, 400, 460, 0, ".", '+'), + (1, 470, 475, 0, ".", '+'), + (1, 500, 550, 0, "0.0", '+'), ]; let expected_str = build_expected_str_bed6(&expected); assert_eq!(output.stdout, expected_str.as_bytes()); @@ -227,15 +227,19 @@ mod testing { .output()?; let expected = vec![ - (1, 100, 120, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), - (1, 125, 150, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), - (1, 160, 200, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), - (1, 200, 300, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), - (1, 400, 460, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), - (1, 470, 475, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), - (1, 500, 550, 0, 0.0, '+', 0, 0, 0, 0, 0, 0), + (1, 100, 120, 0, ".", '+', 0, 0, 0, 0, 0, 0), + (1, 125, 150, 0, ".", '+', 0, 0, 0, 0, 0, 0), + (1, 160, 200, 0, ".", '+', 0, 0, 0, 0, 0, 0), + (1, 200, 300, 0, "0.0", '+', 0, 0, 0, 0, 0, 0), + (1, 400, 460, 0, ".", '+', 0, 0, 0, 0, 0, 0), + (1, 470, 475, 0, ".", '+', 0, 0, 0, 0, 0, 0), + (1, 500, 550, 0, "0.0", '+', 0, 0, 0, 0, 0, 0), ]; let expected_str = build_expected_str_bed12(&expected); + + println!("{}", std::str::from_utf8(&output.stdout).unwrap()); + println!("{}", expected_str); + assert_eq!(output.stdout, expected_str.as_bytes()); Ok(()) }