this is my code: pub fn test( cfivends: &[(u64, u64)], cexons: &[(u64, u64)], cintrons:…
- User
this is my code:
pub fn test( c_fivends: &[(u64, u64)], c_exons: &[(u64, u64)], c_introns: &[(u64, u64)], tx_exons: &[&(u64, u64)], id: &Arc, // flags -> (skip_exon [0: true, 1: false], nt_5_end) flags: &HashSet<(u64, u64)>, line: String, ) { let tx_5end = tx_exons[0]; let (skip, _) = flags.iter().next().unwrap();
codelet status = match c_fivends.interval_search(&tx_5end) { // is inside Some((s, e)) => { // starts differ if s != tx_5end.0 { match skip { 1 => FivePrimeStatus::TruncatedInExon, _ => FivePrimeStatus::Complete, } } else { // starts are equal FivePrimeStatus::Complete } } // is not inside -> check c_exons overlap None => match c_exons.interval_search(&tx_5end) { Some((ex_s, ex_e)) => { if ex_s != tx_5end.0 { match skip { 1 => FivePrimeStatus::TruncatedInExon, _ => FivePrimeStatus::Complete, } } else { // starts are equal FivePrimeStatus::Complete } } None => FivePrimeStatus::Complete, }, };}
pub trait IntervalSearch { fn interval_search(&self, query: &(T, T)) -> Option<(T, T)> where T: PartialOrd + Copy; }
impl IntervalSearch for Vec<(T, T)> { fn interval_search(&self, query: &(T, T)) -> Option<(T, T)> where T: PartialOrd + Copy, { let mut start = 0; let mut end = self.len();
codewhile start < end { let mid = start + (end - start) / 2; let mid_val = self[mid]; if query.1 <= mid_val.0 { end = mid; } else if query.0 >= mid_val.1 { start = mid + 1; } else { return Some(mid_val); } } None } - Assistant