methplotlib 0.23.1__tar.gz → 0.23.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {methplotlib-0.23.1/methplotlib.egg-info → methplotlib-0.23.3}/PKG-INFO +1 -1
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib/import_methylation.py +30 -7
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib/qc.py +0 -5
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib/utils.py +1 -1
- methplotlib-0.23.3/methplotlib/version.py +1 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3/methplotlib.egg-info}/PKG-INFO +1 -1
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib.egg-info/SOURCES.txt +2 -1
- methplotlib-0.23.3/tests/test_import_methylation.py +78 -0
- methplotlib-0.23.1/methplotlib/version.py +0 -1
- {methplotlib-0.23.1 → methplotlib-0.23.3}/LICENSE +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/MANIFEST.in +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/README.md +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib/__init__.py +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib/annotation.py +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib/differential/__init__.py +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib/differential/differential.py +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib/helpers.py +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib/methplotlib.py +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib/plots.py +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib.egg-info/dependency_links.txt +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib.egg-info/entry_points.txt +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib.egg-info/requires.txt +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/methplotlib.egg-info/top_level.txt +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/scripts/allele_specific_modification +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/scripts/differential_modification +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/setup.cfg +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/setup.py +0 -0
- {methplotlib-0.23.1 → methplotlib-0.23.3}/tests/test_differential.py +0 -0
|
@@ -91,6 +91,7 @@ def parse_nanopolish(filename, file_type, name, window, smoothen=5):
|
|
|
91
91
|
raise
|
|
92
92
|
header = gzip.open(filename, "rt").readline().rstrip().split("\t")
|
|
93
93
|
table = pd.read_csv(tabix_stream.stdout, sep="\t", header=None, names=header)
|
|
94
|
+
check_tabix(tabix_stream, filename, window)
|
|
94
95
|
else:
|
|
95
96
|
logging.info(f"Reading {filename} slowly by splitting the file in chunks.")
|
|
96
97
|
sys.stderr.write(f"\nReading {filename} would be faster with bgzip and tabix.\n")
|
|
@@ -235,6 +236,19 @@ def no_records_warning(filename, window):
|
|
|
235
236
|
sys.stderr.write(f"\nWARNING: {message}\nThis dataset is skipped.\n")
|
|
236
237
|
|
|
237
238
|
|
|
239
|
+
def check_tabix(tabix_stream, filename, window):
|
|
240
|
+
"""
|
|
241
|
+
Exit if tabix failed, as a failing tabix also writes nothing to stdout,
|
|
242
|
+
which would otherwise be reported as a window without records.
|
|
243
|
+
Only call this after its stdout has been read.
|
|
244
|
+
"""
|
|
245
|
+
if tabix_stream.wait() != 0:
|
|
246
|
+
sys.exit(
|
|
247
|
+
f"\n\nERROR: tabix failed to read {window.chromosome}:{window.begin}-{window.end} "
|
|
248
|
+
f"from {filename}:\n{tabix_stream.stderr.read().decode()}"
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
|
|
238
252
|
def read_in_chunks(filename, window, sep, usecols, index_suggestion):
|
|
239
253
|
"""
|
|
240
254
|
Read a headerless file in chunks, keeping only the lines of the chromosome of interest.
|
|
@@ -303,6 +317,7 @@ def parse_bedgraph(filename, name, window):
|
|
|
303
317
|
names=colnames,
|
|
304
318
|
dtype={0: str},
|
|
305
319
|
)
|
|
320
|
+
check_tabix(tabix_stream, filename, window)
|
|
306
321
|
else:
|
|
307
322
|
table = read_in_chunks(
|
|
308
323
|
filename,
|
|
@@ -380,13 +395,21 @@ def parse_bedmethyl(filename, name, window, smoothen=5, flavor="modkit", mods_of
|
|
|
380
395
|
sys.stderr.write("\n\nERROR when opening a tabix stream.\n")
|
|
381
396
|
sys.stderr.write("Is tabix installed and on the PATH?.")
|
|
382
397
|
raise
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
398
|
+
try:
|
|
399
|
+
table = pd.read_csv(
|
|
400
|
+
tabix_stream.stdout,
|
|
401
|
+
sep=sep,
|
|
402
|
+
header=None,
|
|
403
|
+
usecols=usecols,
|
|
404
|
+
dtype={0: str},
|
|
405
|
+
).rename(columns=colnames)
|
|
406
|
+
except pd.errors.EmptyDataError:
|
|
407
|
+
table = None
|
|
408
|
+
check_tabix(tabix_stream, filename, window)
|
|
409
|
+
# tabix writes nothing if the window has no records or the chromosome is not in the index
|
|
410
|
+
if table is None:
|
|
411
|
+
no_records_warning(filename, window)
|
|
412
|
+
return []
|
|
390
413
|
else:
|
|
391
414
|
table = read_in_chunks(
|
|
392
415
|
filename,
|
|
@@ -45,7 +45,6 @@ def num_sites_bar(meth_data):
|
|
|
45
45
|
layout = dict(title="Number of called positions")
|
|
46
46
|
return plotly.offline.plot(dict(data=[trace], layout=layout),
|
|
47
47
|
output_type="div",
|
|
48
|
-
show_link=False,
|
|
49
48
|
include_plotlyjs='cdn')
|
|
50
49
|
|
|
51
50
|
|
|
@@ -72,7 +71,6 @@ def pairwise_correlation_plot(full):
|
|
|
72
71
|
|
|
73
72
|
return plotly.offline.plot(dict(data=[trace], layout=layout),
|
|
74
73
|
output_type="div",
|
|
75
|
-
show_link=False,
|
|
76
74
|
include_plotlyjs='cdn')
|
|
77
75
|
|
|
78
76
|
|
|
@@ -99,7 +97,6 @@ def pca(full):
|
|
|
99
97
|
)
|
|
100
98
|
return plotly.offline.plot(dict(data=data, layout=layout),
|
|
101
99
|
output_type="div",
|
|
102
|
-
show_link=False,
|
|
103
100
|
include_plotlyjs='cdn')
|
|
104
101
|
|
|
105
102
|
|
|
@@ -110,7 +107,6 @@ def global_box(data):
|
|
|
110
107
|
x="dataset", y="freq", title="Global frequency of modification")
|
|
111
108
|
return plotly.offline.plot(fig,
|
|
112
109
|
output_type="div",
|
|
113
|
-
show_link=False,
|
|
114
110
|
include_plotlyjs='cdn')
|
|
115
111
|
|
|
116
112
|
|
|
@@ -129,5 +125,4 @@ def modified_fraction_histogram(full):
|
|
|
129
125
|
return plotly.offline.plot(dict(data=traces,
|
|
130
126
|
layout=layout),
|
|
131
127
|
output_type="div",
|
|
132
|
-
show_link=False,
|
|
133
128
|
include_plotlyjs='cdn')
|
|
@@ -405,5 +405,5 @@ def create_browser_output(fig, outfile, window):
|
|
|
405
405
|
def write_html_output(fig, outfile):
|
|
406
406
|
with open(outfile, "w+") as output:
|
|
407
407
|
output.write(
|
|
408
|
-
plotly.offline.plot(fig, output_type="div",
|
|
408
|
+
plotly.offline.plot(fig, output_type="div", include_plotlyjs="cdn")
|
|
409
409
|
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.23.3"
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import shutil
|
|
2
|
+
|
|
3
|
+
import pysam
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from methplotlib.import_methylation import parse_bedgraph, parse_bedmethyl, parse_nanopolish
|
|
7
|
+
from methplotlib.utils import Region
|
|
8
|
+
|
|
9
|
+
pytestmark = pytest.mark.skipif(shutil.which("tabix") is None, reason="tabix not on the PATH")
|
|
10
|
+
|
|
11
|
+
# `modkit pileup --only-tabs` records, as shared in issue #52
|
|
12
|
+
BEDMETHYL = """\
|
|
13
|
+
1\t10468\t10469\th\t1\t+\t10468\t10469\t255,0,0\t1\t0.00\t0\t0\t1\t1\t0\t0\t0
|
|
14
|
+
1\t10468\t10469\tm\t1\t+\t10468\t10469\t255,0,0\t1\t100.00\t1\t0\t0\t1\t0\t0\t0
|
|
15
|
+
1\t10469\t10470\th\t2\t-\t10469\t10470\t255,0,0\t2\t0.00\t0\t1\t1\t0\t0\t0\t0
|
|
16
|
+
1\t10469\t10470\tm\t2\t-\t10469\t10470\t255,0,0\t2\t50.00\t1\t1\t0\t0\t0\t0\t0
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
BEDGRAPH = """\
|
|
20
|
+
1\t10468\t10469\t0.5
|
|
21
|
+
1\t10469\t10470\t1.0
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
NANOPOLISH_FREQ = """\
|
|
25
|
+
chromosome\tstart\tend\tnum_motifs_in_group\tcalled_sites\tcalled_sites_methylated\tmethylated_frequency\tgroup_sequence
|
|
26
|
+
1\t10468\t10468\t1\t10\t5\t0.5\tACGTA
|
|
27
|
+
1\t10470\t10470\t1\t10\t10\t1.0\tACGTA
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def indexed(tmp_path, name, content, **index_args):
|
|
32
|
+
path = tmp_path / name
|
|
33
|
+
path.write_text(content)
|
|
34
|
+
# bgzips the file and creates the .tbi index next to it
|
|
35
|
+
return pysam.tabix_index(str(path), **index_args)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.fixture
|
|
39
|
+
def indexed_bedmethyl(tmp_path):
|
|
40
|
+
return indexed(tmp_path, "test.bed", BEDMETHYL, preset="bed")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def corrupt_index(filename):
|
|
44
|
+
with open(filename + ".tbi", "w") as index:
|
|
45
|
+
index.write("not an index")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_indexed_bedmethyl_with_records(indexed_bedmethyl):
|
|
49
|
+
mods = parse_bedmethyl(indexed_bedmethyl, "test", Region("1:10000-11000"))
|
|
50
|
+
assert sorted(m.name for m in mods) == ["test_h", "test_m"]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@pytest.mark.parametrize("window", ["chrX:146,991,437-147,034,645", "1:500000-600000"])
|
|
54
|
+
def test_indexed_bedmethyl_without_records(indexed_bedmethyl, window):
|
|
55
|
+
assert parse_bedmethyl(indexed_bedmethyl, "test", Region(window)) == []
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@pytest.mark.parametrize(
|
|
59
|
+
"name, content, index_args, parse",
|
|
60
|
+
[
|
|
61
|
+
("test.bed", BEDMETHYL, {"preset": "bed"}, parse_bedmethyl),
|
|
62
|
+
("test.bedgraph", BEDGRAPH, {"preset": "bed"}, parse_bedgraph),
|
|
63
|
+
(
|
|
64
|
+
"freq.tsv",
|
|
65
|
+
NANOPOLISH_FREQ,
|
|
66
|
+
{"seq_col": 0, "start_col": 1, "end_col": 2, "line_skip": 1},
|
|
67
|
+
lambda f, n, w: parse_nanopolish(f, "nanopolish_freq", n, w),
|
|
68
|
+
),
|
|
69
|
+
],
|
|
70
|
+
ids=["bedmethyl", "bedgraph", "nanopolish_freq"],
|
|
71
|
+
)
|
|
72
|
+
def test_tabix_failure(tmp_path, name, content, index_args, parse):
|
|
73
|
+
# a corrupt index makes tabix exit with an error and no output,
|
|
74
|
+
# which should not be reported as a window without records
|
|
75
|
+
filename = indexed(tmp_path, name, content, **index_args)
|
|
76
|
+
corrupt_index(filename)
|
|
77
|
+
with pytest.raises(SystemExit, match="tabix failed"):
|
|
78
|
+
parse(filename, "test", Region("1:10000-11000"))
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.23.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|