Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 6856c58

Browse files
authored
Fix overflow bugs in VDJ FR3 start identification. (#316)
Consistently handle FR3 start window bounds in the face of sequences that are possibly shorter than the window we're searching in. Bail out early if the full search window does not overlap with the sequence, to ensure that the FR3 start computed based on a given contig is the same irrespective of the amount of prefix clipped in the contig.
1 parent 305edf9 commit 6856c58

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

vdj_ann/src/vdj_features.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,11 @@ pub fn fr3_start(aa: &[u8], chain_type: &str, verbose: bool) -> Option<usize> {
466466
];
467467

468468
// Score positions.
469-
469+
if cdr3_start < 42 - 2 {
470+
return None;
471+
}
470472
let mut score_pos = Vec::<(usize, isize)>::with_capacity(42 - 32 + 1);
471-
for j in cdr3_start.saturating_sub(42 - 2)..=cdr3_start.saturating_sub(32 - 2) {
473+
for j in cdr3_start - (42 - 2)..=cdr3_start - (32 - 2) {
472474
let mut score = 0;
473475
for (p, wm) in pwm.iter().enumerate() {
474476
for l in wm {
@@ -525,7 +527,9 @@ pub fn fr3_start(aa: &[u8], chain_type: &str, verbose: bool) -> Option<usize> {
525527
];
526528

527529
// Score positions.
528-
530+
if cdr3_start < 36 {
531+
return None;
532+
}
529533
let mut score_pos = Vec::<(usize, usize)>::with_capacity(36 - 33 + 1);
530534
for j in cdr3_start - 36..=cdr3_start - 33 {
531535
let mut score = 0;
@@ -569,7 +573,9 @@ pub fn fr3_start(aa: &[u8], chain_type: &str, verbose: bool) -> Option<usize> {
569573
];
570574

571575
// Score positions.
572-
576+
if cdr3_start < 38 {
577+
return None;
578+
}
573579
let mut score_pos = Vec::<(usize, usize)>::with_capacity(38 - 35 + 1);
574580
for j in cdr3_start - 38..=cdr3_start - 35 {
575581
let mut score = 0;

0 commit comments

Comments
 (0)