Skip to content

Commit c524e02

Browse files
committed
Add details about copying path and mutations to node metadata
1 parent b49a51b commit c524e02

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

sc2ts/inference.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,14 @@ def match_path_ts(samples, ts, path, reversions):
388388
first_sample = len(tables.nodes)
389389
for sample in samples:
390390
assert sample.path == path
391-
metadata = {**sample.metadata, "sc2ts_qc": sample.alignment_qc}
391+
metadata = {
392+
**sample.metadata,
393+
"sc2ts": {
394+
"qc": sample.alignment_qc,
395+
"path": [x.asdict() for x in sample.path],
396+
"mutations": [x.asdict() for x in sample.mutations],
397+
}
398+
}
392399
node_id = tables.nodes.add_row(
393400
flags=tskit.NODE_IS_SAMPLE, time=0, metadata=metadata
394401
)
@@ -400,7 +407,7 @@ def match_path_ts(samples, ts, path, reversions):
400407

401408
# Now add the mutations
402409
for node_id, sample in enumerate(samples, first_sample):
403-
metadata = {**sample.metadata, "sc2ts_qc": sample.alignment_qc}
410+
#metadata = {**sample.metadata, "sc2ts_qc": sample.alignment_qc}
404411
for mut in sample.mutations:
405412
tables.mutations.add_row(
406413
site=site_id_map[mut.site_id],
@@ -1058,6 +1065,13 @@ class PathSegment:
10581065
def contains(self, position):
10591066
return self.left <= position < self.right
10601067

1068+
def asdict(self):
1069+
return {
1070+
"left": self.left,
1071+
"right": self.right,
1072+
"parent": self.parent,
1073+
}
1074+
10611075

10621076
@dataclasses.dataclass(frozen=True)
10631077
class MatchMutation:
@@ -1071,6 +1085,16 @@ class MatchMutation:
10711085
def __str__(self):
10721086
return f"{int(self.site_position)}{self.inherited_state}>{self.derived_state}"
10731087

1088+
def asdict(self):
1089+
return {
1090+
"site_id": int(self.site_id),
1091+
"site_position": int(self.site_position),
1092+
"derived_state": self.derived_state,
1093+
"inherited_state": self.inherited_state,
1094+
"is_reversion": self.is_reversion,
1095+
"is_immediate_reversion": self.is_immediate_reversion,
1096+
}
1097+
10741098

10751099
def update_path_info(samples, ts, sample_paths, sample_mutations):
10761100
tables = ts.tables

0 commit comments

Comments
 (0)