mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 16:50:27 +00:00
Add some options to obiannotate
This commit is contained in:
62
pkg/obiseq/eval.go
Normal file
62
pkg/obiseq/eval.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package obiseq
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obieval"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Expression(expression string) func(*BioSequence) (interface{},error) {
|
||||
|
||||
exp, err := obieval.OBILang.NewEvaluable(expression)
|
||||
if err != nil {
|
||||
log.Fatalf("Error in the expression : %s", expression)
|
||||
}
|
||||
|
||||
f := func(sequence *BioSequence) (interface{},error) {
|
||||
return exp(context.Background(),
|
||||
map[string]interface{}{
|
||||
"annotations": sequence.Annotations(),
|
||||
"sequence": sequence,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func EditIdWorker(expression string) SeqWorker {
|
||||
e := Expression(expression)
|
||||
f := func(sequence *BioSequence) *BioSequence {
|
||||
v,err := e(sequence)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Expression '%s' cannot be evaluated on sequence %s",
|
||||
expression,
|
||||
sequence.Id())
|
||||
}
|
||||
sequence.SetId(fmt.Sprintf("%v",v))
|
||||
return sequence
|
||||
}
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func EditAttributeWorker(key string, expression string) SeqWorker {
|
||||
e := Expression(expression)
|
||||
f := func(sequence *BioSequence) *BioSequence {
|
||||
v,err := e(sequence)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Expression '%s' cannot be evaluated on sequence %s",
|
||||
expression,
|
||||
sequence.Id())
|
||||
}
|
||||
sequence.SetAttribute(key,v)
|
||||
return sequence
|
||||
}
|
||||
|
||||
return f
|
||||
}
|
||||
Reference in New Issue
Block a user