mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
First functional version of a blackboard and a blackboard based obicount
This commit is contained in:
50
pkg/obiblackboard/count_sequences.go
Normal file
50
pkg/obiblackboard/count_sequences.go
Normal file
@ -0,0 +1,50 @@
|
||||
package obiblackboard
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter"
|
||||
)
|
||||
|
||||
type SequenceCounter struct {
|
||||
Variants int
|
||||
Reads int
|
||||
Nucleotides int
|
||||
Runner DoTask
|
||||
}
|
||||
|
||||
func CountSequenceAggregator(target string) *SequenceCounter {
|
||||
cc := &SequenceCounter{
|
||||
Variants: 0,
|
||||
Reads: 0,
|
||||
Nucleotides: 0,
|
||||
Runner: nil,
|
||||
}
|
||||
|
||||
mutex := sync.Mutex{}
|
||||
|
||||
runner := func(bb *Blackboard, task *Task) *Task {
|
||||
body := task.Body.(obiiter.BioSequenceBatch)
|
||||
|
||||
mutex.Lock()
|
||||
cc.Variants += body.Len()
|
||||
cc.Reads += body.Slice().Count()
|
||||
cc.Nucleotides += body.Slice().Size()
|
||||
mutex.Unlock()
|
||||
|
||||
nt := task.GetNext(target, true, false)
|
||||
return nt
|
||||
}
|
||||
|
||||
cc.Runner = runner
|
||||
return cc
|
||||
}
|
||||
|
||||
func RecycleSequences(rescycleSequence bool, target string) DoTask {
|
||||
return func(bb *Blackboard, task *Task) *Task {
|
||||
body := task.Body.(obiiter.BioSequenceBatch)
|
||||
// log.Warningf("With priority %d, Recycling %s[%d]", task.Priority, body.Source(), body.Order())
|
||||
body.Recycle(rescycleSequence)
|
||||
return task.GetNext(target, false, false)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user