Skip to content

Commit 1427a0b

Browse files
committed
fix!: paired reads require --output once for each file
1 parent 3895c93 commit 1427a0b

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

README.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,7 @@ NOTE: This parameter is required if passing paired Illumina data to `reads`.
295295
By default, `rasusa` will output the subsampled file to `stdout` (if one file is given).
296296
If you would prefer to specify an output file path, then use this option.
297297

298-
Output for Illumina paired files can be specified in the two ways
299-
300-
1. Using `--output` twice `-o out.r1.fq -o out.r2.fq`
301-
2. Using `--output` once, but passing both files immediately after `-o out.r1.fq
302-
out.r2.fq`
298+
Output for Illumina paired files must be specified using `--output` twice - `-o out.r1.fq -o out.r2.fq`
303299

304300
The ordering of the output files is assumed to be the same as the input.
305301
_Note: The output will always be in the same format as the input. You cannot pass fastq
@@ -386,7 +382,7 @@ Explicitly set the number of reads in the subsample. This option takes the numbe
386382
the same format as [genome size](#genome-size).
387383

388384
When providing paired reads as input, this option will sample this many total read
389-
pairs. For example, when passing `-n 20 -i r1.fq r2.fq`, the two output files will have
385+
pairs. For example, when passing `-n 20 r1.fq r2.fq`, the two output files will have
390386
20 reads each, and the read ids will be the same in both.
391387

392388
*Note: if this option is given, genome size and coverage are not required.*
@@ -457,11 +453,13 @@ Arguments:
457453
For paired Illumina, the order matters. i.e., R1 then R2.
458454
459455
Options:
460-
-o, --output <OUTPUT>...
456+
-o, --output <OUTPUT>
461457
Output filepath(s); stdout if not present.
462458
463-
For paired Illumina you may either pass this flag twice `-o o1.fq -o o2.fq` or give two files consecutively `-o o1.fq o2.fq`. NOTE: The order of the pairs is assumed to be the same as the input - e.g., R1 then R2. This option is required for paired input.
459+
For paired Illumina pass this flag twice `-o o1.fq -o o2.fq`
464460
461+
NOTE: The order of the pairs is assumed to be the same as the input - e.g., R1 then R2. This option is required for paired input.
462+
465463
-g, --genome-size <size|faidx>
466464
Genome size to calculate coverage with respect to. e.g., 4.3kb, 7Tb, 9000, 4.1MB
467465
@@ -619,7 +617,7 @@ mode as this is analogous to `rasusa reads`.
619617
NUM_READS=140000
620618
SEQTK_CMD_1="seqtk sample -s 1 r1.fq $NUM_READS > /tmp/r1.fq; seqtk sample -s 1 r2.fq $NUM_READS > /tmp/r2.fq;"
621619
SEQTK_CMD_2="seqtk sample -2 -s 1 r1.fq $NUM_READS > /tmp/r1.fq; seqtk sample -2 -s 1 r2.fq $NUM_READS > /tmp/r2.fq;"
622-
RASUSA_CMD="rasusa -i r1.fq r2.fq -n $NUM_READS -s 1 -o /tmp/r1.fq -o /tmp/r2.fq"
620+
RASUSA_CMD="rasusa reads r1.fq r2.fq -n $NUM_READS -s 1 -o /tmp/r1.fq -o /tmp/r2.fq"
623621
hyperfine --warmup 10 --runs 100 --export-markdown results-paired.md \
624622
"$SEQTK_CMD_1" "$SEQTK_CMD_2" "$RASUSA_CMD"
625623
```

src/reads.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ pub struct Reads {
2626

2727
/// Output filepath(s); stdout if not present.
2828
///
29-
/// For paired Illumina you may either pass this flag twice `-o o1.fq -o o2.fq` or give two
30-
/// files consecutively `-o o1.fq o2.fq`. NOTE: The order of the pairs is assumed to be the
31-
/// same as the input - e.g., R1 then R2. This option is required for paired input.
32-
#[clap(short = 'o', long = "output", num_args = 1..=2)]
29+
/// For paired Illumina pass this flag twice `-o o1.fq -o o2.fq`
30+
///
31+
/// NOTE: The order of the pairs is assumed to be the same as the input - e.g., R1 then R2.
32+
///
33+
/// This option is required for paired input.
34+
#[arg(short = 'o', long = "output", action = clap::ArgAction::Append)]
3335
pub output: Vec<PathBuf>,
3436

3537
/// Genome size to calculate coverage with respect to. e.g., 4.3kb, 7Tb, 9000, 4.1MB
@@ -472,7 +474,7 @@ mod tests {
472474
}
473475

474476
#[test]
475-
fn all_valid_args_with_two_inputs_parsed_as_expected() {
477+
fn two_outputs_passed_with_one_option_flag() {
476478
let infile = "tests/cases/r1.fq.gz";
477479
let passed_args = vec![
478480
SUB,
@@ -490,7 +492,7 @@ mod tests {
490492
];
491493

492494
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
493-
cmd.args(passed_args).assert().success();
495+
cmd.args(passed_args).assert().failure();
494496
}
495497

496498
#[test]
@@ -581,4 +583,15 @@ mod tests {
581583
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
582584
cmd.args(passed_args).assert().success();
583585
}
586+
587+
#[test]
588+
fn two_input_two_outputs_is_ok_when_positional_args_at_end() {
589+
let infile = "tests/cases/r1.fq.gz";
590+
let passed_args = vec![
591+
SUB, "-c", "5", "-g", "8mb", "-s", "88", "-o", "out.fq", "-o", "out.fq", infile, infile,
592+
];
593+
594+
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
595+
cmd.args(passed_args).assert().success();
596+
}
584597
}

tests/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ fn two_valid_illumina_inputs_suceeds() -> Result<(), Box<dyn std::error::Error>>
152152
"2",
153153
"-o",
154154
"/tmp/out.fq",
155+
"-o",
155156
"/tmp/out2.fq",
156157
]);
157158

0 commit comments

Comments
 (0)