Skip to content

Commit

Permalink
fix target_id
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaGuarracino committed Dec 29, 2024
1 parent 5956725 commit ad4c62a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
18 changes: 9 additions & 9 deletions src/impg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl Impg {
Interval {
first: range_start,
last: range_end,
metadata: 0
metadata: target_id
}
));
if let Some(tree) = self.trees.get(&target_id) {
Expand All @@ -346,7 +346,7 @@ impl Impg {
Interval {
first: adjusted_target_start,
last: adjusted_target_end,
metadata: 0
metadata: target_id
}
);
results.push(adjusted_interval);
Expand Down Expand Up @@ -375,7 +375,7 @@ impl Impg {
Interval {
first: range_start,
last: range_end,
metadata: 0
metadata: target_id
}
));
// Initialize stack with first query
Expand All @@ -393,13 +393,13 @@ impl Impg {
.or_default()
.insert((range_start, range_end));

while let Some((current_target, current_start, current_end)) = stack.pop() {
if let Some(tree) = self.trees.get(&current_target) {
tree.query(current_start, current_end, |interval| {
while let Some((current_target_id, current_target_start, current_target_end)) = stack.pop() {
if let Some(tree) = self.trees.get(&current_target_id) {
tree.query(current_target_start, current_target_end, |interval| {
let metadata = &interval.metadata;
let (adjusted_query_start, adjusted_query_end, adjusted_cigar, adjusted_target_start, adjusted_target_end) =
project_target_range_through_alignment(
(current_start, current_end),
(current_target_start, current_target_end),
(metadata.target_start, metadata.target_end, metadata.query_start, metadata.query_end, metadata.strand),
&metadata.get_cigar_ops(&self.paf_file, self.paf_gzi_index.as_ref())
);
Expand All @@ -415,13 +415,13 @@ impl Impg {
Interval {
first: adjusted_target_start,
last: adjusted_target_end,
metadata: 0
metadata: current_target_id
}
);
results.push(adjusted_interval);

// Only add non-overlapping portions to the stack for further exploration
if metadata.query_id != current_target {
if metadata.query_id != current_target_id {
let ranges = visited_ranges.entry(metadata.query_id)
.or_default(); // Note the closure here

Expand Down
14 changes: 8 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn main() -> io::Result<()> {

if output_paf {
// Skip the first element (the input range) for PAF
output_results_paf(&impg, results.into_iter().skip(1), &target_name, None);
output_results_paf(&impg, results.into_iter().skip(1), None);
} else {
output_results_bed(&impg, results);
}
Expand All @@ -148,9 +148,9 @@ fn main() -> io::Result<()> {
// Skip the first element (the input range) for both PAF and BEDPE
let results_iter = results.into_iter().skip(1);
if output_paf {
output_results_paf(&impg, results_iter, &target_name, name);
output_results_paf(&impg, results_iter, name);
} else {
output_results_bedpe(&impg, results_iter, &target_name, name);
output_results_bedpe(&impg, results_iter, name);
}
}
} else {
Expand Down Expand Up @@ -315,12 +315,13 @@ fn output_results_bed(impg: &Impg, results: Vec<AdjustedInterval>) {
}
}

fn output_results_bedpe<I>(impg: &Impg, results: I, target_name: &str, name: Option<String>)
fn output_results_bedpe<I>(impg: &Impg, results: I, name: Option<String>)
where
I: Iterator<Item = AdjustedInterval>
{
for (overlap_query, _, overlap_target) in results {
let query_name = impg.seq_index.get_name(overlap_query.metadata).unwrap();
let target_name = impg.seq_index.get_name(overlap_target.metadata).unwrap();
let (first, last, strand) = if overlap_query.first <= overlap_query.last {
(overlap_query.first, overlap_query.last, '+')
} else {
Expand All @@ -333,20 +334,21 @@ where
}
}

fn output_results_paf<I>(impg: &Impg, results: I, target_name: &str, name: Option<String>)
fn output_results_paf<I>(impg: &Impg, results: I, name: Option<String>)
where
I: Iterator<Item = AdjustedInterval>
{
let target_length = impg.seq_index.get_len_from_id(impg.seq_index.get_id(target_name).unwrap()).unwrap();
for (overlap_query, cigar, overlap_target) in results {
let query_name = impg.seq_index.get_name(overlap_query.metadata).unwrap();
let target_name = impg.seq_index.get_name(overlap_target.metadata).unwrap();
let (first, last, strand) = if overlap_query.first <= overlap_query.last {
(overlap_query.first, overlap_query.last, '+')
} else {
(overlap_query.last, overlap_query.first, '-')
};

let query_length = impg.seq_index.get_len_from_id(overlap_query.metadata).unwrap();
let target_length = impg.seq_index.get_len_from_id(overlap_target.metadata).unwrap();

let (matches, mismatches, insertions, inserted_bp, deletions, deleted_bp, block_len) = cigar.iter().fold((0, 0, 0, 0, 0, 0, 0), |(m, mm, i, i_bp, d, d_bp, bl), op| {
let len = op.len();
Expand Down

0 comments on commit ad4c62a

Please sign in to comment.