Skip to content

Instantly share code, notes, and snippets.

@nachocab
Created April 29, 2015 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nachocab/4931cc20084472941e85 to your computer and use it in GitHub Desktop.
Save nachocab/4931cc20084472941e85 to your computer and use it in GitHub Desktop.
targets <- read.table("targets.txt", header = TRUE)
counts <- read.delim("counts.txt", row.names = "gene_id")
counts <- counts[, targets$sample_name] # important, the ordering of the columns in the counts file must match the sample_name in the targets file
group <- factor(targets$virus_dpi, levels = unique(targets$virus_dpi))
library(edgeR)
y <- DGEList(counts = counts, group = group)
y <- calcNormFactors(y)
design <- model.matrix( ~ 0 + group, data = y$samples)
colnames(design) <- levels(group)
y <- estimateGLMCommonDisp(y, design)
y <- estimateGLMTrendedDisp(y, design)
y <- estimateGLMTagwiseDisp(y, design)
fit <- glmFit(y, design)
contrasts <- makeContrasts(
lassa_d3 = (lassa_3 - lassa_0),
marburg_d3 = (marburg_3 - marburg_0),
ebola_k_d4 = (ebola_k_4 - ebola_k_0),
common_early = (marburg_3 + lassa_3 + ebola_k_4)/3 - (marburg_0 + lassa_0 + ebola_k_0)/3,
# you can add more contrasts here
levels = design)
contrast_name <- "lassa_d3" # or "ebola_k_d4", etc.
lrt <- glmLRT(fit, contrast = contrasts[,contrast_name])
topTags(lrt)
# I recommend you add a gene_name column to lrt$table so you don't have to work with gene ids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment