Пример #1
0
// LuaOp uses go-lua to run a lua snippet on a list of values and return a single value.
// It makes the chrom, start, end, and values available to the lua interpreter.
func (s *Source) LuaOp(v interfaces.IVariant, code string, vals []interface{}) string {
	value, err := s.Vm.Run(code, map[string]interface{}{
		"chrom": v.Chrom(),
		"start": v.Start(),
		"stop":  v.End(),
		"vals":  vals})
	if err != nil {
		return fmt.Sprintf("lua-error: %s", err)
	}
	return fmt.Sprintf("%v", value)
}
Пример #2
0
// LuaOp uses go-lua to run a lua snippet on a list of values and return a single value.
// It makes the chrom, start, end, and values available to the lua interpreter.
func (s *Source) LuaOp(v interfaces.IVariant, code string, vals []interface{}) string {
	value, err := s.Vm.Run(code, map[string]interface{}{
		"chrom": v.Chrom(),
		"start": v.Start(),
		"stop":  v.End(),
		"ref":   v.Ref(),
		"alt":   v.Alt(),
		"vals":  vals})
	if err != nil {
		log.Printf("ERROR in at %s:%d. %s\nvals:%+v", v.Chrom(), v.Start()+1, err, vals)
		return fmt.Sprintf("err:%v", value)
	}
	return fmt.Sprintf("%v", value)
}
Пример #3
0
// JsOp uses Otto to run a javascript snippet on a list of values and return a single value.
// It makes the chrom, start, end, and values available to the js interpreter.
func (s *Source) JsOp(v interfaces.IVariant, js *otto.Script, vals []interface{}) string {
	s.mu.Lock()
	s.Vm.Set("chrom", v.Chrom())
	s.Vm.Set("start", v.Start())
	s.Vm.Set("end", v.End())
	s.Vm.Set("vals", vals)
	//s.Vm.Set("info", v.Info.String())
	value, err := s.Vm.Run(js)
	if err != nil {
		return fmt.Sprintf("js-error: %s", err)
	}
	val, err := value.ToString()
	s.mu.Unlock()
	if err != nil {
		log.Println("js-error:", err)
		val = fmt.Sprintf("error:%s", err)
	}
	return val
}