Skip to content

Commit

Permalink
Add contains() method to IntervalTree and implement first version of …
Browse files Browse the repository at this point in the history
…intersection_strict
  • Loading branch information
CedricHermansBIT committed Feb 12, 2024
1 parent 11c7b2a commit f10899e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
7 changes: 7 additions & 0 deletions src/intervaltree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,11 @@ impl IntervalTree {
result
}

pub fn contains(&self, start: i32, end: i32) -> Vec<&Interval> {
let mut result = self.overlap(start, end);
// TODO: merge overlapping intervals with same name into one interval
result.retain(|x| x.start <= start && x.end >= end);
result
}

}
39 changes: 24 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,30 @@ fn process_union_read(features: &IntervalTree, start_pos: i32, end_pos: i32, is_
let new_overlap = features.overlap(start_pos, end_pos);
let strand = if is_reverse_strand { '-' } else { '+' };
// add all overlapping features to the list
add_stranded_features(new_overlap, strand, overlapping_features, args);

}

fn process_intersection_nonempty_read(_features: &IntervalTree, _start_pos: i32, _end_pos: i32, _strand: bool, _overlapping_features: &mut Vec<Feature>, _args: &Args) {
todo!("process_partial_read for intersection-nonempty");
}

fn process_intersection_strict_read(features: &IntervalTree, start_pos: i32, end_pos: i32, strand: bool, overlapping_features: &mut Vec<Feature>, args: &Args) {
//todo!("process_partial_read for intersection-strict");
let new_contained = features.contains(start_pos, end_pos);
let strand = if strand { '-' } else { '+' };
// add all contained features to the list
add_stranded_features(new_contained, strand, overlapping_features, args);
}

fn filter_ambiguity_union(
overlapping_features: &[Feature],
) -> Vec<String> {
let unique_feature_names: HashSet<String> = overlapping_features.iter().map(|x| x.name().to_string().clone()).filter(|x| !x.is_empty()).collect();
unique_feature_names.into_iter().collect()
}

fn add_stranded_features(new_overlap: Vec<&Interval>, strand: char, overlapping_features: &mut Vec<Feature>, args: &Args) {
for overlap in new_overlap {
let feature = overlap.data.as_ref().unwrap();
match args.stranded.as_str() {
Expand All @@ -702,19 +726,4 @@ fn process_union_read(features: &IntervalTree, start_pos: i32, end_pos: i32, is_
}
}
}
}

fn process_intersection_nonempty_read(_features: &IntervalTree, _start_pos: i32, _end_pos: i32, _strand: bool, _overlapping_features: &mut Vec<Feature>, _args: &Args) {
todo!("process_partial_read for intersection-nonempty");
}

fn process_intersection_strict_read(_features: &IntervalTree, _start_pos: i32, _end_pos: i32, _strand: bool, _overlapping_features: &mut Vec<Feature>, _args: &Args) {
todo!("process_partial_read for intersection-strict");
}

fn filter_ambiguity_union(
overlapping_features: &[Feature],
) -> Vec<String> {
let unique_feature_names: HashSet<String> = overlapping_features.iter().map(|x| x.name().to_string().clone()).filter(|x| !x.is_empty()).collect();
unique_feature_names.into_iter().collect()
}

0 comments on commit f10899e

Please sign in to comment.