3
$\begingroup$

I have seen many posts regarding counts to RPKM and TPM. I haven't seen any post for counts to FPKM.

I have RNA-Seq data which is paired-end reads. Extracted the counts using featureCounts for all the samples.

There is a function to convert counts to RPKM: using the gene_length

rpkm <- function(counts, lengths) {
  rate <- counts / lengths 
  rate / sum(counts) * 1e6
}

I know that RPKM is mainly used for single-end reads data. Do you think I can use the above function for converting counts to FPKM as my data is paired end? [TCGA data: HTSeq counts are converted to HTSeq FPKM]

Somewhere I have seen that the same function applies for single end data which will be RPKM and also for paired end data which will be FPKM. Am Ir right or wrong?

If not can anyone show some function or code to convert counts to FPKM please.

thanq

$\endgroup$
  • $\begingroup$ Why do you need RPKM/FPKM? Haven't you heard that these values are obsolete? $\endgroup$ – benn Oct 22 '18 at 10:51
  • 1
    $\begingroup$ I guess OP wants to follow the most up to date procedures, but seeing that in TCGA they used FPKM is trying to work like them. I thought that FPKM were ok: see this bioinformatics.stackexchange.com/a/4270/48, or this bioinformatics.stackexchange.com/a/69/48. @beginner I hope the links are helpful, update the question otherwise $\endgroup$ – llrs Oct 22 '18 at 11:09
  • $\begingroup$ @Llopis thanks for the links. In this bioinformatics.stackexchange.com/questions/66/… I see that FPKM function using effective length...it is gene_length right? $\endgroup$ – beginner Oct 22 '18 at 11:14
  • $\begingroup$ @b.nota Yes, but as TCGA data is FPKM I wanted to use FPKM data. $\endgroup$ – beginner Oct 22 '18 at 11:17
  • $\begingroup$ @beginner See this question and answers: bioinformatics.stackexchange.com/q/367/48 $\endgroup$ – llrs Oct 22 '18 at 11:31
4
$\begingroup$

I have seen many posts regarding counts to RPKM and TPM.

There’s your answer then: FPKM = RPKM. It’s simply a more accurate name.

Speaking of RPKM for paired-end data is discouraged because the reference to “read” in this context lends itself to ambiguity. But mathematically the quantity is the same: we are counting fragments, not individual reads (of which each fragment has two, for paired-end data).

But as mentioned in the comments, there are good reasons against using FPKMs.

$\endgroup$
  • $\begingroup$ thanks for the answer. I have a question. I have Ensembl gene ids as rows and samples as columns with counts. I have an other column gene_length. I'm trying to convert those counts to TPM. In this post [gist.github.com/slowkow/6e34ccb4d1311b8fe62e] they used gene_length to convert counts to TPM. But I have seen one of your post in Rpubs [rpubs.com/klmr/rnaseq-norm] where you used effective length. Which one is the right one for converting counts to TPM? $\endgroup$ – beginner Oct 23 '18 at 11:43
  • 2
    $\begingroup$ In every case, the correct number is the effective length, i.e. the transcript/gene length minus the average read length plus 1 (this is the “effective” length because it represents the number of possible alignment positions of a read to the transcript). That said, in practice it should make very little difference. $\endgroup$ – Konrad Rudolph Oct 23 '18 at 11:47
  • $\begingroup$ I see that in the post it is given EffectiveLength = Length - mean_fragment_length + 1; And how the mean_fragment_length is 300? One more question can I use this for Ensembl gene ids? or only for transcripts? $\endgroup$ – beginner Oct 23 '18 at 11:57
  • 3
    $\begingroup$ @beginner The fragment length is determined by your sequencing protocol. It’s (more or less) the distance between the two paired reads (including the read lengths, minus any overlap). For a typical long RNA-seq library prep it’s often in the order of 300–400 bp. You can run Picard’s CollectInsertSizeMetrics tool on your aligned BAM files to find the mean fragment length. $\endgroup$ – Konrad Rudolph Oct 23 '18 at 13:35
  • 1
    $\begingroup$ You can use this on any annotated feature you like, both genes and transcripts. There are some fundamental issues with using genes (essentially, you lose information about alternative transcripts, and gene-level statistics by necessity need to average across transcripts) but that isn’t specific to quantification, and in practice it’s usually not an issue. $\endgroup$ – Konrad Rudolph Oct 23 '18 at 13:50
2
$\begingroup$

You can use countToFPKM package. This package provides an easy to use function to convert the read count matrix into FPKM matrix; following the equation in enter image description here

The fpkm() function requires three inputs to return FPKM as numeric matrix normalized by library size and feature length:

  • counts A numeric matrix of raw feature counts.
  • featureLength A numeric vector with feature lengths that can be obtained using
    biomaRt.
  • meanFragmentLength A numeric vector with mean fragment lengths,
    which can be calculate with Picard using CollectInsertSizeMetrics.

See https://github.com/AAlhendi1707/countToFPKM

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.