From 448f5f83fa63dad7c0d87b87ca258d8263ebb23f Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Thu, 8 Sep 2022 07:50:17 +0200 Subject: [PATCH] Patch a bug in comparison of attibutes during sequence annotation merging --- pkg/obiseq/merge.go | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/pkg/obiseq/merge.go b/pkg/obiseq/merge.go index 6a49094..8a28e36 100644 --- a/pkg/obiseq/merge.go +++ b/pkg/obiseq/merge.go @@ -2,6 +2,7 @@ package obiseq import ( "fmt" + "reflect" "strings" "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 - of occurrence for a given attribute. + Tests if the sequence has already a slot summarizing statistics + of occurrence for a given attribute. */ func (sequence *BioSequence) HasStatsOn(key string) bool { if !sequence.HasAnnotation() { @@ -154,7 +155,19 @@ func (sequence *BioSequence) Merge(tomerge *BioSequence, na string, inplace bool for k, va := range annotations { if !strings.HasPrefix(k, "merged_") { 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) } } @@ -171,14 +184,16 @@ func (sequence *BioSequence) Merge(tomerge *BioSequence, na string, inplace bool return sequence } -/** - Merges a set of sequence into a single sequence. +/* +* - 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 + Merges a set of sequence into a single sequence. - 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 { seq := sequences[0]