Skip to content

Commit

Permalink
Merge pull request #34 from aberHRML/devel
Browse files Browse the repository at this point in the history
0.3.2
  • Loading branch information
wilsontom authored Jan 15, 2020
2 parents ce83f9b + 4328b68 commit 9870f11
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 29 deletions.
6 changes: 3 additions & 3 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.3.1
Date: 2019-11-22
Version: 0.3.2
Date: 2019-12-16
Authors@R: c(
person("Tom", "Wilson", , "tpw2@aber.ac.uk", c("aut", "cre"), comment = c(ORCID = "0000-0003-3112-4682")),
person("Jasen", "Finch", , "jsf9@aber.ac.uk", "aut"))
Expand All @@ -28,7 +28,7 @@ Encoding: UTF-8
LazyData: true
URL: https://github.com/aberHRML/classyfireR
BugReports: https://github.com/aberHRML/classyfireR/issues
RoxygenNote: 7.0.0
RoxygenNote: 7.0.2
Roxygen: list(markdown = TRUE)
Collate:
'allGenerics.R'
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ exportMethods(direct_parent)
exportMethods(meta)
exportMethods(show)
importFrom(magrittr,"%>%")
importFrom(methods,show)
importFrom(tibble,tibble)
importFrom(utils,globalVariables)
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# classyfireR 0.3.2

* Add check to `get_classification` for when a valid http status code (200) is returned but the content of the return is `{}`. This appears to be an error during InChIKey validation.

* Add further length checks in `get_classification` for when there are no `alternative_parents` returned.

# classyfireR 0.3.1

* Add length checks in `get_classification` for when elements of the `json` output is missing (ie, no external descriptors present)
Expand Down
35 changes: 23 additions & 12 deletions R/get_classification.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ get_classification <- function(inchi_key)
}

if (response$status_code == 200) {
message(crayon::green(clisymbols::symbol$tick, inchi_key))
text_content <- httr::content(response, 'text')

if (text_content == '{}') {
message(crayon::red(clisymbols::symbol$cross, inchi_key))
return(invisible(NULL))
} else{
message(crayon::green(clisymbols::symbol$tick, inchi_key))
}


json_res <- jsonlite::fromJSON(text_content)

classification <- parse_json_output(json_res)
Expand All @@ -58,24 +65,28 @@ get_classification <- function(inchi_key)

object@direct_parent <- json_res$direct_parent

object@alternative_parents <-
tibble::tibble(
name = json_res$alternative_parents$name,
description = json_res$alternative_parents$description,
chemont_id = json_res$alternative_parents$chemont_id,
url = json_res$alternative_parents$url
)
if (length(json_res$alternative_parents) > 0) {
object@alternative_parents <-
tibble::tibble(
name = json_res$alternative_parents$name,
description = json_res$alternative_parents$description,
chemont_id = json_res$alternative_parents$chemont_id,
url = json_res$alternative_parents$url
)
} else{
object@alternative_parents <- tibble::tibble()
}

if(length(json_res$predicted_chebi_terms) > 0) {
if (length(json_res$predicted_chebi_terms) > 0) {
object@predicted_chebi <- json_res$predicted_chebi_terms
}else{
} else{
object@predicted_chebi <- vector(mode = 'character')
}


if(length(json_res$external_descriptors) > 0) {
if (length(json_res$external_descriptors) > 0) {
object@external_descriptors <- parse_external_desc(json_res)
}else{
} else{
object@external_descriptors <- tibble::tibble()
}

Expand Down
26 changes: 13 additions & 13 deletions R/internals.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ parse_json_output <- function(json_res)




#' Parse External Descriptors
#'
#' Parse the list output of returned External Descriptors
Expand All @@ -69,23 +68,24 @@ parse_json_output <- function(json_res)
#' * __source__ External source name
#' * __source_id__ External source ID
#' * __annotations__ External source annotation
#' @importFrom tibble tibble
#' @keywords internal

parse_external_desc <- function(x)
{
external_ann <- list()
for (i in seq_along(x$external_descriptors$annotations)) {
external_ann[[i]] <-
paste(x$external_descriptors$annotations[[i]], collapse = ' // ')
}

external_desc <-
tibble::tibble(
source = x$external_descriptors$source,
source_id = x$external_descriptors$source_id,
annotations = unlist(external_ann)
)
external_ann <- list()
for (i in seq_along(x$external_descriptors$annotations)) {
external_ann[[i]] <-
paste(x$external_descriptors$annotations[[i]], collapse = ' // ')
}

return(external_desc)
external_desc <-
tibble(
source = x$external_descriptors$source,
source_id = x$external_descriptors$source_id,
annotations = unlist(external_ann)
)

return(external_desc)
}
1 change: 1 addition & 0 deletions R/show-method.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' show-ClassyFire
#' @rdname show
#' @param object a `ClassyFire` S4 object
#' @importFrom methods show
#' @export

setMethod('show', signature = 'ClassyFire',
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![Build Status](https://travis-ci.org/aberHRML/classyfireR.svg?branch=master)](https://travis-ci.org/aberHRML/classyfireR) [![Build status](https://ci.appveyor.com/api/projects/status/ua94fiotdmc0ssq5/branch/master?svg=true)](https://ci.appveyor.com/project/wilsontom/classyfirer/branch/master) [![codecov](https://codecov.io/gh/aberHRML/classyfireR/branch/master/graph/badge.svg)](https://codecov.io/gh/aberHRML/classyfireR) ![License](https://img.shields.io/badge/license-GNU%20GPL%20v3.0-blue.svg "GNU GPL v3.0") [![DOI](https://zenodo.org/badge/118162964.svg)](https://zenodo.org/badge/latestdoi/118162964)

[![CRAN](https://www.r-pkg.org/badges/version/classyfireR)](https://cran.r-project.org/web/packages/classyfireR/index.html) ![total downloads](https://cranlogs.r-pkg.org/badges/grand-total/classyfireR?color=red)
[![CRAN](https://www.r-pkg.org/badges/version/classyfireR)](https://cran.r-project.org/web/packages/classyfireR/index.html) ![total downloads](https://cranlogs.r-pkg.org/badges/grand-total/classyfireR?color=red) [![GitHub](https://img.shields.io/github/v/release/aberHRML/classyfireR?color=brightgreen&label=GitHub%20Version)](https://github.com/aberHRML/classyfireR/releases)
> __R Interface to the [ClassyFire REST API](http://classyfire.wishartlab.com)__

Expand Down

0 comments on commit 9870f11

Please sign in to comment.