CPM<-read.table("~/Desktop/OneDrive/GTEx/cpm.tsv",header = T,row.names = 1)#读取文档
TPM<-read.table("~/Desktop/OneDrive/GTEx/pm.tsv",header = T,row.names = 1)
#设置一个计数用的函数
MyFunction<-function(x){
ifelse(x>2,1,0)
}
#设置一个空的变量储存基因
keep_genes<-vector()
row_names<-row.names(CPM)
#Run一个循环,这里样本总数为130也可以用ncol(CPM)来实现
for (i in row_names){
cpm<-CPM[i,]
count<-apply(cpm,2,MyFunction)
a<-sum(count)
if (a>=65)
keep_genes<-c(keep_genes,i)
}
#最终还是要回归到TPM中,提取TPM中符合条件的基因
keep_TPM<-TPM[keep_genes,]
write.csv(keep_TPM,"tpm_cpm>2.csv")
网友评论