Skip to content

Commit

Permalink
logging info for while querying
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaGuarracino committed Jan 12, 2025
1 parent 1524898 commit 36fe4a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/impg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rayon::prelude::*;
use noodles::bgzf;
use regex::Regex;
use std::cmp::{min,max};
use log::debug;

/// Parse a CIGAR string into a vector of CigarOp
// Note that the query_delta is negative for reverse strand alignments
Expand Down Expand Up @@ -223,7 +224,6 @@ pub struct Impg {

impl Impg {
pub fn from_paf_records(records: &[PafRecord], paf_file: &str) -> Result<Self, ParseErr> {

let paf_gzi_index: Option<bgzf::gzi::Index> = if [".gz", ".bgz"].iter().any(|e| paf_file.ends_with(e)) {
let paf_gzi_file = paf_file.to_owned() + ".gzi";
Some(bgzf::gzi::read(paf_gzi_file.clone()).unwrap_or_else(|_| panic!("Could not open {}", paf_gzi_file)))
Expand Down Expand Up @@ -329,6 +329,9 @@ impl Impg {
metadata: target_id
}
));

debug!("Querying region: {}:{}-{}", self.seq_index.get_name(target_id).unwrap(), range_start, range_end);

if let Some(tree) = self.trees.get(&target_id) {
tree.query(range_start, range_end, |interval| {
let metadata = &interval.metadata;
Expand All @@ -355,6 +358,9 @@ impl Impg {
}
});
}

debug!("Collected {} results", results.len());

results
}

Expand Down Expand Up @@ -395,7 +401,11 @@ impl Impg {
.or_default()
.insert((range_start, range_end));

while let Some((current_target_id, current_target_start, current_target_end)) = stack.pop() {
let mut prec_num_results = 0;

while let Some((current_target_id, current_target_start, current_target_end)) = stack.pop() {
debug!("Querying region: {}:{}-{}", self.seq_index.get_name(current_target_id).unwrap(), current_target_start, current_target_end);

if let Some(tree) = self.trees.get(&current_target_id) {
tree.query(current_target_start, current_target_end, |interval| {
let metadata = &interval.metadata;
Expand Down Expand Up @@ -436,6 +446,7 @@ impl Impg {
});

// Merge contiguous/overlapping ranges with same sequence_id
let stack_size = stack.len();
stack.sort_by_key(|(id, start, _)| (*id, *start));
let mut write = 0;
for read in 1..stack.len() {
Expand All @@ -448,7 +459,11 @@ impl Impg {
}
}
stack.truncate(write + 1);
}
debug!("Merged stack size from {} to {}", stack_size, stack.len());
}

debug!("Collected {} results", results.len() - prec_num_results);
prec_num_results = results.len();
}

results
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use coitrees::IntervalTree;
use impg::paf;
use rayon::ThreadPoolBuilder;
use std::io::BufRead;
use log::{warn, error};
use log::{warn, error, info};
use impg::partition::partition_alignments;

/// Common options shared between all commands
Expand Down Expand Up @@ -133,6 +133,7 @@ fn main() -> io::Result<()> {
}
} else if let Some(target_bed) = target_bed {
let targets = parse_bed_file(&target_bed)?;
info!("Parsed {} target ranges from BED file", targets.len());
for (target_name, target_range, name) in targets {
let results = perform_query(&impg, &target_name, target_range, transitive);
if check_intervals {
Expand Down

0 comments on commit 36fe4a7

Please sign in to comment.