Skip to content

Commit d27ae96

Browse files
committed
stringdb
1 parent ac080e0 commit d27ae96

File tree

16 files changed

+433
-9
lines changed

16 files changed

+433
-9
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ TODO.md
1616
^.*\.Rproj$
1717
^\.Rproj\.user$
1818
graphic-abstract-The-Innovation-2021.jpg
19+
outdated

DESCRIPTION

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: clusterProfiler
22
Type: Package
33
Title: A universal enrichment tool for interpreting omics data
4-
Version: 4.9.0
4+
Version: 4.9.0.001
55
Authors@R: c(
66
person(given = "Guangchuang", family = "Yu", email = "[email protected]", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-6485-8781")),
77
person(given = "Li-Gen", family = "Wang", email = "[email protected]", role = "ctb"),
@@ -19,13 +19,18 @@ Depends:
1919
Imports:
2020
AnnotationDbi,
2121
downloader,
22+
digest,
2223
DOSE (>= 3.23.2),
2324
dplyr,
2425
enrichplot (>= 1.9.3),
26+
fs,
2527
GO.db,
2628
GOSemSim,
2729
gson (>= 0.0.7),
30+
httr,
31+
igraph,
2832
magrittr,
33+
memoise,
2934
methods,
3035
plyr,
3136
qvalue,

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ readme:
1515
Rscript -e 'rmarkdown::render("README.Rmd", rmarkdown::md_document(variant="gfm"), encoding="UTF-8")'
1616

1717
build:
18-
cd ..;\
19-
R CMD build $(PKGSRC)
18+
# cd ..;\
19+
# R CMD build $(PKGSRC)
20+
Rscript -e 'devtools::build()'
2021

2122
build2:
2223
cd ..;\
@@ -26,9 +27,10 @@ install:
2627
cd ..;\
2728
R CMD INSTALL $(PKGNAME)_$(PKGVERS).tar.gz
2829

29-
check: build
30-
cd ..;\
31-
Rscript -e 'rcmdcheck::rcmdcheck("$(PKGNAME)_$(PKGVERS).tar.gz")'
30+
check: #build
31+
#cd ..;\
32+
# Rscript -e 'rcmdcheck::rcmdcheck("$(PKGNAME)_$(PKGVERS).tar.gz")'
33+
Rscript -e 'devtools::check()'
3234

3335
check2: build
3436
cd ..;\

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export(enricher)
5757
export(filter)
5858
export(geneID)
5959
export(geneInCategory)
60+
export(getPPI)
61+
export(getTaxID)
62+
export(getTaxInfo)
6063
export(get_wp_organisms)
6164
export(go2ont)
6265
export(go2term)

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ TODO:
1111
-->
1212

1313

14+
# clusterProfiler 4.9.0.002
15+
16+
+ `getPPI()` to query PPI network from 'stringdb' (2023-05-15, Mon)
17+
+ `getTaxID()` and `getTaxInfo()` functions to query taxonomy information (2023-05-14, Sun)
18+
1419
# clusterProfiler 4.8.0
1520

1621
+ Bioconductor RELEASE_3_17 (2023-05-03, Wed)

R/data.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ NULL
2121

2222

2323

24+
2425
#' Datasets
2526
#' DE_GSE8057 contains differential epxressed genes obtained from GSE8057 dataset
2627
#'

R/enrichDAVID.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ enrichDAVID <- function(gene,
130130

131131
qobj <- tryCatch(qvalue(p=Over$pvalue, lambda=0.05, pi0.method="bootstrap"),
132132
error=function(e) NULL)
133-
if (class(qobj) == "qvalue") {
133+
if (inherits(qobj, "qvalue")) {
134134
qvalues <- qobj$qvalues
135135
} else {
136136
qvalues <- NA

R/enrichKEGG.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ viewKEGG <- function(obj, pathwayID, foldChange,
239239
kegg.native=TRUE,
240240
out.suffix="clusterProfiler") {
241241

242-
if (class(obj) != "enrichResult")
242+
if (!inherits(obj, "enrichResult"))
243243
stop("only enrichResult object supported.")
244244
if (obj@ontology != "KEGG")
245245
stop("only KEGG supported.")

R/ppi.R

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
getPPI_oldversion <- function(x, ID=1, taxID = "auto", limit = NULL, output = 'igraph') {
2+
output <- match.arg(output, c("igraph", "data.frame"))
3+
4+
if (taxID == "auto") {
5+
if (is.null(x@organism) || length(x@organism) == 0) {
6+
stop("Unable to determine taxonomy ID. You can use the `getTaxID()` to get the taxonomy ID from scientific species name.\n")
7+
}
8+
taxID <- getTaxID(x@organism)
9+
}
10+
11+
genes <- paste(unlist(geneInCategory(x)[x$ID[ID]]), collapse = "%0d")
12+
13+
if (is.null(limit)) {
14+
## only use the genes in interest
15+
interaction_type <- "network?identifiers="
16+
limit <- ""
17+
} else {
18+
## incorporate partner genes, size restricted by limit
19+
interaction_type <- "interaction_partners?identifiers="
20+
limit <- paste("&limit=",limit,sep = "")
21+
}
22+
23+
url <- paste0("https://string-db.org/api/json/",
24+
interaction_type, genes,
25+
"&species=", taxID,
26+
limit
27+
)
28+
29+
fromJSON <- yulab.utils::get_fun_from_pkg("jsonlite", 'fromJSON')
30+
res <- fromJSON(url)
31+
if (output == "data.frame") {
32+
return(res)
33+
}
34+
35+
node <- unique(c(res$preferredName_A, res$preferredName_B))
36+
37+
igraph::graph_from_data_frame(
38+
d = res[,c(3,4,6)],
39+
vertices = node,
40+
directed=F
41+
)
42+
}
43+
44+
45+
#' networkParamsParser
46+
#'
47+
#' parameters parser for [Getting the STRING network interactions](https://string-db.org/cgi/help.pl?sessionId=btsvnCeNrBk7).
48+
#'
49+
#' @param identifiers required parameter for multiple items, e.g. `c("PTCH1", "TP53", "BRCA1", "BRCA2")`
50+
#' @param species NCBI taxon identifiers (e.g. Human is 9606, see: [STRING organisms](https://string-db.org/cgi/input.pl?input_page_active_form=organisms).
51+
#' @param required_score threshold of significance to include a interaction, a number between 0 and 1000 (default depends on the network)
52+
#' @param network_type network type: functional (default), physical
53+
#' @param add_nodes adds a number of proteins with to the network based on their confidence score (default:1)
54+
#' @param show_query_node_labels when available use submitted names in the preferredName column when (0 or 1) (default:0)
55+
#' @param caller_identity your identifier for use.
56+
#'
57+
#' @noRd
58+
#' @return a list contain parameters for query
59+
networkParamsParser <- function(
60+
identifiers,
61+
species,
62+
required_score = NULL,
63+
network_type = "functional",
64+
add_nodes = 1,
65+
show_query_node_labels = 0,
66+
caller_identity = NULL
67+
) {
68+
# Format the identifiers
69+
identifiers <- paste(identifiers, collapse = "\n")
70+
71+
# Check parameters
72+
if (missing(species)) {
73+
stop("Please provide an NCBI taxon identifier for the species.")
74+
}
75+
76+
# Create parameters list
77+
params <- list(
78+
identifiers = identifiers,
79+
species = species,
80+
required_score = required_score,
81+
network_type = network_type,
82+
add_nodes = add_nodes,
83+
show_query_node_labels = show_query_node_labels,
84+
caller_identity = caller_identity
85+
)
86+
87+
# Remove NULL elements from the list
88+
filtered_params <- Filter(Negate(is.null), params)
89+
return(filtered_params)
90+
}
91+
92+
#' getPPI
93+
#'
94+
#' [Getting the STRING network interactions](https://string-db.org/cgi/help.pl?sessionId=btsvnCeNrBk7).
95+
#'
96+
#' @title getPPI
97+
#' @param x an `enrichResult`` object or a vector of proteins, e.g. `c("PTCH1", "TP53", "BRCA1", "BRCA2")`
98+
#' @param ID ID or index to extract genes in the enriched term(s) if `x` is an `enrichResult` object
99+
#' @param taxID NCBI taxon identifiers (e.g. Human is 9606, see: [STRING organisms](https://string-db.org/cgi/input.pl?input_page_active_form=organisms).
100+
#' @param required_score threshold of significance to include a interaction, a number between 0 and 1000 (default depends on the network)
101+
#' @param network_type network type: functional (default), physical
102+
#' @param add_nodes adds a number of proteins with to the network based on their confidence score (default:1)
103+
#' @param show_query_node_labels when available use submitted names in the preferredName column when (0 or 1) (default:0)
104+
#' @param output one of `data.frame` or `igraph`
105+
#' @author Yonghe Xia and modified by Guangchuang Yu
106+
#' @return a `data.frame` or an `igraph` object
107+
#' @export
108+
getPPI <- function(
109+
x,
110+
ID=1,
111+
taxID = "auto",
112+
required_score = NULL,
113+
network_type = "functional",
114+
add_nodes = 0,
115+
show_query_node_labels = 0,
116+
output = 'igraph') {
117+
118+
output <- match.arg(output, c("igraph", "data.frame"))
119+
if (taxID == "auto") {
120+
if (!inherits(x, 'enrichResult') || is.null(x@organism) || length(x@organism) == 0) {
121+
stop("Unable to determine taxonomy ID. You can use the `getTaxID()` to get the taxonomy ID from scientific species name.\n")
122+
}
123+
taxID <- getTaxID(x@organism)
124+
}
125+
if (inherits(x, 'enrichResult')) {
126+
if (is(ID, 'numeric')) {
127+
id <- x$ID[ID]
128+
} else {
129+
id <- ID
130+
}
131+
genes <- unlist(geneInCategory(x)[id])
132+
} else {
133+
genes <- x
134+
}
135+
136+
networkParams <- networkParamsParser(
137+
identifiers = genes,
138+
species = taxID,
139+
required_score = required_score,
140+
network_type = network_type,
141+
add_nodes = add_nodes,
142+
show_query_node_labels = show_query_node_labels
143+
)
144+
145+
# Set stringDB base URL
146+
address <- "https://string-db.org"
147+
148+
# Validate the address
149+
#
150+
httr::stop_for_status(httr::GET(address))
151+
152+
# read data from stringDB api
153+
response <- httr::GET(paste(address, "/api/tsv/network", sep = ""), query = networkParams)
154+
res <- read_tsv_with_cache(response$url, header = TRUE)
155+
156+
if (output == "data.frame") {
157+
return(res)
158+
}
159+
160+
node <- unique(c(res$preferredName_A, res$preferredName_B))
161+
162+
igraph::graph_from_data_frame(
163+
d = res[,c(3,4,6)],
164+
vertices = node,
165+
directed=F
166+
)
167+
}
168+

0 commit comments

Comments
 (0)