Module: BioLocus::Store

Defined in:
lib/bio-locus/store.rb

Class Method Summary collapse

Class Method Details

.run(options) ⇒ Object



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
# File 'lib/bio-locus/store.rb', line 4

def Store.run(options)
  invert_match = options[:invert_match]
  store = DbMapper.factory(options)
  count = count_new = count_dup = 0
  STDIN.each_line do | line |
    Keys::each_key(line,options) do | key |
      has_match = lambda { 
                           if invert_match
                             not store[key]
                           else
                             store[key]
                           end
                         }
      if not has_match.call
        count_new += 1 
        store[key] = true
      else
        count_dup += 1
        if options[:debug]
          $stderr.print "Store hit: <#{key}>\n"
        end
      end
      count += 1
      $stderr.print '.' if (count % 1_000_000) == 0 if not options[:quiet]
      next
    end
  end
  store.close
  $stderr.print "Stored #{count_new} positions out of #{count} in #{options[:db]} (#{count_dup} duplicate hits)\n" if !options[:quiet]
end