DOWLOAD-DESKTOP-NOTEBOOK.nb (862 KB)
– you have earned Featured Contributor Badge ![]()
Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!
The sharks taxonomy can be visualized as a tree, starting with a single species i.e. the great white shark as so:
ResourceFunction["TaxonomyTree"][
Entity["TaxonomicSpecies", "CarcharodonCarcharias::k6mys"],
"Depth" -> 7]
Cool. But I got an error, see image. Also starting entity looks like "“great white shark” not some general shark. I might be confused. Cool post.
Dear Kapio, you’re not confused; the error is odd as you copied the same expression as I did. You should be able to get all the way up to the "cartilaginous fishes, before we enter into “sibling taxa territory” at larger “Depth” values:
ResourceFunction["TaxonomyTree"][
Entity["TaxonomicSpecies", "CarcharodonCarcharias::k6mys"],
"Depth" -> 9]
Thanks for letting me know; I will look into this. Maybe the entity framework was unable to to retrieve some data during your evaluation.
This is a nice function. I haven’t looked too closely at the code, but I saw that you construct a Graph object and then convert it to a Tree object using GraphTree. Is there a complication with constructing it directly using NestTree, like you do in this post?
@Ian, do you have some idea why did I get that error? – See my comment above.
Thanks Ian.
Feel free to give me any feedback on the code. I am still learning about the Tree syntax and the new TaxonomicSpecies entities. I used Graphs as they are so easy to create with rules and rules are also easy to manipulate. The nested structure in trees adds a layer of complexity. On the other hand, once I have a tree, they are very comfortable to analyze.
My use case for the ResourceFunction is:
- Use one known species and retrieve its taxonomy, visualized as a tree. If the Entity is a species-taxon: Ability to move up the taxa by a set number of levels. If the Entity is at a higher taxon: Ability to move down the taxa, where the entity’s taxon is the root.
- Compare the taxonomy of two or more different species by exploiting the TaxonomicSequence.
For use case 2 I assumed every TaxonomicSequence is complete and consistent. It’s not always the case. I was unable to create a RulesTree from the start as it turned out: is wasn’t a tree. The issue can be shown in my “berrries” example. A graph showed me why: some vertices had an InDegree > 1, and this is simple to identify and correct in a graph.
In use case 1, the same issue may exist, and I did not have a proper solution for NestTree when I created the function. For example NestGraph Entity[“TaxonomicSpecies”, “Lonicera::3gqqp”] resulted in a graph that was not a tree. However, I believe NestTree may offer a solution after all as this works just fine
children[ent : Entity["TaxonomicSpecies", _]] :=
Replace[ent[
EntityProperty["TaxonomicSpecies",
"ChildTaxa"]], _Missing -> {}];
children[_] = {};
NestTree[children, Entity["TaxonomicSpecies", "Lonicera::3gqqp"], 2,
TreeLayout -> Left, TreeElementLabelFunction -> All -> CommonName,
MaxDisplayedChildren -> Infinity]
I will rewrite some of the code of TaxonomyTree in future also with new insights I have on the taxonomic structure in the entity framework.
Thanks Ian, for the suggestion.
I don’t know, I get the same error you do.
Thanks for the explanation. If NestGraph gives a non-tree for a given function and initial value, NestTree would still give a tree but would have duplicate branches, so I see why it makes sense to first build a graph.
Well, this is embarrassing. The resource function works fine on my desktop installation where I removed any possible local resource object when testing on random entities and tree depths. However, I get the same error when I try it on Mathematica Online or the Citrix app of Mathematica. I will contact the WRT to put the function back into review status until this has been sorted.
A new version of the ResourceFunction will become available soon. This version as been rewritten and no longer uses the child-taxa property iteratively. This version of TaxonomyTree relies on the TaxonomicSequence and the SpeciesList properties. These properties give results reliably across different installations e.g. cloud, Citrix on a PC.
Version 1.0.0 employed the child-taxa entity property iteratively as a way to traverse the taxonomy tree. Unfortunately, the child-taxa property may not yield any results on some platforms, causing the ResourceFunction to fail.
Comparison of child-taxa resolution performance
My PC, Windows:
Mathematica Online:
Mathematica 13.3. Windows running in a Citrix session:
Of course I tested version 1.0.0 on my PC without any issues, but for other platforms it will not work. I don’t think this is how the TaxonomicSpecies entities are supposed to work, so I may report this to Wolfram Support.
In the meantime (before the update), this expression should show you the sharks phyletic group in a taxonomy tree:
ResourceFunction["TaxonomyTree"][
EntityClass[
"TaxonomicSpecies", {EntityProperty["TaxonomicSpecies",
"PhyleticGroups"] -> Entity["SpeciesPhyleticGroup", "Shark"]}][
"Entities"]]
@kapio An update of the ResourceFunction has been released. Please run ResourceUpdate[“TaxonomyTree”].







