Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function(s) to add taxa to a taxonomy #172

Open
zachary-foster opened this issue May 16, 2018 · 6 comments
Open

New function(s) to add taxa to a taxonomy #172

zachary-foster opened this issue May 16, 2018 · 6 comments

Comments

@zachary-foster
Copy link
Collaborator

add_taxon(obj, new_taxon, supertaxon = NULL, subtaxa = NULL)

Adds new_taxon to obj taxonomy. supertaxon and subtaxa would accept existing taxon IDs.

  • supertaxon = NULL and subtaxa is used: New taxon is added between the subtaxa and the existing supertaxon that contains all of the subtaxa
  • supertaxon is used and subtaxa = NULL New taxon is added within the existing supertaxon. Existing subtaxa of the existing supertaxon are not affected.
  • supertaxon is used and subtaxa is used: Connects existing supertaxa with existing subtaxa, with the new taxon in between.
  • supertaxon = NULL and and subtaxa = 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.

@sckott
Copy link
Contributor

sckott commented May 16, 2018

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?

@zachary-foster
Copy link
Collaborator Author

zachary-foster commented May 16, 2018

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.

@sckott
Copy link
Contributor

sckott commented May 18, 2018

So right now, someone would need to e.g., recreate the entire taxonomy object with new taxa if they had new taxa to add?

@zachary-foster
Copy link
Collaborator Author

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

@sckott
Copy link
Contributor

sckott commented May 18, 2018

Definitely seems like a pain point that we should sort out

@zachary-foster
Copy link
Collaborator Author

Also, could add a function called add_subtree that adds one taxonomy/taxmap as subtaxa of a taxon in another taxonomy/taxmap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants