R libraries and Bioconductor

Packages and Libraries

R is at heart a collection of ‘packages’. There is a ‘base’ system that contains the truly basic commands, such as the assignment operator -> or the command to create a vector. In addition to that, there are ‘standard R’ packages that are included when you install the R kernel (in the Jupyter notebook), or ‘R’ as a program to run either at the command line or with Rstudio. (I’ve shown some examples of these different ways to run R in class).

Libraries

Many packages, even those included in [standard R] (https://www.r-project.org/), will need to be ‘loaded’ to be used. In other words, they exist on your computer (or in your container), but the R kernel doesn’t know about them. This is because if it did, R would be using computer memory (RAM) to remember all their functions and variables. If all the available packages were loaded, you might not have any RAM left!

A consequence of this is that you often have to tell R explicitly that you want to use a particular package. You do that using library. Let’s read in the titanic data set to have something to play with.

[1]:
titanic <- read.csv("titanic.csv")
[2]:
head(titanic)
A data.frame: 6 × 7
XNamePClassAgeSexSurvivedSexCode
<int><fct><fct><dbl><fct><int><int>
1Allen, Miss Elisabeth Walton 1st29.00female11
2Allison, Miss Helen Loraine 1st 2.00female01
3Allison, Mr Hudson Joshua Creighton 1st30.00male 00
4Allison, Mrs Hudson JC (Bessie Waldo Daniels)1st25.00female01
5Allison, Master Hudson Trevor 1st 0.92male 10
6Anderson, Mr Harry 1st47.00male 10

There is a cool R function that will allow us to look at some random rows from a data frame. It’s called sample_n. Let’s try it:

[3]:
sample_n(titanic, 10)
Error in sample_n(titanic, 10): could not find function "sample_n"
Traceback:

Oops. It turns out sample_n is in the dplyr package. It’s installed in your container - but R doesn’t know that! Let’s tell R we want to use it:

[4]:
library(dplyr)

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

[5]:
sample_n(titanic, 10)
A data.frame: 10 × 7
XNamePClassAgeSexSurvivedSexCode
<int><fct><fct><dbl><fct><int><int>
304Geiger, Miss Emily 1stNAfemale11
675Birkeland, Mr Hans 3rd21male 00
555Sincock, Miss Maude 2nd20female11
52Case, Mr Howard Brown 1st49male 00
125Greenfield, Mrs Leo David (Blanche Strouse)1st45female11
427Harbeck, Mr William H 2nd44male 00
195Ostby, Miss Helen Raghnild 1st22female11
1183Salkjelsvik, Miss Anna 3rdNAfemale11
953Leeni, Mr Fahim 3rdNAmale 10
935Kink, Miss Maria 3rd22female01

Installed and installing packages

Now, dplyr is actually not part of standard R. It’s installed separately. There are a multitude of R packages out there. Anyone can write one (yes, even you!!!). They are shared with the public using the [CRAN archive.] (https://cran.r-project.org/) In order to be listed in CRAN, packages need to meet specific criteria for documentation purposes, testing, etc.

You can check to see what packages are installed using installed.packages()

[6]:
installed.packages()
A matrix: 304 × 16 of type chr
PackageLibPathVersionPriorityDependsImportsLinkingToSuggestsEnhancesLicenseLicense_is_FOSSLicense_restricts_useOS_typeMD5sumNeedsCompilationBuilt
countrycodecountrycode /home/jovyan/R/x86_64-pc-linux-gnu-library/3.61.1.0 NAR (>= 2.10) NA NA testthat (>= 0.5) NA GPL-3 NANANANAno 3.6.0
acepackacepack /usr/local/lib/R/site-library 1.4.1 NANA NA NA testthat NA MIT + file LICENSENANANANAyes3.6.0
ade4ade4 /usr/local/lib/R/site-library 1.7-13 NAR (>= 2.10) graphics, grDevices, methods, stats, utils, MASS NA ade4TkGUI, adegraphics, adephylo, ape, CircStats, deldir, lattice, pixmap, sp, spdep, splancs, waveslim NA GPL (>= 2) NANANANAyes3.6.0
airwayairway /usr/local/lib/R/site-library 1.4.0 NAR (>= 2.10), SummarizedExperiment NA NA knitr, GEOquery NA LGPL NANANANAno 3.6.0
annotateannotate /usr/local/lib/R/site-library 1.62.0 NAR (>= 2.10), AnnotationDbi (>= 1.27.5), XML Biobase, DBI, xtable, graphics, utils, stats, methods, BiocGenerics (>= 0.13.8), RCurl NA hgu95av2.db, genefilter, Biostrings (>= 2.25.10), IRanges, rae230a.db, rae230aprobe, tkWidgets, GO.db, org.Hs.eg.db, org.Mm.eg.db, hom.Hs.inp.db, humanCHRLOC, Rgraphviz, RUnit, NA Artistic-2.0 NANANANAno 3.6.0
AnnotationDbiAnnotationDbi /usr/local/lib/R/site-library 1.46.0 NAR (>= 2.7.0), methods, utils, stats4, BiocGenerics (>= 0.29.2), Biobase (>= 1.17.0), IRanges DBI, RSQLite, S4Vectors (>= 0.9.25) NA hgu95av2.db, GO.db, org.Sc.sgd.db, org.At.tair.db, KEGG.db, RUnit, TxDb.Hsapiens.UCSC.hg19.knownGene, hom.Hs.inp.db, org.Hs.eg.db, reactome.db, AnnotationForge, graph, EnsDb.Hsapiens.v75, BiocStyle, knitr NA Artistic-2.0 NANANANAno 3.6.0
AnnotationFilterAnnotationFilter/usr/local/lib/R/site-library 1.8.0 NAR (>= 3.4.0) utils, methods, GenomicRanges, lazyeval NA BiocStyle, knitr, testthat, RSQLite, org.Hs.eg.db NA Artistic-2.0 NANANANAno 3.6.0
apeape /usr/local/lib/R/site-library 5.3 NAR (>= 3.2.0) nlme, lattice, graphics, methods, stats, tools, utils, parallel, Rcpp (>= 0.12.0) Rcpp gee, expm, igraph NA GPL (>= 2) NANANANAyes3.6.0
askpassaskpass /usr/local/lib/R/site-library 1.1 NANA sys (>= 2.1) NA testthat NA MIT + file LICENSENANANANAyes3.6.0
assertthatassertthat /usr/local/lib/R/site-library 0.2.1 NANA tools NA testthat, covr NA GPL-3 NANANANAno 3.6.0
backportsbackports /usr/local/lib/R/site-library 1.1.4 NAR (>= 3.0.0) utils NA NA NA GPL-2 NANANANAyes3.6.0
base64encbase64enc /usr/local/lib/R/site-library 0.1-3 NAR (>= 2.9.0) NA NA NA png GPL-2 | GPL-3 NANANANAyes3.6.0
BHBH /usr/local/lib/R/site-library 1.69.0-1NANA NA NA NA NA BSL-1.0 NANANANAno 3.6.0
BiobaseBiobase /usr/local/lib/R/site-library 2.44.0 NAR (>= 2.10), BiocGenerics (>= 0.27.1), utils methods NA tools, tkWidgets, ALL, RUnit, golubEsets NA Artistic-2.0 NANANANAyes3.6.0
BiocGenericsBiocGenerics /usr/local/lib/R/site-library 0.30.0 NAR (>= 3.6.0), methods, utils, graphics, stats, parallel methods, utils, graphics, stats, parallel NA Biobase, S4Vectors, IRanges, GenomicRanges, Rsamtools, AnnotationDbi, oligoClasses, oligo, affyPLM, flowClust, affy, DESeq2, MSnbase, annotate, RUnit NA Artistic-2.0 NANANANAno 3.6.0
BiocManagerBiocManager /usr/local/lib/R/site-library 1.30.4 NAR (>= 3.5.0) utils NA BiocStyle, BiocVersion, remotes, testthat, knitr, withr NA Artistic-2.0 NANANANAno 3.6.0
BiocParallelBiocParallel /usr/local/lib/R/site-library 1.18.0 NAmethods stats, utils, futile.logger, parallel, snow BH BiocGenerics, tools, foreach, BatchJobs, BBmisc, doParallel, Rmpi, GenomicRanges, RNAseqData.HNRNPC.bam.chr14, TxDb.Hsapiens.UCSC.hg19.knownGene, VariantAnnotation, Rsamtools, GenomicAlignments, ShortRead, codetools, RUnit, BiocStyle, knitr, batchtools, data.table NA GPL-2 | GPL-3 NANANANAyes3.6.0
BiocVersionBiocVersion /usr/local/lib/R/site-library 3.9.0 NAR (>= 3.6.0), R (< 3.7.0) NA NA NA NA Artistic-2.0 NANANANAno 3.6.0
biomaRtbiomaRt /usr/local/lib/R/site-library 2.40.0 NAmethods utils, XML, RCurl, AnnotationDbi, progress, stringr, httr NA annotate, BiocStyle, knitr, rmarkdown, testthat NA Artistic-2.0 NANANANAno 3.6.0
biomformatbiomformat /usr/local/lib/R/site-library 1.12.0 NAR (>= 3.2), methods plyr (>= 1.8), jsonlite (>= 0.9.16), Matrix (>= 1.2), rhdf5 NA testthat (>= 0.10), knitr (>= 1.10), BiocStyle (>= 1.6), rmarkdown (>= 0.7) NA GPL-2 NANANANAno 3.6.0
BiostringsBiostrings /usr/local/lib/R/site-library 2.52.0 NAR (>= 3.5.0), methods, BiocGenerics, S4Vectors (>= 0.21.13), IRanges, XVector (>= 0.23.2) graphics, methods, stats, utils S4Vectors, IRanges, XVectorBSgenome (>= 1.13.14), BSgenome.Celegans.UCSC.ce2 (>= 1.3.11), BSgenome.Dmelanogaster.UCSC.dm3 (>= 1.3.11), BSgenome.Hsapiens.UCSC.hg18, drosophila2probe, hgu95av2probe, hgu133aprobe, GenomicFeatures (>= 1.3.14), hgu95av2cdf, affy (>= 1.41.3), affydata (>= 1.11.5), RUnit RmpiArtistic-2.0 NANANANAyes3.6.0
biovizBasebiovizBase /usr/local/lib/R/site-library 1.32.0 NAR (>= 2.10), methods grDevices, stats, scales, Hmisc, RColorBrewer, dichromat, BiocGenerics, S4Vectors (>= 0.9.25), IRanges (>= 1.99.28), GenomeInfoDb (>= 1.5.14), GenomicRanges (>= 1.23.21), SummarizedExperiment, Biostrings (>= 2.33.11), Rsamtools (>= 1.17.28), GenomicAlignments (>= 1.1.16), GenomicFeatures (>= 1.21.19), AnnotationDbi, VariantAnnotation (>= 1.11.4), ensembldb (>= 1.99.13), AnnotationFilter (>= 0.99.8), rlangNA BSgenome.Hsapiens.UCSC.hg19, TxDb.Hsapiens.UCSC.hg19.knownGene, BSgenome, rtracklayer, EnsDb.Hsapiens.v75, RUnit NA Artistic-2.0 NANANANAyes3.6.0
bitbit /usr/local/lib/R/site-library 1.1-14 NAR (>= 2.9.2) NA NA NA NA GPL-2 NANANANAyes3.6.0
bit64bit64 /usr/local/lib/R/site-library 0.9-7 NAR (>= 3.0.1), bit (>= 1.1-12), utils, methods, stats NA NA NA NA GPL-2 NANANANAyes3.6.0
bitopsbitops /usr/local/lib/R/site-library 1.0-6 NANA NA NA NA NA GPL (>= 2) NANANANAyes3.6.0
blobblob /usr/local/lib/R/site-library 1.1.1 NANA methods, prettyunits NA covr, pillar (>= 1.2.1), testthat NA GPL-3 NANANANAno 3.6.0
broombroom /usr/local/lib/R/site-library 0.5.2 NAR (>= 3.1) backports, dplyr, generics (>= 0.0.2), methods, nlme, purrr, reshape2, stringr, tibble, tidyr NA AER, akima, AUC, bbmle, betareg, biglm, binGroup, boot, brms, btergm, car, caret, coda, covr, e1071, emmeans, ergm, gam (>= 1.15), gamlss, gamlss.data, gamlss.dist, geepack, ggplot2, glmnet, gmm, Hmisc, irlba, joineRML, Kendall, knitr, ks, Lahman, lavaan, lfe, lme4, lmodel2, lmtest, lsmeans, maps, maptools, MASS, Matrix, mclust, mgcv, muhaz, multcomp, network, nnet, orcutt (>= 2.2), ordinal, plm, plyr, poLCA, psych, quantreg, rgeos, rmarkdown, robust, rsample, rstan, rstanarm, sp, speedglm, statnet.common, survey, survival, testthat, tseries, xergm, zooNA MIT + file LICENSENANANANAno 3.6.0
BSgenomeBSgenome /usr/local/lib/R/site-library 1.52.0 NAR (>= 2.8.0), methods, BiocGenerics (>= 0.13.8), S4Vectors (>= 0.17.28), IRanges (>= 2.13.16), GenomeInfoDb (>= 1.15.2), GenomicRanges (>= 1.31.10), Biostrings (>= 2.47.6), rtracklayer (>= 1.39.7)methods, utils, stats, BiocGenerics, S4Vectors, IRanges, XVector, GenomeInfoDb, GenomicRanges, Biostrings, Rsamtools, rtracklayer NA BiocManager, Biobase, BSgenome.Celegans.UCSC.ce2, BSgenome.Hsapiens.UCSC.hg38, BSgenome.Hsapiens.UCSC.hg38.masked, BSgenome.Mmusculus.UCSC.mm10, BSgenome.Rnorvegicus.UCSC.rn5, BSgenome.Scerevisiae.UCSC.sacCer1, TxDb.Hsapiens.UCSC.hg38.knownGene, TxDb.Mmusculus.UCSC.mm10.knownGene, SNPlocs.Hsapiens.dbSNP144.GRCh38, XtraSNPlocs.Hsapiens.dbSNP144.GRCh38, hgu95av2probe, RUnit NA Artistic-2.0 NANANANAno 3.6.0
callrcallr /usr/local/lib/R/site-library 3.2.0 NANA processx (>= 3.3.0), R6, utils NA cliapp, covr, crayon, pingr, ps, testthat, withr NA MIT + file LICENSENANANANAno 3.6.0
caretcaret /usr/local/lib/R/site-library 6.0-84 NAR (>= 3.2.0), lattice (>= 0.20), ggplot2 foreach, methods, plyr, ModelMetrics (>= 1.1.0), nlme, reshape2, stats, stats4, utils, grDevices, recipes (>= 0.1.4), withr (>= 2.0.0) NA BradleyTerry2, e1071, earth (>= 2.2-3), fastICA, gam (>= 1.15), ipred, kernlab, knitr, klaR, MASS, ellipse, mda, mgcv, mlbench, MLmetrics, nnet, party (>= 0.9-99992), pls, pROC, proxy, randomForest, RANN, spls, subselect, pamr, superpc, Cubist, testthat (>= 0.9.1), rpart, dplyr NA GPL (>= 2) NANANANAyes3.6.0
zoozoo /usr/local/lib/R/site-library1.8-6 NA R (>= 3.1.0), stats utils, graphics, grDevices, lattice (>= 0.20-27)NAcoda, chron, DAAG, fts, ggplot2, mondate, scales, strucchange, timeDate, timeSeries, tis, tseries, xtsNA GPL-2 | GPL-3 NANANANAyes3.6.0
basebase /usr/lib/R/library 3.6.0 base NA NA NAmethods NA Part of R 3.6.0 NANANANANA 3.6.0
bootboot /usr/lib/R/library 1.3-20 recommendedR (>= 3.0.0), graphics, stats NA NAMASS, survival NA Unlimited NANANANAno 3.5.1
classclass /usr/lib/R/library 7.3-15 recommendedR (>= 3.0.0), stats, utils MASS NANA NA GPL-2 | GPL-3 NANANANAyes3.6.0
clustercluster /usr/lib/R/library 2.0.8 recommendedR (>= 3.3.0) graphics, grDevices, stats, utils NAMASS, Matrix NA GPL (>= 2) NANANANAyes3.6.0
codetoolscodetools /usr/lib/R/library 0.2-16 recommendedR (>= 2.1) NA NANA NA GPL NANANANAno 3.5.3
compilercompiler /usr/lib/R/library 3.6.0 base NA NA NANA NA Part of R 3.6.0 NANANANANA 3.6.0
datasetsdatasets /usr/lib/R/library 3.6.0 base NA NA NANA NA Part of R 3.6.0 NANANANANA 3.6.0
foreignforeign /usr/lib/R/library 0.8-71 recommendedR (>= 3.0.0) methods, utils, stats NANA NA GPL (>= 2) NANANANAyes3.6.0
graphicsgraphics /usr/lib/R/library 3.6.0 base NA grDevices NANA NA Part of R 3.6.0 NANANANAyes3.6.0
grDevicesgrDevices /usr/lib/R/library 3.6.0 base NA NA NAKernSmooth NA Part of R 3.6.0 NANANANAyes3.6.0
gridgrid /usr/lib/R/library 3.6.0 base NA grDevices, utils NAlattice NA Part of R 3.6.0 NANANANAyes3.6.0
KernSmoothKernSmooth/usr/lib/R/library 2.23-15 recommendedR (>= 2.5.0), stats NA NAMASS NA Unlimited NANANANAyes3.6.0
latticelattice /usr/lib/R/library 0.20-38 recommendedR (>= 3.0.0) grid, grDevices, graphics, stats, utils NAKernSmooth, MASS, latticeExtra chron GPL (>= 2) NANANANAyes3.6.0
MASSMASS /usr/lib/R/library 7.3-51.3recommendedR (>= 3.1.0), grDevices, graphics, stats, utilsmethods NAlattice, nlme, nnet, survival NA GPL-2 | GPL-3 NANANANAyes3.6.0
MatrixMatrix /usr/lib/R/library 1.2-17 recommendedR (>= 3.2.0) methods, graphics, grid, stats, utils, lattice NAexpm, MASS MatrixModels, graph, SparseM, sfsmiscGPL (>= 2) | file LICENCENANANANAyes3.6.0
methodsmethods /usr/lib/R/library 3.6.0 base NA utils, stats NAcodetools NA Part of R 3.6.0 NANANANAyes3.6.0
mgcvmgcv /usr/lib/R/library 1.8-28 recommendedR (>= 2.14.0), nlme (>= 3.1-64) methods, stats, graphics, Matrix, splines, utilsNAparallel, survival, MASS NA GPL (>= 2) NANANANAyes3.6.0
nlmenlme /usr/lib/R/library 3.1-139 recommendedR (>= 3.4.0) graphics, stats, utils, lattice NAHmisc, MASS NA GPL (>= 2) | file LICENCENANANANAyes3.6.0
nnetnnet /usr/lib/R/library 7.3-12 recommendedR (>= 2.14.0), stats, utils NA NAMASS NA GPL-2 | GPL-3 NANANANAyes3.6.0
parallelparallel /usr/lib/R/library 3.6.0 base NA tools, compiler NAmethods snow, nws, Rmpi Part of R 3.6.0 NANANANAyes3.6.0
rpartrpart /usr/lib/R/library 4.1-15 recommendedR (>= 2.15.0), graphics, stats, grDevices NA NAsurvival NA GPL-2 | GPL-3 NANANANAyes3.6.0
spatialspatial /usr/lib/R/library 7.3-11 recommendedR (>= 3.0.0), graphics, stats, utils NA NAMASS NA GPL-2 | GPL-3 NANANANAyes3.6.0
splinessplines /usr/lib/R/library 3.6.0 base NA graphics, stats NAMatrix, methods NA Part of R 3.6.0 NANANANAyes3.6.0
statsstats /usr/lib/R/library 3.6.0 base NA utils, grDevices, graphics NAMASS, Matrix, SuppDists, methods, stats4 NA Part of R 3.6.0 NANANANAyes3.6.0
stats4stats4 /usr/lib/R/library 3.6.0 base NA graphics, methods, stats NANA NA Part of R 3.6.0 NANANANANA 3.6.0
survivalsurvival /usr/lib/R/library 2.44-1.1recommendedR (>= 2.13.0) graphics, Matrix, methods, splines, stats, utilsNANA NA LGPL (>= 2) NANANANAyes3.6.0
tcltktcltk /usr/lib/R/library 3.6.0 base NA utils NANA NA Part of R 3.6.0 NANANANAyes3.6.0
toolstools /usr/lib/R/library 3.6.0 base NA NA NAcodetools, methods, xml2, curl, commonmark NA Part of R 3.6.0 NANANANAyes3.6.0
utilsutils /usr/lib/R/library 3.6.0 base NA NA NAmethods, xml2, commonmark NA Part of R 3.6.0 NANANANAyes3.6.0

You can install new packages using the command install.packages()

[7]:
install.packages("auk", lib = "~/work")
[8]:
.libPaths("~/work")
library(auk)
auk 0.3.3 is designed for EBD files downloaded after 2018-08-15.
No EBD data directory set, see ?auk_set_ebd_path to set EBD_PATH
eBird taxonomy version:  2018
[9]:
remove.packages("auk")
Removing package from ‘/home/jovyan/work’
(as ‘lib’ is unspecified)

BioConductor

CRAN is home to many, many R packages. But there is a whole other world out there when it comes to bioinformatics in R. It’s called BioConductor. BioConductor is a comprehensive toolkit for all things having to do with high-throughput sequencing data processing and analysis. In this course, we will use the BioConductor package DESeq2 to perform differential expression analysis. It’s the end of the pipeline, after QC, clipping and trimming, aligning and counting.

Installing BioConductor packages

BioConductor has it’s own installation procedure (and it’s own criteria for documentation, testing, etc.) - separate from CRAN. Let’s have a look at the page for DESeq2

[10]:
#source("https://bioconductor.org/biocLite.R")
#biocLite("DESeq2")

DESeq2 and S4 Objects

We’ll walk through an example using a sample data set called ‘airway’. Airway is an object of type ‘SummarizedExperiment’. This kind of object is the basis for many objects used in Bioconductor packages.

[11]:
library("airway")
data("airway")
se <- airway
Loading required package: SummarizedExperiment
Loading required package: GenomicRanges
Loading required package: stats4
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: ‘BiocGenerics’

The following objects are masked from ‘package:parallel’:

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from ‘package:dplyr’:

    combine, intersect, setdiff, union

The following objects are masked from ‘package:stats’:

    IQR, mad, sd, var, xtabs

The following objects are masked from ‘package:base’:

    anyDuplicated, append, as.data.frame, basename, cbind, colnames,
    dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
    grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which, which.max, which.min

Loading required package: S4Vectors

Attaching package: ‘S4Vectors’

The following objects are masked from ‘package:dplyr’:

    first, rename

The following object is masked from ‘package:base’:

    expand.grid

Loading required package: IRanges

Attaching package: ‘IRanges’

The following objects are masked from ‘package:dplyr’:

    collapse, desc, slice

Loading required package: GenomeInfoDb
Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Loading required package: DelayedArray
Loading required package: matrixStats

Attaching package: ‘matrixStats’

The following objects are masked from ‘package:Biobase’:

    anyMissing, rowMedians

The following object is masked from ‘package:dplyr’:

    count

Loading required package: BiocParallel

Attaching package: ‘DelayedArray’

The following objects are masked from ‘package:matrixStats’:

    colMaxs, colMins, colRanges, rowMaxs, rowMins, rowRanges

The following objects are masked from ‘package:base’:

    aperm, apply, rowsum

[12]:
str(se)
Formal class 'RangedSummarizedExperiment' [package "SummarizedExperiment"] with 6 slots
  ..@ rowRanges      :Formal class 'GRangesList' [package "GenomicRanges"] with 5 slots
  .. .. ..@ unlistData     :Formal class 'GRanges' [package "GenomicRanges"] with 7 slots
Warning message:
“Not a validObject(): no slot of name "elementType" for this object of class "GRanges"”
  .. .. .. .. ..@ seqnames       :Formal class 'Rle' [package "S4Vectors"] with 4 slots
  .. .. .. .. .. .. ..@ values         : Factor w/ 722 levels "1","2","3","4",..: 23 20 1 6 1 23 6 3 7 12 ...
  .. .. .. .. .. .. ..@ lengths        : int [1:47916] 27 29 173 80 75 27 4 41 196 71 ...
  .. .. .. .. .. .. ..@ elementMetadata: NULL
  .. .. .. .. .. .. ..@ metadata       : list()
  .. .. .. .. ..@ strand         :Formal class 'Rle' [package "S4Vectors"] with 4 slots
  .. .. .. .. .. .. ..@ values         : Factor w/ 3 levels "+","-","*": 2 1 2 1 2 1 2 1 2 1 ...
  .. .. .. .. .. .. ..@ lengths        : int [1:31658] 17 10 59 72 26 45 68 12 42 33 ...
  .. .. .. .. .. .. ..@ elementMetadata: NULL
  .. .. .. .. .. .. ..@ metadata       : list()
  .. .. .. .. ..@ ranges         :Formal class 'IRanges' [package "IRanges"] with 6 slots
  .. .. .. .. .. .. ..@ start          : int [1:745593] 99883667 99885756 99887482 99887538 99888402 99888402 99888439 99888928 99888928 99890175 ...
  .. .. .. .. .. .. ..@ width          : int [1:745593] 1317 108 84 28 135 135 98 99 99 75 ...
  .. .. .. .. .. .. ..@ NAMES          : NULL
  .. .. .. .. .. .. ..@ elementType    : chr "integer"
  .. .. .. .. .. .. ..@ elementMetadata: NULL
  .. .. .. .. .. .. ..@ metadata       : list()
  .. .. .. .. ..@ elementMetadata:Formal class 'DataFrame' [package "IRanges"] with 6 slots
  .. .. .. .. .. .. ..@ rownames       : NULL
  .. .. .. .. .. .. ..@ nrows          : int 745593
  .. .. .. .. .. .. ..@ listData       :List of 2
  .. .. .. .. .. .. .. ..$ exon_id  : int [1:745593] 667145 667146 667147 667148 667149 667150 667151 667153 667152 667154 ...
  .. .. .. .. .. .. .. ..$ exon_name: chr [1:745593] "ENSE00001459322" "ENSE00000868868" "ENSE00000401072" "ENSE00001849132" ...
  .. .. .. .. .. .. ..@ elementType    : chr "ANY"
  .. .. .. .. .. .. ..@ elementMetadata: NULL
  .. .. .. .. .. .. ..@ metadata       : list()
  .. .. .. .. ..@ seqinfo        :Formal class 'Seqinfo' [package "GenomeInfoDb"] with 4 slots
  .. .. .. .. .. .. ..@ seqnames   : chr [1:722] "1" "2" "3" "4" ...
  .. .. .. .. .. .. ..@ seqlengths : int [1:722] 249250621 243199373 198022430 191154276 180915260 171115067 159138663 146364022 141213431 135534747 ...
  .. .. .. .. .. .. ..@ is_circular: logi [1:722] FALSE FALSE FALSE FALSE FALSE FALSE ...
  .. .. .. .. .. .. ..@ genome     : chr [1:722] NA NA NA NA ...
  .. .. .. .. ..@ metadata       : list()
  .. .. .. .. ..@ NA             : NULL
  .. .. ..@ elementMetadata:Formal class 'DataFrame' [package "IRanges"] with 6 slots
  .. .. .. .. ..@ rownames       : NULL
  .. .. .. .. ..@ nrows          : int 64102
  .. .. .. .. ..@ listData       : Named list()
  .. .. .. .. ..@ elementType    : chr "ANY"
  .. .. .. .. ..@ elementMetadata: NULL
  .. .. .. .. ..@ metadata       : list()
  .. .. ..@ elementType    : chr "GRanges"
  .. .. ..@ metadata       :List of 1
  .. .. .. ..$ genomeInfo:List of 20
  .. .. .. .. ..$ Db type                                 : chr "TranscriptDb"
  .. .. .. .. ..$ Supporting package                      : chr "GenomicFeatures"
  .. .. .. .. ..$ Data source                             : chr "BioMart"
  .. .. .. .. ..$ Organism                                : chr "Homo sapiens"
  .. .. .. .. ..$ Resource URL                            : chr "www.biomart.org:80"
  .. .. .. .. ..$ BioMart database                        : chr "ensembl"
  .. .. .. .. ..$ BioMart database version                : chr "ENSEMBL GENES 75 (SANGER UK)"
  .. .. .. .. ..$ BioMart dataset                         : chr "hsapiens_gene_ensembl"
  .. .. .. .. ..$ BioMart dataset description             : chr "Homo sapiens genes (GRCh37.p13)"
  .. .. .. .. ..$ BioMart dataset version                 : chr "GRCh37.p13"
  .. .. .. .. ..$ Full dataset                            : chr "yes"
  .. .. .. .. ..$ miRBase build ID                        : chr NA
  .. .. .. .. ..$ transcript_nrow                         : chr "215647"
  .. .. .. .. ..$ exon_nrow                               : chr "745593"
  .. .. .. .. ..$ cds_nrow                                : chr "537555"
  .. .. .. .. ..$ Db created by                           : chr "GenomicFeatures package from Bioconductor"
  .. .. .. .. ..$ Creation time                           : chr "2014-07-10 14:55:55 -0400 (Thu, 10 Jul 2014)"
  .. .. .. .. ..$ GenomicFeatures version at creation time: chr "1.17.9"
  .. .. .. .. ..$ RSQLite version at creation time        : chr "0.11.4"
  .. .. .. .. ..$ DBSCHEMAVERSION                         : chr "1.0"
  .. .. ..@ partitioning   :Formal class 'PartitioningByEnd' [package "IRanges"] with 5 slots
  .. .. .. .. ..@ end            : int [1:64102] 17 27 56 86 158 184 229 243 297 309 ...
  .. .. .. .. ..@ NAMES          : chr [1:64102] "ENSG00000000003" "ENSG00000000005" "ENSG00000000419" "ENSG00000000457" ...
  .. .. .. .. ..@ elementType    : chr "integer"
  .. .. .. .. ..@ elementMetadata: NULL
  .. .. .. .. ..@ metadata       : list()
  ..@ colData        :Formal class 'DataFrame' [package "IRanges"] with 6 slots
  .. .. ..@ rownames       : chr [1:8] "SRR1039508" "SRR1039509" "SRR1039512" "SRR1039513" ...
  .. .. ..@ nrows          : int 8
  .. .. ..@ listData       :List of 9
  .. .. .. ..$ SampleName: Factor w/ 8 levels "GSM1275862","GSM1275863",..: 1 2 3 4 5 6 7 8
  .. .. .. ..$ cell      : Factor w/ 4 levels "N052611","N061011",..: 4 4 1 1 3 3 2 2
  .. .. .. ..$ dex       : Factor w/ 2 levels "trt","untrt": 2 1 2 1 2 1 2 1
  .. .. .. ..$ albut     : Factor w/ 1 level "untrt": 1 1 1 1 1 1 1 1
  .. .. .. ..$ Run       : Factor w/ 8 levels "SRR1039508","SRR1039509",..: 1 2 3 4 5 6 7 8
  .. .. .. ..$ avgLength : int [1:8] 126 126 126 87 120 126 101 98
  .. .. .. ..$ Experiment: Factor w/ 8 levels "SRX384345","SRX384346",..: 1 2 3 4 5 6 7 8
  .. .. .. ..$ Sample    : Factor w/ 8 levels "SRS508567","SRS508568",..: 2 1 3 4 5 6 7 8
  .. .. .. ..$ BioSample : Factor w/ 8 levels "SAMN02422669",..: 1 4 6 2 7 3 8 5
  .. .. ..@ elementType    : chr "ANY"
  .. .. ..@ elementMetadata: NULL
  .. .. ..@ metadata       : list()
  ..@ assays         :Reference class 'ShallowSimpleListAssays' [package "GenomicRanges"] with 1 field
  .. ..$ data: NULL
  .. ..and 12 methods.
  ..@ NAMES          : NULL
  ..@ elementMetadata:Formal class 'DataFrame' [package "S4Vectors"] with 6 slots
  .. .. ..@ rownames       : NULL
  .. .. ..@ nrows          : int 64102
  .. .. ..@ listData       : Named list()
  .. .. ..@ elementType    : chr "ANY"
  .. .. ..@ elementMetadata: NULL
  .. .. ..@ metadata       : list()
  ..@ metadata       :List of 1
  .. ..$ :Formal class 'MIAME' [package "Biobase"] with 13 slots
  .. .. .. ..@ name             : chr "Himes BE"
  .. .. .. ..@ lab              : chr NA
  .. .. .. ..@ contact          : chr ""
  .. .. .. ..@ title            : chr "RNA-Seq transcriptome profiling identifies CRISPLD2 as a glucocorticoid responsive gene that modulates cytokine"| __truncated__
  .. .. .. ..@ abstract         : chr "Asthma is a chronic inflammatory respiratory disease that affects over 300 million people worldwide. Glucocorti"| __truncated__
  .. .. .. ..@ url              : chr "http://www.ncbi.nlm.nih.gov/pubmed/24926665"
  .. .. .. ..@ pubMedIds        : chr "24926665"
  .. .. .. ..@ samples          : list()
  .. .. .. ..@ hybridizations   : list()
  .. .. .. ..@ normControls     : list()
  .. .. .. ..@ preprocessing    : list()
  .. .. .. ..@ other            : list()
  .. .. .. ..@ .__classVersion__:Formal class 'Versions' [package "Biobase"] with 1 slot
  .. .. .. .. .. ..@ .Data:List of 2
  .. .. .. .. .. .. ..$ : int [1:3] 1 0 0
  .. .. .. .. .. .. ..$ : int [1:3] 1 1 0

This tutorial gives a great introduction to the SummarizedExperiment object. We’ll take a peek, and then move on to DESeq2

[13]:
assays(se)
List of length 1
names(1): counts
[14]:
assays(se)$counts
A matrix: 64102 × 8 of type int
SRR1039508SRR1039509SRR1039512SRR1039513SRR1039516SRR1039517SRR1039520SRR1039521
ENSG00000000003 679 448 873 408 1138 1047 770 572
ENSG00000000005 0 0 0 0 0 0 0 0
ENSG00000000419 467 515 621 365 587 799 417 508
ENSG00000000457 260 211 263 164 245 331 233 229
ENSG00000000460 60 55 40 35 78 63 76 60
ENSG00000000938 0 0 2 0 1 0 0 0
ENSG000000009713251367961774252 67211102751767995
ENSG00000001036143310621733 881 1424 143913591109
ENSG00000001084 519 380 595 493 820 714 696 704
ENSG00000001167 394 236 464 175 658 584 360 269
ENSG00000001460 172 168 264 118 241 210 155 177
ENSG000000014612112186751372657 2735 275124672905
ENSG00000001497 524 488 638 357 676 806 493 475
ENSG00000001561 71 51 211 156 23 38 134 172
ENSG00000001617 555 394 905 415 727 697 618 599
ENSG00000001626 10 2 9 2 10 6 5 5
ENSG000000016291660125122591079 2462 251418881660
ENSG00000001630 59 54 66 23 84 87 31 59
ENSG00000001631 729 692 943 475 1034 1163 731 744
ENSG00000002016 201 161 256 99 268 257 160 137
ENSG00000002079 3 0 3 1 4 0 0 1
ENSG00000002330 206 174 184 111 194 260 156 177
ENSG00000002549145912941317 998 1451 1824 8531031
ENSG000000025867507720395016214109731286368347225
ENSG00000002587 2 0 1 0 0 2 0 0
ENSG00000002726 0 0 1 0 0 0 0 0
ENSG00000002745 4 6 22 10 2 1 5 3
ENSG00000002746 151 139 117 65 90 102 86 119
ENSG00000002822 411 303 446 195 445 523 295 300
ENSG000000028346314636478315809 66771197057667825
LRG_7000000000
LRG_7100000000
LRG_71500000000
LRG_71700000000
LRG_7200000000
LRG_7300000000
LRG_7400000000
LRG_7500000000
LRG_7600000000
LRG_7700000000
LRG_7800000000
LRG_7900000000
LRG_800000000
LRG_8000000000
LRG_8100000000
LRG_8300000000
LRG_8400000000
LRG_8500000000
LRG_8600000000
LRG_8800000000
LRG_8900000000
LRG_9000000000
LRG_9100000000
LRG_9200000000
LRG_9300000000
LRG_9400000000
LRG_9600000000
LRG_9700000000
LRG_9800000000
LRG_9900000000
[15]:
rowRanges(se)
GRangesList object of length 64102:
$ENSG00000000003
GRanges object with 17 ranges and 2 metadata columns:
       seqnames            ranges strand |   exon_id       exon_name
          <Rle>         <IRanges>  <Rle> | <integer>     <character>
   [1]        X 99883667-99884983      - |    667145 ENSE00001459322
   [2]        X 99885756-99885863      - |    667146 ENSE00000868868
   [3]        X 99887482-99887565      - |    667147 ENSE00000401072
   [4]        X 99887538-99887565      - |    667148 ENSE00001849132
   [5]        X 99888402-99888536      - |    667149 ENSE00003554016
   ...      ...               ...    ... .       ...             ...
  [13]        X 99890555-99890743      - |    667156 ENSE00003512331
  [14]        X 99891188-99891686      - |    667158 ENSE00001886883
  [15]        X 99891605-99891803      - |    667159 ENSE00001855382
  [16]        X 99891790-99892101      - |    667160 ENSE00001863395
  [17]        X 99894942-99894988      - |    667161 ENSE00001828996

...
<64101 more elements>
-------
seqinfo: 722 sequences (1 circular) from an unspecified genome
[16]:
colData(se)
DataFrame with 8 rows and 9 columns
           SampleName     cell      dex    albut        Run avgLength
             <factor> <factor> <factor> <factor>   <factor> <integer>
SRR1039508 GSM1275862   N61311    untrt    untrt SRR1039508       126
SRR1039509 GSM1275863   N61311      trt    untrt SRR1039509       126
SRR1039512 GSM1275866  N052611    untrt    untrt SRR1039512       126
SRR1039513 GSM1275867  N052611      trt    untrt SRR1039513        87
SRR1039516 GSM1275870  N080611    untrt    untrt SRR1039516       120
SRR1039517 GSM1275871  N080611      trt    untrt SRR1039517       126
SRR1039520 GSM1275874  N061011    untrt    untrt SRR1039520       101
SRR1039521 GSM1275875  N061011      trt    untrt SRR1039521        98
           Experiment    Sample    BioSample
             <factor>  <factor>     <factor>
SRR1039508  SRX384345 SRS508568 SAMN02422669
SRR1039509  SRX384346 SRS508567 SAMN02422675
SRR1039512  SRX384349 SRS508571 SAMN02422678
SRR1039513  SRX384350 SRS508572 SAMN02422670
SRR1039516  SRX384353 SRS508575 SAMN02422682
SRR1039517  SRX384354 SRS508576 SAMN02422673
SRR1039520  SRX384357 SRS508579 SAMN02422683
SRR1039521  SRX384358 SRS508580 SAMN02422677
[17]:
metadata(se)
[[1]]
Experiment data
  Experimenter name: Himes BE
  Laboratory: NA
  Contact information:
  Title: RNA-Seq transcriptome profiling identifies CRISPLD2 as a glucocorticoid responsive gene that modulates cytokine function in airway smooth muscle cells.
  URL: http://www.ncbi.nlm.nih.gov/pubmed/24926665
  PMIDs: 24926665

  Abstract: A 226 word abstract is available. Use 'abstract' method.

[18]:
# Just a list - we can add elements

metadata(se)$formula <- counts ~ dex + albut

metadata(se)
[[1]]
Experiment data
  Experimenter name: Himes BE
  Laboratory: NA
  Contact information:
  Title: RNA-Seq transcriptome profiling identifies CRISPLD2 as a glucocorticoid responsive gene that modulates cytokine function in airway smooth muscle cells.
  URL: http://www.ncbi.nlm.nih.gov/pubmed/24926665
  PMIDs: 24926665

  Abstract: A 226 word abstract is available. Use 'abstract' method.

$formula
counts ~ dex + albut

[19]:
# subset the first five transcripts and first three samples
se[1:5, 1:3]
class: RangedSummarizedExperiment
dim: 5 3
metadata(2): '' formula
assays(1): counts
rownames(5): ENSG00000000003 ENSG00000000005 ENSG00000000419
  ENSG00000000457 ENSG00000000460
rowData names(0):
colnames(3): SRR1039508 SRR1039509 SRR1039512
colData names(9): SampleName cell ... Sample BioSample
[20]:
assays(se[1:5,1:3])$counts

A matrix: 5 × 3 of type int
SRR1039508SRR1039509SRR1039512
ENSG00000000003679448873
ENSG00000000005 0 0 0
ENSG00000000419467515621
ENSG00000000457260211263
ENSG00000000460 60 55 40
[21]:
library("DESeq2")


dds <- DESeqDataSet(se, design = ~ cell + dex)
dds


Registered S3 methods overwritten by 'ggplot2':
  method         from
  [.quosures     rlang
  c.quosures     rlang
  print.quosures rlang
class: DESeqDataSet
dim: 64102 8
metadata(3): '' formula version
assays(1): counts
rownames(64102): ENSG00000000003 ENSG00000000005 ... LRG_98 LRG_99
rowData names(0):
colnames(8): SRR1039508 SRR1039509 ... SRR1039520 SRR1039521
colData names(9): SampleName cell ... Sample BioSample
[22]:
# remove rows with less than 10 total transcripts

keep <- rowSums(counts(dds)) >= 10
dds <- dds[keep,]
[23]:
colData(dds)
DataFrame with 8 rows and 9 columns
           SampleName     cell      dex    albut        Run avgLength
             <factor> <factor> <factor> <factor>   <factor> <integer>
SRR1039508 GSM1275862   N61311    untrt    untrt SRR1039508       126
SRR1039509 GSM1275863   N61311      trt    untrt SRR1039509       126
SRR1039512 GSM1275866  N052611    untrt    untrt SRR1039512       126
SRR1039513 GSM1275867  N052611      trt    untrt SRR1039513        87
SRR1039516 GSM1275870  N080611    untrt    untrt SRR1039516       120
SRR1039517 GSM1275871  N080611      trt    untrt SRR1039517       126
SRR1039520 GSM1275874  N061011    untrt    untrt SRR1039520       101
SRR1039521 GSM1275875  N061011      trt    untrt SRR1039521        98
           Experiment    Sample    BioSample
             <factor>  <factor>     <factor>
SRR1039508  SRX384345 SRS508568 SAMN02422669
SRR1039509  SRX384346 SRS508567 SAMN02422675
SRR1039512  SRX384349 SRS508571 SAMN02422678
SRR1039513  SRX384350 SRS508572 SAMN02422670
SRR1039516  SRX384353 SRS508575 SAMN02422682
SRR1039517  SRX384354 SRS508576 SAMN02422673
SRR1039520  SRX384357 SRS508579 SAMN02422683
SRR1039521  SRX384358 SRS508580 SAMN02422677
[24]:
# Specify reference level

dds$dex <- factor(dds$dex, levels = c("untrt","trt"))

#alternative
dds$dex <- relevel(dds$dex, ref = "untrt")

[25]:
ddsDE <- DESeq(dds)
res   <- results(ddsDE)
res
estimating size factors
estimating dispersions
gene-wise dispersion estimates
mean-dispersion relationship
final dispersion estimates
fitting model and testing
log2 fold change (MLE): dex trt vs untrt
Wald test p-value: dex trt vs untrt
DataFrame with 22369 rows and 6 columns
                        baseMean      log2FoldChange              lfcSE
                       <numeric>           <numeric>          <numeric>
ENSG00000000003 708.597861536998  -0.381227063105246  0.100702281802452
ENSG00000000419 520.296296925274   0.206840376248021  0.112107724670949
ENSG00000000457 237.162103834464   0.037954335389843  0.142823085130162
ENSG00000000460 57.9323803212894 -0.0885309218770955  0.284934403160848
ENSG00000000971 5817.31081674539    0.42642455731918 0.0888056149171329
...                          ...                 ...                ...
ENSG00000273483 2.68955174874763    0.84920766214805   1.25336471679961
ENSG00000273485 1.28646279725438  -0.123613168835481   1.58825060361379
ENSG00000273486 15.4524429107135  -0.150428542992948  0.482097671940096
ENSG00000273487 8.16326862804303    1.04563935414612  0.693057045984001
ENSG00000273488 8.58437098976254   0.108945615633239  0.632299687532417
                               stat               pvalue                 padj
                          <numeric>            <numeric>            <numeric>
ENSG00000000003   -3.78568445800561 0.000153286080966785   0.0012892045764893
ENSG00000000419    1.84501448811957    0.065035431092294    0.194929521562025
ENSG00000000457   0.265743702114076    0.790436603689371    0.909899502487793
ENSG00000000460  -0.310706327123015    0.756023886827025     0.89299357560032
ENSG00000000971    4.80177472693691 1.57265558148175e-06 2.06391014885582e-05
...                             ...                  ...                  ...
ENSG00000273483   0.677542339245393    0.498061916323377                   NA
ENSG00000273485 -0.0778297634858257    0.937963470414454                   NA
ENSG00000273486  -0.312029183604188    0.755018344483373    0.892519390830221
ENSG00000273487    1.50873490170137    0.131366542567104    0.323297597320869
ENSG00000273488   0.172300600144854    0.863201212561737    0.943414817499248