title: GDAS001-安裝Bioconductor與獲取幫助
type: "tags"
tags:
- Bioconductor
categories: - Genomics Data Analysis Series
安裝Bioconductor
使用以下代碼安裝Bioconductor,直接粘貼到R的控制臺即可。
source("http://bioconductor.org/biocLite.R")
biocLite()
這兩行代碼會安裝核心的Bioconductor包。如果要再安裝其它的包,則要使用biocLite()函數(shù),并且使用字符串參數(shù)指定包的名稱,例如我們安裝以下的兩個包:
biocLite(c("genefilter","geneplotter"))
在使用的時候,就跟常規(guī)的R包一樣了,例如library()加載即可,例如 library(genefilter)。
獲取幫助
R中的幫助函數(shù)很多, 如果在命令行中直接輸入 help.start() 就能查看R幫助起始頁面。
查看函數(shù)幫助文檔
通常情況,使用?后面添加函數(shù)名稱,回車則可以查看此函數(shù)的幫助文檔。使用example(函數(shù))則能查看該函數(shù)的幫助文檔中Examples部分中的案例,如下所示:
?mean
?mad
example(mad)
example(boxplot)
輸入函數(shù)名稱,但不添加任何參數(shù),則顯示此函數(shù)的所有代碼。
在函數(shù)的幫助文檔中,我們可以看到許多內(nèi)容,包括關于此函數(shù)的描述,用法,參數(shù),細節(jié),參考文獻,使用案例等。
包幫助
如果想查看某個包中所有函數(shù)的幫助文檔,那么此時可以直接查看該函數(shù)的包文檔,如果想使用Web瀏覽器來查看這些文檔,那么需要添加以下參數(shù)(R默認的IDE):
help(package="genefilter", help_type="html")
如果使用的Rstudio,那么上述命令與下面命令的功能是一樣的:
help(package="genefilter")
一種查看某個包中的有哪些函數(shù)的快速方法是使用雙冒號::,如下所示:
library(geneplotter)
geneplotter::
對象幫助
如果要在R中查看某個對象的幫助信息,可以按如下操作:
class(6)
?numeric
?"numeric-class"
不過有的時候,在一些包中,某個構(gòu)建的函數(shù)與此函數(shù)構(gòu)建的對象的幫助文檔是一樣的,如下所示:
library(Biobase)
?ExpressionSet
?"ExpressionSet-class"
快速查看某個對象的方法:
methods(class="ExpressionSet")
methods(class="lm")
使用method()函數(shù)則能查看由某個類定義的實例的所有方法:
R has good capabilities for self-description. Classes can be formally linked to methods that operate usefully on their instances. The methods available can be listed using the methods function.
data(sample.ExpressionSet)
methods(class=class(sample.ExpressionSet))
## [1] [ [[ [[<- $$
## [5] $$<- abstract annotation annotation<-
## [9] as.data.frame assayData assayData<- classVersion
## [13] classVersion<- coerce combine description
## [17] description<- dim dimnames dimnames<-
## [21] dims esApply experimentData experimentData<-
## [25] exprs exprs<- fData fData<-
## [29] featureData featureData<- featureNames featureNames<-
## [33] fvarLabels fvarLabels<- fvarMetadata fvarMetadata<-
## [37] initialize isCurrent isVersioned KEGG2heatmap
## [41] KEGGmnplot makeDataPackage Makesense notes
## [45] notes<- pData pData<- phenoData
## [49] phenoData<- preproc preproc<- protocolData
## [53] protocolData<- pubMedIds pubMedIds<- rowMedians
## [57] rowQ sampleNames sampleNames<- show
## [61] storageMode storageMode<- updateObject updateObjectTo
## [65] varLabels varLabels<- varMetadata varMetadata<-
## [69] write.exprs
## see '?methods' for accessing help and source code
源代碼
You can find the source code for many functions by typing out the name of the function without () and pressing enter.
read.csv
## function (file, header = TRUE, sep = ",", quote = "\\"", dec = ".",
## fill = TRUE, comment.char = "", ...)
## read.table(file = file, header = header, sep = sep, quote = quote,
## dec = dec, fill = fill, comment.char = comment.char, ...)
## <bytecode: 0x7f8e35b19200>
## <environment: namespace:utils>
我們從上面可以看出來,read.csv()函數(shù)只是打包了(wraps)了read.table()函數(shù)。
有的時候,你需要指定一個特定的類,才能查看該方法的源代碼,如下所示:
plotMA
## nonstandardGenericFunction for "plotMA" defined from package "BiocGenerics"
##
## function (object, ...)
## {
## standardGeneric("plotMA")
## }
## <environment: 0x7f8e338381b8>
## Methods may be defined for arguments: object
## Use showMethods("plotMA") for currently available ones.
showMethods("plotMA")
## Function: plotMA (package BiocGenerics)
## object="ANY"
## object="data.frame"
getMethod("plotMA","data.frame")
## Method Definition:
##
## function (object, ...)
## {
## .local <- function (object, ylim = NULL, colNonSig = "gray32",
## colSig = "red3", colLine = "#ff000080", log = "x", cex = 0.45,
## xlab = "mean expression", ylab = "log fold change", ...)
## {
## if (!(ncol(object) == 3 & inherits(object[[1]], "numeric") &
## inherits(object[[2]], "numeric") & inherits(object[[3]],
## "logical"))) {
## stop("When called with a data.frame, plotMA expects the data frame to have 3 columns, two numeric ones for mean and log fold change, and a logical one for significance.")
## }
## colnames(object) <- c("mean", "lfc", "sig")
## object = subset(object, mean != 0)
## py = object$lfc
## if (is.null(ylim))
## ylim = c(-1, 1) * quantile(abs(py[is.finite(py)]),
## probs = 0.99) * 1.1
## plot(object$mean, pmax(ylim[1], pmin(ylim[2], py)), log = log,
## pch = ifelse(py < ylim[1], 6, ifelse(py > ylim[2],
## 2, 16)), cex = cex, col = ifelse(object$sig,
## colSig, colNonSig), xlab = xlab, ylab = ylab,
## ylim = ylim, ...)
## abline(h = 0, lwd = 4, col = colLine)
## }
## .local(object, ...)
## }
## <environment: namespace:geneplotter>
##
## Signatures:
## object
## target "data.frame"
## defined "data.frame"
簡要案例Vignettes
“Vignettes”包含在R包中,并且是Bioconductor包的標準組件之一。這個函數(shù)通常會通過“塊”代碼的形式,來顯示此包中函數(shù)的使用案例。
在Bioconductor的官網(wǎng)有PDF格式或R代碼的Vignettes。此外,通過在R中來調(diào)用vignette能夠保證正在使用的包的正確版本。以下代碼就是列出某個特定包的vignettes名字,如下所示:
vignette(package="Biobase")
結(jié)果如下所示:
Vignettes in package ‘Biobase’:
ExpressionSetIntroduction
An introduction to Biobase and
ExpressionSets (source, pdf)
esApply esApply Introduction (source, pdf)
BiobaseDevelopment
Notes for eSet developers (source,
pdf)
進行一步調(diào)用 vignette 能夠瀏覽PDF格式的內(nèi)容:
vignette("ExpressionSetIntroduction")
也可以使用Web瀏覽器的方式來查看vignette,如下所示:
browseVignettes(package="Biobase")
分析幫助
workflows repository 這個庫中包含了大量的可計算文檔(computable documents),以及描述了如何執(zhí)行某些常見的分析,這些數(shù)據(jù)來源于已經(jīng)發(fā)布的數(shù)據(jù)。
總結(jié)
- Bioconductor上的所有R函數(shù)都有自己的文檔,以及運行案例;
- 所有的Bioconductor包都有自己的vignettes,它描述了該包中的函數(shù)如何配合使用,并且是如何實現(xiàn)包的目標;
- Bioconductor包含許多workflow documents,我們可以通過這些工作流程文檔來進行學習;
- R內(nèi)置了許多基礎函數(shù)用于完成基礎的統(tǒng)計分析;
- R’s mailing list for elementary questions 與Bioconductor’s support site 上含有非常多的信息,可以用于進一步的學習。