Skip to contents

`rgi_stream()` is [rgi_runs()] without the download: instead of saving each run's reads to a file, it streams them from NCBI with `fastq-dump -Z –split-spot –skip-technical` (in `sra_env`) straight into `rgi bwt` (in `rgi_env`), so no reads are ever written to disk. It takes the same arguments as [rgi_runs()] (apart from `working_file`), checks the CARD data in `card_db` in the same way, writes the same outputs (`<outdir>/<run_accession>_<aligner>[_wildcard][_other_models].<output>`), and returns the same result, and each skips outputs the other has made. As with [rgi_runs()], the results are read-level: see [rgi_runs()] for how CARD's data must be loaded first, and for what the results can and cannot tell you.

Usage

rgi_stream(
  runs,
  card_db = "../localDB",
  aligner = "kma",
  include_wildcard = FALSE,
  include_other_models = FALSE,
  keep_bam = FALSE,
  outdir = file.path("data", "rgi"),
  threads = 6,
  quiet = FALSE,
  overwrite = FALSE,
  sra_env = "sra_env",
  rgi_env = "rgi_env"
)

Arguments

runs

A data frame with a `run_accession` column (SRR, ERR or DRR accessions), such as the output of [get_bioproject_runs()].

card_db

The `localDB` directory of CARD data loaded with `rgi load –local` (see "CARD reference data"), or `NULL` to use the data loaded into `rgi_env`. Defaults to `"../localDB"`.

aligner

Read aligner(s) for `rgi bwt`: `"kma"` (the default, and RGI's recommendation), `"bowtie2"` and/or `"bwa"`. Several give one set of outputs per aligner.

include_wildcard

If `TRUE`, also map reads to CARD's Resistomes & Variants (WildCARD) sequences (`–include_wildcard`).

include_other_models

If `TRUE`, also map reads to CARD's protein variant, rRNA variant, knockout and protein overexpression models (`–include_other_models`). RGI does not yet check these against CARD's curated resistance mutations, so their hits need care.

keep_bam

If `TRUE`, keep the sorted BAM alignment file and its index. If `FALSE` (the default), they are deleted to save space.

outdir

Directory for the output files. Created if needed. Defaults to `data/rgi`.

threads

Number of threads for `rgi bwt`.

quiet

If `TRUE`, hide the console output of `fastq-dump` and `rgi`. Defaults to `FALSE`.

overwrite

If `TRUE`, run samples whose output already exists again. If `FALSE` (the default), skip them.

sra_env

Conda environment with the SRA Toolkit (see [setup_conda_sra()]).

rgi_env

Conda environment with RGI (see [setup_conda_rgi()]).

Value

A tibble with one row per run and aligner, invisibly, as returned by [rgi_runs()].

Details

The reads reach RGI through a named pipe (FIFO) in a temporary directory, which `rgi bwt` reads as if it were a reads file; both reads of each paired-end spot are streamed one after the other, as in [rgi_runs()]. A stream can only be read once, so with several aligners, each run is streamed once per aligner. See [smash_stream()] for when streaming helps.

Streaming saves the space the reads would take, but not the space RGI needs while it works: its aligner writes temporary alignment files next to the outputs in `outdir`, which can be several times the size of the run's compressed reads (about 1.4 GB for a 378 MB run), and which RGI deletes when it finishes.

The read counts in a gene's "Mapped Reads with Flanking Sequence" column (and so "All Mapped Reads") can differ by a few reads between runs of `rgi bwt` on the same reads, streamed or not; the genes found and their "Completely Mapped Reads" do not.

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

[rgi_runs()], which downloads each run with `fasterq-dump` before mapping it, and [smash_stream()], [sylph_stream()] and [funprofiler_stream()].

Examples

if (FALSE) { # \dontrun{
runs <- get_bioproject_runs("PRJNA123456")
rgi_stream(runs, card_db = "../localDB")
} # }