TCGA 01 TCGAbiolinks下载转录组数据差异分析

1. 准备

安装和导入TCGAbiolinks包

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("TCGAbiolinks")

library(TCGAbiolinks)
library(dplyr)
library(DT)

查看各个癌种的项目id,总共有65个ID值

getGDCprojects()$project_id
# [1] "GENIE-MSK"             "TCGA-UCEC"             "TCGA-ACC"             
# [4] "TCGA-LGG"              "TCGA-SARC"             "TCGA-PAAD"            
# [7] "TCGA-ESCA"             "TCGA-LUAD"             "TCGA-PRAD"            
# [10] "GENIE-VICC"            "TCGA-LAML"             "TCGA-KIRC"            
# [13] "TCGA-COAD"             "TCGA-PCPG"             "TCGA-HNSC"            
# [16] "BEATAML1.0-COHORT"     "BEATAML1.0-CRENOLANIB" "GENIE-JHU"            
# [19] "MMRF-COMMPASS"         "TCGA-LUSC"             "TCGA-OV"              
# [22] "TCGA-GBM"              "TCGA-UCS"              "WCDT-MCRPC"           
# [25] "TCGA-MESO"             "TCGA-TGCT"             "TCGA-KICH"            
# [28] "TCGA-READ"             "TCGA-UVM"              "TCGA-STAD"            
# [31] "TCGA-THCA"             "OHSU-CNL"              "GENIE-DFCI"           
# [34] "GENIE-NKI"             "ORGANOID-PANCREATIC"   "VAREPOP-APOLLO"       
# [37] "GENIE-GRCC"            "FM-AD"                 "TARGET-ALL-P1"        
# [40] "TARGET-ALL-P2"         "TARGET-ALL-P3"         "TARGET-RT"            
# [43] "CTSP-DLBCL1"           "GENIE-UHN"             "GENIE-MDA"            
# [46] "TARGET-AML"            "TARGET-NBL"            "TARGET-WT"            
# [49] "NCICCR-DLBCL"          "TCGA-LIHC"             "TCGA-THYM"            
# [52] "TCGA-CHOL"             "TCGA-SKCM"             "TARGET-CCSK"          
# [55] "TARGET-OS"             "TCGA-DLBC"             "TCGA-CESC"            
# [58] "TCGA-BRCA"             "TCGA-KIRP"             "TCGA-BLCA"            
# [61] "CGCI-HTMCP-CC"         "HCMI-CMDC"             "CGCI-BLGSP"           
# [64] "CPTAC-2"               "CPTAC-3" 

查看project中有哪些数据类型,如查询"TCGA-LUAD",有7种数据类型,case_count为病人数,file_count为对应的文件数,file_size为总文件大小,若要下载表达谱,可以设置参数data.category="Transcriptome Profiling"

TCGAbiolinks:::getProjectSummary("TCGA-LUAD")
# $case_count
# [1] 585
# 
# $file_count
# [1] 18162
# 
# $file_size
# [1] 2.304064e+13
# 
# $data_categories
#   case_count file_count               data_category
# 1        519       2916     Transcriptome Profiling
# 2        569       5368 Simple Nucleotide Variation
# 3        585       2731                 Biospecimen
# 4        585        623                    Clinical
# 5        579        657             DNA Methylation
# 6        518       3383       Copy Number Variation
# 7        582       2484            Sequencing Reads

2. 下载LUAD肺腺癌的转录组数据

建立查询

query <- GDCquery(project = "TCGA-LUAD",
                  data.category = "Transcriptome Profiling",
                  data.type = "Gene Expression Quantification", 
                  workflow.type = "HTSeq - Counts")

查看所有样本编号

# 594个barcode
samplesDown <- getResults(query,cols=c("cases"))

从结果中筛选出肿瘤样本barcode:TP(primary solid tumor)

# 533个barcode
dataSmTP <- TCGAquery_SampleTypes(barcode = samplesDown,
                                  typesample = "TP")

从结果中筛选出NT(正常组织)样本的barcode:NT()

# 59个barcode
dataSmNT <- TCGAquery_SampleTypes(barcode = samplesDown,
                                  typesample = "NT")

还有2个复发的样本barcode:NR(Recurrent Solid Tumor)

# 2个barcode
dataSmTR <- TCGAquery_SampleTypes(barcode = samplesDown,
                                  typesample = "TR")

重新按照样本分组建立查询

queryDown <- GDCquery(project = "TCGA-LUAD", 
                      data.category = "Transcriptome Profiling",
                      data.type = "Gene Expression Quantification", 
                      workflow.type = "HTSeq - Counts", 
                      barcode = c(dataSmTP, dataSmNT)
                      )

下载查询到的数据,默认存放位置为当前工作目录下的GDCdata文件夹中

GDCdownload(query = queryDown, files.per.chunk=6, method ="api", 
            directory ="lung_cancer")

3. 数据读入与预处理

