mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
correction of several small bugs
This commit is contained in:
@ -72,8 +72,8 @@ func (s *BioSequence) HasAttribute(key string) bool {
|
||||
ok := s.annotations != nil
|
||||
|
||||
if ok {
|
||||
defer s.AnnotationsUnlock()
|
||||
s.AnnotationsLock()
|
||||
defer s.AnnotationsUnlock()
|
||||
_, ok = s.annotations[key]
|
||||
}
|
||||
|
||||
@ -112,8 +112,8 @@ func (s *BioSequence) GetAttribute(key string) (interface{}, bool) {
|
||||
ok := s.annotations != nil
|
||||
|
||||
if ok {
|
||||
defer s.AnnotationsUnlock()
|
||||
s.AnnotationsLock()
|
||||
defer s.AnnotationsUnlock()
|
||||
val, ok = s.annotations[key]
|
||||
}
|
||||
|
||||
@ -144,8 +144,8 @@ func (s *BioSequence) SetAttribute(key string, value interface{}) {
|
||||
|
||||
annot := s.Annotations()
|
||||
|
||||
defer s.AnnotationsUnlock()
|
||||
s.AnnotationsLock()
|
||||
defer s.AnnotationsUnlock()
|
||||
annot[key] = value
|
||||
}
|
||||
|
||||
@ -205,8 +205,8 @@ func (s *BioSequence) GetFloatAttribute(key string) (float64, bool) {
|
||||
// No return value.
|
||||
func (s *BioSequence) DeleteAttribute(key string) {
|
||||
if s.annotations != nil {
|
||||
defer s.AnnotationsUnlock()
|
||||
s.AnnotationsLock()
|
||||
defer s.AnnotationsUnlock()
|
||||
delete(s.annotations, key)
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ type BioSequence struct {
|
||||
feature []byte
|
||||
paired *BioSequence // A pointer to the paired sequence
|
||||
annotations Annotation
|
||||
annot_lock sync.Mutex
|
||||
annot_lock *sync.Mutex
|
||||
}
|
||||
|
||||
// NewEmptyBioSequence creates a new BioSequence object with an empty sequence.
|
||||
@ -90,7 +90,7 @@ func NewEmptyBioSequence(preallocate int) *BioSequence {
|
||||
feature: nil,
|
||||
paired: nil,
|
||||
annotations: nil,
|
||||
annot_lock: sync.Mutex{},
|
||||
annot_lock: &sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,7 @@ func TestCopy(t *testing.T) {
|
||||
"annotation1": "value1",
|
||||
"annotation2": "value2",
|
||||
},
|
||||
annot_lock: sync.Mutex{},
|
||||
annot_lock: &sync.Mutex{},
|
||||
}
|
||||
|
||||
newSeq := seq.Copy()
|
||||
|
@ -91,8 +91,7 @@ func (sequence *BioSequence) HasStatsOn(key string) bool {
|
||||
// - StatsOnValues
|
||||
func (sequence *BioSequence) StatsOn(desc StatsOnDescription, na string) StatsOnValues {
|
||||
mkey := StatsOnSlotName(desc.Name)
|
||||
annotations := sequence.Annotations()
|
||||
istat, ok := annotations[mkey]
|
||||
istat, ok := sequence.GetAttribute(mkey)
|
||||
|
||||
var stats StatsOnValues
|
||||
var newstat bool
|
||||
@ -117,39 +116,40 @@ func (sequence *BioSequence) StatsOn(desc StatsOnDescription, na string) StatsOn
|
||||
}
|
||||
}
|
||||
default:
|
||||
stats = make(StatsOnValues, 10)
|
||||
annotations[mkey] = stats
|
||||
stats = make(StatsOnValues)
|
||||
sequence.SetAttribute(mkey, stats)
|
||||
newstat = true
|
||||
}
|
||||
} else {
|
||||
stats = make(StatsOnValues, 10)
|
||||
annotations[mkey] = stats
|
||||
stats = make(StatsOnValues)
|
||||
sequence.SetAttribute(mkey, stats)
|
||||
newstat = true
|
||||
}
|
||||
|
||||
if newstat && sequence.StatsPlusOne(desc, sequence, na) {
|
||||
delete(sequence.Annotations(), desc.Key)
|
||||
if newstat {
|
||||
sequence.StatsPlusOne(desc, sequence, na)
|
||||
}
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
// StatsPlusOne adds the count of the sequence toAdd to the count of the key in the stats.
|
||||
// StatsPlusOne updates the statistics on the given attribute (desc) on the receiver BioSequence
|
||||
// with the value of the attribute on the toAdd BioSequence.
|
||||
//
|
||||
// Parameters:
|
||||
// - key: the attribute key (string) to be summarized
|
||||
// - toAdd: the BioSequence to add to the stats
|
||||
// - desc: StatsOnDescription of the attribute to be updated
|
||||
// - toAdd: the BioSequence containing the attribute to be updated
|
||||
// - na: the value to be used if the attribute is not present
|
||||
//
|
||||
// Return type:
|
||||
// - bool
|
||||
// - bool: true if the update was successful, false otherwise
|
||||
func (sequence *BioSequence) StatsPlusOne(desc StatsOnDescription, toAdd *BioSequence, na string) bool {
|
||||
sval := na
|
||||
annotations := sequence.Annotations()
|
||||
stats := sequence.StatsOn(desc, na)
|
||||
retval := false
|
||||
|
||||
if toAdd.HasAnnotation() {
|
||||
value, ok := toAdd.Annotations()[desc.Key]
|
||||
value, ok := toAdd.GetAttribute(desc.Key)
|
||||
|
||||
if ok {
|
||||
|
||||
@ -178,8 +178,9 @@ func (sequence *BioSequence) StatsPlusOne(desc StatsOnDescription, toAdd *BioSeq
|
||||
if !ok {
|
||||
old = 0
|
||||
}
|
||||
|
||||
stats[sval] = old + desc.Weight(toAdd)
|
||||
annotations[StatsOnSlotName(desc.Name)] = stats // TODO: check if this is necessary
|
||||
sequence.SetAttribute(StatsOnSlotName(desc.Name), stats) // TODO: check if this is necessary
|
||||
return retval
|
||||
}
|
||||
|
||||
@ -263,7 +264,7 @@ func (sequence *BioSequence) Merge(tomerge *BioSequence, na string, inplace bool
|
||||
}
|
||||
}
|
||||
|
||||
annotations["count"] = count
|
||||
sequence.SetCount(count)
|
||||
return sequence
|
||||
}
|
||||
|
||||
@ -282,7 +283,7 @@ func (sequences BioSequenceSlice) Merge(na string, statsOn StatsOnDescriptions)
|
||||
seq.SetQualities(nil)
|
||||
|
||||
if len(sequences) == 1 {
|
||||
seq.Annotations()["count"] = seq.Count()
|
||||
seq.SetCount(seq.Count())
|
||||
for _, desc := range statsOn {
|
||||
seq.StatsOn(desc, na)
|
||||
}
|
||||
@ -296,5 +297,4 @@ func (sequences BioSequenceSlice) Merge(na string, statsOn StatsOnDescriptions)
|
||||
|
||||
sequences.Recycle(false)
|
||||
return seq
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user