Skip to contents

Downloads each SRA run in `runs`, profiles its KEGG Orthology (KO) content with [fmh-funprofiler](https://github.com/KoslickiLab/fmh-funprofiler) (`funcprofiler`), 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 functional counterpart of [smash_runs()] and [sylph_runs()].

Usage

funprofiler_runs(
  runs,
  database = "../KOs_sketched_scaled_1000.sig.zip",
  k = 11,
  scaled = 1000,
  threshold_bp = 1000,
  outdir = file.path("data", "funprofiler"),
  working_file = "working_data.fastq.gz",
  threads = 6,
  quiet = FALSE,
  overwrite = FALSE,
  sra_env = "sra_env",
  funprofiler_env = "funprofiler_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 KO reference sketch (`.sig.zip` or `.sbt.zip`) for `funcprofiler`. Defaults to `"../KOs_sketched_scaled_1000.sig.zip"`.

k

Protein k-mer size(s): 7, 11 and/or 15, each of which must be in `database`. Defaults to 11.

scaled

Scaled value(s) for the FracMinHash sketch, each at least the scaled value of `database`. Defaults to 1000.

threshold_bp

Minimum estimated overlap, in base pairs, for a KO to be reported (`funcprofiler -t`). Larger values are faster but less sensitive. Defaults to 1000, as in `funcprofiler`.

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` and `pigz`.

quiet

If `TRUE`, hide the console output of `prefetch`, `fasterq-dump` and `funcprofiler`. Defaults to `FALSE`.

overwrite

If `TRUE`, make profiles that already exist again. If `FALSE` (the default), skip them.

sra_env

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

funprofiler_env

Conda environment with fmh-funprofiler (see [setup_conda_funprofiler()]).

Value

A tibble with one row per run and combination of `k` and `scaled`, invisibly, with columns `run_accession`, `k`, `scaled`, `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:

  1. 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.

  2. For each combination of `k` and `scaled`, `working_file` is profiled with `funcprofiler <working_file> <database> <k> <scaled> <output> -t <threshold_bp>` (in `funprofiler_env`). `funcprofiler` translates the reads and sketches them with `sourmash sketch translate`, compares the sketch with the KO database using `sourmash prefetch`, and reports each KO found with its relative abundance.

  3. The profile, a CSV file with columns `ko_id` and `abundance`, is written to `<outdir>/<run_accession>_k<k>_scale<scaled>_ko_profiles.csv`, e.g. `data/funprofiler/SRR123456_k11_scale1000_ko_profiles.csv`. A run with no KO matches gets a profile with no rows.

The intermediate files `funcprofiler` leaves behind (the metagenome sketch and the `sourmash prefetch` output) are deleted after each run. 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.

`k` is the *protein* k-mer size: `funcprofiler` accepts 7, 11 and 15 (DNA k-mer sizes 21, 33 and 45), which the pre-built KEGG sketches (<https://zenodo.org/records/10045253>) all include. `scaled` must be at least the database's scaled value (1000 for `KOs_sketched_scaled_1000.sig.zip`); sketches at other scaled values are available from <https://zenodo.org/records/10981414>. Before downloading anything, `funprofiler_runs()` reads the database's manifest (with `sourmash sig fileinfo`) and stops with an error if it has no protein sketches for a requested `k`, or if a requested `scaled` is smaller than the database's. `funcprofiler` does not check this itself: it would write an empty profile for a missing `k`, and silently compare a smaller `scaled` at the database's value. Several values of `k` or `scaled` give one profile per combination; each combination is a separate `funcprofiler` run over the 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 `funcprofiler` 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 `funprofiler_runs()` itself are shown either way, and can be hidden with [suppressMessages()].

A run that fails to download 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. Profiles that already exist (for the same run, `k` and `scaled`) are skipped unless `overwrite = TRUE`, so an interrupted job can be restarted with the same call. A run is downloaded only if at least one of its profiles still needs to be made. 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, and [funprofiler_local()] for local paired-end reads.

Examples

if (FALSE) { # \dontrun{
runs <- get_bioproject_runs("PRJNA123456")
res <- funprofiler_runs(runs[runs$library_strategy == "WGS", ])

# one table with every run's KO profile
kos <- do.call(rbind, lapply(seq_len(nrow(res)), function(i) {
  p <- utils::read.csv(res$profile[i])
  if (nrow(p)) cbind(run_accession = res$run_accession[i], p)
}))
} # }