The code in this vignette is not run when it is built, and the output shown is illustrative.
Metagenomes from human specimens (stool, swabs, saliva) contain human reads, which should not be made public. Before uploading them to SRA, mask those reads with NCBI’s Human Read Removal Tool (HRRT), the tool SRA itself uses to screen submissions. lims2sra runs it in three steps, as sra2lab runs its tools:
| function | |
|---|---|
setup_conda_hrrt() |
create a conda environment with HRRT and its human database |
document_conda_hrrt() |
record the environment and database, for a methods section |
hrrt_local() |
scrub each specimen’s paired FASTQ files |
Linux only. HRRT’s core program,
aligns_to, is built only for Linux on x86-64 (Intel or AMD) processors. The conda package installs on a Mac but cannot scrub there, so these functions stop with an error on anything else: run them on a Linux server or cluster.
How HRRT works
HRRT looks for k-mers from a database built from human RefSeq records, minus any k-mer also found in bacterial, archaeal or viral RefSeq records. A read with a hit is treated as human. The database includes k-mers that humans share with other primates and eukaryotes, so HRRT errs towards calling reads human, while keeping bacterial and viral pathogen reads.
By default the bases of each human read are replaced with
N, keeping its name and qualities. Every read stays in
place, so R1 and R2 stay paired and the files keep their read counts;
SRA accepts masked reads. hrrt_local() treats each read
pair (a spot) as a unit: if either read is human, both are
masked.
1. Set up the environment
Once, on the Linux machine (if conda is not found, set
options(lims2sra.conda = "/path/to/conda"); sra2lab’s
sra2lab.conda option works too, see “Finding conda” in
?setup_conda_hrrt):
This creates the conda environment hrrt_env with the
bioconda package sra-human-scrubber, downloads the current
human database from NCBI (about 1 GB) into it, and runs HRRT’s own test,
which should end with test succeeded.
2. Document it
document_conda_hrrt(write_yml = TRUE)
#> Wrote methods/hrrt_env.yml
#> ...
#> HRRT database: human_filter.db.20250916v2methods/hrrt_env.yml recreates the environment with
conda env create -f methods/hrrt_env.yml. The database is
not part of the environment export, so note its version (the date in its
name) in your methods too.
3. Scrub the reads
hrrt_local() takes a table of specimens (a data frame
with a specimen_id column) and the directory holding their
FASTQ files, found by their _R1/_R2 names as
in prepare_sra_metadata(). The specimen IDs can come
straight from the LIMS report: here, the stool swabs of a study, whose
barcodes name the sequence files.
aliquots <- lims_aggregate("data/IDSampleByStudy.xlsx")
stool <- aliquots[aliquots$sample_type == "Stool Swab", ]
scrubbed <- hrrt_local(stool, "/data/run1/fastq", threads = 16,
tmp_dir = "/scratch/hrrt")
#> HRRT database: human_filter.db.20250916v2
#> Specimen matches with /data/run1/fastq:
#> specimens with files found: 48 of 48 (100.0%)
#> file stems matching a specimen: 48 of 50 (96.0%)
#> [1/48] S-250917-01842: scrubbing S-250917-01842_S294_R1_001.fastq.gz + S-250917-01842_S294_R2_001.fastq.gz ...
#> [1/48] S-250917-01842: 2210 of 8915320 spots masked; wrote data/scrubbed/S-250917-01842_R1.fastq.gz, data/scrubbed/S-250917-01842_R2.fastq.gz
#> ...For each specimen, it writes to outdir (default
data/scrubbed):
-
<specimen_id>_R1.fastq.gzand<specimen_id>_R2.fastq.gz, the scrubbed reads; -
<specimen_id>_hrrt.tsv, the number of spots and of human spots.
The result has one row per specimen:
scrubbed
#> # A tibble: 48 × 8
#> specimen_id r1 r2 spots human_spots pct_human status message
#> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr>
#> 1 S-250917-01842 data/scrubbed/S-2509… data/… 8915320 2210 0.0248 scrubbed NA
#> ...pct_human is worth a look: a stool metagenome is usually
well under 1% human, while a skin or nasal swab can be mostly human.
Some options:
-
remove = TRUEremoves human spots instead of masking them, so the files get smaller and lose reads. -
save_removed = TRUEalso keeps the human spots in<specimen_id>_human.fastq.gz, to check what was flagged. These are human reads: store them accordingly, and do not upload them. -
databaseuses a different HRRT database, e.g. one copy shared by a lab. -
quiet = TRUEhides HRRT’s console output.
Each pair is uncompressed into tmp_dir while it is
scrubbed, and needs about three times the size of its uncompressed reads
there, so point tmp_dir at scratch space for large
metagenomes. HRRT also loads its 1 GB database into memory.
Reruns
A specimen whose scrubbed files already exist is skipped, so a long
run that was stopped can be started again with the same call. A specimen
that fails (e.g. its R1 and R2 have different numbers of reads) is
reported with a warning and the others carry on; run the same call again
to retry it. Set overwrite = TRUE to scrub everything
again, e.g. after updating the database.
4. Prepare the submission
The scrubbed files are named
<specimen_id>_R1.fastq.gz, as
prepare_sra_metadata() expects, so point it at them (see
vignette("metagenome-workflow")), and upload the scrubbed
files, not the originals:
prepare_sra_metadata(
"data/IDSampleByStudy.xlsx",
package = "metagenome",
fastq_dir = "data/scrubbed",
geo_loc_name = "USA: Pennsylvania, Philadelphia",
lat_lon = "39.95 N 75.19 W"
)Scrubbing before the upload means the human reads never leave your server, and the files you submit are the files that are released.