Skip to contents

Aggregate, compare and visualize sourmash sketches in R, of cultured isolates and of metagenomes. smash2lab picks up where the sourmash functions of sra2lab (smash_runs(), smash_stream(), smash_local()) leave off.

Documentation, with a worked vignette for each function: https://bjklab.github.io/smash2lab/.

Installation

# install.packages("remotes")
remotes::install_github("bjklab/smash2lab")

smash2lab reads signatures and compares them in R: sourmash is needed only to make the sketches (with sra2lab), not to use this package.

Functions

Function What it does
smash_aggregate() Reads sourmash signatures (.sig, .sig.gz, .zip) into one tibble, one row per sketch, keeping every hash (exactly, as text) and its abundance, with the sketch parameters (k, scaled, seed, abund/noabund). Joins sample metadata and records what was sketched: isolate or metagenome, the isolate’s species, and the sample’s source. Optionally drops low-abundance (error) k-mers and downsamples. smash_hashes() unnests the hashes, one row per sketch and hash.
smash_timeline() Cohort sampling timeline: one row per subject, one point per sample, isolates and metagenomes as different shapes, coloured or split into panels by source, isolate species or a subject feature.
smash_heatmap() Hashes x samples geom_tile() heatmap, with samples in panels by subject, ordered by time and labelled by source; shared, prevalent or abundant hashes, the hashes of a reference sample, or hashes you choose, in groups.
smash_compare() Every pairwise similarity of sourmash compare (Jaccard, containment, max/avg containment, angular similarity, and their ANI estimates), computed in R. smash_read_compare() reads sourmash compare --csv output instead, and smash_compare_matrix() gives a matrix.
smash_compare_plot() Plots comparisons as a matrix in blocks by subject, as distributions (same versus different subjects, per species or source), as a PCoA ordination, or as a network of pairs above a threshold (e.g. strain-level ANI).

All plots are ordinary ggplot2 objects, so they can be extended with + and saved with ggsave().

Example

The package ships sourmash signatures (k = 31 and k = 51) of 18 runs of BioProject PRJNA1556220 and the BioProject’s run table, and signatures of 30 bacterial isolates (six species, five subjects and their environmental swabs) from BioProject PRJNA1570337, with its run table.

library(smash2lab)

sketches <- smash_aggregate(
  smash_example("signatures"),       # e.g. "data/smash"
  metadata = smash_example("runs"),  # e.g. "data/PRJNA1556220_runs.csv"
  k = 31
)

smash_timeline(sketches, site = "sample_source")

smash_heatmap(sketches, subject = "host_subject_id",
              time = "collection_date", site = "sample_source")

cmp <- smash_compare(sketches)
smash_compare_plot(cmp, "angular_similarity", type = "distribution",
                   subject = "host_subject_id", group = "sample_source")
smash_compare_plot(cmp, "angular_similarity", type = "ordination",
                   subject = "host_subject_id")

# isolates: which are the same strain?
isolates <- smash_aggregate(smash_example("isolates"),
                            metadata = smash_example("isolate_runs"), k = 51)
smash_timeline(isolates, color_var = "species")
iso_cmp <- smash_compare(isolates)
smash_compare_plot(iso_cmp, "max_containment_ani", type = "network",
                   subject = "host_subject_id", shape = "species",
                   threshold = 0.999, layout = "circle")

Vignettes

Install with remotes::install_github("bjklab/smash2lab", build_vignettes = TRUE) to have them available locally.