Skip to content

Commit 27095d8

Browse files
author
dagou
committed
bug fix
1 parent 045006a commit 27095d8

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

kr2r/src/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct ClassifyArgs {
6161

6262
/// File path for outputting normal Kraken output.
6363
#[clap(long = "output-dir", value_parser)]
64-
pub kraken_output_dir: Option<PathBuf>,
64+
pub output_dir: Option<PathBuf>,
6565

6666
/// Enable paired-end processing.
6767
#[clap(short = 'P', long = "paired-end-processing", action)]

kr2r/src/bin/direct.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct Args {
2828

2929
/// File path for outputting normal Kraken output.
3030
#[clap(long = "output-dir", value_parser)]
31-
pub kraken_output_dir: Option<PathBuf>,
31+
pub output_dir: Option<PathBuf>,
3232

3333
/// Enable paired-end processing.
3434
#[clap(short = 'P', long = "paired-end-processing", action)]
@@ -161,7 +161,7 @@ fn process_fastx_file<R>(
161161
where
162162
R: Reader,
163163
{
164-
let mut writer: Box<dyn Write + Send> = match &args.kraken_output_dir {
164+
let mut writer: Box<dyn Write + Send> = match &args.output_dir {
165165
Some(ref file_path) => {
166166
let filename = file_path.join(format!("output_{}.txt", file_index));
167167
let file = File::create(filename)?;
@@ -225,7 +225,7 @@ where
225225

226226
let thread_sequences = seq_counter.load(Ordering::SeqCst);
227227
let thread_classified = classify_counter.load(Ordering::SeqCst);
228-
if let Some(output) = &args.kraken_output_dir {
228+
if let Some(output) = &args.output_dir {
229229
let filename = output.join(format!("output_{}.kreport2", file_index));
230230
report_kraken_style(
231231
filename,
@@ -248,7 +248,7 @@ fn process_files(
248248
chtable: &CHTable,
249249
taxonomy: &Taxonomy,
250250
) -> Result<()> {
251-
let (mut file_index, mut file_writer) = if let Some(out_dir) = &args.kraken_output_dir {
251+
let (mut file_index, mut file_writer) = if let Some(out_dir) = &args.output_dir {
252252
let file_path = out_dir.join("sample_file.map");
253253
let file_writer = create_sample_file(&file_path);
254254
let file_index = get_lastest_file_index(&file_path)?;
@@ -295,7 +295,7 @@ fn process_files(
295295
total_seqs += thread_sequences;
296296
total_unclassified += thread_unclassified;
297297
}
298-
if let Some(output) = &args.kraken_output_dir {
298+
if let Some(output) = &args.output_dir {
299299
let filename = output.join("output.kreport2");
300300
report_kraken_style(
301301
filename,

kr2r/src/bin/kun.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ impl From<ClassifyArgs> for resolve::Args {
9292
Self {
9393
database: item.database,
9494
chunk_dir: item.chunk_dir,
95+
num_threads: item.num_threads,
9596
confidence_threshold: item.confidence_threshold,
9697
minimum_hit_groups: item.minimum_hit_groups,
97-
kraken_output_dir: item.kraken_output_dir,
98+
output_dir: item.output_dir,
9899
report_kmer_data: item.report_kmer_data,
99100
report_zero_counts: item.report_zero_counts,
100101
}

kr2r/src/bin/resolve.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use kr2r::HitGroup;
99
// use rayon::prelude::*;
1010
use seqkmer::{buffer_map_parallel, trim_pair_info, OptionPair};
1111
use std::collections::HashMap;
12-
use std::fs::File;
12+
use std::fs::{create_dir_all, File};
1313
use std::io::{self, BufRead, BufReader, BufWriter, Read, Result, Write};
1414
use std::path::{Path, PathBuf};
1515
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -63,7 +63,11 @@ pub struct Args {
6363

6464
/// File path for outputting normal Kraken output.
6565
#[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,
6771

6872
// /// output file contains all unclassified sequence
6973
// #[clap(long, value_parser, default_value_t = false)]
@@ -128,7 +132,7 @@ fn process_batch<P: AsRef<Path>>(
128132

129133
buffer_map_parallel(
130134
&hit_counts,
131-
num_cpus::get(),
135+
args.num_threads,
132136
|(k, rows)| {
133137
if let Some(item) = id_map.get(&k) {
134138
let mut rows = rows.to_owned();
@@ -168,7 +172,9 @@ fn process_batch<P: AsRef<Path>>(
168172
},
169173
|result| {
170174
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");
172178
}
173179
},
174180
)
@@ -194,6 +200,10 @@ pub fn run(args: Args) -> Result<()> {
194200
let mut total_seqs = 0;
195201
let mut total_unclassified = 0;
196202

203+
if let Some(output) = &args.output_dir {
204+
create_dir_all(output)?;
205+
}
206+
197207
// 开始计时
198208
let start = Instant::now();
199209
println!("resolve start...");
@@ -202,7 +212,7 @@ pub fn run(args: Args) -> Result<()> {
202212
let sample_id_map = read_id_to_seq_map(&sample_id_files[i])?;
203213

204214
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 {
206216
Some(ref file_path) => {
207217
let filename = file_path.join(format!("output_{}.txt", i));
208218
let file = File::create(filename)?;
@@ -235,7 +245,7 @@ pub fn run(args: Args) -> Result<()> {
235245
.merge(&entry.value())
236246
.unwrap();
237247
});
238-
if let Some(output) = &args.kraken_output_dir {
248+
if let Some(output) = &args.output_dir {
239249
let filename = output.join(format!("output_{}.kreport2", i));
240250
report_kraken_style(
241251
filename,
@@ -252,7 +262,7 @@ pub fn run(args: Args) -> Result<()> {
252262
total_unclassified += thread_sequences - thread_classified;
253263
}
254264

255-
if let Some(output) = &args.kraken_output_dir {
265+
if let Some(output) = &args.output_dir {
256266
if !sample_files.is_empty() {
257267
let min = &sample_files.keys().min().cloned().unwrap();
258268
let max = &sample_files.keys().max().cloned().unwrap();

0 commit comments

Comments
 (0)