This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Change nexus textlabels

Dear all,

Any suggestion how to change the tip labels of a phylogenetic tree in nexus format? in R? bash script?

r nexus tree bash

1 answer

Hi, if you want to try replacing headers, this should do the job (Python 2.7 script, takes the two list filenames as arguments):

import sys

listA = []
listB = []

for line in open(sys.argv[1]):
    listA.append(line.replace('\n',''))

for line in open(sys.argv[2]):
    listB.append(line.replace('\n',''))

for line in listA:
    id = ''
    for char in line:
        if char != '.':
            id += char
        else:
            break
    for linej in listB:
        if id in linej:
            print linej

Well, this was meant to reply to an original question, now missing -.-''

thanks! this prints me the headers but is not replacing in the original file...

Yep, indeed the script was simply meant to help you re-format your list IDs, as you originally requested. If you want to get some help then... you should help people to help you! For instance, in the original question at least you were pointing out to one example ID. That said, unfortunately I am not familiar with NEXUS files, so I am not the best person to assist you any further. On general terms, in your place I would try to figure out where those tip labels are taken from, to know what to replace in your NEXUS text file.

Log in to answer this question.