Skip to contents

Arranges one similarity from smash_compare() or smash_read_compare() as a square matrix, laid out as sourmash compare lays it out, with 1 on the diagonal. For the directional containment and containment_ani, the value in row a and column b is the containment of b in a (the fraction of b's hashes found in a), as in sourmash compare --containment.

Usage

smash_compare_matrix(compare, metric = "jaccard", samples = NULL)

Arguments

compare

A tibble from smash_compare() or smash_read_compare().

metric

The similarity to arrange, e.g. "jaccard", "containment", "angular_similarity" or "max_containment_ani".

samples

Optional order of the samples. Defaults to their order in compare.

Value

A numeric matrix with the samples as row and column names.

See also

Examples

sketches <- smash_aggregate(smash_example("signatures"), k = 31,
                            min_abundance = 2)
cmp <- smash_compare(sketches)
m <- smash_compare_matrix(cmp, "jaccard")
round(m[1:4, 1:4], 3)
#>             SRR41520862 SRR41520863 SRR41520865 SRR41520867
#> SRR41520862       1.000       0.058       0.076       0.055
#> SRR41520863       0.058       1.000       0.202       0.073
#> SRR41520865       0.076       0.202       1.000       0.100
#> SRR41520867       0.055       0.073       0.100       1.000

# hierarchical clustering on Jaccard distance
plot(hclust(as.dist(1 - m), method = "average"))