Skip to contents

Before looking at what is in the samples, it helps to see how the cohort was sampled: how many subjects, how many samples each gave, from which sites, and how far apart. sylph_timeline() draws one row per subject and one point per sample, at the day it was collected.

Files you need

sylph2lab works on files you already have, made by sylph (usually through sra2lab) and downloaded from NCBI and GTDB. A typical analysis directory looks like this:

~/projects/
├── gtdb-r232-c200-dbv2.syl2db          <- sylph database (shared, ~19 GB)
├── gtdb/
│   ├── bac120_taxonomy_r232.tsv.gz     <- GTDB taxonomy (shared, optional)
│   └── ar53_taxonomy_r232.tsv.gz
└── PRJNA1556220/                       <- analysis directory (working directory)
    └── data/
        ├── PRJNA1556220_runs.csv       <- run metadata
        └── sylph/                      <- one *_profiling.tsv per run

The sylph database. The profiles are made by sylph against a reference database. Pre-built databases are listed on the sylph documentation’s pre-built databases page. The example data in this vignette were profiled against the GTDB r232 two-stage database, gtdb-r232-c200-dbv2.syl2db (about 19 GB, needs sylph 1.0.0 or later), which sra2lab::sylph_runs() uses by default:

cd ~/projects
wget http://faust.compbio.cs.cmu.edu/sylph-stuff/gtdb-r232-c200-dbv2.syl2db
# mirror: https://storage.googleapis.com/sylph-stuff/gtdb-r232-c200-dbv2.syl2db

sylph2lab itself never reads the database, but it needs to know which GTDB release it came from, to download the matching taxonomy.

GTDB taxonomy (optional). sylph reports each genome by its file name (which holds the NCBI assembly accession) and the name of its first contig. For GTDB names at every rank, download the taxonomy tables of the same GTDB release as the database from the GTDB downloads page. For release 232, they are in https://data.gtdb.ecogenomic.org/releases/release232/232.0/:

File Size Contents
bac120_taxonomy_r232.tsv.gz 9.4 MB bacterial genomes
ar53_taxonomy_r232.tsv.gz 0.3 MB archaeal genomes
gtdb_url <- "https://data.gtdb.ecogenomic.org/releases/release232/232.0"
dir.create("~/projects/gtdb", showWarnings = FALSE)
for (f in c("bac120_taxonomy_r232.tsv.gz", "ar53_taxonomy_r232.tsv.gz")) {
  download.file(file.path(gtdb_url, f), file.path("~/projects/gtdb", f),
                mode = "wb")
}

The much larger GTDB metadata tables in the same directory (bac120_metadata_r232.tsv.gz, 276 MB, and ar53_metadata_r232.tsv.gz, 6.7 MB) hold genome size, completeness, NCBI names and more for each accession. sylph2lab does not need them, but they can be joined to the sylph_aggregate() output by accession in the same way (remove the RS_ or GB_ prefix from their accessions first). For an older database, use the same release’s files, e.g. release220/220.0/bac120_taxonomy_r220.tsv.gz for gtdb-r220-c200-dbv1.syldb.

Run metadata. sra2lab::get_bioproject_runs() returns one row per SRA run, with the BioSample attributes the submitters gave (subject, collection date, body site, …). Save it next to the profiles:

runs <- sra2lab::get_bioproject_runs("PRJNA1556220")
write.csv(runs, "data/PRJNA1556220_runs.csv", row.names = FALSE)

For local reads profiled with sra2lab::sylph_local(), use your own specimen table instead, with one row per specimen ID.

The sylph profiles come from sra2lab::sylph_runs(), sylph_stream(), sylph_local() or multiprocess_runs(), one <id>_profiling.tsv per sample; see vignette("sylph-workflow", package = "sra2lab").

The example data

sylph2lab ships the profiles of 18 runs from BioProject PRJNA1556220, “Microbiome changes in the peri-heart transplant setting”, profiled against gtdb-r232-c200-dbv2.syl2db: the 8 runs of the sra2lab sylph vignette, plus repeat stool and perirectal swabs from the same subjects, so that five subjects have two to six samples each. It also ships the run table for all 67 runs of the BioProject, and the rows of the two GTDB r232 taxonomy files for the 560 genomes detected in the example profiles (559 bacterial, 1 archaeal). sylph_example() gives their paths, which stand in for data/sylph, data/PRJNA1556220_runs.csv and the full taxonomy files below. The taxonomy subsets only cover the example genomes; for your own data, download the full files.

The timeline needs only sample metadata: the subject, the collection date and (optionally) the site of each sample. The sylph database and GTDB taxonomy are not used here, but they are needed for the profiles you will plot next.

The profiled samples

Combine the profiles with the run table, as in vignette("sylph-aggregate"):

library(sylph2lab)

profiles <- sylph_aggregate(sylph_example("profiles"),
                            metadata = sylph_example("runs"))

and plot their timeline. The defaults match sra2lab run tables: subjects in host_subject_id, dates in collection_date, and samples in sample_id:

sylph_timeline(profiles, site = "isolation_source")

Sampling timeline of the 18 profiled samples from 7 subjects: one row per subject, with a point for each sample at its collection day, coloured by swab type.

