Plot a heatmap of hashes across subjects, sources and time
Source:R/smash_heatmap.R
smash_heatmap.RdDraws a hashes x samples heatmap with ggplot2::geom_tile(): one row per
hash (a hashed k-mer kept in the sketches), one column per sample, with
the columns split into panels by subject, ordered by time within each
subject, and labelled by date and source. A hash seen in several of a
subject's samples, or in several subjects, shows k-mers (and so, at
k = 31 or 51, genomes) that persist or are shared.
Usage
smash_heatmap(
data,
sample = "sample_id",
subject = NULL,
time = NULL,
site = NULL,
sample_label = NULL,
hashes = NULL,
reference = NULL,
top_n = 50,
select = c("shared", "prevalent", "abundant"),
value = c("presence", "abundance", "log10"),
min_abundance = 1,
cluster = c("hashes", "none", "samples", "both"),
show_hash_labels = NULL,
palette = "viridis"
)Arguments
- data
A data frame from
smash_aggregate(), with one sketch per sample.- sample
Column identifying the sample. Defaults to
"sample_id".- subject
Optional column identifying the subject; samples are split into side-by-side panels by subject.
- time
Optional column giving each sample's time (a
Date, date text, or number), to order the samples within each subject and label them.- site
Optional column with the sample's source or site (e.g.
"sample_source"), added to the sample labels.- sample_label
Optional column to label the samples with, instead of their
timeandsite(or, without these, theirsample). It must have one value per sample.- hashes
Optional hashes to show: a character vector, or a data frame with columns
hashand (optionally)group. See Details.- reference
Optional sample(s) whose hashes are shown. See Details.
- top_n
Number of hashes to show.
Infshows all (which can be slow to draw).- select
How to rank hashes when neither
hashesnorreferenceis given:"shared","prevalent"or"abundant". See Details.- value
"presence","abundance"or"log10".- min_abundance
Drop hashes seen fewer than this many times, in sketches with abundances, before choosing and plotting. Defaults to 1.
- cluster
Order hashes and/or samples by hierarchical clustering (
stats::hclust(), on Jaccard distances of presence forvalue = "presence", otherwise on Euclidean distances of the plotted values):"hashes"(the default),"none","samples"or"both". Samples are clustered within each subject; unclustered samples are ordered bytime.- show_hash_labels
Show the hashes as row labels? Defaults to
TRUEwhen 60 or fewer hashes are shown.- palette
A viridis palette option for the fill scale.
Value
A ggplot object. The plotted values are in its data element,
with columns sample, hash, abundance, value and the sample
columns.
Details
A sketch holds thousands to millions of hashes, so only top_n are
shown, chosen in one of three ways:
hasheshashes you choose: a vector of hashes, or a data frame with a
hashcolumn and optionally agroupcolumn (e.g. the strain or species each hash was assigned to), which splits the rows into panels. For example, the hashes private to one subject fromsmash_hashes(), or those of an isolate's genome.referencethe hashes of one or more reference samples, e.g. an isolate, to see which other samples (e.g. metagenomes) hold them.
- otherwise
hashes ranked by
select:"shared"(the default) ranks hashes found in at least two samples but not in all by the number of samples they are in,"prevalent"ranks all hashes by the number of samples they are in, and"abundant"by their mean abundance across samples (sketches with abundances only).
Ties are broken by mean abundance, then by hash. With reference, hashes
are ranked by the number of other samples they are in.
value sets what the tiles show: "presence" (the default; hashes absent
from a sample are grey), "abundance" (the k-mer count of the hash in the
sample's sketch) or "log10" (its log10).
See also
smash_aggregate() to make data, smash_hashes() to choose
hashes, and smash_compare_plot() to compare whole sketches.
Examples
sketches <- smash_aggregate(smash_example("signatures"),
metadata = smash_example("runs"), k = 51)
smash_heatmap(sketches, subject = "host_subject_id",
time = "collection_date", site = "sample_source")
# k-mer abundances of the most prevalent hashes
smash_heatmap(sketches, subject = "host_subject_id",
time = "collection_date", site = "sample_source",
select = "prevalent", value = "log10")
# where are the hashes of one stool sample found?
smash_heatmap(sketches, subject = "host_subject_id",
time = "collection_date", site = "sample_source",
reference = "SRR41520874", top_n = 40)