File tree 3 files changed +16
-3
lines changed
3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,12 @@ pub struct Normalize {
41
41
#[ arg( long, value_enum, default_value_t = Method :: Tpm ) ]
42
42
pub method : Method ,
43
43
44
+ /// Output destination.
45
+ ///
46
+ /// If not set, output is written to stdout.
47
+ #[ arg( short = 'o' , long) ]
48
+ pub output : Option < PathBuf > ,
49
+
44
50
/// Input counts file.
45
51
pub src : PathBuf ,
46
52
}
Original file line number Diff line number Diff line change @@ -28,16 +28,18 @@ pub enum NormalizeError {
28
28
Normalization ( #[ source] normalization:: Error ) ,
29
29
}
30
30
31
- pub fn normalize < P , Q > (
31
+ pub fn normalize < P , Q , R > (
32
32
src : P ,
33
33
annotations_src : Q ,
34
34
feature_type : & str ,
35
35
id : & str ,
36
36
method : normalization:: Method ,
37
+ dst : Option < R > ,
37
38
) -> Result < ( ) , NormalizeError >
38
39
where
39
40
P : AsRef < Path > ,
40
41
Q : AsRef < Path > ,
42
+ R : AsRef < Path > ,
41
43
{
42
44
let annotations_src = annotations_src. as_ref ( ) ;
43
45
65
67
normalization:: Method :: Tpm => tpm:: normalize ( & lengths, & counts) ,
66
68
} ;
67
69
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
+ } ;
70
76
71
77
write_normalized_counts ( & mut writer, & names, & normalized_counts) ?;
72
78
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ fn normalize(options: cli::Normalize) -> anyhow::Result<()> {
58
58
& options. feature_type ,
59
59
& options. id ,
60
60
options. method ,
61
+ options. output ,
61
62
) ?;
62
63
63
64
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments