first preliminary version of obiscript.

Former-commit-id: 0d2c0fc5e33e0873ba5c04aca4cf7dd69aa83c90
This commit is contained in:
2024-03-06 12:56:44 -03:00
parent b4afd784dc
commit b40015deb7
10 changed files with 739 additions and 4 deletions

View File

@@ -0,0 +1,14 @@
package obiscript
import (
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilua"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obioptions"
)
func CLIScriptPipeline() obiiter.Pipeable {
pipe := obilua.LuaScriptPipe(CLIScriptFilename(), true, obioptions.CLIParallelWorkers())
return pipe
}

View File

@@ -0,0 +1,83 @@
package obiscript
import (
"log"
"os"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitools/obiconvert"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitools/obigrep"
"github.com/DavidGamba/go-getoptions"
)
var _script = ""
var _askTemplate = false
func ScriptOptionSet(options *getoptions.GetOpt) {
options.StringVar(&_script, "script", _script,
options.Description("The script to execute."),
options.Alias("S"),
options.Description("Name of a map attribute."))
options.BoolVar(&_askTemplate, "template", _askTemplate,
options.Description("Print on the standard output a script template."),
)
}
func OptionSet(options *getoptions.GetOpt) {
ScriptOptionSet(options)
obiconvert.OptionSet(options)
obigrep.SequenceSelectionOptionSet(options)
}
func CLIScriptFilename() string {
return _script
}
func CLIScript() string {
file, err := os.ReadFile(_script) // Reads the script
if err != nil {
log.Fatalf("cannot read the script file : %s", _script)
}
return string(file)
}
func CLIAskScriptTemplate() bool {
return _askTemplate
}
func CLIScriptTemplate() string {
return `
import {
"sync"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiseq"
}
//
// Begin function run before the first sequence being processed
//
func Begin(environment *sync.Map) {
}
//
// Begin function run after the last sequence being processed
//
func End(environment *sync.Map) {
}
//
// Worker function run for each sequence validating the selection predicat as specified by
// the command line options.
//
// The function must return the altered sequence.
// If the function returns nil, the sequence is discarded from the output
func Worker(sequence *obiseq.BioSequence, environment *sync.Map) *obiseq.BioSequence {
return sequence
}
`
}