From 7cc5df2ad1e2a1aa5c6d4d9f5865491c6b30ee2a Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 26 Aug 2015 13:24:57 +0200 Subject: Initial commit --- .Rbuildignore | 4 ++ .gitignore | 1 + ChangeLog | 5 ++ DESCRIPTION | 16 +++++ GNUmakefile | 75 +++++++++++++++++++++++ NAMESPACE | 7 +++ R/chent.R | 154 ++++++++++++++++++++++++++++++++++++++++++++++++ README.html | 104 ++++++++++++++++++++++++++++++++ README.md | 18 ++++++ inst/examples/ai.R | 2 + inst/examples/chents.R | 2 + inst/staticdocs/index.r | 5 ++ man/chent.Rd | 33 +++++++++++ man/pai.Rd | 27 +++++++++ roxygen.log | 4 ++ 15 files changed, 457 insertions(+) create mode 100644 .Rbuildignore create mode 100644 .gitignore create mode 100644 ChangeLog create mode 100644 DESCRIPTION create mode 100644 GNUmakefile create mode 100644 NAMESPACE create mode 100644 R/chent.R create mode 100644 README.html create mode 100644 README.md create mode 100644 inst/examples/ai.R create mode 100644 inst/examples/chents.R create mode 100644 inst/staticdocs/index.r create mode 100644 man/chent.Rd create mode 100644 man/pai.Rd create mode 100644 roxygen.log diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..740d75d --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,4 @@ +^chents_*.tar.gz +GNUmakefile +README.html +sd/* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d536fda --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +chents_*.tar.gz diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..5a1734e --- /dev/null +++ b/ChangeLog @@ -0,0 +1,5 @@ +commit 11bf23fcf72ec7c537c67786fb377635ab3d3932 +Author: Johannes Ranke +Date: 2015-08-26 13:24:57 +0200 + + Initial commit diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..c86a2ea --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,16 @@ +Package: chents +Type: Package +Title: Chemical Entities as R Objects +Version: 0.1-1.9000 +Date: 2015-08-26 +Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"), + email = "jranke@uni-bremen.de")) +Description: Utilities for dealing with chemical entities and associated data as R objects. +Imports: webchem, R6 +Suggests: knitr, testthat +License: GPL +LazyLoad: yes +LazyData: yes +Encoding: UTF-8 +VignetteBuilder: knitr +URL: http://cgit.jrwb.de/chents diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..482ec37 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,75 @@ +PKGSRC := $(shell basename $(CURDIR)) +PKGNAME := $(shell sed -n "s/Package: *\([^ ]*\)/\1/p" DESCRIPTION) +PKGVERS := $(shell sed -n "s/Version: *\([^ ]*\)/\1/p" DESCRIPTION) +TGZ := $(PKGNAME)_$(PKGVERS).tar.gz +R_HOME ?= $(shell R RHOME) +DATE := $(shell date +%Y-%m-%d) + +.PHONEY: usage check clean roxygen sd + +usage: + @echo "Usage: make TARGET with TARGET being:" + @echo "" + @echo " clean - Clean up." + @echo " roxygen - Roxygenize." + @echo " build - Build source package." + @echo " quickcheck - Run check on the package." + @echo " check - Run CRAN check on the package." + @echo " install - Install the package." + +pkgfiles = DESCRIPTION \ + README.html \ + R/* \ + inst/examples/*.R \ + inst/staticdocs/index.r + +clean: + @echo "Cleaning up..." + rm -fR chents.Rcheck + @echo "DONE." + +roxygen: + @echo "Roxygenizing package..." + "$(R_HOME)/bin/Rscript" -e 'library(devtools); document(".")' 2>&1 | tee roxygen.log + @echo "DONE." + +$(TGZ): $(pkgfiles) + sed -i -e "s/Date:.*/Date: $(DATE)/" DESCRIPTION + @echo "Roxygenizing package..." + "$(R_HOME)/bin/Rscript" -e 'library(devtools); document(".")' 2>&1 | tee roxygen.log + @echo "Building package..." + git log --no-merges -M --date=iso > ChangeLog + "$(R_HOME)/bin/R" CMD build . + @echo "DONE." + +README.html: README.md + "$(R_HOME)/bin/Rscript" -e "rmarkdown::render('README.md', output_format = 'html_document')" + +build: $(TGZ) + +test: build + @echo "Running testthat tests..." + "$(R_HOME)/bin/Rscript" -e 'library(devtools); devtools::test(".")' 2>&1 | tee test.log + @echo "DONE." + +quickcheck: build + @echo "Running check..." + "$(R_HOME)/bin/R" CMD check $(TGZ) + @echo "DONE." + +check: build + @echo "Running CRAN check..." + "$(R_HOME)/bin/R" CMD check --as-cran $(TGZ) + @echo "DONE." + +install: build + @echo "Installing package..." + "$(R_HOME)/bin/R" CMD INSTALL --no-multiarch $(TGZ) + @echo "DONE." + +winbuilder: build + date + @echo "Uploading to R-release on win-builder" + curl -T $(TGZ) ftp://anonymous@win-builder.r-project.org/R-release/ + @echo "Uploading to R-devel on win-builder" + curl -T $(TGZ) ftp://anonymous@win-builder.r-project.org/R-devel/ diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..4cdb514 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,7 @@ +# Generated by roxygen2 (4.1.1): do not edit by hand + +export(chent) +export(pai) +importFrom(R6,R6Class) +importFrom(webchem,cid_compinfo) +importFrom(webchem,get_cid) diff --git a/R/chent.R b/R/chent.R new file mode 100644 index 0000000..90e3baf --- /dev/null +++ b/R/chent.R @@ -0,0 +1,154 @@ +# Copyright (C) 2015 Johannes Ranke +# Contact: jranke@uni-bremen.de +# This file is part of the R package chents + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. + +# You should have received a copy of the GNU General Public License along with +# this program. If not, see + +#' An R6 class for chemical entities with associated data +#' +#' The class is initialised with an identifier. Chemical information is retrieved +#' from the internet. +#' +#' @docType class +#' @export +#' @format An \code{\link{R6Class}} generator object +#' @importFrom R6 R6Class +#' @importFrom webchem get_cid cid_compinfo +#' @field identifier The identifier that was used to initiate the object, with attribute 'source' +#' @field inchikey InChI Key, with attribute 'source' +#' @field smiles SMILES code, with attribute 'source' +#' @field mw Molecular weight, with attribute 'source' +#' @field pubchem List of information retreived from PubChem +#' @example inst/examples/chents.R +#' @keywords data + +chent <- R6Class("chent", + public <- list( + identifier = NULL, + inchikey = NULL, + smiles = NULL, + mw = NULL, + pubchem = NULL, + initialize = function(identifier, type = c("name", "smiles"), + source = c("pubchem")) { + self$identifier <- identifier + type = match.arg(type) + attr(self$identifier, "type") <- type + source = match.arg(source) + switch(source, + pubchem = { + self$try_pubchem(identifier) + } + ) + invisible(self) + }, + try_pubchem = function(identifier) { + pubchem_cids = webchem::get_cid(identifier) + + if (is.na(pubchem_cids[1])) { + stop("Query ", identifier, " did not give results at PubChem") + } else { + message("Found ", length(pubchem_cids), " entries in PubChem, using the first one.") + self$get_pubchem(pubchem_cids[1]) + } + }, + get_pubchem = function(pubchem_cid) { + self$pubchem = webchem::cid_compinfo(pubchem_cid) + + self$smiles = self$pubchem$CanonicalSmiles + attr(self$smiles, "source") <- "pubchem" + attr(self$smiles, "type") <- "canonical" + + self$mw = as.numeric(self$pubchem$MolecularWeight) + attr(self$mw, "source") <- "pubchem" + + if (is.null(self$inchikey)) { + self$inchikey <- self$pubchem$InChIKey + attr(self$inchikey, "source") <- "pubchem" + } else { + if (self$pubchem$InChIKey != self$inchikey) { + stop("InChiKey of PubChem record does not the one retreived from ", + attr(self$inchi, "source")) + } + } + }, + show = function() { + cat(" built using $identifier", self$identifier, "\n") + cat ("InChI Key $inchikey", self$inchikey, "\n") + cat ("SMILES string $smiles", self$smiles, "\n") + if (!is.null(self$mw)) cat ("Molecular weight $mw:", round(self$mw, 1), "\n") + if (!is.null(self$pubchem)) { + cat ("PubChem synonyms (first 10):\n") + print(head(self$pubchem$synonyms, n = 10L)) + } + } + ) +) + +#' An R6 class for pesticidal active ingredients and associated data +#' +#' The class is initialised with an identifier which is generally an ISO common name. +#' Additional chemical information is retrieved from the internet. +#' +#' @docType class +#' @importFrom R6 R6Class +#' @export +#' @format An \code{\link{R6Class}} generator object +#' @field iso ISO common name according to ISO 1750 as retreived from www.alanwood.net/pesticides +#' @field alanwood List of information retreived from www.alanwood.net/pesticides +#' @example inst/examples/ai.R +#' @keywords data + +pai <- R6Class("pai", + inherit = chent, + public <- list( + iso = NULL, + alanwood = NULL, + initialize = function(identifier, type = c("name", "smiles"), + source = c("alanwood", "pubchem")) { + self$identifier <- identifier + type = match.arg(type) + attr(self$identifier, "type") <- type + source = match.arg(source) + switch(source, + alanwood = { + self$alanwood = webchem::alanwood(identifier, type = "commonname") + if (is.na(self$alanwood[1])) { + message("Common name ", identifier, " is not known at www.alanwood.net, trying PubChem") + self$try_pubchem(identifier) + } else { + self$iso = self$alanwood$cname + attr(self$iso, "source") <- "alanwood" + attr(self$iso, "status") <- self$alanwood$status + self$inchikey = self$alanwood$inchikey + attr(self$inchikey, "source") <- "alanwood" + + # Get additional information from PubChem + pubchem_cids = get_cid(identifier) + self$get_pubchem(pubchem_cids[[1]]) + } + }, + pubchem = { + self$try_pubchem(identifier) + } + ) + invisible(self) + }, + print = function() { + cat(" with ISO common name $iso", self$iso, "\n") + super$show() + } + ) +) +# vim: set ts=2 sw=2 expandtab: diff --git a/README.html b/README.html new file mode 100644 index 0000000..f10c789 --- /dev/null +++ b/README.html @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+

