check this function: // Find 5' truncations in a set of query reads // based on a…
- User
check this function:
// Find 5' truncations in a set of query reads // based on a consensus/target track/group // // In short, each Vec<Arc> is a group of overlapping // transcripts. For each of these groups, a pre-processing sort // is performed to facilite further comparisons detailed here. // // Pre-sort logic: // For a given group, all transcripts are sorted by their first // exon start and end coordinates so that: // // 5'------------------------------- 3' // Target1: XXXXX---XXXXXX------XXXXXX---XXXXXX // Target2: XXXXXXXXXXXX------XXXXXX---XXXXXX // Target3: XXXXXXXX------XXXXXX---XXXXXX // Target4: XXXX-XXXXXX---XXXXXX // Target5: XX-XXXXXX---XXXXXX // // This allows for a more efficient search for 5' truncations // in the query transcripts. // // See config.rs for the definition of FendPred and FendCGroup // structs. // ... fn find_truncation( tx: &FendPred, target: &Vec<Arc>, flags: (bool, usize), ) -> Option { let skip_exon = flags.0; let threshold = flags.1; let (query_exon_start, query_exon_end) = tx.exons.get(0).unwrap();
for t in target { for (idx, (target_exon_start, target_exon_end)) in t.exons.iter().enumerate() { if query_exon_start >= target_exon_start && query_exon_start <= target_exon_end { // Query is inside target group 5' ends // // Does not directly mean that its truncated. // mRNAs captured by PacBio Iso-Seqs present // a particular distribution of pseudo-5'-truncations // that are not necessarily indicative of a true // truncation. // // Four different scenarios can be observed: // // 1. Query start is within the target start and end (same end) // // Target: XXXXX---XXXXXX---XXXXXX // ||| // Query: XXX---XXXXXX---XXXXXX // // 2. Query start is within the target start and end (different end) // // Target: XXXXX---XXXXXX---XXXXXX // ||^ // Query: XX----XXXXXX---XXXXXX // // 3. Query start is within target start/end but query ends in an intron // // Target: XXXXX---XXXXXX---XXXXXX // |||** // Query: XXXXX-XXXXXX---XXXXXX // // 4. Query retains an intron // // Target: XXXXX---XXXXXX---XXXXXX // |||***|||||| // Query: XXXXXXXXXXXX---XXXXXX // // In all cases, the query is considered complete. // ... return Some(Status::Complete); } else { // Query is not inside the current target group 5' end. // Here, three possibilities are considered: // // 1. Query start is before the next target start (in intron) // // Target: XXXXX-----XXXXX-----XXXXXXX // ||| // Query: XXX-XXXXX-----XXXXXXX // // 2. Query start is after the next target start (or somewhere downstream) // // Target: XXXXX-----XXXXX-----XXXXXXX // ||| // Query: XXX-----XXXXXXX // // 3. Query start is after the next target end (not on reach) // // Target: XXXXX-----XXXXX-----XXXXXXX // ||| // Query: XXX-XXXXXXX //... if query_exon_start < &t.exons[idx + 1].0 && idx < t.exons.len() - 1 { // Query starts in an intron if query_exon_end > &t.exons[idx + 1].0 { // Query ends overlaps with the next exon // // Target: XXXXX-----XXXXX-----XXXXXXX // ***** // Query: XXXXXXXX-----XXXXXXX return Some(Status::Truncated); } else { // Query 5'end is in an intron // // Target: XXXXX-----XXXXX-----XXXXXXX // ||| // Query: XXX-XXXXX-----XXXXXXX return Some(Status::Complete); } } else if query_exon_start >= &t.exons[idx + 1].0 && query_exon_end <= &t.exons[idx + 1].1 && idx < t.exons.len() - 1 { // Query is in the next exon // // Target: XXXXX-----XXXXX-----XXXXXXX // ||| // Query: XXX------XXXXXXX return Some(Status::Truncated); } else { // Query starts somewhere downstream // the next exon continue; } } } } None}
I am getting this errors:
' panicked at 101: :src/fivend/classify.rsindex out of bounds: the len is 12 but the index is 12src/fivend/classify.rs:index out of bounds: the len is 12 but the index is 12101: :47 :101101: 47::index out of bounds: the len is 12 but the index is 12: 47index out of bounds: the len is 12 but the index is 1247 :
: index out of bounds: the len is 12 but the index is 12index out of bounds: the len is 12 but the index is 12 ' panicked at src/fivend/classify.rs:101' panicked at :index out of bounds: the len is 12 but the index is 12src/fivend/classify.rssrc/fivend/classify.rs47 :' panicked at : :101src/fivend/classify.rsindex out of bounds: the len is 12 but the index is 12101::47 : :10147101index out of bounds: the len is 12 but the index is 12:: : 47index out of bounds: the len is 12 but the index is 1247:
: index out of bounds: the len is 12 but the index is 12index out of bounds: the len is 12 but the index is 12
thread 'thread 'thread 'thread 'thread '' panicked at ' panicked at ' panicked at ' panicked at ' panicked at src/fivend/classify.rssrc/fivend/classify.rssrc/fivend/classify.rssrc/fivend/classify.rssrc/fivend/classify.rs:::::101101101101101:::::4747474747: : : : : index out of bounds: the len is 4 but the index is 4index out of bounds: the len is 4 but the index is 4index out of bounds: the len is 4 but the index is 4index out of bounds: the len is 4 but the index is 4index out of bounds: the len is 4 but the index is 4
I am assuming that it is because once the inner loop reaches the last exon and there is no break statement. I am not really sure. Could you help me please?
- Assistant
Based on the provided code and error messages, it appears that the "index out of bounds" error you are encountering is caused by trying to access an index in the
exonsvector that does not exist. Specifically, the error is triggered because of attempts to access the next exon (t.exons[idx + 1]) without first checking ifidx + 1is a valid index withint.exons.Here are the key problematic parts in your code snippet:
if query_exon_start < &t.exons[idx + 1].0 && idx < t.exons.len() - 1 { ... } else if query_exon_start >= &t.exons[idx + 1].0 && query_exon_end <= &t.exons[idx + 1].1 && idx < t.exons.len() - 1 { ... }In both sections, you are accessing
t.exons[idx + 1]before checking ifidx + 1is within the bounds of theexonsarray. This means that whenidxis equal tot.exons.len() - 1(i.e., the last index),idx + 1goes out of bounds.To fix these issues, you need to ensure that you are checking the bounds before accessing the array. A proper way to restructure the checking conditions might be:
if idx < t.exons.len() - 1 { if query_exon_start < &t.exons[idx + 1].0 { // Query starts in an intron if query_exon_end > &t.exons[idx + 1].0 { // Query ends overlaps with the next exon return Some(Status::Truncated); } else { // Query 5'end is in an intron return Some(Status::Complete); } } else if query_exon_start >= &t.exons[idx + 1].0 && query_exon_end <= &t.exons[idx + 1].1 { // Query is in the next exon return Some(Status::Truncated); } else { // Query starts somewhere downstream the next exon continue; } } else { // This is the last exon, special handling may be necessary // Depending on your business logic, decide how to handle this case }This change ensures that you only access
t.exons[idx + 1]after confirming thatidx + 1is a valid index. Also, note that I moved the boundary check to the outermost part to confirm it's checked first before any access attempts.Also, make sure you understand all scenarios including the edge cases where the comparison might reach the end of the
exonsarray. In such cases, based on your application logic, further conditions might be required to handle those properly.