-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add percent coverage option to stat (#83)
* initial commit * fix combine and parsing thresholds * off by one * remove minus one * fix rm rf command in test-driver * add perc_cov tests * update readme * update cli yml * write value as scientific notation if small. update test expected output
- Loading branch information
Showing
10 changed files
with
160 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use super::{Task, TaskPartition}; | ||
use std::iter::Once; | ||
|
||
#[derive(Clone)] | ||
pub struct PercentCovPart { | ||
//thresholds should be sorted | ||
thresholds: Vec<u32>, | ||
counts: Vec<u32>, | ||
} | ||
|
||
impl TaskPartition<Once<i32>> for PercentCovPart { | ||
type ParentType = PercentCov; | ||
type ResultType = Vec<u32>; | ||
fn new(left: u32, right: u32, parent: &Self::ParentType) -> Self { | ||
Check warning on line 14 in d4/src/task/perc_cov.rs
|
||
Self { | ||
thresholds: parent.3.clone(), | ||
counts: vec![0; parent.3.len()], | ||
} | ||
} | ||
// #[inline(always)] | ||
fn feed(&mut self, _: u32, value: &mut Once<i32>) -> bool { | ||
let value = value.next().unwrap(); | ||
for (i, thresh) in self.thresholds.iter().enumerate() { | ||
if value as u32 >= *thresh { | ||
self.counts[i] += 1 | ||
} | ||
} | ||
true | ||
} | ||
// #[inline(always)] | ||
fn feed_range(&mut self, left: u32, right: u32, value: &mut Once<i32>) -> bool { | ||
let value = value.next().unwrap(); | ||
for (i, thresh) in self.thresholds.iter().enumerate() { | ||
if value as u32 >= *thresh { | ||
self.counts[i] += right - left as u32 | ||
} | ||
} | ||
true | ||
} | ||
|
||
fn result(&mut self) -> Self::ResultType { | ||
self.counts.clone() | ||
} | ||
} | ||
|
||
pub struct PercentCov(String, u32, u32, Vec<u32>); | ||
|
||
impl PercentCov { | ||
pub fn new(chrom: &str, begin: u32, end: u32, thresholds: Vec<u32>) -> Self { | ||
PercentCov(chrom.to_string(), begin, end, thresholds) | ||
} | ||
} | ||
|
||
impl Task<std::iter::Once<i32>> for PercentCov { | ||
type Partition = PercentCovPart; | ||
type Output = Vec<f32>; | ||
fn region(&self) -> (&str, u32, u32) { | ||
(self.0.as_str(), self.1, self.2) | ||
} | ||
fn combine(&self, parts: &[Vec<u32>]) -> Self::Output { | ||
let divisor = (self.2 - self.1) as f32; | ||
|
||
let mut sums: Vec<u32> = vec![0; self.3.len()]; | ||
|
||
// Sum the vectors index-wise | ||
|
||
for part in parts { | ||
for (i, &value) in part.iter().enumerate() { | ||
sums[i] += value; | ||
} | ||
} | ||
|
||
let result: Vec<f32> = sums.into_iter().map(|x| x as f32 / divisor).collect(); | ||
|
||
result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
${D4TOOLS} stat -s perc_cov=1,2 -r ${DATADIR}/input_10nt.multiple_ranges.bed ${DATADIR}/input_10nt.d4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
chr 0 2 0.000e0 0.000e0 | ||
chr 0 8 0.625 0.375 | ||
chr 0 10 0.600 0.300 | ||
chr 1 6 0.600 0.400 | ||
chr 3 9 1.000 0.500 | ||
chr 4 5 1.000 1.000 | ||
chr 5 10 0.800 0.400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
${D4TOOLS} stat -s perc_cov=1,2 -r ${DATADIR}/input_10nt.overlapping_ranges.bed ${DATADIR}/input_10nt.d4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
chr 0 10 0.600 0.300 | ||
chr 4 5 1.000 1.000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,7 @@ EOF | |
|
||
popd >& /dev/null | ||
|
||
rm ${OUTDIR} -rf | ||
rm -rf ${OUTDIR} | ||
done | ||
|
||
echo | ||
|