Prepare NCBI BioSample and SRA metadata from a biobank sample report
Source:R/lims2sra.R
prepare_sra_metadata.RdReorganizes a biobank sample report (e.g. IDSampleByStudy_*.xlsx) into
the two tables needed for an NCBI SRA submission:
BioSample attributes, laid out in the column order of an NCBI BioSample package template (Metagenome.environmental.1.0 or Microbe.1.0). The templates ship with the package as the zero-row data frames
Metagenome_environmentalandMicrobe.SRA metadata, one row per sample, linking each sample to its two paired-end read files (R1 and R2). By default these are named
<Sample>_R1.fastq.gzand<Sample>_R2.fastq.gz; iffastq_diris given, the actual files are found by their "R1"/"R2" designator, e.g.<Sample>_S294_R1_001.fastq.gz.
Both tables share sample_name (the report's "Sample" column), which the
NCBI Submission Portal uses to join SRA runs to BioSamples.
If fastq_dir is given, a message reports the number and percentage of
input_xlsx samples found in fastq_dir, and of fastq_dir samples found
in input_xlsx.
Usage
prepare_sra_metadata(
input_xlsx,
package = c("metagenome", "microbe"),
output_dir = dirname(input_xlsx),
bioproject_accession = "",
geo_loc_name = "missing",
lat_lon = "missing",
host = "Homo sapiens",
metagenome_organism = c(Stool = "human gut metagenome", Feces = "human gut metagenome",
`Stool in Glycerol` = "human gut metagenome", `Stool in RNALater` =
"human gut metagenome", `Stool Swab` = "human gut metagenome", `Rectal Swab` =
"human gut metagenome", `Perirectal Swab` = "human gut metagenome", `Axilla Swab` =
"human skin metagenome", `Groin Swab` = "human skin metagenome", `Nasal Swab` =
"human nasopharyngeal metagenome", `Oral Swab` = "human oral metagenome",
`Throat Swab` = "human oral metagenome", Saliva = "human saliva metagenome",
Sputum = "human sputum metagenome", EndotrachealAspirate =
"human tracheal metagenome", `Inner Cannula` = "human tracheal metagenome", Urine =
"human urinary tract metagenome", `Blood Serum` = "human blood metagenome",
`Plasma (EDTA)` = "human blood metagenome", `Whole Blood` = "human blood metagenome",
`Whole Blood (EDTA)` = "human blood metagenome", `Whole Blood (Heparin)` =
"human blood metagenome", `Environmental Swab` = "indoor metagenome", Environment =
"indoor metagenome", `Fomite Swab` = "indoor metagenome",
Buffer =
"blank sample"),
derived_sample_types = c("DNA", "RNA", "Cell Lysate", "Cell Pellet", "Cells",
"Cell Suspension", "Fluid", "Virus", "Bacterial Cell Iso"),
microbe_organism = NULL,
microbe_sample_type = "missing",
body_site = c(Stool = "feces", Feces = "feces", `Stool in Glycerol` = "feces",
`Stool in RNALater` = "feces", `Stool Swab` = "feces", `Rectal Swab` = "rectum",
`Perirectal Swab` = "perirectal region", `Axilla Swab` = "axilla", `Groin Swab` =
"groin", `Nasal Swab` = "anterior nares", `Oral Swab` = "oral cavity", `Throat Swab`
= "oropharynx", Saliva = "oral cavity", Sputum = "lower respiratory tract",
EndotrachealAspirate = "trachea", `Inner Cannula` = "trachea", Urine =
"urinary tract", `Blood Serum` = "blood",
`Plasma (EDTA)` = "blood",
`Whole Blood` = "blood", `Whole Blood (EDTA)` = "blood", `Whole Blood (Heparin)` =
"blood"),
environmental_sample_types = c("Environmental Swab", "Environment", "Fomite Swab"),
include_subject_id = TRUE,
fastq_dir = NULL,
library_strategy = "WGS",
library_source = NULL,
library_selection = "RANDOM",
platform = "ILLUMINA",
instrument_model = "Illumina NovaSeq 6000",
design_description = NULL
)Arguments
- input_xlsx
Path to the sample report. Must contain the columns "Sample", "Sample Type" and "Collection Date". "External Participant ID", "Original Sample Type" and "Microbial Species" are used when present.
- package
BioSample package to target:
"metagenome"(Metagenome.environmental.1.0) or"microbe"(Microbe.1.0).- output_dir
Directory to write the outputs to (two .tsv files and one .xlsx with both tables). Created if needed. If
NULL, nothing is written.- bioproject_accession
BioProject accession (e.g.
"PRJNA123456"). Leave blank if it is not yet assigned.- geo_loc_name
Mandatory geographic location, using the INSDC country vocabulary, e.g.
"USA: Pennsylvania, Philadelphia".- lat_lon
Latitude and longitude, e.g.
"39.95 N 75.19 W". Mandatory for the metagenome package; optional (left blank if"missing") for the microbe package.- host
Natural host organism, as a full taxonomic name. For the metagenome package, only applied to samples from a human metagenome (organism starting with "human"); left blank for environmental samples and blanks. For the microbe package, applied to every isolate except those cultured from
environmental_sample_types.- metagenome_organism
For the metagenome package: either a named character vector mapping specimen types to NCBI Taxonomy metagenome names, or a single string applied to every sample. Unmapped types get
"missing"and a warning. The default covers the specimen types found in the MOTION LabVantage reports; every name is a valid NCBI Taxonomy name:stool, feces, stool in glycerol/RNAlater, stool, rectal and perirectal swabs: "human gut metagenome"
axilla and groin swabs: "human skin metagenome"
nasal swabs: "human nasopharyngeal metagenome"
oral and throat swabs: "human oral metagenome"; saliva: "human saliva metagenome"
sputum: "human sputum metagenome"
endotracheal aspirates and tracheostomy inner cannulas: "human tracheal metagenome"
urine: "human urinary tract metagenome"
serum, plasma and whole blood: "human blood metagenome"
environmental, environment and fomite swabs: "indoor metagenome" (use "hospital metagenome" if all of them are from hospital surfaces)
buffer (reagent blanks): "blank sample"
Bacterial cultures and isolates are left unmapped: they belong in the microbe package.
- derived_sample_types
"Sample Type" values that are laboratory derivatives rather than specimens, including cultured isolates ("Bacterial Cell Iso"). For these samples the "Original Sample Type" column is used instead, when it is filled in, so an isolate is described by the specimen it was cultured from.
- microbe_organism
For the microbe package: organism name applied to every sample (or a vector with one value per sample). If
NULL, the report's "Microbial Species" column is used; samples with no organism get"missing"and a warning.- microbe_sample_type
For the microbe package: value of the mandatory
sample_typeattribute, e.g."cell culture"or"mixed culture".- body_site
Named character vector mapping specimen types to the body site written to
host_tissue_sampled(microbe package only).- environmental_sample_types
Specimen types from the built environment rather than a host. Isolates cultured from them get a blank
host(microbe package only).- include_subject_id
If
TRUE, the report's "External Participant ID" is added as the custom BioSample attributehost_subject_id. The internal "Participant" ID is never exported.- fastq_dir
Optional directory of FASTQ files. If given, read files are recognized by their "R1"/"R2" designator (e.g.
S_250917_01842_S294_R1_001.fastq.gz) and matched to the "Sample" ID: the text before "_R1"/"R2" must be the Sample ID, alone or followed by "" and anything else (e.g._S294), so sampleS-240926-01587matchesS-240926-01587_S294_R1_001.fastq.gzbut sampleS-1does not matchS-10_R1_001.fastq.gz. Matching is case-sensitive and character-exact, so-and_are not interchangeable. The actual file names are used infilename/filename2. Samples whose R1 or R2 file is not found are dropped with a warning. If a sample matches more than one pair of files, one pair is used and a warning names the sample. A FASTQ sample is one unique file name stem (the text before "_R1"/"_R2"). Sample name matches are summarized in a console message (see Description); a sample with only one of its two read files still counts as found there, because its name matches, but is dropped from the output.- library_strategy
SRA library strategy (e.g.
"WGS","AMPLICON").- library_source
SRA library source. If
NULL,"METAGENOMIC"for the metagenome package and"GENOMIC"for the microbe package.- library_selection
SRA library selection method (e.g.
"RANDOM","PCR").- platform
Sequencing platform (e.g.
"ILLUMINA").- instrument_model
Sequencing instrument, using SRA's controlled vocabulary (e.g.
"Illumina NovaSeq 6000","Illumina NovaSeq X").- design_description
Free-text description of library preparation. If
NULL, a description is generated from the package and sample type, e.g. "Paired-end whole-genome sequencing of DNA extracted from an isolate cultured from throat swab". The SRAtitleis generated the same way: from the specimen type for metagenomes, and from the organism and Sample ID for isolates (e.g. "Whole-genome sequencing of Staphylococcus aureus isolate S_240926_02278").
Value
A list with two data frames: biosample (BioSample attributes, in
template column order) and sra (SRA metadata, with filename and
filename2 for the R1 and R2 reads). Returned invisibly when
output_dir is not NULL.
Details
Samples whose "Sample Type" is a laboratory derivative (see
derived_sample_types, e.g. DNA, Cell Lysate or a bacterial isolate) are
described by the specimen they came from, taken from the "Original Sample
Type" column. That specimen type sets the organism, isolation_source, body
site and, for isolates, whether there is a host.