Skip to content

Commit 9021d84

Browse files
committed
Allow confounder to be non for mulitlevel_modeling
Signed-off-by: zethson <[email protected]>
1 parent ec4fb3a commit 9021d84

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pertpy/tools/_dialogue.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,13 @@ def _get_top_cor(
317317
def _apply_HLM_per_MCP_for_one_pair(
318318
self,
319319
mcp_name: str,
320-
scores_df: dict,
320+
scores_df: pd.DataFrame,
321321
ct_data: AnnData,
322322
tme: pd.DataFrame,
323323
sig: dict,
324324
n_counts: str,
325325
formula: str,
326-
confounder: str,
326+
confounder: str | None,
327327
) -> tuple[pd.DataFrame, dict[str, Any]]:
328328
"""Applies hierarchical modeling for a single MCP.
329329
@@ -344,7 +344,7 @@ def _apply_HLM_per_MCP_for_one_pair(
344344
"""
345345
HLM_result = self._mixed_effects(
346346
scores=scores_df[[mcp_name]],
347-
x_labels=ct_data.obs[[n_counts, confounder]],
347+
x_labels=ct_data.obs[[n_counts, confounder]] if confounder else ct_data.obs[[n_counts]],
348348
tme=tme,
349349
genes_in_mcp=list(sig[mcp_name]["up"]) + list(sig[mcp_name]["down"]),
350350
formula=formula,
@@ -678,7 +678,7 @@ def multilevel_modeling(
678678
ct_subs: dict,
679679
mcp_scores: dict,
680680
ws_dict: dict,
681-
confounder: str,
681+
confounder: str | None,
682682
formula: str = None,
683683
):
684684
"""Runs the multilevel modeling step to match genes to MCPs and generate p-values for MCPs.
@@ -706,7 +706,7 @@ def multilevel_modeling(
706706
>>> all_results, new_mcps = dl.multilevel_modeling(ct_subs=ct_subs, mcp_scores=mcps, ws_dict=ws, \
707707
confounder="gender")
708708
"""
709-
# all possible pairs of cell types with out pairing same cell type
709+
# all possible pairs of cell types without pairing same cell type
710710
cell_types = list(ct_subs.keys())
711711
pairs = list(itertools.combinations(cell_types, 2))
712712

@@ -716,7 +716,7 @@ def multilevel_modeling(
716716
# Hierarchical modeling expects DataFrames
717717
mcp_cell_types = {f"MCP{i + 1}": cell_types for i in range(self.n_mcps)}
718718
mcp_scores_df = {
719-
ct: pd.DataFrame(v, index=ct_subs[ct].obs.index, columns=mcp_cell_types.keys())
719+
ct: pd.DataFrame(v, index=ct_subs[ct].obs.index, columns=list(mcp_cell_types.keys()))
720720
for ct, v in mcp_scores.items()
721721
}
722722

0 commit comments

Comments
 (0)