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
|
# File 'lib/bio-locus/match.rb', line 3
def Match.run(options)
do_delete = (options[:task] == :delete)
invert_match = options[:invert_match]
store = DbMapper.factory(options)
lines = 0
= 0
count = 0
= true
uniq_match = {}
uniq_no_match = {}
STDIN.each_line do | line |
if and line =~ /^#/
print line
+= 1
next
else
= false
end
if line =~ /^#/
+= 1
else
lines += 1
end
$stderr.print '.' if (lines % 1_000_000) == 0 if not options[:quiet]
Keys::each_key(line,options) do | key |
has_match = lambda {
if invert_match
not store[key]
else
store[key]
end
}
if has_match.call
$stderr.print "Matched <#{key}>\n" if options[:debug]
count += 1
if do_delete
store.delete(key)
else
print line
uniq_match[key] ||= true
end
else
uniq_no_match[key] ||= true
end
end
end
store.close
if do_delete
$stderr.print "\nDeleted #{count} keys in #{options[:db]} reading #{lines} lines !\n" if not options[:quiet]
else
$stderr.print "\nMatched #{count} (unique #{uniq_match.keys.size}) lines out of #{lines} (header #{}, unique #{uniq_no_match.keys.size+uniq_match.keys.size}) in #{options[:db]}!\n" if not options[:quiet]
end
end
|