The Role of S4 in Bioconductor

Introduction to Bioconductor in R

James Chapman

Curriculum Manager, DataCamp

S3

Positive

  • CRAN, simple but powerful
  • Flexible and interactive
  • Uses a generic function
  • Functionality depends on the first argument
  • Example: plot() and methods(plot)

Negative

  • Bad at validating types and naming conventions (dot not dot?)
  • Inheritance works, but depends on the input
Introduction to Bioconductor in R

S4

Positive

  • Formal definition of classes
  • Bioconductor reusability
  • Has validation of types
  • Naming conventions

Example: myDescriptor <- new("GenomeDescription")

Negative

  • Complex structure compared to S3
Introduction to Bioconductor in R

Is it S4 or not?

Ask if an object is S4

isS4(myDescriptor)
TRUE

str of S4 objects start with Formal class

str(myDescriptor)
Formal class 'GenomeDescription' [package "GenomeInfoDb"] with 7 slots
...
Introduction to Bioconductor in R

S4 class definition

A class describes a representation

  • name
  • slots (methods/fields)
  • contains (inheritance definition)
MyEpicProject <- setClass(# Define class name with UpperCamelCase
                          "MyEpicProject",
                          # Define slots, helpful for validation
                          slots = c(ini = "Date", 
                                    end = "Date", 
                                    milestone = "character"),
                          # Define inheritance        
                          contains = "MyProject")
Introduction to Bioconductor in R
.S4methods(class = "GenomeDescription")
 [1] coerce          commonName      organism        provider       
 [5] providerVersion releaseDate     releaseName     seqinfo        
 [9] seqnames        show            toString        bsgenomeName   
see '?methods' for accessing help and source code
showMethods(classes = "GenomeDescription", where = search())

Object summary

show(myDescriptor)
| organism:  ()
| provider: 
| provider version: 
| release date: 
| release name: 
| ---
| seqlengths:
Introduction to Bioconductor in R

Let's practice!

Introduction to Bioconductor in R

Preparing Video For Download...