Add managment of the taxonomy alias politic

This commit is contained in:
Eric Coissac
2025-02-10 14:05:47 +01:00
parent e2563cd8df
commit 6a8061cc4f
16 changed files with 114 additions and 48 deletions

View File

@ -4,6 +4,7 @@ import (
"math"
"strings"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax"
log "github.com/sirupsen/logrus"
)
@ -15,7 +16,7 @@ func (sequence *BioSequence) TaxonomicDistribution(taxonomy *obitax.Taxonomy) ma
taxonomy = taxonomy.OrDefault(true)
for taxid, v := range taxids {
t, err := taxonomy.Taxon(taxid)
t, isAlias, err := taxonomy.Taxon(taxid)
if err != nil {
log.Fatalf(
"On sequence %s taxid %s is not defined in taxonomy: %s (%v)",
@ -25,6 +26,11 @@ func (sequence *BioSequence) TaxonomicDistribution(taxonomy *obitax.Taxonomy) ma
err,
)
}
if isAlias && obidefault.FailOnTaxonomy() {
log.Fatalf("On sequence %s taxid %s is an alias on %s",
sequence.Id(), taxid, t.String())
}
taxons[t.Node] = v
}
return taxons

View File

@ -5,6 +5,7 @@ import (
log "github.com/sirupsen/logrus"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils"
)
@ -16,7 +17,7 @@ func (s *BioSequence) Taxon(taxonomy *obitax.Taxonomy) *obitax.Taxon {
return nil
}
taxon, _ := taxonomy.Taxon(taxid)
taxon, _, _ := taxonomy.Taxon(taxid)
return taxon
}
@ -28,6 +29,8 @@ func (s *BioSequence) Taxon(taxonomy *obitax.Taxonomy) *obitax.Taxon {
// taxid - the taxid to set.
func (s *BioSequence) SetTaxid(taxid string, rank ...string) {
var err error
var isAlias bool
if taxid == "" {
taxid = "NA"
} else {
@ -35,16 +38,39 @@ func (s *BioSequence) SetTaxid(taxid string, rank ...string) {
taxon := (*obitax.Taxon)(nil)
if taxonomy != nil {
taxon, err = taxonomy.Taxon(taxid)
taxon, isAlias, err = taxonomy.Taxon(taxid)
if err != nil {
log.Warnf("%s: Taxid: %v is unknown from taxonomy (%v)",
s.Id(), taxid, err)
if obidefault.FailOnTaxonomy() {
log.Fatalf("%s: Taxid: %v is unknown from taxonomy (%v)",
s.Id(), taxid, err)
} else {
log.Warnf("%s: Taxid: %v is unknown from taxonomy (%v)",
s.Id(), taxid, err)
}
}
if isAlias {
if obidefault.FailOnTaxonomy() {
log.Fatalf("%s: Taxid: %v is an alias from taxonomy (%v) to %s",
s.Id(), taxid, taxonomy.Name(), taxon.String())
} else {
if obidefault.UpdateTaxid() {
log.Warnf("%s: Taxid: %v is updated to %s",
s.Id(), taxid, taxon.String())
taxid = taxon.String()
} else {
log.Warnf("%s: Taxid %v has to be updated to %s",
s.Id(), taxid, taxon.String())
}
}
} else {
if taxon != nil {
taxid = taxon.String()
}
}
}
if taxon != nil {
taxid = taxon.String()
}
}

View File

@ -63,7 +63,7 @@ func IsSubCladeOfSlot(taxonomy *obitax.Taxonomy, key string) SequencePredicate {
val, ok := sequence.GetStringAttribute(key)
if ok {
parent, err := taxonomy.Taxon(val)
parent, _, err := taxonomy.Taxon(val)
if err != nil {
log.Warnf("%s: %s is unkown from the taxonomy (%v)", sequence.Id(), val, err)