@@ -317,13 +317,13 @@ def _get_top_cor(
317
317
def _apply_HLM_per_MCP_for_one_pair (
318
318
self ,
319
319
mcp_name : str ,
320
- scores_df : dict ,
320
+ scores_df : pd . DataFrame ,
321
321
ct_data : AnnData ,
322
322
tme : pd .DataFrame ,
323
323
sig : dict ,
324
324
n_counts : str ,
325
325
formula : str ,
326
- confounder : str ,
326
+ confounder : str | None ,
327
327
) -> tuple [pd .DataFrame , dict [str , Any ]]:
328
328
"""Applies hierarchical modeling for a single MCP.
329
329
@@ -344,7 +344,7 @@ def _apply_HLM_per_MCP_for_one_pair(
344
344
"""
345
345
HLM_result = self ._mixed_effects (
346
346
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 ]] ,
348
348
tme = tme ,
349
349
genes_in_mcp = list (sig [mcp_name ]["up" ]) + list (sig [mcp_name ]["down" ]),
350
350
formula = formula ,
@@ -678,7 +678,7 @@ def multilevel_modeling(
678
678
ct_subs : dict ,
679
679
mcp_scores : dict ,
680
680
ws_dict : dict ,
681
- confounder : str ,
681
+ confounder : str | None ,
682
682
formula : str = None ,
683
683
):
684
684
"""Runs the multilevel modeling step to match genes to MCPs and generate p-values for MCPs.
@@ -706,7 +706,7 @@ def multilevel_modeling(
706
706
>>> all_results, new_mcps = dl.multilevel_modeling(ct_subs=ct_subs, mcp_scores=mcps, ws_dict=ws, \
707
707
confounder="gender")
708
708
"""
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
710
710
cell_types = list (ct_subs .keys ())
711
711
pairs = list (itertools .combinations (cell_types , 2 ))
712
712
@@ -716,7 +716,7 @@ def multilevel_modeling(
716
716
# Hierarchical modeling expects DataFrames
717
717
mcp_cell_types = {f"MCP{ i + 1 } " : cell_types for i in range (self .n_mcps )}
718
718
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 () ))
720
720
for ct , v in mcp_scores .items ()
721
721
}
722
722
0 commit comments