diff --git a/pkg/obiformats/options.go b/pkg/obiformats/options.go index 69345e9..8190801 100644 --- a/pkg/obiformats/options.go +++ b/pkg/obiformats/options.go @@ -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 diff --git a/pkg/obiiter/extract_taxonomy.go b/pkg/obiiter/extract_taxonomy.go index fd05eaf..e7dc9d8 100644 --- a/pkg/obiiter/extract_taxonomy.go +++ b/pkg/obiiter/extract_taxonomy.go @@ -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 } diff --git a/pkg/obioptions/version.go b/pkg/obioptions/version.go index 390efe2..b451e4a 100644 --- a/pkg/obioptions/version.go +++ b/pkg/obioptions/version.go @@ -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. diff --git a/pkg/obitax/default_taxonomy.go b/pkg/obitax/default_taxonomy.go index 4ddc9d3..4765b77 100644 --- a/pkg/obitax/default_taxonomy.go +++ b/pkg/obitax/default_taxonomy.go @@ -26,7 +26,7 @@ func (taxonomy *Taxonomy) OrDefault(panicOnNil bool) *Taxonomy { return taxonomy } -func IsDefaultTaxonomyDefined() bool { +func HasDefaultTaxonomyDefined() bool { return __defaut_taxonomy__ != nil } diff --git a/pkg/obitax/iterator.go b/pkg/obitax/iterator.go index 8c4d9c7..8b472fd 100644 --- a/pkg/obitax/iterator.go +++ b/pkg/obitax/iterator.go @@ -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. diff --git a/pkg/obitax/taxonomy.go b/pkg/obitax/taxonomy.go index 90a5e1b..b022df8 100644 --- a/pkg/obitax/taxonomy.go +++ b/pkg/obitax/taxonomy.go @@ -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