好久没更了,今天写一下hdWGCNA
吧,单细胞和空间转录组都能用到的高级分析。🧐
rm(list = ls())
library(Seurat)
library(tidyverse)
library(cowplot)
library(patchwork)
library(WGCNA)
library(hdWGCNA)
记得设置一下哦。😘
theme_set(theme_cowplot())
set.seed(123)
enableWGCNAThreads(nThreads = 8)
seurat_obj <- readRDS('Zhou_2020.rds')
常规操作一下,这里不做具体介绍了,大家自己看seurat
的教程吧。😂
p <- DimPlot(seurat_obj,
group.by='cell_type',
label=T)
p
选择在至少5%
的细胞中表达的基因。🧬
seurat_obj <- SetupForWGCNA(
seurat_obj,
gene_select = "fraction",
fraction = 0.05,
wgcna_name = "tutorial"
)
seurat_obj <- MetacellsByGroups(
seurat_obj = seurat_obj,
group.by = c("cell_type", "Sample"),
reduction = 'harmony',
k = 25,
max_shared = 10,
ident.group = 'cell_type'
)
# normalize metacell
seurat_obj <- NormalizeMetacells(seurat_obj)
这里我们对示例数据集中的抑制性神经元
(inhibitory neuron (INH) cells
)进行共表达网络分析。🧐
seurat_obj <- SetDatExpr(
seurat_obj,
group_name = "INH",
group.by='cell_type',
assay = 'RNA',
slot = 'data'
)
seurat_obj <- TestSoftPowers(
seurat_obj,
networkType = 'signed'
)
plot_list <- PlotSoftPowers(seurat_obj)
wrap_plots(plot_list, ncol=2)
power_table <- GetPowerTable(seurat_obj)
head(power_table)
seurat_obj <- ConstructNetwork(
seurat_obj,
tom_name = 'INH'
)
可视化一下!~🫠
PlotDendrogram(seurat_obj, main='INH hdWGCNA Dendrogram')
seurat_obj <- ScaleData(seurat_obj, features=VariableFeatures(seurat_obj))
seurat_obj <- ModuleEigengenes(
seurat_obj,
group.by.vars="Sample"
)
ME
会存储为矩阵形式,其中行是细胞,列是模块。可以使用GetMEs
函数从Seurat
对象中提取,该函数默认检索hME
。😏
# harmonized module eigengenes:
hMEs <- GetMEs(seurat_obj)
# module eigengenes:
MEs <- GetMEs(seurat_obj, harmonized=FALSE)
seurat_obj <- ModuleConnectivity(
seurat_obj,
group.by = 'cell_type', group_name = 'INH'
)
重命名一下!~🙊
seurat_obj <- ResetModuleNames(
seurat_obj,
new_name = "INH-M"
)
可视化每个模块中按kME
排名的基因。🧬
p <- PlotKMEs(seurat_obj, ncol=5)
p
modules <- GetModules(seurat_obj) %>% subset(module != 'grey')
head(modules[,1:6])
hub_df <- GetHubGenes(seurat_obj, n_hubs = 10)
head(hub_df)
saveRDS(seurat_obj, file='hdWGCNA_object.rds')
最后祝大家早日不卷!~