<p>Lots of ways to do this, but here's one way using <a href="/questions/tagged/sed" class="post-tag" title="show questions tagged &#39;sed&#39;" rel="tag">sed</a>:</p>
<pre><code>sed 's/TRINITY_\([^_]\+\)_\([^_]\+\)_[^:]\+/\1_\2/g' file.tree
</code></pre>
<p>The above applies a substitution to capture the first two fields using parentheses (which need to be escaped). Each field captures any character not an underscore one or more times (using the &quot;+&quot; symbol, which also needs to be escaped). Finally, we also match any character not a colon one or more times. The replacement string can be just the first two capture groups separated with an underscore.</p>

CC BY-SA 4.0
2021-12-22T03:47:37.970Z
Hi Steve,
Thanks for your warm response. But my file is a ".tree" file, not a fasta file since the file dosent start with a ">" symbol. Like as following the file looks:

(TRINITY_Clupea_DN5452_c0_g1_i1.p1:0.0824467436,TRINITY_Engraulis_DN43599_c0_g1_i1.p1:0.1634781085)100:0.0876433106,TRINITY_Sardina_DN15766_c0_g1_i2.p1:0.0164132018)..................

And i want like:

(Clupea_DN5452:0.0824467436,Engraulis_DN43599:0.1634781085)100:0.0876433106,Sardina_DN15766:0.0164132018)..................

Want to keep only the 2nd and 3rd part from the id. 

Thanks.
Kishor Kumar Sarker
CC BY-SA 4.0
2021-12-22T02:12:43.133Z
2021-12-22T05:01:20.483Z
2021-12-22T05:01:20.483Z
Steve
<p>If you want to remove component/gene/isoform parts from a Trinity ID, you can do <code>s/_c[0-9]+_.*?:/:/</code> to remove anything between the first c with only numbers after it up to the next colon. Combining this with the TRINITY removal at the start, it'd be something like this:</p>
<pre><code>sed 's/TRINITY_\(.*?\)_c[0-9]+_.*?:/\1:/g' file.tree
</code></pre>

CC BY-SA 4.0
2022-01-03T12:23:40.403Z
I have tried like as follows:
sed 's/TRINITY_\(.*?\)_c[0-9]+_.*?:/\1:/g' OG0000004.tre


