could you help me? This is my code: pub fn cmp_introns( introns: &[(u64, u64)], exons:…
- User
could you help me? This is my code:
pub fn cmp_introns( introns: &[(u64, u64)], exons: &[&(u64, u64)], bklist: &HashSet<(u64, u64)>, id: &Arc, ) -> Result<(String, Status)> { let mut status = Status::NoIntronRetention; let mut irs: Vec = vec![]; let mut n: u64 = 0; let mut bk = 0; let mut pos = 0;
for (k, (start, end)) in exons.iter().enumerate() { let intron = introns.get(pos); println!("{} {} {:?} vs {:?}", k, start, end, intron); match intron { Some((istart, iend)) => { if end > istart { if start < istart && end > iend { if bklist.contains(&(istart.clone(), iend.clone())) { bk += 1; pos += 1; continue; } else { irs.push(k as u64); n += 1; pos += 1; continue; } } else { pos += 1; continue; } } else { pos += 1; continue; } } None => break, } }I am trying to make it efficient, so each intron is only seen 2 times at max. The main idea here is to see if any exon retains any intron. I do want each exon to iterate over the whole collection of introns, instead I want each intron to be seen the least amount of times, making it efficient. The current implementation fails to detect the test set. Any idea
- Assistant
- User
check this:
let introns = exon_starts[1..] .iter() .map(|&s| s - 1) .zip(exon_ends[..exon_ends.len() - 1].iter().map(|&e| e + 1)) .map(|(s, e)| (e, s)) .collect::<HashSet<(u64, u64)>>();how can I make sure that e < s?
- Assistant
Your current approach is creating pairs of exon ends and starts by shifting the starts to the left (subtracting 1) and shifting the ends to the right (adding 1), which is a common technique to find potential intronic regions between exons. However, the call swaps these values, which might not be what you intended if you want to keep orientation.