Skip to content

Commit

Permalink
Refactoring DIALOGUE
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 93e5db6 commit 00052a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/tutorials/notebooks
13 changes: 7 additions & 6 deletions pertpy/tools/_dialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import numpy as np
import pandas as pd
import scanpy as sc
import scipy
import seaborn as sns
import statsmodels.formula.api as smf
import statsmodels.stats.multitest as ssm
Expand Down Expand Up @@ -70,9 +71,9 @@ def _get_pseudobulks(
for category in adata.obs.loc[:, groupby].cat.categories:
temp = adata.obs.loc[:, groupby] == category
if strategy == "median":
pseudobulk[category] = adata[temp].X.median(axis=0).A1
pseudobulk[category] = adata[temp].X.median(axis=0)
elif strategy == "mean":
pseudobulk[category] = adata[temp].X.mean(axis=0).A1
pseudobulk[category] = adata[temp].X.mean(axis=0)

pseudobulk = pd.DataFrame(pseudobulk).set_index("Genes")

Expand Down Expand Up @@ -517,8 +518,8 @@ def _pcor_mat(v1, v2, v3, method="spearman"):
# TODO: probably format the up and down within get_top_elements
cca_sig: dict[str, Any] = defaultdict(dict)
for i in range(0, int(len(cca_sig_unformatted) / 2)):
cca_sig[f"MCP{i + 1}"]["up"] = cca_sig_unformatted[i * 2]
cca_sig[f"MCP{i + 1}"]["down"] = cca_sig_unformatted[i * 2 + 1]
cca_sig[f"MCP{i}"]["up"] = cca_sig_unformatted[i * 2]
cca_sig[f"MCP{i}"]["down"] = cca_sig_unformatted[i * 2 + 1]

cca_sig = dict(cca_sig)
cca_sig_results[ct] = cca_sig
Expand Down Expand Up @@ -710,7 +711,7 @@ def multilevel_modeling(
formula = f"y ~ x + {self.n_counts_key}"

# Hierarchical modeling expects DataFrames
mcp_cell_types = {f"MCP{i + 1}": cell_types for i in range(self.n_mcps)}
mcp_cell_types = {f"MCP{i}": cell_types for i in range(self.n_mcps)}
mcp_scores_df = {
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 Expand Up @@ -1055,7 +1056,7 @@ def get_extrema_MCP_genes(self, ct_subs: dict, fraction: float = 0.1):
rank_dfs[mcp] = {}
ct_ranked = self._get_extrema_MCP_genes_single(ct_subs, mcp=mcp, fraction=fraction)
for celltype in ct_ranked.keys():
rank_dfs[mcp][celltype] = sc.get.rank_genes_groups_df(ct_ranked[celltype])
rank_dfs[mcp][celltype] = sc.get.rank_genes_groups_df(ct_ranked[celltype], group=None)

return rank_dfs

Expand Down

0 comments on commit 00052a4

Please sign in to comment.