But is priniting like as:
(TRINITY_Engraulis_DN849_c0_g1_i1.p1:0.05941030350315353731,(((((TRINITY_Tenualosa_DN4978_c0_g1_i1.p1:0.07382876155314552213,TRINITY_Alosa_DN5385_c0_g1_i1.p1:0.01287649339098437609):0.00905926786283233615,TRINITY_Sardina_DN264_c0_g1_i7.p1:0.02335748047027334101):0.04151957750042657019,((TRINITY_Colia_DN12738_c0_g1_i1.p1:0.04097580399145889923,(TRINITY_Engraulis_DN8273_c0_g2_i3.p1:0.04815781217046399831,(((((TRINITY_Engraulis_DN16258_c3_g1_i1.p1:0.08818477156986732901,....
Kishor Kumar Sarker
CC BY-SA 4.0
2022-01-04T09:01:22.617Z
@kishor-kumar-sarker Looks like you didn't escape the parentheses
gringer
CC BY-SA 4.0
2021-12-23T21:22:08.100Z
2021-12-23T21:22:08.100Z
gringer
<p>I have a gene tree file of 436 orthologue genes from 6 species. I want to remove unwanted extensions as it looks massy after visualization. My file looks like:</p>
<p>(TRINITY_Clupea_DN5452_c0_g1_i1.p1:0.0824467436,TRINITY_Engraulis_DN43599_c0_g1_i1.p1:0.1634781085)100:0.0876433106,TRINITY_Sardina_DN15766_c0_g1_i2.p1:0.0164132018)..................</p>
<p>What i need:</p>
<p>(Clupea_DN5452:0.0824467436,Engraulis_DN43599:0.1634781085)100:0.0876433106,Sardina_DN15766:0.0164132018)..................</p>
<p>As &quot;TRINITY&quot; is identicial, i can remove it using sed. But after the species name ids are not identical. And i only need the 2nd and 3rd part of the identifier.</p>
<p>It will be helpful for me if i get some suggestion. Thanks.</p>

<phylogenetics><identifiers><trinity>
Remove variable sequence component within a tree text file
# Remove variable sequence component within a tree text file

(Asked by: username_0 on 2021-12-22)

I have a gene tree file of 436 orthologue genes from 6 species. I want to remove unwanted extensions as it looks massy after visualization. My file looks like:

(TRINITY\_Clupea\_DN5452\_c0\_g1\_i1.p1:0.0824467436,TRINITY\_Engraulis\_DN43599\_c0\_g1\_i1.p1:0.1634781085)100:0.0876433106,TRINITY\_Sardina\_DN15766\_c0\_g1\_i2.p1:0.0164132018)..................

What i need:

(Clupea\_DN5452:0.0824467436,Engraulis\_DN43599:0.1634781085)100:0.0876433106,Sardina\_DN15766:0.0164132018)..................

As "TRINITY" is identicial, i can remove it using sed. But after the species name ids are not identical. And i only need the 2nd and 3rd part of the identifier.

It will be helpful for me if i get some suggestion. Thanks.

**Tags:** phylogenetics, identifiers, trinity

---

## 2 answers

### Answer by username_1 on 2021-12-22. Score: 1

Lots of ways to do this, but here's one way using sed:
sed 's/TRINITY_\([^_]\+\)_\([^_]\+\)_[^:]\+/\1_\2/g' file.tree

The above applies a substitution to capture the first two fields using parentheses (which need to be escaped). Each field captures any character not an underscore one or more times (using the "+" symbol, which also needs to be escaped). Finally, we also match any character not a colon one or more times. The replacement string can be just the first two capture groups separated with an underscore.

> **Comments:**
> **username_0**: Hi Steve, Thanks for your warm response. But my file is a ".tree" file, not a fasta file since the file dosent start with a ">" symbol. Like as following the file looks:  (TRINITY_Clupea_DN5452_c0_g1_i1.p1:0.0824467436,TRINITY_Engraulis_DN43599_c0_g1_i1.p1:0.1634781085)100:0.0876433106,TRINITY_Sardina_DN15766_c0_g1_i2.p1:0.0164132018)..................  And i want like:  (Clupea_DN5452:0.0824467436,Engraulis_DN43599:0.1634781085)100:0.0876433106,Sardina_DN15766:0.0164132018)..................  Want to keep only the 2nd and 3rd part from the id.   Thanks.  

---

### Answer by username_2 on 2021-12-23. Score: 0

If you want to remove component/gene/isoform parts from a Trinity ID, you can do s/_c[0-9]+_.*?:/:/ to remove anything between the first c with only numbers after it up to the next colon. Combining this with the TRINITY removal at the start, it'd be something like this:
sed 's/TRINITY_\(.*?\)_c[0-9]+_.*?:/\1:/g' file.tree

> **Comments:**
> **username_0**: I have tried like as follows: sed 's/TRINITY_\(.*?\)_c[0-9]+_.*?:/\1:/g' OG0000004.tre   But is priniting like as: (TRINITY_Engraulis_DN849_c0_g1_i1.p1:0.05941030350315353731,(((((TRINITY_Tenualosa_DN4978_c0_g1_i1.p1:0.07382876155314552213,TRINITY_Alosa_DN5385_c0_g1_i1.p1:0.01287649339098437609):0.00905926786283233615,TRINITY_Sardina_DN264_c0_g1_i7.p1:0.02335748047027334101):0.04151957750042657019,((TRINITY_Colia_DN12738_c0_g1_i1.p1:0.04097580399145889923,(TRINITY_Engraulis_DN8273_c0_g2_i3.p1:0.04815781217046399831,(((((TRINITY_Engraulis_DN16258_c3_g1_i1.p1:0.08818477156986732901,....  
> **username_2**: @kishor-kumar-sarker Looks like you didn't escape the parentheses  

---

