2022-02-14 00:01:01 +01:00
|
|
|
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() {
|
|
|
|
for newflux := range dispatcher.News() {
|
2022-02-15 00:47:02 +01:00
|
|
|
jobDone.Add(1)
|
2022-02-18 22:53:09 +01:00
|
|
|
go func(newflux int) {
|
2022-02-15 00:47:02 +01:00
|
|
|
data, err := dispatcher.Outputs(newflux)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Cannot retreive the new chanel : %v", err)
|
|
|
|
}
|
|
|
|
|
2022-02-14 09:12:57 +01:00
|
|
|
out, err := formater(data,
|
2022-02-21 19:00:23 +01:00
|
|
|
fmt.Sprintf(prototypename, dispatcher.Classifier().Value(newflux)),
|
2022-02-14 09:12:57 +01:00
|
|
|
options...)
|
2022-02-15 00:47:02 +01:00
|
|
|
|
2022-02-14 09:12:57 +01:00
|
|
|
if err != nil {
|
2022-02-21 19:00:23 +01:00
|
|
|
log.Fatalf("cannot open the output file for key %s",
|
|
|
|
dispatcher.Classifier().Value(newflux))
|
2022-02-14 09:12:57 +01:00
|
|
|
}
|
|
|
|
|
2022-02-14 00:01:01 +01:00
|
|
|
out.Recycle()
|
|
|
|
jobDone.Done()
|
2022-02-14 09:12:57 +01:00
|
|
|
}(newflux)
|
2022-02-14 00:01:01 +01:00
|
|
|
}
|
2022-02-15 00:47:02 +01:00
|
|
|
jobDone.Done()
|
2022-02-14 00:01:01 +01:00
|
|
|
}()
|
|
|
|
|
|
|
|
jobDone.Wait()
|
|
|
|
}
|