2022-01-13 23:27:39 +01:00
|
|
|
package obitax
|
|
|
|
|
2022-02-01 23:25:19 +01:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
|
|
|
|
)
|
|
|
|
|
2022-01-13 23:27:39 +01:00
|
|
|
func (taxon *TaxNode) IsSubCladeOf(parent *TaxNode) bool {
|
|
|
|
|
|
|
|
for taxon.taxid != parent.taxid && taxon.parent != taxon.taxid {
|
|
|
|
taxon = taxon.pparent
|
|
|
|
}
|
|
|
|
|
|
|
|
return taxon.taxid == parent.taxid
|
|
|
|
}
|
|
|
|
|
|
|
|
func (taxon *TaxNode) IsBelongingSubclades(clades *TaxonSet) bool {
|
|
|
|
_, ok := (*clades)[taxon.taxid]
|
|
|
|
|
|
|
|
for !ok && taxon.parent != taxon.taxid {
|
|
|
|
taxon = taxon.pparent
|
|
|
|
_, ok = (*clades)[taxon.taxid]
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok
|
|
|
|
}
|
2022-02-01 23:25:19 +01:00
|
|
|
|
|
|
|
func IsSubCladeOf(taxonomy Taxonomy, taxid int) obiseq.SequencePredicate {
|
|
|
|
parent, err := taxonomy.Taxon(taxid)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Cannot find taxon : %d (%v)", taxid, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
f := func(sequence obiseq.BioSequence) bool {
|
|
|
|
taxon, err := taxonomy.Taxon(sequence.Taxid())
|
|
|
|
return err == nil && taxon.IsSubCladeOf(parent)
|
|
|
|
}
|
|
|
|
|
|
|
|
return f
|
|
|
|
}
|