Skip to content

Commit

Permalink
Merge pull request #33 from wikipathways/json_api
Browse files Browse the repository at this point in the history
Json api
  • Loading branch information
AlexanderPico authored Oct 12, 2023
2 parents 2bd93c4 + 1e4b37c commit d9a2540
Show file tree
Hide file tree
Showing 69 changed files with 998 additions and 387 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Authors@R: c(person("Egon", "Willighagen", role = c("aut","cre"),
email = "alex.pico@gladstone.ucsf.edu",
comment = c(ORCID = "0000-0001-5706-2163"))
)
Imports: httr, utils, XML, rjson, data.table, tidyr, RCurl
Imports: httr, utils, XML, rjson, data.table, tidyverse, RCurl, dplyr, tidyr, magrittr, readr, stringr
Suggests: testthat, BiocStyle, knitr, rmarkdown
Description: Use this package to interface with the WikiPathways API. It provides programmatic access to WikiPathways content in multiple data and image formats, including official monthly release files and convenient GMT read/write functions.
License: MIT + file LICENSE
Expand All @@ -20,4 +20,4 @@ LazyLoad: yes
biocViews: Visualization, GraphAndNetwork, ThirdPartyClient, Network, Metabolomics
NeedsCompilation: no
VignetteBuilder: knitr
RoxygenNote: 7.1.1
RoxygenNote: 7.2.3
16 changes: 13 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Generated by roxygen2: do not edit by hand

export(downloadPathwayArchive)
export(findPathwayIDsByOrcid)
export(findPathwayIdsByLiterature)
export(findPathwayIdsByText)
export(findPathwayIdsByXref)
export(findPathwayNamesByLiterature)
export(findPathwayNamesByOrcid)
export(findPathwayNamesByText)
export(findPathwayNamesByXref)
export(findPathwayUrlsByLiterature)
export(findPathwayUrlsByOrcid)
export(findPathwayUrlsByText)
export(findPathwayUrlsByXref)
export(findPathwaysByLiterature)
export(findPathwaysByOrcid)
export(findPathwaysByText)
export(findPathwaysByXref)
export(getCounts)
export(getCurationStatus)
export(getCurationTagNames)
export(getCurationTags)
export(getEveryCurationTag)
Expand All @@ -21,17 +27,22 @@ export(getOntologyTermNames)
export(getOntologyTerms)
export(getPathway)
export(getPathwayHistory)
export(getPathwayIdsByCommunity)
export(getPathwayIdsByCurationTag)
export(getPathwayIdsByOntologyTerm)
export(getPathwayIdsByParentOntologyTerm)
export(getPathwayInfo)
export(getPathwayNamesByCommunity)
export(getPathwayUrlsByCommunity)
export(getPathwaysByCommunity)
export(getPathwaysByCurationTag)
export(getPathwaysByOntologyTerm)
export(getPathwaysByParentOntologyTerm)
export(getRecentChanges)
export(getRecentChangesIds)
export(getRecentChangesNames)
export(getXrefList)
export(listCommunities)
export(listOrganisms)
export(listPathwayIds)
export(listPathwayNames)
Expand All @@ -43,15 +54,14 @@ export(readPathwayGMT)
export(wikipathwaysAPI)
export(wikipathwaysGET)
export(writeGMT)
import(dplyr)
importFrom(RCurl,getURL)
importFrom(XML,readHTMLTable)
importFrom(data.table,dcast)
importFrom(data.table,rbindlist)
importFrom(data.table,setDT)
importFrom(httr,GET)
importFrom(purrr,map_dfr)
importFrom(rjson,fromJSON)
importFrom(tidyr,separate)
importFrom(tidyr,unnest)
importFrom(utils,URLencode)
importFrom(utils,browseURL)
importFrom(utils,download.file)
Expand Down
19 changes: 19 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
Changes in version 1.22.0
+ Reimplementation of every function, replacing web service with static JSON
+ getRecentChanges now returns data.frame of pathways per last-edit date
+ findPathwaysByText has new param, "field" to optionally specify which fields to search
+ getPathwayHistory now opens pathway commit history in browser
+ getPathwayInfo now returns all pathways if param is left NULL
+ New functions:
- listCommunities
- getPathwaysByCommunity
- getPathwayXXXsByCommunity
- getCounts
- findPathwaysByOrcid
- getCurationStatus
+ Deprecated functions:
- getCurationTags
- getCurationTagNames
- getXXXByCurationTag
- wikipathwaysAPI
- wikipathwaysGET
Changes in version 1.17.1
+ doc fix: dplyr redundant, throws error
+ doc fix: specify rjson and lib packages in Rmd
Expand Down
4 changes: 2 additions & 2 deletions R/downloadPathwayArchive.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#' @examples \donttest{
#' downloadPathwayArchive() ## open in browser
#' downloadPathwayArchive(format="gmt") ## open in browser
#' downloadPathwayArchive(date="20171010", format="svg") ## open in browser
#' downloadPathwayArchive(date="20171010", organism="Mus musculus", format="svg") ## download file
#' downloadPathwayArchive(date="20230710", format="svg") ## open in browser
#' downloadPathwayArchive(date="20230710", organism="Mus musculus", format="svg") ## download file
#' downloadPathwayArchive(organism="Mus musculus") ## download file
#' }
#' @seealso readPathwayGMT
Expand Down
78 changes: 0 additions & 78 deletions R/findPathwayByText.R

