Skip to content

Commit 05f6db9

Browse files
committed
m
1 parent 2b88add commit 05f6db9

6 files changed

Lines changed: 109 additions & 58 deletions

File tree

src/core/fasta_reader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::aux::he::{
1515
make_custom_error, make_custom_error3, make_custom_error4, ErrorExplained, OrExaplain,
1616
};
1717
use crate::aux::limited_bufreader::LimitedBufReader;
18-
use crate::aux::pbar::prepare_pbar;
18+
use crate::aux::pbar::{prepare_pbar, prepare_pbar_force};
1919

2020
use super::fusion_scan::Error;
2121

@@ -191,7 +191,7 @@ impl FastaReader {
191191
}
192192

193193
pub(crate) fn read_all(&mut self) {
194-
let pbar = prepare_pbar(0);
194+
let pbar = prepare_pbar_force(0);
195195
pbar.set_message("Reading references...");
196196
while self.read_next() {
197197
pbar.inc(1);

src/core/fusion_mapper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<'s> FusionMapper<'s> {
273273
),
274274
}
275275
}
276-
pub(crate) fn filter_matches(&mut self, inner_thread_pool:&ThreadPool) -> () {
276+
pub(crate) fn filter_matches(&mut self, inner_thread_pool:Option<&ThreadPool>) -> () {
277277
// calc the sequence number before any filtering
278278
// let mut total = 0;
279279
// for fm in self.fusion_matches.lock().unwrap().iter() {
@@ -485,7 +485,7 @@ impl<'s> FusionMapper<'s> {
485485
log::info!("found {} fusions", self.m_fusion_results.len(),);
486486
}
487487

488-
fn remove_alignables(&mut self, inner_thread_pool:&ThreadPool) -> () {
488+
fn remove_alignables(&mut self, inner_thread_pool:Option<&ThreadPool>) -> () {
489489
if self.get_ref().is_none() {
490490
return;
491491
}

src/core/fusion_scan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl FusionScan {
100100
// exit(0);
101101
// }
102102

103-
let mut scanner_m_ref = ScannerFastaReader::new(m_reference);
103+
let scanner_m_ref = ScannerFastaReader::new(m_reference);
104104

105105
let fusion_csv_paths = self.get_fusion_csv_vec_from_input()?;
106106
let (html_file_paths, json_file_paths) =

src/core/matcher.rs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Matcher {
4444
pub(crate) fn from_ref_and_seqs(
4545
fasta_ref: Arc<FastaReader>,
4646
seqs: &[Sequence],
47-
inner_thread_pool:&ThreadPool,
47+
inner_thread_pool:Option<&ThreadPool>,
4848
) -> Self {
4949
let mut matcher = Self {
5050
m_kmer_positions: HashMap::with_hasher(GFHasherBuilder::new()),
@@ -117,7 +117,7 @@ impl Matcher {
117117

118118
// }
119119

120-
fn make_index(&mut self, itp:&ThreadPool) {
120+
fn make_index(&mut self, itp:Option<&ThreadPool>) {
121121
if self.m_reference.is_none() {
122122
return;
123123
}
@@ -131,26 +131,34 @@ impl Matcher {
131131

132132
log::debug!("indexing contig per ctg_name...");
133133
// let mut seq_cv= Vec::new();
134-
itp.install(|| {
135-
contig_ref.iter().enumerate().par_bridge().for_each(|(ctg, e)| {
136-
let (ctg_name, s) = (e.0.as_str(), e.1.as_str());
137-
let seq_cv = s
138-
.as_bytes()
139-
.iter()
140-
.copied()
141-
.map(|b| b.to_ascii_uppercase())
142-
.collect::<Vec<u8>>();
143-
// let s = s.to_uppercase();
144-
m_contig_names.lock().unwrap().push(ctg_name.to_owned());
145-
146-
//index forward
147-
self.index_contig_bytes(ctg as i32, &seq_cv, 0, &m_kmer_positions);
148-
149-
//index reverse complement
150-
// ctg.fetch_add(1, Ordering::Relaxed);
151-
// seq_cv.clear();
152-
});
153-
});
134+
135+
let do_index_contig = |(ctg, e):(usize, (&String, &String))| {
136+
let (ctg_name, s) = (e.0.as_str(), e.1.as_str());
137+
let seq_cv = s
138+
.as_bytes()
139+
.iter()
140+
.copied()
141+
.map(|b| b.to_ascii_uppercase())
142+
.collect::<Vec<u8>>();
143+
// let s = s.to_uppercase();
144+
m_contig_names.lock().unwrap().push(ctg_name.to_owned());
145+
146+
//index forward
147+
self.index_contig_bytes(ctg as i32, &seq_cv, 0, &m_kmer_positions);
148+
149+
//index reverse complement
150+
// ctg.fetch_add(1, Ordering::Relaxed);
151+
// seq_cv.clear();
152+
};
153+
154+
match itp{
155+
Some(itp) => {
156+
itp.install(|| {
157+
contig_ref.iter().enumerate().par_bridge().for_each(do_index_contig);
158+
});
159+
},
160+
None => contig_ref.iter().enumerate().for_each(do_index_contig),
161+
};
154162

155163

156164
log::info!("matcher indexing done");

src/core/pescanner.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub(crate) struct PairEndScanner<'s> {
6060
m_produce_finished: AtomicBool,
6161
m_thread_num: i32,
6262
m_fusion_mapper_o: Option<FusionMapper<'s>>,
63-
m_thread_pool: ThreadPool,
63+
m_thread_pool: Option<ThreadPool>,
6464
input_seq_pairs: Option<&'s [SequenceReadPair]>,
6565
}
6666

@@ -75,10 +75,16 @@ impl<'s> PairEndScanner<'s> {
7575
thread_num: i32,
7676
input_seq_pairs: Option<&'s [SequenceReadPair]>,
7777
) -> Self {
78-
let itp = ThreadPoolBuilder::new()
79-
.num_threads(thread_num as usize)
80-
.build()
81-
.unwrap();
78+
let itp = if thread_num > 1 {
79+
let tp = ThreadPoolBuilder::new()
80+
.num_threads(thread_num as usize)
81+
.build()
82+
.unwrap();
83+
84+
Some(tp)
85+
} else {
86+
None
87+
};
8288

8389
Self {
8490
m_fusion_file: fusion_file,
@@ -288,15 +294,21 @@ impl<'s> PairEndScanner<'s> {
288294
}
289295

290296
fn _scan(&mut self) -> Result<bool, Error> {
291-
self.m_thread_pool.scope(|tps| {
292-
tps.spawn(|tps| self.producer_task().unwrap());
297+
match self.m_thread_pool {
298+
Some(ref itp) => {
299+
itp.scope(|tps| {
300+
tps.spawn(|tps| self.producer_task().unwrap());
301+
302+
for t in (0..(rayon::current_num_threads() - 1)) {
303+
tps.spawn(|tps| {
304+
self.consumer_task().unwrap();
305+
})
306+
}
307+
});
293308

294-
for t in (0..(rayon::current_num_threads() - 1)) {
295-
tps.spawn(|tps| {
296-
self.consumer_task().unwrap();
297-
})
298-
}
299-
});
309+
},
310+
None => self.producer_task().unwrap(),
311+
}
300312

301313
log::debug!("Produced and consumed all the tasks.");
302314
let m_fusion_mapper = self.m_fusion_mapper_o.as_mut().unwrap();
@@ -320,7 +332,7 @@ impl<'s> PairEndScanner<'s> {
320332
// exit(0);
321333

322334
log::debug!("run matches methods...");
323-
m_fusion_mapper.filter_matches(&self.m_thread_pool);
335+
m_fusion_mapper.filter_matches(self.m_thread_pool.as_ref());
324336
m_fusion_mapper.sort_matches();
325337
m_fusion_mapper.cluster_matches();
326338

src/core/sescanner.rs

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::{
22
error,
3-
sync::{atomic::{AtomicBool, AtomicUsize, Ordering}, Arc},
3+
sync::{
4+
atomic::{AtomicBool, AtomicUsize, Ordering},
5+
Arc,
6+
},
47
thread::sleep,
58
time::Duration,
69
};
@@ -15,7 +18,13 @@ use crate::core::{
1518
};
1619

1720
use super::{
18-
fasta_reader::FastaReader, fusion_mapper::FusionMapper, fusion_scan::Error, html_reporter::HtmlReporter, json_reporter::JsonReporter, read::{SequenceRead, SequenceReadCow}, read_match::ReadMatch
21+
fasta_reader::FastaReader,
22+
fusion_mapper::FusionMapper,
23+
fusion_scan::Error,
24+
html_reporter::HtmlReporter,
25+
json_reporter::JsonReporter,
26+
read::{SequenceRead, SequenceReadCow},
27+
read_match::ReadMatch,
1928
};
2029

2130
#[derive(Debug)]
@@ -45,7 +54,7 @@ pub(crate) struct SingleEndScanner<'s> {
4554
m_produce_finished: AtomicBool,
4655
m_thread_num: i32,
4756
m_fusion_mapper_o: Option<FusionMapper<'s>>,
48-
m_thread_pool: ThreadPool,
57+
m_thread_pool: Option<ThreadPool>,
4958
input_seqs: Option<&'s [SequenceRead]>,
5059
}
5160

@@ -57,9 +66,18 @@ impl<'s> SingleEndScanner<'s> {
5766
html: String,
5867
json: String,
5968
thread_num: i32,
60-
input_seq_pairs:Option<&'s [SequenceRead]>,
69+
input_seq_pairs: Option<&'s [SequenceRead]>,
6170
) -> Self {
62-
let itp = ThreadPoolBuilder::new().num_threads(thread_num as usize).build().unwrap();
71+
let itp = if thread_num > 1 {
72+
let tp = ThreadPoolBuilder::new()
73+
.num_threads(thread_num as usize)
74+
.build()
75+
.unwrap();
76+
77+
Some(tp)
78+
} else {
79+
None
80+
};
6381

6482
Self {
6583
m_fusion_file: fusion_file,
@@ -73,7 +91,6 @@ impl<'s> SingleEndScanner<'s> {
7391
m_fusion_mapper_o: None,
7492
m_thread_pool: itp,
7593
input_seqs: input_seq_pairs,
76-
7794
// repo_not_full: Condvar::new(),
7895
// repo_not_empty: Condvar::new(),
7996
}
@@ -84,15 +101,30 @@ impl<'s> SingleEndScanner<'s> {
84101
}
85102

86103
fn _scan(&mut self) -> Result<bool, Error> {
87-
self.m_thread_pool.scope(|tps| {
88-
tps.spawn(|tps| self.producer_task().unwrap());
104+
match self.m_thread_pool {
105+
Some(ref itp) => {
106+
itp.scope(|tps| {
107+
tps.spawn(|tps| self.producer_task().unwrap());
108+
109+
for t in (0..(rayon::current_num_threads() - 1)) {
110+
tps.spawn(|tps| {
111+
self.consumer_task().unwrap();
112+
})
113+
}
114+
});
89115

90-
for t in (0..(rayon::current_num_threads() - 1)) {
91-
tps.spawn(|tps| {
92-
self.consumer_task().unwrap();
93-
})
94-
}
95-
});
116+
},
117+
None => self.producer_task().unwrap(),
118+
}
119+
// self.m_thread_pool.scope(|tps| {
120+
// tps.spawn(|tps| self.producer_task().unwrap());
121+
122+
// for t in (0..(rayon::current_num_threads() - 1)) {
123+
// tps.spawn(|tps| {
124+
// self.consumer_task().unwrap();
125+
// })
126+
// }
127+
// });
96128

97129
log::debug!("Produced and consumed all the tasks.");
98130
let m_fusion_mapper = self.m_fusion_mapper_o.as_mut().unwrap();
@@ -116,7 +148,7 @@ impl<'s> SingleEndScanner<'s> {
116148
// exit(0);
117149

118150
log::debug!("run matches methods...");
119-
m_fusion_mapper.filter_matches(&self.m_thread_pool);
151+
m_fusion_mapper.filter_matches(self.m_thread_pool.as_ref());
120152
m_fusion_mapper.sort_matches();
121153
m_fusion_mapper.cluster_matches();
122154

@@ -410,7 +442,6 @@ impl<'s> SingleEndScanner<'s> {
410442
// }
411443
}
412444

413-
414445
struct FastqReaderWrapper<'s> {
415446
input_seq_pairs_iter: Option<std::slice::Iter<'s, SequenceRead>>,
416447
fastq_reader_pair: Option<FastqReader>,
@@ -439,4 +470,4 @@ impl<'s> FastqReaderWrapper<'s> {
439470
.map(SequenceReadCow::Owned),
440471
}
441472
}
442-
}
473+
}

0 commit comments

Comments
 (0)