Fisrt functional version

This commit is contained in:
Eric Coissac
2024-11-14 19:10:23 +01:00
parent 9471fedfa1
commit 03f4e88a17
26 changed files with 908 additions and 307 deletions

View File

@@ -7,13 +7,13 @@ import (
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax"
)
func IFilterRankRestriction() func(*obitax.ITaxonSet) *obitax.ITaxonSet {
f := func(s *obitax.ITaxonSet) *obitax.ITaxonSet {
func IFilterRankRestriction() func(*obitax.ITaxon) *obitax.ITaxon {
f := func(s *obitax.ITaxon) *obitax.ITaxon {
return s
}
if __restrict_rank__ != "" {
f = func(s *obitax.ITaxonSet) *obitax.ITaxonSet {
f = func(s *obitax.ITaxon) *obitax.ITaxon {
return s.IFilterOnTaxRank(__restrict_rank__)
}
}
@@ -21,21 +21,21 @@ func IFilterRankRestriction() func(*obitax.ITaxonSet) *obitax.ITaxonSet {
return f
}
func ITaxonNameMatcher() (func(string) *obitax.ITaxonSet, error) {
func ITaxonNameMatcher() (func(string) *obitax.ITaxon, error) {
taxonomy, err := CLILoadSelectedTaxonomy()
if err != nil {
return nil, err
}
fun := func(name string) *obitax.ITaxonSet {
fun := func(name string) *obitax.ITaxon {
return taxonomy.IFilterOnName(name, __fixed_pattern__)
}
return fun, nil
}
func ITaxonRestrictions() (func(*obitax.ITaxonSet) *obitax.ITaxonSet, error) {
func ITaxonRestrictions() (func(*obitax.ITaxon) *obitax.ITaxon, error) {
clades, err := CLITaxonomicalRestrictions()
@@ -45,23 +45,19 @@ func ITaxonRestrictions() (func(*obitax.ITaxonSet) *obitax.ITaxonSet, error) {
rankfilter := IFilterRankRestriction()
fun := func(iterator *obitax.ITaxonSet) *obitax.ITaxonSet {
fun := func(iterator *obitax.ITaxon) *obitax.ITaxon {
return rankfilter(iterator).IFilterBelongingSubclades(clades)
}
return fun, nil
}
func TaxonAsString(taxon *obitax.TaxNode, pattern string) string {
func TaxonAsString(taxon *obitax.Taxon, pattern string) string {
text := taxon.ScientificName()
if __with_path__ {
var bf bytes.Buffer
path, err := taxon.Path()
if err != nil {
fmt.Printf("%+v", err)
}
path := taxon.Path()
bf.WriteString(path.Get(path.Len() - 1).ScientificName())
@@ -72,15 +68,15 @@ func TaxonAsString(taxon *obitax.TaxNode, pattern string) string {
text = bf.String()
}
return fmt.Sprintf("%-20s | %10d | %10d | %-20s | %s",
return fmt.Sprintf("%-20s | %10s | %10s | %-20s | %s",
pattern,
taxon.Taxid(),
taxon.Parent().Taxid(),
taxon.String(),
taxon.Parent().String(),
taxon.Rank(),
text)
}
func TaxonWriter(itaxa *obitax.ITaxonSet, pattern string) {
func TaxonWriter(itaxa *obitax.ITaxon, pattern string) {
for itaxa.Next() {
fmt.Println(TaxonAsString(itaxa.Get(), pattern))
}

View File

@@ -12,12 +12,12 @@ var __taxdump__ = ""
var __alternative_name__ = false
var __rank_list__ = false
var __selected_taxonomy__ = (*obitax.Taxonomy)(nil)
var __taxonomical_restriction__ = make([]int, 0)
var __taxonomical_restriction__ = make([]string, 0)
var __fixed_pattern__ = false
var __with_path__ = false
var __taxid_path__ = -1
var __taxid_sons__ = -1
var __taxid_path__ = "NA"
var __taxid_sons__ = "NA"
var __restrict_rank__ = ""
func LoadTaxonomyOptionSet(options *getoptions.GetOpt, required, alternatiive bool) {
@@ -43,7 +43,7 @@ func FilterTaxonomyOptionSet(options *getoptions.GetOpt) {
options.Alias("l"),
options.Description("List every taxonomic rank available in the taxonomy."))
options.IntSliceVar(&__taxonomical_restriction__, "restrict-to-taxon", 1, 1,
options.StringSliceVar(&__taxonomical_restriction__, "restrict-to-taxon", 1, 1,
options.Alias("r"),
options.Description("Restrict output to some subclades."))
}
@@ -67,18 +67,18 @@ func CLITaxonomicalRestrictions() (*obitax.TaxonSet, error) {
return nil, err
}
ts := make(obitax.TaxonSet)
ts := taxonomy.NewTaxonSet()
for _, taxid := range __taxonomical_restriction__ {
tx, err := taxonomy.Taxon(taxid)
tx := taxonomy.Taxon(taxid)
if err != nil {
return nil, err
}
ts.Inserts(tx)
ts.InsertTaxon(tx)
}
return &ts, nil
return ts, nil
}
func CLILoadSelectedTaxonomy() (*obitax.Taxonomy, error) {
@@ -106,17 +106,17 @@ func OptionSet(options *getoptions.GetOpt) {
options.BoolVar(&__with_path__, "with-path", false,
options.Alias("P"),
options.Description("Adds a column containing the full path for each displayed taxon."))
options.IntVar(&__taxid_path__, "parents", -1,
options.StringVar(&__taxid_path__, "parents", "NA",
options.Alias("p"),
options.Description("Displays every parental tree's information for the provided taxid."))
options.StringVar(&__restrict_rank__, "rank", "",
options.Description("Restrict to the given taxonomic rank."))
}
func CLIRequestsPathForTaxid() int {
func CLIRequestsPathForTaxid() string {
return __taxid_path__
}
func CLIRequestsSonsForTaxid() int {
func CLIRequestsSonsForTaxid() string {
return __taxid_sons__
}