-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path02getOpenTargetsData.R
More file actions
73 lines (59 loc) · 3.47 KB
/
02getOpenTargetsData.R
File metadata and controls
73 lines (59 loc) · 3.47 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
library(data.table)
library(httr)
library(jsonlite)
library(foreach)
library(doParallel)
registerDoParallel(parallel::detectCores() - 1)
# options
# permissive
min.drugs.score <- -Inf
min.degs.score <- -Inf
## strict
#min.drugs.score <- 0.5
#min.degs.score <- 0.2
# read STOPGAP data to get EFO IDs for diseases
stopgap <- fread("../dat/stopgap.tsv")
## query the Open Targets API to get all known drugs for each disease
# get token
token <- content(GET("https://www.targetvalidation.org/api/latest/public/auth/request_token", query = list(app_name = "personal", secret = "8r88SQNM2A2nayCd47rSWVTh7x5DSw47")))$token
# diseases to process
efo.ids <- unique(stopgap[, efo.id])
## drugs
# loop thorugh diseases
opentargets.drugs <- foreach(i = seq(efo.ids), .combine = rbind) %dopar% {
# query API
tmp <- GET("https://www.targetvalidation.org/api/latest/public/evidence/filter", query = list(disease = efo.ids[i], datatype = "known_drug", scorevalue_min = min.drugs.score, size = 10000), add_headers(`Auth-Token` = token))
# check response and request new token if necessary
if (tmp$status_code == 419) {
token <- content(GET("https://www.targetvalidation.org/api/latest/public/auth/request_token", query = list(app_name = "personal", secret = "8r88SQNM2A2nayCd47rSWVTh7x5DSw47")))$token
tmp <- GET("https://www.targetvalidation.org/api/latest/public/evidence/filter", query = list(disease = efo.ids[i], datatype = "known_drug", scorevalue_min = min.drugs.score, size = 10000), add_headers(`Auth-Token` = token))
}
# extract and check data
tmp <- fromJSON(content(tmp, type = "text", encoding = "UTF-8"))
if (length(tmp$data) > 0) {
tmp <- unique(as.data.table(flatten(tmp$data)))
tmp[, chembl.id := sub("http://identifiers.org/chembl.compound/", "", drug.id)]
tmp <- tmp[, .(efo.id = disease.id, efo.term = disease.efo_info.label, chembl.id, chembl.name = drug.molecule_name, chembl.type = drug.molecule_type, phase = drug.max_phase_for_all_diseases.numeric_index)]
}
}
# export
fwrite(opentargets.drugs, "../dat/opentargets.drugs.tsv", sep = "\t")
## DEGs
# loop thorugh diseases
opentargets.degs <- foreach(i = seq(efo.ids), .combine = rbind) %dopar% {
# query API
tmp <- GET("https://www.targetvalidation.org/api/latest/public/evidence/filter", query = list(disease = efo.ids[i], datatype = "rna_expression", scorevalue_min = min.degs.score, size = 10000), add_headers(`Auth-Token` = token))
# check response and request new token if necessary
if (tmp$status_code == 419) {
token <- content(GET("https://www.targetvalidation.org/api/latest/public/auth/request_token", query = list(app_name = "personal", secret = "8r88SQNM2A2nayCd47rSWVTh7x5DSw47")))$token
tmp <- GET("https://www.targetvalidation.org/api/latest/public/evidence/filter", query = list(disease = efo.ids[i], datatype = "rna_expression", scorevalue_min = min.degs.score, size = 10000), add_headers(`Auth-Token` = token))
}
# extract and check data
tmp <- fromJSON(content(tmp, type = "text", encoding = "UTF-8"))
if (length(tmp$data) > 0) {
tmp <- unique(as.data.table(flatten(tmp$data)))
tmp <- tmp[, .(efo.id = disease.id, efo.term = disease.efo_info.label, ensembl.id = target.id, gene.symbol = target.gene_info.symbol, comparison = evidence.comparison_name, lfc = evidence.log2_fold_change.value, pval = evidence.resource_score.value)]
}
}
# export
fwrite(opentargets.degs, "../dat/opentargets.degs.tsv", sep = "\t")