library(edgeR)

data = read.table("/data/images/proton/run125/www/genes2.counts.matrix4", header=T, row.names=1, com='')
col_ordering = c(1,2,6)
rnaseqMatrix = data[,col_ordering]
rnaseqMatrix = round(rnaseqMatrix)
rnaseqMatrix = rnaseqMatrix[rowSums(rnaseqMatrix)>=2,]
conditions = factor(c(rep("FAGsA", 2), rep("FAGsB", 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='genes2.counts.matrix4.FAGsA_vs_FAGsB.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("genes2.counts.matrix4.FAGsA_vs_FAGsB.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()
