check this code: pub fn cmpexons( cnexons: &mut Vec<(u32, u32)>, txexons: Vec<&(u32,…
- User
check this code:
pub fn cmp_exons( cn_exons: &mut Vec<(u32, u32)>, tx_exons: Vec<&(u32, u32)>, id: Arc, ) -> (Status, Vec) { let mut cn_idx = VecDeque::from_iter(0..cn_exons.len()); let mut matches = vec![]; let mut status = Status::Pass; let mut last_exon_end: u32 = 0; // let last = tx_exons.len() - 1;
codefor (start, end) in tx_exons.iter().map(|t| (**t)) { for exon in cn_exons .iter() .skip_while(|e| (start >= e.0 && end <= e.1) || start > e.1 || end < e.0) { if end < exon.0 { println!("{:?} {:?}", exon, (start, end)); } } } // println!("{:?} has {:?} intron retentions", id, inrets); (status, matches)}
this is the output:
(15546530, 15546788) (15537701, 15545347) (15549468, 15549525) (15537701, 15545347)
why these are not being catch by skip_while? In theory, since end < end.0 in both cases, these should be skipped
- Assistant
The
skip_whilemethod in Rust's iterators is not performing as you expect because it stops skipping as soon as the condition is false for the first time and never resumes skipping. In other words,skip_whileis stateful and once it encounters an element for which the closure returnsfalse, it will yield all subsequent elements even if they match the condition.Let's look at your code. Here's how
skip_whileis behaving in your loop:rustfor exon in cn_exons .iter() .skip_while(|e| (start >= e.0 && end <= e.1) || start > e.1 || end < e.0) { // Your code }