library(edgeR)

data = read.table("/data/images/proton/run125/www/genes.counts.matrix2", header=T, row.names=1, com='')
col_ordering = c(1,2,4)
rnaseqMatrix = data[,col_ordering]
rnaseqMatrix = round(rnaseqMatrix)
rnaseqMatrix = rnaseqMatrix[rowSums(rnaseqMatrix)>=2,]
conditions = factor(c(rep("FAGsA", 2), rep("GUT1", 1)))

exp_study = DGEList(counts=rnaseqMatrix, group=conditions)
exp_study = calcNormFactors(exp_study)
et = exactTest(exp_study, dispersion=0.1)
tTags = topTags(et,n=NULL)
r = rownames(tTags)
c=data[r,col_ordering]
write.table(cbind(tTags,c), file='genes.counts.matrix2.FAGsA_vs_GUT1.edgeR.DE_results', sep='	', quote=F, row.names=T)
source("/data/results/tools/align/trinity/trinityrnaseq_r20140413p1/Analysis/DifferentialExpression/R/rnaseq_plot_funcs.R")
pdf("genes.counts.matrix2.FAGsA_vs_GUT1.edgeR.DE_results.MDS.pdf")
plotMDS(exp_study)
dev.off()
pdf("genes.counts.matrix2.FAGsA_vs_GUT1.edgeR.DE_results.MA_n_Volcano.pdf")
result_table = tTags$table
plot_MA_and_Volcano(result_table$logCPM, result_table$logFC, result_table$FDR)
dev.off()
