Skip to content

Commit

Permalink
feat: move progress bar into bamchunk iterator, unify progress bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvollger committed Jul 31, 2023
1 parent c4c4b02 commit 678db90
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bio-io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ version = "0.2.0"
anyhow = "1.0.58"
colored = "2.0.0"
gzp = "0.11.3"
rayon = "1.5"
indicatif = {version = "0.17.0", features = ["rayon"]}
#env_logger = "0.9.0"
itertools = "0.10.5"
lazy_static = "1.4.0"
log = "0.4"
Expand Down
4 changes: 3 additions & 1 deletion bio-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use indicatif::{style, ProgressBar};
use itertools::Itertools;
use lazy_static::lazy_static;
use niffler::get_reader;
use rayon::current_num_threads;
use regex::Regex;
use rust_htslib::bam;
use rust_htslib::bam::record::Aux;
Expand Down Expand Up @@ -182,7 +183,8 @@ pub struct BamChunk<'a> {
}

impl<'a> BamChunk<'a> {
pub fn new(bam: bam::Records<'a, bam::Reader>, chunk_size: usize) -> Self {
pub fn new(bam: bam::Records<'a, bam::Reader>, chunk_size: Option<usize>) -> Self {
let chunk_size = chunk_size.unwrap_or_else(|| current_num_threads() * 100);
let bar = no_length_progress_bar();
Self {
bam,
Expand Down
5 changes: 2 additions & 3 deletions src/extract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::fiber::FiberseqData;
use super::*;
use rayon::{current_num_threads, prelude::*};
use rayon::prelude::*;
use rust_htslib::{bam, bam::HeaderView, bam::Read};

pub fn process_bam_chunk(
Expand Down Expand Up @@ -91,8 +91,7 @@ pub fn extract_contained(bam: &mut bam::Reader, mut out_files: FiberOut) {

// process bam in chunks
// keeps mem pretty low, about 1GB per thread
let chunk_size = current_num_threads() * 500;
let bam_chunk_iter = BamChunk::new(bam.records(), chunk_size);
let bam_chunk_iter = BamChunk::new(bam.records(), None);
for chunk in bam_chunk_iter {
process_bam_chunk(chunk, &mut out_files, &head_view);
}
Expand Down
4 changes: 1 addition & 3 deletions src/nucleosomes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::fiber::FiberseqData;
use super::*;
use rayon::current_num_threads;
use rayon::iter::ParallelIterator;
use rayon::prelude::IntoParallelRefMutIterator;
use rust_htslib::{
Expand Down Expand Up @@ -298,8 +297,7 @@ pub fn add_nucleosomes_to_bam(
allowed_m6a_skips,
};
// read in bam data
let chunk_size = current_num_threads() * 1000;
let bam_chunk_iter = BamChunk::new(bam.records(), chunk_size);
let bam_chunk_iter = BamChunk::new(bam.records(), None);

// iterate over chunks
for mut chunk in bam_chunk_iter {
Expand Down
5 changes: 2 additions & 3 deletions src/predict_m6a/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use bio_io;
use nucleosomes;
use ordered_float::OrderedFloat;
use rayon::iter::ParallelIterator;
use rayon::prelude::IndexedParallelIterator;
use rayon::prelude::IntoParallelRefMutIterator;
use rayon::{current_num_threads, prelude::IndexedParallelIterator};
use rust_htslib::{
bam,
bam::record::{Aux, AuxArray},
Expand Down Expand Up @@ -538,8 +538,7 @@ pub fn read_bam_into_fiberdata(
predict_options: &PredictOptions,
) {
// read in bam data
let chunk_size = current_num_threads() * 500;
let bam_chunk_iter = BamChunk::new(bam.records(), chunk_size);
let bam_chunk_iter = BamChunk::new(bam.records(), None);

// iterate over chunks
let mut total_read = 0;
Expand Down
4 changes: 1 addition & 3 deletions src/strip_basemods.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use super::basemods;
use super::*;
use rayon::current_num_threads;
use rayon::iter::ParallelIterator;
use rayon::prelude::IntoParallelRefMutIterator;
use rust_htslib::bam::Record;
use rust_htslib::{bam, bam::Read};

pub fn strip_base_mods(bam: &mut bam::Reader, out: &mut bam::Writer, basemod: &str) {
// read in bam data
let chunk_size = current_num_threads() * 500;
let bam_chunk_iter = BamChunk::new(bam.records(), chunk_size);
let bam_chunk_iter = BamChunk::new(bam.records(), None);

// iterate over chunks
for mut chunk in bam_chunk_iter {
Expand Down

0 comments on commit 678db90

Please sign in to comment.