Skip to content

Commit

Permalink
Skip second overlap if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
timoast committed Jul 20, 2024
1 parent 3aa389c commit 1800b4f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ fn fcount(
let mut line_str = String::new();
let mut startpos: u32;
let mut endpos: u32;
let mut check_end: bool;

loop {
match reader.read_line(&mut line_str) {
Expand Down Expand Up @@ -156,6 +157,7 @@ fn fcount(
// check if cell is to be included
let cell_barcode: &str = fields[3];
if let Some(&cell_index) = cells.get(cell_barcode) {
check_end = true;

// create intervals from fragment entry
let seqname: &str = fields[0];
Expand All @@ -165,15 +167,23 @@ fn fcount(
startpos = fields[1].parse().map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
endpos = fields[2].parse().map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;

// find overlapping peaks
if let Some(olap_start) = find_overlaps(&peaks, seqname, startpos, startpos+1) {

for peak_index in olap_start {
*peak_cell_counts[peak_index.0].entry(cell_index).or_insert(0) += 1;

// check if fragment end is behind peak end (if so, it overlaps and we don't need a full search)
if endpos < peak_index.1 {
check_end = false;
*peak_cell_counts[peak_index.0].entry(cell_index).or_insert(0) += 1;
}
}
}
if let Some(olap_end) = find_overlaps(&peaks, seqname, endpos, endpos+1) {
for peak_index in olap_end {
*peak_cell_counts[peak_index.0].entry(cell_index).or_insert(0) += 1;
if check_end {
if let Some(olap_end) = find_overlaps(&peaks, seqname, endpos, endpos+1) {
for peak_index in olap_end {
*peak_cell_counts[peak_index.0].entry(cell_index).or_insert(0) += 1;
}
}
}
}
Expand Down

0 comments on commit 1800b4f

Please sign in to comment.