Skip to content

Instantly share code, notes, and snippets.

@telatin
Created October 12, 2020 06:36
Show Gist options
  • Save telatin/c0d1eb3646c27144ec2870d8ef912bd1 to your computer and use it in GitHub Desktop.
Save telatin/c0d1eb3646c27144ec2870d8ef912bd1 to your computer and use it in GitHub Desktop.
library(edgeR)
# Input file and columns (ctrl, treated)
x <- read.delim("counts.tsv",row.names="Geneid")
group <- factor(c(1,1,1,2,2,2))
y <- DGEList(counts=x,group=group)
y <- calcNormFactors(y)
design <- model.matrix(~group)
y <- estimateDisp(y,design)
# Pairwise test
etx <- exactTest(y)
etp <- topTags(etx, n=100000, sort.by="p.value")
# Generate the output.
write.table(etp$table, file="etp.tsv", sep="\t", row.name=TRUE, quote=FALSE)
# Normalized counts
scale = y$samples$lib.size*y$samples$norm.factors
nc = round(t(t(x)/scale)*mean(scale))
# Save output
dt = data.frame("id"=rownames(nc),nc)
write.table(dt, file="norm-matrix-edgeR.txt", sep="\t", row.name=TRUE, col.names=NA,quote=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment