Patch a bug in comparison of attibutes during sequence annotation merging

This commit is contained in:
2022-09-08 07:50:17 +02:00
parent 6b8f4490cf
commit 448f5f83fa

View File

@ -2,6 +2,7 @@ package obiseq
import ( import (
"fmt" "fmt"
"reflect"
"strings" "strings"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils" "git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
@ -15,8 +16,8 @@ func StatsOnSlotName(key string) string {
} }
/* /*
Tests if the sequence has already a slot summarizing statistics Tests if the sequence has already a slot summarizing statistics
of occurrence for a given attribute. of occurrence for a given attribute.
*/ */
func (sequence *BioSequence) HasStatsOn(key string) bool { func (sequence *BioSequence) HasStatsOn(key string) bool {
if !sequence.HasAnnotation() { if !sequence.HasAnnotation() {
@ -154,7 +155,19 @@ func (sequence *BioSequence) Merge(tomerge *BioSequence, na string, inplace bool
for k, va := range annotations { for k, va := range annotations {
if !strings.HasPrefix(k, "merged_") { if !strings.HasPrefix(k, "merged_") {
vm, ok := ma[k] vm, ok := ma[k]
if !ok || vm != va { if ok {
switch vm := vm.(type) {
case int, float64, string, bool:
if va != vm {
delete(annotations, k)
}
default:
if !reflect.DeepEqual(va, vm) {
delete(annotations, k)
}
}
} else {
delete(annotations, k) delete(annotations, k)
} }
} }
@ -171,14 +184,16 @@ func (sequence *BioSequence) Merge(tomerge *BioSequence, na string, inplace bool
return sequence return sequence
} }
/** /*
Merges a set of sequence into a single sequence. *
The function assumes that every sequence in the batch is Merges a set of sequence into a single sequence.
identical in term of sequence. Actually the function only
aggregates the annotations of the different sequences to be merged
Quality information is lost during the merge procedure. The function assumes that every sequence in the batch is
identical in term of sequence. Actually the function only
aggregates the annotations of the different sequences to be merged
Quality information is lost during the merge procedure.
*/ */
func (sequences BioSequenceSlice) Merge(na string, statsOn []string) *BioSequence { func (sequences BioSequenceSlice) Merge(na string, statsOn []string) *BioSequence {
seq := sequences[0] seq := sequences[0]