hrrt_local() masks (or removes) human reads in each specimen's paired
FASTQ files with NCBI's
Human Read Removal Tool
(HRRT), the tool SRA itself uses to screen human reads in submissions.
Scrub metagenomic reads from human specimens before uploading them to
SRA. It needs the conda environment made by setup_conda_hrrt(), and so,
like HRRT, runs only on Linux on x86-64 processors.
Arguments
- specimens
A data frame with a
specimen_idcolumn, such as the output oflims_aggregate()(filtered to the sequenced aliquots). The IDs are used in the output file names, so they must be unique and must not contain/or\. Other columns are ignored.- local_files
Directory holding the specimens' paired FASTQ files.
- outdir
Directory for the scrubbed files. Created if needed. Must not be
local_files. Defaults todata/scrubbed.- remove
If
FALSE(the default), mask human spots by replacing their bases withN. IfTRUE, remove them, so the scrubbed files have fewer reads than the originals.- save_removed
If
TRUE, also write the human spots, unmasked and interleaved, to<outdir>/<specimen_id>_human.fastq.gz, e.g. to check what was flagged. These are human reads: store them accordingly.- database
Path to an HRRT database (
human_filter.db). IfNULL(the default), the database downloaded intohrrt_envbysetup_conda_hrrt().- threads
Number of threads for HRRT's
aligns_to.- tmp_dir
Directory for the temporary files (see "Disk space").
- quiet
If
TRUE, hide HRRT's console output. Defaults toFALSE.- overwrite
If
TRUE, scrub specimens whose outputs already exist. IfFALSE(the default), skip them.- hrrt_env
Conda environment with HRRT (see
setup_conda_hrrt()).
Value
A tibble, invisibly, with one row per specimen:
specimen_idThe specimen.
r1,r2The scrubbed files (
NAif it failed).spotsThe number of spots (read pairs).
human_spotsThe number of spots masked or removed.
pct_humanhuman_spotsas a percentage ofspots.status"scrubbed","skipped"(already done) or"failed".messageWhy it failed.
The database used is given in a message.
Details
For each specimen, hrrt_local():
finds its R1 and R2 files in
local_files, asprepare_sra_metadata()does (see "Finding read files");interleaves them, so each spot (read pair) is its R1 read followed by its R2 read;
identifies the spots with human k-mers (HRRT's
aligns_to);masks both reads of each human spot, replacing their bases with
N(HRRT's default), or withremove = TRUEremoves the spot;splits the spots back into
<outdir>/<specimen_id>_R1.fastq.gzand<specimen_id>_R2.fastq.gz, and writes the counts to<specimen_id>_hrrt.tsv.
Steps 2 to 4 are HRRT's scrub.sh -s, run directly (see
system.file("bash", "hrrt_pair.sh", package = "lims2sra")), because
the bioconda build of scrub.sh 2.2.1 numbers the spots inconsistently
with -s and would mask the wrong reads.
Masking keeps every read, in the same order, so R1 and R2 stay paired and
the read counts match the original files; SRA accepts masked reads. The
scrubbed files are named as prepare_sra_metadata() expects, so pass
outdir to its fastq_dir. The original files are never changed.
Finding read files
Files in local_files (not its subdirectories) are recognized by their
R1/R2 designator, _R1 or _R2, optionally followed by _001, then
.fastq or .fq, optionally gzipped (e.g.
S-240926-01587_S294_R1_001.fastq.gz or S-01_R2.fq). A file belongs to
a specimen when the text before _R1/_R2 is the specimen ID, alone or
followed by _ and anything else (_S294, _S572_L001). The _ keeps
specimen S-1 from claiming the files of S-10, and a file goes to the
longest specimen ID it matches. Matching is case-sensitive and
character-exact, so - and _ are not interchangeable. A message
reports how many specimens had files found. Specimens without both an R1
and an R2 file are recorded as "failed", with a warning; the others are
still scrubbed.
Reruns and failures
A specimen whose outputs all exist is skipped (its counts are read back
from <specimen_id>_hrrt.tsv) unless overwrite = TRUE. Outputs left
unfinished by an interrupted, killed or crashed R session are made again:
before a specimen is scrubbed, a hidden marker file is written beside each
output and removed when it is finished. A specimen that fails is reported
with a warning and its outputs are removed; run the same call again to
retry only the failed specimens.
Disk space
Each pair is uncompressed into tmp_dir while it is scrubbed, and needs
about three times the size of its uncompressed reads there at the peak.
The default, R's tempdir(), may be on a small disk: point tmp_dir at
scratch space for large metagenomes. HRRT also loads its database (about
1 GB) into memory.
See also
setup_conda_hrrt(), document_conda_hrrt(), and
prepare_sra_metadata() for the SRA metadata of the scrubbed files.
Examples
if (FALSE) { # \dontrun{
specimens <- tibble::tibble(specimen_id = c("S-01", "S-02"))
# data/scrubbed/S-01_R1.fastq.gz, S-01_R2.fastq.gz, S-01_hrrt.tsv, ...
scrubbed <- hrrt_local(specimens, "fastq", threads = 16,
tmp_dir = "/scratch/hrrt")
# then the SRA metadata for the scrubbed files
prepare_sra_metadata("IDSampleByStudy.xlsx", fastq_dir = "data/scrubbed",
geo_loc_name = "USA: Pennsylvania, Philadelphia",
lat_lon = "39.95 N 75.19 W")
} # }