跳到正文
0%

GEO数据库的使用及数据分析(练习)

GEO数据链接:
https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE61763

#安装GEOquery package
> if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

> BiocManager::install("GEOquery")

> library(GEOquery)

因为GFW的原因,导致部分用户出现网络错误,进而导致不能下载数据,所以需要修改一下这个option

> options('download.file.method.GEOquery'='libcurl')
#开始下载GEO数据
> gse <- getGEO('GSE61763')

## Found 1 file(s)
GSE61763_series_matrix.txt.gz
试开URL’https://ftp.ncbi.nlm.nih.gov/geo/series/GSE61nnn/GSE61763/matrix/GSE61763_series_matrix.txt.gz'
 length 7625052 bytes (7.3 MB)
downloaded 7.3 MB


-- Column specification ------------------------------------------------------------------------------
cols(
  .default = col_double(),
  ID_REF = col_character()
)
i Use `spec()` for the full column specifications.

File stored at: 
C:\Users\lenovo\AppData\Local\Temp\RtmpABSroa/GPL19197.soft

查看下载的GSE数据

> head(gse)

$GSE61763_series_matrix.txt.gz
ExpressionSet (storageMode: lockedEnvironment)
assayData: 57176 features, 30 samples 
  element names: exprs 
protocolData: none
phenoData
  sampleNames: GSM1513596 GSM1513597 ... GSM1513625 (30 total)
  varLabels: title geo_accession ... tnm:ch1 (49 total)
  varMetadata: labelDescription
featureData
  featureNames: A_23_P100001 A_23_P100022 ... CUST_9_PI427704219 (57176 total)
  fvarLabels: ID GB_ACC ... Sequence (5 total)
  fvarMetadata: Column Description labelDescription
experimentData: use 'experimentData(object)'
  pubMedIds: 25685243 
Annotation: GPL19197 

提取表达矩阵

> gset <- gse[[1]]
> head(gset)

ExpressionSet (storageMode: lockedEnvironment)
assayData: 1 features, 30 samples 
  element names: exprs 
protocolData: none
phenoData
  sampleNames: GSM1513596 GSM1513597 ... GSM1513625 (30 total)
  varLabels: title geo_accession ... tnm:ch1 (49 total)
  varMetadata: labelDescription
featureData
  featureNames: A_23_P100001
  fvarLabels: ID GB_ACC ... Sequence (5 total)
  fvarMetadata: Column Description labelDescription
experimentData: use 'experimentData(object)'
  pubMedIds: 25685243 
Annotation: GPL19197 


#提取表型数据信息
> pdata <- pData(gset)

# 查看数据的维度,共30个样本数据,也就是15对
> dim(pdata)
[1] 30 49

#设定level
> group_list=c(rep(c('tumor','normal'),15))
> group_list <-factor(group_list) 
> group_list <- relevel(group_list, ref='tumor')
> group_list
 [1] tumor  normal tumor  normal tumor  normal tumor  normal
 [9] tumor  normal tumor  normal tumor  normal tumor  normal
[17] tumor  normal tumor  normal tumor  normal tumor  normal
[25] tumor  normal tumor  normal tumor  normal
Levels: tumor normal

# 通过exprs()函数获取表达矩阵
> exprSet <- exprs(gset)
> dim(exprSet)
[1] 57176    30

#boxplot查看整体样本的表达情况
> boxplot(exprSet,outline=FALSE,notch=T,col=group_list,las=2)

校正前

校正前的整体样本表达情况

整体表达不整齐,使用limma包内置函数人工校正

> library(limma)

载入程辑包:'limma'

The following object is masked from 'package:BiocGenerics':

    plotMA

> exprSet <- normalizeBetweenArrays(exprSet)
> boxplot(exprSet,outline=FALSE,notch=T,col=group_list,las=2)

校正后

校正后就感觉数据整体平整很多

表达量很大,log转换(选log2)

> ex <- exprSet
> qx <- as.numeric(quantile(ex, c(0., 0.25, 0.5, 0.75, 0.99, 1.0), na.rm=T))
> LogC <- (qx[5] > 100) ||
+ (qx[6]-qx[1] > 50 && qx[2] > 0) ||
+ (qx[2] > 0 && qx[2] < 1 && qx[4] > 1 && qx[4] < 2)

> if (LogC) { ex[which(ex <= 0)] <- NaN
+ exprSet <- log2(ex) }
> dim(exprSet)
[1] 57176    30

添加Annotation

> gpl<- getGEO('GPL19197',destdir = './')
File stored at: 
.//GPL19197.soft
> GPL19197 <- GEOquery::Table(gpl)
> probeset <- rownames(exprSet)
> probe2symbol <- data.frame(probeset,symbol=GPL19197$`Gene Symbol`,stringsAsFactors = F)
> dim(probe2symbol)
[1] 57176     2
> head(probe2symbol)
      probeset  symbol