chents

+

The R package chents provides some utilities for working with chemical entities in R, made available under the GNU public license. This means:

+
This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see <http://www.gnu.org/licenses/>
+
+ + +
+ + + + + + + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..b0647b3 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# chents + +The R package **chents** provides some utilities for working with chemical +entities in R, made available under the GNU public license. +This means: + + This program is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see diff --git a/inst/examples/ai.R b/inst/examples/ai.R new file mode 100644 index 0000000..91b644a --- /dev/null +++ b/inst/examples/ai.R @@ -0,0 +1,2 @@ +atr <- pai$new("atrazine") +print(atr) diff --git a/inst/examples/chents.R b/inst/examples/chents.R new file mode 100644 index 0000000..7fb3286 --- /dev/null +++ b/inst/examples/chents.R @@ -0,0 +1,2 @@ +oct <- chent$new("1-octanol") +print(oct) diff --git a/inst/staticdocs/index.r b/inst/staticdocs/index.r new file mode 100644 index 0000000..83bfccd --- /dev/null +++ b/inst/staticdocs/index.r @@ -0,0 +1,5 @@ +sd_section( + "Class definitions", + "R6 classes and their methods", + c("chent", "pai") +) diff --git a/man/chent.Rd b/man/chent.Rd new file mode 100644 index 0000000..ed304f5 --- /dev/null +++ b/man/chent.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/chent.R +\docType{class} +\name{chent} +\alias{chent} +\title{An R6 class for chemical entities with associated data} +\format{An \code{\link{R6Class}} generator object} +\usage{ +chent +} +\description{ +The class is initialised with an identifier. Chemical information is retrieved +from the internet. +} +\section{Fields}{ + +\describe{ +\item{\code{identifier}}{The identifier that was used to initiate the object, with attribute 'source'} + +\item{\code{inchikey}}{InChI Key, with attribute 'source'} + +\item{\code{smiles}}{SMILES code, with attribute 'source'} + +\item{\code{mw}}{Molecular weight, with attribute 'source'} + +\item{\code{pubchem}}{List of information retreived from PubChem} +}} +\examples{ +oct <- chent$new("1-octanol") +print(oct) +} +\keyword{data} + diff --git a/man/pai.Rd b/man/pai.Rd new file mode 100644 index 0000000..c366991 --- /dev/null +++ b/man/pai.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/chent.R +\docType{class} +\name{pai} +\alias{pai} +\title{An R6 class for pesticidal active ingredients and associated data} +\format{An \code{\link{R6Class}} generator object} +\usage{ +pai +} +\description{ +The class is initialised with an identifier which is generally an ISO common name. +Additional chemical information is retrieved from the internet. +} +\section{Fields}{ + +\describe{ +\item{\code{iso}}{ISO common name according to ISO 1750 as retreived from www.alanwood.net/pesticides} + +\item{\code{alanwood}}{List of information retreived from www.alanwood.net/pesticides} +}} +\examples{ +atr <- pai$new("atrazine") +print(atr) +} +\keyword{data} + diff --git a/roxygen.log b/roxygen.log new file mode 100644 index 0000000..f691b87 --- /dev/null +++ b/roxygen.log @@ -0,0 +1,4 @@ +Updating chents documentation +Loading chents +Writing chent.Rd +Writing pai.Rd -- cgit v1.2.1