<p>The best way to deal with this is to use unique gene IDs, for example ensembl accession numbers. So use the ensemble gtf annotation when quantifying the read counts and not the gene symbols. Just to illustrate, when I look for "5S_rRNA" in ensembl's annotation, i see 18 different "genes" with that gene symbol. But which 2 you have is unclear now.</p>

<pre><code>grep "5S_rRNA" ensembl_symbol.txt
"ENSG00000252830"       "5S_rRNA"
"ENSG00000276442"       "5S_rRNA"
"ENSG00000274408"       "5S_rRNA"
"ENSG00000274059"       "5S_rRNA"
"ENSG00000276861"       "5S_rRNA"
"ENSG00000274759"       "5S_rRNA"
"ENSG00000280646"       "5S_rRNA"
"ENSG00000277411"       "5S_rRNA"
"ENSG00000201285"       "5S_rRNA"
"ENSG00000212595"       "5S_rRNA"
"ENSG00000277418"       "5S_rRNA"
"ENSG00000277049"       "5S_rRNA"
"ENSG00000274097"       "5S_rRNA"
"ENSG00000277488"       "5S_rRNA"
"ENSG00000274663"       "5S_rRNA"
"ENSG00000283433"       "5S_rRNA"
"ENSG00000275305"       "5S_rRNA"
"ENSG00000278457"       "5S_rRNA"
</code></pre>

CC BY-SA 4.0
2018-10-25T09:57:04.920Z
Yes you are right. But can I take median of those duplicates? something like aggregate(. ~ gene_name, data = df, median)
beginner
CC BY-SA 4.0
2018-10-25T10:03:18.393Z
Expanding this answer, it seems that it was mapped to ensembl ids. So I would recommend to keep them as they are, and only when looking for biological meaning to change to gene symbols (or when talking to others)
llrs
CC BY-SA 4.0
2018-10-25T10:04:07.930Z
I would strongly advice not to use FPKM at all, it is pretty clear now that they are not the right values to use for any analysis. If you still want to use it, keep your two genes apart like they were.
benn
CC BY-SA 4.0
2018-10-25T09:44:56.603Z
2018-10-25T11:13:11.407Z
2018-10-25T11:13:11.407Z
benn
<p>I assume you're familiar with the various issues surrounding FPKMs, so I'll not expound upon them.</p>

<p>As a general rule, you should be using gene IDs rather than gene names, since the former are unique while the latter are not. If you only have access to data quantified on gene names, then the appropriate way to merge RPKMs is with a weighted sum:</p>

<p><span class="math-container">$FPKM_{gene} = \frac{FPKM_{copy1} * Length_{copy1} + FPKM_{copy2} * Length_{copy2}}{Length_{copy1} + Length_{copy2}}$</span></p>

<p>As an aside, rRNA expression levels will tend to be wrong, since they're normally excluded by either poly-A enrichment or the use of ribo-zero.</p>

CC BY-SA 4.0
2018-10-25T15:09:58.077Z
Sure I will use gene ids. but lets say I have counts data and before doing differential analysis do you think this is the right to way to filter duplicates; aggregate(. ~ gene_name, data = df, max)
beginner
CC BY-SA 4.0
2018-10-25T17:07:48.200Z
If you have counts then sum them.
Devon Ryan
CC BY-SA 4.0
2018-10-25T18:17:12.130Z
So, if the first column is Ensembl ids and all other columns are samples in a dataframe "df", Is this right way to sum the duplicate Ensembl ids? aggregate(. ~Ensembl_ids, data=df, FUN=sum)
beginner
CC BY-SA 4.0
2018-10-25T21:24:03.947Z
There should never be duplicate Ensembl IDs, they're unique. You only have issues like this with gene names or UCSC IDs.
Devon Ryan
CC BY-SA 4.0
2018-10-25T21:29:37.187Z
oh yes, so with gene names Is this the way to sum the counts of duplicates aggregate(. ~gene_names, data=df, FUN=sum)
beginner
CC BY-SA 4.0
2018-11-14T09:41:29.490Z
I have to say I disagree with the weighted approach - why would you place more emphasis on any of the individdual loci (in this case the longer)?
Kristoffer Vitting-Seerup
CC BY-SA 4.0
2018-10-25T09:57:56.657Z
2018-10-25T09:57:56.657Z
Devon Ryan
<p>I have RNA-Seq data which is <code>FPKM</code>. In the dataframe <code>df</code> first column is <code>gene_name</code> and the other 100 columns are <code>samples</code>.</p>

<p>Usually if it is <code>counts</code> data I do like following:</p>

<pre><code>df2 &lt;- aggregate(. ~ gene_name, data = df, max)
</code></pre>

<p>I'm not sure what do with the <code>FPKM</code> data if there are duplicate genes with different <code>FPKM</code> value for the same sample.</p>

<p>Lets say it looks like this:</p>

<pre><code>gene_name     sample1        sample2        sample3
5S_rRNA      0.3206147    0.3327312      0.377578
5S_rRNA      0.3342000    0.0000000      0.1305166
</code></pre>

<p>Any suggestions please.</p>

CC BY-SA 4.0
2018-10-25T09:16:15.603Z
How were the read mapped? Do you have access to the raw counts data?
llrs
CC BY-SA 4.0
2018-10-25T09:57:49.090Z
I have downloaded TCGA FPKM data. Would like to use the data for co-expression analysis with cemitool
beginner
<r><rna-seq><gene-expression><fpkm>
How to deal with duplicate genes having different expression values?
# How to deal with duplicate genes having different expression values?

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

I have RNA-Seq data which is FPKM. In the dataframe df first column is gene_name and the other 100 columns are samples.
Usually if it is counts data I do like following:
df2 <- aggregate(. ~ gene_name, data = df, max)

I'm not sure what do with the FPKM data if there are duplicate genes with different FPKM value for the same sample.
Lets say it looks like this:
gene_name     sample1        sample2        sample3
5S_rRNA      0.3206147    0.3327312      0.377578
5S_rRNA      0.3342000    0.0000000      0.1305166

Any suggestions please.

**Tags:** r, rna-seq, gene-expression, fpkm
> **Comments:**
> **username_1**: How were the read mapped? Do you have access to the raw counts data?  
> **username_0**: I have downloaded TCGA FPKM data. Would like to use the data for co-expression analysis with cemitool  

---

## 2 answers

### Answer by username_3 on 2018-10-25. Score: 5 | Accepted answer

I assume you're familiar with the various issues surrounding FPKMs, so I'll not expound upon them.

As a general rule, you should be using gene IDs rather than gene names, since the former are unique while the latter are not. If you only have access to data quantified on gene names, then the appropriate way to merge RPKMs is with a weighted sum:

$FPKM\_{gene} = \frac{FPKM\_{copy1} \* Length\_{copy1} + FPKM\_{copy2} \* Length\_{copy2}}{Length\_{copy1} + Length\_{copy2}}$

As an aside, rRNA expression levels will tend to be wrong, since they're normally excluded by either poly-A enrichment or the use of ribo-zero.

> **Comments:**
> **username_0**: Sure I will use gene ids. but lets say I have counts data and before doing differential analysis do you think this is the right to way to filter duplicates; aggregate(. ~ gene_name, data = df, max)  
> **username_3**: If you have counts then sum them.  
> **username_0**: So, if the first column is Ensembl ids and all other columns are samples in a dataframe "df", Is this right way to sum the duplicate Ensembl ids? aggregate(. ~Ensembl_ids, data=df, FUN=sum)  
> **username_3**: There should never be duplicate Ensembl IDs, they're unique. You only have issues like this with gene names or UCSC IDs.  
> **username_0**: oh yes, so with gene names Is this the way to sum the counts of duplicates aggregate(. ~gene_names, data=df, FUN=sum)  
> **username_4**: I have to say I disagree with the weighted approach - why would you place more emphasis on any of the individdual loci (in this case the longer)?  

---

### Answer by username_2 on 2018-10-25. Score: 3

The best way to deal with this is to use unique gene IDs, for example ensembl accession numbers. So use the ensemble gtf annotation when quantifying the read counts and not the gene symbols. Just to illustrate, when I look for "5S_rRNA" in ensembl's annotation, i see 18 different "genes" with that gene symbol. But which 2 you have is unclear now.
grep "5S_rRNA" ensembl_symbol.txt
"ENSG00000252830"       "5S_rRNA"
"ENSG00000276442"       "5S_rRNA"
"ENSG00000274408"       "5S_rRNA"
"ENSG00000274059"       "5S_rRNA"
"ENSG00000276861"       "5S_rRNA"
"ENSG00000274759"       "5S_rRNA"
"ENSG00000280646"       "5S_rRNA"
"ENSG00000277411"       "5S_rRNA"
"ENSG00000201285"       "5S_rRNA"
"ENSG00000212595"       "5S_rRNA"
"ENSG00000277418"       "5S_rRNA"
"ENSG00000277049"       "5S_rRNA"
"ENSG00000274097"       "5S_rRNA"
"ENSG00000277488"       "5S_rRNA"
"ENSG00000274663"       "5S_rRNA"
"ENSG00000283433"       "5S_rRNA"
"ENSG00000275305"       "5S_rRNA"
"ENSG00000278457"       "5S_rRNA"

> **Comments:**
> **username_0**: Yes you are right. But can I take median of those duplicates? something like aggregate(. ~ gene_name, data = df, median)  
> **username_1**: Expanding this answer, it seems that it was mapped to ensembl ids. So I would recommend to keep them as they are, and only when looking for biological meaning to change to gene symbols (or when talking to others)  
> **username_2**: I would strongly advice not to use FPKM at all, it is pretty clear now that they are not the right values to use for any analysis. If you still want to use it, keep your two genes apart like they were.  

---

