This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to edit name/ID in a newick tree format

Hi there,

I am trying to edit a newick tree. This is my tree

(Solanumtuberosum_stu4396:0.10246,(Solanumtuberosum_stu4462:0.0388307,(Solanumtuberosum_stu4373:0.134577,Solanumtuberosum_stu4418:0.0203854)n2:0.0314355)n1:0. 10246)n0;

And, I would like to remove the first part of the Ids "Solanumtuberosum" and just leave the "stu4396" ID. For instance, I would like to have this:

(stu4396:0.10246,(stu4462:0.0388307,(stu4373:0.134577,stu4418:0.0203854)n2:0.0314355)n1:0. 10246)n0;

Thank you very much.

Best

Ivan

newick format

3 answers

$ echo '(Solanumtuberosum_stu4373:0.134577,Solanumtuberosum_stu4418:0.0203854)n2:0.0314355)n1:0. 10246)n0;' |\
sed 's/\([(,]\)[A-Za-z]*_/\1/g'

(stu4373:0.134577,stu4418:0.0203854)n2:0.0314355)n1:0. 10246)n0;

Thank you very much, this worked well!

Sorry, I another tree, I already have realized that some IDS did not change. In particular "DaturastramoniumTeo1_date29029" and "DaturastramoniumTic23_dati18250" Do you know why?

(pin9322:0.0604111,((nta31317:0.0366408,nta31450:0.0580446)n2:0.0713836,((stu15449:0.0100372,(sly17389:5e-09,spim16755:5e-09)n6:0.020268)n4:0.0302766,(cam27073:0.0527933,(DaturastramoniumTeo1_date29029:0.0559328,DaturastramoniumTic23_dati18250:5e-09)n7:0.0279078)n5:0.0175644)n3:0.0283923)n1:0.0604111)n0;

Best

Log in to answer this question.