setwd("/home/tommy/scripts")
library("DESeq")
countsTable<- read.delim("All_counts_nozero_1pseudocount_with_header.txt", header=TRUE)
rownames(countsTable)<- countsTable$Gene
countsTable<- countsTable[,-1]

head(countsTable)
conds<- factor(c("alpha","beta","alpha","beta","alpha","beta"))

cds<- newCountDataSet(countsTable, conds)
cds<- estimateSizeFactors(cds)
sizeFactors(cds)
head(counts(cds))
head(counts(cds,normalized=TRUE))
cds<- estimateDispersions(cds)

plotDispEsts(cds)

res = nbinomTest( cds, 'alpha', 'beta' )
head(res)
plotMA(res)

hist(res$pval, breaks=100, col='skyblue', border='slateblue', main='')
resSig = res[ res$pval < 0.1, ]
head(resSig)

cdsBlind<- estimateDispersions(cds, method= "blind")
vsd<- varianceStabilizingTransformation(cdsBlind)
plotPCA(vsd, intgroup=c("condition"))