Adds possibility to extract a taxonomy from taxonomic path included in sequence files

This commit is contained in:
Eric Coissac
2025-01-30 11:18:21 +01:00
parent 2452aef7a9
commit 0df082da06
20 changed files with 460 additions and 173 deletions

View File

@@ -1,6 +1,7 @@
package obitax
import (
"errors"
"iter"
"regexp"
@@ -379,3 +380,29 @@ func (taxon *Taxon) SameAs(other *Taxon) bool {
return taxon.Taxonomy == other.Taxonomy && taxon.Node.id == other.Node.id
}
func (taxon *Taxon) AddChild(child string, replace bool) (*Taxon, error) {
if taxon == nil {
return nil, errors.New("nil taxon")
}
code, taxid, scientific_name, rank, err := ParseTaxonString(child)
if err != nil {
return nil, err
}
if taxon.Taxonomy.code != code {
return nil, errors.New("taxonomy code mismatch")
}
newTaxon, err := taxon.Taxonomy.AddTaxon(taxid, *taxon.Node.id, rank, false, replace)
if err != nil {
return nil, err
}
newTaxon.SetName(scientific_name, "scientific name")
return newTaxon, nil
}