From 3b5d4ba4555cfad09fad4cfcbda48ca0f23b750d Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Tue, 11 Mar 2025 16:35:38 +0100 Subject: [PATCH] patch a bug in obiannotate --- pkg/obiiter/workers.go | 5 +++++ pkg/obioptions/version.go | 2 +- pkg/obiseq/worker.go | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/pkg/obiiter/workers.go b/pkg/obiiter/workers.go index 6320737..ca9465c 100644 --- a/pkg/obiiter/workers.go +++ b/pkg/obiiter/workers.go @@ -63,6 +63,11 @@ func (iterator IBioSequence) MakeIConditionalWorker(predicate obiseq.SequencePre // // The function returns a new IBioSequence containing the modified slices. func (iterator IBioSequence) MakeISliceWorker(worker obiseq.SeqSliceWorker, breakOnError bool, sizes ...int) IBioSequence { + + if worker == nil { + return iterator + } + nworkers := obidefault.ParallelWorkers() if len(sizes) > 0 { diff --git a/pkg/obioptions/version.go b/pkg/obioptions/version.go index 4fab2a9..6d67e4b 100644 --- a/pkg/obioptions/version.go +++ b/pkg/obioptions/version.go @@ -8,7 +8,7 @@ import ( // corresponds to the last commit, and not the one when the file will be // commited -var _Commit = "52d5f6f" +var _Commit = "50d11ce" var _Version = "Release 4.4.0" // Version returns the version of the obitools package. diff --git a/pkg/obiseq/worker.go b/pkg/obiseq/worker.go index fcafd22..4c0c04a 100644 --- a/pkg/obiseq/worker.go +++ b/pkg/obiseq/worker.go @@ -133,6 +133,34 @@ func SeqToSliceWorker(worker SeqWorker, return f } +func SeqToSliceFilterOnWorker(condition SequencePredicate, + breakOnError bool) SeqSliceWorker { + + if condition == nil { + return func(slice BioSequenceSlice) (BioSequenceSlice, error) { + return slice, nil + } + } + + f := func(input BioSequenceSlice) (BioSequenceSlice, error) { + output := MakeBioSequenceSlice(len(input)) + + i := 0 + + for _, s := range input { + if condition(s) { + output[i] = s + i++ + } + } + + return output[0:i], nil + } + + return f + +} + // SeqToSliceConditionalWorker creates a new SeqSliceWorker that processes each sequence in a slice based on a condition. It takes a SequencePredicate and a worker function as arguments. The worker function is only applied to sequences that satisfy the condition. // If `condition` is nil, this function just behaves like SeqToSliceWorker with the provided `worker`. // If `breakOnError` is true, the pipeline will stop and return an error if any sequence processing fails. Otherwise, it will log a warning message for each failed sequence. @@ -153,6 +181,10 @@ func SeqToSliceConditionalWorker( return SeqToSliceWorker(worker, breakOnError) } + if worker == nil { + return nil + } + f := func(input BioSequenceSlice) (BioSequenceSlice, error) { output := MakeBioSequenceSlice(len(input)) @@ -180,6 +212,9 @@ func SeqToSliceConditionalWorker( s.Id(), err) } } + } else { + output[i] = s + i++ } }