mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Refactoring codes for removing buffer size options. An some other changes...
Former-commit-id: 10b57cc1a27446ade3c444217341e9651e89cdce
This commit is contained in:
192
pkg/obiseq/language.go
Normal file
192
pkg/obiseq/language.go
Normal file
@ -0,0 +1,192 @@
|
||||
package obiseq
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
|
||||
"github.com/PaesslerAG/gval"
|
||||
)
|
||||
|
||||
func maxIntVector(values []int) float64 {
|
||||
m := values[0]
|
||||
for _, v := range values {
|
||||
if v > m {
|
||||
m = v
|
||||
}
|
||||
}
|
||||
|
||||
return float64(m)
|
||||
}
|
||||
|
||||
func maxIntMap(values map[string]int) float64 {
|
||||
var m int
|
||||
first := true
|
||||
for _, v := range values {
|
||||
if first {
|
||||
first = false
|
||||
m = v
|
||||
} else {
|
||||
if v > m {
|
||||
m = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return float64(m)
|
||||
}
|
||||
|
||||
func minIntVector(values []int) float64 {
|
||||
m := values[0]
|
||||
for _, v := range values {
|
||||
if v < m {
|
||||
m = v
|
||||
}
|
||||
}
|
||||
|
||||
return float64(m)
|
||||
}
|
||||
|
||||
func minIntMap(values map[string]int) float64 {
|
||||
var m int
|
||||
first := true
|
||||
for _, v := range values {
|
||||
if first {
|
||||
first = false
|
||||
m = v
|
||||
} else {
|
||||
if v < m {
|
||||
m = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return float64(m)
|
||||
}
|
||||
|
||||
func maxFloatVector(values []float64) float64 {
|
||||
m := values[0]
|
||||
for _, v := range values {
|
||||
if v > m {
|
||||
m = v
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func maxFloatMap(values map[string]float64) float64 {
|
||||
var m float64
|
||||
first := true
|
||||
for _, v := range values {
|
||||
if first {
|
||||
first = false
|
||||
m = v
|
||||
} else {
|
||||
if v > m {
|
||||
m = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func minFloatVector(values []float64) float64 {
|
||||
m := values[0]
|
||||
for _, v := range values {
|
||||
if v < m {
|
||||
m = v
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func minFloatMap(values map[string]float64) float64 {
|
||||
var m float64
|
||||
first := true
|
||||
for _, v := range values {
|
||||
if first {
|
||||
first = false
|
||||
m = v
|
||||
} else {
|
||||
if v < m {
|
||||
m = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// func maxNumeric(args ...interface{}) (interface{}, error) {
|
||||
// var m float64
|
||||
// first := true
|
||||
|
||||
// for _, v := range args {
|
||||
// switch {
|
||||
// case
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
var OBILang = gval.NewLanguage(
|
||||
gval.Full(),
|
||||
gval.Function("len", func(args ...interface{}) (interface{}, error) {
|
||||
length := goutils.Len(args[0])
|
||||
return (float64)(length), nil
|
||||
}),
|
||||
gval.Function("ismap", func(args ...interface{}) (interface{}, error) {
|
||||
ismap := goutils.IsAMap(args[0])
|
||||
return ismap, nil
|
||||
}),
|
||||
gval.Function("printf", func(args ...interface{}) (interface{}, error) {
|
||||
text := fmt.Sprintf(args[0].(string), args[1:]...)
|
||||
return text, nil
|
||||
}),
|
||||
gval.Function("subspc", func(args ...interface{}) (interface{}, error) {
|
||||
text := strings.ReplaceAll(args[0].(string), " ", "_")
|
||||
return text, nil
|
||||
}),
|
||||
gval.Function("int", func(args ...interface{}) (interface{}, error) {
|
||||
val, err := goutils.InterfaceToInt(args[0])
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("%v cannot be converted to an integer value", args[0])
|
||||
}
|
||||
return val, nil
|
||||
}),
|
||||
gval.Function("numeric", func(args ...interface{}) (interface{}, error) {
|
||||
val, err := goutils.InterfaceToFloat64(args[0])
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("%v cannot be converted to a numeric value", args[0])
|
||||
}
|
||||
return val, nil
|
||||
}),
|
||||
gval.Function("bool", func(args ...interface{}) (interface{}, error) {
|
||||
val, err := goutils.InterfaceToBool(args[0])
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("%v cannot be converted to a boolan value", args[0])
|
||||
}
|
||||
return val, nil
|
||||
}),
|
||||
gval.Function("ifelse", func(args ...interface{}) (interface{}, error) {
|
||||
if args[0].(bool) {
|
||||
return args[1], nil
|
||||
} else {
|
||||
return args[2], nil
|
||||
}
|
||||
}),
|
||||
gval.Function("gcskew", func(args ...interface{}) (interface{}, error) {
|
||||
composition := (args[0].(*BioSequence)).Composition()
|
||||
return float64(composition['g']-composition['c']) / float64(composition['g']+composition['c']), nil
|
||||
}),
|
||||
gval.Function("composition", func(args ...interface{}) (interface{}, error) {
|
||||
return (args[0].(*BioSequence)).Composition(), nil
|
||||
}))
|
||||
|
Reference in New Issue
Block a user