`smash_stream()` is [smash_runs()] without the download: instead of saving each run's reads to a file and then sketching it, it streams the reads from NCBI with `fastq-dump -Z` straight into `sourmash sketch dna`, so no reads are ever written to disk. It takes the same arguments as [smash_runs()] (apart from `working_file` and `threads`), writes the same signature files, and returns the same result, so the two can be used interchangeably, and each skips signatures the other has made.
Usage
smash_stream(
runs,
k = 31,
scaled = 1000,
method = "abund",
seed = 42,
outdir = file.path("data", "smash"),
quiet = FALSE,
overwrite = FALSE,
sra_env = "sra_env",
smash_env = "smash_env"
)Arguments
- runs
A data frame with a `run_accession` column (SRR, ERR or DRR accessions), such as the output of [get_bioproject_runs()].
- k
k-mer size(s) for the sketch, e.g. `31` or `c(21, 31, 51)`.
- scaled
Scaled value(s) for the FracMinHash sketch, e.g. `1000` or `c(1000, 100)`.
- method
`"abund"` to track k-mer abundance, `"noabund"` not to, or `c("abund", "noabund")` for both. Defaults to `"abund"`.
- seed
Hash seed for the sketch. Only a single seed is allowed.
- outdir
Directory for the signature files. Created if needed.
- quiet
If `TRUE`, hide the console output of `fastq-dump` and `sourmash`. Defaults to `FALSE`.
- overwrite
If `TRUE`, sketch runs whose signature file already exists again. If `FALSE` (the default), skip them.
- sra_env
Conda environment with the SRA Toolkit (see [setup_conda_sra()]).
- smash_env
Conda environment with sourmash (see [setup_conda_sourmash()]).
Value
A tibble with one row per run and combination of `k`, `scaled` and `method`, invisibly, as returned by [smash_runs()].
Details
The runs are processed in order with [purrr::pmap()]. For each run, the reads are streamed with `fastq-dump -Z –split-spot –skip-technical <run_accession>` (in `sra_env`), and piped to `sourmash sketch dna -p k=<k>,scaled=<scaled>,<method>,seed=<seed> -` (in `smash_env`). `-Z` writes the reads to standard output; `–split-spot` writes both reads of a paired-end spot, one after the other; and `–skip-technical` leaves out technical reads such as barcodes, as in [smash_runs()]. The signature is named after the run accession, and each combination of `k`, `scaled` and `method` gets its own signature file, `<outdir>/<run_accession>_k<k>_scale<scaled>_seed<seed>_<method>.sig`, as in [smash_runs()].
Streaming saves disk space and the time spent writing and re-reading a reads file, but `fastq-dump` is single-threaded, so it can be slower than `fasterq-dump` for large runs; which is faster depends on your connection and disk. If the stream is cut off (for example, by a network error), the pipeline fails, rather than leaving a sketch of part of the run, and the run is recorded as `"failed"` (see "Internet connection" below).
As in [smash_runs()], a run that fails is reported with a warning and recorded in the result, while the remaining runs are still processed; signature files that already exist are skipped unless `overwrite = TRUE` (outputs left unfinished by an interrupted, killed or crashed R session are made again); and `quiet = TRUE` hides the console output of `fastq-dump` and `sourmash`.
Internet connection
The reads are downloaded while the tool runs, so a `*_stream()` function needs a steady internet connection for as long as each run is being processed, and is more likely than the `*_runs()` functions to fail if the connection is slow, drops out or is unreliable, or if NCBI is busy. A run whose stream is cut off fails (`fastq-dump`'s exit status fails the step) rather than being sketched, profiled or mapped from part of its reads; it is reported with a warning and recorded as `"failed"`, and the remaining runs still go ahead. Run the same call again to retry the failed runs; on an unreliable connection, the `*_runs()` functions, which finish each download before processing it, may be the better choice.
See also
[smash_runs()], which downloads each run with `fasterq-dump` before sketching it, and [sylph_stream()], [funprofiler_stream()] and [rgi_stream()].
Examples
if (FALSE) { # \dontrun{
runs <- get_bioproject_runs("PRJNA123456")
smash_stream(runs[runs$library_strategy == "WGS", ])
# 2 k-mer sizes x 2 scaled values = 4 files per run, from one stream
smash_stream(runs, k = c(21, 31), scaled = c(1000, 100))
} # }