help me here: pub fn cmpexons( cnexons: &mut Vec<(u32, u32)>, txexons: Vec<&(u32, u32)>,…
- User
help me here:
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;
for (start, end) in tx_exons.iter() {
for i in cn_idx.iter() {
let exon = &cn_exons[*i];
// match | in front | behind
if (start >= &exon.0 && end <= &exon.1) || start > &exon.1 || end < &exon.0 {
cn_idx.pop_front();
continue;
}
// alternative splicing
if end > &exon.1 && end < &cn_exons[*i + 1].0 {
println!(
"{:?} exon {:?} AS - {:?} {:?} - {:?}",
id, i, start, end, exon
);
continue;
}
println!(
"{:?} exon {:?} IR - {:?} {:?} - {:?}",
id, i, start, end, exon
);
}
}
// println!("{:?} has {:?} intron retentions", id, inrets);
(status, matches)
}
error[E0502]: cannot borrow cn_idx as mutable because it is also borrowed
as immutable
--> src/exon.rs:36:17
|
32 | for i in cn_idx.iter() {
| -------------
| |
| immutable borrow occurs here
| immutable borrow later used here
...
36 | cn_idx.pop_front();
| ^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
- Assistant
- User
here:
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;
code - Assistant
- User
I want to remove those indices before the next iteration on tx_exons
- Assistant
If you want to remove certain indices from
cn_exonsbefore proceeding to the next iteration oftx_exons, you can do so by collecting the indices to remove during one iteration and then removing them at the end of that iteration. This way, each iteration of will operate on an updated list. Here's how you can implement this: