Draw and color subtree using NEXUS ancestral data

I need to redraw some subtrees from the auspice tree for a publication. I want to edit them, removing the circles and increasing the height.
I exported these subtrees as nexus files, which contains the ancestral/transmission data, as you know.

How could I redraw these subtrees using a script? I would like to color the branches based on the ancestral/transmission data automatically. Can I do it using auspice? Do you know a script of R or Python for this purpose?

I look forward to a response.
Thanks.

Hi @fhsantanna! This is a complex topic since all approaches seem to lead inevitably to a matplotlib-based solution (if you’re working in Python). You may be interested in baltic, a tree plotting library with an extensive collection of code examples and a separate example gallery.

1 Like

Wonderful! That is what I need!

@jlhudd , I am trying to use baltic with a nexus file downloaded from auspice.
Here is the nexus file:

#nexus
begin trees;
tree one = (Argentina/C97133/2020[&clade_membership=20B,num_date=2020.886612021858,num_date_CI={2020.886612021858,2020.886612021858},pangolin_lineage=P.2,localidade=South America,division=Argentina,country=Argentina,region=South America,host=Human,age=49,sex=Male,recency=Older,division_exposure=Argentina,region_exposure=South America,subclade_membership=20B/S.484K,div=23]:0.022244654877567882,(Brazil/AM-21143316HC/2021[&clade_membership=20B,num_date=2021.009589041096,num_date_CI={2021.009589041096,2021.009589041096},pangolin_lineage=P.2,localidade=Brazil,location=Manaus,division=Amazonas BR,country=Brazil,region=South America,host=Human,age=35,sex=Male,recency=One week ago,division_exposure=Amazonas BR,region_exposure=South America,subclade_membership=20B/S.484K,div=23]:0.06563654070760094,Brazil/AM-L87-CD2680/2020[&clade_membership=20B,num_date=2020.9767759562842,num_date_CI={2020.9767759562842,2020.9767759562842},pangolin_lineage=B.1.1.28,localidade=Brazil,location=Manaus,division=Amazonas BR,country=Brazil,region=South America,host=Human,recency=One week ago,division_exposure=Amazonas BR,region_exposure=South America,subclade_membership=20B/S.484K,div=23]:0.03282345589582292)NODE_0004335[&clade_membership=20B,num_date=2020.9439525003884,num_date_CI={2020.7799157869863,2020.9690196954846},localidade=Brazil,subclade_membership=20B/S.484K,div=22]:0.0795851334080453)NODE_0002344[&clade_membership=20B,num_date=2020.8643673669803,num_date_CI={2020.784333364771,2020.886612021858},localidade=Brazil,subclade_membership=20B/S.484K,div=22]:0;
end;

When I try to load the file using baltic, the following error occurs:

myTree = bt.loadNexus(nexus_file)

AssertionError Traceback (most recent call last)
in
----> 1 myTree = bt.loadNexus(nexus_file)

~/miniconda3/envs/pandas/lib/python3.9/site-packages/baltic/baltic.py in loadNexus(tree_path, tip_regex, date_fmt, treestring_regex, variableDate, absoluteTime, verbose)
1286 tipFlag=False
1287
→ 1288 assert ll,‘Regular expression failed to find tree string’
1289 ll.traverse_tree() ## traverse tree
1290 ll.sortBranches() ## traverses tree, sorts branches, draws tree

AssertionError: Regular expression failed to find tree string

Do you know what might be the problem? Nwk tree load with any problem.
Thank you very much.

I was able to color a tree above using ggtree (R package) using the ancestral data.

However, when I work with a larger dataset such as this one (WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free), I cannot read the nexus file generated by auspice in Figtree.
I get the following error:

"Error reading tree file:
Number format error: For input string: 0.006486150556156645)NODE_0004110

In R, I got the following error:

nexus ← treeio::read.beast(file = “example.nexus”)
Error in FUN(X[[i]], …): numbers of left and right parentheses in Newick string not equal

Traceback:

  1. treeio::read.beast(file = “example.nexus”)
  2. read.stats_beast(file)
  3. read.stats_beast_internal(beast, trees)
  4. read.tree(text = tree)
  5. lapply(STRING, .treeBuild)
  6. FUN(X[[i]], …)

I was not able to identify the problem of the nexus file generated by auspice. Could you give me a clue?

I believe there is a bug in auspice file exportation, some parenthesis might be missing in the nexus file. I cannot read the nexus file in any phylogenetic viewer (itol, ggtree, figtree).