美文网首页ggplot集锦
R处理输入数据——学习DEseq2包

R处理输入数据——学习DEseq2包

作者: 纵纵纵小鸮 | 来源:发表于2022-09-04 21:25 被阅读0次

    1. names()函数:

    get or set the names of one object

    2. 利用DEseq2计算fpkm后fpkm转tpm

    data_in = read.table("pla_cat_counts.txt", head=TRUE,row.names =1)

    countData = as.data.frame(data_in)

    colData = read.table("design.txt", head=TRUE)

    names(colData)=c("samples","condition")

    dds <- DESeqDataSetFromMatrix(countData = countData,

                                      colData = colData,

                                      design = ~ condition)

    rowRanges(dds) = ebg

    head(rowRanges(dds))

    fpkm_out = fpkm(dds)

    write.table(as.data.frame(fpkm_out), file="fpkm_out.txt",sep="\t",quote = FALSE)

    ###fpkmtotpm

    fpkm<-read.table("fpkm_out.txt", sep = "\t", head=TRUE, row.names = 1)

    head(fpkm)

    fpkmToTpm <- function(fpkm){

      exp(log(fpkm) - log(sum(fpkm)) + log(1e6))

    }

    tpms <- data.frame(apply(fpkm,2,fpkmToTpm))

    head(tpms)

    colSums(tpms)    

    3. 在R中查看数据类型

    dim查看数据维度,mode查看数据类型,class查看数据对象类型

    4. 批量输出文件

    for (item in 1:groupnum){ ###遍历所有比较组

      name=paste("result",item,".txt",sep="")

    5. 提取data.frame中的某行某列

    group1sample <- design[design$condition == g1,][1]   ##提取design中condition=g1的行

    library(dplyr)

    G1tpm1<-(select(tpms,group1sample[1,]))   ##提取tpms中列名等于 group1sample[1,]的列

    6. 合并列,并计算平均值

    group2tpm <- cbind(G2tpm1, G2tpm2)   

    mean2<- rowMeans(group2tpm, na.rm=F)   

    相关文章

      网友评论

        本文标题:R处理输入数据——学习DEseq2包

        本文链接:https://www.haomeiwen.com/subject/thwmnrtx.html