復(fù)現(xiàn):純R代碼實現(xiàn)ssGSEA算法評估腫瘤免疫浸潤程度

最近學習了生信菜鳥團的純R代碼實現(xiàn)ssGSEA算法評估腫瘤免疫浸潤程度,想復(fù)制作者的流程猿挚,但是發(fā)現(xiàn)了幾個不一樣的地方,所以重新整理流程驶鹉,代碼主要來自原作者Juan_NF绩蜻。

文章來源:Local mutational diversity drives intratumoral immune heterogeneity in non-small cell lung cancer
方法來源:
Pan-cancer Immunogenomic Analyses Reveal Genotype-Immunophenotype Relationships and Predictors of Response to Checkpoint Blockade
研究背景:方法基于使用metagenes,即代表特定免疫細胞亞群的非重疊基因組室埋,并且既不在CRC細胞系中也不在正常組織中表達办绝。然后使用這些組的metagenes的表達來使用基因集富集分析(GSEA)分析統(tǒng)計富集。優(yōu)點是該方法的穩(wěn)健性姚淆,這是由于兩個特征:
(1)使用一組基因而不是代表一個免疫亞群的單個基因孕蝉,因為使用單個基因作為免疫亞群的標記可以是誤導(dǎo)因為許多基因在不同的細胞類型中表達;
(2)評估一組基因相對于樣品中所有其他基因表達的相對表達變化。
為28個免疫細胞亞群定義了一組泛癌癥腌逢,并將分析擴展到實體癌癥降淮。對具有> 8,000個腫瘤樣品的20個實體癌癥的TCGA數(shù)據(jù)進行了免疫原性表征,并提供了腫瘤內(nèi)免疫浸潤的細胞組成的全面視圖搏讶。此外骤肛,還得出了癌癥抗原以及個體樣本的遺傳特征(腫瘤異質(zhì)性和克隆性)纳本,以便能夠?qū)γ庖咛卣饕约澳[瘤的遺傳特征進行綜合分析。開發(fā)了數(shù)據(jù)庫TCIA(癌癥免疫組圖譜)腋颠。基于反卷積方法識別免疫亞群的分數(shù)(CIBERSORT;
紐曼等人吓笙,2015年)在TCIA網(wǎng)站上提供了GSEA和反卷積數(shù)據(jù)淑玫。

1.提取矩陣和表型信息,需要手動從GEO下載

下載GSE112996_merged_fpkm_table.txt.gz
GSE112996_series_matrix.txt.gz面睛,這兩個文件絮蒿,對
GSE112996_series_matrix.txt.gz進行解壓,把這兩個文件放到Rproject創(chuàng)建的文件夾叁鉴。

rm(list=ls())
a <- read.table('GSE112996_merged_fpkm_table.txt.gz',
                header = T,
                row.names=1)
raw_data<- a[,-1]
###表型信息提取
pheno <- read.csv(file = 'GSE112996_series_matrix.txt')
pheno <- data.frame(num1 = strsplit(as.character(pheno[42,]),split='\t')[[1]][-1],
                    num2 = gsub('patient: No.','P',strsplit(as.character(pheno[51,]),split='\t')[[1]][-1]))

{
####數(shù)據(jù)過濾
data<- a[!apply(raw_data,1,sum)==0,]
####去除重復(fù)基因名的行土涝,歸一化
data$median=apply(data[,-1],1,median)
data=data[order(data$GeneName,data$median,decreasing = T),]
data=data[!duplicated(data$GeneName),]
rownames(data)=data$GeneName
uni_matrix <- data[,grep('\\d+',colnames(data))]
uni_matrix <- log2(uni_matrix+1)
colnames(uni_matrix)<- gsub('X','',gsub('\\.','\\-',colnames(uni_matrix)))
uni_matrix<- uni_matrix[,order(colnames(uni_matrix))]
}
save(uni_matrix,pheno,file = 'uni_matrix.Rdata')

2.進行ssGSEA分析

只是用到了處理后的矩陣和基因集兩個內(nèi)容;對score結(jié)果歸一化后進行熱圖繪制幌墓。
獲取免疫細胞的metagenes基因集,得到一個名為mmc3.xlsx的文件但壮,刪除前兩行,保存為mmc3.csv常侣。

##加載包
{
library(genefilter)
library(GSVA)
library(Biobase)
library(stringr)
}
##載入數(shù)據(jù)
load('uni_matrix.Rdata')
gene_set<-read.csv("mmc3.csv")[, 1:2]
head(gene_set)
list<- split(as.matrix(gene_set)[,1], gene_set[,2])
gsva_matrix<- gsva(as.matrix(uni_matrix), list,method='ssgsea',kcdf='Gaussian',abs.ranking=TRUE)
library(pheatmap)
gsva_matrix1<- t(scale(t(gsva_matrix)))
gsva_matrix1[gsva_matrix1< -2] <- -2
gsva_matrix1[gsva_matrix1>2] <- 2
anti_tumor <- c('Activated CD4 T cell', 'Activated CD8 T cell', 'Central memory CD4 T cell', 'Central memory CD8 T cell', 'Effector memeory CD4 T cell', 'Effector memeory CD8 T cell', 'Type 1 T helper cell', 'Type 17 T helper cell', 'Activated dendritic cell', 'CD56bright natural killer cell', 'Natural killer cell', 'Natural killer T cell')
pro_tumor <- c('Regulatory T cell', 'Type 2 T helper cell', 'CD56dim natural killer cell', 'Immature dendritic cell', 'Macrophage', 'MDSC', 'Neutrophil', 'Plasmacytoid dendritic cell')
anti<- gsub('^ ','',rownames(gsva_matrix1))%in%anti_tumor
pro<- gsub('^ ','',rownames(gsva_matrix1))%in%pro_tumor
non <- !(anti|pro)
gsva_matrix1<- rbind(gsva_matrix1[anti,],gsva_matrix1[pro,],gsva_matrix1[non,])
normalization<-function(x){
  return((x-min(x))/(max(x)-min(x)))}
nor_gsva_matrix1 <- normalization(gsva_matrix1)
annotation_col = data.frame(patient=pheno$num2)
rownames(annotation_col)<-colnames(uni_matrix)
bk = unique(c(seq(0,1, length=100)))
pheatmap(nor_gsva_matrix1,
         show_colnames = F,
         cluster_rows = F,cluster_cols = F,
         annotation_col = annotation_col,
         breaks=bk,cellwidth=5,cellheight=5,
         fontsize=5,gaps_row = c(12,20),
         filename = 'ssgsea.pdf',width = 8)
save(gsva_matrix,gsva_matrix1,pheno,file = 'score.Rdata')
圖1

3.計算score加和后蜡饵,ggplot2進行繪圖

rm(list=ls())
anti_tumor <- c('Activated CD4 T cell', 'Activated CD8 T cell', 'Central memory CD4 T cell', 'Central memory CD8 T cell', 'Effector memeory CD4 T cell', 'Effector memeory CD8 T cell', 'Type 1 T helper cell', 'Type 17 T helper cell', 'Activated dendritic cell', 'CD56bright natural killer cell', 'Natural killer cell', 'Natural killer T cell')
pro_tumor <- c('Regulatory T cell', 'Type 2 T helper cell', 'CD56dim natural killer cell', 'Immature dendritic cell', 'Macrophage', 'MDSC', 'Neutrophil', 'Plasmacytoid dendritic cell')
load('score.Rdata')
anti<- as.data.frame(gsva_matrix1[gsub('^ ','',rownames(gsva_matrix1))%in%anti_tumor,])
pro<- as.data.frame(gsva_matrix1[gsub('^ ','',rownames(gsva_matrix1))%in%pro_tumor,])
anti_n<- apply(anti,2,sum)
pro_n<- apply(pro,2,sum)
patient <- pheno$num2[match(colnames(gsva_matrix1),pheno$num1)]
library(ggplot2)
data <- data.frame(anti=anti_n,pro=pro_n,patient=patient)
anti_pro<- cor.test(anti_n,pro_n,method='pearson')
gg<- ggplot(data,aes(x = anti, y = pro),color=patient) + 
  xlim(-20,15)+ylim(-15,10)+
  labs(x="Anti-tumor immunity", y="Pro-tumor suppression") +
  geom_point(aes(color=patient),size=3)+geom_smooth(method='lm')+
  annotate("text", x = -5, y =7.5,label=paste0('R=',round(anti_pro$estimate,4),'\n','p<0.001'))
ggsave(gg,filename = 'cor.pdf', height = 6, width = 8)
圖2

文章原圖

基本一致,但是細節(jié)之處需要調(diào)節(jié)胳施,不當之處請指正溯祸!

參考文獻:

  1. 純R代碼實現(xiàn)ssGSEA算法評估腫瘤免疫浸潤程度
  2. Pan-cancer Immunogenomic Analyses Reveal Genotype-Immunophenotype Relationships and Predictors of Response to Checkpoint Blockade
  3. Local mutational diversity drives intratumoral immune heterogeneity in non-small cell lung cancer

生信技能樹公益視頻合輯:學習順序是linux,r舞肆,軟件安裝焦辅,geo,小技巧椿胯,ngs組學筷登!
B站鏈接
YouTube鏈接
生信工程師入門最佳指南
學徒培養(yǎng)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市压状,隨后出現(xiàn)的幾起案子仆抵,更是在濱河造成了極大的恐慌,老刑警劉巖种冬,帶你破解...
    沈念sama閱讀 218,682評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件镣丑,死亡現(xiàn)場離奇詭異,居然都是意外死亡娱两,警方通過查閱死者的電腦和手機莺匠,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來十兢,“玉大人趣竣,你說我怎么就攤上這事摇庙。” “怎么了遥缕?”我有些...
    開封第一講書人閱讀 165,083評論 0 355
  • 文/不壞的土叔 我叫張陵卫袒,是天一觀的道長。 經(jīng)常有香客問我单匣,道長夕凝,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,763評論 1 295
  • 正文 為了忘掉前任户秤,我火速辦了婚禮码秉,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘鸡号。我一直安慰自己转砖,他們只是感情好,可當我...
    茶點故事閱讀 67,785評論 6 392
  • 文/花漫 我一把揭開白布鲸伴。 她就那樣靜靜地躺著府蔗,像睡著了一般。 火紅的嫁衣襯著肌膚如雪挑围。 梳的紋絲不亂的頭發(fā)上礁竞,一...
    開封第一講書人閱讀 51,624評論 1 305
  • 那天,我揣著相機與錄音杉辙,去河邊找鬼模捂。 笑死,一個胖子當著我的面吹牛蜘矢,可吹牛的內(nèi)容都是我干的狂男。 我是一名探鬼主播,決...
    沈念sama閱讀 40,358評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼品腹,長吁一口氣:“原來是場噩夢啊……” “哼岖食!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起舞吭,我...
    開封第一講書人閱讀 39,261評論 0 276
  • 序言:老撾萬榮一對情侶失蹤泡垃,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后羡鸥,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體蔑穴,經(jīng)...
    沈念sama閱讀 45,722評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年惧浴,在試婚紗的時候發(fā)現(xiàn)自己被綠了存和。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,030評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖捐腿,靈堂內(nèi)的尸體忽然破棺而出纵朋,到底是詐尸還是另有隱情,我是刑警寧澤茄袖,帶...
    沈念sama閱讀 35,737評論 5 346
  • 正文 年R本政府宣布操软,位于F島的核電站,受9級特大地震影響绞佩,放射性物質(zhì)發(fā)生泄漏寺鸥。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,360評論 3 330
  • 文/蒙蒙 一品山、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧烤低,春花似錦肘交、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,941評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至腻要,卻和暖如春复罐,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背雄家。 一陣腳步聲響...
    開封第一講書人閱讀 33,057評論 1 270
  • 我被黑心中介騙來泰國打工效诅, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人趟济。 一個月前我還...
    沈念sama閱讀 48,237評論 3 371
  • 正文 我出身青樓乱投,卻偏偏與公主長得像,于是被迫代替她去往敵國和親顷编。 傳聞我的和親對象是個殘疾皇子戚炫,可洞房花燭夜當晚...
    茶點故事閱讀 44,976評論 2 355

推薦閱讀更多精彩內(nèi)容