Work on iterators and recycling of biosequences

This commit is contained in:
2022-01-14 23:11:36 +01:00
parent ef66ca4972
commit e8fff6477b
22 changed files with 350 additions and 111 deletions

View File

@@ -39,6 +39,7 @@ func (batch BioSequenceBatch) IsNil() bool {
type __ibiosequencebatch__ struct {
channel chan BioSequenceBatch
current BioSequenceBatch
pushBack bool
all_done *sync.WaitGroup
buffer_size int
finished bool
@@ -61,9 +62,11 @@ func MakeIBioSequenceBatch(sizes ...int) IBioSequenceBatch {
i := __ibiosequencebatch__{
channel: make(chan BioSequenceBatch, buffsize),
current: NilBioSequenceBatch,
pushBack: false,
buffer_size: buffsize,
finished: false,
p_finished: nil}
p_finished: nil,
}
i.p_finished = &i.finished
waiting := sync.WaitGroup{}
i.all_done = &waiting
@@ -99,6 +102,7 @@ func (iterator IBioSequenceBatch) Split() IBioSequenceBatch {
i := __ibiosequencebatch__{
channel: iterator.pointer.channel,
current: NilBioSequenceBatch,
pushBack: false,
all_done: iterator.pointer.all_done,
buffer_size: iterator.pointer.buffer_size,
finished: false,
@@ -111,6 +115,12 @@ func (iterator IBioSequenceBatch) Next() bool {
if *(iterator.pointer.p_finished) {
return false
}
if iterator.pointer.pushBack {
iterator.pointer.pushBack = false
return true
}
next, ok := (<-iterator.pointer.channel)
if ok {
@@ -123,6 +133,12 @@ func (iterator IBioSequenceBatch) Next() bool {
return false
}
func (iterator IBioSequenceBatch) PushBack() {
if !iterator.pointer.current.IsNil() {
iterator.pointer.pushBack = true
}
}
// The 'Get' method returns the instance of BioSequenceBatch
// currently pointed by the iterator. You have to use the
// 'Next' method to move to the next entry before calling
@@ -303,14 +319,14 @@ func (iterator IBioSequenceBatch) Rebatch(size int, sizes ...int) IBioSequenceBa
return newIter
}
func (iterator IBioSequenceBatch) Destroy() {
func (iterator IBioSequenceBatch) Recycle() {
log.Println("Start recycling of Bioseq objects")
for iterator.Next() {
batch := iterator.Get()
for _, seq := range batch.Slice() {
(&seq).Destroy()
(&seq).Recycle()
}
}
log.Println("End of the recycling of Bioseq objects")

View File

@@ -44,7 +44,7 @@ func (s BioSequence) IsNil() bool {
return s.sequence == nil
}
func (s BioSequence) Reset() {
func (s *BioSequence) Reset() {
s.sequence.id.Reset()
s.sequence.definition.Reset()
s.sequence.sequence.Reset()
@@ -168,6 +168,10 @@ func (s BioSequence) SetQualities(qualities Quality) {
s.sequence.qualities.Write(qualities)
}
func (s BioSequence) WriteQualities(data []byte) (int, error) {
return s.sequence.qualities.Write(data)
}
func (s BioSequence) Write(data []byte) (int, error) {
return s.sequence.sequence.Write(data)
}

View File

@@ -10,10 +10,11 @@ import (
type __ibiosequence__ struct {
channel chan BioSequence
current BioSequence
pushBack bool
all_done *sync.WaitGroup
buffer_size int
finished bool
p_finished *bool
pFinished *bool
}
type IBioSequence struct {
@@ -55,10 +56,13 @@ func MakeIBioSequence(sizes ...int) IBioSequence {
i := __ibiosequence__{
channel: make(chan BioSequence, buffsize),
current: NilBioSequence,
pushBack: false,
buffer_size: buffsize,
finished: false,
p_finished: nil}
i.p_finished = &i.finished
pFinished: nil,
}
i.pFinished = &i.finished
waiting := sync.WaitGroup{}
i.all_done = &waiting
ii := IBioSequence{&i}
@@ -66,23 +70,32 @@ func MakeIBioSequence(sizes ...int) IBioSequence {
}
func (iterator IBioSequence) Split() IBioSequence {
i := __ibiosequence__{
channel: iterator.pointer.channel,
current: NilBioSequence,
pushBack: false,
finished: false,
all_done: iterator.pointer.all_done,
buffer_size: iterator.pointer.buffer_size,
p_finished: iterator.pointer.p_finished}
pFinished: iterator.pointer.pFinished,
}
newIter := IBioSequence{&i}
return newIter
}
func (iterator IBioSequence) Next() bool {
if iterator.IsNil() || *(iterator.pointer.p_finished) {
if iterator.IsNil() || *(iterator.pointer.pFinished) {
iterator.pointer.current = NilBioSequence
return false
}
if iterator.pointer.pushBack {
iterator.pointer.pushBack = false
return true
}
next, ok := (<-iterator.pointer.channel)
if ok {
@@ -91,10 +104,16 @@ func (iterator IBioSequence) Next() bool {
}
iterator.pointer.current = NilBioSequence
*iterator.pointer.p_finished = true
*iterator.pointer.pFinished = true
return false
}
func (iterator IBioSequence) PushBack() {
if !iterator.pointer.current.IsNil() {
iterator.pointer.pushBack = true
}
}
// The 'Get' method returns the instance of BioSequence
// currently pointed by the iterator. You have to use the
// 'Next' method to move to the next entry before calling
@@ -106,7 +125,7 @@ func (iterator IBioSequence) Get() BioSequence {
// Finished returns 'true' value if no more data is available
// from the iterator.
func (iterator IBioSequence) Finished() bool {
return *iterator.pointer.p_finished
return *iterator.pointer.pFinished
}
func (iterator IBioSequence) BufferSize() int {

View File

@@ -55,6 +55,7 @@ func (batch PairedBioSequenceBatch) IsNil() bool {
type __ipairedbiosequencebatch__ struct {
channel chan PairedBioSequenceBatch
current PairedBioSequenceBatch
pushBack bool
all_done *sync.WaitGroup
buffer_size int
finished bool
@@ -77,9 +78,12 @@ func MakeIPairedBioSequenceBatch(sizes ...int) IPairedBioSequenceBatch {
i := __ipairedbiosequencebatch__{
channel: make(chan PairedBioSequenceBatch, buffsize),
current: NilPairedBioSequenceBatch,
pushBack: false,
buffer_size: buffsize,
finished: false,
p_finished: nil}
p_finished: nil,
}
i.p_finished = &i.finished
waiting := sync.WaitGroup{}
i.all_done = &waiting
@@ -115,6 +119,7 @@ func (iterator IPairedBioSequenceBatch) Split() IPairedBioSequenceBatch {
i := __ipairedbiosequencebatch__{
channel: iterator.pointer.channel,
current: NilPairedBioSequenceBatch,
pushBack: false,
all_done: iterator.pointer.all_done,
buffer_size: iterator.pointer.buffer_size,
finished: false,
@@ -127,6 +132,12 @@ func (iterator IPairedBioSequenceBatch) Next() bool {
if *(iterator.pointer.p_finished) {
return false
}
if iterator.pointer.pushBack {
iterator.pointer.pushBack = false
return true
}
next, ok := (<-iterator.pointer.channel)
if ok {
@@ -139,6 +150,12 @@ func (iterator IPairedBioSequenceBatch) Next() bool {
return false
}
func (iterator IPairedBioSequenceBatch) PushBack() {
if !iterator.pointer.current.IsNil() {
iterator.pointer.pushBack = true
}
}
// The 'Get' method returns the instance of BioSequenceBatch
// currently pointed by the iterator. You have to use the
// 'Next' method to move to the next entry before calling

View File

@@ -14,7 +14,6 @@ var __bioseq__pool__ = sync.Pool{
func MakeEmptyBioSequence() BioSequence {
bs := BioSequence{__bioseq__pool__.Get().(*__sequence__)}
bs.Reset()
return bs
}
@@ -23,12 +22,13 @@ func MakeBioSequence(id string,
definition string) BioSequence {
bs := MakeEmptyBioSequence()
bs.SetId(id)
bs.SetSequence(sequence)
bs.Write(sequence)
bs.SetDefinition(definition)
return bs
}
func (sequence *BioSequence) Destroy() {
func (sequence *BioSequence) Recycle() {
sequence.Reset()
__bioseq__pool__.Put(sequence.sequence)
sequence.sequence = nil
}

View File

@@ -84,9 +84,10 @@ func (iterator IBioSequenceBatch) MakeIWorker(worker SeqWorker, sizes ...int) IB
}
log.Println("Start of the batch workers")
for i := 0; i < nworkers; i++ {
for i := 0; i < nworkers-1; i++ {
go f(iterator.Split())
}
go f(iterator)
return newIter
}
@@ -126,9 +127,10 @@ func (iterator IBioSequenceBatch) MakeISliceWorker(worker SeqSliceWorker, sizes
}
log.Println("Start of the batch slice workers")
for i := 0; i < nworkers; i++ {
for i := 0; i < nworkers - 1; i++ {
go f(iterator.Split())
}
go f(iterator)
return newIter
}