工作生活

学习总结

2019-07-04  本文已影响0人  桃浪桃浪

时间:2019.7.4
内容:初级题与中级题

分组
> plate <- as.data.frame(plate)
> e$plate <- plate###将plate加入e中成为plate列
> e1 <- e[e$plate=='0048']
> class(e1)
[1] "character"
> dim(e1) <- c(384,3)
> class(e1)
[1] "matrix"
> e2 <- e[e$plate=='0049']
> dim(e2) <- c(384,3)
> e1 <- e1[,-2]
> e2 <- e2[,-2]
> e1 <- as.numeric(e1)
> dim(e1 ) <- c(384,2)
> class(e1[,1])
[1] "numeric"
> colnames(e1) <- c('MBases','plate')
> e2 <- as.numeric(e2)
> dim(e2) <- c(384,2)
> colnames(e2) <- c('MBases','plate')
频数图
> hist(e1[,1])
image.png
> hist(e2[,1])
image.png
使用ggplot2画图
箱图
library(ggplot2)
class(e1)
e1 <- as.data.frame(e1)
e2 <- as.data.frame(e2)
> ggplot(e1,aes(x=plate,y=MBases))+geom_boxplot()
> ggplot(e2,aes(x=plate,y=MBases))+geom_boxplot()
image.png image.png
频数图
> ggplot(e1,aes(x=MBases))+geom_histogram(bins = 40,color="blue")
> ggplot(e2,aes(x=MBases))+geom_histogram(bins = 40,color="blue")
image.png
> ggplot(e2,aes(x=MBases))+geom_histogram(bins = 40,color="blue")
image.png
密度图
> ggplot(e1,aes(x=MBases))+geom_density()
image.png
> ggplot(e2,aes(x=MBases))+geom_density()
image.png
使用ggpubr作图
library(ggpubr)
箱图
> ggboxplot(e1,x = 'plate',y = 'MBases')
image.png
> ggboxplot(e2,x = 'plate',y = 'MBases')
image.png
频数图
> gghistogram(e1,x='MBases',bins=30)
image.png
> gghistogram(e2,x='MBases',bins=30)
image.png
密度图
> ggdensity(e1,x='MBases')
image.png
> ggdensity(e2,x='MBases')
image.png
随机取384个MBases信息,跟前面的两个plate的信息组合成新的数据框,第一列是分组,第二列是MBases,总共是384*3行数据。
> a1 <- e$MBases[1:384]
> a2 <- e$Title[1:384]
> a <- data.frame(a1,a2)
> a$plate <- as.data.frame(plate[,1][1:384])
> colnames(a) <- c('MBases','Title','plate')

中级题

作业 1

根据R包org.Hs.eg.db找到下面ensembl 基因ID 对应的基因名(symbol)

> g2s <- toTable(org.Hs.egSYMBOL)
> g2e <- toTable(org.Hs.egENSEMBL)
> ensemble_id <- c('ENSG00000000003.13','ENSG00000000005.5','ENSG00000000419.11','ENSG00000000457.12','ENSG00000000460.15','ENSG00000000938.11')
> #批量取基因名
> library(stringr)
> unlist(str_split(ensemble_id,'[.]'))
 [1] "ENSG00000000003" "13"              "ENSG00000000005" "5"              
 [5] "ENSG00000000419" "11"              "ENSG00000000457" "12"             
 [9] "ENSG00000000460" "15"              "ENSG00000000938" "11"       
> tmp <- unlist(str_split(ensemble_id,'[.]',simplify = T))###simplify = T 此参数生成为矩阵
image.png
> class(unlist(str_split(ensemble_id,'[.]',simplify = T)))
[1] "matrix"
> ensemble_id <- tmp[,1]
> ensembl_id <- as.data.frame(ensemble_id)
image.png
> colnames(ensembl_id) <- 'ensembl_id'
> merge1 <- merge(x=ensembl_id,y=g2e,by='ensembl_id')
image.png
> merge2 <- merge(x=merge1,y=g2s,by='gene_id')
image.png
作业 2

根据R包hgu133a.db找到下面探针对应的基因名(symbol)

> tmp <- c('1053_at','117_at','121_at','1255_g_at','1316_at','1320_at','1405_i_at','1431_at','1438_at','1487_at','1494_f_at','1598_g_at','160020_at','1729_at','177_at')
> probe_id <- as.data.frame(tmp)
> View(probe_id)
> colnames(probe_id) <- 'probe_id'
> View(probe_id)
image.png
> a <- toTable(hgu133aSYMBOL)
> merge <- merge(x=probe_id,y=a,by='probe_id')
image.png
上一篇下一篇

猜你喜欢

热点阅读