Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bin/FragGeneScanRs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ fn run<R: Read + Send, W: WritingBuffer + Send>(
.map(u8::to_ascii_uppercase)
.map(Nuc::from)
.collect();
let read_prediction = if nseq.is_empty() {
let read_prediction = if nseq.len() < 3 {
gene::ReadPrediction::new(head)
} else {
viterbi(&global, &locals, head, nseq, whole_genome)
Expand Down
10 changes: 3 additions & 7 deletions src/viterbi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ pub fn forward(
Vec<[f64; hmm::State::COUNT]>,
Vec<[Option<hmm::State>; hmm::State::COUNT]>,
) {
let mut alpha: Vec<[f64; hmm::State::COUNT]> = Vec::with_capacity(seq.len());
let mut path: Vec<[Option<hmm::State>; hmm::State::COUNT]> = Vec::with_capacity(seq.len());
let mut alpha: Vec<[f64; hmm::State::COUNT]> = vec![[0.0; hmm::State::COUNT]; seq.len()];
let mut path: Vec<[Option<hmm::State>; hmm::State::COUNT]> =
vec![[Some(hmm::State::S); hmm::State::COUNT]; seq.len()];
Comment on lines +30 to +32
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forward() allocates alpha/path using seq.len(), but the function later unconditionally indexes alpha[0] and seq[0..=2] (and writes to alpha[1]/alpha[2]). Since the caller currently only guards is_empty(), inputs with length 1–2 will panic. Consider adding an early return/guard for seq.len() < 3 (either here or in viterbi()/caller) so short records are handled safely.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a valid comment, but was also valid for the original code. I fixed it at the caller side in FragGeneScanRs.rs.

let mut temp_i: [usize; hmm::PERIOD] = [0; hmm::PERIOD];
let mut temp_i_1: [usize; hmm::PERIOD] = [0; hmm::PERIOD];

for _ in 0..seq.len() {
alpha.push([0.0; hmm::State::COUNT]);
path.push([Some(hmm::State::S); hmm::State::COUNT]);
}
alpha[0].copy_from_slice(&global.pi);
for i in &mut alpha[0] {
*i *= -1.0
Expand Down