吨吨吨的生信技能树r语言学习笔记(2)

学习bioconductor,后期会详细看写一个笔记
2018-05-R与Bioconductor的入门课_哔哩哔哩_bilibili

碎碎念:其实我觉得入门应该从第14课开始看,然后再回到前面看进阶,特别是如果以前没有怎么接触r,会学的非常吃力,极度推荐先看王通老师的r语言入门


14.学习资源介绍
r语言博客:https://www.jianshu.com/nb/22007361
统计学基础:https://mp.weixin.qq.com/s/OtB2h6f00U2SRZLzveJKfQ
可视化基础:http://www.sthda.com/english/wiki/data-visualization
bioconductor基础:bioconductor.github.io/BiocWorkshops
书籍:r语言实战
list.file()展示文件,和linux的ls一样

15.与Exel的区别
read.table('文件名',sep='\t')
sum()
变量如何理解:赋值
变量类型:向量型vector,矩阵型matrix,数组型array,列表型list,数据框型dataframe
如何取行列:[]
which()获取行号
table()统计并获得资料

16.简单统计及数学函数
t.test()
mean()
max()
fivenum()
mad()
......

17.基础语法

正则表达式
wxs=a[a[,1]=='WXS',] #第一列是wxs的
wxs=a[grepl ('WXS',a[,1]),]

wxs=a[which(a[,1]=='WXS'),]
wxs=a[grep('WXS',a[,1]),]

分割一列
strsplit()
#(其实separate函数也可以做到)
循环
第一种  
lapply(strsplit(tmp,','),function(x){cat(x)})
第二种  
for(x in l[1:4]){
printx([2])
}
sub() #substitution就是替代
unique()#去重

18.高级数据处理技巧
管道%>%

library(CLL)
library(airway)
suppressPackageStartupMessages(library(CLL))
data(sCLLex)
exprSet=exprs(sCLLex)   ##sCLLex是依赖于CLL这个package的一个对象
samples=sampleNames(sCLLex)
pdata=pData(sCLLex)
group_list=as.character(pdata[,2])
dim(exprSet)
apply(e,2,mean)
#apply很复杂

分列的新技巧
1.library(stringr)
str_split('a$library_name',',',simplify=T) [,2] #这里的simplify=T可以自动unlisted形成dataframe
2.do.call(rbind,strsplit(a$library_name,','))[,2]

19.绘图应该如何学

a=read.csv('a.csv',stringsAsFactors=F)
boxplot(a$Mbases~a$Assay_type)
p=t.test(a$Mbases~a$Assay_type)$p.value
paste0('p value=',p)#就是把两个粘起来

#让他更加炫酷(s  thda上找一找)这个(dalao)不重要(xuyao)
ggplot啊,ggpubr啊。。。。。。

23.系统的入门r语言
1)如何学习:腾讯视频,网易云课堂等各种资源,书本如r语言实战等
2)r studio:现在已经4.1.2了,安装包blablabla
才发现我基本安装的时候问update我都选的a
3)理解r和excel的异同

24.r语言可视化基础
1)使用rmarkdown制作网页:R markdown cheat sheet
2)ggplot2:ggplot2-cheatsheet
这要是打印一个就完了
可视化进阶:总能找到一个抄的代码hhh找一篇好看的文章然后抄袭就完了

25.用shiny写一个计算器

library(shiny)
ui <- fluidPage(textInput('a','please input the first number:'),#inputid, label
                checkboxGroupInput('op','please choose a sign',
                                   c('+'='+',
                                     '-'='-',
                                     '*'='*',
                                     '/'='/',
                                     '%'='%%')),
                textInput('b','please input the second number:'),
                submitButton('do','calculator'),
                textOutput('result')
                )#创建一个流式布局
server=function(input,output){
  output$result=renderPrint({
    input$do 
    print(eval(parse(text=paste0(input$a,input$op,input$b))))
    })
}#parse()函数能将字符串转换为表达式expression;eval()函数能对表达式求解
shinyApp(ui=ui,server=server)#调用该程序

更多学习shiny的知识有:
https://shiny.rstudio.com/articles/

26.r语言操作图片
对图片进行merge等操作,
使用’png'包等等
‘Imagemagick’

27.r语言写爬虫
网上查吧,感觉这些都是,你有需求的时候就会了,没有需求你也懒得搞

28.r语言爬取生信软件列表到思维导图
我没有网页基础知识hh所以跳过

29.r语言进行id转换
代码来源:
http://www.biotrainee.com/thread-941-1-1.html
http://www.biotrainee.com/thread-409-1-1.html

rm(list=ls())
 
library("hgu95av2.db")
ls('package:hgu95av2.db')
probe2entrezID=toTable(hgu95av2ENTREZID)
probe2symbol=toTable(hgu95av2SYMBOL)
probe2genename=toTable(hgu95av2GENENAME)
 
my_probe = sample(unique(mappedLkeys(hgu95av2ENTREZID)),30)
 
tmp1 = probe2symbol[match(my_probe,probe2symbol$probe_id),]
tmp2 = probe2entrezID[match(my_probe,probe2entrezID$probe_id),]
tmp3 = probe2genename[match(my_probe,probe2genename$probe_id),]
 
write.table(my_probe,'my_probe.txt',quote = F,col.names = F,row.names =F)
write.table(tmp1$symbol,'my_symbol.txt',quote = F,col.names = F,row.names =F)
write.table(tmp2$gene_id,'my_geneID.txt',quote = F,col.names = F,row.names =F)

r语言中的排序,集合运算,reshape以及merge的总结:https://cloud.tencent.com/developer/article/1055787

30.多个差异分析结果直接量取交集并集
网站:http://www.biotrainee.com/thread-1288-1-1.html

image

你可能感兴趣的:(吨吨吨的生信技能树r语言学习笔记(2))