This file was deleted.

66 changes: 25 additions & 41 deletions R/findPathwaysByLiterature.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,33 @@
#'
#' @description Retrieve pathways containing the query citation.
#' @param query The \code{character} string to search for, e.g., a PMID, title
#' keyword or author name.
#' @return A \code{dataframe} of pathway attributes in addition to query result
#' score and literature details
#' @details The score is from a lucene index search engine, ranging from 0 to
#' 1 with higher scores for better matches. The two literature columns are
#' lists of pubmed ids and titles for the citations matching the query per
#' pathway. The graphId column lists the id for any objects in the
#' GPML pathway model that have been spcifically annotated with the matching
#' citations.
#' keyword, journal abbreviation, year, or author name.
#' @return A \code{dataframe} of pathway attributes including the matching
#' citations
#' @examples {
#' findPathwaysByLiterature('19649250')
#' findPathwaysByLiterature('smith')
#' findPathwaysByLiterature('cancer')
#' findPathwaysByLiterature('15134803')
#' findPathwaysByLiterature('Schwartz GL')
#' findPathwaysByLiterature('Eur J Pharmacol')
#' findPathwaysByLiterature('antihypertensive drug responses')
#' }
#' @export
#' @importFrom tidyr unnest
#' @importFrom data.table dcast
#' @importFrom data.table setDT
findPathwaysByLiterature <- function(query) {
res <- wikipathwaysGET('findPathwaysByLiterature', list(query=query))
if(length(res$result) == 0){
#' @importFrom purrr map_dfr
findPathwaysByLiterature <- function(query=NULL) {
if(is.null(query))
stop("Must provide a query, e.g., 15134803 or Schwartz GL")

res <- rjson::fromJSON(file="https://www.wikipathways.org/json/findPathwaysByLiterature.json")
res.df <- res$pathwayInfo %>%
purrr::map_dfr(~as.data.frame(t(unlist(.x))))

res.df <- res.df %>%
rowwise() %>%
dplyr::filter(any(grepl(tolower(query),tolower(c_across(refs:citations)))))

if(nrow(res.df) == 0)
message("No results")
return(data.frame())
}
res.df <- suppressWarnings(data.table::rbindlist(res$result, fill = TRUE))
res.df$revision <- vapply(res.df$revision, as.integer, integer(1))
res.df$score <- vapply(res.df$score, function(s){
as.numeric(unlist(s))
}, numeric(1))
## reshape literature field
res.df.tall <- unnest(res.df, cols = c("fields"))
res.df.odd <- as.data.frame(res.df.tall)[c(TRUE,FALSE), ]
res.df.odd$fields <- vapply(res.df.odd$fields, unlist, character(1))
res.df.even <- as.data.frame(res.df.tall)[c(FALSE,TRUE), ]
res.df.even$fields <- sapply(res.df.even$fields, unlist) #can't use vapply: variable returns
row.names(res.df.odd) <- NULL
row.names(res.df.even) <- NULL
res.df.fields <- merge(res.df.even, res.df.odd[,2, drop = FALSE], by=0)
res.df.cast <- dcast(setDT(res.df.fields), score+id+name+url+species+revision~fields.y, value.var="fields.x")
return(res.df.cast)

return(as.data.frame(res.df))
}

# ------------------------------------------------------------------------------
Expand All @@ -60,7 +46,7 @@ findPathwaysByLiterature <- function(query) {
#' }
#' @seealso findPathwaysByLiterature
#' @export
findPathwayIdsByLiterature <- function(query) {
findPathwayIdsByLiterature <- function(query=NULL) {
res <- findPathwaysByLiterature(query)
return(res$id)
}
Expand All @@ -69,8 +55,6 @@ findPathwayIdsByLiterature <- function(query) {
#' @title Find Pathway Names By Literature
#'
#' @description Retrieve list of pathway names containing the query citation.
#' @details Note: there will be multiple listings of the same pathway name if
#' copies exist for multiple species.
#' @param query The \code{character} string to search for, e.g., a PMID, title
#' keyword or author name.
#' @return A \code{list} of lists
Expand All @@ -81,7 +65,7 @@ findPathwayIdsByLiterature <- function(query) {
#' }
#' @seealso findPathwaysByLiterature
#' @export
findPathwayNamesByLiterature <- function(query) {
findPathwayNamesByLiterature <- function(query=NULL) {
res <- findPathwaysByLiterature(query)
return(res$name)
}
Expand All @@ -100,7 +84,7 @@ findPathwayNamesByLiterature <- function(query) {
#' }
#' @seealso findPathwaysByLiterature
#' @export
findPathwayUrlsByLiterature <- function(query) {
findPathwayUrlsByLiterature <- function(query=NULL) {
res <- findPathwaysByLiterature(query)
return(res$url)
}
78 changes: 78 additions & 0 deletions R/findPathwaysByOrcid.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# ------------------------------------------------------------------------------
#' @title Find Pathways By ORCID
#'
#' @description Retrieve pathways containing the query ORCID
#' @param query The \code{character} ORCID to search for.
#' @return A \code{dataframe} of pathway attributes including the matching
#' ORCIDs
#' @examples {
#' findPathwaysByOrcid(' 0000-0001-9773-4008')
#' }
#' @export
#' @importFrom purrr map_dfr
#' @import dplyr
findPathwaysByOrcid <- function(query=NULL) {
if(is.null(query))
stop("Must provide an ORCID, e.g., 0000-0001-9773-4008")

res <- rjson::fromJSON(file="https://www.wikipathways.org/json/findPathwaysByOrcid.json")
res.df <- res$pathwayInfo %>%
purrr::map_dfr(~as.data.frame(t(unlist(.x))))

res.df <- res.df %>%
rowwise() %>%
dplyr::filter(grepl(tolower(query),tolower(orcids)))

if(nrow(res.df) == 0)
message("No results")

return(as.data.frame(res.df))
}

# ------------------------------------------------------------------------------
#' @title Find Pathway WPIDs By ORCID
#'
#' @description Retrieve list of pathway WPIDs containing the query ORCID
#' @param query The \code{character} ORCID to search for.
#' @return A \code{list} of WPIDs
#' @examples {
#' findPathwayIDsByOrcid(' 0000-0001-9773-4008')
#' }
#' @seealso findPathwaysByOrcid
#' @export
findPathwayIDsByOrcid <- function(query=NULL) {
res <- findPathwaysByOrcid(query)
return(res$id)
}

# ------------------------------------------------------------------------------
#' @title Find Pathway Names By ORCID
#'
#' @description Retrieve list of pathway names containing the query ORCID
#' @param query The \code{character} ORCID to search for.
#' @return A \code{list} of lists
#' @examples {
#' findPathwayNamesByOrcid(' 0000-0001-9773-4008')
#' }
#' @seealso findPathwaysByOrcid
#' @export
findPathwayNamesByOrcid <- function(query=NULL) {
res <- findPathwaysByOrcid(query)
return(res$name)
}

# ------------------------------------------------------------------------------
#' @title Find Pathway URLs By ORCID
#'
#' @description Retrieve list of pathway URLs containing the query ORCID
#' @param query The \code{character} ORCID to search for.
#' @return A \code{list} of lists
#' @examples {
#' findPathwayUrlsByOrcid(' 0000-0001-9773-4008')
#' }
#' @seealso findPathwaysByOrcid
#' @export
findPathwayUrlsByOrcid <- function(query=NULL) {
res <- findPathwaysByOrcid(query)
return(res$url)
}
Loading

0 comments on commit d9a2540

Please sign in to comment.