Dear Michael,
I have to calculate rpkm from counts data which I got from STAR. I'm using edgeR for this and it needs gene_length. I'm doing this rpkm calculation not for DE analysis. Could you please tell me how can I calculate rpkm from counts.
Do you think this is the right way to calculate gene_length?
library(GenomicFeatures)
hg19.ens <- makeTxDbFromUCSC(genome="hg19", tablename="ensGene")
exonic <- exonsBy(hg19.ens, by="gene")
red.exonic <- reduce(exonic)
exon.lengths <- sum(width(red.exonic))
If you use featureCounts from subread (http://subread.sourceforge.net/) instead of htseq for your quantification, you will get the gene length automatically. Just a suggestion.
The length in featureCounts is wrong. Because it includes the length of intron!