Open zachary-foster opened 6 years ago
good idea.
is there a way to do this now? and are you talking about the object taxonomy
or just to any objects in the pkg?
is there a way to do this now?
For taxmap
and taxonomy
objects, not easily (we dont have a function to do it). You would need to modify the edge list and add a taxon to the taxa
list.
and are you talking about the object taxonomy or just to any objects in the pkg?
I was just thinking about taxonomy
objects, but it would make sense to have to same functionality for hierarchy
, and hierarchies
objects. For taxa
objects, you can just append/split them like any other list. I am not sure what would be the best way to do this with hierarchy
and hierarchies
objects. Those would be much easier to modify "by hand" than taxonomy
objects.
So right now, someone would need to e.g., recreate the entire taxonomy
object with new taxa if they had new taxa to add?
That would perhaps be the least error-prone way to do it for taxonomy
objects: output the classifications()
, add taxon in same format, and reread with parse_tax_data
, but some info would be lost (e.g. ranks). For taxmap
, it would be harder to preserve the datasets.
One could modify an object in place as well, but it could be tricky:
> library(taxa)
> ex_taxonomy
<Taxonomy>
9 taxa: b. Mammalia, c. Notoryctidae, d. Felidae ... h. Notoryctes typhlops, i. Puma concolor, j. Panthera tigris
9 edges: NA->b, b->c, b->d, c->e, d->f, d->g, e->h, f->i, g->j
> print_tree(ex_taxonomy)
Mammalia
├─Notoryctidae
│ └─Notoryctes
│ └─Notoryctes typhlops
└─Felidae
├─Puma
│ └─Puma concolor
└─Panthera
└─Panthera tigris
> ex_taxonomy$taxa <- c(ex_taxonomy$taxa, new_id = taxon("new_taxon"))
> ex_taxonomy$edge_list <- rbind(ex_taxonomy$edge_list, c("b", "new_id"))
> ex_taxonomy
<Taxonomy>
10 taxa: b. Mammalia, c. Notoryctidae, d. Felidae ... i. Puma concolor, j. Panthera tigris, new_id. new_taxon
10 edges: NA->b, b->c, b->d, c->e, d->f, d->g, e->h, f->i, g->j, b->new_id
> print_tree(ex_taxonomy)
Mammalia
├─Notoryctidae
│ └─Notoryctes
│ └─Notoryctes typhlops
├─Felidae
│ ├─Puma
│ │ └─Puma concolor
│ └─Panthera
│ └─Panthera tigris
└─new_taxon
Definitely seems like a pain point that we should sort out
Also, could add a function called add_subtree
that adds one taxonomy/taxmap as subtaxa of a taxon in another taxonomy/taxmap.
add_taxon(obj, new_taxon, supertaxon = NULL, subtaxa = NULL)
Adds
new_taxon
toobj
taxonomy.supertaxon
andsubtaxa
would accept existing taxon IDs.supertaxon = NULL
andsubtaxa
is used: New taxon is added between the subtaxa and the existing supertaxon that contains all of the subtaxasupertaxon
is used andsubtaxa = NULL
New taxon is added within the existing supertaxon. Existing subtaxa of the existing supertaxon are not affected.supertaxon
is used andsubtaxa
is used: Connects existing supertaxa with existing subtaxa, with the new taxon in between.supertaxon = NULL
and andsubtaxa = NULL
: Added as a root with no subtaxa and prints a warning/message.Alternatively, there could be three separate functions corresponding to the top three points above:
add_supertaxon
add_subtaxa
/add_subtaxon
insert_taxon
Thoughs @sckott? It seems like there could be a few ways to do implement a function to add taxa and I am not sure what would be best.