1
2
3
4
5
if (!require("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("STRINGdb")
library(STRINGdb)

1、定义要使用的STRING版本、物种,以及PPI阈值分数

1
2
3
4
string_db <- STRINGdb$new(version="11", 
                          species=9606,
                          score_threshold=200, 
                          input_directory="")

2、示例基因

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
data(diff_exp_example1)
genes = diff_exp_example1[1:50,]
head(genes)
#      pvalue    logFC         gene
# 1 0.0001018 3.333461       VSTM2L
# 2 0.0001392 3.822383       TBC1D2
# 3 0.0001720 3.306056        LENG9
# 4 0.0001739 3.024605       TMEM27
# 5 0.0001990 3.854414 LOC100506014
# 6 0.0002393 3.082052       TSPAN1

###基因名匹配protein ID
#第一个参数是data.frame; 第二个参数是基因所在列的列名
genes_mapped <- string_db$map(genes, "gene" )
#Warning:  we couldn't map to STRING 30% of your identifiers

head(genes_mapped)
#            gene    pvalue    logFC            STRING_id
# 1        VSTM2L 0.0001018 3.333461 9606.ENSP00000362560
# 2        TBC1D2 0.0001392 3.822383 9606.ENSP00000481721
# 3         LENG9 0.0001720 3.306056 9606.ENSP00000479355
# 4        TMEM27 0.0001739 3.024605 9606.ENSP00000369699
# 40 LOC100506014 0.0001990 3.854414                 <NA>
# 5        TSPAN1 0.0002393 3.082052 9606.ENSP00000361072

#string_db$plot_network(genes_mapped$STRING_id)

3、下载这些基因间的互作关系

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
ppi = string_db$get_interactions(genes_mapped$STRING_id) %>% distinct()
ppi = ppi %>% 
  dplyr::left_join(genes_mapped[,c(1,4)], by=c('from'='STRING_id')) %>% #列标序号根据具体情况而定
  dplyr::rename(Gene1=gene) %>% ##列名根据具体情况而定
  dplyr::left_join(genes_mapped[,c(1,4)], by=c('to'='STRING_id')) %>% 
  dplyr::rename(Gene2=gene) %>% 
  dplyr::select(Gene1, Gene2, combined_score)
head(ppi)
#      Gene1   Gene2 combined_score
# 1       C3  TYROBP            240
# 2   ABCA12   GRHL3            308
# 3 FAM189A1 TM4SF20            400
# 4   ABCA12  NIPAL4            824
# 5    GRHL3  NIPAL4            275
# 6    GRHL3  IGDCC4            238