immunarch — Fast and Seamless Exploration of Single-cell and Bulk T-cell/Antibody Immune Repertoires in R
10× Genomics单细胞免疫组库VDJ分析必知必会
免疫组库数据分析||immunarch教程:克隆型分析
免疫组库数据分析||immunarch教程:探索性数据分析
免疫组库数据分析||immunarch教程:载入10X数据
免疫组库数据分析||immunarch教程:快速开始
免疫组库数据分析||immunarch教程:GeneUsage分析
今天,我们继续我们的免疫组库数据分析的Demos,这一次我们来谈谈Diversity 分析。像我这样刚入门免疫组库的人首先会问什么是Diversity ?如果不是生态学出身,可能更多地听到的是异质性,多样性是异质性的一种体现。坦率地说,我接触多样性是从《数量生态学》开始的,这是一门研究某生境下物种分布/多寡/迁移的学科。其实我们的数据可以做一个类比:群落-组织;物种-VDJ克隆型。其实《数量生态学》研究的也是一张丰度表。所以我们可以用数量生态学大名鼎鼎的R包(vegan)来计算VDJ
的多样性,只是我们今天介绍的immunarch 用的是自己写的代码(我是怎么知道的?看了源码呀),而另一个VDJ分析工具(scRepertoire)就直接用了vegen 。
所以,什么是Diversity ?
在生物学种,物种(替换为克隆型)丰富度(Species Richness,s)是一个相对的术语,指的是群落(组织)中物种的数量,它直接关系到某一地区物种多样性的测量。一个相关的术语,均匀性(evenness ,E),是多样性的另一个方面,它定义了同一地区每个物种的个体数量。这些术语一起被用来描述地球上的物种多样性(diversity )模式。
在下面的分析中,我们可以看到许多生态学中的概念和指标。在新版的《数量生态学:R语言应用》中新增第八章专门讲了群落多样性,可以参考。很多分析不过是换个矩阵,当年为什么要学生态学,原来在这等着我呢。
在immunarch中有更丰富的多样性指标和方便的统计方法。在repDiversity函数中实现了对曲目多样性估计的几种方法。与上述函数相似的。method参数设置了多样性估计的方法。你可以选择以下方法之一:
-
Chao1
estimator is a nonparameteric asymptotic estimator of species richness (number of species in a population). -
Hill
numbers are a mathematically unified family of diversity indices (differing only by an exponent q). -
div
- True diversity, or the effective number of types, refers to the number of equally-abundant types needed for the average proportional abundance of the types to equal that observed in the dataset of interest where all types may not be equally abundant. -
gini.simp
- The Gini-Simpson index is the probability of interspecific encounter, i.e., probability that two entities represent different types. -
inv.simp
- Inverse Simpson index is the effective number of types that is obtained when the weighted arithmetic mean is used to quantify average proportional abundance of types in the dataset of interest. -
gini
- The Gini coefficient measures the inequality among values of a frequency distribution (for example levels of income). A Gini coefficient of zero expresses perfect equality, where all values are the same (for example, where everyone has the same income). A Gini coefficient of one (or 100 percents ) expresses maximal inequality among values (for example where only one person has all the income). -
raref
- Rarefaction is a technique to assess species richness from the results of sampling through extrapolation.
我们同样载入R包和数据:
library(immunarch); data(immdata) # Load the package and the test dataset
?repDiversity
div_div <- repDiversity(immdata$data, "inv.simp")
div_div
Sample Value
1 A2-i129 795.1269
2 A2-i131 1271.0224
3 A2-i133 425.6711
4 A2-i132 3435.5682
5 A4-i191 191.2722
6 A4-i192 525.2406
7 MS1 140.5916
8 MS2 1816.6960
9 MS3 141.6550
10 MS4 4504.9258
11 MS5 135.1877
12 MS6 3809.8502
下面我们用vegna计算一下来做个比较:
library(vegan)
ve_inv <- diversity(immdata$data$`A2-i129`$Clones,"inv")
ve_inv
797.5846
names(immdata$data)
[1] "A2-i129" "A2-i131" "A2-i133" "A2-i132" "A4-i191" "A4-i192" "MS1" "MS2" "MS3" "MS4" "MS5" "MS6"
ve_inv = unlist(lapply(1:length(names(immdata$data)), FUN = function(x ){diversity(immdata$data[[x]]$Clones,"inv")}))
cor(div_div$Value,ve_inv)
[1] 0.9986046
两种方法计算的inv.simp相关系数为0.9986046.
继续发挥immunarch 短平快的优势,快速统计和作图。
# Compute statistics and visualise them
# Chao1 diversity measure
div_chao <- repDiversity(immdata$data, "chao1")
# Hill numbers
div_hill <- repDiversity(immdata$data, "hill")
# D50
div_d50 <- repDiversity(immdata$data, "d50")
# Ecological diversity measure
div_div <- repDiversity(immdata$data, "div")
p1 <- vis(div_chao)
p2 <- vis(div_chao, .by = c("Status", "Sex"), .meta = immdata$meta)
p3 <- vis(div_hill, .by = c("Status", "Sex"), .meta = immdata$meta)
p4 <- vis(div_d50)
p5 <- vis(div_d50, .by = "Status", .meta = immdata$meta)
p6 <- vis(div_div)
p1 + p2
p3 + p6
p4 + p5
做过扩增子和生态的朋友对稀释曲线不应感到陌生:
imm_raref <- repDiversity(immdata$data, "raref", .verbose = F)
imm_raref[1:5,]
Size Q0.025 Mean Q0.975 Sample Type
1 0.02 0.02485373 0.02387968 0.02582681 A2-i129 interpolation
2 0.04 0.04849410 0.04689468 0.05009084 A2-i129 interpolation
3 0.06 0.07154025 0.06938140 0.07369409 A2-i129 interpolation
4 0.08 0.09416917 0.09148383 0.09684658 A2-i129 interpolation
5 0.10 0.11647440 0.11328184 0.11965546 A2-i129 interpolation
p1 <- vis(imm_raref)
p2 <- vis(imm_raref, .by = "Status", .meta = immdata$meta)
p1 + p2
repDiversity(immdata$data, "raref", .verbose = F) %>% vis(.log = TRUE)
VDJ 多样性是免疫组库分析的核心,本节我们引进生态学多样性的指标来刻画克隆型,为我们从总体上来看VDJ的状态。我们为什么要做多样性研究?还不是为了找出异质性吗。
下面的描述来自生物学的某个wiki,对我们研究VDJ不无启发意义。
以下是三种公认的生物物种多样性假说。它们包括:(1)异质性假说,(2)竞争假说,(3)捕食假说。
衡量多样性有三个主要原因:(1)衡量稳定性,以确定一个环境是否在退化,(2)比较两个或更多的环境,和(3)消除对广泛列表的需要(形成数据概览,即用一个多样性指标,说明了需要列举很多概念才能说清楚的东西)。多样性指数提供了一个群落组成的重要信息。这些指数不仅衡量了物种的丰富度,还考虑了物种的相对丰富度或均匀度。在测量物种多样性时,物种丰富度和均匀度必须同时考虑。此外,指数还提供了物种稀有度和共性的重要信息。
https://immunarch.com/articles/web_only/v6_diversity.html
https://en.wikibooks.org/wiki/Ecology/Species_Richness_and_Diversity