Manage a lock on StatsOnValues

This commit is contained in:
Eric Coissac
2025-06-17 16:46:11 +02:00
parent 8a2bb1fe82
commit 9965370d85
9 changed files with 230 additions and 100 deletions

View File

@ -280,7 +280,7 @@ func _parse_json_header_(header string, sequence *obiseq.BioSequence) string {
if err != nil {
log.Fatalf("%s: Cannot parse merged slot %s: %v", sequence.Id(), skey, err)
} else {
annotations[skey] = data
annotations[skey] = obiseq.MapAsStatsOnValues(data)
}
} else {
log.Fatalf("%s: Cannot parse merged slot %s", sequence.Id(), skey)

View File

@ -216,11 +216,14 @@ func ParseOBIFeatures(text string, annotations obiseq.Annotation) string {
j = __obi_header_map_int_key__.ReplaceAll(j, []byte(`$1"$2":`))
var err error
switch {
case strings.HasPrefix(key, "merged_") ||
strings.HasSuffix(key, "_count"):
case strings.HasSuffix(key, "_count"):
dict := make(map[string]int)
err = json.Unmarshal(j, &dict)
value = dict
case strings.HasPrefix(key, "merged_"):
dict := make(map[string]int)
err = json.Unmarshal(j, &dict)
value = obiseq.MapAsStatsOnValues(dict)
case strings.HasSuffix(key, "_status") ||
strings.HasSuffix(key, "_mutation"):
dict := make(map[string]string)
@ -313,10 +316,20 @@ func WriteFastSeqOBIHeade(buffer *bytes.Buffer, sequence *obiseq.BioSequence) {
switch t := value.(type) {
case string:
buffer.WriteString(fmt.Sprintf("%s=%s; ", key, t))
case *obiseq.StatsOnValues:
t.RLock()
tv, err := obiutils.JsonMarshal(t.Map())
t.RUnlock()
if err != nil {
log.Fatalf("Cannot convert %v value", value)
}
tv = bytes.ReplaceAll(tv, []byte(`"`), []byte("'"))
buffer.WriteString(fmt.Sprintf("%s=", key))
buffer.Write(tv)
buffer.WriteString("; ")
case map[string]int,
map[string]string,
map[string]interface{},
obiseq.StatsOnValues:
map[string]interface{}:
tv, err := obiutils.JsonMarshal(t)
if err != nil {
log.Fatalf("Cannot convert %v value", value)