File: prevent_open_file_regression

package info (click to toggle)
python-pybedtools 0.8.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 16,140 kB
  • sloc: python: 9,589; cpp: 899; makefile: 149; sh: 116
file content (60 lines) | stat: -rwxr-xr-x 1,570 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python

"""
Test for running many random intersections in parallel.  Use this for making
sure the open file bug (#38) doesn't return.  Not part of the standard test
suite because of the amount of time it takes to run....

Stored here because it's a test, but .py extension removed so nosetests doesn't
find it.
"""
import pybedtools
import sys
import os

prog = sys.argv[0]

usage = """
    Tries to create the open file bug by performing 10k iterations.

    To test BedTool.randomstats:

        %(prog)s randomstats

    To test BedTool.naive_jaccard:

        %(prog)s jaccard

    """ % locals()

if not os.path.exists('TEMP'):
    os.makedirs('TEMP')

if len(sys.argv) < 2:
    print(usage)
    sys.exit(1)

pybedtools.set_tempdir('TEMP')

gfn = pybedtools.chromsizes_to_file({'chr1': (0, 1000)})

a = pybedtools.example_bedtool('a.bed').set_chromsizes({'chr1': (1, 1000)})
b = pybedtools.example_bedtool('b.bed')


if sys.argv[1] == 'randomstats':
    results = a.randomstats(b, 100000, report_iterations=True, processes=8,
                            intersect_kwargs={'sorted': True})

elif sys.argv[1] == 'newrandomstats':
    results = a.randomstats(b, 100000, processes=8,
                            new=True, genome_fn=gfn,
                            intersect_kwargs={'sorted': True})

elif sys.argv[1] == 'jaccard':
    results = a.random_jaccard(other=b, iterations=10000, genome_fn=gfn,
                               processes=8, shuffle_kwargs=dict(chrom=True),
                               )
else:
    print(usage)
    sys.exit(1)