Skip to contents

This vignette walks through preparing an NCBI Sequence Read Archive (SRA) submission of human metagenomes with lims2sra: reading a sample report exported from a LIMS (here, LabVantage), turning it into BioSample and SRA metadata tables with prepare_sra_metadata(package = "metagenome"), and using those tables in the NCBI Submission Portal. It also shows how a folder of sequence files that holds only some of the report’s samples changes the result.

The example report lists 50 stool and stool swab specimens, from 50 subjects in the mVACS study, that were sequenced as paired-end Illumina shotgun metagenomes.

The NCBI submission in brief

An SRA submission is made of three linked records:

  • a BioProject, describing the study as a whole;
  • one BioSample per specimen, describing where it came from: organism, host, specimen type, collection date and place;
  • one SRA experiment and run per sequencing library, describing how it was sequenced and listing its read files.

All three can be created in one pass through the SRA submission wizard of the NCBI Submission Portal. The wizard asks for two tables, which are what prepare_sra_metadata() writes: a BioSample attributes table, in the column layout of the chosen BioSample package, and an SRA metadata table. The two are joined by sample_name.

1. Set up an analysis directory

Keep each submission in its own directory, with the LIMS report under data/ and the files for NCBI under submission/:

mVACS/                                                 <- working directory
├── data/
│   └── IDSampleReport_lims2sra_metagenome_demo.xlsx     <- LIMS report
├── fastq/                                             <- read files (step 4)
└── submission/                                        <- files for NCBI (steps 3-4)

The demo report ships with lims2sra, in the vignettes/metagenome-demo/data/ folder of the package source.

2. Read the sample report

library(lims2sra)

report_xlsx <- "data/IDSampleReport_lims2sra_metagenome_demo.xlsx"
report <- readxl::read_excel(report_xlsx)
dim(report)
#> [1] 50 18
names(report)
#>  [1] "External Participant ID" "Participant"            
#>  [3] "Study"                   "Sample"                 
#>  [5] "Identifier"              "Sample Type"            
#>  [7] "Container"               "Sample Source"          
#>  [9] "Microbial Species"       "Original Sample Type"   
#> [11] "Immediate Parent"        "Tissue"                 
#> [13] "Department"              "Custodian"              
#> [15] "Status"                  "Disposal Status"        
#> [17] "Collection Date"         "Location"

prepare_sra_metadata() needs three of these columns and uses three more when they are present:

Column Use
Sample the specimen ID: BioSample sample_name, and the start of each FASTQ file name (required)
Sample Type the specimen type, which sets the organism and isolation_source (required)
Collection Date BioSample collection_date (required)
Original Sample Type the parent specimen, used in place of Sample Type for derivatives such as DNA
External Participant ID the study subject ID, written as host_subject_id
Microbial Species the organism, for the microbe package only

Every other column, including the internal Participant ID, the custodian and the storage location, stays out of the submission.

table(report$`Sample Type`)
#> 
#>      Stool Stool Swab 
#>         27         23
range(as.Date(report$`Collection Date`))
#> [1] "2023-10-17" "2024-11-18"

Both specimen types map to the NCBI Taxonomy name “human gut metagenome” in the default metagenome_organism table. Every specimen has a collection date; one without would be submitted as "missing", one of the null values NCBI accepts.

3. Prepare the BioSample and SRA metadata

Give the attributes that are the same for every sample: the location of collection (mandatory for the metagenome package, in the INSDC country vocabulary and as latitude and longitude) and the sequencing details:

meta <- prepare_sra_metadata(
  report_xlsx,
  package           = "metagenome",
  output_dir        = "submission",
  geo_loc_name      = "USA: Pennsylvania, Philadelphia",
  lat_lon           = "39.95 N 75.19 W",
  library_strategy  = "WGS",
  library_selection = "RANDOM",
  platform          = "ILLUMINA",
  instrument_model  = "Illumina NovaSeq 6000"
)
#> Wrote 50 samples (100 FASTQ files) for package 'metagenome':
#>   submission/Metagenome.environmental.1.0_biosample_attributes.tsv
#>   submission/Metagenome.environmental.1.0_sra_metadata.tsv
#>   submission/Metagenome.environmental.1.0_submission.xlsx

Leave bioproject_accession blank when the BioProject is created in the same submission; if it already exists, give its accession (e.g. "PRJNA123456").

The output files

