mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
37 lines
637 B
Go
37 lines
637 B
Go
|
package obitax
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
func (taxon *TaxNode) Path() (*TaxonSlice, error) {
|
||
|
|
||
|
path := make(TaxonSlice, 0, 30)
|
||
|
path = append(path, taxon)
|
||
|
|
||
|
for taxon != taxon.pparent {
|
||
|
taxon = taxon.pparent
|
||
|
|
||
|
if taxon == nil {
|
||
|
return nil, errors.New(fmt.Sprint("Taxonomy must be reindexed"))
|
||
|
}
|
||
|
|
||
|
path = append(path, taxon)
|
||
|
}
|
||
|
|
||
|
return &path, nil
|
||
|
}
|
||
|
|
||
|
// Returns a TaxonSet listing the requested taxon and all
|
||
|
// its ancestors in the taxonomy down to the root.
|
||
|
func (taxonomy *Taxonomy) Path(taxid int) (*TaxonSlice, error) {
|
||
|
taxon, err := taxonomy.Taxon(taxid)
|
||
|
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return taxon.Path()
|
||
|
}
|