Dear All,
Hope everyone is doing well.
I am doing a Discrete phylogeographic analysis of influenza H3N2
I have created a Nextstrain workflow for the real-time tracking of influenza H3N2 following instructions and successfully created a JSON tree file and I can drag and drop it into Auspice for visualization. Usually, I download the Nexus tree file from the Auspic.us website available at the bottom of the page and open the Nexus tree file in Figtree, and view a time-calibrated tree in Figtree similar to Auspice.us
as my plan is to fix this time-calibrated tree as a starting tree for beast analysis. But in the beast, the Nexus format is getting an error about the inappropriate format
My question is
What is the best way to convert the. JSON tree file into .Nexus ?
I tried the R tool by following the JSON lite package I could not convert the JSON format to Nexus.
Any suggestion will be really appreciated.
I am looking forward to your opinion
Thank you
Hi! You may be interested in the treeio package in R (Bioconductor - treeio), which is available from Bioconductor and works within the ggtree framework.
Treeio has a function (treeio::read.nextstrain.json) which can parse nextstrain output. I have not used it personally so I cannot attest to how well it works. You can then convert to nexus and write it out. Treeio has functions to output trees in beast’s native nexus format.
If this doesn’t work I think there might be two other options:
First, nextstrain produces a newick formatted tree file from the augur refine command. This newick formatted file can be converted to nexus using treeio or another tool such as phyx ((GitHub - FePhyFoFum/phyx: phylogenetics tools for linux (and other mostly posix compliant) computers)).
Second, you can run treetime directly on your data set. Nextstrain augur’s refine command is a wrapper around treetime- which outputs its tree directly in nexus format.
Hope this helps!
Dear methhew,
I am grateful for your meaningful input.
Update related to suggestion
-
I understand treeio has read.nextstrain.json function but it is not working for me.
I may need to update my treeio package -
However I used newick tree generated after augur refine command in nextstrain workflow. and converted into nexus using treeio and it worked for me. did not try phyx for now
-
For tree time ( I used the maximum likelihood tree generated by IQTree and use tree-time to date the ML tree . It gave me nexus format tree.
But Beast V.1.10.4 is giving me error that tree is not fully bifurcated but the same tree file is working well for Beast V.2.7.4. I am trying to solve this issue
Thank you very much for your time and Help .
Best regards
Sikandar
Thanks @matthew.wersebe for your input here! I didn’t know about treeio having a nextstrain.json read function. Here’s a link to the treeio docs for those interested: read.nextstrain.json — read.nextstrain.json • treeio (I’m not an R user myself). And here is the source file: treeio/R/nextstrain.json.R at acf29745bd1f98f78ca8e8ab23758c95f65e8086 · YuLab-SMU/treeio · GitHub
@Sikandar_Azam, what’s the error you get from treeio when reading the nextstrain json using the read function? It’s possible that the auspice json schema has changed and treeio has not yet updated to be able to deal with it.
I think you can tell treetime to make a fully bifurcated tree using --keep-polytomies false
: Detailed command line documentation — TreeTime 0.11.1 documentation
The documentation isn’t 100% clear on this but I’d assume not keeping polytomies means fully resolving them. It could be that Beast2 doesn’t mind a non-fully bifurcated tree but Beast1 does.
You could try to check whether the tree really is not fully bifurcating. This could also be a bug in Beast1 or somewhere in the export process.
If you shared the tree files here then others could try to see what’s going on, it’s always helpful to have the exact files that cause errors/issues.
Best, Cornelius
@corneliusroemer I am using Treeio Version 1.20.2. in R Version 4.2.1. The Treeio package did not recognize the next strain function. I might need to update the Treeio Package.
You are right that my tree was not fully bifurcating that’s why I was getting the error
However, I use tree time to solve the problem of importing the nexus tree into Beast v.10.4. and created a bifurcated tree by resolving the polytomies and it worked well.
–keep–polytomies false
and another option that I tried was using the ape package in R and creating a bifurcating tree.
so both tree time and ape package worked well in my Case
Thank you for your feedback
Great to hear you found a way @Sikandar_Azam!
Treeio seems to have introduced the Nextstrain Json read function in v1.21.1, so yes it’s not present in your version.