list.files("submission")
#> [1] "Metagenome.environmental.1.0_biosample_attributes.tsv"
#> [2] "Metagenome.environmental.1.0_sra_metadata.tsv"        
#> [3] "Metagenome.environmental.1.0_submission.xlsx"
File Contents Used in the Submission Portal at
Metagenome.environmental.1.0_biosample_attributes.tsv one row per specimen, in the column order of NCBI’s Metagenome or environmental (v1.0) BioSample package the BioSample attributes step
Metagenome.environmental.1.0_sra_metadata.tsv one row per specimen, with its library details and its R1 and R2 file names the SRA metadata step
Metagenome.environmental.1.0_submission.xlsx both tables, as sheets BioSample and SRA_data for review, or for combining several runs (see Next steps)

The same two tables are returned as data frames, so they can be checked in R before anything is uploaded.

BioSample attributes

names(meta$biosample)
#>  [1] "*sample_name"         "sample_title"         "bioproject_accession"
#>  [4] "*organism"            "host"                 "isolation_source"    
#>  [7] "*collection_date"     "*geo_loc_name"        "*lat_lon"            
#> [10] "ref_biomaterial"      "rel_to_oxygen"        "samp_collect_device" 
#> [13] "samp_mat_process"     "samp_size"            "source_material_id"  
#> [16] "description"          "host_subject_id"
knitr::kable(head(meta$biosample[, c("*sample_name", "sample_title",
                                     "*organism", "host", "isolation_source",
                                     "*collection_date", "samp_collect_device",
                                     "host_subject_id")], 5))
*sample_name sample_title *organism host isolation_source *collection_date samp_collect_device host_subject_id
S.240116.00375 mVACS_P_subject_0330 Stool Swab 2024-05-27 human gut metagenome Homo sapiens Stool Swab 2024-05-27 swab mVACS_P_subject_0330
S.240116.00160 mVACS_P_subject_0329 Stool Swab 2024-05-27 human gut metagenome Homo sapiens Stool Swab 2024-05-27 swab mVACS_P_subject_0329
S.240116.00151 mVACS_P_subject_0326 Stool Swab 2024-05-27 human gut metagenome Homo sapiens Stool Swab 2024-05-27 swab mVACS_P_subject_0326
S.240116.00156 mVACS_P_subject_0328 Stool Swab 2024-05-27 human gut metagenome Homo sapiens Stool Swab 2024-05-27 swab mVACS_P_subject_0328
S.240106.00109 mVACS_P_subject_0304 Stool 2024-05-27 human gut metagenome Homo sapiens Stool 2024-05-27 mVACS_P_subject_0304

Column names starting with * are mandatory in the package template; the portal reads them with or without the asterisk. Columns lims2sra has no value for (e.g. rel_to_oxygen, samp_size) are left empty, and host_subject_id is added after the template columns as a custom attribute (set include_subject_id = FALSE to leave it out).

NCBI rejects BioSamples whose attributes, other than sample_name, sample_title and description, are identical; prepare_sra_metadata() warns if any are. Here many specimens share a collection date, but each comes from a different subject, so host_subject_id tells every sample apart.

collection_date and host_subject_id are released publicly with the BioSamples. Check that the subject IDs cannot identify participants, and whether your protocol requires dates to be coarsened; NCBI also accepts a year and month (2024-01) or a year alone, which can be edited in the report or the table before uploading.

SRA metadata

names(meta$sra)
#>  [1] "sample_name"        "library_ID"         "title"             
#>  [4] "library_strategy"   "library_source"     "library_selection" 
#>  [7] "library_layout"     "platform"           "instrument_model"  
#> [10] "design_description" "filetype"           "filename"          
#> [13] "filename2"
knitr::kable(head(meta$sra[, c("sample_name", "library_ID",
                               "library_strategy", "library_source",
                               "library_layout", "filename", "filename2")], 5))
sample_name library_ID library_strategy library_source library_layout filename filename2
S.240116.00375 S.240116.00375 WGS METAGENOMIC paired S.240116.00375_R1.fastq.gz S.240116.00375_R2.fastq.gz
S.240116.00160 S.240116.00160 WGS METAGENOMIC paired S.240116.00160_R1.fastq.gz S.240116.00160_R2.fastq.gz
S.240116.00151 S.240116.00151 WGS METAGENOMIC paired S.240116.00151_R1.fastq.gz S.240116.00151_R2.fastq.gz
S.240116.00156 S.240116.00156 WGS METAGENOMIC paired S.240116.00156_R1.fastq.gz S.240116.00156_R2.fastq.gz
S.240106.00109 S.240106.00109 WGS METAGENOMIC paired S.240106.00109_R1.fastq.gz S.240106.00109_R2.fastq.gz

