Skip to content

Commit

Permalink
Merge 0aca74f into 3d7b50f
Browse files Browse the repository at this point in the history
  • Loading branch information
htc502 committed Aug 5, 2015
2 parents 3d7b50f + 0aca74f commit 4b87eca
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 108 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -16,7 +16,7 @@ is intended to be a general-purpose wrapper for the `Eutils` API. Functions that
make use of `rentrez` to perform more specific tasks should be added to existing
packages, or form the basis of new ones.

###Perferred way to contribute code
###Preferred way to contribute code

* Fork this repo to your Github account
* Clone your version on your account down to your machine from your account, e.g,. `git clone https://github.com/<yourgithubusername>/rentrez.git`
Expand All @@ -33,5 +33,5 @@ Please note that this project is released with a [Contributor Code of
Conduct](CONDUCT.md). By participating in this project you agree to abide by its
terms.

Thanks for contibuting!
Thanks for contributing!

12 changes: 6 additions & 6 deletions NEWS
Expand Up @@ -8,19 +8,19 @@ Version 0.4
------------------------
* entrez_summary now fetches 'version 2.0' esummary records from NCBI
* This change may break some scripts. In particular, the names of some
elements in esummary records have changed. Broken scripts shold produce a
elements in esummary records have changed. Broken scripts should produce a
helpful error message, and using entrez_summary(..., version="1.0")
should fix it. More details are given in the help to entrez_summary.
* When version 2.0 records are requested entrez_summary fetches the json
record.
* New helper functions for einfo Eutil
* entrez_dbs() lists avaliable databases.
* entrez_dbs() lists available databases.
* entrez_db_summary() gets summary information about a given database.
* entrez_db_links() lists databases against which a given db's records might
be cross referenced.
* entrez_db_searchable() lists search terms avaliable for a given database.
* entrez_db_searchable() lists search terms available for a given database.
* Nicer print functions for search and summary objects
* New dependancy on jsonlite for handling json records.
* New dependency on jsonlite for handling json records.
* Bunch of bugs squashed and typos cleaned up

Version 0.3.1
Expand All @@ -41,8 +41,8 @@ Version 0.2.4

Version 0.2.3
---------------------------------
* Edited license/description to meet CRAN requiremens
* Added sentence to description to summarise the package
* Edited license/description to meet CRAN requirements
* Added sentence to description to summarize the package


Version 0.2.2
Expand Down
19 changes: 10 additions & 9 deletions R/base.r
Expand Up @@ -3,7 +3,7 @@
#
# http://cran.r-project.org/web/packages/httr/vignettes/api-packages.html
#
#and also conforming to the NBCI's requirements about rate limiting and
#and also conforming to the NBCI's requirements about rate limiting and
#adding identifiers to each request:
#
# http://www.ncbi.nlm.nih.gov/books/NBK25497/#chapter2.Usage_Guidelines_and_Requirements
Expand All @@ -16,24 +16,25 @@
entrez_email <- function() 'david.winter@gmail.com'
entrez_tool <- function() 'rentrez'

#Create a URL for the EUtils API.
#Create a URL for the EUtils API.
#
# This function is used by all the API-querying functions in rentrez to build
# the appropriate url. Required arguments for each rentrez are handled in each
# function. Those arguments that either ID(s) or are WebEnv cookie can be set
# by passing a string or two argument names to `make_entrez_query`
#
#
# efetch_url <- make_entrez_query("efetch", require_one_of=c("id", "WebEnv"),
# efetch_url <- make_entrez_query("efetch", require_one_of=c("id", "WebEnv"),
# id=c(23310964,23310965), db="pubmed",
# rettype="xml")
#