1 A_23_P100001 FAM174B
2 A_23_P100022    SV2B
3 A_23_P100056  RBPMS2
4 A_23_P100074    AVEN
5 A_23_P100127   CASC5
6 A_23_P100141    UNKL

去除表达矩阵的一些缺失值

> library(dplyr)

载入程辑包:'dplyr'

> library(tibble)

载入程辑包:'tibble'

The following object is masked from 'package:ShortRead':

    view

> exprSet <- as.data.frame(exprSet)
> exprSet <- exprSet %>% 
+     rownames_to_column(var='probeset') %>% 
+     #合并探针的信息
+     inner_join(probe2symbol,by='probeset') %>% 
+     #去掉多余信息
+     select(-probeset) %>% 
+     #重新排列
+     select(symbol,everything()) %>% 
+     #求出平均数(这边的点号代表上一步产出的数据)
+     mutate(rowMean =rowMeans(.[grep('GSM', names(.))])) %>%
+     # #去除symbol中的NA 
+     filter(symbol != 'NA') %>% 
+     #把表达量的平均值按从大到小排序
+     arrange(desc(rowMean)) %>% 
+     # symbol留下第一个
+     distinct(symbol,.keep_all = T) %>%
+     #反向选择去除rowMean这一列 
+     select(-rowMean) %>% 
+     # 列名变成行名
+     column_to_rownames(var = 'symbol')
> exprSet <- na.omit(exprSet)
> dim(exprSet)
[1] 22723    30

PCA分析

> pcaData <- exprSet
> head(pcaData)
        GSM1513596 GSM1513597 GSM1513598 GSM1513599 GSM1513600
ZNF865    18.83438   18.74083   18.83438   18.83438   18.83438
RN28S1    18.74083   18.83438   18.74083   18.74083   18.74083
PQLC2     18.39928   18.59863   18.59863   18.59863   18.50781
GPR155    18.59863   18.32740   18.39928   18.32740   18.32740
          17.83468   18.22174   18.32740   18.22174   18.39928
FAM74A4   18.32740   17.89507   18.22174   18.05010   18.22174
        GSM1513601 GSM1513602 GSM1513603 GSM1513604 GSM1513605
ZNF865    18.74083   18.83438   18.74083   18.74083   18.74083
RN28S1    18.83438   18.74083   18.83438   18.83438   18.83438
PQLC2     18.50781   18.50781   18.50781   17.33055   18.59863
GPR155    18.22174   18.39928   18.22174   18.39928   18.32740
          18.13508   18.13508   18.32740   18.59863   18.39928
FAM74A4   17.67673   17.94982   18.00258   18.22174   18.05010
        GSM1513606 GSM1513607 GSM1513608 GSM1513609 GSM1513610
ZNF865    18.59863   18.83438   18.50781   18.83438   18.74083
RN28S1    18.74083   18.50781   18.39928   18.74083   18.83438
PQLC2     18.50781   18.59863   18.32740   18.22174   18.59863
GPR155    18.13508   18.39928   18.00258   18.50781   18.22174
          18.22174   18.32740   18.05010   18.05010   18.39928
FAM74A4   18.05010   18.00258   17.79035   18.39928   18.05010
        GSM1513611 GSM1513612 GSM1513613 GSM1513614 GSM1513615
ZNF865    18.74083   18.83438   18.74083   18.83438   18.83438
RN28S1    18.83438   18.50781   18.83438   18.74083   18.74083
PQLC2     18.50781   18.74083   18.05010   18.59863   18.50781
GPR155    18.32740   18.39928   18.50781   18.32740   18.39928
          18.39928   18.32740   18.39928   18.39928   18.13508
FAM74A4   18.13508   18.13508   18.32740   18.13508   18.22174
        GSM1513616 GSM1513617 GSM1513618 GSM1513619 GSM1513620
ZNF865    18.83438   18.83438   18.39928   18.83438   18.83438
RN28S1    18.50781   18.74083   18.59863   18.39928   18.50781
PQLC2     18.59863   18.59863   18.32740   18.59863   18.59863
GPR155    18.22174   18.39928   18.05010   18.50781   18.39928
          18.32740   18.32740   18.22174   18.32740   18.32740
FAM74A4   18.00258   18.22174   17.83468   18.13508   18.13508
        GSM1513621 GSM1513622 GSM1513623 GSM1513624 GSM1513625
