Skip to content

Commit 181d2c5

Browse files
Merge pull request #224 from jeromekelleher/fix-info-bugs2
Remove submission delay from utils
2 parents ddf9899 + 1216618 commit 181d2c5

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

sc2ts/utils.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import tszip
1414
import numpy as np
1515
import pandas as pd
16+
1617
# TODO where do we use this? This is a *great* example of why not to use
1718
# this style, because we have loads of variables called "tree" in this file.
1819
from sklearn import tree
@@ -326,7 +327,6 @@ def __init__(self, ts, show_progress=True, pango_source="Viridian_pangolin"):
326327
self.recombinants = get_recombinants(ts)
327328
self.nodes_max_descendant_samples = max_descendant_samples(ts)
328329
self.nodes_date = np.zeros(ts.num_nodes, dtype="datetime64[D]")
329-
self.nodes_submission_date = np.zeros(ts.num_nodes, dtype="datetime64[D]")
330330
self.nodes_num_masked_sites = np.zeros(ts.num_nodes, dtype=np.int32)
331331
self.nodes_metadata = {}
332332
iterator = tqdm.tqdm(
@@ -348,7 +348,6 @@ def __init__(self, ts, show_progress=True, pango_source="Viridian_pangolin"):
348348
if node.is_sample():
349349
self.strain_map[md["strain"]] = node.id
350350
self.nodes_date[node.id] = md["date"]
351-
self.nodes_submission_date[node.id] = md["date_submitted"]
352351
pango = md.get(pango_source, "unknown")
353352
self.pango_lineage_samples[pango].append(node.id)
354353
if "sc2ts" in md:
@@ -362,8 +361,6 @@ def __init__(self, ts, show_progress=True, pango_source="Viridian_pangolin"):
362361
self.ts.nodes_time[node.id]
363362
)
364363

365-
self.nodes_submission_delay = self.nodes_submission_date - self.nodes_date
366-
367364
self.sites_num_masked_samples = np.zeros(self.ts.num_sites, dtype=int)
368365
if ts.table_metadata_schemas.site.schema is not None:
369366
for site in ts.sites():
@@ -393,7 +390,6 @@ def __init__(self, ts, show_progress=True, pango_source="Viridian_pangolin"):
393390
# # Corresponding sample-set names for this array
394391
# self.pango_lineage_keys = np.array(list(self.pango_lineage_samples.keys()))
395392

396-
397393
def _compute_mutation_stats(self):
398394
ts = self.ts
399395

@@ -511,7 +507,6 @@ def summary(self):
511507

512508
data = [
513509
("latest_sample", latest_sample),
514-
("max_submission_delay", np.max(self.nodes_submission_delay[samples])),
515510
("samples", self.ts.num_samples),
516511
("nodes", self.ts.num_nodes),
517512
("mc_nodes", mc_nodes),
@@ -622,7 +617,6 @@ def _node_summary(self, u, child_mutations=True):
622617
"children": np.sum(self.ts.edges_parent == u),
623618
"descendants": self.nodes_max_descendant_samples[u],
624619
"date": self.nodes_date[u],
625-
"delay": self.nodes_submission_delay[u],
626620
"qc": qc,
627621
**self._node_mutation_summary(u, child_mutations=child_mutations),
628622
}
@@ -1547,7 +1541,13 @@ def sort_mutation_label(s):
15471541
except ValueError:
15481542
if s[0] == "$":
15491543
# matplotlib mathtext - remove the $ and the formatting
1550-
s = s.replace("$", "").replace(r"\bf", "").replace("\it", "").replace("{", "").replace("}", "")
1544+
s = (
1545+
s.replace("$", "")
1546+
.replace(r"\bf", "")
1547+
.replace("\it", "")
1548+
.replace("{", "")
1549+
.replace("}", "")
1550+
)
15511551
try:
15521552
return float(s[1:-1])
15531553
except ValueError:
@@ -1572,7 +1572,14 @@ def sort_mutation_label(s):
15721572
if exterior_edge_len is None:
15731573
exterior_edge_len = 0.4
15741574

1575-
if show_descendant_samples not in {"samples", "tips", "sample_tips", "all", "", False}:
1575+
if show_descendant_samples not in {
1576+
"samples",
1577+
"tips",
1578+
"sample_tips",
1579+
"all",
1580+
"",
1581+
False,
1582+
}:
15761583
raise ValueError(
15771584
"show_descendant_samples must be one of 'samples', 'tips', 'sample_tips', 'all', or '' / False"
15781585
)
@@ -1616,7 +1623,7 @@ def sort_mutation_label(s):
16161623
if show:
16171624
s = ti.nodes_max_descendant_samples[u]
16181625
if node.is_sample():
1619-
s -= 1 # don't count self
1626+
s -= 1 # don't count self
16201627
if s > 0:
16211628
nodelabels[u].append(f"+{s} {'samples' if s > 1 else 'sample'}")
16221629

@@ -1675,14 +1682,18 @@ def sort_mutation_label(s):
16751682
lpos = "lft"
16761683
elif edge.left > 0 and edge.right == ts.sequence_length:
16771684
lpos = "rgt"
1678-
# Add spaces between or in front of labels if
1679-
# multiple lft or rgt labels (i.e. intervals) exist for an edge
1685+
# Add spaces between or in front of labels if
1686+
# multiple lft or rgt labels (i.e. intervals) exist for an edge
16801687
if interval_labels[lpos][pc]: # between same side labels
16811688
interval_labels[lpos][pc] += " "
1682-
if lpos == "rgt" and interval_labels["lft"][pc]: # in front of rgt label
1689+
if (
1690+
lpos == "rgt" and interval_labels["lft"][pc]
1691+
): # in front of rgt label
16831692
interval_labels[lpos][pc] = " " + interval_labels[lpos][pc]
16841693
interval_labels[lpos][pc] += f"{int(edge.left)}{int(edge.right)}"
1685-
if lpos == "lft" and interval_labels["rgt"][pc]: # at end of lft label
1694+
if (
1695+
lpos == "lft" and interval_labels["rgt"][pc]
1696+
): # at end of lft label
16861697
interval_labels[lpos][pc] += " "
16871698

16881699
if label_replace is not None:

0 commit comments

Comments
 (0)