From 8b70b1a5d8c245e981b8c00df81022ef5c422c51 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Wed, 8 Feb 2023 13:56:50 +0100 Subject: [PATCH] Last bug on sequence writing --- pkg/obiformats/fastseq_write_fasta.go | 5 +++++ pkg/obiformats/fastseq_write_fastq.go | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/obiformats/fastseq_write_fasta.go b/pkg/obiformats/fastseq_write_fasta.go index 404c03a..4db2ef7 100644 --- a/pkg/obiformats/fastseq_write_fasta.go +++ b/pkg/obiformats/fastseq_write_fasta.go @@ -6,6 +6,7 @@ import ( "io" "os" "strings" + "sync" "time" log "github.com/sirupsen/logrus" @@ -78,6 +79,7 @@ func WriteFasta(iterator obiiter.IBioSequence, header_format := opt.FormatFastSeqHeader() newIter.Add(nwriters) + var waitWriter sync.WaitGroup go func() { newIter.WaitAndClose() @@ -85,6 +87,7 @@ func WriteFasta(iterator obiiter.IBioSequence, time.Sleep(time.Millisecond) } close(chunkchan) + waitWriter.Wait() obiiter.UnregisterPipe() log.Debugln("End of the fasta file writing") }() @@ -112,6 +115,7 @@ func WriteFasta(iterator obiiter.IBioSequence, next_to_send := 0 received := make(map[int]FileChunck, 100) + waitWriter.Add(1) go func() { for chunk := range chunkchan { if chunk.order == next_to_send { @@ -136,6 +140,7 @@ func WriteFasta(iterator obiiter.IBioSequence, file.Close() } } + waitWriter.Done() }() diff --git a/pkg/obiformats/fastseq_write_fastq.go b/pkg/obiformats/fastseq_write_fastq.go index 9f37aff..403fe6a 100644 --- a/pkg/obiformats/fastseq_write_fastq.go +++ b/pkg/obiformats/fastseq_write_fastq.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "os" + "sync" "time" log "github.com/sirupsen/logrus" @@ -69,12 +70,15 @@ func WriteFastq(iterator obiiter.IBioSequence, newIter.Add(nwriters) + var waitWriter sync.WaitGroup + go func() { newIter.WaitAndClose() for len(chunkchan) > 0 { time.Sleep(time.Millisecond) } close(chunkchan) + waitWriter.Wait() obiiter.UnregisterPipe() log.Debugln("End of the fastq file writing") }() @@ -101,6 +105,7 @@ func WriteFastq(iterator obiiter.IBioSequence, next_to_send := 0 received := make(map[int]FileChunck, 100) + waitWriter.Add(1) go func() { for chunk := range chunkchan { if chunk.order == next_to_send { @@ -125,6 +130,8 @@ func WriteFastq(iterator obiiter.IBioSequence, file.Close() } } + + waitWriter.Done() }() return newIter, nil