mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00

modified: cmd/obitools/obitag/main.go modified: cmd/obitools/obitag2/main.go modified: go.mod modified: go.sum modified: pkg/obiformats/ncbitaxdump/read.go modified: pkg/obioptions/version.go modified: pkg/obiseq/attributes.go modified: pkg/obiseq/taxonomy_lca.go modified: pkg/obiseq/taxonomy_methods.go modified: pkg/obiseq/taxonomy_predicate.go modified: pkg/obitax/inner.go modified: pkg/obitax/lca.go new file: pkg/obitax/taxid.go modified: pkg/obitax/taxon.go modified: pkg/obitax/taxonomy.go modified: pkg/obitax/taxonslice.go modified: pkg/obitools/obicleandb/obicleandb.go modified: pkg/obitools/obigrep/options.go modified: pkg/obitools/obilandmark/obilandmark.go modified: pkg/obitools/obilandmark/options.go modified: pkg/obitools/obirefidx/famlilyindexing.go modified: pkg/obitools/obirefidx/geomindexing.go modified: pkg/obitools/obirefidx/obirefidx.go modified: pkg/obitools/obirefidx/options.go modified: pkg/obitools/obitag/obigeomtag.go modified: pkg/obitools/obitag/obitag.go modified: pkg/obitools/obitag/options.go modified: pkg/obiutils/strings.go
92 lines
2.2 KiB
Go
92 lines
2.2 KiB
Go
package obiseq
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax"
|
|
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils"
|
|
)
|
|
|
|
func IsAValidTaxon(taxonomy *obitax.Taxonomy, withAutoCorrection ...bool) SequencePredicate {
|
|
// deprecatedTaxidsWarning := make(map[string]bool)
|
|
|
|
autocorrection := false
|
|
if len(withAutoCorrection) > 0 {
|
|
autocorrection = withAutoCorrection[0]
|
|
}
|
|
|
|
f := func(sequence *BioSequence) bool {
|
|
taxon := sequence.Taxon(taxonomy)
|
|
|
|
if taxon != nil {
|
|
taxid := sequence.Taxid()
|
|
ttaxid := taxon.String()
|
|
if taxid != ttaxid {
|
|
if autocorrection {
|
|
sequence.SetTaxid(ttaxid)
|
|
log.Printf(
|
|
"Sequence %s : Taxid %d updated with %d",
|
|
sequence.Id(),
|
|
taxid,
|
|
ttaxid,
|
|
)
|
|
} // else {
|
|
// if _, ok := deprecatedTaxidsWarning[taxid]; !ok {
|
|
// deprecatedTaxidsWarning[taxid] = true
|
|
// log.Printf("Taxid %d is deprecated and must be replaced by %d", taxid, taxon.taxid)
|
|
// }
|
|
// }
|
|
}
|
|
}
|
|
|
|
return taxon != nil
|
|
}
|
|
|
|
return f
|
|
}
|
|
|
|
// A function that takes a taxonomy and a taxid as arguments and returns a function that takes a
|
|
// pointer to a BioSequence as an argument and returns a boolean.
|
|
func IsSubCladeOf(taxonomy *obitax.Taxonomy, parent *obitax.Taxon) SequencePredicate {
|
|
|
|
f := func(sequence *BioSequence) bool {
|
|
taxon := sequence.Taxon(taxonomy)
|
|
return taxon != nil && taxon.IsSubCladeOf(parent)
|
|
}
|
|
|
|
return f
|
|
}
|
|
|
|
func IsSubCladeOfSlot(taxonomy *obitax.Taxonomy, key string) SequencePredicate {
|
|
|
|
f := func(sequence *BioSequence) bool {
|
|
val, ok := sequence.GetStringAttribute(key)
|
|
|
|
if ok {
|
|
parent := taxonomy.Taxon(val)
|
|
taxon := sequence.Taxon(taxonomy)
|
|
return parent != nil && taxon != nil && taxon.IsSubCladeOf(parent)
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
return f
|
|
}
|
|
|
|
func HasRequiredRank(taxonomy *obitax.Taxonomy, rank string) SequencePredicate {
|
|
|
|
if !obiutils.Contains(taxonomy.RankList(), rank) {
|
|
log.Fatalf("%s is not a valid rank (allowed ranks are %v)",
|
|
rank,
|
|
taxonomy.RankList())
|
|
}
|
|
|
|
f := func(sequence *BioSequence) bool {
|
|
taxon := sequence.Taxon(taxonomy)
|
|
return taxon != nil && taxon.HasRankDefined(rank)
|
|
}
|
|
|
|
return f
|
|
}
|