Skip to content

Commit

Permalink
Rejig the flags values
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromekelleher committed Dec 12, 2024
1 parent 058fca7 commit 376e51d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
18 changes: 2 additions & 16 deletions sc2ts/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
NODE_IS_RECOMBINANT = 1 << 23
NODE_IS_EXACT_MATCH = 1 << 24
NODE_IS_IMMEDIATE_REVERSION_MARKER = 1 << 25
NODE_IN_SAMPLE_GROUP = 1 << 26
NODE_IN_RETROSPECTIVE_SAMPLE_GROUP = 1 << 27
NODE_IS_REFERENCE = 1 << 28
NODE_IS_UNCONDITIONALLY_INCLUDED = 1 << 29
NODE_IS_REFERENCE = 1 << 26
NODE_IS_UNCONDITIONALLY_INCLUDED = 1 << 27


@dataclasses.dataclass(frozen=True)
Expand Down Expand Up @@ -77,18 +75,6 @@ class FlagValue:
"Node is marking the existance of an immediate reversion which "
"has not been removed for technical reasons",
),
FlagValue(
NODE_IN_SAMPLE_GROUP,
"G",
"SampleGroup",
"Node is a member of a sample group",
),
FlagValue(
NODE_IN_RETROSPECTIVE_SAMPLE_GROUP,
"Q",
"RetroSampleGroup",
"Node is a member of a retrospective sample group",
),
FlagValue(
NODE_IS_REFERENCE,
"F",
Expand Down
11 changes: 4 additions & 7 deletions sc2ts/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,7 @@ def node_counts(self):
pr_nodes = np.sum(self.ts.nodes_flags == core.NODE_IS_REVERSION_PUSH)
re_nodes = np.sum(self.ts.nodes_flags == core.NODE_IS_RECOMBINANT)
exact_matches = np.sum((self.ts.nodes_flags & core.NODE_IS_EXACT_MATCH) > 0)
sg_nodes = np.sum((self.ts.nodes_flags & core.NODE_IN_SAMPLE_GROUP) > 0)
rsg_nodes = np.sum(
(self.ts.nodes_flags & core.NODE_IN_RETROSPECTIVE_SAMPLE_GROUP) > 0
)
u_nodes = np.sum((self.ts.nodes_flags & core.NODE_IS_UNCONDITIONALLY_INCLUDED) > 0)
immediate_reversion_marker = np.sum(
(self.ts.nodes_flags & core.NODE_IS_IMMEDIATE_REVERSION_MARKER) > 0
)
Expand All @@ -484,8 +481,7 @@ def node_counts(self):
"mc": mc_nodes,
"pr": pr_nodes,
"re": re_nodes,
"sg": sg_nodes,
"rsg": rsg_nodes,
"u": u_nodes,
"imr": immediate_reversion_marker,
"zero_muts": nodes_with_zero_muts,
}
Expand Down Expand Up @@ -734,6 +730,8 @@ def summary(self):
),
("max_samples_per_day", np.max(self.num_samples_per_day)),
("mean_samples_per_day", np.mean(self.num_samples_per_day)),
("sample_groups", len(self.sample_group_nodes)),
("retro_sample_groups", len(self.retro_sample_groups)),
]
df = pd.DataFrame(
{"property": [d[0] for d in data], "value": [d[1] for d in data]}
Expand Down Expand Up @@ -937,7 +935,6 @@ def retro_sample_groups_summary(self):
data.append(d)
return pd.DataFrame(data).set_index("group_id")


def recombinants_summary(self):
data = []
for u in self.recombinants:
Expand Down
8 changes: 7 additions & 1 deletion tests/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,19 @@ def test_node_summary(self, fx_ti_2020_02_13):
for u in range(ti.ts.num_nodes):
d = ti._node_summary(u)
assert d["node"] == u
assert len(d["flags"]) == 10
assert len(d["flags"]) == 8

def test_node_report(self, fx_ti_2020_02_13):
ti = fx_ti_2020_02_13
report = ti.node_report(strain="SRR11597190")
assert len(report) > 0

def test_summary(self, fx_ti_2020_02_15):
df = fx_ti_2020_02_15.summary()
assert df.loc["samples"].value == 43
assert df.loc["sample_groups"].value == 27
assert df.loc["retro_sample_groups"].value == 1


class TestSampleGroupInfo:
def test_draw_svg(self, fx_ti_2020_02_13):
Expand Down

0 comments on commit 376e51d

Please sign in to comment.