Skip to content

Commit f989d4b

Browse files
Merge pull request #509 from jeromekelleher/robust-to-interval-change
Tolerate coordinate shifts
2 parents a1fa4b2 + b71103f commit f989d4b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

sc2ts/info.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,12 +1026,20 @@ def node_info(node, label):
10261026
parent_left = hmm_match["path"][0]["parent"]
10271027
parent_right = hmm_match["path"][1]["parent"]
10281028

1029+
edges_right = self.ts.edges_right[self.ts.edges_child == u]
1030+
interval_right = int(edges_right.min())
1031+
if interval_right != interval[0][1]:
1032+
logger.warning(
1033+
f"RE: {u} interval right shifted from {interval[0][1]} "
1034+
f"to {interval_right}"
1035+
)
1036+
10291037
datum = {
10301038
"num_descendant_samples": self.nodes_max_descendant_samples[u],
10311039
"num_samples": len(samples),
10321040
"distinct_sample_pango": len(set(causal_lineages.values())),
10331041
"interval_left": interval[0][0],
1034-
"interval_right": interval[0][1],
1042+
"interval_right": interval_right,
10351043
"num_mutations": len(hmm_match["mutations"]),
10361044
"Viridian_amplicon_scheme": self.nodes_metadata[v].get(
10371045
"Viridian_amplicon_scheme", "Unknown"

tests/test_info.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,21 @@ def test_recombinants_summary_example_2(self, fx_recombinant_example_2):
223223
assert row["diffs"] == 6
224224
assert row["max_run_length"] == 2
225225

226+
def test_recombinants_summary_example_2_bp_shift(self, fx_recombinant_example_2):
227+
tables = fx_recombinant_example_2.dump_tables()
228+
sample = 55
229+
row = tables.nodes[sample]
230+
md = row.metadata
231+
# Shift the bp one base right
232+
md["sc2ts"]["breakpoint_intervals"] = [[114, 29826]]
233+
tables.nodes[sample] = row.replace(metadata=md)
234+
ts = tables.tree_sequence()
235+
ti = info.TreeInfo(ts, show_progress=False)
236+
df1 = ti.recombinants_summary(characterise_copying=True, show_progress=False)
237+
ti = info.TreeInfo(fx_recombinant_example_2, show_progress=False)
238+
df2 = ti.recombinants_summary(characterise_copying=True, show_progress=False)
239+
pd.testing.assert_frame_equal(df1, df2)
240+
226241

227242
class TestSampleGroupInfo:
228243
def test_draw_svg(self, fx_ti_2020_02_13):

0 commit comments

Comments
 (0)