make_entrez_query <- function(util, config, interface=".fcgi?", ...){
##this fxn assembles the uri make query and return the result as text
args <- list(..., email=entrez_email(), tool=entrez_tool())
if("id" %in% names(args)){
args$id <- paste(args$id, collapse=",")
args$id <- paste(args$id, collapse=",")
}
uri <- paste0("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/", util, interface)
response <- httr::GET(uri, query=args, config= config)
Expand All @@ -42,13 +43,13 @@ make_entrez_query <- function(util, config, interface=".fcgi?", ...){
}

##
# Check for that we have either the ID or the web-history functions are
# Check for that we have either the ID or the web-history functions are
# specified for those functions that need one.
##

id_or_webenv <- function(){
args <- sys.frame(sys.parent())
msg <- "Must specify either (not both) 'id' or web history arguments 'WebEnv' and 'query_key'"
args <- sys.frame(sys.parent()) ##get the eviroment of using the parent call frame number
msg <- "Must specify either (not both) 'id' or web history arguments 'WebEnv' and 'query_key'"
if(!is.null(args$id)){
if(!is.null(args$web_history)){
stop(msg, call.=FALSE)
Expand Down Expand Up @@ -89,7 +90,7 @@ check_xml_errors <- function(x){


parse_response <- function(x, type=NULL){
res <- switch(type,
res <- switch(type,
"json" = fromJSON(x),
"xml" = xmlTreeParse(x, useInternalNodes=TRUE),
"text" = x, #citmatch uses plain old plain text
Expand All @@ -108,7 +109,7 @@ web_history <- function(WebEnv, QueryKey){
#'@export
print.web_history <- function(x, ...){
cat("Web history object (QueryKey = ", x$QueryKey,
", WebEnv = ", substr(x$WebEnv, 1, 12), "...", ")\n",sep="")
", WebEnv = ", substr(x$WebEnv, 1, 12), "...", ")\n",sep="")
}


Expand Down
13 changes: 7 additions & 6 deletions R/entrez_info.r
Expand Up @@ -100,9 +100,10 @@ entrez_db_summary <- function(db, config=NULL){
entrez_db_links <- function(db, config=NULL){
rec <- entrez_info(db, config)
unparsed <- xpathApply(rec, "//Link", xmlChildren)
res <- lapply(unparsed, lapply, xmlValue)
res <- lapply(unparsed, lapply, xmlValue) ##this line applies xmlvalue fun to the list element of a list
##and return a list of list
res <- lapply(res, add_class, new_class='eInfoEntry')
names(res) <- sapply(res, "[[", "DbTo")
names(res) <- sapply(res, "[[", "DbTo") ##this line get the 4th elemnt of each element(also a list) in res
class(res) <- c("eInfoLink", "eInfoList", "list")
attr(res, 'db') <- xmlValue(rec["/eInfoResult/DbInfo/DbName"][[1]])
res
Expand All @@ -115,9 +116,9 @@ entrez_db_links <- function(db, config=NULL){
#' search fields to include in the \code{term} argument of that function.
#'@param config config vector passed to \code{httr::GET}
#'@param db character, name of database to get search field from
#'@return An eInfoSearch object (subclassed from list) summarizing linked-databases.
#'@return An eInfoSearch object (subclassed from list) summarizing linked-databases.
#' Can be coerced to a data-frame with \code{as.data.frame}. Printing the object
#' shows only the names of each available search field.
#' shows only the names of each available search field.
#'@seealso \code{\link{entrez_search}}
#'@family einfo
#'@examples
Expand All @@ -134,7 +135,7 @@ entrez_db_links <- function(db, config=NULL){

entrez_db_searchable <- function(db, config=NULL){
rec <- entrez_info(db, config)
unparsed <- xpathApply(rec,
unparsed <- xpathApply(rec,
"/eInfoResult/DbInfo/FieldList/Field",
xmlChildren)
res <- lapply(unparsed, lapply, xmlValue)
Expand All @@ -160,7 +161,7 @@ as.data.frame.eInfoList <- function(x, ...){
print.eInfoSearch <- function(x, ...){
cat("Searchable fields for database '", attr(x, "db"), "'\n", sep="")
for (term in x){
cat(" ", term$Name, "\t", term$Description, "\n")
cat(" ", term$Name, "\t", term$Description, "\n")
}
}

Expand Down
22 changes: 11 additions & 11 deletions README.Rmd
Expand Up @@ -11,7 +11,7 @@ knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
knitr::opts_knit$set(upload.fun = knitr::imgur_upload, base.url = NULL)
knitr::opts_knit$set(upload.fun = knitr::imgur_upload, base.url = NULL)
```

Expand Down Expand Up @@ -45,12 +45,12 @@ or [by filing an issue](https://github.com/ropensci/rentrez/issues)

##The EUtils API

Each of the functions exportd by `rentrez` is documented, and this README and
the pakage vignette provide examples of how to use the functions together as part
Each of the functions exported by `rentrez` is documented, and this README and
the package vignette provide examples of how to use the functions together as part
of a workflow. The API itself is [well-documented](http://www.ncbi.nlm.nih.gov/books/NBK25500/).
Be sure to read the official documenation to get the most out of API. In particular, be aware of the NCBI's usage
Be sure to read the official documentation to get the most out of API. In particular, be aware of the NCBI's usage
policies and try to limit very large requests to off peak (USA) times (`rentrez`
takes care of limiting the number of requests per second, and seeting the
takes care of limiting the number of requests per second, and setting the
appropriate entrez tool name in each request).

See [getting information about NCBI databases](#getting-information-about-ncbi-databases)
Expand Down Expand Up @@ -95,7 +95,7 @@ In this case we'll get the protein sequences as genbank files, using '
hox_proteins <- entrez_fetch(db="protein", id=hox_data$pubmed_protein, rettype="gb")
```

###Retreiving datasets associated a particular organism.
###Retrieving datasets associated a particular organism.

I like spiders. So let's say I want to learn a little more about New Zealand's
endemic "black widow" the katipo. Specifically, in the past the katipo has
Expand Down Expand Up @@ -160,7 +160,7 @@ configuration options.

Any `rentrez` function that interacts with the Eutils api will
pass the value of the argument `config` along to `httr`'s `GET` function. For
instance, if you acess the internet through a proxy you use the `httr` function
instance, if you access the internet through a proxy you use the `httr` function
`use_proxy()` to provide connection details to an entrez call:

```r
Expand Down Expand Up @@ -204,7 +204,7 @@ snail_coi <- entrez_fetch(db="nuccore", WebEnv=cookie, query_key=qk, rettype="fa

###Getting information about NCBI databases

Most of the exmples above required some background information about what
Most of the examples above required some background information about what
databases NCBI has to offer, and how they can be searched. `rentrez` provides
a set of functions with names starting `entrez_db` that help you to discover
this information in an interactive session.
Expand All @@ -216,14 +216,14 @@ First up, `entrez_dbs()` gives you a list of database names
entrez_dbs()
```

Some of the names are a little opaque, so you can get some more descriptve
Some of the names are a little opaque, so you can get some more descriptive
information about each with `entrez_db_summary()`

```{r summary}
entrez_db_summary("cdd")
```

`entrez_db_searchable()` lets you discover the fields avalible for search terms
`entrez_db_searchable()` lets you discover the fields available for search terms
for a given database. You get back a named-list, with names are fields. Each
element has additional information about each named search field (you can also
use `as.data.frame` to create a dataframe, with one search-field per row):
Expand Down Expand Up @@ -259,7 +259,7 @@ papers_by_year <- function(years, search_term){
}
```

With that we can fetch the data for earch term and, by searching with no term,
With that we can fetch the data for each term and, by searching with no term,
find the total number of papers published in each year:


Expand Down
4 changes: 2 additions & 2 deletions man/entrez_fetch.Rd
Expand Up @@ -10,7 +10,7 @@ entrez_fetch(db, id = NULL, web_history = NULL, rettype, retmode = "text",
\arguments{
\item{db}{character Name of the database to use}

\item{id}{vector with unique ID(s) for reacods in database \code{db}.}
\item{id}{vector with unique ID(s) for records in database \code{db}.}

\item{web_history}{A web_history object}

Expand All @@ -24,7 +24,7 @@ file. Only works with rettype="xml" at present}
\item{config}{vector configuration options passed to httr::GET}

\item{\dots}{character Additional terms to add to the request, see NCBI
documentation linked to in referenes for a complete list}
documentation linked to in references for a complete list}
}
\value{
character string containing the file created
Expand Down
8 changes: 4 additions & 4 deletions man/entrez_link.Rd
Expand Up @@ -12,20 +12,20 @@ entrez_link(dbfrom, web_history = NULL, id = NULL, db = NULL,

\item{web_history}{a web_history object}

\item{id}{vector with unique ID(s) for reacods in database \code{db}.}
\item{id}{vector with unique ID(s) for records in database \code{db}.}

\item{db}{character Name of the database to search for links (or use "all" to
search all databases available for \code{db}. \code{entrez_db_links} allows you
to discover databases that might have linked information (see examples).}

\item{cmd}{link function to use. Allowled values include
\item{cmd}{link function to use. Allowed values include
\itemize{
\item neighbor (default). Returns a set of IDs in \code{db} linked to the
input IDs in \code{dbfrom}.
\item neighbor_score. As 'neighbor', but additionally returns similarity scores.
\item neighbor_history. As 'neighbor', but returns web history objects.
\item acheck. Returns a list of linked databases available from NCBI for a set of IDs.
\item ncheck. Checks for the existance of links within a single database.
\item ncheck. Checks for the existence of links within a single database.
\item lcheck. Checks for external (i.e. outside NCBI) links.
\item llinks. Returns a list of external links for each ID, excluding links
provided by libraries.
Expand All @@ -38,7 +38,7 @@ to discover databases that might have linked information (see examples).}
\item{config}{vector configuration options passed to httr::GET}

\item{\dots}{character Additional terms to add to the request, see NCBI
documentation linked to in referenes for a complete list}
documentation linked to in references for a complete list}
}
\value{
An elink object containing the data defined by the \code{cmd} argument
Expand Down
4 changes: 2 additions & 2 deletions man/entrez_search.Rd
Expand Up @@ -17,11 +17,11 @@ entrez_search(db, term, config = NULL, retmode = "xml",
\item{retmode}{character One of json (default) or xml. This will make no
difference in most cases.}

\item{use_history}{locgical Return a web_history object for use in
\item{use_history}{logical Return a web_history object for use in
later calls to the NCBI}

\item{\dots}{character Additional terms to add to the request, see NCBI
documentation linked to in referenes for a complete list}
documentation linked to in references for a complete list}
}
\value{
ids integer Unique IDS returned by the search
Expand Down
4 changes: 2 additions & 2 deletions man/entrez_summary.Rd
Expand Up @@ -10,7 +10,7 @@ entrez_summary(db, id = NULL, web_history = NULL, version = c("2.0",
\arguments{
\item{db}{character Name of the database to search for}

\item{id}{vector with unique ID(s) for reacods in database \code{db}.}
\item{id}{vector with unique ID(s) for records in database \code{db}.}

\item{web_history}{A web_history object}

Expand All @@ -22,7 +22,7 @@ when only one ID is provided.}
\item{config}{vector configuration options passed to \code{httr::GET}}

\item{\dots}{character Additional terms to add to the request, see NCBI
documentation linked to in referenes for a complete list}
documentation linked to in references for a complete list}
}
\value{
A list of esummary records (if multiple IDs are passed and
Expand Down
4 changes: 2 additions & 2 deletions staticdocs/entrez_fetch.html
Expand Up @@ -60,7 +60,7 @@ <h2>Arguments</h2>
<div class="Value">
<h2>Value</h2>

<p>chracter string containing the file created</p>
<p>character string containing the file created</p>

</div>

Expand Down Expand Up @@ -93,4 +93,4 @@ <h2 id="examples">Examples</h2>
</footer>
</div>
</body>
</html>
</html>
8 changes: 4 additions & 4 deletions staticdocs/entrez_global_query.html
Expand Up @@ -35,7 +35,7 @@

</header>

<h1>See how many hits there are for a given term across all NCBI Entrez databses</h1>
<h1>See how many hits there are for a given term across all NCBI Entrez databases</h1>

<div class="row">
<div class="span8">
Expand All @@ -51,14 +51,14 @@ <h2>Arguments</h2>
<div class="Value">
<h2>Value</h2>

<p>a named vector with counts for each a datbase</p>
<p>a named vector with counts for each a database</p>

</div>

<div class="Description">
<h2>Description</h2>

<p>Contstructs a url with the given arguments, and downloads
<p>Constructs a url with the given arguments, and downloads
xml record returned by that url. See the package-level
documentation for general advice on using the EUtils
functions.</p>
Expand Down Expand Up @@ -86,4 +86,4 @@ <h2 id="examples">Examples</h2>
</footer>
</div>
</body>
</html>
</html>

0 comments on commit 4b87eca

Please sign in to comment.