ZNF865    18.74083   18.74083   18.74083   18.83438   18.50781
RN28S1    18.83438   18.83438   18.83438   18.50781   18.83438
PQLC2     18.13508   18.50781   18.50781   18.74083   18.22174
GPR155    18.50781   18.32740   18.32740   18.22174   18.32740
          18.39928   18.39928   18.39928   18.39928   18.59863
FAM74A4   18.32740   17.83468   18.22174   18.05010   18.00258

#将基因名和样品名进行转置
> pcaDataT <- as.data.frame(t(pcaData))
# 查看数据维度
> dim(pcaDataT)
[1]    30 22723

> head(pcaDataT)[,1:3]
             ZNF865   RN28S1    PQLC2
GSM1513596 18.83438 18.74083 18.39928
GSM1513597 18.74083 18.83438 18.59863
GSM1513598 18.83438 18.74083 18.59863
GSM1513599 18.83438 18.74083 18.59863
GSM1513600 18.83438 18.74083 18.50781
GSM1513601 18.74083 18.83438 18.50781

#将分类信息加上,方便后面作图时颜色来区分
> pcaDataTGroup <- cbind(pcaDataT,as.data.frame(group_list))
> dim(pcaDataTGroup)
[1]    30 22724
> head(pcaDataTGroup)[,22720:22724]
            GALNTL5 LOC647012 LOC339822     ODF1 group_list
GSM1513596 2.962558  2.368222  3.321705 3.150202      tumor
GSM1513597 3.524921  3.030981  3.647162 3.441140     normal
GSM1513598 2.515347  1.696235  2.649310 2.854849      tumor
GSM1513599 2.791733  1.647627  2.854849 3.157716     normal
GSM1513600 1.647627  2.861833  2.064990 2.649310      tumor
GSM1513601 3.030981  2.233265  2.875022 2.462675     normal

#使用R自带的prcomp()函数进行分析
> pca <- prcomp(pcaDataT,scale=TRUE)
# 查看一下汇总情况
> summary(pca)
Importance of components:
                           PC1     PC2      PC3      PC4
Standard deviation     69.7013 53.6954 41.59722 38.27877
Proportion of Variance  0.2138  0.1269  0.07615  0.06448
Cumulative Proportion   0.2138  0.3407  0.41684  0.48132
                            PC5      PC6      PC7      PC8
Standard deviation     34.27880 32.53043 29.90406 27.07682
Proportion of Variance  0.05171  0.04657  0.03935  0.03226
Cumulative Proportion   0.53303  0.57960  0.61896  0.65122
                            PC9     PC10     PC11    PC12
Standard deviation     26.73741 25.63509 24.28643 23.4961
Proportion of Variance  0.03146  0.02892  0.02596  0.0243
Cumulative Proportion   0.68268  0.71160  0.73756  0.7619
                           PC13     PC14     PC15     PC16
Standard deviation     22.54617 21.24446 20.90725 19.67930
Proportion of Variance  0.02237  0.01986  0.01924  0.01704
Cumulative Proportion   0.78423  0.80409  0.82333  0.84037
                           PC17     PC18     PC19     PC20
Standard deviation     19.62633 19.39049 18.81680 18.53608
Proportion of Variance  0.01695  0.01655  0.01558  0.01512
Cumulative Proportion   0.85732  0.87387  0.88945  0.90457
                           PC21     PC22     PC23     PC24
Standard deviation     17.27997 16.62282 16.24557 15.85570
Proportion of Variance  0.01314  0.01216  0.01161  0.01106
Cumulative Proportion   0.91771  0.92987  0.94149  0.95255
                           PC25     PC26     PC27     PC28
Standard deviation     15.68151 15.07915 14.48868 14.27492
Proportion of Variance  0.01082  0.01001  0.00924  0.00897
Cumulative Proportion   0.96337  0.97338  0.98262  0.99159
                           PC29      PC30
Standard deviation     13.82776 1.559e-13
Proportion of Variance  0.00841 0.000e+00
Cumulative Proportion   1.00000 1.000e+00


#查看一下数据结构
> str(pca)
List of 5
 $ sdev    : num [1:30] 69.7 53.7 41.6 38.3 34.3 ...
 $ rotation: num [1:22723, 1:30] 0.00525 -0.00221 0.00164 -0.00047 0.00375 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:22723] "ZNF865" "RN28S1" "PQLC2" "GPR155" ...
  .. ..$ : chr [1:30] "PC1" "PC2" "PC3" "PC4" ...
 $ center  : Named num [1:22723] 18.8 18.7 18.5 18.3 18.3 ...
  ..- attr(*, "names")= chr [1:22723] "ZNF865" "RN28S1" "PQLC2" "GPR155" ...
 $ scale   : Named num [1:22723] 0.113 0.144 0.268 0.134 0.159 ...
  ..- attr(*, "names")= chr [1:22723] "ZNF865" "RN28S1" "PQLC2" "GPR155" ...
 $ x       : num [1:30, 1:30] -70.3 68.8 -65.9 86.2 -49.5 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:30] "GSM1513596" "GSM1513597" "GSM1513598" "GSM1513599" ...
  .. ..$ : chr [1:30] "PC1" "PC2" "PC3" "PC4" ...
 - attr(*, "class")= chr "prcomp


