Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaGuarracino committed Jan 3, 2025
1 parent b931428 commit 8a39e5b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/impg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ impl CigarOp {
_ => panic!("Invalid CIGAR operation: {}", self.op()),
}
}

fn adjust_len(&mut self, length_delta: i32) {
self.val = (self.val & (7 << 29)) | ((self.len() + length_delta) as u32);
}
}

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
Expand Down Expand Up @@ -485,7 +489,7 @@ fn project_target_range_through_alignment(
}

match (cigar_op.target_delta(), cigar_op.query_delta(strand)) {
(0, query_delta) => { // Insertion in query
(0, query_delta) => { // Insertion in query (deletions in target)
if target_pos >= requested_target_range.0 {
if !found_overlap {
projected_query_start = query_pos;
Expand All @@ -499,7 +503,7 @@ fn project_target_range_through_alignment(
}
query_pos += query_delta;
},
(target_delta, 0) => { // Deletion in query
(target_delta, 0) => { // Deletion in query (insertions in target)
let overlap_start = target_pos.max(requested_target_range.0);
let overlap_end = (target_pos + target_delta).min(last_target_pos);

Expand Down Expand Up @@ -553,15 +557,13 @@ fn project_target_range_through_alignment(
let mut adjusted_ops = cigar_ops[first_op_idx..last_op_idx].to_vec();

// Adjust first operation length
if first_op_offset > 0 && !adjusted_ops.is_empty() {
let first_op = &mut adjusted_ops[0];
first_op.val = (first_op.val & (7 << 29)) | ((first_op.len() - first_op_offset) as u32);
if first_op_offset > 0 {
adjusted_ops[0].adjust_len(-first_op_offset);
}

// Adjust last operation length
if last_op_remaining < 0 && !adjusted_ops.is_empty() {
let last_op = adjusted_ops.last_mut().unwrap();
last_op.val = (last_op.val & (7 << 29)) | ((last_op.len() + last_op_remaining) as u32);
if last_op_remaining < 0 {
adjusted_ops[last_op_idx - first_op_idx - 1].adjust_len(last_op_remaining);
}

(
Expand Down

0 comments on commit 8a39e5b

Please sign in to comment.