Compare commits

...

16 Commits

Author SHA1 Message Date
Eric Coissac e298daeef9 [v4.5] Bugfix for 3-base sequence handling and utility refactoring
- **Bug fix**: Corrected logic in 4-mer calculation to properly handle sequences of length exactly three. Previously, such cases could produce invalid or unexpected results due to an incomplete guard condition (`length < 0`) which failed for ` length == 3` (where computed step size was zero). The fix ensures all sequences shorter than four bases are safely excluded.

- **Refactor**: Introduced a new internal utility function (`inverser_chaine`) to centralize string reversal logic, improving code maintainability and test coverage without affecting user-facing behavior.
2026-04-13 17:18:53 +02:00
Eric Coissac d9e6f67a6e chore: bump version to 4.4.36
Update package and file versions from v4.4.35 to 4.4.36.
2026-04-13 17:18:48 +02:00
Eric Coissac f036c7fa96 ⬆️ version bump to v4.5
- Update `version.txt` from "v3" to v4.5
- Bump Go constant `_Version = 'Release 4.x.y'` accordingly
2026-04-13 17:18:34 +02:00
Eric Coissac e33665e716 Refactor: Extract utility function for string reversal
- Introduce `inverser_chaine()` helper to centralize logic
 - Update tests and documentation accordingly
2026-04-13 17:18:34 +02:00
Eric Coissac c955a614ca chore: bump version to 4.4.35
Update obioptions/version.go and version.txt to reflect release 4.4.35.
2026-04-13 17:18:34 +02:00
Eric Coissac f19065261e We kept 2026-04-13 17:18:34 +02:00
coissac 3e349e92e1 Merge pull request #104 from theo-krueger/master
Bugfix: result of 0 4mers not caught if sequence length == 3
2026-04-13 16:39:08 +02:00
coissac a4ce24a418 Merge pull request #108 from metabarcoding/push-qlxnulxwokxo
Push qlxnulxwokxo
2026-04-13 16:27:43 +02:00
Eric Coissac 960ad1531d [4.4.34] HTTP client thread-safety and CI infrastructure updates
- Improved concurrency safety by replacing the global HTTP client with a thread-safe, lazy-initialized instance using `sync.Once`. The new implementation enables connection pooling (`MaxIdleConnsPerHost`, connections per host) and dynamically configures pool size based on `obidefault.ParallelWorkers()`, ensuring robust behavior in multi-threaded Lua environments.
- Updated GitHub Actions workflows to the latest stable versions of `actions/setup-go` and ` actions/checkout`, improving build reliability.
- Removed outdated Go dependency checksums for buger/jsonparser v1.1.x to keep the build clean and consistent.
2026-04-13 16:27:14 +02:00
Eric Coissac 137f49d1d1 🔧 refactor(http): use thread-safe lazy-initialized HTTP client with connection pooling
- Replace global _httpClient variable by a sync.Once-based lazy initialization
- Add getHTTPClient() function to safely initialize client with connection pooling settings (MaxIdleConnsPerHost, Max Con ns/Conn per host)
- Set connection pool size based on obidefault.ParallelWorkers()

This ensures safe concurrent access and better resource management in multi-threaded Lua environments.
2026-04-13 16:27:09 +02:00
Eric Coissac 083a92e13d ⬆️ update GitHub Actions to latest versions
- Upgrade actions/setup-go from v2/v4 (depending on workflow) to latest stable version
- Update all actions/checkout from v3/v4 (depending on workflow) to latest stable version
- Clean up outdated go.sum entries for buger/jsonparser v1.1.x
2026-04-13 14:41:47 +02:00
coissac 67683435e8 Merge pull request #107 from metabarcoding/push-oyzynqqnturm
Push oyzynqqnturm
2026-04-13 14:29:44 +02:00
Eric Coissac f32b29db4f Release 4.4.33 2026-04-13 14:29:18 +02:00
Eric Coissac 10f49fe64b 📝 Clarify RegisterHTTP global registration intent
//
// Registers the http module in Lua state as a global,
// aligning with obicontext and BioSequence conventions.
The change ensures consistent module exposure across Lua environments.
2026-04-13 14:29:16 +02:00
coissac d257917748 Merge pull request #106 from metabarcoding/push-qoqotlnktvls
Push qoqotlnktvls
2026-04-13 14:08:42 +02:00
theo-krueger c7816973a6 Bugfix: result of 0 4mers not caught if sequence length == 3
In the 4mer calculation:
length := slength - 3

- for sequences with <4 bases, length is <=0