profiles has one row per sample and genome; sylph_timeline() reduces it to one row per sample first. Each subject’s row is labelled with its number of samples, subjects are ordered by their first sample, and by default the x axis is days since that subject’s first sample (see The x axis for the alternatives). Five of the seven subjects have repeat samples: GOL_017, for example, gave a groin and a perirectal swab on day 0, and stool and perirectal swabs on days 3 and 10, while GOL_019’s two stool swabs were more than three weeks apart.

The whole cohort

sylph_timeline() takes any data frame with sample, subject and date columns, so it can also show every run in the BioProject, profiled or not, straight from the run table. Name the sample column:

runs <- read.csv(sylph_example("runs"))   # "data/PRJNA1556220_runs.csv"

sylph_timeline(runs, sample = "run_accession", site = "isolation_source")

Sampling timeline of all 67 runs in the BioProject, from 18 subjects, coloured by swab type.

Samples taken from the same subject on the same day (here, often several swab types at one visit) are spread out vertically so that none is hidden. Most subjects were sampled at one to four visits over about three weeks.

The x axis

x_axis sets where day 0 is, and so what the timeline emphasises:

x_axis Day 0 Shows
"subject-day" (default) each subject’s first sample the spacing of each subject’s samples, aligned at the start
"study-day" the first sample in the data, across all subjects when each subject entered, and their follow-up, on one study clock
"calendar-day" (calendar dates) when samples were taken, e.g. to line up with seasons or events

The default suits comparing sampling schedules, as above. With "study-day", each subject’s row starts on the day they entered the study, counted from the cohort’s first sample:

sylph_timeline(profiles, site = "isolation_source", x_axis = "study-day")

Sampling timeline of the 18 profiled samples on a shared study-day axis: subjects enter at different times over about a year.

GOL_003 was sampled in September 2025, and the other subjects between March and August 2026, so on the shared clock each subject’s few weeks of samples are short runs spread across the year. "calendar-day" shows the same layout with dates instead of day numbers. Here, without site, each subject gets its own colour and there is no legend, as in a donor timeline:

sylph_timeline(runs, sample = "run_accession", x_axis = "calendar-day")

Sampling timeline of all runs on a calendar date axis, one colour per subject.

The options can be abbreviated (x_axis = "study"). Day 0 is the first sample in the data, for each subject or for the study, so a study contact without a sample (such as enrollment) does not move it.

Colours

color_var sets what the colours show. By default (color_var = "site") they show the site column, as above, or each subject when there is no site. To compare groups of subjects instead, colour by a subject feature: anything with one value per subject, such as treatment arm, outcome or age. Give it as a column of data:

sylph_timeline(profiles, color_var = "treatment_arm")

or as a vector with one value per row of data, which is handy for a grouping you make on the fly. The example run table has no subject-level columns besides the subject ID, so here we mark the subjects sampled more than once, and name the legend with color_label:

n_samples <- tapply(profiles$sample_id, profiles$host_subject_id,
                    function(x) length(unique(x)))
repeat_sampled <- names(n_samples)[n_samples > 1]

sylph_timeline(
  profiles,
  color_var = ifelse(profiles$host_subject_id %in% repeat_sampled,
                     "Repeat samples", "Single sample"),
  color_label = "Follow-up"
)

Sampling timeline of the 18 profiled samples, coloured by whether the subject was sampled more than once.

A subject feature must have the same value in all of a subject’s rows; otherwise sylph_timeline() stops and names the subjects where it varies. Numeric features, such as age, get a continuous colour scale. The site is not shown when colouring by a subject feature; to see both, put one of them in panels (next section).

Panels

facet_var splits the timeline into panels, stacked in one column with one panel per value. It takes the same options as color_var: "site", a subject-level column, or a vector with one value per row. Each panel shows only its own subjects, and taller panels hold more subjects.

With facet_var = "site", each site gets a panel, and a subject sampled at several sites has a row in each. Here the colours show the subject feature from above, so both are visible:

follow_up <- ifelse(profiles$host_subject_id %in% repeat_sampled,
                    "Repeat samples", "Single sample")

sylph_timeline(profiles, site = "isolation_source", facet_var = "site",
               color_var = follow_up, color_label = "Follow-up")

Sampling timeline in four panels, one per swab type, coloured by whether the subject was sampled more than once.

Faceting by a subject feature instead puts each subject in one panel, for example to set treatment arms or outcome groups apart (facet_var = "treatment_arm"). Panels follow the factor levels if the variable is a factor, and are sorted otherwise; subjects with a missing value go in a last panel, “(missing)”. Colour can still show the site:

sylph_timeline(profiles, site = "isolation_source", facet_var = follow_up)

Sampling timeline in two panels, subjects with repeat samples and subjects with a single sample, coloured by swab type.

Other options

sample_noun changes the word in the labels, e.g. sample_noun = "donations", and show_counts = FALSE drops the counts. palette takes any viridis option ("turbo", the default, "viridis", "magma", …).

Dates

Dates can be Dates, or text in YYYY-MM-DD, YYYY/MM/DD or MM/DD/YYYY form. SRA allows collection dates such as "missing", "2025" or "2025-09"; samples with such dates cannot be placed on a day, so they are left out with a warning. Excel serial dates (numbers) must be converted first, for example with janitor::excel_numeric_to_date().

Customising and saving

The result is a ggplot, so it can be changed with + and saved with ggsave():

library(ggplot2)

p <- sylph_timeline(runs, sample = "run_accession", site = "isolation_source") +
  labs(x = "Study day", fill = "Swab")
ggsave("figs/sampling_timeline.pdf", p, width = 8, height = 6)