10X空间转录组数据分析之同型分数(细胞网络)和异型分数(临近网络)计算

hello,大家好,中秋结束了,不知道大家过的怎么样,假期结束了,我们又要开始工作了,今天我们来分享一个新的内容点,关于空间转录组的同型分数和异性分数计算,相对难一点,大家好好准备。

关于R包STutility,不知道大家了解多少,这个包有很多值得学习的功能,今天介绍的两个就是这个R包的功能,当然,还有值得注意的一点就是这个R包的线性降维采用的是NMF,关于NMF也分享了很多了,大家可以多看看,多多学习。

好了,开始我们今天的内容,当然,之前我们需要对空间转录组数据做一些基础的分析,包括降维聚类,差异富集,以及单细胞空间联合对空间数据进行注释等等,在这个基础上,我们来进行下面的分析。

第一部分:Homotypic score calculation (within-class neighborhood analysis)(相对简单一点)

To assess the extent of spatial clustering of spots within each class, a network approach was applied using the GetSpatNet function in STUtility(这个R包的网址在STUtility).The spot degree, ki, (i.e., the number of directly adjacent spots, which for Visium corresponds to a maximum spot degree of six(空间位点上一个点最多周围近邻6个spot)) for every spot i in the network was computed and thereafter(之后,此后) the network’s average degree, \overline{\text{k}}obs, was calculated as \overline{\text{k}} = 2L/N,where L and N, respectively, corresponds to the total number of edges and nodes (spots) in the network. In order to account for differences in network size, the average degree was computed for random networks where the spots’ classifications had been shuffled within each sample.Based on the network size in each sample, an average was calculated as
图片.png
where N is the number of permutations.A final score, \overline{\text{k}}δ, was thereafter computed as the difference between the observed and expected average degree and could thus inform to what extent the observed value exceeded what would be expected to be seen by chance.(当然,这里强调的是网络的边和点,边更重要一点,定义相似度的距离,很好的方法)。
图片.png

第二点,Heterotypic score calculation (between-class neighborhood analysis)

To quantify the neighboring class identities adjacent to each spot, the RegionNeighbors function from STUtility was applied.(这个我们在最后面分享一下代码),The number of times spots of one class was found adjacent to another class identity was thereafter summarized in an adjacency matrix, Aobs, with the dimensions N X N, where N equals the total number of unique classes(就是多少个细胞类型,得到的矩阵就是临近细胞类型多样性的矩阵)。矩阵中的对角线填充了与该类对应的邻居总数的信息。Since large classes tend to have a larger number of neighbors simply by chance, we corrected the number of class-class neighbors by computing a score and comparing it with what would be expected to see at random(类似于显著性检验).“预期”值是通过对每个样本中的点类身份进行混洗,然后构建邻接矩阵 Aexp 来生成的。 This process was then iterated for a total of 50 permutations, and the average and standard deviation was calculated for each position in the matrix across the iterations to produce the matrices Aμexp and Aδexp respectively.Ultimately, a z-score for each position in the matrix was calculated as AZ = (Aobs - Aμexp)/Aδexp,where positive values are interpreted as class-class relationships observed x standard deviations more often than expected by chance and vice versa.(也是很巧妙的构思,对于研究邻居多样性很有帮助).
图片.png

接下来我们看看Heterotypic score calculation (between-class neighborhood analysis)计算的代码

Sometimes it can be useful to extract the “neighborhood” of a set of spots. As an example, we show how this can be applied to find all the neighboring spots of any region of interest.
首先是我们之前处理好的空间转录组数据
library(STutility)
library(Seurat)
se = readRDS(spatialRDS)
FeatureOverlay(se, features = "seurat_clusters", sampleids = 1:2, ncols = 2)
图片.png
当然,我们这里没有进行单细胞空间联合分析,所以这里我们就以cluster的信息进行演示,真正运用的时候大家可以自行挑选区域,或者联合后得到的细胞类型。

1、Connected Spatial Network

Once you have defined a region of interest and you want to find all spots neighboring to this region you can use the RegionNeighbours function to automatically detect such spots.
se <- SetIdent(se, value = "seurat_clusters")
se <- RegionNeighbours(se, id = "2", verbose = TRUE)
The default behavior is to find all spots which are neighbors with the selected id but ignoring its label, therefore it will simply be called nbs_2 as in “neighbors to 2”. The output will be stored as a new column in the meta.data slot, and in this example will be called “nbs_2”. The neighborhood detection algorithm is applied to each section separately and can therefore be run on multiple sections at the same time.
FeatureOverlay(se, features = "nbs_2", ncols = 2, sampleids = 1:2, cols = c("red", "lightgray"), pt.size = 2)
图片.png
可以通过设置 keep.within.id = TRUE 来保留 id 组中的所有点。
se <- SetIdent(se, value = "seurat_clusters")
se <- RegionNeighbours(se, id = 2, keep.within.id = T, verbose = TRUE)
FeatureOverlay(se, features = "nbs_2", ncols = 2, sampleids = 1:2, cols = c("red", "lightgray"), pt.size = 2)
图片.png
Using these two sets of spots, we can run a DE analysis to check what genes are up-regulated outside the cluster border.
library(magrittr)
library(dplyr)

se <- SetIdent(se, value = "nbs_2")
nbs_2.markers <- FindMarkers(se, ident.1 = "2", ident.2 = "nbs_2")
nbs_2.markers$gene <- rownames(nbs_2.markers)
se.subset <- SubsetSTData(se, expression = nbs_2 %in% c("2", "nbs_2"))
sorted.marks <- nbs_2.markers %>% top_n(n = 40, wt = abs(avg_logFC))
sorted.marks <- sorted.marks[order(sorted.marks$avg_logFC, decreasing = T), ]
DoHeatmap(se.subset, features = sorted.marks$gene, group.colors = c("red", "lightgray"), disp.min = -2, disp.max = 2)
图片.png
From this DE-test we can for example see that the genes COX6C and FCGR3B genes are up-regulated inside the cluser whereas LGALS1 and CYBA genes are more highly expressed outisde the cluster border.
FeatureOverlay(se.subset, features = c("COX6C", "FCGR3B", "LGALS1", "CYBA"), pt.size = 2,  
               ncols = 2, cols = c("darkblue", "cyan", "yellow", "red", "darkred"))
图片.png
And lastly, if you want to keep the labels for the neighbors you can set keep.idents = TRUE and you can keep one label per identity for the neighboring spots, e.g. “label”_nb_to_2
se <- SetIdent(se, value = "seurat_clusters")
se <- RegionNeighbours(se, id = 2, keep.idents = TRUE, verbose = TRUE)
FeatureOverlay(se, features = "nbs_2", ncols = 2, sampleids = 1:2, pt.size = 2)
图片.png

这里还是要提醒大家,这里只是用cluster进行演示,真正的近邻分析应该是和单细胞进行联合后进行数据分析,大家多多留心。

生活很好,有你更好

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
禁止转载,如需转载请通过简信或评论联系作者。
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,098评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,213评论 2 380
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,960评论 0 336
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,519评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,512评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,533评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,914评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,574评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,804评论 1 296
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,563评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,644评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,350评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,933评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,908评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,146评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,847评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,361评论 2 342

推荐阅读更多精彩内容