Skip to content

Commit

Permalink
start of intersection api
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Oct 6, 2023
1 parent c672997 commit 6d63a76
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/intersections.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use crate::intersection::{Intersection, Intersections};

Check warning on line 1 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `Intersection`

Check warning on line 1 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `Intersection`

Check warning on line 1 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `Intersection`
use crate::position::{Position, Positioned};

Check warning on line 2 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `Position`

Check warning on line 2 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `Position`

Check warning on line 2 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `Position`

/// Simple interval is used to return only the chrom, start, end.
#[derive(Debug)]
pub struct SimpleInterval<'a> {
chrom: &'a str,
start: u64,
stop: u64,
}

impl<'a> Positioned for SimpleInterval<'a> {
fn chrom(&self) -> &str {
self.chrom
}
fn start(&self) -> u64 {
self.start
}
fn stop(&self) -> u64 {
self.stop
}
}

/// IntersectionMode determines what part of overlap is returned.
/// The f32 is the proportion of overlap required.
pub enum IntersectionMode {
// https://bedtools.readthedocs.io/en/latest/content/tools/intersect.html#usage-and-option-summary
/// Return Chunks of A(B) that overlap B(A)
Chunks(f32),
/// Return All of A(B) that overlaps B(A)
All(f32),
/// Return A(B) if it does not overlap B(A)
None(f32),
}

impl Intersections {
pub fn intersections<'a>(
&'a self,
a_mode: Option<IntersectionMode>,
b_mode: Option<IntersectionMode>,
count: bool,

Check warning on line 41 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Check

unused variable: `count`

Check warning on line 41 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `count`

Check warning on line 41 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `count`
) -> Vec<SimpleInterval<'a>> {
match (a_mode, b_mode) {
(None, None) => self.a_chunks(None),
(Some(a_fraction), None) => unimplemented!(),

Check warning on line 45 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Check

unused variable: `a_fraction`

Check warning on line 45 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `a_fraction`

Check warning on line 45 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `a_fraction`
(None, Some(b_fraction)) => unimplemented!(),

Check warning on line 46 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Check

unused variable: `b_fraction`

Check warning on line 46 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `b_fraction`

Check warning on line 46 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `b_fraction`
(Some(a_fraction), Some(b_fraction)) => unimplemented!(),

Check warning on line 47 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Check

unused variable: `a_fraction`

Check warning on line 47 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Check

unused variable: `b_fraction`

Check warning on line 47 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `a_fraction`

Check warning on line 47 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `b_fraction`

Check warning on line 47 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `a_fraction`

Check warning on line 47 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `b_fraction`
}
}

pub fn a_chunks<'a>(&'a self, mode: Option<IntersectionMode>) -> Vec<SimpleInterval<'a>> {

Check warning on line 51 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Check

unused variable: `mode`

Check warning on line 51 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `mode`

Check warning on line 51 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `mode`
todo!("handle mode fraction of overlap");
self.overlapping

Check warning on line 53 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Check

unreachable expression

Check warning on line 53 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unreachable expression

Check warning on line 53 in src/intersections.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unreachable expression
.iter()
.map(|inter| {
let start = inter.interval.start().max(self.base_interval.start());
let stop = inter.interval.stop().min(self.base_interval.stop());
SimpleInterval {
chrom: inter.interval.chrom(),
start: start,
stop: stop,
}
})
.collect()
}
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
/// Intersection iterators and data structures.
pub mod intersection;

/// What to do with the intersections
pub mod intersections;

/// Position traits.
pub mod position;

Expand Down

0 comments on commit 6d63a76

Please sign in to comment.