mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-10 01:30:27 +00:00
Changes to be committed:
modified: go.mod modified: go.sum modified: pkg/obilua/obilib.go modified: pkg/obilua/obiseq.go modified: pkg/obilua/obiseqslice.go new file: pkg/obilua/obitaxon.go new file: pkg/obilua/obitaxonomy.go modified: pkg/obioptions/version.go
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package obilua
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiformats"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiseq"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
@@ -11,6 +14,7 @@ func registerBioSequenceSliceType(luaState *lua.LState) {
|
||||
bioSequenceSliceType := luaState.NewTypeMetatable(luaBioSequenceSliceTypeName)
|
||||
luaState.SetGlobal(luaBioSequenceSliceTypeName, bioSequenceSliceType)
|
||||
luaState.SetField(bioSequenceSliceType, "new", luaState.NewFunction(newObiSeqSlice))
|
||||
luaState.SetField(bioSequenceSliceType, "nil", obiseqslice2Lua(luaState, nil))
|
||||
|
||||
luaState.SetField(bioSequenceSliceType, "__index",
|
||||
luaState.SetFuncs(luaState.NewTable(),
|
||||
@@ -37,6 +41,9 @@ var bioSequenceSliceMethods = map[string]lua.LGFunction{
|
||||
"pop": bioSequenceSlicePop,
|
||||
"sequence": bioSequenceSliceGetSetSequence,
|
||||
"len": bioSequenceSliceGetLength,
|
||||
"fasta": bioSequenceSliceGetFasta,
|
||||
"fastq": bioSequenceSliceGetFastq,
|
||||
"string": bioSequenceSliceAsString,
|
||||
}
|
||||
|
||||
func checkBioSequenceSlice(L *lua.LState) *obiseq.BioSequenceSlice {
|
||||
@@ -105,3 +112,96 @@ func bioSequenceSlicePop(luaState *lua.LState) int {
|
||||
return 1
|
||||
|
||||
}
|
||||
|
||||
func bioSequenceSliceGetFasta(luaState *lua.LState) int {
|
||||
s := checkBioSequenceSlice(luaState)
|
||||
|
||||
formater := obiformats.FormatFastSeqJsonHeader
|
||||
|
||||
if luaState.GetTop() > 1 {
|
||||
format := luaState.CheckString(2)
|
||||
switch format {
|
||||
case "json":
|
||||
formater = obiformats.FormatFastSeqJsonHeader
|
||||
case "obi":
|
||||
formater = obiformats.FormatFastSeqOBIHeader
|
||||
}
|
||||
}
|
||||
|
||||
txts := make([]string, len(*s))
|
||||
|
||||
for i, seq := range *s {
|
||||
txts[i] = obiformats.FormatFasta(seq, formater)
|
||||
}
|
||||
|
||||
txt := strings.Join(txts, "\n")
|
||||
|
||||
luaState.Push(lua.LString(txt))
|
||||
return 1
|
||||
}
|
||||
|
||||
func bioSequenceSliceGetFastq(luaState *lua.LState) int {
|
||||
s := checkBioSequenceSlice(luaState)
|
||||
|
||||
formater := obiformats.FormatFastSeqJsonHeader
|
||||
|
||||
if luaState.GetTop() > 1 {
|
||||
format := luaState.CheckString(2)
|
||||
switch format {
|
||||
case "json":
|
||||
formater = obiformats.FormatFastSeqJsonHeader
|
||||
case "obi":
|
||||
formater = obiformats.FormatFastSeqOBIHeader
|
||||
}
|
||||
}
|
||||
|
||||
txts := make([]string, len(*s))
|
||||
|
||||
for i, seq := range *s {
|
||||
txts[i] = obiformats.FormatFastq(seq, formater)
|
||||
}
|
||||
|
||||
txt := strings.Join(txts, "\n")
|
||||
|
||||
luaState.Push(lua.LString(txt))
|
||||
return 1
|
||||
}
|
||||
|
||||
func bioSequenceSliceAsString(luaState *lua.LState) int {
|
||||
s := checkBioSequenceSlice(luaState)
|
||||
|
||||
formater := obiformats.FormatFastSeqJsonHeader
|
||||
|
||||
if luaState.GetTop() > 1 {
|
||||
format := luaState.CheckString(2)
|
||||
switch format {
|
||||
case "json":
|
||||
formater = obiformats.FormatFastSeqJsonHeader
|
||||
case "obi":
|
||||
formater = obiformats.FormatFastSeqOBIHeader
|
||||
}
|
||||
}
|
||||
|
||||
txts := make([]string, len(*s))
|
||||
|
||||
format := obiformats.FormatFasta
|
||||
|
||||
allQual := true
|
||||
|
||||
for _, s := range *s {
|
||||
allQual = allQual && s.HasQualities()
|
||||
}
|
||||
|
||||
if allQual {
|
||||
format = obiformats.FormatFastq
|
||||
}
|
||||
|
||||
for i, seq := range *s {
|
||||
txts[i] = format(seq, formater)
|
||||
}
|
||||
|
||||
txt := strings.Join(txts, "\n")
|
||||
|
||||
luaState.Push(lua.LString(txt))
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user