<blockquote>
  <p>I have seen many posts regarding counts to RPKM and TPM.</p>
</blockquote>

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

<p>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 <em>fragments</em>, not individual reads (of which each fragment has two, for paired-end data).</p>

<p>But as mentioned in the comments, <a href="https://bioinformatics.stackexchange.com/a/69/29">there are good reasons against using FPKMs</a>.</p>

CC BY-SA 4.0
2018-10-23T11:43:44.473Z
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 [https://gist.github.com/slowkow/6e34ccb4d1311b8fe62e] they used gene_length to convert counts to TPM. But I have seen one of your post in Rpubs [http://rpubs.com/klmr/rnaseq-norm] where you used effective length. Which one is the right one for converting counts to TPM?
beginner
CC BY-SA 4.0
2018-10-23T11:47:14.580Z
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.
Konrad Rudolph
CC BY-SA 4.0
2018-10-23T11:57:51.743Z
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?
beginner
CC BY-SA 4.0
2018-10-23T13:35:40.047Z
@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.
Konrad Rudolph
CC BY-SA 4.0
2018-10-23T13:44:02.917Z
Sure. I will. I'm working with TCGA data. could you please tell about my other question I the previous comment.
beginner
CC BY-SA 4.0
2018-10-23T13:50:17.693Z
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.
Konrad Rudolph
CC BY-SA 4.0
2018-10-22T12:39:34.817Z
2018-10-22T12:39:34.817Z
Konrad Rudolph
<p>You can use <a href="https://github.com/AAlhendi1707/countToFPKM" rel="nofollow noreferrer">countToFPKM</a> package.
This package provides an easy to use function to convert the read count matrix into FPKM matrix; following the equation in 
<img src="https://s0.wp.com/latex.php?latex=%5Ctext%7BFPKM%7D_i%20%3D%20%5Cdfrac%7BX_i%7D%7B%20%5Cleft%28%5Cdfrac%7B%5Cwidetilde%7Bl%7D_i%7D%7B10%5E3%7D%5Cright%29%20%5Cleft%28%20%5Cdfrac%7BN%7D%7B10%5E6%7D%20%5Cright%29%7D%20%3D%20%5Cdfrac%7BX_i%7D%7B%5Cwidetilde%7Bl%7D_i%20N%7D%20%5Ccdot%2010%5E9%20%20&amp;bg=ffffff&amp;fg=000000&amp;s=0" alt="enter image description here"></p>

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

<ul>
<li><code>counts</code> A numeric matrix of raw feature counts. </li>
<li><code>featureLength</code> A    numeric vector with feature lengths that can be
obtained using<br>
<a href="https://bioconductor.org/packages/release/bioc/vignettes/biomaRt/inst/doc/biomaRt.html" rel="nofollow noreferrer">biomaRt</a>.</li>
<li><code>meanFragmentLength</code> A numeric vector with mean fragment lengths,<br>
which can be calculate with <a href="https://broadinstitute.github.io/picard/command-line-overview.html#CollectInsertSizeMetrics" rel="nofollow noreferrer">Picard</a>
using CollectInsertSizeMetrics.</li>
</ul>

<p>See <a href="https://github.com/AAlhendi1707/countToFPKM" rel="nofollow noreferrer">https://github.com/AAlhendi1707/countToFPKM</a></p>

CC BY-SA 4.0
2019-03-23T17:10:56.673Z
2019-03-30T16:26:39.840Z
2019-03-30T16:26:39.840Z
Ahmed Alhendi
<p>I have seen many posts regarding counts to RPKM and TPM. I haven't seen any post for counts to FPKM. </p>

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

<p>There is a function to convert counts to RPKM: using the gene_length</p>

<pre><code>rpkm &lt;- function(counts, lengths) {
  rate &lt;- counts / lengths 
  rate / sum(counts) * 1e6
}
</code></pre>

<p>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]</p>

<p>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?</p>

<p>If not can anyone show some function or code to convert counts to FPKM please.</p>

