patch a bug in obiannotate

This commit is contained in:
Eric Coissac
2025-03-11 16:35:38 +01:00
parent 50d11ce374
commit 3b5d4ba455
3 changed files with 41 additions and 1 deletions

View File

@ -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 {

View File

@ -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.

View File

@ -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++
}
}