读取下载的数据并将其准备到R对象中,在工作目录生成luad_case.rda文件,同时还产生Human_genes__GRCh38_p12_.rda文件(project文件)

dataPrep1 <- GDCprepare(query = queryDown, save = TRUE, 
                        save.filename = "luad_cases.rda", 
                        directory ="lung_cancer")
# Starting to add information to samples
# => Add clinical information to samples
# => Adding TCGA molecular information from marker papers
# => Information will have prefix 'paper_' 
# luad subtype information from:doi:10.1038/nature13385
# Accessing www.ensembl.org to get gene information
# Downloading genome information (try:0) Using: Human genes (GRCh38.p13)
# From the 60483 genes we couldn't map 3990(不能mapping则自动删除该基因)
# 去除dataPrep1中的异常值,dataPrep数据中含有肿瘤组织和正常组织的数据

# save(dataPrep1, file="dataPrep1_LUAD_TP_TN.RData")
rm(list=ls())
load("dataPrep1_LUAD_TP_TN.RData")

TCGAanalyze_Preprocessing执行不同样本表达矩阵之间相关性(Array Array Intensity correlation,AAIC)分析。根据样本之间Spearman相关系数的平方对称矩阵和箱线图,找到具有低相关性的样本,这些样本可以被识别为可能的异常值。使用spearman相关系数去除数据中的异常值,一般设置阈值为0.6。在该次分析中无异常样本

# 无样本被删除
dataPrep <- TCGAanalyze_Preprocessing(object = dataPrep1, 
                                      cor.cut = 0.6,
                                      datatype = "HTSeq - Counts",
                                      filename = "AAIC.png")

将数据进行标准化使得不同样本之间具有可比性,使用包含EDASeq包功能的TCGAanalyze_Normalization函数,将mRNA标准化,此功能实现泳道内归一化程序,以针对GC含量效应(或其他基因水平的效应):全局缩放和分位数归一化。

dataNorm.luad <- TCGAanalyze_Normalization(tabDF = dataPrep,
                                           geneInfo = geneInfo,
                                           method = "gcContent")

使用TCGAanalyze_Filtering对低表达量的mRNA进行过滤,method = "quantile"时为筛选出所有样本中均值小于所有样本中rowMeans qnt.cut = 0.25的分位数(默认为25%的分位数)基因,即只保留表达量为前75%的基因。参考:The filtering of low-expression genes of RNA-seq data

dataFilt <- TCGAanalyze_Filtering(tabDF = dataNorm.luad,
                                  method = "quantile", 
                                  qnt.cut =  0.25)
save(dataFilt, file="dataFilt.RData")
load("dataFilt.RData")

4. 分组及差异分析

选择NT组的前10和TP组的前10个样本进行差异分析

# selection of normal samples "NT"
samplesNT <- TCGAquery_SampleTypes(barcode = colnames(dataFilt),
                                   typesample = c("NT"))
# selection of tumor samples "TP"
samplesTP <- TCGAquery_SampleTypes(barcode = colnames(dataFilt), 
                                   typesample = c("TP"))
# Diff.expr.analysis (DEA)
dataDEGs <- TCGAanalyze_DEA(mat1 = dataFilt[,samplesNT[1:10]],
                            mat2 = dataFilt[,samplesTP[1:10]],
                            Cond1type = "Normal",
                            Cond2type = "Tumor",
#                            fdr.cut = 0.01 ,
#                            logFC.cut = 1,
                            method = "glmLRT")
# Batch correction skipped since no factors provided
# ----------------------- DEA -------------------------------
#   there are Cond1 type Normal in  10 samples
# there are Cond2 type Tumor in  10 samples
# there are  12980 features as miRNA or genes 
# I Need about  8.7 seconds for this DEA. [Processing 30k elements /s]  
# ----------------------- END DEA -------------------------------

DEG.LUAD.edgeR <- TCGAanalyze_DEA(mat1 = dataFilt[,samplesNT[1:10]],
                                  mat2 = dataFilt[,samplesTP[1:10]],
                                  pipeline="edgeR",
                                  batch.factors = c("TSS"),
                                  Cond1type = "Normal",
                                  Cond2type = "Tumor",
                                  voom =FALSE, 
                                  method = "glmLRT",
                                  # fdr.cut = 0.01,  #保留FDR<0.01的基因
                                  # logFC.cut = 1 #保留logFC>1的基因
)
# ----------------------- DEA -------------------------------
#   there are Cond1 type Normal in  10 samples
# there are Cond2 type Tumor in  10 samples
# there are  12980 features as miRNA or genes 
# I Need about  8.7 seconds for this DEA. [Processing 30k elements /s]  
# ----------------------- END DEA -------------------------------

5. 绘制火山图和热图

火山图绘制

valcano_data <- data.frame(genes=rownames(DEG.LUAD.edgeR), 
                           logFC=DEG.LUAD.edgeR$logFC, 
                           FDR=DEG.LUAD.edgeR$FDR,
                           group=rep("NotSignificant", 
                                     nrow(DEG.LUAD.edgeR)),
                           stringsAsFactors = F)

