creating design and count matrix for rna-seq differential expression
1
1
Entering edit mode
7.1 years ago

Hello

I am trying to understand how to run a differential expression using R and for that I am referring to Smyth and other's "limma: linear models for microarray and RNA-seq data user guide" (2016). This vignette refers to data sets provided by WEHI bioinfo. The latter provides the link to a dataset made of four libraries (A_1, A_2, B_1 and B_2), a chromosome reference fasta file and a Targets.txt file in the form:

CellType    InputFile   OutputFile
A           A_1.txt.gz  A_1.bam
A           A_2.txt.gz  A_2.bam
B           B_1.txt.gz  B_1.bam
B           B_2.txt.gz  B_2.bam

The case study prepares a design object using a model.matrix function based on the CellType field of the Targets.txt file, then creates an index reference and performs alignment, summarization, filtering, normalization and finally linear model fitting using the following commands:

library(limma)
library(edgeR)
library(Rsubread)
targets <- readTargets(file="Targets.txt") 
celltype <- factor(targets$CellType)
design <- model.matrix(~celltype)
buildindex(basename = "chr1", reference = "hg19_chr1.fa") 
align(index = "chr1", readfile1 = targets$InputFile, input_format = "gzFASTQ", output_format = "BAM", output_file = targets$OutputFile, unique = TRUE, indels = 5)
fc <- featureCounts(files = targets$OutputFile, annot.inbuilt = "hg19") 
x <- DGEList(counts = fc$counts, genes = fc$annotation[,c("GeneID", "Length")])
isexpr <- rowSums(cpm(x) > 10) >= 2
x <- x[isexpr,]
y <- voom(x, design, plot = TRUE) 
fit <- eBayes(lmFit(y, design))

This all works fine -- although it is unfeasible to attach the actual data herein -- and I wanted to extend this example to the Smith's example (page 69). Here the first step is to create a matrix of read counts; I believe this should come from the featureCounts function thus it is represented by the fc object. The second step is to remove the low counts and to apply scale normalization. I therefore used:

dge <- DGEList(counts = fc$counts, genes = fc$annotation[,c("GeneID", "Length")])
isexpr <- rowSums(cpm(dge) > 10) >= 2
dge <- dge[isexpr,]
dge <- calcNormFactors(dge)
logCPM <- cpm(dge, log = TRUE, prior.count = 3)
fit <- eBayes(logCPM, design)

but I get an error in the final step:

> fit <- eBayes(logCPM, design)
Error: $ operator is invalid for atomic vectors

The same is true if I take off the annotation feature of dge with

dge <- DGEList(counts = fc$counts)

I imagine the problem is due to the design object, so my question is how can I handle the model.matrix function so that I can apply it to different cases? Thank you.

RNA-Seq • 3.0k views
ADD COMMENT
0
Entering edit mode
7.1 years ago

I imagine the issue is related to you skipping the lmFit() step after cpm().

ADD COMMENT
0
Entering edit mode

Nice catch Devon!! Upvote to you. Definitely need a linear model prior to running eBayes.

ADD REPLY
0
Entering edit mode

ops, i did miss that line. Running:

logCPM <- cpm(dge, log = TRUE, prior.count = 3)
fit <- lmFit(logCPM, design)
fit <- eBayes(fit, trend = TRUE)

as in the vignette goes smoothly. my bad.

ADD REPLY

Login before adding your answer.

Traffic: 2034 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6