Downloads each SRA run in `runs`, profiles it against a sylph database, and deletes the reads before moving on, so that only one run's reads are ever stored locally. `runs` is typically the output of [get_bioproject_runs()], or a filtered version of it. This is the sylph counterpart of [smash_runs()].
Usage
sylph_runs(
runs,
database = "../gtdb-r232-c200-dbv2.syl2db",
outdir = file.path("data", "sylph"),
working_file = "working_data.fastq.gz",
threads = 6,
quiet = FALSE,
overwrite = FALSE,
sra_env = "sra_env",
sylph_env = "sylph_env"
)Arguments
- runs
A data frame with a `run_accession` column (SRR, ERR or DRR accessions), such as the output of [get_bioproject_runs()].
- database
Path to a sylph database (`.syldb`, or a two-stage `.syl2db`), passed to `sylph profile` with `-d`. Defaults to `"../gtdb-r232-c200-dbv2.syl2db"`. Pre-built databases are listed at <https://sylph-docs.github.io/pre%E2%80%90built-databases/>.
- outdir
Directory for the profile files. Created if needed.
- working_file
Path of the temporary reads file. If it ends in `.gz` (the default), the reads are compressed; otherwise (e.g. `"working_data.fastq"`), they are written as plain FASTQ, which is faster but takes several times the disk space.
- threads
Number of threads for `fasterq-dump`, `pigz`, `sylph sketch` and `sylph profile`.
- quiet
If `TRUE`, hide the console output of `prefetch`, `fasterq-dump` and `sylph`. Defaults to `FALSE`.
- overwrite
If `TRUE`, profile runs whose profile file already exists again. If `FALSE` (the default), skip them.
- sra_env
Conda environment with the SRA Toolkit (see [setup_conda_sra()]).
- sylph_env
Conda environment with sylph (see [setup_conda_sylph()]).
Value
A tibble with one row per run, invisibly, with columns `run_accession`, `profile` (path to the profile file, `NA` if it failed), `status` (`"profiled"`, `"skipped"` or `"failed"`) and `message` (why it failed, otherwise `NA`).
Details
The runs are processed in order with [purrr::pmap()]. For each run:
The run is downloaded with `prefetch` and its reads are extracted with `fasterq-dump –split-spot –skip-technical –stdout` (in `sra_env`) into a single file, `working_file`, compressed if it ends in `.gz`, as in [smash_runs()]. `working_file` is overwritten for each run.
`working_file` is sketched with `sylph sketch -r <working_file> -S <run_accession>` (in `sylph_env`), giving a temporary `<run_accession>.sylsp` sample sketch.
The sketch is profiled with `sylph profile -d <database> <run_accession>.sylsp`, and the profile is written to `<outdir>/<run_accession>_profiling.tsv`, e.g. `data/sylph/SRR123456_profiling.tsv`. Because the sample is named after the run, the profile's `Sample_file` column holds the run accession, so profiles from different runs can be combined directly.
When all runs are done, `working_file` is deleted. It is also deleted if the function stops early, for example on an error or interrupt.
Both mates of a paired-end spot are written to the same file (`–split-spot`), and sylph sketches them as single-end reads.
See [smash_runs()] for the disk space the download needs, and for skipping compression with a plain `working_file` such as `"working_data.fastq"`.
`prefetch`, `fasterq-dump` and `sylph` print progress to the console as they run. With `quiet = TRUE` that output is hidden; if a step fails, its last lines are included in the failure message. The one-line progress messages from `sylph_runs()` itself are shown either way, and can be hidden with [suppressMessages()].
A run that fails to download, sketch or profile is reported with a warning and recorded in the result; the remaining runs are still processed. Each failure is also reported straight away, with a `[3/120] SRR...: FAILED: <reason>` message, since R shows warnings only once the whole call has finished; the reason is kept in the result's `message` column. Runs whose profile already exists are skipped unless `overwrite = TRUE`, so an interrupted job can be restarted with the same call. Profiles left unfinished by an interrupted, killed or crashed R session are made again, not skipped (see [smash_runs()]).
See also
[get_bioproject_runs()] to list the runs in a BioProject, [smash_runs()] to sketch them with sourmash, and [sylph_local()] for local paired-end reads.
Examples
if (FALSE) { # \dontrun{
runs <- get_bioproject_runs("PRJNA123456")
res <- sylph_runs(runs[runs$library_strategy == "WGS", ], threads = 8)
# combine the profiles
profiles <- do.call(rbind, lapply(
res$profile[!is.na(res$profile)], utils::read.delim
))
} # }