Skip to content

Commit

Permalink
bug fix #3 and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderPico committed Sep 9, 2018
1 parent c4495a8 commit afcccba
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 42 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ LazyLoad: yes
biocViews: Visualization, GraphAndNetwork, ThirdPartyClient, Network, Metabolomics
NeedsCompilation: no
VignetteBuilder: knitr
RoxygenNote: 6.0.1
RoxygenNote: 6.1.0
40 changes: 25 additions & 15 deletions R/downloadPathwayArchive.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
#' @title Download Pathway Archive
#'
#' @description Access the monthly archives of pathway content from WikiPathways.
#' @details If you specify an archive date, organism and format, then the archive file
#' will be downloaded. Otherwise, the archive will be opened in a tab in your
#' @details If you do not specify an organism, then an archive file
#' will not be downloaded. Rather, the archive will be opened in a tab in your
#' default browser.
#' @param date (optional) The timestamp for a monthly release (e.g., 20171010)
#' or "current" (default) for latest release.
#' @param organism (optional) A particular species. See \link{listOrganisms}.
#' @param format (optional) Either gpml (default), gmt or svg.
#' @return Downloaded file or tab in default browser
#' @param destpath (optional) Destination path for file to be downloaded to.
#' Default is current workding directory.
#' @return Filename of downloaded file or an opened tab in default browser
#' @examples \donttest{
#' downloadPathwayArchive()
#' downloadPathwayArchive(format="gmt")
#' downloadPathwayArchive(date="20171010", format="svg")
#' downloadPathwayArchive(date="20171010", organism="Mus musculus", format="svg")
#' 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(organism="Mus musculus") ## download file
#' }
#' @export
#' @importFrom utils browseURL download.file
downloadPathwayArchive <- function(date='current',organism = NULL, format=c('gpml', 'gmt', 'svg')){
downloadPathwayArchive <- function(date='current',organism=NULL, format=c('gpml', 'gmt', 'svg'), destpath='./'){
#get validated format
format <- match.arg(format)

Expand All @@ -34,14 +37,21 @@ downloadPathwayArchive <- function(date='current',organism = NULL, format=c('gpm
stop('The organism must match the list of supported organisms, see listOrganisms()')

#download specific file, or...
if (!is.null(organism) && date != 'current'){
ext <- ".zip"
if (format == 'gmt')
ext <- ".gmt"
filename <- paste0(paste('wikipathways',date,format,sub("\\s","_",organism),sep="-"), ext)
if (!is.null(organism)){
if (date == 'current'){ #determine filename
curr.files <- readHTMLTable(paste0('http://data.wikipathways.org/current/',format))[[1]]$Filename
filename <- grep(sub("\\s","_",organism), curr.files, value=TRUE)
if (length(filename) == 0)
stop ('Could not find a file matching your specifications. Try browsing http://data.wikipathways.org.')
} else { #construct filename
ext <- ".zip"
if (format == 'gmt')
ext <- ".gmt"
filename <- paste0(paste('wikipathways',date,format,sub("\\s","_",organism),sep="-"), ext)
}
url <- paste('http://data.wikipathways.org',date, format, filename, sep="/")
download.file(url, filename, 'wget')

download.file(url, paste(destpath,filename,sep='/'), 'auto')
return(filename)
} else { #...just open browser
browseURL(paste('http://data.wikipathways.org',date, format ,sep="/"))
}
Expand Down
20 changes: 12 additions & 8 deletions man/downloadPathwayArchive.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/getColoredPathway.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vignettes/Overview.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ date: "`r Sys.Date()`"
output:
BiocStyle::html_document:
toc_float: true
# pdf_document:
# toc: true
vignette: >
%\VignetteIndexEntry{1. Overview}
%\VignetteEngine{knitr::rmarkdown}
Expand Down Expand Up @@ -154,6 +156,24 @@ And, as you may have suspected from the function name, you can also add color to

This will produce an svg image of the pathway with the ACE gene highlighted by color.

WikiPathways also provides a monthly data release archived at http://data.wikipathways.org. The archive includes GPML, GMT and SVG collections by organism and timestamped. There's an R function for grabbing files from the archive...

```{r}
downloadPathwayArchive()
```

This will simply open the archive in your default browser so you can look around (in case you don't know what you are looking for). By default, it opens to the latest collection of GPML files. However, if you provide an organism, then it will download that file to your current working directory or specified **destpath**. For example, here's how you'd get the latest GMT file for mouse:

```{r}
downloadPathwayArchive(organism="Mus musculus", format="gmt")
```

And if you might want to specify an archive date so that you can easily share and reproduce your script at any time in the future and get the same result. Remember, new pathways are being added to WikiPathways every month and existing pathways are improved continuously!

```{r}
downloadPathwayArchive(date="20171010", organism="Mus musculus", format="gmt")
```

# Wrapping up

That's an overview of the **rWikiPathways** package. Check out other vignettes and the complete list of package functions:
Expand Down
10 changes: 2 additions & 8 deletions vignettes/rWikiPathways-and-BridgeDbR.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@ date: "`r Sys.Date()`"
output:
BiocStyle::html_document:
toc_float: true
# pdf_document:
# toc: true
vignette: >
%\VignetteIndexEntry{2. rWikiPathways and BridgeDbR}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
bibliography: tutorial.bib
csl: biomed-central.csl
references:
- id: dummy
title: no title
author:
- family: noname
given: noname
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
Expand Down
10 changes: 2 additions & 8 deletions vignettes/rWikiPathways-and-RCy3.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@ date: "`r Sys.Date()`"
output:
BiocStyle::html_document:
toc_float: true
# pdf_document:
# toc: true
vignette: >
%\VignetteIndexEntry{3. rWikiPathways and RCy3}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
bibliography: tutorial.bib
csl: biomed-central.csl
references:
- id: dummy
title: no title
author:
- family: noname
given: noname
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
Expand Down

0 comments on commit afcccba

Please sign in to comment.