Update obisummary to account new obiseq.StatsOnValues type

This commit is contained in:
Eric Coissac
2025-06-19 17:21:30 +02:00
parent 27fa984a63
commit 235a7e202a
3 changed files with 44 additions and 2 deletions

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 = "add9d89" var _Commit = "27fa984"
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

@ -139,7 +139,10 @@ func (data *DataSummary) Update(s *obiseq.BioSequence) *DataSummary {
} }
for k, v := range s.Annotations() { for k, v := range s.Annotations() {
_, isSov := v.(*obiseq.StatsOnValues)
switch { switch {
case isSov:
plusOneUpdateIntMap(data.map_tags, k)
case obiutils.IsAMap(v): case obiutils.IsAMap(v):
plusOneUpdateIntMap(data.map_tags, k) plusOneUpdateIntMap(data.map_tags, k)
case obiutils.IsASlice(v): case obiutils.IsASlice(v):

View File

@ -2,6 +2,7 @@ package obiutils
import ( import (
"fmt" "fmt"
"maps"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
@ -90,7 +91,21 @@ func InterfaceToBool(i interface{}) (val bool, err error) {
// It returns a map[string]interface{} which is the converted map. If the input map is not of type map[string]interface{}, // It returns a map[string]interface{} which is the converted map. If the input map is not of type map[string]interface{},
// it panics and logs an error message. // it panics and logs an error message.
func MapToMapInterface(m interface{}) map[string]interface{} { func MapToMapInterface(m interface{}) map[string]interface{} {
if IsAMap(m) { type hasMap interface {
Map() map[string]int
RLock()
RUnlock()
Len() int
}
if v, ok := m.(hasMap); ok {
val := make(map[string]interface{}, v.Len())
v.RLock()
defer v.RUnlock()
for k, v := range v.Map() {
val[k] = v
}
} else if IsAMap(m) {
reflectMap := reflect.ValueOf(m) reflectMap := reflect.ValueOf(m)
keys := reflectMap.MapKeys() keys := reflectMap.MapKeys()
val := make(map[string]interface{}, len(keys)) val := make(map[string]interface{}, len(keys))
@ -193,9 +208,19 @@ func InterfaceToFloat64(i interface{}) (val float64, err error) {
func InterfaceToIntMap(i interface{}) (val map[string]int, err error) { func InterfaceToIntMap(i interface{}) (val map[string]int, err error) {
err = nil err = nil
type hasMap interface {
Map() map[string]int
RLock()
RUnlock()
}
switch i := i.(type) { switch i := i.(type) {
case map[string]int: case map[string]int:
val = i val = i
case hasMap:
i.RLock()
defer i.RUnlock()
val = maps.Clone(i.Map())
case map[string]interface{}: case map[string]interface{}:
val = make(map[string]int, len(i)) val = make(map[string]int, len(i))
for k, v := range i { for k, v := range i {
@ -219,9 +244,23 @@ func InterfaceToIntMap(i interface{}) (val map[string]int, err error) {
func InterfaceToStringMap(i interface{}) (val map[string]string, err error) { func InterfaceToStringMap(i interface{}) (val map[string]string, err error) {
err = nil err = nil
type hasMap interface {
Map() map[string]int
RLock()
RUnlock()
Len() int
}
switch i := i.(type) { switch i := i.(type) {
case map[string]string: case map[string]string:
val = i val = i
case hasMap:
val = make(map[string]string, i.Len())
i.RLock()
defer i.RUnlock()
for k, v := range i.Map() {
val[k] = strconv.Itoa(v)
}
case map[string]interface{}: case map[string]interface{}:
val = make(map[string]string, len(i)) val = make(map[string]string, len(i))
for k, v := range i { for k, v := range i {