From d04161a0fb4bad7143e7271e7f635574eafdda1f Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Tue, 23 Aug 2022 15:08:35 +0200 Subject: [PATCH] small code refactoring --- pkg/obiiter/batchiterator.go | 18 ++++-------------- pkg/obitools/obidistribute/distribute.go | 6 +++--- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/pkg/obiiter/batchiterator.go b/pkg/obiiter/batchiterator.go index c1873e7..938a159 100644 --- a/pkg/obiiter/batchiterator.go +++ b/pkg/obiiter/batchiterator.go @@ -8,6 +8,7 @@ import ( log "github.com/sirupsen/logrus" + "git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "github.com/tevino/abool/v2" ) @@ -37,7 +38,7 @@ type IBioSequenceBatch struct { var NilIBioSequenceBatch = IBioSequenceBatch{pointer: nil} func MakeIBioSequenceBatch(sizes ...int) IBioSequenceBatch { - buffsize := int32(1) + buffsize := int32(0) if len(sizes) > 0 { buffsize = int32(sizes[0]) @@ -215,7 +216,7 @@ func (iterator IBioSequenceBatch) Get() BioSequenceBatch { func (iterator IBioSequenceBatch) Push(batch BioSequenceBatch) { if batch.IsNil() { - log.Panicln("An Nil batch is pushed on the channel") + log.Panicln("A Nil batch is pushed on the channel") } if batch.Length() == 0 { log.Panicln("An empty batch is pushed on the channel") @@ -369,18 +370,7 @@ func (iterator IBioSequenceBatch) Pool(iterators ...IBioSequenceBatch) IBioSeque return iterator } - counterMutex := sync.Mutex{} - counter := 0 - - nextCounter := func() int { - counterMutex.Lock() - defer counterMutex.Unlock() - - counter++ - - return counter - } - + nextCounter := goutils.AtomicCounter() buffsize := iterator.BufferSize() newIter := MakeIBioSequenceBatch(buffsize) diff --git a/pkg/obitools/obidistribute/distribute.go b/pkg/obitools/obidistribute/distribute.go index 0dacdf2..1eb1c94 100644 --- a/pkg/obitools/obidistribute/distribute.go +++ b/pkg/obitools/obidistribute/distribute.go @@ -13,7 +13,7 @@ func DistributeSequence(sequences obiiter.IBioSequenceBatch) { opts := make([]obiformats.WithOption, 0, 10) - switch obiconvert.OutputFastHeaderFormat() { + switch obiconvert.CLIOutputFastHeaderFormat() { case "json": log.Println("On output use JSON headers") opts = append(opts, obiformats.OptionsFastSeqHeaderFormat(obiformats.FormatFastSeqJsonHeader)) @@ -34,11 +34,11 @@ func DistributeSequence(sequences obiiter.IBioSequenceBatch) { opts = append(opts, obiformats.OptionsBufferSize(obioptions.CLIBufferSize())) opts = append(opts, obiformats.OptionsBatchSize(obioptions.CLIBatchSize())) - opts = append(opts, obiformats.OptionsQualityShift(obiconvert.OutputQualityShift())) + opts = append(opts, obiformats.OptionsQualityShift(obiconvert.CLIOutputQualityShift())) var formater obiformats.SequenceBatchWriterToFile - switch obiconvert.OutputFormat() { + switch obiconvert.CLIOutputFormat() { case "fastq": formater = obiformats.WriteFastqBatchToFile case "fasta":