<p>thanq</p>

CC BY-SA 4.0
2018-10-22T10:51:13.597Z
Why do you need RPKM/FPKM? Haven't you heard that these values are obsolete?
benn
CC BY-SA 4.0
2018-10-22T11:09:05.680Z
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 https://bioinformatics.stackexchange.com/a/4270/48, or this https://bioinformatics.stackexchange.com/a/69/48. @beginner I hope the links are helpful, update the question otherwise
llrs
CC BY-SA 4.0
2018-10-22T11:14:53.207Z
@Llopis thanks for the links. In this https://bioinformatics.stackexchange.com/questions/66/how-to-compute-rpkm-in-r/69#69 I see that FPKM function using effective length...it is gene_length right?
beginner
CC BY-SA 4.0
2018-10-22T11:17:05.607Z
@b.nota Yes, but as TCGA data is FPKM I wanted to use FPKM data.
beginner
CC BY-SA 4.0
2018-10-22T11:31:27.163Z
@beginner See this question and answers: https://bioinformatics.stackexchange.com/q/367/48
llrs
<rna-seq><rna><gene-expression><fpkm>
How to convert featureCounts to FPKM?
# How to convert featureCounts to FPKM?

(Asked by: username_0 on 2018-10-22)

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

**Tags:** rna-seq, rna, gene-expression, fpkm
> **Comments:**
> **username_1**: Why do you need RPKM/FPKM? Haven't you heard that these values are obsolete?  
> **username_2**: 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 https://bioinformatics.stackexchange.com/a/4270/48, or this https://bioinformatics.stackexchange.com/a/69/48. @beginner I hope the links are helpful, update the question otherwise  
> **username_0**: @Llopis thanks for the links. In this https://bioinformatics.stackexchange.com/questions/66/how-to-compute-rpkm-in-r/69#69 I see that FPKM function using effective length...it is gene_length right?  
> **username_0**: @b.nota Yes, but as TCGA data is FPKM I wanted to use FPKM data.  
> **username_2**: @beginner See this question and answers: https://bioinformatics.stackexchange.com/q/367/48  

---

## 2 answers

### Answer by username_3 on 2018-10-22. Score: 4

> 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](https://bioinformatics.stackexchange.com/a/69/29).

> **Comments:**
> **username_0**: 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 [https://gist.github.com/slowkow/6e34ccb4d1311b8fe62e] they used gene_length to convert counts to TPM. But I have seen one of your post in Rpubs [http://rpubs.com/klmr/rnaseq-norm] where you used effective length. Which one is the right one for converting counts to TPM?  
> **username_3**: 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.  
> **username_0**: 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?  
> **username_3**: @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.  
> **username_0**: Sure. I will. I'm working with TCGA data. could you please tell about my other question I the previous comment.  
> **username_3**: 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.  

---

### Answer by username_4 on 2019-03-23. Score: 2

You can use [countToFPKM](https://github.com/AAlhendi1707/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](https://s0.wp.com/latex.php?latex=%5Ctext%7BFPKM%7D_i%20%3D%20%5Cdfrac%7BX_i%7D%7B%20%5Cleft%28%5Cdfrac%7B%5Cwidetilde%7Bl%7D_i%7D%7B10%5E3%7D%5Cright%29%20%5Cleft%28%20%5Cdfrac%7BN%7D%7B10%5E6%7D%20%5Cright%29%7D%20%3D%20%5Cdfrac%7BX_i%7D%7B%5Cwidetilde%7Bl%7D_i%20N%7D%20%5Ccdot%2010%5E9%20%20&bg=ffffff&fg=000000&s=0)

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](https://bioconductor.org/packages/release/bioc/vignettes/biomaRt/inst/doc/biomaRt.html).
* `meanFragmentLength` A numeric vector with mean fragment lengths,  
  which can be calculate with [Picard](https://broadinstitute.github.io/picard/command-line-overview.html#CollectInsertSizeMetrics)
  using CollectInsertSizeMetrics.

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


---

