These functions are designed to calculate dissimilarities on data stored
within a
TreeSummarizedExperiment
object. For overlap, Unifrac, and Jensen-Shannon Divergence (JSD)
dissimilarities, the functions use mia internal functions, while for other
types of dissimilarities, they rely on vegdist
by default.
addDissimilarity(x, method, ...)
getDissimilarity(x, method, ...)
# S4 method for class 'SummarizedExperiment'
addDissimilarity(x, method = "bray", name = method, ...)
# S4 method for class 'SummarizedExperiment'
getDissimilarity(
x,
method = "bray",
assay.type = "counts",
niter = NULL,
transposed = FALSE,
...
)
# S4 method for class 'TreeSummarizedExperiment'
getDissimilarity(
x,
method = "bray",
assay.type = "counts",
niter = NULL,
transposed = FALSE,
...
)
# S4 method for class 'ANY'
getDissimilarity(x, method = "bray", niter = NULL, ...)TreeSummarizedExperiment
or matrix.
Character scalar. Specifies which dissimilarity to
calculate. (Default: "bray")
other arguments passed into avgdist,
vegdist, or into mia internal functions:
sample: The sampling depth in rarefaction.
(Default: min(rowSums2(x)))
dis.fun: Character scalar. Specifies the dissimilarity
function to be used.
transf: Function. Specifies the optional
transformation applied before calculating the dissimilarity matrix.
tree.name: (Unifrac) Character scalar. Specifies the
name of the tree from rowTree(x) that is used in calculation.
Disabled when tree is specified. (Default: "phylo")
tree: (Unifrac) phylo. A phylogenetic tree used in
calculation. (Default: NULL)
weighted: (Unifrac) Logical scalar. Should use
weighted-Unifrac calculation?
Weighted-Unifrac takes into account the relative abundance of
species/taxa shared between samples, whereas unweighted-Unifrac only
considers presence/absence. Default is FALSE, meaning the
unweighted-Unifrac dissimilarity is calculated for all pairs of samples.
(Default: FALSE)
node.label (Unifrac) character vector. Used only if
x is a matrix. Specifies links between rows/columns and tips of
tree. All the node labs must be present in tree. For the
links, you can provide a vector with whose length equals to the number of
rows/columns in x. Alternatively, you can provide a named vector
where names represent names in abundance table and values their
corresponding node in tree.
chunkSize: (JSD) Integer scalar. Defines the size of
data send to the individual worker. Only has an effect, if BPPARAM
defines more than one worker. (Default: nrow(x))
BPPARAM: (JSD)
BiocParallelParam.
Specifies whether the calculation should be parallelized.
detection: (Overlap) Numeric scalar.
Defines detection threshold for absence/presence of features. Feature that
has abundance under threshold in either of samples, will be discarded when
evaluating overlap between samples. (Default: 0)
binary: Logical scalar. Whether to perform
presence/absence transformation before dissimilarity calculation. For
Jaccard index the default is TRUE. For other dissimilarity metrics,
please see vegdist.
Character scalar. The name to be used to store the result
in metadata of the output. (Default: method)
Character scalar. Specifies the name of assay
used in calculation. (Default: "counts")
Integer scalar. Specifies the number of
rarefaction rounds. Rarefaction is not applied when niter=NULL
(see Details section). (Default: NULL)
Logical scalar. Specifies if x is transposed with
cells in rows. (Default: FALSE)
getDissimilarity returns a sample-by-sample dissimilarity matrix.
addDissimilarity returns x that includes dissimilarity matrix
in its metadata.
Overlap reflects similarity between sample-pairs. When overlap is calculated using relative abundances, the higher the value the higher the similarity is. When using relative abundances, overlap value 1 means that all the abundances of features are equal between two samples, and 0 means that samples have completely different relative abundances.
Unifrac is calculated with a C++ implementation of the Striped Unifrac algorithm (McDonald et al. 2021).
If rarefaction is enabled, vegan:avgdist() is
utilized.
Rarefaction can be used to control uneven sequencing depths. Although, it is highly debated method. Some think that it is the only option that successfully controls the variation caused by uneven sampling depths. The biggest argument against rarefaction is the fact that it omits data.
Rarefaction works by sampling the counts randomly. This random sampling
is done niter times. In each sampling iteration, sample number
of random samples are drawn, and dissimilarity is calculated for this
subset. After the iterative process, there are niter number of
result that are then averaged to get the final result.
Refer to Schloss (2024) for more details on rarefaction.
For unifrac dissimilarity: http://bmf.colorado.edu/unifrac/
See also additional descriptions of Unifrac in the following articles:
Lozupone, Hamady and Knight, “Unifrac - An Online Tool for Comparing Microbial Community Diversity in a Phylogenetic Context.”, BMC Bioinformatics 2006, 7:371
Lozupone, Hamady, Kelley and Knight, “Quantitative and qualitative (beta) diversity measures lead to different insights into factors that structure microbial communities.” Appl Environ Microbiol. 2007
Lozupone C, Knight R. “Unifrac: a new phylogenetic method for comparing microbial communities.” Appl Environ Microbiol. 2005 71 (12):8228-35.
McDonald D, Vázquez-Baeza Y, Koslicki D, McClelland J, Reeve N, Xu Z, Gonzalez A, Knight R. “Striped UniFrac: enabling microbiome analysis at unprecedented scale.” Nat Methods. 2018 15 (11):847-848. doi: 10.1038/s41592-018-0187-8.
For JSD dissimilarity: Jensen-Shannon Divergence and Hilbert space embedding. Bent Fuglede and Flemming Topsoe University of Copenhagen, Department of Mathematics http://www.math.ku.dk/~topsoe/ISIT2004JSD.pdf
For rarefaction: Schloss PD (2024) Rarefaction is currently the best approach to control for uneven sequencing effort in amplicon sequence analyses. mSphere 28;9(2):e0035423. doi: 10.1128/msphere.00354-23
library(mia)
library(scater)
# load dataset
data(GlobalPatterns)
tse <- GlobalPatterns
### Overlap dissimilarity
tse <- addDissimilarity(tse, method = "overlap", detection = 0.25)
metadata(tse)[["overlap"]]
#> CL3 CC1 SV1 M31Fcsw M11Fcsw M31Plmr M11Plmr
#> CC1 985499.5
#> SV1 692281.0 848128.0
#> M31Fcsw 951745.0 975408.0 808197.0
#> M11Fcsw 1217896.5 1253551.5 1083470.0 1785249.5
#> M31Plmr 466124.0 626083.0 493475.0 1014235.5 1281625.5
#> M11Plmr 436360.5 499477.0 414307.0 848139.0 1122612.5 551528.5
#> F21Plmr 189694.0 291743.5 273429.0 616931.5 894038.5 441530.5 299140.0
#> M31Tong 1174598.0 1229914.0 1097341.0 1706441.0 1946599.0 1340479.0 1184561.5
#> M11Tong 159105.5 220015.5 144416.0 745652.5 1024052.5 380641.0 227037.5
#> LMEpi24M 1166203.5 1307727.0 1192077.5 1599443.5 1982577.0 1183592.5 1138447.5
#> SLEpi20M 754872.5 815047.5 658354.0 1137849.5 1467925.5 759783.0 719079.5
#> AQC1cm 891753.5 997242.0 692093.5 1182564.5 1469919.0 772221.0 675288.5
#> AQC4cm 1368073.5 1497090.5 1168803.5 1622182.5 1919925.5 1213249.0 1130264.0
#> AQC7cm 1036772.5 1187267.0 830315.5 1281239.0 1564216.5 879010.0 797615.5
#> NP2 360957.5 405369.5 272556.5 787535.5 1075807.5 436212.5 330404.0
#> NP3 824101.5 828367.0 661708.5 1237686.5 1534350.5 811049.0 838668.5
#> NP5 861958.0 865378.0 712705.0 1294562.5 1606345.0 895855.5 849872.5
#> TRRsed1 99313.5 143887.0 190577.5 541276.5 811452.0 284617.0 145628.0
#> TRRsed2 351572.0 459754.5 304333.0 757818.5 1049991.5 340828.0 313685.5
#> TRRsed3 327360.0 379139.0 223779.0 763371.5 997684.5 290772.5 218502.5
#> TS28 624664.5 648472.5 521238.0 1221536.0 1462594.5 697629.0 557145.0
#> TS29 769249.5 776365.5 671889.0 1347125.5 1552821.5 814524.5 699393.0
#> Even1 978147.5 1038226.0 796474.0 1332322.5 1586458.5 842413.5 678228.0
#> Even2 784025.5 941708.0 693164.0 1199305.0 1460535.0 729549.5 560118.5
#> Even3 751326.0 807375.5 809754.0 1246595.5 1467452.5 767190.0 598642.0
#> F21Plmr M31Tong M11Tong LMEpi24M SLEpi20M AQC1cm AQC4cm
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr
#> M31Tong 1077004.5
#> M11Tong 131018.0 1047508.0
#> LMEpi24M 1017521.0 2024365.5 1101925.0
#> SLEpi20M 554381.0 1567813.0 642227.5 1651477.0
#> AQC1cm 547105.0 1520428.0 577228.5 1608273.5 1174190.0
#> AQC4cm 998910.0 2051930.5 1108218.0 2179140.0 1751904.0 1758771.0
#> AQC7cm 662458.0 1728503.5 784701.5 1864644.5 1426762.5 1429167.0 2026146.0
#> NP2 270038.0 1209387.5 293531.5 1238659.5 796451.5 812915.0 1400285.0
#> NP3 578321.5 1697735.5 715681.5 1683481.5 1179390.5 1270814.0 1790660.5
#> NP5 681794.0 1811876.0 838350.0 1770500.0 1259181.0 1334017.0 1854015.0
#> TRRsed1 87773.5 980573.5 65217.0 1011842.5 521681.5 494856.0 985763.5
#> TRRsed2 238362.0 1153742.0 225444.0 1129898.5 656716.5 715371.5 1229872.5
#> TRRsed3 153508.0 1043396.0 129250.0 1025518.0 570554.0 610521.0 1114243.5
#> TS28 410238.0 1424754.0 471252.5 1310570.0 916424.0 914313.0 1358702.5
#> TS29 571671.0 1547449.0 613823.0 1461118.5 1031225.0 1134535.5 1613484.5
#> Even1 509060.5 1578801.5 626756.5 1572468.5 1124671.0 1161962.5 1703981.0
#> Even2 429468.5 1448323.5 509204.0 1430593.5 977856.5 993697.5 1479496.0
#> Even3 463482.5 1500253.0 561539.0 1519288.0 1030249.0 1023662.5 1499581.5
#> AQC7cm NP2 NP3 NP5 TRRsed1 TRRsed2 TRRsed3
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr
#> M31Tong
#> M11Tong
#> LMEpi24M
#> SLEpi20M
#> AQC1cm
#> AQC4cm
#> AQC7cm
#> NP2 1071726.5
#> NP3 1436127.5 961190.0
#> NP5 1509321.5 1063725.0 1559049.5
#> TRRsed1 662344.5 265898.0 714368.5 835773.0
#> TRRsed2 916395.5 431212.0 915340.0 998249.5 268039.5
#> TRRsed3 794425.5 322803.5 775024.0 784470.0 159239.5 381979.5
#> TS28 1024423.5 537932.5 1028058.5 1144928.5 288216.5 583381.5 577097.5
#> TS29 1271708.0 704238.5 1138939.0 1211490.5 435429.0 688699.5 679880.0
#> Even1 1364357.0 694364.5 1261159.0 1332217.0 616518.0 780421.0 730090.5
#> Even2 1146982.5 589007.5 1109287.0 1163733.5 490509.0 623804.5 563258.0
#> Even3 1170876.5 626299.0 1142307.5 1224271.5 546121.0 671455.5 614319.5
#> TS28 TS29 Even1 Even2
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr
#> M31Tong
#> M11Tong
#> LMEpi24M
#> SLEpi20M
#> AQC1cm
#> AQC4cm
#> AQC7cm
#> NP2
#> NP3
#> NP5
#> TRRsed1
#> TRRsed2
#> TRRsed3
#> TS28
#> TS29 1071187.0
#> Even1 1057572.0 1185539.5
#> Even2 924017.0 1051850.5 1090891.0
#> Even3 977024.0 1110777.5 1143819.0 1022623.5
### JSD dissimilarity
tse <- addDissimilarity(tse, method = "jsd")
metadata(tse)[["jsd"]]
#> CL3 CC1 SV1 M31Fcsw M11Fcsw
#> CC1 0.254707967
#> SV1 0.505148131 0.437803575
#> M31Fcsw 0.680926324 0.686321320 0.684818606
#> M11Fcsw 0.681341779 0.686944393 0.685067549 0.286477378
#> M31Plmr 0.671307430 0.662016825 0.664984538 0.672037459 0.683101301
#> M11Plmr 0.630301161 0.601303835 0.603099982 0.663333479 0.675503732
#> F21Plmr 0.658553888 0.638357788 0.626435718 0.676464058 0.684159903
#> M31Tong 0.685940753 0.686204142 0.686366143 0.682689520 0.685337047
#> M11Tong 0.668180478 0.663601984 0.668525563 0.666433533 0.669598556
#> LMEpi24M 0.671572083 0.662382257 0.671223797 0.687812811 0.687097891
#> SLEpi20M 0.670364754 0.657859919 0.663640746 0.689766845 0.689859222
#> AQC1cm 0.625183897 0.601849476 0.640651113 0.674026751 0.678225628
#> AQC4cm 0.634836376 0.616883820 0.653336325 0.689186522 0.689486856
#> AQC7cm 0.623063112 0.602590148 0.647553149 0.689121613 0.689222527
#> NP2 0.682663185 0.680103035 0.683165646 0.689728143 0.689829767
#> NP3 0.682616391 0.679678499 0.678957832 0.689145323 0.689448384
#> NP5 0.685917253 0.684846927 0.685982742 0.689093028 0.689532213
#> TRRsed1 0.661247061 0.658164402 0.653347602 0.666476987 0.667270721
#> TRRsed2 0.671333770 0.667005355 0.671671859 0.688635373 0.688865112
#> TRRsed3 0.662967405 0.662359489 0.667615365 0.625861006 0.640590903
#> TS28 0.680152498 0.685236897 0.683633272 0.292085890 0.438058196
#> TS29 0.682117898 0.685667672 0.684678038 0.443335240 0.538829879
#> Even1 0.662349027 0.670055002 0.673051538 0.553806929 0.540855342
#> Even2 0.667521688 0.671220676 0.674039616 0.562497370 0.550161268
#> Even3 0.672378467 0.677452163 0.672799806 0.560711360 0.548726196
#> M31Plmr M11Plmr F21Plmr M31Tong M11Tong
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr 0.438600393
#> F21Plmr 0.174033354 0.382022849
#> M31Tong 0.377261181 0.630284299 0.441439964
#> M11Tong 0.365418116 0.591424774 0.392572226 0.270078347
#> LMEpi24M 0.675709113 0.654049339 0.667369867 0.673488613 0.371367009
#> SLEpi20M 0.680639287 0.659202192 0.671460060 0.682582542 0.551524882
#> AQC1cm 0.677109375 0.649693671 0.664155340 0.673272135 0.601587237
#> AQC4cm 0.683357191 0.661490237 0.671873814 0.680082693 0.628244325
#> AQC7cm 0.682579691 0.657417503 0.670460254 0.680645436 0.619068666
#> NP2 0.686050048 0.677031995 0.677307605 0.669692555 0.642442647
#> NP3 0.682922017 0.667832537 0.674298793 0.671241821 0.647158884
#> NP5 0.681515684 0.677972377 0.675768474 0.659591185 0.638152316
#> TRRsed1 0.661904492 0.652267056 0.646884121 0.658151069 0.605400495
#> TRRsed2 0.673798579 0.649531109 0.653650555 0.683581914 0.668921098
#> TRRsed3 0.676866542 0.666192217 0.668961967 0.679348695 0.656683020
#> TS28 0.681502464 0.670327344 0.680976671 0.681518724 0.663517263
#> TS29 0.682788055 0.673800439 0.681903810 0.682496294 0.665063718
#> Even1 0.677241937 0.670432069 0.672792254 0.680076956 0.660510253
#> Even2 0.677508690 0.672330618 0.674178474 0.682067765 0.666681950
#> Even3 0.678694431 0.673295102 0.674975071 0.682923180 0.666399295
#> LMEpi24M SLEpi20M AQC1cm AQC4cm AQC7cm
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr
#> M31Tong
#> M11Tong
#> LMEpi24M
#> SLEpi20M 0.438958399
#> AQC1cm 0.619279384 0.589254830
#> AQC4cm 0.649125923 0.623610920 0.043661029
#> AQC7cm 0.632675525 0.606650570 0.056416209 0.014405090
#> NP2 0.676487508 0.660665394 0.608811137 0.608554952 0.620077397
#> NP3 0.677619887 0.669217246 0.613941609 0.629923017 0.638587546
#> NP5 0.680183308 0.671752500 0.605939293 0.611144449 0.627513279
#> TRRsed1 0.644416782 0.656957693 0.607033067 0.619500757 0.618606489
#> TRRsed2 0.683377981 0.682873258 0.664490926 0.664772357 0.661234528
#> TRRsed3 0.681953879 0.681776217 0.649437382 0.659912706 0.656045285
#> TS28 0.687023267 0.688300188 0.666477288 0.687120032 0.687107397
#> TS29 0.686622149 0.686726653 0.657881720 0.682103192 0.682159744
#> Even1 0.682703387 0.681376401 0.654870389 0.671880547 0.671600081
#> Even2 0.685649484 0.686525429 0.668566630 0.684357485 0.683887271
#> Even3 0.684359498 0.686620040 0.670604627 0.686536706 0.686095352
#> NP2 NP3 NP5 TRRsed1 TRRsed2
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr
#> M31Tong
#> M11Tong
#> LMEpi24M
#> SLEpi20M
#> AQC1cm
#> AQC4cm
#> AQC7cm
#> NP2
#> NP3 0.383387830
#> NP5 0.228166675 0.328832394
#> TRRsed1 0.582057317 0.580369463 0.552593953
#> TRRsed2 0.665300104 0.651770785 0.661081878 0.224840619
#> TRRsed3 0.668961542 0.658294868 0.665777464 0.264043576 0.156533858
#> TS28 0.687581977 0.686855723 0.686900428 0.659790498 0.684880590
#> TS29 0.686348073 0.686219563 0.687080093 0.664382336 0.687477044
#> Even1 0.680150832 0.679511021 0.680840574 0.580111672 0.679034736
#> Even2 0.686775516 0.685499969 0.686135755 0.589592653 0.685684982
#> Even3 0.687266091 0.685968549 0.686501064 0.587995151 0.686191570
#> TRRsed3 TS28 TS29 Even1 Even2
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr
#> M31Tong
#> M11Tong
#> LMEpi24M
#> SLEpi20M
#> AQC1cm
#> AQC4cm
#> AQC7cm
#> NP2
#> NP3
#> NP5
#> TRRsed1
#> TRRsed2
#> TRRsed3
#> TS28 0.595332889
#> TS29 0.622345026 0.264303958
#> Even1 0.594832547 0.548865714 0.565470944
#> Even2 0.604402259 0.560393200 0.574150684 0.008222361
#> Even3 0.604483562 0.552374311 0.569527813 0.006627728 0.008132505
# Multi Dimensional Scaling applied to JSD dissimilarity matrix
tse <- addMDS(tse, method = "overlap", assay.type = "counts")
reducedDim(tse, "MDS") |> head()
#> [,1] [,2]
#> CL3 -59443.48966 30449.91
#> CC1 -90318.88662 -39519.24
#> SV1 50022.89144 -38252.95
#> M31Fcsw 67.34763 209366.60
#> M11Fcsw 167716.35955 -569793.66
#> M31Plmr 27167.45045 104144.91
### Unifrac dissimilarity
res <- getDissimilarity(tse, method = "unifrac", weighted = FALSE)
dim(as.matrix(res))
#> [1] 26 26
tse <- addDissimilarity(tse, method = "unifrac", weighted = TRUE)
metadata(tse)[["unifrac"]]
#> CL3 CC1 SV1 M31Fcsw M11Fcsw M31Plmr
#> CC1 0.21963128
#> SV1 0.36013714 0.31451172
#> M31Fcsw 0.85677021 0.85436199 0.84332919
#> M11Fcsw 0.86610725 0.86331592 0.84668072 0.33502452
#> M31Plmr 0.58924172 0.58469846 0.60065349 0.79134820 0.85796211
#> M11Plmr 0.47949672 0.47094132 0.48155659 0.82352557 0.82244003 0.42721162
#> F21Plmr 0.57029030 0.56523984 0.54769386 0.78295133 0.81236325 0.19836640
#> M31Tong 0.63585960 0.63252945 0.65718578 0.88401950 0.88944558 0.44507138
#> M11Tong 0.60867186 0.60383109 0.59064026 0.77952545 0.79962911 0.35000209
#> LMEpi24M 0.54972288 0.52606910 0.52869884 0.88084193 0.86367410 0.60345919
#> SLEpi20M 0.49114347 0.46507285 0.45351410 0.82458207 0.81219289 0.56460044
#> AQC1cm 0.58030014 0.56691215 0.59647289 0.95433954 0.93706177 0.70595263
#> AQC4cm 0.61637683 0.60466184 0.62357843 0.95380887 0.93596952 0.70854109
#> AQC7cm 0.56496506 0.55171281 0.57782048 0.92477709 0.90690605 0.66567908
#> NP2 0.53916824 0.53965220 0.52004647 0.86988191 0.85230423 0.64412002
#> NP3 0.64967202 0.64302873 0.59387131 0.71314365 0.70643124 0.73356002
#> NP5 0.60188961 0.59543185 0.56058153 0.84692645 0.83146988 0.65969039
#> TRRsed1 0.46163686 0.46385094 0.46342153 0.81626568 0.81821706 0.54865778
#> TRRsed2 0.47910285 0.48584484 0.49713977 0.84872812 0.84507125 0.57707441
#> TRRsed3 0.48035807 0.48755141 0.46688966 0.80813152 0.81730651 0.57197377
#> TS28 0.76684559 0.76428747 0.75319351 0.48883996 0.75553076 0.70097385
#> TS29 0.74324093 0.74158454 0.75023383 0.61553136 0.87304341 0.69217070
#> Even1 0.68908646 0.68963538 0.68355096 0.49100462 0.63713979 0.54223497
#> Even2 0.69840990 0.69937410 0.69463359 0.49712988 0.64606298 0.54963143
#> Even3 0.69237685 0.69329031 0.68787052 0.49224873 0.64957246 0.53868866
#> M11Plmr F21Plmr M31Tong M11Tong LMEpi24M SLEpi20M
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr 0.37757623
#> M31Tong 0.46622897 0.42697531
#> M11Tong 0.48783806 0.28668805 0.39253826
#> LMEpi24M 0.46646573 0.55586162 0.64193843 0.51271790
#> SLEpi20M 0.42761364 0.49586755 0.60447938 0.51470801 0.36897450
#> AQC1cm 0.55607596 0.67211020 0.73479156 0.66582567 0.44793363 0.56474459
#> AQC4cm 0.57221022 0.67693267 0.73511419 0.67480307 0.46471288 0.57907248
#> AQC7cm 0.53996970 0.63270723 0.69309058 0.63044621 0.42520725 0.53469346
#> NP2 0.50705248 0.56509552 0.64756715 0.56848373 0.49413718 0.47386372
#> NP3 0.62113330 0.65917739 0.76560455 0.69313856 0.66838692 0.59396658
#> NP5 0.53260598 0.57972257 0.68601012 0.59126518 0.51128923 0.50200241
#> TRRsed1 0.41263572 0.50643108 0.53492909 0.53704773 0.52051049 0.46506724
#> TRRsed2 0.37299868 0.54140462 0.55227796 0.59294432 0.52923714 0.48987318
#> TRRsed3 0.42764732 0.55132907 0.56232723 0.58753063 0.56429730 0.52135315
#> TS28 0.73916427 0.69142366 0.78936848 0.68844756 0.79019640 0.73331315
#> TS29 0.69286759 0.71781828 0.80947505 0.74577649 0.76679354 0.73586366
#> Even1 0.58653370 0.52872395 0.58493530 0.52174816 0.71931564 0.65319756
#> Even2 0.59826599 0.54254409 0.59672093 0.53620151 0.73209469 0.66643325
#> Even3 0.58815541 0.53052712 0.58466568 0.52447642 0.72444729 0.65879259
#> AQC1cm AQC4cm AQC7cm NP2 NP3 NP5
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr
#> M31Tong
#> M11Tong
#> LMEpi24M
#> SLEpi20M
#> AQC1cm
#> AQC4cm 0.07934332
#> AQC7cm 0.12331235 0.09171972
#> NP2 0.55901426 0.58267263 0.54291930
#> NP3 0.73661791 0.73324690 0.69093160 0.42616506
#> NP5 0.54870605 0.54717347 0.50535556 0.26308754 0.40649021
#> TRRsed1 0.54187827 0.55250081 0.49714559 0.43318694 0.54743794 0.48105735
#> TRRsed2 0.54243983 0.53212764 0.49951219 0.48133932 0.58718366 0.52053730
#> TRRsed3 0.58023674 0.57555376 0.52921453 0.52209621 0.61523348 0.55623751
#> TS28 0.86399541 0.86519086 0.83526280 0.79125273 0.86961416 0.81835467
#> TS29 0.82810568 0.83054616 0.80917905 0.82030097 0.90026099 0.83571981
#> Even1 0.80437440 0.80547485 0.76768049 0.68324775 0.71782556 0.65110165
#> Even2 0.81730775 0.81829582 0.78057175 0.69582974 0.72978748 0.66430331
#> Even3 0.81033115 0.81130079 0.77348425 0.68838470 0.72829482 0.65766953
#> TRRsed1 TRRsed2 TRRsed3 TS28 TS29 Even1
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr
#> M31Tong
#> M11Tong
#> LMEpi24M
#> SLEpi20M
#> AQC1cm
#> AQC4cm
#> AQC7cm
#> NP2
#> NP3
#> NP5
#> TRRsed1
#> TRRsed2 0.21490116
#> TRRsed3 0.22643701 0.19167874
#> TS28 0.72757348 0.75939406 0.71958436
#> TS29 0.72683690 0.72334973 0.69026717 0.23438534
#> Even1 0.62083970 0.66680524 0.62567633 0.50113274 0.59879081
#> Even2 0.63341320 0.67833367 0.63676083 0.51393970 0.60873618 0.03824023
#> Even3 0.62581526 0.67098962 0.63040798 0.49473072 0.59493406 0.02640161
#> Even2
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr
#> M31Tong
#> M11Tong
#> LMEpi24M
#> SLEpi20M
#> AQC1cm
#> AQC4cm
#> AQC7cm
#> NP2
#> NP3
#> NP5
#> TRRsed1
#> TRRsed2
#> TRRsed3
#> TS28
#> TS29
#> Even1
#> Even2
#> Even3 0.04234192
### Bray dissimilarity
# Bray is usually applied to relative abundances so we have to apply
# transformation first
tse <- transformAssay(tse, method = "relabundance")
res <- getDissimilarity(tse, method = "bray", assay.type = "relabundance")
res
#> CL3 CC1 SV1 M31Fcsw M11Fcsw M31Plmr
#> CC1 0.59029490
#> SV1 0.84384585 0.78355878
#> M31Fcsw 0.99475056 0.99697183 0.99618942
#> M11Fcsw 0.99487923 0.99727732 0.99635607 0.54689733
#> M31Plmr 0.98445002 0.97650496 0.98156783 0.98742517 0.99553373
#> M11Plmr 0.95377160 0.92603902 0.93296891 0.98396692 0.99040516 0.80200672
#> F21Plmr 0.97394536 0.95474720 0.95232519 0.99061479 0.99557739 0.46947732
#> M31Tong 0.99515900 0.99589003 0.99520574 0.99575309 0.99667602 0.73274634
#> M11Tong 0.98105013 0.97884283 0.98453425 0.98840489 0.98943797 0.69927733
#> LMEpi24M 0.98439780 0.97517743 0.98586208 0.99739526 0.99774477 0.99145711
#> SLEpi20M 0.98448675 0.97507957 0.97875210 0.99841813 0.99855270 0.99225317
#> AQC1cm 0.94779207 0.92924887 0.96127687 0.99004372 0.99139778 0.99097918
#> AQC4cm 0.95583278 0.94216546 0.97125170 0.99829580 0.99838610 0.99450432
#> AQC7cm 0.94520510 0.93077116 0.96599031 0.99818395 0.99829442 0.99402462
#> NP2 0.99367620 0.99122195 0.99333584 0.99849716 0.99857549 0.99624296
#> NP3 0.99348020 0.99037506 0.99090294 0.99823125 0.99835771 0.99354905
#> NP5 0.99600043 0.99472654 0.99554062 0.99817460 0.99839327 0.99440271
#> TRRsed1 0.97680064 0.97614209 0.97738452 0.98469936 0.98709772 0.98163599
#> TRRsed2 0.98464780 0.98187364 0.98520053 0.99744564 0.99756779 0.98710014
#> TRRsed3 0.97979420 0.98023818 0.98335529 0.95816033 0.96312360 0.98948156
#> TS28 0.99353363 0.99569940 0.99483417 0.64268016 0.78782644 0.99475321
#> TS29 0.99399631 0.99610229 0.99514351 0.78262637 0.88635552 0.99468213
#> Even1 0.98680027 0.98992671 0.99019550 0.89136956 0.87906516 0.99208059
#> Even2 0.98865822 0.99147234 0.99103264 0.89812186 0.88870857 0.99230154
#> Even3 0.99033247 0.99315799 0.99143010 0.89776990 0.88598513 0.99282937
#> M11Plmr F21Plmr M31Tong M11Tong LMEpi24M SLEpi20M
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr 0.73712108
#> M31Tong 0.95592245 0.76703101
#> M11Tong 0.92513115 0.71112780 0.59031917
#> LMEpi24M 0.97142726 0.98603352 0.99128977 0.74580723
#> SLEpi20M 0.97635322 0.98642937 0.99489643 0.90233606 0.78385147
#> AQC1cm 0.96562588 0.98174466 0.98903798 0.93637168 0.94613567 0.94057012
#> AQC4cm 0.97456428 0.98720007 0.99253323 0.96021156 0.97099988 0.95958619
#> AQC7cm 0.97166691 0.98584740 0.99361238 0.95544661 0.95976856 0.94984233
#> NP2 0.99015067 0.99030553 0.98915786 0.96839713 0.99061040 0.97064278
#> NP3 0.98362285 0.98817545 0.98877553 0.96918204 0.99059568 0.97973218
#> NP5 0.99161038 0.99129987 0.98735545 0.97541987 0.99212081 0.98716565
#> TRRsed1 0.97179186 0.97191560 0.98215072 0.94326469 0.97632666 0.97574280
#> TRRsed2 0.96284619 0.96299781 0.99411956 0.98769722 0.99407992 0.99359788
#> TRRsed3 0.98063491 0.98432791 0.99222445 0.97708977 0.99313857 0.99296507
#> TS28 0.98941263 0.99359208 0.99521212 0.98709879 0.99686009 0.99765732
#> TS29 0.98949843 0.99335801 0.99434433 0.98646607 0.99557421 0.99627895
#> Even1 0.98662161 0.98628365 0.99243068 0.98332732 0.99314994 0.99228899
#> Even2 0.98834682 0.98863308 0.99442274 0.98905496 0.99593101 0.99636618
#> Even3 0.98889948 0.98866658 0.99440985 0.98919910 0.99611433 0.99655701
#> AQC1cm AQC4cm AQC7cm NP2 NP3 NP5
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr
#> M31Tong
#> M11Tong
#> LMEpi24M
#> SLEpi20M
#> AQC1cm
#> AQC4cm 0.16304813
#> AQC7cm 0.21199799 0.13652373
#> NP2 0.95813803 0.96129836 0.96525635
#> NP3 0.96223012 0.96712390 0.97174560 0.71918264
#> NP5 0.93302264 0.93776812 0.94256521 0.56554285 0.68029527
#> TRRsed1 0.94479953 0.95580459 0.95314483 0.92460405 0.91552971 0.91653511
#> TRRsed2 0.98213973 0.98209398 0.97965702 0.98195083 0.96897398 0.97941744
#> TRRsed3 0.96934214 0.97801112 0.97434182 0.98549758 0.97865696 0.98310374
#> TS28 0.98734799 0.99721043 0.99715447 0.99745782 0.99686338 0.99705073
#> TS29 0.98688168 0.99596685 0.99594942 0.99626206 0.99598727 0.99638084
#> Even1 0.98371239 0.99055265 0.99035097 0.99217448 0.99205466 0.99347857
#> Even2 0.98947270 0.99540712 0.99511712 0.99675002 0.99636568 0.99646933
#> Even3 0.99078069 0.99666139 0.99620877 0.99701099 0.99664043 0.99692439
#> TRRsed1 TRRsed2 TRRsed3 TS28 TS29 Even1
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr
#> M31Tong
#> M11Tong
#> LMEpi24M
#> SLEpi20M
#> AQC1cm
#> AQC4cm
#> AQC7cm
#> NP2
#> NP3
#> NP5
#> TRRsed1
#> TRRsed2 0.54482665
#> TRRsed3 0.59701084 0.42564996
#> TS28 0.98128746 0.99545170 0.94900978
#> TS29 0.98223170 0.99622952 0.95857267 0.61813117
#> Even1 0.94177469 0.99240341 0.94907622 0.87744794 0.87635032
#> Even2 0.94714479 0.99520080 0.95354122 0.88489924 0.88242703 0.06917443
#> Even3 0.94659526 0.99581221 0.95449116 0.88192419 0.88070775 0.05844839
#> Even2
#> CC1
#> SV1
#> M31Fcsw
#> M11Fcsw
#> M31Plmr
#> M11Plmr
#> F21Plmr
#> M31Tong
#> M11Tong
#> LMEpi24M
#> SLEpi20M
#> AQC1cm
#> AQC4cm
#> AQC7cm
#> NP2
#> NP3
#> NP5
#> TRRsed1
#> TRRsed2
#> TRRsed3
#> TS28
#> TS29
#> Even1
#> Even2
#> Even3 0.08029104
# If applying rarefaction, the input must be count matrix and transformation
# method specified in function call (Note: increase niter)
rclr <- function(x){
vegan::decostand(x, method="rclr")
}
res <- getDissimilarity(
tse, method = "euclidean", transf = rclr, niter = 2L)
res
#> CL3 CC1 SV1 M31Fcsw M11Fcsw M31Plmr
#> CL3 0.000000 12.566740 47.398941 114.925322 107.052130 143.045485
#> CC1 12.566740 0.000000 42.937266 120.705679 112.712463 140.275903
#> SV1 47.398941 42.937266 0.000000 105.797926 98.658362 106.896200
#> M31Fcsw 114.925322 120.705679 105.797926 0.000000 9.433174 94.254211
#> M11Fcsw 107.052130 112.712463 98.658362 9.433174 0.000000 92.792014
#> M31Plmr 143.045485 140.275903 106.896200 94.254211 92.792014 0.000000
#> M11Plmr 107.542616 104.119675 71.694644 85.475883 81.112435 36.628724
#> F21Plmr 120.334717 118.012117 85.931018 79.496485 76.490607 23.071697
#> M31Tong 120.587512 119.851775 92.116669 64.290024 61.761603 33.225179
#> M11Tong 124.369003 124.245187 100.171607 60.635103 58.541665 42.242552
#> LMEpi24M 103.264758 101.858207 75.924567 67.504288 62.862305 45.187420
#> SLEpi20M 96.878019 95.686781 70.555809 65.427789 60.238540 50.884142
#> AQC1cm 98.757413 95.784533 89.046535 93.783502 87.523754 84.819775
#> AQC4cm 100.846651 97.069775 88.281674 98.167893 92.002328 81.518748
#> AQC7cm 102.381204 98.076457 90.677184 104.228649 98.027182 85.705645
#> NP2 91.858857 95.173211 77.266296 34.407956 27.704515 76.152457
#> NP3 88.209114 89.036058 68.578444 52.066274 45.633910 65.623143
#> NP5 92.021727 93.626193 74.567545 45.688242 39.522781 67.524712
#> TRRsed1 96.491665 103.050518 109.286491 59.013471 53.737034 126.670368
#> TRRsed2 82.431110 90.047300 97.717527 58.747571 52.577055 128.133995
#> TRRsed3 92.000020 99.713374 105.083518 53.270256 48.003011 128.101385
#> TS28 107.628154 111.992289 92.613782 18.373769 15.091687 78.810276
#> TS29 105.520008 110.335874 92.892202 15.252512 10.210063 83.570641
#> Even1 118.609179 123.713458 109.186815 12.807946 14.611392 89.802342
#> Even2 123.678490 131.592986 127.308255 35.787765 37.201628 126.759942
#> Even3 131.852130 139.492859 132.402175 33.867303 37.543174 124.421658
#> M11Plmr F21Plmr M31Tong M11Tong LMEpi24M SLEpi20M
#> CL3 107.542616 120.334717 120.587512 124.369003 103.264758 96.878019
#> CC1 104.119675 118.012117 119.851775 124.245187 101.858207 95.686781
#> SV1 71.694644 85.931018 92.116669 100.171607 75.924567 70.555809
#> M31Fcsw 85.475883 79.496485 64.290024 60.635103 67.504288 65.427789
#> M11Fcsw 81.112435 76.490607 61.761603 58.541665 62.862305 60.238540
#> M31Plmr 36.628724 23.071697 33.225179 42.242552 45.187420 50.884142
#> M11Plmr 0.000000 17.068070 31.046340 42.284546 23.060019 25.310964
#> F21Plmr 17.068070 0.000000 18.967724 31.724276 24.194020 29.010232
#> M31Tong 31.046340 18.967724 0.000000 13.931888 20.190108 25.195410
#> M11Tong 42.284546 31.724276 13.931888 0.000000 25.770559 30.306256
#> LMEpi24M 23.060019 24.194020 20.190108 25.770559 0.000000 6.583187
#> SLEpi20M 25.310964 29.010232 25.195410 30.306256 6.583187 0.000000
#> AQC1cm 62.497885 69.032426 64.159284 60.429544 49.865260 48.554990
#> AQC4cm 59.154980 66.471459 63.504759 60.821326 48.951435 48.146623
#> AQC7cm 63.447226 71.298370 69.114783 66.580542 54.575138 53.814026
#> NP2 57.195393 56.284934 44.321768 43.812131 38.861046 35.052199
#> NP3 41.457077 43.911956 35.454511 37.481101 23.832565 18.657414
#> NP5 46.551729 46.839374 35.748506 35.830950 26.999896 22.799762
#> TRRsed1 107.352541 108.088961 93.666358 86.684869 86.457870 82.469085
#> TRRsed2 105.581963 107.932820 95.295568 90.589148 86.466989 81.609673
#> TRRsed3 108.046500 108.853591 94.952709 89.335784 87.996318 83.606639
#> TS28 68.270128 62.735600 48.828223 47.630171 51.522491 49.532268
#> TS29 71.769072 67.011192 52.891494 50.909768 54.189853 51.790451
#> Even1 82.741629 75.914142 59.055625 53.134234 63.099287 61.746125
#> Even2 116.533376 111.747887 95.343500 88.939770 96.427094 93.814865
#> Even3 117.161579 110.925211 94.197313 87.702861 97.396513 95.361515
#> AQC1cm AQC4cm AQC7cm NP2 NP3 NP5
#> CL3 98.757413 100.846651 102.381204 91.858857 88.209114 92.021727
#> CC1 95.784533 97.069775 98.076457 95.173211 89.036058 93.626193
#> SV1 89.046535 88.281674 90.677184 77.266296 68.578444 74.567545
#> M31Fcsw 93.783502 98.167893 104.228649 34.407956 52.066274 45.688242
#> M11Fcsw 87.523754 92.002328 98.027182 27.704515 45.633910 39.522781
#> M31Plmr 84.819775 81.518748 85.705645 76.152457 65.623143 67.524712
#> M11Plmr 62.497885 59.154980 63.447226 57.195393 41.457077 46.551729
#> F21Plmr 69.032426 66.471459 71.298370 56.284934 43.911956 46.839374
#> M31Tong 64.159284 63.504759 69.114783 44.321768 35.454511 35.748506
#> M11Tong 60.429544 60.821326 66.580542 43.812131 37.481101 35.830950
#> LMEpi24M 49.865260 48.951435 54.575138 38.861046 23.832565 26.999896
#> SLEpi20M 48.554990 48.146623 53.814026 35.052199 18.657414 22.799762
#> AQC1cm 0.000000 7.727167 11.746029 65.545806 51.517114 53.987090
#> AQC4cm 7.727167 0.000000 6.277798 68.998565 53.612071 56.744985
#> AQC7cm 11.746029 6.277798 0.000000 75.044837 59.569817 62.838042
#> NP2 65.545806 68.998565 75.044837 0.000000 19.076306 13.542805
#> NP3 51.517114 53.612071 59.569817 19.076306 0.000000 7.408093
#> NP5 53.987090 56.744985 62.838042 13.542805 7.408093 0.000000
#> TRRsed1 78.194314 85.414575 89.568644 57.752137 67.065746 62.620161
#> TRRsed2 81.782387 88.523123 92.726855 54.940818 64.750642 61.235325
#> TRRsed3 85.851598 92.671746 97.156510 55.006854 66.842122 62.368241
#> TS28 83.645150 87.042786 93.222525 22.163170 37.493453 32.227287
#> TS29 83.244761 87.069032 93.207159 20.770290 38.229239 32.372570
#> Even1 86.737895 91.262369 97.326059 33.445032 49.456036 42.539507
#> Even2 109.141082 115.214463 120.696292 60.971593 78.282260 71.814845
#> Even3 113.610871 119.361411 125.029857 63.270305 80.883468 74.157961
#> TRRsed1 TRRsed2 TRRsed3 TS28 TS29 Even1
#> CL3 96.491665 82.431110 92.000020 107.628154 105.520008 118.609179
#> CC1 103.050518 90.047300 99.713374 111.992289 110.335874 123.713458
#> SV1 109.286491 97.717527 105.083518 92.613782 92.892202 109.186815
#> M31Fcsw 59.013471 58.747571 53.270256 18.373769 15.252512 12.807946
#> M11Fcsw 53.737034 52.577055 48.003011 15.091687 10.210063 14.611392
#> M31Plmr 126.670368 128.133995 128.101385 78.810276 83.570641 89.802342
#> M11Plmr 107.352541 105.581963 108.046500 68.270128 71.769072 82.741629
#> F21Plmr 108.088961 107.932820 108.853591 62.735600 67.011192 75.914142
#> M31Tong 93.666358 95.295568 94.952709 48.828223 52.891494 59.055625
#> M11Tong 86.684869 90.589148 89.335784 47.630171 50.909768 53.134234
#> LMEpi24M 86.457870 86.466989 87.996318 51.522491 54.189853 63.099287
#> SLEpi20M 82.469085 81.609673 83.606639 49.532268 51.790451 61.746125
#> AQC1cm 78.194314 81.782387 85.851598 83.645150 83.244761 86.737895
#> AQC4cm 85.414575 88.523123 92.671746 87.042786 87.069032 91.262369
#> AQC7cm 89.568644 92.726855 97.156510 93.222525 93.207159 97.326059
#> NP2 57.752137 54.940818 55.006854 22.163170 20.770290 33.445032
#> NP3 67.065746 64.750642 66.842122 37.493453 38.229239 49.456036
#> NP5 62.620161 61.235325 62.368241 32.227287 32.372570 42.539507
#> TRRsed1 0.000000 17.392499 14.168315 64.671528 59.795719 55.959994
#> TRRsed2 17.392499 0.000000 10.277864 63.263661 58.096065 59.076410
#> TRRsed3 14.168315 10.277864 0.000000 60.149048 54.846728 53.187152
#> TS28 64.671528 63.263661 60.149048 0.000000 5.785944 20.373004
#> TS29 59.795719 58.096065 54.846728 5.785944 0.000000 17.982134
#> Even1 55.959994 59.076410 53.187152 20.373004 17.982134 0.000000
#> Even2 46.587890 49.751440 40.294823 51.704742 47.089115 37.251532
#> Even3 56.091192 59.609203 50.263422 50.805383 46.946888 35.272127
#> Even2 Even3
#> CL3 123.678490 131.852130
#> CC1 131.592986 139.492859
#> SV1 127.308255 132.402175
#> M31Fcsw 35.787765 33.867303
#> M11Fcsw 37.201628 37.543174
#> M31Plmr 126.759942 124.421658
#> M11Plmr 116.533376 117.161579
#> F21Plmr 111.747887 110.925211
#> M31Tong 95.343500 94.197313
#> M11Tong 88.939770 87.702861
#> LMEpi24M 96.427094 97.396513
#> SLEpi20M 93.814865 95.361515
#> AQC1cm 109.141082 113.610871
#> AQC4cm 115.214463 119.361411
#> AQC7cm 120.696292 125.029857
#> NP2 60.971593 63.270305
#> NP3 78.282260 80.883468
#> NP5 71.814845 74.157961
#> TRRsed1 46.587890 56.091192
#> TRRsed2 49.751440 59.609203
#> TRRsed3 40.294823 50.263422
#> TS28 51.704742 50.805383
#> TS29 47.089115 46.946888
#> Even1 37.251532 35.272127
#> Even2 0.000000 11.770926
#> Even3 11.770926 0.000000