Without a FASTQ folder, the read files are assumed to be named <Sample>_R1.fastq.gz and <Sample>_R2.fastq.gz. Sequencing cores rarely name them that way, so in practice give the folder with the reads, as in the next step.

4. Match the samples to a folder of FASTQ files

A sequencing run often holds only some of a report’s samples: some failed library preparation, some will be sequenced later, and the run’s folder also holds files that belong to no sample. For this example, make a hypothetical run folder with empty files named the way Illumina’s demultiplexing names them (<Sample>_S<n>_R1_001.fastq.gz):

  • 40 of the 50 samples, each with an R1 and an R2 file;
  • one more sample with an R1 file but no R2 file (e.g. an interrupted transfer);
  • the run’s Undetermined reads, and a mock community positive control, neither of which is in the report.
dir.create("fastq", showWarnings = FALSE)
sequenced <- report$Sample[1:41]
stems <- c(paste0(sequenced, "_S", seq_along(sequenced)),
           "ZymoMock_S42", "Undetermined_S0")
fastq_files <- c(paste0(stems, "_R1_001.fastq.gz"),
                 paste0(setdiff(stems, stems[41]), "_R2_001.fastq.gz"))
invisible(file.create(file.path("fastq", fastq_files)))
head(sort(list.files("fastq")), 4)
#> [1] "S.231017.01646_S8_R1_001.fastq.gz" "S.231017.01646_S8_R2_001.fastq.gz"
#> [3] "S.231027.01510_S9_R1_001.fastq.gz" "S.231027.01510_S9_R2_001.fastq.gz"
length(list.files("fastq"))
#> [1] 85

Pass the folder as fastq_dir:

meta_run <- prepare_sra_metadata(
  report_xlsx,
  package          = "metagenome",
  output_dir       = "submission",
  geo_loc_name     = "USA: Pennsylvania, Philadelphia",
  lat_lon          = "39.95 N 75.19 W",
  fastq_dir        = "fastq",
  instrument_model = "Illumina NovaSeq 6000"
)
#> Sample name matches between input_xlsx and fastq_dir:
#>   input_xlsx samples found in fastq_dir: 41 of 50 (82.0%)
#>   fastq_dir samples found in input_xlsx: 41 of 43 (95.3%)
#> Warning: 10 sample(s) lack an R1 and/or R2 file in fastq and were dropped:
#> S.240723.00481, S.240722.00824, S.240709.00193, S.240729.00464, S.240729.00468,
#> S.240729.00472, S.240801.00918, S.240805.04200, S.240805.04205, S.240805.04209
#> Wrote 40 samples (80 FASTQ files) for package 'metagenome':
#>   submission/Metagenome.environmental.1.0_biosample_attributes.tsv
#>   submission/Metagenome.environmental.1.0_sra_metadata.tsv
#>   submission/Metagenome.environmental.1.0_submission.xlsx

Three things happen:

  • The match is summarized. 41 of the 50 report samples have files in the folder, and 41 of the 43 sample names in the folder (stems before _R1/_R2) are in the report: the other two are Undetermined_S0 and ZymoMock_S42, which are ignored.
  • Samples without both read files are dropped, with a warning naming them (the first 10): the 9 samples that are not in the run, and the one with an R1 file but no R2 file. They are left out of both tables.
  • The actual file names are used in filename and filename2:
nrow(meta_run$biosample)
#> [1] 40
knitr::kable(head(meta_run$sra[, c("sample_name", "filename", "filename2")], 3))
sample_name filename filename2
S.240116.00375 S.240116.00375_S1_R1_001.fastq.gz S.240116.00375_S1_R2_001.fastq.gz
S.240116.00160 S.240116.00160_S2_R1_001.fastq.gz S.240116.00160_S2_R2_001.fastq.gz
S.240116.00151 S.240116.00151_S3_R1_001.fastq.gz S.240116.00151_S3_R2_001.fastq.gz

So the outputs describe only the 40 samples that can be submitted now, and list exactly the 80 files to upload for them. The 10 samples not yet sequenced, and the one with a missing file, can go in a later submission. Because the files in submission/ are overwritten on each call, give each run its own output_dir when preparing more than one.

When no names match

File names must contain the Sample ID exactly, character for character. If the sequencing core changed the IDs, for example to underscores, nothing matches:

