您的位置:首页 > 编程语言

WGCNA 课程56个样本基因的代码

2018-01-26 22:47 169 查看
首先把多个TXT文件合并为矩阵 用GIT

##ls

awk '{print FILENAME"\t"$0}' * |head

awk '{print FILENAME"\t"$0}' * |grep -v 名字 >tmp.txt

wc tmp.txt

library(WGCNA)

options(stringsAsFactors = FALSE)

enableWGCNAThreads()  ##这一步为开线程

#1. 数据读入,处理和保存

a=read.table( "C:/Users/TEMP.LAPTOP-C1T85A2O/Documents/tmp/tmp.txt",sep="\t",stringsAsFactors = F)

library(reshape2)

tmp <- a[1:20,]  ##选a的原因提前用小数据试一下确认操作无误继续曹操作

dcast(tmp,formula = V2~V1)   ##因为要的行是样本名列是基因
fpkm <- dcast(a,formula = V2~V1)

View(fpkm)

head(fpkm)

dim(fpkm)

names(fpkm)
rownames(fpkm) <- fpkm[,1]

fpkm <- fpkm[,-1]

unlist(lapply(names(fpkm),function(x){
  tmp <- strsplit(x,"_")[[1]],[2]
  tmp <- strsplit(x"\\.")[[1]][[1]]
})
)

datExpr0 <- t(fpkm)

gsg = goodSamplesGenes(datExpr0, verbose = 3);gsg$allOK

gsg$allOK
sampleTree = hclust(dist(datExpr0), method = "average")

library(WGCNA)


fpkm <- fpkm[,-1]

datExpr0 <- t(fpkm)
gsg = goodSamplesGenes(datExpr0, verbose = 3);
gsg$allOK  ##if false remove the missing gene and do it again
#datExpr0 < datExpr0[,gsg$goodGenes] 错了之后的做完这步再重复上两个
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  生物信息 IT