Label branch with spike mutations

Hi everyone, I was wondering if there is a way to label branches with spike mutations only? I see there’s the aa option, but short of manually editing the JSON I can’t work out how to get an option for spike only.

Thanks! (And thanks for such a great tool!)

Hi, the .json is quite easy to modify, in python

import json 
f = open("mytree.json","r",encoding="utf-8")
tree = json.load(f)
def rec(n):
   if "children" in n:
      for c in n["children"]:
          rec(c)
   # remove the non-spike mutations from n["branch_attrs"]["label"]["aa"]

rec(tree[“tree”])

1 Like

This is exactly what I needed, thanks for your help!

In case you want a working script

import json
f = open("mybuild.json","r",encoding="utf-8")
o = json.load(f)
f.close()

def rec(n):
	if "children" in n:
		for c in n["children"]:
			rec(c)
	if ("branch_attrs" in n) and ("labels" in n["branch_attrs"]) and ("aa" in n["branch_attrs"]["labels"]) and ("S: " in n["branch_attrs"]["labels"]["aa"]):
		n["branch_attrs"]["labels"].update({"aa_spike":n["branch_attrs"]["labels"]["aa"].split("S: ")[1].split(";")[0]})
		
rec(o["tree"])
f = open("mybuild_with_aa_spike.json","w",encoding="utf-8")
json.dump(o,f)
f.close()
1 Like

This is great, thank you! Much cleaner than what I wrote. Really appreciate the help!