├── R ├── colors.R ├── init.R ├── resample.R ├── fixedWidthCat.R ├── mySessionInfo.R └── requiredLibs.R ├── NAMESPACE ├── man ├── parseLibVers.Rd ├── mySessionInfo.Rd ├── fixedWidthCat.Rd ├── resample.Rd ├── requiredPackages.Rd └── markup.Rd └── DESCRIPTION /R/colors.R: -------------------------------------------------------------------------------- 1 | lcol1 <- "mistyrose" 2 | lcol2 <- "lightblue" 3 | lcol3 <- "lightgreen" 4 | 5 | dcol1 <- "red" 6 | dcol2 <- "blue" 7 | dcol3 <- "green" 8 | -------------------------------------------------------------------------------- /R/init.R: -------------------------------------------------------------------------------- 1 | .onAttach <- function(libname, pkgname) { 2 | ## global options used by all chapters that load this package. 3 | options(width=62, digits=3, continue=" ") 4 | } 5 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | export( 2 | parseLibVers, 3 | requiredPackages, packages2install, 4 | resample, 5 | mySessionInfo, 6 | fixedWidthCat, 7 | lcol1, 8 | lcol2, 9 | lcol3, 10 | dcol1, 11 | dcol2, 12 | dcol3, 13 | numName, 14 | sepInt 15 | ) 16 | -------------------------------------------------------------------------------- /man/parseLibVers.Rd: -------------------------------------------------------------------------------- 1 | \name{parseLibVers} 2 | \alias{parseLibVers} 3 | \alias{packages2install} 4 | \title{Parse the library versions} 5 | \description{ 6 | This is a helper function to check for valid package versions 7 | } 8 | \usage{ 9 | parseLibVers() 10 | } 11 | \value{ 12 | Called for its side effects 13 | } 14 | \author{Florian Hahne} 15 | 16 | \keyword{misc} -------------------------------------------------------------------------------- /man/mySessionInfo.Rd: -------------------------------------------------------------------------------- 1 | \name{mySessionInfo} 2 | \alias{mySessionInfo} 3 | 4 | \title{ Wrapper around sessionInfo } 5 | \description{ 6 | This will produce the LaTeX output for the sessionInfo and the 7 | references at the end of each lab. 8 | } 9 | \usage{ 10 | mySessionInfo(ref=TRUE) 11 | } 12 | 13 | \arguments{ 14 | \item{ref}{logical controlling whether to include references} 15 | } 16 | 17 | \value{ 18 | This function is called for its side effects 19 | } 20 | 21 | \author{Florian Hahne} 22 | 23 | 24 | \keyword{misc} -------------------------------------------------------------------------------- /man/fixedWidthCat.Rd: -------------------------------------------------------------------------------- 1 | \name{fixedWidthCat} 2 | \alias{fixedWidthCat} 3 | \alias{numName} 4 | \alias{sepInt} 5 | \title{Control the output of show methods} 6 | \description{ 7 | \code{fixedWidthCat} makes sure that the output of a show method fits on the 8 | page by inserting lines breaks into long strings. 9 | 10 | \code{numName} converts an integer to it's literal name. 11 | 12 | \code{sepInt} prints integers with a comma as separator between 1000s 13 | } 14 | \usage{ 15 | fixedWidthCat(x, width=getOption("width")) 16 | } 17 | \arguments{ 18 | \item{x}{An R object which is to be shown.} 19 | \item{width}{The number of characters after which lines are to be broken.} 20 | } 21 | \value{ 22 | A character vector of the output with long lines broken 23 | } 24 | \author{Florian Hahne} 25 | \examples{ 26 | long <- paste(rep(letters[1:24], 5), sep="", collapse="") 27 | fixedWidthCat(long) 28 | } 29 | 30 | \keyword{misc} -------------------------------------------------------------------------------- /man/resample.Rd: -------------------------------------------------------------------------------- 1 | \name{resample} 2 | \alias{resample} 3 | 4 | \title{Resample from ALL ExpressionSet and plot} 5 | \description{ 6 | A function to resample samples from each class 7 | of an ExpressionSet and plot the results calculated by a function 8 | that returns the number of differentially expressed genes between the 9 | classes. 10 | } 11 | \usage{ 12 | resample(x, selfun, groupsize = 6 * (1:6), nrep = 25) 13 | } 14 | 15 | \arguments{ 16 | \item{x}{An \code{ExpressionSet} object derived from the \code{ALL} 17 | data package.} 18 | \item{selfun}{A function that takes the resampling subset of the 19 | \code{ExpressionSet} and computes the number of differentially 20 | expressed genes between the two classes} 21 | \item{groupsize}{The number of samples for each class} 22 | \item{nrep}{number of iterations of resampling procedure} 23 | } 24 | \value{ 25 | The function is called for the side effect of producing a plot. 26 | } 27 | \author{Florian Hahne} 28 | 29 | 30 | \keyword{misc} 31 | -------------------------------------------------------------------------------- /R/resample.R: -------------------------------------------------------------------------------- 1 | ## a function to resample 'nrep' times 6*(1:6) samples from each class 2 | ## of the ExpressionSet x and plot the number of differentially expressed 3 | ## genes as calculated by function 'selfun'. 4 | ## This code is used for the differential expression lab in section 8. 5 | resample <- function(x, selfun, groupsize = 6*(1:6), nrep = 25) { 6 | twoGroups <- split(1:nrow(pData(x)), x$mol.biol) 7 | stopifnot(length(twoGroups)==2) 8 | n <- matrix(nrow = nrep, ncol = length(groupsize)) 9 | for (i in seq(along = groupsize)) { 10 | for (rep in 1:nrep) { 11 | samp <- c(sample(twoGroups[[1]], groupsize[i]), 12 | sample(twoGroups[[2]], groupsize[i])) 13 | n[rep, i] <- do.call(selfun, args=list(x = x[, samp])) 14 | } 15 | cat(".") 16 | } 17 | cat("\n") 18 | mns <- apply(n, 2, mean) 19 | stds <- apply(n, 2, sd) 20 | plot(groupsize, mns, pch = 16, col = "#c03030", 21 | ylim = c(min(mns-stds) - 5, max(mns + stds) + 5), xlab = "groupsize", 22 | ylab = "selected no. of diff. exp. genes", main = selfun) 23 | segments(groupsize, mns - stds, groupsize, mns + stds, col = "red") 24 | return(invisible(NULL)) 25 | } 26 | -------------------------------------------------------------------------------- /man/requiredPackages.Rd: -------------------------------------------------------------------------------- 1 | \name{requiredPackages} 2 | \alias{requiredPackages} 3 | \title{check for missing and outdated packages} 4 | \description{ 5 | Both functions compare the \code{Depends} field of the 6 | \code{DESCRIPTION} of the \code{BiocCaseStudies} package. 7 | \code{requiredPackages} is run before a build of the book. It throws 8 | an error if there are any missing or outdated packages. 9 | \code{packages2install} returns a character vector of packages 10 | that need (re)installing. 11 | } 12 | \usage{ 13 | requiredPackages(load=FALSE) 14 | packages2install() 15 | } 16 | 17 | \arguments{ 18 | \item{load}{Logical. Should all packages be loaded?} 19 | } 20 | 21 | \value{ 22 | \code{requiredPackages} returns \code{invisible(NULL)}. 23 | The function is called for its side effects. 24 | \code{packages2install} returns a character vector that can be passed 25 | to the \code{install} function from the \code{BiocManager} package. 26 | } 27 | 28 | \author{Florian Hahne} 29 | \examples{ 30 | \dontrun{ 31 | if (!requireNamespace("BiocManager", quietly = TRUE)) 32 | install.packages("BiocManager") 33 | BiocManager::install(packages2install()) 34 | } 35 | } 36 | 37 | \keyword{misc} -------------------------------------------------------------------------------- /R/fixedWidthCat.R: -------------------------------------------------------------------------------- 1 | ## helper function that counts trailing spaces in a string 2 | trailingSpaces <- function(x, width){ 3 | y <- gsub("^ *", "", x) 4 | tmp <- nchar(x)-nchar(y) 5 | if(tmp>=width) 6 | tmp <- min(0, width-nchar(y)) 7 | return(tmp) 8 | } 9 | 10 | 11 | ## This function captures the output that's generated by 12 | ## a show method for any R object and makes sure 13 | ## that lines are broken in case the output is too long 14 | fixedWidthCat <- function(x, width=getOption("width")){ 15 | output <- gsub("\t", " ", capture.output(x)) 16 | longLines <- which(nchar(output)>width) 17 | for(l in longLines){ 18 | ident <- trailingSpaces(output[l], width) 19 | output[l] <- strbreak(output[l], exdent=ident, collapse="\n") 20 | } 21 | cat(output, sep="\n", collapse="") 22 | } 23 | 24 | 25 | 26 | ## match numbers from 1 to 13 to textual names 27 | numName <- function(x){ 28 | if(x>13) 29 | return(x) 30 | nums <- c("one", "two", "three", "four", "five", "six", "seven", "eight", 31 | "nine", "ten", "eleven", "twelve", "thirteen") 32 | nums[x] 33 | } 34 | 35 | 36 | ## print integers with comma as 1000 separator 37 | sepInt <- function(x){ 38 | if(x<1000) 39 | return(x) 40 | sprintf("%d,%03d", x %/% 1000, x %% 1000) 41 | } 42 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: BiocCaseStudies 2 | Title: BiocCaseStudies: Support for the Case Studies Monograph 3 | Version: 1.53.0 4 | Author: R. Gentleman, W. Huber, F. Hahne, M. Morgan, S. Falcon 5 | Description: Software and data to support the case studies. 6 | Maintainer: Bioconductor Package Maintainer 7 | 8 | License: Artistic-2.0 9 | LazyLoad: true 10 | Collate: init.R requiredLibs.R resample.R mySessionInfo.R colors.R 11 | fixedWidthCat.R 12 | Depends: tools, methods, utils, Biobase 13 | Suggests: affy (>= 1.17.3), affyPLM (>= 1.15.1), affyQCReport (>= 14 | 1.17.0), ALL (>= 1.4.3), annaffy (>= 1.11.1), annotate (>= 15 | 1.17.3), AnnotationDbi (>= 1.1.6), apComplex (>= 2.5.0), 16 | Biobase (>= 1.17.5), bioDist (>= 1.11.3), biocGraph (>= 1.1.1), 17 | biomaRt (>= 1.13.5), CCl4 (>= 1.0.6), CLL (>= 1.2.4), Category 18 | (>= 2.5.0), class (>= 7.2-38), cluster (>= 1.11.9), convert (>= 19 | 1.15.0), gcrma (>= 2.11.1), genefilter (>= 1.17.6), geneplotter 20 | (>= 1.17.2), GO.db (>= 2.0.2), GOstats (>= 2.5.0), graph (>= 21 | 1.17.4), GSEABase (>= 1.1.13), hgu133a.db (>= 2.0.2), 22 | hgu95av2.db, hgu95av2cdf (>= 2.0.0), hgu95av2probe (>= 2.0.0), 23 | hopach (>= 1.13.0), KEGG.db (>= 2.0.2), kohonen (>= 2.0.2), 24 | lattice (>= 0.17.2), latticeExtra (>= 0.3-1), limma (>= 25 | 2.13.1), MASS (>= 7.2-38), MLInterfaces (>= 1.13.17), multtest 26 | (>= 1.19.0), org.Hs.eg.db (>= 2.0.2), ppiStats (>= 1.5.4), 27 | randomForest (>= 4.5-20), RBGL (>= 1.15.6), RColorBrewer (>= 28 | 1.0-2), Rgraphviz (>= 1.17.11), vsn (>= 3.4.0), weaver (>= 29 | 1.5.0), xtable (>= 1.5-2), yeastExpData (>= 0.9.11) 30 | biocViews: Infrastructure 31 | -------------------------------------------------------------------------------- /R/mySessionInfo.R: -------------------------------------------------------------------------------- 1 | ## split long strings 2 | insertLinefeed <- function(str, n=57, tex=TRUE){ 3 | ss <- strsplit(str, " ") 4 | out <- NULL 5 | for(i in seq(along=ss)){ 6 | for(j in seq(along=ss[[i]])){ 7 | ins <- ss[[i]][j] 8 | if(i==1 && j==1){ 9 | out <- c(out, substr(ins,0,n-6)) 10 | ins <- substr(ins,n-5,nchar(ins)) 11 | } 12 | while(nchar(ins)>n){ 13 | out <- c(out, substr(ins,0,n)) 14 | ins <- substr(ins,n+1,nchar(ins)) 15 | } 16 | } 17 | ss[[i]] <- c(out, ins) 18 | } 19 | if(tex) 20 | ret <- paste(unlist(ss), "|", collapse="\\\\\n\\verb|", sep="") 21 | else 22 | ret <- paste(unlist(ss), collapse="\n", sep="") 23 | return(substr(ret, 0, nchar(ret)-1)) 24 | } 25 | 26 | mySessionInfo <- function(ref=TRUE){ 27 | 28 | ## force floats and wrap in minpage 29 | cat("\\subsubsection*{}") 30 | cat("\\FloatBarrier\n") 31 | cat("\\hrulefill\\\\\n") 32 | #cat("\\begin{minipage}{\\textwidth}\n") 33 | cat("The version number of R and the packages and their versions", 34 | "that were used to generate this document are listed below:\n") 35 | se <- sessionInfo() 36 | se$locale <- insertLinefeed(se$locale) 37 | cat(myToLatex(se)) 38 | if(ref){ 39 | cat("\\bibliographystyle{abbrvnat}\n") 40 | cat("\\bibliography{../Common/useR}\n") 41 | } 42 | #cat("\\end{minipage}\n") 43 | } 44 | 45 | 46 | myToLatex <- function (object, ...) 47 | { 48 | opkgver <- sapply(object$otherPkgs, function(x) x$Version) 49 | nspkgver <- sapply(object$loadedOnly, function(x) x$Version) 50 | z <- c("\\begin{itemize}", paste(" \\item ", 51 | object$R.version$version.string, 52 | ", \\\\\\verb|",object$R.version$platform, 53 | "|", sep = ""), 54 | paste(" \\item Locale: \\verb|", object$locale, 55 | "|", sep = ""), strwrap(paste("\\item Base packages:", 56 | paste(sort(object$basePkgs), 57 | collapse = ", ")), 58 | indent = 2, exdent = 4)) 59 | if (length(opkgver)) { 60 | opkgver <- opkgver[sort(names(opkgver))] 61 | z <- c(z, strwrap(paste(" \\item Other packages: ", 62 | paste(names(opkgver), opkgver, sep = "~", 63 | collapse = ", ")), 64 | indent = 2, exdent = 4)) 65 | } 66 | if (length(nspkgver)) { 67 | nspkgver <- nspkgver[sort(names(nspkgver))] 68 | z <- c(z, strwrap(paste(" \\item Loaded via a namespace ", 69 | "(and not attached): ", 70 | paste(names(nspkgver), nspkgver, 71 | sep = "~", collapse = ", ")), 72 | indent = 2, exdent = 4)) 73 | } 74 | z <- c(z, "\\end{itemize}") 75 | class(z) <- "Latex" 76 | z 77 | } 78 | 79 | -------------------------------------------------------------------------------- /R/requiredLibs.R: -------------------------------------------------------------------------------- 1 | ## parse package information from the Suggests field 2 | parseLibVers <- function(){ 3 | sug <- gsub("\n", "", packageDescription("BiocCaseStudies")$Suggests) 4 | tmp <- unlist(strsplit(sug, ",")) 5 | res <- data.frame(package=I(gsub("^ | ?[(].*", "", tmp)), 6 | version=I(gsub(">= ?|)", "", sapply(strsplit(tmp, "(", 7 | fixed=TRUE), function(x) x[2])))) 8 | return(res) 9 | } 10 | 11 | 12 | ## check for missing and outdated packages 13 | requiredPackages <- function(load=FALSE){ 14 | ## get package information 15 | cat("checking for package dependencies...\n") 16 | oldOpt <- options(warn=-1) 17 | reqPck <- parseLibVers() 18 | avPck <- lapply(reqPck$package, function(x){ 19 | pd <- packageDescription(x) 20 | if(is(pd, "packageDescription")) 21 | packageDescription(x)$Version 22 | else 23 | NULL}) 24 | names(avPck) <- reqPck$package 25 | ## find missing packages 26 | missing <- sapply(avPck, is.null) 27 | if(any(missing)){ 28 | file.remove("useRbook.tex") 29 | stop("Please install the following package(s) to build the book:\n ", 30 | paste(unlist(reqPck$package[missing]), "\n "), call.=FALSE) 31 | } 32 | ## continue only with packages for which version is specified 33 | sel <- !missing & !is.na(reqPck$version) 34 | avPck <- unlist(avPck[sel]) 35 | ## find outdated packages 36 | #outdated <- mapply(">", reqPck[sel, "version"], avPck) 37 | outdated <- mapply(function(x,y) package_version(x) > package_version(y), 38 | reqPck[sel, "version"], avPck) 39 | if(any(outdated)){ 40 | file.remove("useRbook.tex") 41 | stop("The following package(s) need(s) to be updated\n", 42 | "in order to build the book:\n ", 43 | paste(unlist(names(avPck)[outdated]), "(is", avPck[outdated] , 44 | "should be", reqPck[sel, "version"][outdated], 45 | ")\n "), call.=FALSE) 46 | } 47 | options(oldOpt) 48 | cat("Great!!! All packages are up to date\n") 49 | 50 | if(load){ 51 | loadRes <- list() 52 | for(p in reqPck[,1]) 53 | loadRes[[p]] <- try(eval(parse(text=paste("library(", p, ")", 54 | sep=""))), silent=TRUE) 55 | err <- sapply(loadRes, function(x) is(x, "try-error")) 56 | if(any(err)) 57 | stop("The following package(s) could not be loaded:\n", 58 | paste(names(loadRes[err]), collapse=", ", sep="")) 59 | else(message("All packages loaded successfully")) 60 | } 61 | return(invisible(NULL)) 62 | } 63 | 64 | packages2install = function(){ 65 | ## get package information 66 | reqPck = parseLibVers() 67 | avPck = lapply(reqPck$package, function(x){ 68 | pd = packageDescription(x) 69 | if(is(pd, "packageDescription")) 70 | packageDescription(x)$Version 71 | else 72 | NULL}) 73 | names(avPck) = reqPck$package 74 | 75 | ## find missing packages 76 | missing = sapply(avPck, is.null) 77 | s1 = if(any(missing)) unlist(reqPck$package[missing]) else character(0) 78 | 79 | ## find outdated packages 80 | sel = !missing & !is.na(reqPck$version) 81 | avPck = unlist(avPck[sel]) 82 | outdated = mapply(function(x,y) package_version(x) > package_version(y), 83 | reqPck[sel, "version"], avPck) 84 | 85 | 86 | s2 = if(any(outdated)) unlist(names(avPck)[outdated]) else character(0) 87 | 88 | return(c(s1, s2)) 89 | } 90 | -------------------------------------------------------------------------------- /man/markup.Rd: -------------------------------------------------------------------------------- 1 | \name{markup} 2 | \alias{markup} 3 | \alias{lcol1} 4 | \alias{lcol2} 5 | \alias{lcol3} 6 | \alias{dcol1} 7 | \alias{dcol2} 8 | \alias{dcol3} 9 | \alias{myref} 10 | \alias{Ex} 11 | \alias{solution} 12 | \alias{myincfig} 13 | \alias{solfig} 14 | \alias{booklab} 15 | \alias{indexTerm} 16 | 17 | \title{Markup commands.} 18 | 19 | \description{Usage of predefined markup commands for layout of Bioc Case 20 | Studies book.} 21 | 22 | \details{ 23 | The following markup commands, LaTeX makros and environments are 24 | available for controling the layout and structure of the book: 25 | 26 | \itemize{ 27 | \item{\code{Ex}:}{environment for exercise chunks.} 28 | 29 | \item{\code{solution}:}{environment for solutions to the exercises.} 30 | 31 | \item{\\\code{myincfig}:}{macro for figure environments with three parameters: 32 | (1) figure filename (2) figure width (3) figure caption} 33 | 34 | \item{\\\code{solfig}:}{macro for figure environments within solution 35 | chunks. This is necessary because LaTex doesn't allow for floats 36 | within minipage environments.} 37 | 38 | \item{\\\code{myref}:}{reference to other labs/chapters. For the book 39 | this is a simplewrapper around ref ignoring the second argument, for 40 | the labs this command is replaced in the useRlabs.sty file allowing 41 | for referencing bbetween the individual documents.} 42 | 43 | \item{\\\code{booklab}:}{macro for conditional text input with two 44 | parameters. The first parameter will be used for the book while the 45 | second will be used for the labs.} 46 | } 47 | The following makros will automatically create index entries as side 48 | effect. Apart from that they do text highlighting as well. 49 | \itemize{ 50 | \item{\\\code{R}:}{the R language glyph (in sans serif font)} 51 | 52 | \item{\\\code{Rpackage}:}{an R package (in bold font)} 53 | 54 | \item{\\\code{Rclass}:}{an R class (in italics)} 55 | 56 | \item{\\\code{Rmethod}:}{an R method (in small typewriter font)} 57 | 58 | \item{\\\code{Rfunction}:}{an R function (in small typewriter font)} 59 | } 60 | Implicit index terms can be generated using 61 | 62 | \itemize{ 63 | \item{\\\code{indexTerm}:}{with the optional first argument giving the 64 | actual term and the second argument giving a string that appears in 65 | the text. E.g. \code{indexTerm[tree]{trees}} would give you 66 | "trees" in the text but create an index for "tree". Omitting the 67 | optional first argument will create an index for the same string that 68 | appears in the text.} 69 | } 70 | Some more usful text markup that doesn't create indices: 71 | \itemize{ 72 | \item{\\\code{Robject}:}{an R object (in small typewriter font)} 73 | 74 | \item{\\\code{Rfunarg}:}{the agument to an R function (in italics)} 75 | 76 | \item{\\\code{code}:}{typewriter font} 77 | 78 | \item{\\\code{term}:}{whatever \code{\\{emph}} is set to} 79 | 80 | \item{\\\code{file}:}{italics} 81 | 82 | \item{\\\code{reg}:}{The registered trademark glyph} 83 | } 84 | The following environments are used to structure the document and for 85 | parsing . They do not impose any layout. 86 | 87 | \itemize{ 88 | \item{\code{chapterheader}:}{this contains title, authors and abstract 89 | of the chapter/lab} 90 | 91 | \item{\code{chapterbody:}}{this contains the actual chapter body} 92 | 93 | \item{\code{chaptertrailer:}}{this contains session info and references 94 | for a chapter} 95 | 96 | \item{\\\code{yaa}:}{This is a wrapper for \code{input} also setting the 97 | graphics include path. Its first parameter is filename, second 98 | parameter is graphics path} 99 | } 100 | 101 | Color and options 102 | 103 | \itemize{ 104 | \item{colors:}{There are some predefined colors that should be used 105 | consistantly throughout the whole book for things like histograms, 106 | barplots, etc. They are defined by \code{BiocCaseStudies} as objects 107 | \code{lcol1}, \code{lcol2} and \code{lcol3} for light colors, and 108 | \code{dcol1}, \code{dcol2} and \code{dcol3} for dark colors.} 109 | 110 | \item{Sweave options:}{The boolean option \code{hideme} can be used in 111 | Sweave code chunks that should not be part of the Stangle output. This 112 | only effects Stangle, so a "regular" Sweave will evaluate these 113 | chunks. The intention is to have the possibility for sanity checks or 114 | conditional code evaluation which should not confuse the users when 115 | they work with the extracted code.} 116 | } 117 | } 118 | 119 | \author{Florian Hahne} 120 | 121 | 122 | \keyword{misc} 123 | --------------------------------------------------------------------------------