今天继续之前的hdWGCNA教程,做完了前面的模块分割、鉴定,该和各种traits相关起来啦。😂
rm(list = ls())
library(Seurat)
library(dplyr)
library(cowplot)
library(WGCNA)
library(hdWGCNA)
记得设置一下哦!~😂
theme_set(theme_cowplot())
set.seed(123)
enableWGCNAThreads(nThreads = 8)
我们把之前的数据加进来吧。😀
load('hdWGCNA_object.Rdata')
我们会用到函数ModuleTraitCorrelation将选定的变量与模块特征相关联。😘
可以使用的变量:👇
大家在这里记得转换类型,比如factor,numeric。😘
# convert sex to factor
seurat_obj$msex <- as.factor(seurat_obj$msex)
# convert age_death to numeric
seurat_obj$age_death <- as.numeric(seurat_obj$age_death)
# list of traits to correlate
cur_traits <- c('braaksc', 'pmi', 'msex', 'age_death', 'doublet_scores', 'nCount_RNA', 'nFeature_RNA', 'total_counts_mt')
seurat_obj <- ModuleTraitCorrelation(
seurat_obj,
features = 'hMEs',
traits = cur_traits,
group.by='cell_type'
)
# get the mt-correlation results
mt_cor <- GetModuleTraitCorrelation(seurat_obj)
names(mt_cor)

names(mt_cor$cor)

这里我们可以看一下模块和特征的具体相关性数值。🌟
head(mt_cor$cor$INH[,1:5])

来可视化一下吧,方法很多,包里也自带了相关性热图。😘
PlotModuleTraitCorrelation(
seurat_obj,
label = 'fdr',
label_symbol = 'stars',
text_size = 2,
text_digits = 2,
text_color = 'white',
high_color = '#EB3678',
mid_color = '#E2E2B6',
low_color = '#6EACDA',
plot_max = 0.2,
combine = T,
wgcna_name = 'tutorial'
)
