R語言使用cgdsr包獲取TCGA數據示例詳解
TCGA數據源
眾所周知,TCGA數據庫是目前最綜合全面的癌癥病人相關組學數據庫,包括的測序數據有:
DNA Sequencing
miRNA Sequencing
Protein Expression
mRNA Sequencing
Total RNA Sequencing
Array-based Expression
DNA Methylation
Copy Number
TCGA數據庫探索工具
知名的腫瘤研究機構都有著自己的TCGA數據庫探索工具,比如:
Broad Institute FireBrowse portal, The Broad Institute
cBioPortal for Cancer Genomics, Memorial Sloan-Kettering Cancer Center
TCGA Batch Effects, MD Anderson Cancer Center
Regulome Explorer, Institute for Systems Biology
Next-Generation Clustered Heat Maps, MD Anderson Cancer Center
其中cBioPortal更是被包裝到R包裡面
這裡介紹如何使用R語言的cgdsr包來獲取任意TCGA數據。
cgdsr包:R語言工具包,可以下載TCGA數據。
DT包:data.table包,簡稱DT包,是R語言中的數據可視化工具包。DT包可以將Javascript中的方法運用到R中,也能將矩陣或者數據表在網頁中可視化為表格,以及其它的一些功能。
> setwd("C:/Users/YLAB/Documents/R/win-library/4.1/") > install.packages("R.methodsS3_1.8.1.zip",repos=NULL)#安裝 > install.packages("R.oo_1.24.0.zip",repos=NULL)#安裝 > install.packages("data.table") > BiocManager::install("cgdsr", force = TRUE)#安裝 > library(cgdsr) > library(DT) #創建一個cgdsr對象 > mycgds <- CGDS("http://www.cbioportal.org/") #檢查下載是否成功,如果是FAILED就是沒成功。 > test(mycgds) getCancerStudies... OK getCaseLists (1/2) ... OK getCaseLists (2/2) ... OK getGeneticProfiles (1/2) ... OK getGeneticProfiles (2/2) ... OK getClinicalData (1/1) ... OK getProfileData (1/6) ... OK getProfileData (2/6) ... OK getProfileData (3/6) ... OK getProfileData (4/6) ... OK getProfileData (5/6) ... OK getProfileData (6/6) ... OK all_TCGA_studies <- getCancerStudies(mycgds) > DT::datatable(all_TCGA_studies)
查看任意數據集的樣本列表方式
上表的cancer_study_id其實就是數據集的名字,我們任意選擇一個數據集,比如stad_tcga_pub ,可以查看它裡面有多少種樣本列表方式。
stad2014 <- "stad_tcga_pub" ## 獲取在stad2014數據集中有哪些表格(每個表格都是一個樣本列表) all_tables <- getCaseLists(mycgds, stad2014) dim(all_tables) ## 共6種樣本列表方式 [1] 6 5 DT::datatable(all_tables[,1:3])
查看任意數據集的數據形式
## 而後獲取可以下載哪幾種數據,一般是mutation,CNV和表達量數據 all_dataset <- getGeneticProfiles(mycgds, stad2014) DT::datatable(all_dataset, extensions = 'FixedColumns', options = list( #dom = 't', scrollX = TRUE, fixedColumns = TRUE ))
一般來說,TCGA的一個項目數據就幾種,如下:
選定數據形式及樣本列表後獲取感興趣基因的信息,下載mRNA數據
my_dataset <- 'stad_tcga_pub_rna_seq_v2_mrna' my_table <- "stad_tcga_pub_rna_seq_v2_mrna" BRCA1 <- getProfileData(mycgds, "BRCA1", my_dataset, my_table) dim(BRCA1) [1] 265 1
樣本個數差異很大,不同癌癥熱度不一樣。
選定樣本列表獲取臨床信息
## 如果我們需要繪制survival curve,那麼需要獲取clinical數據 clinicaldata <- getClinicalData(mycgds, my_table) DT::datatable(clinicaldata, extensions = 'FixedColumns', options = list( #dom = 't', scrollX = TRUE, fixedColumns = TRUE ))
綜合性獲取
隻需要根據癌癥列表選擇自己感興趣的研究數據集即可,然後選擇好感興趣的數據形式及對應的樣本量。就可以獲取對應的信息:
library(cgdsr) library(DT) mycgds <- CGDS("http://www.cbioportal.org") ##mycancerstudy = getCancerStudies(mycgds)[25,1] mycancerstudy = 'brca_tcga' getCaseLists(mycgds,mycancerstudy)[,1] ## [1] "brca_tcga_3way_complete" "brca_tcga_all" ## [3] "brca_tcga_protein_quantification" "brca_tcga_sequenced" ## [5] "brca_tcga_cna" "brca_tcga_methylation_hm27" ## [7] "brca_tcga_methylation_hm450" "brca_tcga_mrna" ## [9] "brca_tcga_rna_seq_v2_mrna" "brca_tcga_rppa" ## [11] "brca_tcga_cnaseq"
getGeneticProfiles(mycgds,mycancerstudy)[,1] ## [1] "brca_tcga_rppa" ## [2] "brca_tcga_rppa_Zscores" ## [3] "brca_tcga_protein_quantification" ## [4] "brca_tcga_protein_quantification_zscores" ## [5] "brca_tcga_gistic" ## [6] "brca_tcga_mrna" ## [7] "brca_tcga_mrna_median_Zscores" ## [8] "brca_tcga_rna_seq_v2_mrna" ## [9] "brca_tcga_rna_seq_v2_mrna_median_Zscores" ## [10] "brca_tcga_linear_CNA" ## [11] "brca_tcga_methylation_hm450" ## [12] "brca_tcga_mutations"
下載mRNA數據
mycaselist ='brca_tcga_rna_seq_v2_mrna' mygeneticprofile = 'brca_tcga_rna_seq_v2_mrna' # Get data slices for a specified list of genes, genetic profile and case list expr=getProfileData(mycgds,c('BRCA1','BRCA2'),mygeneticprofile,mycaselist) DT::datatable(expr)
很簡單就得到瞭指定基因在指定癌癥的表達量
獲取病例列表的臨床數據
myclinicaldata = getClinicalData(mycgds,mycaselist) DT::datatable(myclinicaldata, extensions = 'FixedColumns', options = list( #dom = 't', scrollX = TRUE, fixedColumns = TRUE )) ## Warning in instance$preRenderHook(instance): It seems your data is too ## big for client-side DataTables. You may consider server-side processing: ## http://rstudio.github.io/DT/server.html
從cBioPortal下載點突變信息
#突變基因名稱集合 mutGene=c("EGFR", "PTEN", "TP53", "ATRX") #檢索基因和遺傳圖譜的基因組圖譜數據 mut_df <- getProfileData(mycgds, caseList ="gbm_tcga_sequenced", geneticProfile = "gbm_tcga_mutations", genes = mutGene ) mut_df <- apply(mut_df,2,as.factor) mut_df[mut_df == "NaN"] = "" mut_df[is.na(mut_df)] = "" mut_df[mut_df != ''] = "MUT" DT::datatable(mut_df)
從cBioPortal下載拷貝數變異數據
mutGene=c("TP53","UGT2B7","CYP3A4") cna<-getProfileData(mycgds,mutGene,"gbm_tcga_gistic","gbm_tcga_sequenced") cna<-apply(cna,2,function(x) as.character(factor(x,levels = c(-2:2),labels = c("HOMDEL","HETLOSS","DIPLOID","GAIN","AMP")))) cna[is.na(cna)]="" cna[cna=="DIPLOID"]="" DT::datatable(cna)
把拷貝數及點突變信息結合畫熱圖
下面的函數,主要是配色比較復雜,其實原理很簡單,就是一個熱圖。
library(ComplexHeatmap) library(grid) conb <- data.frame(matrix(paste(as.matrix(cna),as.matrix(mut_df),sep = ";"), nrow=nrow(cna),ncol=ncol(cna), dimnames=list(row.names(mut_df),colnames(cna)))) mat <- as.matrix(t(conb)) DT::datatable((mat)) alt <- apply(mat,1,function(x)strsplit(x,";")) alt <- unique(unlist(alt)) alt <- alt[which(alt !="")] alt <-c("background",alt) alter_fun = list( background = function(x,y,w,h){ grid.rect(x,y,w-unit(0.5,"mm"),h-unit(0.5,"mm"), gp=gpar(fill="#CCCCCC",col=NA)) }, HOMDEL = function(x,y,w,h){ grid.rect(x,y,w-unit(0.5,"mm"),h-unit(0.5,"mm"), gp=gpar(fill="blue3",col=NA)) }, HETLOSS = function(x,y,w,h){ grid.rect(x,y,w-unit(0.5,"mm"),h-unit(0.5,"mm"), gp=gpar(fill="cadetblue1",col=NA)) }, GAIN = function(x,y,w,h){ grid.rect(x,y,w-unit(0.5,"mm"),h-unit(0.5,"mm"), gp=gpar(fill="pink",col=NA)) }, AMP = function(x,y,w,h){ grid.rect(x,y,w-unit(0.5,"mm"),h-unit(0.5,"mm"), gp=gpar(fill="red",col=NA)) }, MUT = function(x,y,w,h){ grid.rect(x,y,w-unit(0.5,"mm"),h-unit(0.5,"mm"), gp=gpar(fill="#008000",col=NA)) }) col <- c("MUT"="#008000","AMP"="red","HOMDEL"="blue3", "HETLOSS"="cadetblue1","GAIN"="pink") alt = intersect(names(alter_fun),alt) alt_fun_list <- alter_fun[alt] col <- col[alt] oncoPrint(mat=mat,alter_fun = alt_fun_list, get_type = function(x) strsplit(x,";")[[1]], col = col)
以上就是R語言使用cgdsr包獲取TCGA數據示例詳解的詳細內容,更多關於R語言cgdsr獲取TCGA數據的資料請關註WalkonNet其它相關文章!
推薦閱讀:
- R語言ComplexHeatmap繪制復雜熱圖heatmap
- ComplexHeatmap繪制單個熱圖
- python 中的@property的用法詳解
- 使用R語言繪制散點圖結合邊際分佈圖教程
- R包ggtreeExtra繪制進化樹