valcano_data[which(valcano_data['FDR'] < 0.05 & 
                     valcano_data['logFC'] > 1.5),"group"] <- "Increased"
valcano_data[which(valcano_data['FDR'] < 0.05 &
                     valcano_data['logFC'] < -1.5),"group"] <- "Decreased"

cols = c("darkgrey","#00B2FF","orange")
names(cols) = c("NotSignificant","Increased","Decreased")

library(ggplot2)
ggplot(valcano_data, aes(x = logFC, y = -log10(FDR), color = group))+
  scale_colour_manual(values = cols) +
  ggtitle(label = "Volcano Plot", subtitle = "LUAD 10 samples volcano plot") +
  geom_point(size = 2.5, alpha = 1, na.rm = T) +
  theme_bw(base_size = 14) + 
  theme(legend.position = "right") + 
  xlab(expression(log[2]("logFC"))) + 
  ylab(expression(-log[10]("FDR"))) +
  geom_hline(yintercept = 1.30102, colour="#990000", linetype="dashed") + 
  geom_vline(xintercept = 1.5849, colour="#990000", linetype="dashed") + 
  geom_vline(xintercept = -1.5849, colour="#990000", linetype="dashed")+ 
  scale_y_continuous(trans = "log1p")

火山图

在火山图中标注特定基因如CALCA和MUC5B基因为红色

valcano_data_specific_genes = valcano_data[which(valcano_data$genes %in% 
                                          c("CALCA", "MUC5B")), ]

cols = c("darkgrey","#00B2FF","orange", "red")
names(cols) = c("NotSignificant","Increased","Decreased", "Specific")

library(ggplot2)
ggplot(valcano_data, aes(x = logFC, y = -log10(FDR), color = group))+
  scale_colour_manual(values = cols) +
  ggtitle(label = "Volcano Plot", subtitle = "LUAD 10 samples volcano plot") +
  geom_point(size = 2.5, alpha = 1, na.rm = T) +
  theme_bw(base_size = 14) + 
  theme(legend.position = "right") + 
  xlab(expression(log[2]("logFC"))) + 
  ylab(expression(-log[10]("FDR"))) +
  geom_hline(yintercept = 1.30102, colour="#990000", linetype="dashed") + 
  geom_vline(xintercept = 1.5849, colour="#990000", linetype="dashed") + 
  geom_vline(xintercept = -1.5849, colour="#990000", linetype="dashed")+ 
  scale_y_continuous(trans = "log1p") + 
  geom_point(data=valcano_data_specific_genes, col="red", size=2)
火山图——带标注

合并平均表达量与差异基因表格(方便查询)

#获取肿瘤组织对应的表达矩阵
dataTP <- dataFilt[,samplesTP[1:10]]

#获取正常组织对应的表达矩阵
dataTN <- dataFilt[,samplesNT[1:10]]

# 合并表格,增加2组每个基因的平均表达量
dataDEGsFiltLevel <- TCGAanalyze_LevelTab(FC_FDR_table_mRNA=dataDEGsFilt,
                                          typeCond1="Normal",
                                          typeCond2="Tumor", 
                                          TableCond1=dataTN,
                                          TableCond2=dataTP)
#查看结果
head(dataDEGsFiltLevel,2)
# mRNA     logFC         FDR   Normal    Tumor     Delta
# SFTPC   SFTPC -9.656391 0.001493513 850460.0  76090.8 8212374.1
# SFTPA2 SFTPA2 -1.755048 0.277785397 521998.4 154404.7  916132.2
# CALCA CALCA   5.803164    0.2678382   22.8    9511.5  132.3121
# MUC5B MUC5B   5.2703226   1.827029e-03    2722.7  49155.1 14349.507227

热图绘制

library(pheatmap)
t <- dataFilt[valcano_data$genes[which(valcano_data['FDR'] < 0.05 & 
                            abs(valcano_data['logFC']) >1.5)],
              c(samplesTP[1:10], samplesNT[1:10])]

t <- na.omit(t)
t <- log2(t+1)
col <- data.frame(Type=c(rep("Tumor", 10), rep("Normal", 10)))
col$Type <- factor(col$Type, levels = c("Normal", "Tumor"))
rownames(col) <- colnames(t)
pheatmap(t,
         annotation_col = col,
         annotation_colors = list(Type=c(Tumor="red", Normal="#00B2FF")),
         annotation_legend = T,
         border_color = "black",
         cluster_rows = T,
         cluster_cols = T,
         show_colnames = F,
         show_rownames = F,
         color = colorRampPalette(c("green", "black", "red"))(50))
热图
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,406评论 5 475
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,976评论 2 379
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,302评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,366评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,372评论 5 363
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,457评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,872评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,521评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,717评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,523评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,590评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,299评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,859评论 3 306
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,883评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,127评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,760评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,290评论 2 342