SynergyScreen is an R package that I have developed to facilitate design and analysis of medium-throughput compound synergy screens using single-ray design. These slides describe the functionality of the package and R programming techniques. These slides were presented at Madison R Meet-up (MadR) on 18 January 2017.
4. How to Make Biofuels
www.glbrc.org
4
HydrolysateBiomass
Microbes
Fuel
Problem: hydrolysate
contains compounds
that are toxic to
microbes
5. What is Synergy?
Synergy is “the interaction or cooperation of
two or more organizations, substances, or
other agents to produce a combined effect
greater than the sum of their separate
effects” (Google)
Synergy is when the effect of two toxins is
greater than expected when they do not
interact
The opposite of synergy is called antagonism
www.glbrc.org
5
6. The Isobole Method
Interaction Index: 𝐼 =
𝑑 𝐴
𝐷 𝐴
+
𝑑 𝐵
𝐷 𝐵
www.glbrc.org
6
No interaction: I = 1 Synergy: I < 1 Antagonism: I > 1
15. S4 Classes
Why use classes? As opposed to (nested) lists and data
frames?
Constrain and validate contents of objects
Define custom show, plot and other methods
Inheritance
[At least] 3 OOP systems in R: S3, S4 and RC
S4 is recommended by Bioconductor project
S4 learning resources
Hadley Wickham, Advanced R, OO field guide, S4: http://adv-
r.had.co.nz/OO-essentials.html#s4
John Chambers’ Software for Data Analysis
S4 system development in Bioconductor
My S4 slides: http://rpubs.com/ybukhman/intro_to_S4
www.glbrc.org
15
16. Synergy Screen Structure
Synergy screen
Compounds
Experimental design
Raw data
Normalized data
Dose-response experiments
• Compounds; doses; responses; models
Synergy experiments
• Dose-response experiments
Interaction index values
www.glbrc.org
16
21. Debug a method
www.glbrc.org
21
I know this is a hack. However, in my hands, setting break points in
Rstudio or using trace() did not consistently work.
22. An S4 class that extends list
How: use contains argument with setClass
Why: constrain list elements, e.g. to be of the same
class, DRE
www.glbrc.org
22
setClass("DREList", contains="list",
validity=function(object) {
checks = sapply(object, is, "DRE")
if(!all(checks)) {
return(paste("The following elements are not of class DRE:",
paste(object[!checks], collapse="; ")))
}
# Check names
cnames = sapply(object, function(x) x@name)
if (is.null(names(object)) || any(names(object) != cnames){
return("Inconsistent names")
}
# All done
return(TRUE)
}
)
25. Why develop a package?
Users can download and install your software
using standard procedures
Provide documentation for your software
Provide example dataset(s)
Submit your code to CRAN or Bioconductor
Publish a paper
www.glbrc.org
25
26. Initialize a new R package
Create a new package from an R session:
devtools::create(“MyNewPackage”)
Initialize a project at a git or SVN server
Edit DESCRIPTION
Let roxygen2 generate and manage NAMESPACE
Add a package documentation file, e.g. MyNewPackage.R
Start writing a vignette:
devtools::use_vignette(“my-first-
vignette”)
www.glbrc.org
26
27. DESCRIPTION
Information about your package and its
maintainer
License
List of other packages that your package
needs to function
Information on how to collate files in your
package (autogenerated by roxygen2)
www.glbrc.org
27
28. Package structure
Project root folder: DESCRIPTION, NAMESPACE,
.gitignore, .Rbuildignore, RStudio project file
(SynergyScreen.Rproj)
Subfolders
R – .R files that contain functions, classes, methods etc.
man – help pages (.Rd)
data - datasets
tests – test scripts
vignettes – long-form documentation using R markdown
inst – other stuff, e.g. raw data files, one-off scripts etc.
www.glbrc.org
28
29. Document your package
Use roxygen2 to parse specially formatted
comments and generate documentation (.Rd)
files
Write long form documentation in the form
of vignettes
www.glbrc.org
29
36. Organize code and
documentation files
Organize by generic function
Organize by class
Use @include tags to specify collation
order
Put data documentation in data.R
www.glbrc.org
36
37. Namespace
Why namespaces?
Avoid confusion when different packages define functions that have
the same name
Import functions from other packages
Export functions from your package to make them accessible to others
Poor practice
Edit file NAMESPACE manually
Export everything
www.glbrc.org
37
38. Good Practice
Read Hadley’s book, http://r-
pkgs.had.co.nz/namespace.html
Let roxygen2 generate the NAMESPACE file
For imports:
List packages under Imports field in DESCRIPTION
Call functions explicitly by package::function
For frequently used functions, use @importFrom package
function
To import all functions from a package, use @import package
For exports:
use the @export tag to export functions, classes and methods
Datasets are exported automatically: no need for @export
www.glbrc.org
38
40. Tests
Why test? Verify that new edits do not inadvertently damage
previously developed functionality.
Use package testthat. Read Hadley’s book: http://r-
pkgs.had.co.nz/tests.html
Do a package check or just run the tests. The former also
checks syntax, documentation etc.
www.glbrc.org
40