Lua is a scripting language. Its name means moon in Portuguese. Its purpose is to provide an interpreter that can be easily integrated into software to add scripting capabilities. OBITools provides the obiscript
command for this purpose. The obiscript
command allows a small script to be applied to each selected sequence in a sequence file. The Lua interpreter used by obiscript
is
GopherLua Version 1.1.1 which implements Lua version 5.1.
The aim of this section is not to be a full introduction to
Lua, but to show how to write a
Lua script that can be used with obiscript
. A full documentation of
Lua is available on the official website of the language (
https://www.lua.org/manual/5.1).
The structure of a Lua script for obiscript
#
📄 example.lua 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| function begin()
obicontext.item("compteur",0)
end
function worker(sequence)
samples = sequence:attribute("merged_sample")
samples["tutu"]=4
sequence:attribute("merged_sample",samples)
sequence:attribute("toto",44444)
nb = obicontext.inc("compteur")
sequence:id("seq_" .. nb)
return sequence
end
function finish()
print("compteur = " .. obicontext.item("compteur"))
end
|
The begin
and finish function
#
The worker
function
#
The obicontext
to share information
#
The BioSequence
class
#
The BioSequenceSlice
class
#
The Taxonomy
class
#
The Taxon
class
#
📄 extrem_quality.lua 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
| --
-- Script for obiscript extracting the qualities of
-- the first `size` and last `size` base pairs of
-- all the reads longer than 2 x `size`
--
-- The result is a csv file on the stdout
--
-- obiscript -S ../qualities.lua FAZ61712_c61e82f1_69e58200_0_nolambda.fastq > xxxx
-- Import the io module
local io = require("io")
-- Set the output stream to the stdout of the Go program
io.output(io.stdout)
size = 60
function begin()
obicontext.item("locker", Mutex:new())
header = "id"
for i = 1, size do
header = header .. ", L" .. i
end
for i = size, 1, -1 do
header = header .. ", R" .. i
end
obicontext.item("locker"):lock()
print(header)
obicontext.item("locker"):unlock()
end
function worker(sequence)
l = sequence:len()
if l > size * 2 then
qualities = sequence:qualities()
rep = sequence:id()
for i = 1, size do
rep = rep .. ", " .. qualities[i]
end
for i = size, 1, -1 do
rep = rep .. ", " .. qualities[l - i + 1]
end
obicontext.item("locker"):lock()
print(rep)
obicontext.item("locker"):unlock()
end
return BioSequenceSlice.new()
end
|