Skip to contents

Reads the CSV written by sourmash compare --csv into the same long format as smash_compare(), one row per ordered pair of samples, with the similarity in a column named by metric. Use it to plot comparisons made with sourmash (for example in the smash_env conda environment of sra2lab; see vignette("smash-compare")) with smash_compare_plot().

Usage

smash_read_compare(
  file,
  metric = "jaccard",
  distance = FALSE,
  data = NULL,
  sample = "sample_id",
  keep = NULL
)

Arguments

file

Path of the CSV written by sourmash compare --csv.

metric

What the matrix holds, to name the value column: "jaccard" (sourmash compare --ignore-abundance), "angular_similarity" (the default output for sketches with abundances), "containment" (--containment), "max_containment", "avg_containment", or with --ani, "jaccard_ani", "containment_ani", "max_containment_ani" or "avg_containment_ani". Distance matrices (--distance-matrix) are converted back to similarities with distance = TRUE.

distance

If TRUE, the file is a distance matrix (--distance-matrix), and its values are converted to similarities (1 - distance).

data

Optional data frame from smash_aggregate(), to match signature names to samples and join keep columns.

sample

Column identifying the sample. Defaults to "sample_id".

keep

Columns of data describing the samples to carry into the result, each twice, with suffixes _1 and _2 (e.g. host_subject_id_1, host_subject_id_2). Defaults to sample_type, species, sample_source, and host_subject_id and collection_date where present.

Value

A tibble with one row per ordered pair of samples: sample_1, sample_2, the metric column, and the keep columns when data is given.

Details

sourmash compare --csv writes a square matrix whose header holds the signature names (for sra2lab sketches, the run accession or specimen ID). With data (from smash_aggregate()), names are matched to its name column to give each sample its sample_id, and the keep columns are joined. For --containment matrices, the value in row a and column b is the containment of b in a; it is read as the containment of sample_1 = b in sample_2 = a, as in smash_compare().

See also

smash_compare(), which computes the same in R.

Examples

if (FALSE) { # \dontrun{
# in a shell, or with system2() from R (see vignette("smash-compare")):
# sourmash compare -k 31 --ignore-abundance --csv data/compare_k31.csv \
#   data/smash/*_k31_scale1000_seed42_abund.sig
sketches <- smash_aggregate("data/smash", metadata = "data/runs.csv",
                            k = 31)
cmp <- smash_read_compare("data/compare_k31.csv", metric = "jaccard",
                          data = sketches)
smash_compare_plot(cmp, "jaccard", type = "distribution",
                   subject = "host_subject_id")
} # }