small code refactoring

This commit is contained in:
2022-08-23 15:08:35 +02:00
parent d2f4919bc8
commit d04161a0fb
2 changed files with 7 additions and 17 deletions

View File

@ -8,6 +8,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"github.com/tevino/abool/v2" "github.com/tevino/abool/v2"
) )
@ -37,7 +38,7 @@ type IBioSequenceBatch struct {
var NilIBioSequenceBatch = IBioSequenceBatch{pointer: nil} var NilIBioSequenceBatch = IBioSequenceBatch{pointer: nil}
func MakeIBioSequenceBatch(sizes ...int) IBioSequenceBatch { func MakeIBioSequenceBatch(sizes ...int) IBioSequenceBatch {
buffsize := int32(1) buffsize := int32(0)
if len(sizes) > 0 { if len(sizes) > 0 {
buffsize = int32(sizes[0]) buffsize = int32(sizes[0])
@ -215,7 +216,7 @@ func (iterator IBioSequenceBatch) Get() BioSequenceBatch {
func (iterator IBioSequenceBatch) Push(batch BioSequenceBatch) { func (iterator IBioSequenceBatch) Push(batch BioSequenceBatch) {
if batch.IsNil() { 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 { if batch.Length() == 0 {
log.Panicln("An empty batch is pushed on the channel") log.Panicln("An empty batch is pushed on the channel")
@ -369,18 +370,7 @@ func (iterator IBioSequenceBatch) Pool(iterators ...IBioSequenceBatch) IBioSeque
return iterator return iterator
} }
counterMutex := sync.Mutex{} nextCounter := goutils.AtomicCounter()
counter := 0
nextCounter := func() int {
counterMutex.Lock()
defer counterMutex.Unlock()
counter++
return counter
}
buffsize := iterator.BufferSize() buffsize := iterator.BufferSize()
newIter := MakeIBioSequenceBatch(buffsize) newIter := MakeIBioSequenceBatch(buffsize)

View File

@ -13,7 +13,7 @@ func DistributeSequence(sequences obiiter.IBioSequenceBatch) {
opts := make([]obiformats.WithOption, 0, 10) opts := make([]obiformats.WithOption, 0, 10)
switch obiconvert.OutputFastHeaderFormat() { switch obiconvert.CLIOutputFastHeaderFormat() {
case "json": case "json":
log.Println("On output use JSON headers") log.Println("On output use JSON headers")
opts = append(opts, obiformats.OptionsFastSeqHeaderFormat(obiformats.FormatFastSeqJsonHeader)) 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.OptionsBufferSize(obioptions.CLIBufferSize()))
opts = append(opts, obiformats.OptionsBatchSize(obioptions.CLIBatchSize())) 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 var formater obiformats.SequenceBatchWriterToFile
switch obiconvert.OutputFormat() { switch obiconvert.CLIOutputFormat() {
case "fastq": case "fastq":
formater = obiformats.WriteFastqBatchToFile formater = obiformats.WriteFastqBatchToFile
case "fasta": case "fasta":