Commit 082970b7 authored by Marek Ostaszewski's avatar Marek Ostaszewski
Browse files

Update API_find_drug_targets.R

parent 06577b80
......@@ -33,3 +33,37 @@ map_hits <- sapply(aspirin_targets$targets[[1]]$targetElements, nrow) > 0
### Extract HGNC symbols from the 'targetParticipants' part of the results
aspirin_map_hgncs <- sapply(aspirin_targets$targets[[1]]$targetParticipants[map_hits],
function(x) x[,"resource"])
### Query for the drugs targetting given
### Uniprot identifiers
#Define UniProt identifiers to be matched in model elements
uniprot_examples <- c("Q92793", "P16220")
### Request identifiers of models for a given project (main map and submaps)
models <- ask_GET(base_url, "models/")
models <- fromJSON(models, flatten = F)
### For each model, retrieve elements with columns including references
model_elements <- lapply(models$idObject,
function(x) fromJSON(ask_GET(paste0(base_url,"models/",x,"/"),
"bioEntities/elements/?columns=id,name,type,references"),
flatten = F))
### For results in each model, find element identifiers that have the selected uniprot id
identifiers <- c()
for (m in 1:length(model_elements)) {
### In "resources" of each element, find those which have requested UniProt identifiers
hits <- sapply(model_elements[[m]]$references,
function(x) any(uniprot_examples %in% x$resource[x$type == "UNIPROT"]))
### Identifiers of the elements matching the search criteria
identifiers <- c(identifiers, unlist(model_elements[[m]]$id[hits]))
}
### For each identifier, request fo its drug targets, select 'name' from results
drugs <- sapply(identifiers,
function(x) fromJSON(ask_GET(base_url,paste0("drugs:search?target=ALIAS:", x)))$name)
### Display unique results
unique(drugs)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment