R语言for循环练习
2019-07-02 本文已影响0人
ShawnMagic
Assignment
We obtained the readcount and tpm matrix of miRNA from the results of smallRNA sequencing. But this information was merged in one file, I want to extract the tpm value and divide it into 3 files by tissues.
tissue
- leaf
- ovule
- fiber
Workflow:
import matrix into R ==> select cols of tpm ==> export
code
## import file
miRNA.all<-read.table("~/ShawnProject_PhD/MergedData/Readcount_TPM.xls",
header = T,
sep = "\t")
str(miRNA.all)
####################################################
# part of the miRNA.all
# $ B1_O.tpm : num 86.4 43.2 205.2 17794.9 4697.1 ...
# $ B985S_F.tpm : num 309 154 0 12748 14098 ...
# $ B985S_L.tpm : num 1439.1 34.3 34.3 18536.9 445.4 ...
# $ B985S_O.tpm : num 105.7 26.4 52.8 36069.1 2985.9 ...
# $ B985_F.tpm : num 422 188 0 27391 12041 ...
# $ B985_L.tpm : num 902.2 19.2 38.4 21634.6 643.1 ...
# $ B985_O.tpm : num 176 0 0 23182 4039 ...
####################################################
## the pattern of tpms of each tissue was "_"{tissue}.tpm
# config
seq = c(1,2,3)
tissue = c("F","L","O")
name = c("fiber","leaf","ovule")
# looping
for (i in seq) {
names <- paste(name[i],".mi",sep = "")
pattern <- paste("_",tissue[i],".tpm",sep = "")
assign(names, data.frame(miRNA = miRNA.all$sRNA.readcount,# add the miRNA_id
dplyr::select(miRNA.all, contains(pattern))))
}
save(fiber.mi, ovule.mi, leaf.mi, file = "miRNA.tpm.Rdata")