methplotlib 0.23.0__py3-none-any.whl → 0.23.1__py3-none-any.whl

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/annotation.py CHANGED
@@ -27,17 +27,16 @@ def open_gtf(gtff):
27
27
  return gzip.open(gtff, "rt") if gtff.endswith(".gz") else open(gtff)
28
28
 
29
29
 
30
- def good_record(line, chromosome):
30
+ def good_record(fields, chromosome):
31
31
  """
32
32
  Filtering on the gtf lines
33
33
  by checking for right chromosome and right feature type
34
34
 
35
+ Takes the first fields of a line, as splitting off the long attributes
36
+ field for every line of an annotation is a waste.
35
37
  The chromosome has to match the entire field, as a prefix match would
36
38
  e.g. also accept chr10 up to chr19 and chr1_KI270706v1_random for chr1
37
39
  """
38
- if line.startswith("#"):
39
- return False
40
- fields = line.split("\t")
41
40
  return len(fields) > 2 and fields[0] == str(chromosome) and fields[2] in ["exon", "gene"]
42
41
 
43
42
 
@@ -100,10 +99,15 @@ def parse_annotation(gtff, window, simplify=False):
100
99
  chromosomes_seen = set()
101
100
  records = []
102
101
  for line in open_gtf(gtff):
103
- if good_record(line, window.chromosome):
102
+ if line.startswith("#") or not line.strip():
103
+ continue
104
+ # only the fields needed to decide, the attributes are split off
105
+ # further down for the few lines that are of interest
106
+ fields = line.split("\t", 3)
107
+ if good_record(fields, window.chromosome):
104
108
  records.append(get_features(line, type=type))
105
- elif line.strip() and not line.startswith("#"):
106
- chromosomes_seen.add(line.split("\t")[0])
109
+ else:
110
+ chromosomes_seen.add(fields[0])
107
111
  if not records and chromosomes_seen:
