mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-05-01 12:30:39 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e298daeef9 | |||
| d9e6f67a6e | |||
| f036c7fa96 | |||
| e33665e716 | |||
| c955a614ca | |||
| f19065261e | |||
| 3e349e92e1 | |||
| a4ce24a418 | |||
| 960ad1531d | |||
| 137f49d1d1 | |||
| 083a92e13d | |||
| 67683435e8 | |||
| f32b29db4f | |||
| 10f49fe64b | |||
| d257917748 | |||
| fec078c04c | |||
| a92393dd51 | |||
| 7e76698490 | |||
| c7816973a6 |
@@ -10,10 +10,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.23'
|
||||
- name: Checkout obitools4 project
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
- name: Run tests
|
||||
run: make githubtests
|
||||
|
||||
@@ -18,7 +18,7 @@ jobs:
|
||||
with:
|
||||
go-version: "1.26"
|
||||
- name: Checkout obitools4 project
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
- name: Run tests
|
||||
run: make githubtests
|
||||
|
||||
@@ -49,7 +49,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
@@ -107,7 +107,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ require (
|
||||
github.com/DavidGamba/go-getoptions v0.33.0
|
||||
github.com/PaesslerAG/gval v1.2.4
|
||||
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df
|
||||
github.com/buger/jsonparser v1.1.1
|
||||
github.com/buger/jsonparser v1.1.2
|
||||
github.com/chen3feng/stl4go v0.1.1
|
||||
github.com/dlclark/regexp2 v1.11.5
|
||||
github.com/goccy/go-json v0.10.6
|
||||
|
||||
@@ -6,8 +6,8 @@ github.com/PaesslerAG/jsonpath v0.1.0 h1:gADYeifvlqK3R3i2cR5B4DGgxLXIPb3TRTH1mGi
|
||||
github.com/PaesslerAG/jsonpath v0.1.0/go.mod h1:4BzmtoM/PI8fPO4aQGIusjGxGir2BzcV0grWtFzq1Y8=
|
||||
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df h1:GSoSVRLoBaFpOOds6QyY1L8AX7uoY+Ln3BHc22W40X0=
|
||||
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df/go.mod h1:hiVxq5OP2bUGBRNS3Z/bt/reCLFNbdcST6gISi1fiOM=
|
||||
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
|
||||
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
|
||||
github.com/buger/jsonparser v1.1.2 h1:frqHqw7otoVbk5M8LlE/L7HTnIq2v9RX6EJ48i9AxJk=
|
||||
github.com/buger/jsonparser v1.1.2/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
|
||||
github.com/chen3feng/stl4go v0.1.1 h1:0L1+mDw7pomftKDruM23f1mA7miavOj6C6MZeadzN2Q=
|
||||
github.com/chen3feng/stl4go v0.1.1/go.mod h1:5ml3psLgETJjRJnMbPE+JiHLrCpt+Ajc2weeTECXzWU=
|
||||
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
|
||||
|
||||
@@ -47,7 +47,7 @@ func Encode4mer(seq *obiseq.BioSequence, buffer *[]byte) []byte {
|
||||
length := slength - 3
|
||||
rawseq := seq.Sequence()
|
||||
|
||||
if length < 0 {
|
||||
if length <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+90
-7
@@ -91,7 +91,7 @@ func LuaWorker(proto *lua.FunctionProto) obiseq.SeqWorker {
|
||||
err := interpreter.PCall(0, lua.MultRet, nil)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error in executing the lua script")
|
||||
log.Fatalf("Error in executing the lua script: %v", err)
|
||||
}
|
||||
|
||||
result := interpreter.GetGlobal("worker")
|
||||
@@ -141,6 +141,69 @@ func LuaWorker(proto *lua.FunctionProto) obiseq.SeqWorker {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LuaSliceWorker creates a SeqSliceWorker that calls the Lua function
|
||||
// named "slice_worker". Unlike LuaWorker, the entire batch (BioSequenceSlice)
|
||||
// is passed to the Lua function at once, enabling batch-level processing
|
||||
// (e.g. a single HTTP request per batch instead of one per sequence).
|
||||
//
|
||||
// The Lua function signature:
|
||||
//
|
||||
// function slice_worker(slice) -- receives a BioSequenceSlice
|
||||
// -- process the batch
|
||||
// return slice -- returns a BioSequenceSlice (or nil)
|
||||
// end
|
||||
func LuaSliceWorker(proto *lua.FunctionProto) obiseq.SeqSliceWorker {
|
||||
interpreter := NewInterpreter()
|
||||
lfunc := interpreter.NewFunctionFromProto(proto)
|
||||
interpreter.Push(lfunc)
|
||||
err := interpreter.PCall(0, lua.MultRet, nil)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error in executing the lua script: %v", err)
|
||||
}
|
||||
|
||||
result := interpreter.GetGlobal("slice_worker")
|
||||
|
||||
if lua_worker, ok := result.(*lua.LFunction); ok {
|
||||
f := func(slice obiseq.BioSequenceSlice) (obiseq.BioSequenceSlice, error) {
|
||||
if err := interpreter.CallByParam(lua.P{
|
||||
Fn: lua_worker,
|
||||
NRet: 1,
|
||||
Protect: true,
|
||||
}, obiseqslice2Lua(interpreter, &slice)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
lreponse := interpreter.Get(-1)
|
||||
defer interpreter.Pop(1)
|
||||
|
||||
if reponse, ok := lreponse.(*lua.LUserData); ok {
|
||||
s := reponse.Value
|
||||
switch val := s.(type) {
|
||||
case *obiseq.BioSequenceSlice:
|
||||
return *val, nil
|
||||
case *obiseq.BioSequence:
|
||||
return obiseq.BioSequenceSlice{val}, nil
|
||||
default:
|
||||
r := reflect.TypeOf(val)
|
||||
return nil, fmt.Errorf("slice_worker function doesn't return the correct type %s", r)
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok = lreponse.(*lua.LNilType); ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("slice_worker function doesn't return the correct type %T", lreponse)
|
||||
}
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
log.Fatalf("The slice_worker object is not a function")
|
||||
return nil
|
||||
}
|
||||
|
||||
// LuaProcessor processes a Lua script on a sequence iterator and returns a new iterator.
|
||||
//
|
||||
// Parameters:
|
||||
@@ -173,7 +236,7 @@ func LuaProcessor(iterator obiiter.IBioSequence, name, program string, breakOnEr
|
||||
err = interpreter.PCall(0, lua.MultRet, nil)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error in executing the lua script")
|
||||
log.Fatalf("Error in executing the lua script: %v", err)
|
||||
}
|
||||
|
||||
result := interpreter.GetGlobal("begin")
|
||||
@@ -198,7 +261,7 @@ func LuaProcessor(iterator obiiter.IBioSequence, name, program string, breakOnEr
|
||||
err = interpreter.PCall(0, lua.MultRet, nil)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error in executing the lua script")
|
||||
log.Fatalf("Error in executing the lua script: %v", err)
|
||||
}
|
||||
|
||||
result := interpreter.GetGlobal("finish")
|
||||
@@ -216,11 +279,27 @@ func LuaProcessor(iterator obiiter.IBioSequence, name, program string, breakOnEr
|
||||
|
||||
}()
|
||||
|
||||
ff := func(iterator obiiter.IBioSequence) {
|
||||
w := LuaWorker(proto)
|
||||
sw := obiseq.SeqToSliceWorker(w, false)
|
||||
// Detect whether the script defines slice_worker (batch-level) or worker (per-sequence).
|
||||
hasSliceWorker := func() bool {
|
||||
interpreter := NewInterpreter()
|
||||
lfunc := interpreter.NewFunctionFromProto(proto)
|
||||
interpreter.Push(lfunc)
|
||||
if err := interpreter.PCall(0, lua.MultRet, nil); err != nil {
|
||||
return false
|
||||
}
|
||||
result := interpreter.GetGlobal("slice_worker")
|
||||
interpreter.Close()
|
||||
_, ok := result.(*lua.LFunction)
|
||||
return ok
|
||||
}()
|
||||
|
||||
// iterator = iterator.SortBatches()
|
||||
ff := func(iterator obiiter.IBioSequence) {
|
||||
var sw obiseq.SeqSliceWorker
|
||||
if hasSliceWorker {
|
||||
sw = LuaSliceWorker(proto)
|
||||
} else {
|
||||
sw = obiseq.SeqToSliceWorker(LuaWorker(proto), false)
|
||||
}
|
||||
|
||||
for iterator.Next() {
|
||||
seqs := iterator.Get()
|
||||
@@ -235,6 +314,10 @@ func LuaProcessor(iterator obiiter.IBioSequence, name, program string, breakOnEr
|
||||
}
|
||||
}
|
||||
|
||||
if ns == nil {
|
||||
ns = obiseq.BioSequenceSlice{}
|
||||
}
|
||||
|
||||
newIter.Push(obiiter.MakeBioSequenceBatch(seqs.Source(), seqs.Order(), ns))
|
||||
}
|
||||
|
||||
|
||||
+23
-4
@@ -4,18 +4,37 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
const httpClientTimeout = 30 * time.Second
|
||||
|
||||
var _httpClient = &http.Client{
|
||||
Timeout: httpClientTimeout,
|
||||
var (
|
||||
_httpClient *http.Client
|
||||
_httpClientOnce sync.Once
|
||||
)
|
||||
|
||||
func getHTTPClient() *http.Client {
|
||||
_httpClientOnce.Do(func() {
|
||||
conns := 2 * obidefault.ParallelWorkers()
|
||||
_httpClient = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
MaxIdleConnsPerHost: conns,
|
||||
MaxConnsPerHost: conns,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
},
|
||||
Timeout: httpClientTimeout,
|
||||
}
|
||||
})
|
||||
return _httpClient
|
||||
}
|
||||
|
||||
// RegisterHTTP registers the http module in the Lua state.
|
||||
// RegisterHTTP registers the http module in the Lua state as a global,
|
||||
// consistent with obicontext and BioSequence.
|
||||
//
|
||||
// Exposes:
|
||||
//
|
||||
@@ -45,7 +64,7 @@ func luaHTTPPost(L *lua.LState) int {
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := _httpClient.Do(req)
|
||||
resp, err := getHTTPClient().Do(req)
|
||||
if err != nil {
|
||||
L.Push(lua.LNil)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
|
||||
@@ -3,7 +3,7 @@ package obioptions
|
||||
// Version is automatically updated by the Makefile from version.txt
|
||||
// The patch number (third digit) is incremented on each push to the repository
|
||||
|
||||
var _Version = "Release 4.4.31"
|
||||
var _Version = "Release 4.4.37"
|
||||
|
||||
// Version returns the version of the obitools package.
|
||||
//
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
4.4.31
|
||||
4.4.37
|
||||
|
||||
Reference in New Issue
Block a user