基因互作图pheatmap/corrplot

分析目的
组间gene-gene correlation宏观比较,对差异较大的cluster可做进一步分析,挑选出互作变化较大的gene

示例

Progressive plasticity during colorectal cancer metastasis (2024.Nature)


image.png

代码及结果展示

1.#这里只选取想要展示cluster的top gene
 top50_test <- read.table('./2.3_cluster_diff_top50.csv',header=TRUE,sep=',') %>% dplyr::filter(cluster %in%  c('1','3','4','5','8')) %>% dplyr::group_by(cluster) %>% dplyr::slice_head(n=50)  %>% pull(gene)

2.#选取不同组的cells 
OMEN_cells <- subset(scdata2, subset = sample_id %in%  c("OMEN","PRI"))
PP_cells <- subset(scdata2, subset = sample_id %in%  c("POL","POD"))

3.#选取不同组cells的top gene
OMEN_expression <- GetAssayData(OMEN_cells, slot = "counts")[top50_test, ]
PP_expression <- GetAssayData(PP_cells, slot = "counts")[top50_test, ]

4.#表达量变矩阵并计算相关系数
cor_OM <- OMEN_expression %>% as.matrix() %>% t() %>% cor(use = "complete.obs")
cor_PP <- PP_expression %>% as.matrix() %>% t() %>% cor(use = "complete.obs")

5.#变换下半部分的值
cor_OM_PP <- cor_OM

cor_OM_PP[lower.tri(cor_OM_PP)]  <- cor_PP[lower.tri(cor_PP)] #upper is OM
cor_OM_PP[is.na(cor_OM_PP)] <- 0

6.#作图
pdf('./1.pheatmap_OM_PP.pdf')
pheatmap(cor_OM_PP,
           cluster_cols = F,
           cluster_rows = F,
           color = colorRampPalette(c("blue", "white", "red"))(100),
           show_rownames = F,
           show_colnames = F,
         na.rm=TRUE,
         main = "OMEN and PRI vs. POD and POL"
#           annotation_col = top_anno
)
dev.off()

如果发现两组差异较大,可再详细展示

step 1-4同上,得到cor_OM和cor_PP
5.作图
hunt_line <- c(100:130,251,252) ##挑选感兴趣的基因

pdf('./2.C4_OM_corrplot.pdf',width=15,height=15)
corrplot(cor_OM[hunt_line,hunt_line],
         method = 'circle',
         type='upper',
         diag = FALSE,
         bg='white',
         tl.col='black',
         tl.cex=1,
         tl.pos = 'td',
#        title = "C4- OMEN and PRI",
         col = colorRampPalette(c("blue", "white", "red"))(100)
)
dev.off()
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容