def random_intersections(inputs,output): fn1,fn2 = inputs print fn1,fn2 sys.stdout.flush() a = pybedtools.bedtool(fn1) b = pybedtools.bedtool(fn2) results = a.randomstats(b,ITERATIONS,intersectkwargs={'u':True}) key_order = [ fn1, fn2, 'actual', 'lower_95th', 'median randomized', 'upper_95th', 'percentile', 'normalized', ] line = [fn1,fn2] line += [results[i] for i in key_order] line = map(str,line) line = '\t'.join(line)+'\n' fout = open(output,'w') fout.write(line) fout.close()
import pybedtools pybedtools.set_tempdir('.') a = pybedtools.bedtool('a.bed') a.intersect(a) pybedtools.cleanup(verbose=True)