108
112
  sys.stderr.write(
109
113
  f"\nWARNING: no exons or genes of chromosome '{window.chromosome}' "
@@ -121,9 +125,13 @@ def parse_annotation(gtff, window, simplify=False):
121
125
  if simplify:
122
126
  df.drop_duplicates(subset=["chromosome", "begin", "end", "gene"], inplace=True)
123
127
  res = []
124
- for g in transcripts_in_window(df, window, feature="gene"):
125
- gtable = df.loc[df["gene"] == g]
126
- if len(gtable):
128
+ genes = transcripts_in_window(df, window, feature="gene")
129
+ # grouping the features of interest once, rather than scanning the
130
+ # entire frame again for every gene
131
+ per_gene = dict(list(df[df["gene"].isin(genes)].groupby("gene")))
132
+ for g in genes:
133
+ gtable = per_gene.get(g)
134
+ if gtable is not None and len(gtable):
127
135
  res.append(
128
136
  Transcript(
129
137
  transcript=gtable["gene"].tolist()[0],
@@ -138,8 +146,15 @@ def parse_annotation(gtff, window, simplify=False):
138
146
  logging.info(f"Found {len(res)} gene(s) in the region.\n")
139
147
  else:
140
148
  res = []
141
- for t in transcripts_in_window(df, window, feature="transcript"):
142
- tr = df.loc[df["transcript"] == t]
149
+ transcripts = transcripts_in_window(df, window, feature="transcript")
150
+ # grouping the features of interest once, rather than scanning the
151
+ # entire frame again for every transcript
152
+ per_transcript = dict(list(df[df["transcript"].isin(transcripts)].groupby("transcript")))
153
+ for t in transcripts:
154
+ tr = per_transcript.get(t)
155
+ if tr is None or not len(tr):
156
+ # an annotation without transcript_id, e.g. some gff flavors
157
+ continue
143
158
  res.append(
144
159
  Transcript(
145
160
  transcript=t,
@@ -540,9 +540,10 @@ def get_modified_reference_positions(read):
540
540
  # Nake an array with all read positions for which that nucleotide exists in the read
541
541
  # Oddly, get_forward_sequence() returns the sequence as it came from the sequencer
542
542
  # This is the same direction as the Mm/Ml tags are specified in
543
- base_index = np.array(
544
- [i for i, letter in enumerate(read.get_forward_sequence()) if letter == base]
545
- )
543
+ # the positions of that nucleotide in the read, found with numpy
544
+ # as a python loop over every base of a long read is expensive
545
+ sequence = np.frombuffer(read.get_forward_sequence().encode(), dtype="S1")
546
+ base_index = np.flatnonzero(sequence == base.encode())
546
547
  # Based on both arrays, find those read coordinates that have a modification
547
548
  modified_bases = base_index[locations]
548
549
  # Convert the array of read coordinates to reference coordinates
methplotlib/plots.py CHANGED
@@ -189,13 +189,15 @@ def make_per_read_meth_traces_phred(
189
189
  table = table.join(df_heights, on="read_name", how="outer")
190
190
  traces = []
191
191
  hidden = 0
192
- for read in table["read_name"].unique():
193
- strand = table.loc[table["read_name"] == read, "strand"].values[0]
192
+ # one row per read, to avoid scanning the entire table for every read
193
+ per_read = table.drop_duplicates(subset="read_name").set_index("read_name")
194
+ for read in per_read.index:
195
+ strand = per_read.at[read, "strand"]
194
196
  try:
195
197
  traces.append(
196
198
  make_per_read_line_trace(
197
199
  read_range=minmax_table.loc[read],
198
- y_pos=df_heights.loc[read, "height"],
200
+ y_pos=df_heights.at[read, "height"],
199
201
  strand=strand,
200
202
  )
201
203
  )
@@ -233,17 +235,16 @@ def make_per_read_meth_traces_llr(
233
235
  )
234
236
  traces = []
235
237
  hidden = 0
236
- for read in table["read_name"].unique():
237
- strand = table.loc[table["read_name"] == read, "strand"].values[0]
238
- if phased:
239
- phase = table.loc[table["read_name"] == read, "HP"].values[0]
240
- else:
241
- phase = None
238
+ # one row per read, to avoid scanning the entire table for every read
239
+ per_read = table.drop_duplicates(subset="read_name").set_index("read_name")
240
+ for read in per_read.index:
241
+ strand = per_read.at[read, "strand"]
242
+ phase = per_read.at[read, "HP"] if phased else None
242
243
  try:
243
244
  traces.append(
244
245
  make_per_read_line_trace(
245
246
  read_range=minmax_table.loc[read],
246
- y_pos=df_heights.loc[read, "height"],
247
+ y_pos=df_heights.at[read, "height"],
247
248
  strand=strand,
248
249
  phase=phase,
249
250
  size=dotsize,
methplotlib/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.23.0"
1
+ __version__ = "0.23.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: methplotlib
3
- Version: 0.23.0
3
+ Version: 0.23.1
4
4
  Summary: Plot nucleotide modification data from nanopore sequencing
5
5
  Home-page: https://github.com/wdecoster/methplotlib
6
6
  Author: Wouter De Coster
@@ -0,0 +1,19 @@
1
+ methplotlib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ methplotlib/annotation.py,sha256=c-b5bUlVTi2Mc0QDBzsKe4V7N0ETw8BEtvY-e0ZtCjQ,7541
3
+ methplotlib/helpers.py,sha256=D69CLM_M8D0wNoV4p-ODr81uatfeCBUUzYdifUmjL88,432
4
+ methplotlib/import_methylation.py,sha256=XyI52b6GYPDlxm_JbUMFqeDkEMUu8Sg51BcT9a2aEm8,22728
5
+ methplotlib/methplotlib.py,sha256=Gk07ODKVfDlA33SlzgIsqRLP0j1DYng24ku87DyYrXY,6264
6
+ methplotlib/plots.py,sha256=MPViIwPrrYn_gx_1VYs3ZECthll3OPrbcyoVAC00cLU,14757
7
+ methplotlib/qc.py,sha256=1EvpxeU7xfwKcQeNflrO4pgsZbc9gbCTcMbShumB_Mo,5590
8
+ methplotlib/utils.py,sha256=ffRDe2ITycIj7_5JV2NBjU6XA4qYYIK3HuWUkqhfJLI,14536
9
+ methplotlib/version.py,sha256=EmtVqV41YmZp6Mj5pkm4iGXDMznVEE4GQEUYGGidq30,23
10
+ methplotlib/differential/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ methplotlib/differential/differential.py,sha256=YSWUAeMaI_yERj6oAdvyWM3vKn2laTtWp6Y8ZuwvLA4,1773
12
+ methplotlib-0.23.1.data/scripts/allele_specific_modification,sha256=PpBdGIiVm8M6OjM0m68OPWnsyDeXJZDnbSNCrH3CaHY,1403
13
+ methplotlib-0.23.1.data/scripts/differential_modification,sha256=SZ0odGaykx_cqIHh5tOKSVUCbXOdHR4PSv4Yv6V04Zw,1461
14
+ methplotlib-0.23.1.dist-info/licenses/LICENSE,sha256=qan9p7Fjhl7WzXuiZoaXCViH5si1PSKBNm9K2f0_51c,1073
15
+ methplotlib-0.23.1.dist-info/METADATA,sha256=-khfgkXsY0_Jr48VBRtkrn1YYX4r4_qYPZhzS-lGQuo,5718
16
+ methplotlib-0.23.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
17
+ methplotlib-0.23.1.dist-info/entry_points.txt,sha256=Tav-_W5yZc2G8ApYYuFLfVKU2QugXuEN8z_AjPZwORs,61
18
+ methplotlib-0.23.1.dist-info/top_level.txt,sha256=w1XBGUmKUyGeE0_ufRQ6Vi5lMIzDq6TwF587aofDxuQ,12
19
+ methplotlib-0.23.1.dist-info/RECORD,,
@@ -1,19 +0,0 @@
1
- methplotlib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- methplotlib/annotation.py,sha256=JjbwXoAmb53lBJJq4W-_B1P3b2-vIrK2QlHUDavq6lk,6671
3
- methplotlib/helpers.py,sha256=D69CLM_M8D0wNoV4p-ODr81uatfeCBUUzYdifUmjL88,432
4
- methplotlib/import_methylation.py,sha256=7sf396Cjrkdx-JvvEYcj7IVCCQClch-Sv4YJ9kSfQH4,22561
5
- methplotlib/methplotlib.py,sha256=Gk07ODKVfDlA33SlzgIsqRLP0j1DYng24ku87DyYrXY,6264
6
- methplotlib/plots.py,sha256=EZRzc-B4OLjmgFlagzIdhs0S2zyuc_oSv6JqAQs3j3c,14609
7
- methplotlib/qc.py,sha256=1EvpxeU7xfwKcQeNflrO4pgsZbc9gbCTcMbShumB_Mo,5590
8
- methplotlib/utils.py,sha256=ffRDe2ITycIj7_5JV2NBjU6XA4qYYIK3HuWUkqhfJLI,14536
9
- methplotlib/version.py,sha256=6bYcjtcATvc99ZNMjTUfPlrJP3-1WenVEc656roVn_I,23
10
- methplotlib/differential/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- methplotlib/differential/differential.py,sha256=YSWUAeMaI_yERj6oAdvyWM3vKn2laTtWp6Y8ZuwvLA4,1773
12
- methplotlib-0.23.0.data/scripts/allele_specific_modification,sha256=PpBdGIiVm8M6OjM0m68OPWnsyDeXJZDnbSNCrH3CaHY,1403
13
- methplotlib-0.23.0.data/scripts/differential_modification,sha256=SZ0odGaykx_cqIHh5tOKSVUCbXOdHR4PSv4Yv6V04Zw,1461
14
- methplotlib-0.23.0.dist-info/licenses/LICENSE,sha256=qan9p7Fjhl7WzXuiZoaXCViH5si1PSKBNm9K2f0_51c,1073
15
- methplotlib-0.23.0.dist-info/METADATA,sha256=ekpREpDBaoqT6fQD0gTEDI3rN2sYfcgGstYss_OiAB8,5718
16
- methplotlib-0.23.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
17
- methplotlib-0.23.0.dist-info/entry_points.txt,sha256=Tav-_W5yZc2G8ApYYuFLfVKU2QugXuEN8z_AjPZwORs,61
18
- methplotlib-0.23.0.dist-info/top_level.txt,sha256=w1XBGUmKUyGeE0_ufRQ6Vi5lMIzDq6TwF587aofDxuQ,12
19
- methplotlib-0.23.0.dist-info/RECORD,,