Skip to content

Commit

Permalink
Merge pull request #18 from wilsontom/devel
Browse files Browse the repository at this point in the history
Version 0.2.0
  • Loading branch information
wilsontom authored Feb 25, 2019
2 parents dc5eb90 + 6698963 commit df8153b
Show file tree
Hide file tree
Showing 34 changed files with 408 additions and 942 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ README.md
cran-comments.md
NOTES.md
cran_submission/
_pkgdown.yml
README_examples.R
README.Rmd
docs/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.Rproj.user
cran_submission/
README_examples.R
13 changes: 7 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: classyfireR
Type: Package
Title: R Interface to the ClassyFire RESTful API
Version: 0.1.2
Date: 2018-12-06
Version: 0.2.0
Date: 2019-02-25
Authors@R: c(
person("Tom", "Wilson", , "tpw2@aber.ac.uk", c("aut", "cre")))
Description: Access to the ClassyFire RESTful API <http://classyfire.wishartlab.com>. Retrieve existing entity classifications and submit new entities for classification.
Expand All @@ -13,17 +13,18 @@ Imports:
jsonlite,
tibble,
crayon,
clisymbols
clisymbols,
purrr,
dplyr,
stringr
Suggests:
testthat,
covr,
dplyr,
purrr,
tidyr
License: GPL (>= 3)
Encoding: UTF-8
LazyData: true
URL: https://github.com/wilsontom/classyfireR
BugReports: https://github.com/wilsontom/classyfireR/issues
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
Roxygen: list(markdown = TRUE)
11 changes: 7 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Generated by roxygen2: do not edit by hand

export(entity_classification)
export(get_status_code)
export(retrieve_classification)
export(submit_classification)
export(get_classification)
importFrom(dplyr,bind_rows)
importFrom(dplyr,filter)
importFrom(magrittr,"%>%")
importFrom(purrr,map)
importFrom(purrr,map_chr)
importFrom(stringr,str_c)
importFrom(tibble,tibble)
importFrom(utils,globalVariables)
22 changes: 13 additions & 9 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
### NEWS
# classyfireR 0.2.0

#### v0.1.2
* Remove POST submission functions. ClassyFire database is now extensive enough that new submission are rarely needed. This will prevent the intermitent failing of checks on CRAN aswell.
* Add `pkgdown` website for docs
* `entity_classification` renamed to `get_classification`
* All available classificatons now returned (@jasenfinch)

- Fix unit test to catch when server is unresponsive. This will fix intermittent CRAN check fails
# classyfireR 0.1.2

#### v0.1.1
* Fix unit test to catch when server is unresponsive. This will fix intermittent CRAN check fails

- Add more detailed examples ready for CRAN submission
# classyfireR 0.1.1

#### V0.1.0
* Add more detailed examples ready for CRAN submission

# classyfireR 0.1.0

- Low level access to the ClassyFire RESTful API
- Retrieve existing classifications using InChI Keys
- Submit new classifications to the server using InChI Codes and retrieve the results
* Low level access to the ClassyFire RESTful API
* Retrieve existing classifications using InChI Keys
* Submit new classifications to the server using InChI Codes and retrieve the results
2 changes: 2 additions & 0 deletions R/classyfireR.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

