Skip to content

Instantly share code, notes, and snippets.

@ctb
Created April 6, 2013 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctb/5328016 to your computer and use it in GitHub Desktop.
Save ctb/5328016 to your computer and use it in GitHub Desktop.
import khmer, sys, threading, time
###
s = set()
def read_names(rparser, tnum):
print 'started', tnum
n = 0
for n, read in enumerate(rparser):
s.add(read.name)
if n % 1000 == 0:
print 'sleeping', tnum, n
time.sleep(0.2)
print 'done', tnum, 'got', n
###
filename = sys.argv[1]
n_threads = int(sys.argv[2])
config = khmer.get_config()
bufsz = config.get_reads_input_buffer_size()
config.set_reads_input_buffer_size(n_threads * 64 * 1024)
rparser = khmer.ReadParser(filename, n_threads)
print 'starting threads'
threads = []
for tnum in xrange(n_threads):
print 'starting', tnum
t = threading.Thread(target=read_names, args=(rparser, tnum ))
threads.append(t)
t.start()
for t in threads:
t.join()
print 'done; loaded %s sequences' % len(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment