Skip to content

Commit

Permalink
Allow confounder to be non for mulitlevel_modeling
Browse files Browse the repository at this point in the history
Signed-off-by: zethson <lukas.heumos@posteo.net>
  • Loading branch information
Zethson committed Jan 6, 2024
1 parent ec4fb3a commit 9021d84
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pertpy/tools/_dialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,13 @@ def _get_top_cor(
def _apply_HLM_per_MCP_for_one_pair(
self,
mcp_name: str,
scores_df: dict,
scores_df: pd.DataFrame,
ct_data: AnnData,
tme: pd.DataFrame,
sig: dict,
n_counts: str,
formula: str,
confounder: str,
confounder: str | None,
) -> tuple[pd.DataFrame, dict[str, Any]]:
"""Applies hierarchical modeling for a single MCP.
Expand All @@ -344,7 +344,7 @@ def _apply_HLM_per_MCP_for_one_pair(
"""
HLM_result = self._mixed_effects(
scores=scores_df[[mcp_name]],
x_labels=ct_data.obs[[n_counts, confounder]],
x_labels=ct_data.obs[[n_counts, confounder]] if confounder else ct_data.obs[[n_counts]],
tme=tme,
genes_in_mcp=list(sig[mcp_name]["up"]) + list(sig[mcp_name]["down"]),
formula=formula,
Expand Down Expand Up @@ -678,7 +678,7 @@ def multilevel_modeling(
ct_subs: dict,
mcp_scores: dict,
ws_dict: dict,
confounder: str,
confounder: str | None,
formula: str = None,
):
"""Runs the multilevel modeling step to match genes to MCPs and generate p-values for MCPs.
Expand Down Expand Up @@ -706,7 +706,7 @@ def multilevel_modeling(
>>> all_results, new_mcps = dl.multilevel_modeling(ct_subs=ct_subs, mcp_scores=mcps, ws_dict=ws, \
confounder="gender")
"""
# all possible pairs of cell types with out pairing same cell type
# all possible pairs of cell types without pairing same cell type
cell_types = list(ct_subs.keys())
pairs = list(itertools.combinations(cell_types, 2))

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

Expand Down

0 comments on commit 9021d84

Please sign in to comment.