mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
First commit
This commit is contained in:
36
pkg/obitax/path.go
Normal file
36
pkg/obitax/path.go
Normal file
@ -0,0 +1,36 @@
|
||||
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()
|
||||
}
|
Reference in New Issue
Block a user