Debug on taxonomy extraction and CSV conversion

This commit is contained in:
Eric Coissac
2025-07-07 15:29:40 +02:00
parent 8d53d253d4
commit 43b285587e
6 changed files with 39 additions and 17 deletions

View File

@@ -44,6 +44,7 @@ type __options__ struct {
with_scientific_name bool
without_root_path bool
raw_taxid bool
u_to_t bool
with_metadata []string
}
@@ -88,6 +89,7 @@ func MakeOptions(setters []WithOption) Options {
with_path: false,
with_rank: true,
with_taxid: true,
u_to_t: false,
with_scientific_name: false,
without_root_path: false,
raw_taxid: false,
@@ -263,6 +265,10 @@ func (o *Options) RawTaxid() bool {
return o.pointer.raw_taxid
}
func (o *Options) UtoT() bool {
return o.pointer.u_to_t
}
// WithMetadata returns a slice of strings containing the metadata
// associated with the Options instance. It retrieves the metadata
// from the pointer's with_metadata field.
@@ -598,6 +604,14 @@ func OptionsRawTaxid(value bool) WithOption {
return f
}
func OptionsUtoT(value bool) WithOption {
f := WithOption(func(opt Options) {
opt.pointer.u_to_t = value
})
return f
}
func OptionsWithMetadata(values ...string) WithOption {
f := WithOption(func(opt Options) {
opt.pointer.with_metadata = values

View File

@@ -2,17 +2,24 @@ package obiiter
import "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax"
// ExtractTaxonomy iterates over each slice of the IBioSequence and extracts the taxonomy from it using the ExtractTaxonomy method of the slice.
// If the seqAsTaxa parameter is true, then the sequence itself will be treated as a single taxon. Otherwise, each element in the slice will be treated separately.
// The function returns an error if any of the ExtractTaxonomy calls fail and nil otherwise.
func (iterator *IBioSequence) ExtractTaxonomy(seqAsTaxa bool) (taxonomy *obitax.Taxonomy, err error) {
// Iterate over each slice in the iterator
for iterator.Next() {
// Get the current slice
slice := iterator.Get().Slice()
// Try to extract taxonomy from the slice
taxonomy, err = slice.ExtractTaxonomy(taxonomy, seqAsTaxa)
// If an error occurred during extraction, return it immediately
if err != nil {
return
}
}
// Return the extracted taxonomy and no error if all slices were successfully processed
return
}

View File

@@ -8,7 +8,7 @@ import (
// corresponds to the last commit, and not the one when the file will be
// commited
var _Commit = "27fa984"
var _Commit = "235a7e2"
var _Version = "Release 4.4.0"
// Version returns the version of the obitools package.

View File

@@ -26,7 +26,7 @@ func (taxonomy *Taxonomy) OrDefault(panicOnNil bool) *Taxonomy {
return taxonomy
}
func IsDefaultTaxonomyDefined() bool {
func HasDefaultTaxonomyDefined() bool {
return __defaut_taxonomy__ != nil
}

View File

@@ -28,21 +28,22 @@ func NewITaxon() *ITaxon {
// Iterator creates a new ITaxon iterator for the TaxonSet.
// It starts a goroutine to send Taxon instances from the set to the iterator's source channel.
func (set *TaxonSet) Iterator() *ITaxon {
i := NewITaxon()
return set.Sort().Iterator()
// i := NewITaxon()
go func() {
for _, t := range set.set {
taxon := &Taxon{
Taxonomy: set.taxonomy,
Metadata: nil,
Node: t,
}
i.Push(taxon)
}
close(i.source)
}()
// go func() {
// for _, t := range set.set {
// taxon := &Taxon{
// Taxonomy: set.taxonomy,
// Metadata: nil,
// Node: t,
// }
// i.Push(taxon)
// }
// close(i.source)
// }()
return i
// return i
}
// Iterator creates a new ITaxon iterator for the TaxonSlice.

View File

@@ -386,7 +386,7 @@ func (taxonomy *Taxonomy) InsertPathString(path []string) (*Taxonomy, error) {
if err != nil {
return nil, err
}
root.SetName(scientific_name, "scientificName")
root.SetName(scientific_name, "scientific name")
}
var current *Taxon