-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfastq_rnd_seek_proper.jl
executable file
·75 lines (65 loc) · 1.6 KB
/
fastq_rnd_seek_proper.jl
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/Applications/Julia-0.3.8.app/Contents/Resources/julia/bin/julia
# required modules
require("argparse")
using ArgParse
# function to parse arguments
function parse_arguments()
s = ArgParseSettings()
@add_arg_table s begin
"filename"
help = "Input filename."
required = true
"numsamples"
help = "Number of sequences to sample."
arg_type = Int
default = 10000
end
return parse_args(s)
end
# function to return random position in file
function get_random_pos(rnd_num)
return rand(0:rnd_num)
end
# main function
function main()
# retrieve parsed arguments
parsed_args = parse_arguments()
# set filename
filename = parsed_args["filename"]
numsamples = parsed_args["numsamples"]
# check file exists
if !isfile(filename)
throw(LoadError("", 0, "Filename $(filename) not found."))
end
# get file size
infilesize = filesize(filename)
# open input file
infh = open(filename, "r")
# iterate number of samples times
observed = Array(Int64, 0)
for i = 1:numsamples
valid_record = false
lines = Array(ASCIIString, 4)
while !valid_record
pos = get_random_pos(infilesize)
seek(infh, pos)
readuntil(infh, "\n@")
pos = position(infh) - 1
seek(infh, pos)
for j in [1:4]
lines[j] = rstrip(readline(infh))
end
if beginswith(lines[1], "@") && beginswith(lines[3], "+")
if !in(pos, observed)
valid_record = true
push!(observed, pos)
end
end
end
println(join(lines, "\n"))
end
# close file handle
close(infh)
end
# call main function
main()