#将PC1与PC2加进去
> data_pca <- cbind(pcaDataTGroup,pca$x[,1:2])
> head(data_pca)[,22720:22726]
            GALNTL5 LOC647012 LOC339822     ODF1 group_list
GSM1513596 2.962558  2.368222  3.321705 3.150202      tumor
GSM1513597 3.524921  3.030981  3.647162 3.441140     normal
GSM1513598 2.515347  1.696235  2.649310 2.854849      tumor
GSM1513599 2.791733  1.647627  2.854849 3.157716     normal
GSM1513600 1.647627  2.861833  2.064990 2.649310      tumor
GSM1513601 3.030981  2.233265  2.875022 2.462675     normal
                 PC1        PC2
GSM1513596 -70.29442 -106.21949
GSM1513597  68.78575  -50.57325
GSM1513598 -65.90130  -80.09775
GSM1513599  86.22612  -76.48759
GSM1513600 -49.48738  -93.12600
GSM1513601  56.59620   14.35318


> ggplot(data_pca,aes(PC1,PC2,col=group_list,fill=group_list))+
+     stat_ellipse(geom="polygon",col="black",alpha=0.5)+
+     geom_point(shape=21,col="black",size=1.2)+
+     theme(panel.background = element_rect(fill="transparent",color="black"),
+           panel.grid.minor = element_blank(), 
+           panel.grid.major = element_blank())

PCA

PCA(Principal components analysis)

差异基因分析

> pairinfo <- factor(c(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15))
> pairinfo
 [1] 1  1  2  2  3  3  4  4  5  5  6  6  7  7  8  8  9  9  10
[20] 10 11 11 12 12 13 13 14 14 15 15
Levels: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
> design <- model.matrix(~ pairinfo+group_list)
> fit <- lmFit(exprSet,design)
#使用经验贝叶斯算法计算差异表达基因的显著性
> fit <- eBayes(fit)
#使用“FDR校正”
> allDiff_pair <- topTable(fit,adjust='fdr',coef=1,n = Inf,p.value = 0.05)

使用pheatmap()绘制Heatmap

> library(pheatmap)
> allDiff_pair2 <- topTable(fit,adjust='fdr',coef=1,number=Inf,p.value=0.05,lfc = 1) 
> heatdata <- exprSet[rownames(allDiff_pair2),]
> heat <- na.omit(heatdata)
> annotation_col <- data.frame(group_list)
> rownames(annotation_col) <- colnames(heatdata)
> pheatmap(heat, 
+          cluster_rows = TRUE,
+          cluster_cols = TRUE,
+          annotation_col =annotation_col, 
+          annotation_legend=TRUE, 
+          show_rownames = F,
+          show_colnames = T,
+          scale = 'row', 
+          color =colorRampPalette(c('blue', 'white','red'))(100))

火山图绘制

> library(ggplot2)
> library(ggrepel)
> library(dplyr)
> data <- topTable(fit,adjust='fdr',coef=1,number=Inf) 
> data$significant <- as.factor(data$adj.P.Val<0.05 & abs(data$logFC) > 0.6) #以logFC=1.5为界
> data$gene <- rownames(data)

#ggplot画图
> ggplot(data=data, aes(x=logFC, y =-log10(adj.P.Val),color=significant)) +
+     geom_point(alpha=0.8, size=1.2,col='black')+
+     geom_point(data=subset(data, logFC > 1),alpha=0.8, size=1.2,col='red')+
+     geom_point(data=subset(data, logFC < -1),alpha=0.6, size=1.2,col='blue')+
+     labs(x='log2 (fold change)',y='-log10 (adj.P.Val)')+
+     theme(plot.title = element_text(hjust = 0.4))+
+     geom_hline(yintercept = -log10(0.05),lty=4,lwd=0.6,alpha=0.8)+
+     geom_vline(xintercept = c(1,-1),lty=4,lwd=0.6,alpha=0.8)+
+     theme_bw()+
+     theme(panel.border = element_blank(),
+           panel.grid.major = element_blank(), 
+           panel.grid.minor = element_blank(),   
+           axis.line = element_line(colour = 'black'))

感觉这个火山图变成这个样子有些奇怪,怀疑是数据原因本身造成的

围绕这篇笔记交流

公开反馈按文章归档,滚动到这里后加载。

在 GitHub 查看反馈