// 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) }
// AnnotateOne annotates a single variant with the vals func (s *Source) AnnotateOne(v interfaces.IVariant, vals []interface{}, prefix string) { if len(vals) == 0 { return } if s.code != "" { luaval := s.LuaOp(v, s.code, vals) if luaval == "true" || luaval == "false" && strings.Contains(s.Op, "_flag(") { if luaval == "true" { v.Info().Set(prefix+s.Name, true) } } else { v.Info().Set(prefix+s.Name, luaval) } } else { val := Reducers[s.Op](vals) v.Info().Set(prefix+s.Name, val) } }
func (src *Source) AnnotateOne(v interfaces.IVariant, vals []interface{}, prefix string) { if len(vals) == 0 { return } if src.Js != nil { jsval := src.JsOp(v, src.Js, vals) if jsval == "true" || jsval == "false" && strings.Contains(src.Op, "_flag(") { if jsval == "true" { v.Info().Set(prefix+src.Name, true) } } else { v.Info().Set(prefix+src.Name, jsval) } } else { val := Reducers[src.Op](vals) v.Info().Set(prefix+src.Name, val) } }
// 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 }
// 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) }