TPM to logFC and pvalues

I assume you have to find differential expression between two cell lines (Cx and Dx groups). Since you need logFC and Pvalue, this R code can work. And you can use obtained matrix (mysample) to calculate FDR of your interest.

mysample <- read.table("./mymatrix.csv", sep=",", header=TRUE)

for(i in 2:nrow(mysample))

group1 <- mysample[i,grep('^C',names(mysample))]
group2 <- mysample[i,grep('^D',names(mysample))]

group1_avg <- sum(group1)/length(group1)
group2_avg <- sum(group2)/length(group2)

mysample[i, "C_avg"] <- group1_avg
mysample[i, "D_avg"] <- group2_avg

logfc <- abs(log2(group1_avg/group2_avg))

mysample[i, "LogFC"] <-  logfc

temp_data1 <- data.frame(values=c(group1,group2),vars = rep(c("C","D"), times = c(length(group1),length(group2))))
vars1 = c(rep(c("C","D"), times = c(length(group1),length(group2))))

x <- t.test(values1 ~ vars1, data = temp_data1)
pv <- c(x$p.value)

y <- wilcox.test(values1 ~ vars1, data = temp_data1)

wilcox <- c(y$p.value)

mysample[i, "TTEST"] <-  pv
mysample[i, "WilcoxTest"] <-  wilcox


write.table(mysample,"diffExp_res_TPM.txt", sep="t", quote=FALSE,

Source link