Skip to content

Commit

Permalink
Allow rasusa random seed to be configured (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfornika authored Mar 27, 2024
1 parent 0a424e8 commit a903c06
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ nextflow run BCCDC-PHL/downsample-reads \
--outdir </path/to/output_dir>
```

### Random Seed

rasusa allows users to specify a [random seed](https://github.com/mbhall88/rasusa?tab=readme-ov-file#random-seed) to be used
for its random subsampling algorithm. By default, rasusa generates a random seed at runtime using inputs from the operating system.
This pipeline sets the default random seed to `0`, which ensures that the same set of reads will be sampled given the same inputs.
A different random seed can be set using the `--random_seed` flag.

## Output

A pair of fastq.gz files will be produced for each target coverage, for each sample.
Expand Down Expand Up @@ -220,6 +227,8 @@ In the output directory for each sample, a provenance file will be written with
value: 10
- parameter: --genome-size
value: 4.4m
- parameter: --seed
value: 0
- filename: NC000962-downsample-10x_R1.fastq.gz
file_type: fastq-output
sha256: 2fe74753d889d1b6f02832a09b10a1cab51b1fb2e16a2af20577277aded07a83
Expand Down
31 changes: 17 additions & 14 deletions modules/downsample_reads.nf
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,26 @@ process downsample {

script:
"""
printf -- "- process_name: downsample\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " tools:\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " - tool_name: rasusa\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- "- process_name: downsample\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " tools:\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " - tool_name: rasusa\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " tool_version: \$(rasusa --version 2>&1 | cut -d ' ' -f 2)\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " parameters:\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " - parameter: --coverage\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " value: ${coverage}\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " - parameter: --genome-size\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " value: ${genome_size}\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " parameters:\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " - parameter: --coverage\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " value: ${coverage}\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " - parameter: --genome-size\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " value: ${genome_size}\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " - parameter: --seed\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
printf -- " value: ${params.random_seed}\\n" >> ${sample_id}_${coverage}x_downsample_provenance.yml
rasusa \
-i ${reads[0]} \
-i ${reads[1]} \
--coverage ${coverage} \
--genome-size ${genome_size} \
-o ${sample_id}-downsample-${coverage}x_R1.fastq.gz \
-o ${sample_id}-downsample-${coverage}x_R2.fastq.gz
--seed ${params.random_seed} \
-i ${reads[0]} \
-i ${reads[1]} \
--coverage ${coverage} \
--genome-size ${genome_size} \
-o ${sample_id}-downsample-${coverage}x_R1.fastq.gz \
-o ${sample_id}-downsample-${coverage}x_R2.fastq.gz
"""
}

3 changes: 2 additions & 1 deletion nextflow.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
manifest {
author = 'Dan Fornika'
name = 'BCCDC-PHL/downsample-reads'
version = '0.1.1'
version = '0.2.0'
description = 'Downsample Reads'
mainScript = 'main.nf'
nextflowVersion = '>=20.01.0'
Expand All @@ -17,6 +17,7 @@ params {
coverages = 'NO_FILE'
coverage = 30
genome_size = '5m'
random_seed = 0
enable_quality_trimming = false
disable_quality_filtering = false
collect_outputs = false
Expand Down

0 comments on commit a903c06

Please sign in to comment.