Add the --with-taxon-at-rank option code to obiannotate

This commit is contained in:
2023-02-02 16:36:32 +01:00
parent 886c5118e3
commit 5639a09fb9
4 changed files with 45 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ package obiannotate
import (
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitax"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obigrep"
)
@@ -43,6 +44,17 @@ func RenameAttributeWorker(toBeRenamed map[string]string) obiseq.SeqWorker {
return f
}
func AddTaxonAtRankWorker(taxonomy *obitax.Taxonomy, ranks ...string) obiseq.SeqWorker {
f := func(s *obiseq.BioSequence) *obiseq.BioSequence {
for _, r := range ranks {
taxonomy.SetTaxonAtRank(s,r)
}
return s
}
return f
}
func CLIAnnotationWorker() obiseq.SeqWorker {
var annotator obiseq.SeqWorker
annotator = nil
@@ -62,6 +74,12 @@ func CLIAnnotationWorker() obiseq.SeqWorker {
annotator = annotator.ChainWorkers(w)
}
if CLIHasTaxonAtRank() {
taxo := obigrep.CLILoadSelectedTaxonomy()
w := AddTaxonAtRankWorker(taxo,CLITaxonAtRank()...)
annotator = annotator.ChainWorkers(w)
}
return annotator
}

View File

@@ -112,12 +112,19 @@ func CLIHasToBeKeptAttributes() bool {
}
func CLIToBeKeptAttributes() map[string]bool {
d := make(map[string]bool,len(_keepOnly))
d := make(map[string]bool, len(_keepOnly))
for _,v := range _keepOnly {
d[v]=true
for _, v := range _keepOnly {
d[v] = true
}
return d
}
func CLIHasTaxonAtRank() bool {
return len(_taxonAtRank) > 0
}
func CLITaxonAtRank() []string {
return _taxonAtRank
}