````{r setup,echo = false} library(LearnBioconductor)stopifnot(biocinstaller :: biocversion()==“ 3.1”)`````````````:: Markdown()
2015年2月3日##编程_r_是一种编程语言 - 您自己的函数``{r fun} fun} fun < - function(n){x <-rnorm(n)y <-x + rnorm(n,sd =。5)lm(y〜x)}``` - 查看_rstudio_功能向导!- 迭代````{r itteration,eval = false} ##'side Effects'for(i in 1:10)消息(i)##结果用于后续计算sapply(1:10,function(i){sum {rnorm(1000))})`` - 其他迭代范式:`lapply()`,apply()`,mapply() / map()`。- 条件执行``````{r striceedal,eart = false} sapply(1:10,function(i){if(sum(rnorm(1000))> 0){ans < - “ hi!”} else {ans <- “低!”} ans})````##从脚本到包脚本包含数据和转换的组合。通常,转换是特殊的,并且严重依赖各种软件包提供的功能。有时,该脚本包含有用的代码,可以在不同的地方重复使用。我们在本课程中遇到的示例可能包括DNA序列的gc-content(或者已经有一个功能吗?查看`r biocpkg(“ bioStrings''!!),并从一种类型的类型中创建一个简单的'Map'注释另一个。创建一个包装很容易和有益。- 只需要仔细考虑如何实施一次功能。- 包装中的代码重复使用 - 如果您纠正错误,则所有脚本都会自动受益。 - Share with your lab mates / colleagues for consistent results, and with the wider community for fame and glory. What is an _R_ package? - Simple directory structure of required files. Minimal: MyPackage |-- DESCRIPTION (title, author, version, etc.) |-- NAMESPACE (imports / exports) |-- R (R function definitions) |-- gc.R |-- annoHelper.R |-- man (help pages) |-- MyPackage.Rd |-- gc.Rd |-- annoHelper.Rd Check out the _Rstudio_ package wizard! ## Lab ### GC-content Write a function that takes a `DNAStringSet` and returns the GC content. Modify the function using a conditional statement to work whether provided a `DNAString` or a `DNAStringSet`. Test the function. Save the function in a file on your AMI. ### Annotation-helper Write a function that takes as its argument Ensembl gene identifiers (like the `rownames()` of the _SummarizedExperiment_ object in the RNASeq vignette yesterday) and uses the `select()` method and annotation package `r Biocannopkg("org.Hs.eg.db")` to return a named character vector, where the names of the vector are the Ensembl identifiers and the values are the corresponding gene SYMBOLs. Adopt some simple-to-implement policy for handling Ensembl identifiers that map to more than one gene symbol. Save this function to another file ### A package Use the _RStudio_ wizard to create a package from the files containing your GC-content and annotation-helper functions.