Skip to content

Commit

Permalink
fix: update subtract tests to follow inheritance rules of scores. rem…
Browse files Browse the repository at this point in the history
…ove score types from generic
  • Loading branch information
noamteyssier committed Feb 9, 2024
1 parent aa2bf03 commit 39a036f
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 47 deletions.
34 changes: 30 additions & 4 deletions src/commands/flank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/commands/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -123,7 +123,7 @@ pub fn random_bed6<W: Write>(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())?;

Expand Down Expand Up @@ -175,7 +175,7 @@ pub fn random_bed12<W: Write>(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())?;

Expand Down
17 changes: 15 additions & 2 deletions src/commands/shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/io/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/io/read/bed12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn convert_bed12_set<R: Read>(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(),
Expand Down
2 changes: 1 addition & 1 deletion src/io/read/bed6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn convert_bed6_set<R: Read>(reader: R, translater: &mut SplitTranslater) -> Res
record.start(),
record.end(),
name_int,
*record.score(),
record.score(),
record.strand().unwrap_or_default(),
);
set.insert(interval);
Expand Down
9 changes: 4 additions & 5 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ pub type NumericBed4 = Bed4<usize, usize, usize>;
pub type NamedBed4<'a> = Bed4<&'a str, usize, &'a str>;
pub type Bed4Set = IntervalContainer<NumericBed4, usize, usize>;

pub type NumericBed6 = Bed6<usize, usize, usize, f64>;
pub type NamedBed6<'a> = Bed6<&'a str, usize, &'a str, f64>;
pub type NumericBed6 = Bed6<usize, usize, usize>;
pub type NamedBed6<'a> = Bed6<&'a str, usize, &'a str>;
pub type Bed6Set = IntervalContainer<NumericBed6, usize, usize>;

pub type NumericBed12 = Bed12<usize, usize, usize, f64, usize, usize, usize, usize, usize>;
pub type NamedBed12<'a> =
Bed12<&'a str, usize, &'a str, f64, usize, usize, &'a str, &'a str, &'a str>;
pub type NumericBed12 = Bed12<usize, usize, usize, usize, usize, usize, usize, usize>;
pub type NamedBed12<'a> = Bed12<&'a str, usize, &'a str, usize, usize, &'a str, &'a str, &'a str>;
pub type Bed12Set = IntervalContainer<NumericBed12, usize, usize>;

pub type NumericMetaInterval = MetaInterval<usize, usize, usize>;
Expand Down
4 changes: 2 additions & 2 deletions src/types/translate/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
Expand All @@ -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(),
Expand Down
60 changes: 32 additions & 28 deletions tests/subtract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
})
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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(())
}
Expand Down

0 comments on commit 39a036f

Please sign in to comment.