renamed <- "fastq_renamed"
dir.create(renamed, showWarnings = FALSE)
# S.240116.00375_S1_R1_001.fastq.gz -> S_240116_00375_S1_R1_001.fastq.gz
renamed_files <- sub("^S[.]([0-9]+)[.]([0-9]+)", "S_\\1_\\2", fastq_files)
invisible(file.create(file.path(renamed, renamed_files)))
head(sort(renamed_files), 2)
#> [1] "S_231017_01646_S8_R1_001.fastq.gz" "S_231017_01646_S8_R2_001.fastq.gz"

prepare_sra_metadata(report_xlsx, package = "metagenome", output_dir = NULL,
                     fastq_dir = renamed)
#> Sample name matches between input_xlsx and fastq_dir:
#>   input_xlsx samples found in fastq_dir: 0 of 50 (0.0%)
#>   fastq_dir samples found in input_xlsx: 0 of 43 (0.0%)
#> Warning: 50 sample(s) lack an R1 and/or R2 file in fastq_renamed and were
#> dropped: S.240116.00375, S.240116.00160, S.240116.00151, S.240116.00156,
#> S.240106.00109, S.240106.00113, S.240106.00116, S.231017.01646, S.231027.01510,
#> S.231101.00043, ...
#> Error:
#> ! No samples remain after matching to FASTQ files in 'fastq_renamed'. Check that Sample IDs match file names (e.g. '-' vs '_').

The summary shows 0 matches, every sample is dropped, and prepare_sra_metadata() stops. Make the report’s Sample IDs match the file names, rather than renaming the read files, and run it again:

fixed_xlsx <- "data/IDSampleReport_underscore.xlsx"
report_fixed <- report
report_fixed$Sample <- gsub(".", "_", report_fixed$Sample, fixed = TRUE)
writexl::write_xlsx(report_fixed, fixed_xlsx)

fixed <- prepare_sra_metadata(fixed_xlsx, package = "metagenome",
                              output_dir = NULL, fastq_dir = renamed,
                              geo_loc_name = "USA: Pennsylvania, Philadelphia",
                              lat_lon = "39.95 N 75.19 W")
#> Sample name matches between input_xlsx and fastq_dir:
#>   input_xlsx samples found in fastq_dir: 41 of 50 (82.0%)
#>   fastq_dir samples found in input_xlsx: 41 of 43 (95.3%)
#> Warning: 10 sample(s) lack an R1 and/or R2 file in fastq_renamed and were
#> dropped: S_240723_00481, S_240722_00824, S_240709_00193, S_240729_00464,
#> S_240729_00468, S_240729_00472, S_240801_00918, S_240805_04200, S_240805_04205,
#> S_240805_04209
nrow(fixed$sra)
#> [1] 40

The changed IDs become the BioSample names, so keep a record of the mapping back to the LIMS IDs.

5. Submit to NCBI

With the BioSample attributes table, the SRA metadata table and the FASTQ files ready, start a new submission at https://submit.ncbi.nlm.nih.gov/subs/sra/ and work through the wizard:

  1. Submitter and General info. Say whether the BioProject and BioSamples already exist (here, they do not) and set the release date.
  2. Project info. Describe the BioProject, if it is new.
  3. BioSample type. Choose Metagenome or environmental, the package that package = "metagenome" targets.
  4. BioSample attributes. Upload Metagenome.environmental.1.0_biosample_attributes.tsv. The portal checks mandatory fields, controlled vocabularies (e.g. geo_loc_name) and duplicate attributes, and lists any errors to fix.
  5. SRA metadata. Upload Metagenome.environmental.1.0_sra_metadata.tsv. Each row is linked to its BioSample by sample_name.
  6. Files. Upload the FASTQ files listed in filename and filename2. For more than a few files, use the FTP or Aspera preload option: the portal gives you an upload folder in your account, where you make a folder for this submission and put the files, with no subfolders, then select it in this step. Upload exactly the files in the SRA metadata table: here the 80 files of the 40 complete samples, not the R1 file of the incomplete sample, the Undetermined reads or the mock community. The portal checks that each listed file is present.
  7. Review and submit.

After processing, NCBI assigns accessions: a BioProject (PRJNA), a BioSample (SAMN) for each specimen and an SRA run (SRR) for each library, which can be cited in publications and data availability statements.

Next steps

  • Several sequencing runs. Run prepare_sra_metadata() once per run folder, each with its own output_dir, then combine the tables (e.g. with rbind()) into one submission, or submit each run separately.
  • Other specimen types. Specimen types missing from metagenome_organism are submitted with organism "missing", with a warning; add them to the mapping (see ?prepare_sra_metadata for the defaults).
  • Isolates. Bacterial cultures and isolates belong in the Microbe package: use package = "microbe".