Change obiclean algorithm for a better evaluation of ratio

This commit is contained in:
2022-08-31 20:38:03 +02:00
parent 90ba980de6
commit 6b8f4490cf
8 changed files with 371 additions and 75 deletions

View File

@ -2,6 +2,8 @@ package obitax
import (
"fmt"
log "github.com/sirupsen/logrus"
)
func (taxon *TaxNode) Path() (*TaxonSlice, error) {
@ -22,6 +24,34 @@ func (taxon *TaxNode) Path() (*TaxonSlice, error) {
return &path, nil
}
func (taxon *TaxNode) TaxonAtRank(rank string) *TaxNode {
for taxon.rank != rank && taxon != taxon.pparent {
taxon = taxon.pparent
if taxon == nil {
log.Panicln("Taxonomy must be reindexed")
}
}
if taxon == taxon.pparent {
taxon = nil
}
return taxon
}
func (taxon *TaxNode) Species() *TaxNode {
return taxon.TaxonAtRank("species")
}
func (taxon *TaxNode) Genus() *TaxNode {
return taxon.TaxonAtRank("genus")
}
func (taxon *TaxNode) Family() *TaxNode {
return taxon.TaxonAtRank("family")
}
// 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) {