mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Add managment of the taxonomy alias politic
This commit is contained in:
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user