Debian Codegraph @

test/test_gather_bigwig.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 import loggingscip-python python python-stdlib 3.11 logging/__init__:
2 import os.pathscip-python python python-stdlib 3.11 `os.path`/__init__: as op
3 import subprocessscip-python python python-stdlib 3.11 subprocess/__init__:
4 import sysscip-python python python-stdlib 3.11 sys/__init__:
5 import tempfilescip-python python python-stdlib 3.11 tempfile/__init__:
6
7 import pytestscip-python python pytest 9.1.1 pytest/__init__:
8
9 from pbcommand.pb_io.commonscip-python python pbcommand 2.4.4 `pbcommand.pb_io.common`/__init__: import load_pipeline_chunks_from_json, \
10 write_pipeline_chunks
11 from pbcommand.pb_io.reportscip-python python pbcommand 2.4.4 `pbcommand.pb_io.report`/__init__: import load_report_from_json
12 from pbcommand.modelsscip-python python pbcommand 2.4.4 `pbcommand.models`/__init__: import PipelineChunk
13
14 from kineticsTools.tasks.gather_bigwigscip-python python kineticsTools 0.8.0 `kineticsTools.tasks.gather_bigwig`/__init__: import gather_bigwigscip-python python kineticsTools 0.8.0 `kineticsTools.tasks.gather_bigwig`/gather_bigwig().
15
16 logscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/log. = loggingscip-python python python-stdlib 3.11 logging/__init__:.getLoggerscip-python python python-stdlib 3.11 logging/getLogger().(__name__scip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/)
17
18
19 def _generate_chunk_output_filescip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/_generate_chunk_output_file().(iscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/_generate_chunk_output_file().(i)=None):
20 import pyBigWig
21 records = [
22 ("chr1", 4, 5, 0.45),
23 ("chr2", 8, 9, 1.0),
24 ("chr2", 9, 10, 6.7),
25 ("chr1", 1, 2, 1.5),
26 ("chr1", 2, 3, 4.5),
27 ("chr1", 3, 4, 1.9)
28 ]
29 fn = tempfilescip-python python python-stdlib 3.11 tempfile/__init__:.NamedTemporaryFilescip-python python python-stdlib 3.11 tempfile/NamedTemporaryFile().(suffixscip-python python python-stdlib 3.11 tempfile/NamedTemporaryFile().(suffix)=".bw").namescip-python python python-stdlib 3.11 tempfile/_TemporaryFileWrapper#name.
30 _records = records[(iscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/_generate_chunk_output_file().(i) * 3):(iscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/_generate_chunk_output_file().(i) * 3) + 3]
31 assert len(_records) == 3
32 ranges = {}
33 for rec in _records:
34 seqid = rec[0]
35 pos = rec[1]
36 ranges.setdefaultscip-python python python-stdlib 3.11 typing/MutableMapping#setdefault().(seqid, (sysscip-python python python-stdlib 3.11 sys/__init__:.maxsizescip-python python python-stdlib 3.11 sys/maxsize.maxsize., 0))
37 ranges[seqid] = (minscip-python python python-stdlib 3.11 builtins/min().(ranges[seqid][0], pos),
38 maxscip-python python python-stdlib 3.11 builtins/max().(ranges[seqid][1], pos))
39 bw = pyBigWig.open(fn, "w")
40 regions = [(s, ranges[s][1] + 1) for s in sortedscip-python python python-stdlib 3.11 builtins/sorted().(ranges.keysscip-python python python-stdlib 3.11 builtins/dict#keys().())]
41 bw.addHeader(regions)
42 bw.addEntries([rec[0] for rec in _records],
43 [rec[1] - 1 for rec in _records],
44 ends=[rec[2] - 1 for rec in _records],
45 values=[rec[3] for rec in _records])
46 bw.close()
47 return fn
48
49
50 @pytestscip-python python pytest 9.1.1 pytest/__init__:.mark.pybigwig
51 class TestGatherBigwigscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#:
52 NCHUNKSscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#NCHUNKS. = 2
53
54 @classmethodscip-python python python-stdlib 3.11 builtins/classmethod#
55 def setup_classscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#setup_class().(clsscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#setup_class().(cls)):
56 clsscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#setup_class().(cls)._data_filesscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#_data_files. = [_generate_chunk_output_filescip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/_generate_chunk_output_file().(iscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/_generate_chunk_output_file().(i)=i)
57 for i in rangescip-python python python-stdlib 3.11 builtins/range#(clsscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#setup_class().(cls).NCHUNKSscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#NCHUNKS.)]
58
59 def validate_outputscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#validate_output().(selfscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#validate_output().(self), output_filescip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#validate_output().(output_file)):
60 import pyBigWig
61 bw = pyBigWig.open(output_filescip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#validate_output().(output_file))
62 nrec = bw.header()["nBasesCovered"]
63 assert nrec == 6
64 assert pytestscip-python python pytest 9.1.1 pytest/__init__:.approx(bw.stats("chr1", 2, 3)[0]) == 1.9
65 assert pytestscip-python python pytest 9.1.1 pytest/__init__:.approx(bw.stats("chr2", 7, 8)[0]) == 1.0
66
67 def test_gather_bigwigscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#test_gather_bigwig().(selfscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#test_gather_bigwig().(self)):
68 ofn = tempfilescip-python python python-stdlib 3.11 tempfile/__init__:.NamedTemporaryFilescip-python python python-stdlib 3.11 tempfile/NamedTemporaryFile().(suffixscip-python python python-stdlib 3.11 tempfile/NamedTemporaryFile().(suffix)=".bw").namescip-python python python-stdlib 3.11 tempfile/_TemporaryFileWrapper#name.
69 rc = gather_bigwigscip-python python kineticsTools 0.8.0 `kineticsTools.tasks.gather_bigwig`/gather_bigwig().(selfscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#test_gather_bigwig().(self)._data_filesscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#_data_files., ofn)
70 selfscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#test_gather_bigwig().(self).validate_outputscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#validate_output().(ofn)
71
72 def test_gather_bigwig_cliscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#test_gather_bigwig_cli().(selfscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#test_gather_bigwig_cli().(self)):
73 tmp_dir = tempfilescip-python python python-stdlib 3.11 tempfile/__init__:.mkdtempscip-python python python-stdlib 3.11 tempfile/mkdtemp().()
74 ofn = op.joinscip-python python python-stdlib 3.11 genericpath/isfile().(tmp_dir, "gathered.bw")
•75 args = ["python3", "-m", "kineticsTools.tasks.gather_bigwig",
76 ofn] + selfscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#test_gather_bigwig_cli().(self)._data_filesscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#_data_files.
77 logscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/log..infoscip-python python python-stdlib 3.11 logging/Logger#info().("Output will be in %s", tmp_dir)
78 with openscip-python python python-stdlib 3.11 builtins/open().(op.joinscip-python python python-stdlib 3.11 genericpath/isfile().(tmp_dir, "stdout"), "w") as stdout:
79 with openscip-python python python-stdlib 3.11 builtins/open().(op.joinscip-python python python-stdlib 3.11 genericpath/isfile().(tmp_dir, "stderr"), "w") as stderr:
80 subprocessscip-python python python-stdlib 3.11 subprocess/__init__:.check_callscip-python python python-stdlib 3.11 subprocess/check_call().(args, stdoutscip-python python python-stdlib 3.11 subprocess/check_call().(stdout)=stdout, stderrscip-python python python-stdlib 3.11 subprocess/check_call().(stderr)=stderr)
81 selfscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#test_gather_bigwig_cli().(self).validate_outputscip-python python kineticsTools 0.8.0 `test.test_gather_bigwig`/TestGatherBigwig#validate_output().(ofn)