# Remove variable sequence component within a tree text file

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.

Lots of ways to do this, but here's one way using :

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.

• 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. Dec 22, 2021 at 3:47

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

• 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,.... Jan 3 at 12:23
• @kishor-kumar-sarker Looks like you didn't escape the parentheses
– gringer
Jan 4 at 9:01