mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Add a first version of obitag the successor of ecotag
This commit is contained in:
25
pkg/obitax/lca.go
Normal file
25
pkg/obitax/lca.go
Normal file
@ -0,0 +1,25 @@
|
||||
package obitax
|
||||
|
||||
func (t1 *TaxNode) LCA(t2 *TaxNode) (*TaxNode, error) {
|
||||
p1, err1 := t1.Path()
|
||||
|
||||
if err1 != nil {
|
||||
return nil, err1
|
||||
}
|
||||
|
||||
p2, err2 := t2.Path()
|
||||
|
||||
if err2 != nil {
|
||||
return nil, err2
|
||||
}
|
||||
|
||||
i1 := len(*p1) - 1
|
||||
i2 := len(*p2) - 1
|
||||
|
||||
for i1 >= 0 && i2 >= 0 && (*p1)[i1].taxid == (*p2)[i2].taxid {
|
||||
i1--
|
||||
i2--
|
||||
}
|
||||
|
||||
return (*p1)[i1+1], nil
|
||||
}
|
Reference in New Issue
Block a user