Question: Calculating FPKM from raw counts data using fpkm() in deseq2
0
Beginner50 wrote:

I have raw counts data from featureCounts. I actually wanted to do survival analysis. For a specific gene I want to classify the samples into Low and High based on expression cutoff. For that I'm using maxstat package.

First I would like to convert raw counts to FPKM. So, I did like following.

              sample1   sample2   sample3   sample4   sample5
A1BG-AS1      195         612       145       131       300
A2M-AS1       373         445       573      1388      1386
A2ML1-AS1     75          27         45       18        35
A2ML1-AS2      0           0         0         0        0
AA06           0           0         0         0        0

I have a matrix like above having genes as rows and samples as columns.

library("DESeq2")
dds <- DESeqDataSetFromMatrix(countData = counts,
colData = coldata,
design = ~ Type)
dds
dds <- estimateSizeFactors(dds)

And now I used fpm() function to calculate FPKM from counts data.

fpkm_data <- fpkm(dds)
Error in fpkm(dds) : rowRanges(object) has all ranges of zero width.
the user should instead supply a column, mcols(object)$basepairs, which will be used to produce FPKM values​ Sorry, no idea about what to do now. Can you please tell me what I need to do to the data to calculate FPKM. Thank you Hello, I am having the same question. So I have a matrix with the gene length which i calculated from the gff file and I want to add this in the dds in order to run the fpkm(dds) can you help me with this? ADD REPLYlink written 4 weeks ago by aapapaiwannou0 Just add the number of basepairs to here: mcols(dds)$basepairs = ...

Answer: Calculating FPKM from raw counts data using fpkm() in deseq2
0
Michael Love26k wrote:

It’s not trivial to calculate the gene lengths. I don’t have any simple generic code to get the gene lengths (exonic basepairs).

I collaborated on Salmon which is a sophisticated model for estimating abundance, so that’s my solution if users want to work with expression values, rather than making arbitrary calculations on counts (arbitrary because you don’t know the gene length).

I can actually get the gene lengths from the annotation gtf file. So, if I add that gene_length column to the matrix will it work?

Try following the advice given in the message from the software and see how it works. If you get stuck then it’s appropriate to post.