Skip to content

Commit 8de8be8

Browse files
committed
cli: Add output option for normalize command
1 parent 290e985 commit 8de8be8

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

Diff for: src/cli.rs

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ pub struct Normalize {
4141
#[arg(long, value_enum, default_value_t = Method::Tpm)]
4242
pub method: Method,
4343

44+
/// Output destination.
45+
///
46+
/// If not set, output is written to stdout.
47+
#[arg(short = 'o', long)]
48+
pub output: Option<PathBuf>,
49+
4450
/// Input counts file.
4551
pub src: PathBuf,
4652
}

Diff for: src/commands/normalize.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ pub enum NormalizeError {
2828
Normalization(#[source] normalization::Error),
2929
}
3030

31-
pub fn normalize<P, Q>(
31+
pub fn normalize<P, Q, R>(
3232
src: P,
3333
annotations_src: Q,
3434
feature_type: &str,
3535
id: &str,
3636
method: normalization::Method,
37+
dst: Option<R>,
3738
) -> Result<(), NormalizeError>
3839
where
3940
P: AsRef<Path>,
4041
Q: AsRef<Path>,
42+
R: AsRef<Path>,
4143
{
4244
let annotations_src = annotations_src.as_ref();
4345

@@ -65,8 +67,12 @@ where
6567
normalization::Method::Tpm => tpm::normalize(&lengths, &counts),
6668
};
6769

68-
let stdout = io::stdout().lock();
69-
let mut writer = BufWriter::new(stdout);
70+
let mut writer: Box<dyn Write> = if let Some(dst) = dst {
71+
File::create(dst).map(BufWriter::new).map(Box::new)?
72+
} else {
73+
let stdout = io::stdout().lock();
74+
Box::new(BufWriter::new(stdout))
75+
};
7076

7177
write_normalized_counts(&mut writer, &names, &normalized_counts)?;
7278

Diff for: src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ fn normalize(options: cli::Normalize) -> anyhow::Result<()> {
5858
&options.feature_type,
5959
&options.id,
6060
options.method,
61+
options.output,
6162
)?;
6263

6364
Ok(())

0 commit comments

Comments
 (0)