Skip to content

Commit

Permalink
fix!: paired reads require --output once for each file
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhall88 committed May 3, 2024
1 parent 3895c93 commit 1427a0b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,7 @@ NOTE: This parameter is required if passing paired Illumina data to `reads`.
By default, `rasusa` will output the subsampled file to `stdout` (if one file is given).
If you would prefer to specify an output file path, then use this option.

Output for Illumina paired files can be specified in the two ways

1. Using `--output` twice `-o out.r1.fq -o out.r2.fq`
2. Using `--output` once, but passing both files immediately after `-o out.r1.fq
out.r2.fq`
Output for Illumina paired files must be specified using `--output` twice - `-o out.r1.fq -o out.r2.fq`

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

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

*Note: if this option is given, genome size and coverage are not required.*
Expand Down Expand Up @@ -457,11 +453,13 @@ Arguments:
For paired Illumina, the order matters. i.e., R1 then R2.
Options:
-o, --output <OUTPUT>...
-o, --output <OUTPUT>
Output filepath(s); stdout if not present.
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.
For paired Illumina pass this flag twice `-o o1.fq -o 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.
-g, --genome-size <size|faidx>
Genome size to calculate coverage with respect to. e.g., 4.3kb, 7Tb, 9000, 4.1MB
Expand Down Expand Up @@ -619,7 +617,7 @@ mode as this is analogous to `rasusa reads`.
NUM_READS=140000
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;"
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;"
RASUSA_CMD="rasusa -i r1.fq r2.fq -n $NUM_READS -s 1 -o /tmp/r1.fq -o /tmp/r2.fq"
RASUSA_CMD="rasusa reads r1.fq r2.fq -n $NUM_READS -s 1 -o /tmp/r1.fq -o /tmp/r2.fq"
hyperfine --warmup 10 --runs 100 --export-markdown results-paired.md \
"$SEQTK_CMD_1" "$SEQTK_CMD_2" "$RASUSA_CMD"
```
Expand Down
25 changes: 19 additions & 6 deletions src/reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ pub struct Reads {

/// Output filepath(s); stdout if not present.
///
/// 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.
#[clap(short = 'o', long = "output", num_args = 1..=2)]
/// For paired Illumina pass this flag twice `-o o1.fq -o 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.
#[arg(short = 'o', long = "output", action = clap::ArgAction::Append)]
pub output: Vec<PathBuf>,

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

#[test]
fn all_valid_args_with_two_inputs_parsed_as_expected() {
fn two_outputs_passed_with_one_option_flag() {
let infile = "tests/cases/r1.fq.gz";
let passed_args = vec![
SUB,
Expand All @@ -490,7 +492,7 @@ mod tests {
];

let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.args(passed_args).assert().success();
cmd.args(passed_args).assert().failure();
}

#[test]
Expand Down Expand Up @@ -581,4 +583,15 @@ mod tests {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.args(passed_args).assert().success();
}

#[test]
fn two_input_two_outputs_is_ok_when_positional_args_at_end() {
let infile = "tests/cases/r1.fq.gz";
let passed_args = vec![
SUB, "-c", "5", "-g", "8mb", "-s", "88", "-o", "out.fq", "-o", "out.fq", infile, infile,
];

let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.args(passed_args).assert().success();
}
}
1 change: 1 addition & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ fn two_valid_illumina_inputs_suceeds() -> Result<(), Box<dyn std::error::Error>>
"2",
"-o",
"/tmp/out.fq",
"-o",
"/tmp/out2.fq",
]);

Expand Down

0 comments on commit 1427a0b

Please sign in to comment.