@@ -9,7 +9,7 @@ use kr2r::HitGroup;
9
9
// use rayon::prelude::*;
10
10
use seqkmer:: { buffer_map_parallel, trim_pair_info, OptionPair } ;
11
11
use std:: collections:: HashMap ;
12
- use std:: fs:: File ;
12
+ use std:: fs:: { create_dir_all , File } ;
13
13
use std:: io:: { self , BufRead , BufReader , BufWriter , Read , Result , Write } ;
14
14
use std:: path:: { Path , PathBuf } ;
15
15
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
@@ -63,7 +63,11 @@ pub struct Args {
63
63
64
64
/// File path for outputting normal Kraken output.
65
65
#[ clap( long = "output-dir" , value_parser) ]
66
- pub kraken_output_dir : Option < PathBuf > ,
66
+ pub output_dir : Option < PathBuf > ,
67
+
68
+ /// The number of threads to use.
69
+ #[ clap( short = 'p' , long = "num-threads" , value_parser, default_value_t = num_cpus:: get( ) ) ]
70
+ pub num_threads : usize ,
67
71
68
72
// /// output file contains all unclassified sequence
69
73
// #[clap(long, value_parser, default_value_t = false)]
@@ -128,7 +132,7 @@ fn process_batch<P: AsRef<Path>>(
128
132
129
133
buffer_map_parallel (
130
134
& hit_counts,
131
- num_cpus :: get ( ) ,
135
+ args . num_threads ,
132
136
|( k, rows) | {
133
137
if let Some ( item) = id_map. get ( & k) {
134
138
let mut rows = rows. to_owned ( ) ;
@@ -168,7 +172,9 @@ fn process_batch<P: AsRef<Path>>(
168
172
} ,
169
173
|result| {
170
174
while let Some ( Some ( res) ) = result. next ( ) {
171
- writer. write_all ( res. as_bytes ( ) ) . unwrap ( ) ;
175
+ writer
176
+ . write_all ( res. as_bytes ( ) )
177
+ . expect ( "write output content error" ) ;
172
178
}
173
179
} ,
174
180
)
@@ -194,6 +200,10 @@ pub fn run(args: Args) -> Result<()> {
194
200
let mut total_seqs = 0 ;
195
201
let mut total_unclassified = 0 ;
196
202
203
+ if let Some ( output) = & args. output_dir {
204
+ create_dir_all ( output) ?;
205
+ }
206
+
197
207
// 开始计时
198
208
let start = Instant :: now ( ) ;
199
209
println ! ( "resolve start..." ) ;
@@ -202,7 +212,7 @@ pub fn run(args: Args) -> Result<()> {
202
212
let sample_id_map = read_id_to_seq_map ( & sample_id_files[ i] ) ?;
203
213
204
214
let thread_sequences = sample_id_map. len ( ) ;
205
- let mut writer: Box < dyn Write + Send > = match & args. kraken_output_dir {
215
+ let mut writer: Box < dyn Write + Send > = match & args. output_dir {
206
216
Some ( ref file_path) => {
207
217
let filename = file_path. join ( format ! ( "output_{}.txt" , i) ) ;
208
218
let file = File :: create ( filename) ?;
@@ -235,7 +245,7 @@ pub fn run(args: Args) -> Result<()> {
235
245
. merge ( & entry. value ( ) )
236
246
. unwrap ( ) ;
237
247
} ) ;
238
- if let Some ( output) = & args. kraken_output_dir {
248
+ if let Some ( output) = & args. output_dir {
239
249
let filename = output. join ( format ! ( "output_{}.kreport2" , i) ) ;
240
250
report_kraken_style (
241
251
filename,
@@ -252,7 +262,7 @@ pub fn run(args: Args) -> Result<()> {
252
262
total_unclassified += thread_sequences - thread_classified;
253
263
}
254
264
255
- if let Some ( output) = & args. kraken_output_dir {
265
+ if let Some ( output) = & args. output_dir {
256
266
if !sample_files. is_empty ( ) {
257
267
let min = & sample_files. keys ( ) . min ( ) . cloned ( ) . unwrap ( ) ;
258
268
let max = & sample_files. keys ( ) . max ( ) . cloned ( ) . unwrap ( ) ;
0 commit comments