mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 08:40:26 +00:00
Fisrt step in the obitax rewriting
This commit is contained in:
@@ -5,30 +5,59 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type TaxonSlice []*TaxNode
|
||||
|
||||
func (set *TaxonSlice) Get(i int) *TaxNode {
|
||||
return (*set)[i]
|
||||
// TaxonSlice represents a slice of TaxNode[T] instances within a taxonomy.
|
||||
// It encapsulates a collection of taxon nodes and the taxonomy they belong to.
|
||||
//
|
||||
// Fields:
|
||||
// - slice: A slice of pointers to TaxNode[T] representing the taxon nodes.
|
||||
// - taxonomy: A pointer to the Taxonomy[T] instance that these taxon nodes are part of.
|
||||
type TaxonSlice struct {
|
||||
slice []*TaxNode
|
||||
taxonomy *Taxonomy
|
||||
}
|
||||
|
||||
func (set *TaxonSlice) Len() int {
|
||||
return len(*set)
|
||||
// Get retrieves the TaxNode[T] at the specified index from the TaxonSlice.
|
||||
// It returns the taxon node corresponding to the provided index.
|
||||
//
|
||||
// Parameters:
|
||||
// - i: An integer representing the index of the taxon node to retrieve.
|
||||
//
|
||||
// Returns:
|
||||
// - A pointer to the TaxNode[T] at the specified index in the slice.
|
||||
func (slice *TaxonSlice) Get(i int) *TaxNode {
|
||||
return slice.slice[i]
|
||||
}
|
||||
|
||||
// Len returns the number of TaxNode[T] instances in the TaxonSlice.
|
||||
// It provides the count of taxon nodes contained within the slice.
|
||||
//
|
||||
// Returns:
|
||||
// - An integer representing the total number of taxon nodes in the TaxonSlice.
|
||||
func (slice *TaxonSlice) Len() int {
|
||||
return len(slice.slice)
|
||||
}
|
||||
|
||||
// String returns a string representation of the TaxonSlice.
|
||||
// It formats the output to include the IDs, scientific names, and ranks of the taxon nodes
|
||||
// in the slice, concatenated in reverse order, separated by vertical bars.
|
||||
//
|
||||
// Returns:
|
||||
// - A formatted string representing the TaxonSlice, with each taxon in the format
|
||||
// "id@scientific_name@rank". If the slice is empty, it returns an empty string.
|
||||
func (path *TaxonSlice) String() string {
|
||||
var buffer bytes.Buffer
|
||||
|
||||
if len(*path) > 0 {
|
||||
taxon := (*path)[len(*path)-1]
|
||||
fmt.Fprintf(&buffer, "%d@%s@%s",
|
||||
taxon.Taxid(),
|
||||
if path.Len() > 0 {
|
||||
taxon := path.slice[path.Len()-1]
|
||||
fmt.Fprintf(&buffer, "%v@%s@%s",
|
||||
taxon.Id(),
|
||||
taxon.ScientificName(),
|
||||
taxon.Rank())
|
||||
|
||||
for i := len(*path) - 2; i >= 0; i-- {
|
||||
taxon := (*path)[i]
|
||||
fmt.Fprintf(&buffer, "|%d@%s@%s",
|
||||
taxon.Taxid(),
|
||||
for i := path.Len() - 2; i >= 0; i-- {
|
||||
taxon := path.slice[i]
|
||||
fmt.Fprintf(&buffer, "|%v@%s@%s",
|
||||
taxon.Id(),
|
||||
taxon.ScientificName(),
|
||||
taxon.Rank())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user