Skip to content

Commit

Permalink
refactor: add parameter onlyValid to compound_tbl_sdf
Browse files Browse the repository at this point in the history
- Add parameter `onlyValid` to `compound_tbl_sdf` (issue #69).
  • Loading branch information
jorainer committed Nov 27, 2020
1 parent 5e71799 commit fb877b2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: CompoundDb
Type: Package
Title: Creating and Using (Chemical) Compound Annotation Databases
Version: 0.6.4
Version: 0.6.5
Authors@R: c(person(given = "Jan", family = "Stanstrup",
email = "stanstrup@gmail.com",
role = c("aut"),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ importFrom(Biobase,createPackage)
importFrom(ChemmineR,datablock)
importFrom(ChemmineR,datablock2ma)
importFrom(ChemmineR,read.SDFset)
importFrom(ChemmineR,validSDF)
importFrom(DBI,dbDisconnect)
importFrom(DBI,dbDriver)
importFrom(DBI,dbExecute)
Expand Down
16 changes: 14 additions & 2 deletions R/createCompDbPackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#' @param collapse optional `character(1)` to be used to collapse multiple
#' values in the columns `"synonyms"`. See examples for details.
#'
#' @param onlyValid `logical(1)` to import only valid or all elements (defaults
#' to `onlyValid = TRUE`)
#'
#' @return A [tibble::tibble] with general compound information (one row per
#' compound):
#' + `compound_id`: the ID of the compound.
Expand All @@ -59,7 +62,7 @@
#' @seealso [createCompDb()] for a function to create a SQLite-based compound
#' database.
#'
#' @importFrom ChemmineR read.SDFset datablock datablock2ma
#' @importFrom ChemmineR read.SDFset datablock datablock2ma validSDF
#'
#' @examples
#'
Expand All @@ -76,11 +79,20 @@
#' cmps <- compound_tbl_sdf(fl, collapse = "|")
#' cmps
#' cmps$synonyms
compound_tbl_sdf <- function(file, collapse) {
compound_tbl_sdf <- function(file, collapse, onlyValid = TRUE) {
if (missing(file))
stop("Please provide the file name using 'file'")
if (!file.exists(file))
stop("Can not fine file ", file)
suppressWarnings(
sdf <- read.SDFset(file))
nsdf <- length(sdf)
if (onlyValid) {
sdf <- sdf[validSDF(sdf)]
if (length(sdf) != nsdf)
message("Skipped import of ", nsdf - length(sdf),
" invalid elements")
}
res <- .simple_extract_compounds_sdf(
datablock2ma(datablock(read.SDFset(file))))
if (!missing(collapse)) {
Expand Down
6 changes: 6 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Changes in version 0.6.5

- Add parameter `onlyValid` to `compound_tbl_sdf` to allow importing of only
valid elements
[issue #69](https://github.com/EuracBiomedicalResearch/CompoundDb/issues/69).

Changes in version 0.6.4

- Add additional filters: `MassFilter`, `FormulaFilter`, `InchiFilter` and
Expand Down
5 changes: 4 additions & 1 deletion man/compound_tbl_sdf.Rd

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

2 changes: 2 additions & 0 deletions tests/testthat/test_createCompDbPackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ test_that("compound_tbl_sdf works", {

hmdb <- system.file("sdf/HMDB_sub.sdf.gz", package = "CompoundDb")
cmps <- compound_tbl_sdf(hmdb)
cmps2 <- compound_tbl_sdf(hmdb, onlyValid = FALSE)
expect_equal(cmps, cmps2)
expect_true(is(cmps, "data.frame"))
expect_true(is(cmps, "tbl"))
expect_equal(colnames(cmps), c("compound_id", "name", "inchi",
Expand Down

0 comments on commit fb877b2

Please sign in to comment.