Question: edgeR RPKM Values
gravatar for gtasource
22 months ago by
gtasource30 wrote:


I am trying to use edgeR to calculate RPKM values. However, when I have searched for help on this topic. I've still not been able to make sense of the existing R codes to work for me. Here's my current code:

data_raw <- read.table("counts.txt", header = TRUE)
group <- c(rep("Sample1",2),rep("Sample1",2))
d <- DGEList(counts = data_raw, group=group) <- read.table("gene_lengths.txt", header=FALSE)
m <- match(rownames(d),$Transcript)
gene.lengths <-$TranscriptLength[m]

My gene lengths file looks like this:

Gene1   35029
Gene2   72475
Gene3   48792
Gene4   46840

As you can see, I understand that there is limitation in only having two reps. But if anybody could help with this code, or lead me to a tutorial, that would be great.

edger bioconductor R • 1.5k views
ADD COMMENTlink modified 19 months ago by Biostar ♦♦ 20 • written 22 months ago by gtasource30

What is the problem? Do you get an error message? What message, at which step?

ADD REPLYlink written 22 months ago by h.mon29k

After the RPKM step, I receive this errror:

Warning message:
In Ops.factor(left, right) : ‘/’ not meaningful for factors
ADD REPLYlink written 22 months ago by gtasource30

Yes because your code is wrong.



’’ has extra column of gene names in the first column. It just needs gene length colum. Try this in your above code, it might work.


Else below mentioned complete sample code will perfectly work.

ADD REPLYlink modified 21 months ago • written 21 months ago by EagleEye6.5k
group <- c(rep("Sample1",2),rep("Sample1",2))

Why do you have same sample names ('Sample1') for both group. I assume it is,

group <- c(rep("Sample1",2),rep("Sample2",2))

Sample Code:

   data_raw <- read.table("counts.txt", header = T, sep='\t', row.names=1) # Assumed it has column with 1-transcriptids, 2-Sample1.1, 3-Sample1.2, 4-Sample2.1, 5-Sample2.2

    data_raw[,"Transcript"] <- rownames(data_raw) # Adding "Transcript" ids column <- read.table("gene_lengths.txt", header=T, sep='\t') # Assumed has two columns 'Transcript' and 'TranscriptLength'

    m <- merge(data_raw,,by="Transcript")

    group <- c(rep("Sample1",2),rep("Sample2",2))

    d <- DGEList(counts =m[,c(2:5)], group=group) # 1-Transcript, 2-Sample1.1, 3-Sample1.2, 4-Sample2.1, 5-Sample2.2, TranscriptLength

ADD REPLYlink modified 22 months ago • written 22 months ago by EagleEye6.5k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2420 users visited in the last hour