Immune repertoire similarity¶
Description¶
A family of functions to compare shared receptors between repertoires. These methods help you measure repertoire similarity, identify public receptors, compare biological groups, and check whether replicate samples have similar receptor composition.
Available functions
The following methods are available.
1) Shared-receptor counts
(repsim_intersection). Count the unique receptors
shared by each pair of repertoires. Use this method to find related
samples, check replicate similarity, or identify receptors shared across
many repertoires.
2) Jaccard similarity (repsim_jaccard).
Compare the sets of unique receptors in each pair of repertoires. The
score accounts for the total number of unique receptors in both
repertoires. Use it to compare receptor overlap when repertoire sizes
differ.
$J(A, B) = \frac{|A \cap B|}{|A \cup B|}$
3) Chao-Jaccard similarity
(repsim_chao_jaccard). Compare receptor overlap
using receptor counts. The method estimates similarity after allowing
for shared receptors that may be missing because one or both repertoires
were sampled at limited depth. Use it when sampling depth may affect the
observed overlap.
4) Morisita-Horn similarity
(repsim_morisita_horn). Compare receptor abundance
profiles. Abundant receptors have more influence on the score than rare
receptors. Use it to determine whether the same expanded receptors
dominate two repertoires. The method uses imd_proportion as
the abundance measure.
C\_{MH} = {(\_i + \_j) N_i N_j}
5) Bray-Curtis similarity (repsim_bray).
Measure how similar two receptor abundance profiles are. This is one
minus Bray-Curtis dissimilarity: 0 means no overlap, and
1 means identical abundance composition. The method uses
imd_proportion as the abundance measure.
Set transform = "log1p" to reduce the influence of the most
abundant receptors and give lower-abundance receptors more influence on
the result. This can reveal broader repertoire similarity when a few
expanded receptors would otherwise dominate the comparison. The
transformation is applied inside the database query and does not modify
idata.
Immune-repertoire studies commonly calculate Bray-Curtis measures from
clonotype proportions without an additional transformation. Therefore,
transform = "none" remains the default. The
"log1p" option is an exploratory sensitivity analysis based
on a common ecological pre-treatment for reducing the effect of dominant
taxa. After transformation, the values no longer sum to one, and the
result no longer has the simple interpretation of the fraction of
original repertoire abundance that overlaps.
## Usage
repsim_intersection(idata)
repsim_jaccard(idata)
repsim_chao_jaccard(idata)
repsim_morisita_horn(idata)
repsim_bray(idata, transform = c("none", "log1p"))
## Arguments
idata |
An immundata::ImmunData object. |
transform |
A single character string selecting the transformation applied to
imd_proportion before calculating similarity. Use
"none" (the default) for the original proportions or
"log1p" for log(1 + imd_proportion).
|
1) Shared-receptor counts (repsim_intersection)
A symmetric numeric matrix where rows/columns are
repertoire labels derived from schema_repertoire. Each cell
is the count of shared unique receptors. The diagonal contains
per-repertoire richness (total unique receptors).
2) Jaccard similarity (repsim_jaccard)
A symmetric numeric matrix where rows/columns are
repertoire labels derived from schema_repertoire. Each cell
is the Jaccard similarity in \[0,
1\]. The diagonal is 1.
3) Chao-Jaccard similarity (repsim_chao_jaccard)
A symmetric numeric matrix where rows/columns are
repertoire labels derived from schema_repertoire. Each cell
is the Chao-Jaccard similarity in \[0,
1\] (1 = maximum estimated overlap, 0 =
no observed shared receptors). The diagonal is 1.
4) Morisita-Horn similarity (repsim_morisita_horn)
A symmetric numeric matrix whose rows/columns are
repertoire labels derived from schema_repertoire, with
values in \[0, 1\]
(0 = no shared abundance, 1 = identical
abundance composition). The diagonal is 1. Comparisons
involving an empty repertoire are NA.
5) Bray-Curtis similarity (repsim_bray)
A symmetric numeric matrix where rows/columns are
repertoire labels derived from schema_repertoire. Each cell
is Bray-Curtis similarity in \[0,
1\] (0 = no overlap, 1 = identical).
The diagonal is 1.
## Visualisation
All five repsim\_\*() results can
be passed directly to vis(). vis() displays
the result as a dot plot, with repertoire labels on both axes. Each dot
represents one pair of repertoires; its size and fill show the value for
that pair.
1) Shared-receptor counts (repsim_intersection)
Larger and brighter dots mean that the repertoires share more unique
receptors. The matrix diagonal contains repertoire richness; the plot
omits self-comparisons.
2) Jaccard similarity (repsim_jaccard)
Larger and brighter dots mean greater similarity between the sets of
unique receptors. Values range from 0 (no shared receptors)
to 1 (identical receptor sets).
3) Chao-Jaccard similarity (repsim_chao_jaccard)
Larger and brighter dots mean greater estimated similarity after
correction for receptors that may be missing because of limited
sampling. Values range from 0 (no observed shared
receptors) to 1 (maximum estimated similarity).
4) Morisita-Horn similarity (repsim_morisita_horn)
Larger and brighter dots mean greater similarity between receptor
abundance profiles. Values range from 0 (no overlap) to
1 (identical abundance composition).
5) Bray-Curtis similarity (repsim_bray)
Larger and brighter dots mean greater similarity between receptor
abundance profiles. Values range from 0 (no overlap) to
1 (identical abundance composition).
All plots omit self-comparisons. Their color legends mark the smallest,
midpoint, and largest plotted pairwise values.
All repertoire-similarity plots accept:
-
size_max_mmto set the maximum dot diameter. -
row_orderandcol_orderto set the repertoire order on each axis.
- lessons learned* (2023). Frontiers in Immunology. [doi:10.3389/fimmu.2023.1210168](https://doi.org/10.3389/fimmu.2023.1210168)
library("immunarch")
# Limit the number of threads used by the underlying DB for this example.
# Generally, you should NOT do this in your session.
db_exec("SET threads TO 1")
# Load example data.
immdata <- get_test_idata()
#
# Count receptors shared by each pair of repertoires.
m_pub <- repsim_intersection(immdata)
# Visualise the shared-receptor counts.
vis(m_pub)