mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Code reefactoring
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package obitax
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
@ -42,15 +41,11 @@ func (taxonomy *Taxonomy) Length() int {
|
||||
return len(*taxonomy.nodes)
|
||||
}
|
||||
|
||||
func (taxonomy *Taxonomy) Iterator() *ITaxonSet {
|
||||
return taxonomy.nodes.Iterator()
|
||||
}
|
||||
|
||||
func (taxonomy *Taxonomy) AddNewTaxa(taxid, parent int, rank string, replace bool, init bool) (*TaxNode, error) {
|
||||
if !replace {
|
||||
_, ok := (*taxonomy.nodes)[taxid]
|
||||
if ok {
|
||||
return nil, errors.New(fmt.Sprintf("Trying to add taxoon %d already present in the taxonomy", taxid))
|
||||
return nil, fmt.Errorf("trying to add taxoon %d already present in the taxonomy", taxid)
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +61,7 @@ func (taxonomy *Taxonomy) Taxon(taxid int) (*TaxNode, error) {
|
||||
if !ok {
|
||||
a, aok := taxonomy.alias[taxid]
|
||||
if !aok {
|
||||
return nil, errors.New(fmt.Sprintf("Taxid %d is not part of the taxonomy", taxid))
|
||||
return nil, fmt.Errorf("Taxid %d is not part of the taxonomy", taxid)
|
||||
}
|
||||
log.Printf("Taxid %d is deprecated and must be replaced by %d", taxid, a.taxid)
|
||||
t = a
|
||||
@ -109,9 +104,9 @@ func (taxonomy *Taxonomy) ReindexParent() error {
|
||||
for _, taxon := range *taxonomy.nodes {
|
||||
taxon.pparent, ok = (*taxonomy.nodes)[taxon.parent]
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("Parent %d of taxon %d is not defined in taxonomy",
|
||||
return fmt.Errorf("Parent %d of taxon %d is not defined in taxonomy",
|
||||
taxon.taxid,
|
||||
taxon.parent))
|
||||
taxon.parent)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user