mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Some code refactoring, a new version of obiuniq more efficient in memory and a first make file allowing to build obitools
This commit is contained in:
@ -1,5 +1,12 @@
|
||||
package obiseq
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/PaesslerAG/gval"
|
||||
)
|
||||
|
||||
type SequencePredicate func(*BioSequence) bool
|
||||
|
||||
func (predicate1 SequencePredicate) And(predicate2 SequencePredicate) SequencePredicate {
|
||||
@ -73,3 +80,33 @@ func IsShorterOrEqualTo(length int) SequencePredicate {
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func ExrpessionPredicat(expression string) SequencePredicate {
|
||||
|
||||
exp, err := gval.Full().NewEvaluable(expression)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error in the expression : %s", expression)
|
||||
}
|
||||
|
||||
f := func(sequence *BioSequence) bool {
|
||||
value, err := exp.EvalBool(context.Background(),
|
||||
map[string]interface{}{
|
||||
"annot": sequence.Annotations(),
|
||||
"count": sequence.Count(),
|
||||
"length": sequence.Length(),
|
||||
"sequence": sequence,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Expression '%s' cannot be evaluated on sequence %s",
|
||||
expression,
|
||||
sequence.Id())
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
return f
|
||||
}
|
||||
|
Reference in New Issue
Block a user