-
Notifications
You must be signed in to change notification settings - Fork 16
/
eq2tsv
executable file
·68 lines (57 loc) · 1.22 KB
/
eq2tsv
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
#!/usr/bin/env ruby
# input lines are name=value pairs, with other crap strewn about, e.g.
#
# t=0 i=0 label=1 pred=1
# blabla t=2 i=0 label=1 pred=0.999988 OMG!!!
# t=1 i=1993 label=0 pred=0
# t=1 i=1996 label=0 pred=9.16984e-06
#
# this is an easy debug format to output from a C program.
# combined with grep, use this to get tables of useful event-like data
class String
def matches(regex)
ret = []
scan(regex) do |match_groups|
ret << $~
end
ret
end
end
class Regexp
def matches(str)
str.matches(self)
end
end
def parse_line(line)
# >> (/(\S+)=(\S+)/.matches("t=1 i=1996 label=0 pred=9.16984e-06"))[0][1..2]
matches = /(\S*[a-zA-Z0-9])=(\S+)/.matches(line)
ret = {}
for m in matches
k,v = m[1..2]
ret[k] = v
end
ret
end
def puts_nas(n)
puts( (["NA"]*n).join("\t") )
end
names = nil
buildup = 0
for line in STDIN
if line !~ /[a-zA-Z0-9]=\S/
next unless ARGV.member?('-a')
if names.nil?
buildup += 1
else
puts_nas(names.size)
end
next
end
record = parse_line(line.chomp)
if names.nil?
names = record.keys.sort
puts names.join("\t")
buildup.times { puts_nas(names.size) }
end
puts names.map{|k| record[k]}.join("\t")
end