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

View File

@@ -2,17 +2,24 @@ package obiiter
import "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax" 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) { func (iterator *IBioSequence) ExtractTaxonomy(seqAsTaxa bool) (taxonomy *obitax.Taxonomy, err error) {
// Iterate over each slice in the iterator
for iterator.Next() { for iterator.Next() {
// Get the current slice
slice := iterator.Get().Slice() slice := iterator.Get().Slice()
// Try to extract taxonomy from the slice
taxonomy, err = slice.ExtractTaxonomy(taxonomy, seqAsTaxa) taxonomy, err = slice.ExtractTaxonomy(taxonomy, seqAsTaxa)
// If an error occurred during extraction, return it immediately
if err != nil { if err != nil {
return return
} }
} }
// Return the extracted taxonomy and no error if all slices were successfully processed
return return
} }

View File

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

View File

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

View File

@@ -28,21 +28,22 @@ func NewITaxon() *ITaxon {
// Iterator creates a new ITaxon iterator for the TaxonSet. // 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. // It starts a goroutine to send Taxon instances from the set to the iterator's source channel.
func (set *TaxonSet) Iterator() *ITaxon { func (set *TaxonSet) Iterator() *ITaxon {
i := NewITaxon() return set.Sort().Iterator()
// i := NewITaxon()
go func() { // go func() {
for _, t := range set.set { // for _, t := range set.set {
taxon := &Taxon{ // taxon := &Taxon{
Taxonomy: set.taxonomy, // Taxonomy: set.taxonomy,
Metadata: nil, // Metadata: nil,
Node: t, // Node: t,
} // }
i.Push(taxon) // i.Push(taxon)
} // }
close(i.source) // close(i.source)
}() // }()
return i // return i
} }
// Iterator creates a new ITaxon iterator for the TaxonSlice. // 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 { if err != nil {
return nil, err return nil, err
} }
root.SetName(scientific_name, "scientificName") root.SetName(scientific_name, "scientific name")
} }
var current *Taxon var current *Taxon