sylph_heatmap() draws a samples x taxa heatmap with
ggplot2::geom_tile(): one column per sample, one row per
taxon, and the tile colour showing abundance. It sums the genomes of
each taxon at the rank you choose, keeps the most abundant taxa, and can
log- or CLR-transform the values, cluster the rows and columns, and
split the samples into panels.
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.syl2dbsylph2lab 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 GTDB taxonomy matters most here: the heatmap’s rows are taxon
names, and without it some genomes appear under NCBI contig-name labels
such as Clostridiales bacterium rather than a GTDB genus
and species.
A first heatmap
Combine the profiles with the run table and the GTDB taxonomy, as in
vignette("sylph-aggregate"):
library(sylph2lab)
profiles <- sylph_aggregate(sylph_example("profiles"),
metadata = sylph_example("runs"),
taxonomy = sylph_example("taxonomy"))By default, sylph_heatmap() shows the taxonomic
abundance (%) of the 30 species with the highest mean abundance. Here
the samples are split into panels by swab type with
group:
sylph_heatmap(profiles, group = "isolation_source")
Grey tiles are species not detected in that sample. On this linear scale a few dominant genomes (Staphylococcus epidermidis on skin, at 75–97%) hide everything else, which is typical of microbiome data.
Transformations
transform = "log10" spreads out the low abundances, so
you can see which low-abundance taxa each sample shares:
sylph_heatmap(profiles, group = "isolation_source", transform = "log10")
transform = "clr" shows the centred log-ratio: each
taxon’s log abundance relative to the mean log abundance of all taxa in
that sample. CLR values compare taxa within a sample on a common,
symmetric scale, and are the usual input for compositional analyses:
sylph_heatmap(profiles, group = "isolation_source", transform = "clr")
The CLR is computed per sample over all taxa at the chosen
rank, not only the ones shown. Because the log of zero is undefined,
taxa not detected in a sample are first given a small
pseudocount (by default half the smallest non-zero
abundance in the data), so every tile is coloured. Change it with
pseudocount =, and report it, since CLR values depend on
it.
Rank and number of taxa
rank is any column of the profiles:
"species" (the default), "genus",
"organism" or "accession" (one row per
genome), and with GTDB taxonomy, also "family",
"order", "class", "phylum" or
"domain". top_n sets how many taxa are kept
(Inf for all):
sylph_heatmap(profiles, rank = "genus", top_n = 15, transform = "log10",
group = "isolation_source")
Clustering and labels
cluster orders the taxa ("taxa"), samples
("samples") or both by hierarchical clustering, so that
taxa found together and similar samples sit next to each other. With
group, samples are clustered within each panel.
sample_label names another column to label the samples
with:
profiles$label <- paste(profiles$host_subject_id, profiles$isolation_source)
sylph_heatmap(profiles, transform = "clr", cluster = "both",
sample_label = "label")
Without panels, clustering puts the four skin swabs (dominated by Staphylococcus epidermidis) side by side. Among the gut swabs, repeat samples from the same subject tend to sit together: four of GOL_017’s stool and perirectal swabs form one block, and GOL_019’s two stool swabs, three weeks apart, are neighbours.
Higher ranks
The GTDB taxonomy makes the higher ranks available, from
"family" up to "domain". At the family level,
the skin and gut swabs separate clearly:
sylph_heatmap(profiles, rank = "family", top_n = 20, transform = "log10",
group = "isolation_source")
Without taxonomy (sylph_aggregate() with no
taxonomy), only genus, species,
organism and accession are available, with
names from the contig names.
Customising and saving
The result is a ggplot, so scales, themes and labels can be changed
with +. The plotted values are in its data
element (columns sample, taxon,
abundance and value), which is useful for
checking a tile:
p <- sylph_heatmap(profiles, rank = "genus", top_n = 5)
head(p$data)
#> # A tibble: 6 × 4
#> sample taxon abundance value
#> <fct> <fct> <dbl> <dbl>
#> 1 SRR41520862 Staphylococcus 0 NA
#> 2 SRR41520863 Staphylococcus 0 NA
#> 3 SRR41520865 Staphylococcus 0 NA
#> 4 SRR41520867 Staphylococcus 0 NA
#> 5 SRR41520868 Staphylococcus 0 NA
#> 6 SRR41520869 Staphylococcus 0 NA
library(ggplot2)
p <- sylph_heatmap(profiles, group = "isolation_source", transform = "log10",
palette = "magma") +
theme(legend.position = "bottom")
ggsave("figs/species_heatmap.pdf", p, width = 9, height = 8)For heatmaps with many samples, drop the sample labels with
theme(axis.text.x = element_blank()).
Taxon labels longer than 40 characters are wrapped onto two lines, to
leave more of the width for the tiles. They break at spaces, such as
Faecaligallichristensenella faecipullorum (in the example data,
but not among the 30 most abundant species), or after semicolons, so
that full GTDB lineages (rank = "gtdb_taxonomy") break
between ranks. If wrapped labels crowd each other, make the plot taller,
or keep every label on one line with
feature_label_wrap = FALSE.