The check to stop did only catch <0, so sequences lengths 2 or less, leaving sequence lengths of 3 unguarded
if length < 0 {
		return nil
	}
2026-04-10 14:05:30 +02:00
8 changed files with 118 additions and 18 deletions
+2 -2
View File
@@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v2 uses: actions/setup-go@v5
with: with:
go-version: '1.23' go-version: '1.23'
- name: Checkout obitools4 project - name: Checkout obitools4 project
uses: actions/checkout@v4 uses: actions/checkout@v5
- name: Run tests - name: Run tests
run: make githubtests run: make githubtests
+3 -3
View File
@@ -18,7 +18,7 @@ jobs:
with: with:
go-version: "1.26" go-version: "1.26"
- name: Checkout obitools4 project - name: Checkout obitools4 project
uses: actions/checkout@v4 uses: actions/checkout@v5
- name: Run tests - name: Run tests
run: make githubtests run: make githubtests
@@ -49,7 +49,7 @@ jobs:
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v5
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
@@ -107,7 +107,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v5
with: with:
fetch-depth: 0 fetch-depth: 0
-2
View File
@@ -6,8 +6,6 @@ github.com/PaesslerAG/jsonpath v0.1.0 h1:gADYeifvlqK3R3i2cR5B4DGgxLXIPb3TRTH1mGi
github.com/PaesslerAG/jsonpath v0.1.0/go.mod h1:4BzmtoM/PI8fPO4aQGIusjGxGir2BzcV0grWtFzq1Y8= 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 h1:GSoSVRLoBaFpOOds6QyY1L8AX7uoY+Ln3BHc22W40X0=
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df/go.mod h1:hiVxq5OP2bUGBRNS3Z/bt/reCLFNbdcST6gISi1fiOM= 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 h1:frqHqw7otoVbk5M8LlE/L7HTnIq2v9RX6EJ48i9AxJk=
github.com/buger/jsonparser v1.1.2/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= 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 h1:0L1+mDw7pomftKDruM23f1mA7miavOj6C6MZeadzN2Q=
+1 -1
View File
@@ -47,7 +47,7 @@ func Encode4mer(seq *obiseq.BioSequence, buffer *[]byte) []byte {
length := slength - 3 length := slength - 3
rawseq := seq.Sequence() rawseq := seq.Sequence()
if length < 0 { if length <= 0 {
return nil return nil
} }
+87 -4
View File
@@ -141,6 +141,69 @@ func LuaWorker(proto *lua.FunctionProto) obiseq.SeqWorker {
return nil 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. // LuaProcessor processes a Lua script on a sequence iterator and returns a new iterator.
// //
// Parameters: // Parameters:
@@ -216,11 +279,27 @@ func LuaProcessor(iterator obiiter.IBioSequence, name, program string, breakOnEr
}() }()
ff := func(iterator obiiter.IBioSequence) { // Detect whether the script defines slice_worker (batch-level) or worker (per-sequence).
w := LuaWorker(proto) hasSliceWorker := func() bool {
sw := obiseq.SeqToSliceWorker(w, false) 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() { for iterator.Next() {
seqs := iterator.Get() 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)) newIter.Push(obiiter.MakeBioSequenceBatch(seqs.Source(), seqs.Order(), ns))
} }
+23 -4
View File
@@ -4,18 +4,37 @@ import (
"io" "io"
"net/http" "net/http"
"strings" "strings"
"sync"
"time" "time"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
lua "github.com/yuin/gopher-lua" lua "github.com/yuin/gopher-lua"
) )
const httpClientTimeout = 30 * time.Second const httpClientTimeout = 30 * time.Second
var _httpClient = &http.Client{ var (
Timeout: httpClientTimeout, _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: // Exposes:
// //
@@ -45,7 +64,7 @@ func luaHTTPPost(L *lua.LState) int {
} }
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
resp, err := _httpClient.Do(req) resp, err := getHTTPClient().Do(req)
if err != nil { if err != nil {
L.Push(lua.LNil) L.Push(lua.LNil)
L.Push(lua.LString(err.Error())) L.Push(lua.LString(err.Error()))
+1 -1
View File
@@ -3,7 +3,7 @@ package obioptions
// Version is automatically updated by the Makefile from version.txt // Version is automatically updated by the Makefile from version.txt
// The patch number (third digit) is incremented on each push to the repository // The patch number (third digit) is incremented on each push to the repository
var _Version = "Release 4.4.32" var _Version = "Release 4.4.37"
// Version returns the version of the obitools package. // Version returns the version of the obitools package.
// //
+1 -1
View File
@@ -1 +1 @@
4.4.32 4.4.37