Hi, I am trying to build up a phylogenetic tree by iqtree. However, after building the tree, the nodes contain only the subject ID. So I tried to code in Python hoping that I can rename the tree nodes with spices title. I used python dictionary to try match the subject id to the dictionary then have it renamed with its species name. Unfortunately, the code returned the same subject ID not the species name. Can someone please help?
tree file output is:
(XM_625857.1_3361-3407:0.0000000000,(U65981.1_3455-3501:0.0000010000,(M01601_61_000000000-AK68L_1_21:0.0679337469,CP044419.1_717961-718007:0.9567695962):0.0000022960):0.0000023664,XM_662287.1_3361-3407:0.0000000000);
written code:
replace_strings = {'XM 662287.1:3361-3407':'Cryptosporidium hominis TU502 ATPase (Chro.40306) partial mRNA',
'XM 625857.1:3361-3407':'Cryptosporidium parvum Iowa II P-type ATpase involved in cation transport (cgd4 2720) partial mRNA'
,'U65981.1:3455-3501':'Cryptosporidium parvum P-ATPase gene (CppA-E1) gene complete cds',
'M01601:61:000000000-AK68L:1:2108:7181:8437':'M01601:61:000000000-AK68L:1:2108:7181:8437',
'CP044419.1:717961-718007':'Cryptosporidium parvum strain IOWA-ATCC chromosome 4'}
with open("/Users/sabir/Desktop/TMP017787read2_resultsFromNCBI_clustalwd.fas.treefile", "r+") as infile:
# Read each line of file
content = infile.readlines()
new_content = []
for line in content:
new_line = line
for word in replace_strings.items():
new_line = new_line.replace(str(word), str(replace_strings[word]))
new_content.append(new_line)
test = re.match(replace_strings, new_content)
with open("/Users/sabir/Desktop/testoutfile.treefile", "w") as outfile:
for line in new_content:
outfile.write(line)
Thank you Mensur, I will keep those notes in my mind.