globalVariables(c('Level','Classification'))
29 changes: 17 additions & 12 deletions R/entity_classification.R → R/get_classification.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Entity Classification
#' Get Entity Classification
#'
#' Retrieve entity classification from `http://classyfire.wishartlab.com/entities/'
#'
Expand All @@ -12,13 +12,13 @@
#' @examples
#'
#' # Valid InChI key where all four classification levels are available
#' entity_classification('BRMWTNUJHUMWMS-LURJTMIESA-N')
#' get_classification('BRMWTNUJHUMWMS-LURJTMIESA-N')
#'
#' # Valid InChI key where only three classification levels are available
#' entity_classification('MDHYEMXUFSJLGV-UHFFFAOYSA-N')
#' get_classification('MDHYEMXUFSJLGV-UHFFFAOYSA-N')
#'
#' # Invalid InChI key
#' entity_classification('MDHYEMXUFSJLGV-UHFFFAOYSA-B')
#' get_classification('MDHYEMXUFSJLGV-UHFFFAOYSA-B')
#'
#'
#' # Using `dplyr` a vector of InChI Keys can be submitted and easily parsed
Expand All @@ -34,7 +34,7 @@
#' 'WHEUWNKSCXYKBU-QPWUGHHJSA-N',
#' 'WHBMMWSBFZVSSR-GSVOUGTGSA-N')
#'
#' classification_list <- map(keys, entity_classification)
#' classification_list <- map(keys, get_classification)
#'
#' classification_list <- map(classification_list, ~{select(.,-CHEMONT)})
#'
Expand All @@ -44,18 +44,23 @@
#'
#' rownames(spread_tibble) <- keys
#'
#' classification_df <- data.frame(InChIKey = rownames(spread_tibble),
#' Kingdom = spread_tibble$kingdom,
#' SuperClass = spread_tibble$superclass,
#' Class = spread_tibble$class,
#' SubClass = spread_tibble$subclass)
#' classification_tibble <- tibble(
#' InChIKey = rownames(spread_tibble),
#' Kingdom = spread_tibble$kingdom,
#' SuperClass = spread_tibble$superclass,
#' Class = spread_tibble$class,
#' SubClass = spread_tibble$subclass,
#' Level5 = spread_tibble$level.5,
#' Level6 = spread_tibble$level.6,
#' Level7 = spread_tibble$level.7
#' )
#'
#' print(classification_df)
#' print(classification_tibble)
#'
#'
#'
#' @export
entity_classification <- function(inchi_key)
get_classification <- function(inchi_key)
{
entity_url <- 'http://classyfire.wishartlab.com/entities/'

Expand Down
30 changes: 0 additions & 30 deletions R/get_status_code.R

This file was deleted.

44 changes: 28 additions & 16 deletions R/internals.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#' * __Classification__ The compound classification
#' * __CHEMONT__ Chemical Ontology Identification code
#' @keywords internal
#' @importFrom dplyr bind_rows filter
#' @importFrom purrr map map_chr
#' @importFrom stringr str_c
#' @importFrom tibble tibble
#' @importFrom magrittr %>%

parse_json_output <- function(json_res)
{
Expand All @@ -16,27 +21,34 @@ parse_json_output <- function(json_res)
kingdom = json_res[['kingdom']],
superclass = json_res[['superclass']],
class = json_res[['class']],
subclass = json_res[['subclass']]
subclass = json_res[['subclass']],
intermediate_nodes = json_res[['intermediate_nodes']],
direct_parent = json_res[['direct_parent']]
)

len <- lapply(list_output, length) %>% unlist()
if (length(list_output$intermediate_nodes) == 0) {
list_output$intermediate_nodes <- NULL
}

class_tibble <-
tibble::tibble(Level = names(len),
Classification = 'NA',
CHEMONT = 'NA')
list_output <- list_output[!sapply(list_output,is.null)]

for (i in seq_along(len)) {
if (len[[i]] == 4) {
class_tibble[i, 'Classification'] <- list_output[[i]]$name
class_tibble[i, 'CHEMONT'] <- list_output[[i]]$chemont_id
} else{
class_tibble[i, 'Classification'] <- NA
class_tibble[i, 'CHEMONT'] <- NA
}
}
class_tibble <- map(1:length(list_output),~{
l <- list_output[[.]]
tibble(
Level = names(list_output)[.],
Classification = l$name,
CHEMONT = l$chemont_id
)
}) %>%
bind_rows() %>%
filter(!duplicated(Classification))

nIntermediate <- class_tibble %>%
filter(Level == 'intermediate_nodes') %>%
nrow()

return(class_tibble)
class_tibble$Level[class_tibble$Level == 'intermediate_nodes'] <- map_chr(5:(5 + (nIntermediate - 1)),~{str_c('level ',.)})
class_tibble$Level[class_tibble$Level == 'direct_parent'] <- str_c('level ',5 + nIntermediate)

return(class_tibble)
}
33 changes: 0 additions & 33 deletions R/retrieve_classification.R

This file was deleted.

46 changes: 0 additions & 46 deletions R/submit_classification.R

This file was deleted.

Loading

0 comments on commit df8153b

Please sign in to comment.