Files
obitools4/pkg/obitax/path.go

37 lines
637 B
Go
Raw Normal View History

2022-01-13 23:27:39 +01:00
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()
}