mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 16:50:27 +00:00
Adds a first version of a new obidistribute command
This commit is contained in:
48
pkg/obiformats/dispatcher.go
Normal file
48
pkg/obiformats/dispatcher.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package obiformats
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
|
||||
)
|
||||
|
||||
type SequenceBatchWriterToFile func(iterator obiseq.IBioSequenceBatch,
|
||||
filename string,
|
||||
options ...WithOption) (obiseq.IBioSequenceBatch, error)
|
||||
|
||||
func WriterDispatcher(prototypename string,
|
||||
dispatcher obiseq.IDistribute,
|
||||
formater SequenceBatchWriterToFile,
|
||||
options ...WithOption) {
|
||||
|
||||
jobDone := sync.WaitGroup{}
|
||||
jobDone.Add(1)
|
||||
|
||||
go func() {
|
||||
n := 0
|
||||
for newflux := range dispatcher.News() {
|
||||
data, _ := dispatcher.Outputs(newflux)
|
||||
out, err := formater(data,
|
||||
fmt.Sprintf(prototypename, newflux),
|
||||
options...)
|
||||
if err != nil {
|
||||
log.Fatalf("cannot open the output file for key %s", newflux)
|
||||
}
|
||||
|
||||
n++
|
||||
|
||||
if n > 1 {
|
||||
jobDone.Add(1)
|
||||
}
|
||||
|
||||
go func() {
|
||||
out.Recycle()
|
||||
jobDone.Done()
|
||||
}()
|
||||
}
|
||||
}()
|
||||
|
||||
jobDone.Wait()
|
||||
}
|
||||
@@ -122,10 +122,10 @@ func WriteFastqBatch(iterator obiseq.IBioSequenceBatch, file io.Writer, options
|
||||
}
|
||||
|
||||
log.Println("Start of the fastq file writing")
|
||||
go ff(iterator)
|
||||
for i := 0; i < nwriters-1; i++ {
|
||||
go ff(iterator.Split())
|
||||
}
|
||||
go ff(iterator)
|
||||
|
||||
next_to_send := 0
|
||||
received := make(map[int]FileChunck, 100)
|
||||
|
||||
Reference in New Issue
Block a user