Skip to content

Commit faec695

Browse files
Mitchell R. Vollgerclaude
andcommitted
fix: correct off-by-one in centered_query_start/end for minus strand and add missing wide format header column
`centered_query_start` and `centered_query_end` were off by 1 on the minus strand because the half-open interval [start, end) was negated as [-end, -start) instead of the correct [-end+1, -start+1). This caused m6a positions to index into the wrong base when users sliced `query_sequence[-centered_query_end:]` for minus strand reads. The fix converts to inclusive coordinates before negation and back to exclusive after, matching the existing correct logic in `apply_offset_helper()`. Also adds the missing `fire_qual` column name to the wide format header so the header column count (22) matches the data. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 86be096 commit faec695

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/subcommands/center.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,18 @@ impl CenteredFiberData {
123123
};
124124

125125
if self.center_position.strand == '-' {
126+
// Convert end to inclusive before negation to correctly
127+
// handle half-open interval [start, end) under negation.
128+
// Negating [a, b) should give [-b+1, -a+1), not [-b, -a).
129+
// This matches the logic in apply_offset_helper().
130+
c_query_end -= 1;
126131
c_query_start = -c_query_start;
127132
c_query_end = -c_query_end;
128133
if c_query_start > c_query_end {
129134
std::mem::swap(&mut c_query_start, &mut c_query_end);
130135
}
136+
// Convert end back to exclusive
137+
c_query_end += 1;
131138
}
132139
format!(
133140
"{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t",
@@ -224,7 +231,7 @@ impl CenteredFiberData {
224231
}
225232
pub fn header() -> String {
226233
format!(
227-
"{}{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n",
234+
"{}{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n",
228235
CenteredFiberData::leading_header(),
229236
"centered_m6a_positions",
230237
"m6a_qual",
@@ -234,6 +241,7 @@ impl CenteredFiberData {
234241
"centered_nuc_ends",
235242
"centered_msp_starts",
236243
"centered_msp_ends",
244+
"fire_qual",
237245
"query_sequence"
238246
)
239247
}

0 commit comments

Comments
 (0)