Skip to content

Made changes to liana code to update for decoupler-py 2.o #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/source/notebooks/bivariate.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@
],
"source": [
"# Get transcription factor resource\n",
"net = dc.get_collectri()"
"net = dc.op.collectri(organism='human', remove_complexes=False, license='academic', verbose=False)"
]
},
{
Expand Down Expand Up @@ -1665,7 +1665,7 @@
],
"source": [
"# run enrichment\n",
"dc.run_ulm(adata, net=net, use_raw=False, verbose=True)"
"dc.mt.ulm(adata, net=net, raw=False, verbose=True)"
]
},
{
Expand All @@ -1685,7 +1685,7 @@
"metadata": {},
"outputs": [],
"source": [
"est = li.ut.obsm_to_adata(adata, 'ulm_estimate')\n",
"est = li.ut.obsm_to_adata(adata, 'score_ulm')\n",
"est.var['cv'] = est.X.std(axis=0) / est.X.mean(axis=0)\n",
"top_tfs = est.var.sort_values('cv', ascending=False, key=abs).head(50).index\n"
]
Expand Down
16 changes: 8 additions & 8 deletions docs/source/notebooks/liana_c2c.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -1340,7 +1340,7 @@
],
"source": [
"# load PROGENy pathways\n",
"net = dc.get_progeny(organism='human', top=5000)"
"net = dc.op.progeny(organism='human', top=5000)"
]
},
{
Expand All @@ -1355,7 +1355,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1435,18 +1435,18 @@
],
"source": [
"# generate ligand-receptor geneset\n",
"lr_progeny = li.rs.generate_lr_geneset(lr_pairs, net, lr_sep=\"^\")\n",
"lr_progeny = li.rs.generate_lr_geneset(lr_pairs, net, lr_sep=\"^\").rename(columns = {\"interaction\": \"target\"})\n",
"lr_progeny.head()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# run enrichment analysis\n",
"estimate, pvals = dc.run_ulm(lr_loadings.transpose(), lr_progeny, source=\"source\", target=\"interaction\", use_raw=False)"
"estimate, pvals = dc.mt.ulm(lr_loadings.transpose(), lr_progeny, raw=False)"
]
},
{
Expand All @@ -1459,7 +1459,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -1474,7 +1474,7 @@
}
],
"source": [
"dc.plot_barplot(estimate, 'Factor 6', vertical=True, cmap='coolwarm', vmin=-7, vmax=7)"
"dc.pl.barplot(estimate, 'Factor 6', vertical=True, cmap='coolwarm', vmin=-7, vmax=7)"
]
},
{
Expand Down
31 changes: 14 additions & 17 deletions docs/source/notebooks/misty.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -562,12 +562,12 @@
],
"source": [
"# obtain genesets\n",
"progeny = dc.get_progeny(organism='human', top=500)"
"progeny = dc.op.progeny(organism='human', top=500)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -587,25 +587,22 @@
],
"source": [
"# use multivariate linear model to estimate activity\n",
"dc.run_mlm(\n",
"dc.mt.mlm(\n",
" mat=adata,\n",
" net=progeny,\n",
" source='source',\n",
" target='target',\n",
" weight='weight',\n",
" verbose=True,\n",
" use_raw=False,\n",
" raw=False\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# extract progeny activities as an AnnData object\n",
"acts_progeny = li.ut.obsm_to_adata(adata, 'mlm_estimate')"
"acts_progeny = li.ut.obsm_to_adata(adata, 'score_mlm')"
]
},
{
Expand Down Expand Up @@ -1300,17 +1297,17 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# get TF prior knowledge\n",
"net = dc.get_collectri()"
"net = dc.op.collectri(organism='human', remove_complexes=False, license='academic', verbose=False)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -1330,22 +1327,22 @@
],
"source": [
"# Estimate activities\n",
"dc.run_ulm(\n",
"dc.mt.ulm(\n",
" mat=adata,\n",
" net=net,\n",
" verbose=True,\n",
" use_raw=False,\n",
" raw=False\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# extract activities\n",
"acts_tfs = li.ut.obsm_to_adata(adata, 'ulm_estimate')"
"acts_tfs = li.ut.obsm_to_adata(adata, 'score_ulm')"
]
},
{
Expand Down
246 changes: 180 additions & 66 deletions docs/source/notebooks/mofacellular.ipynb

Large diffs are not rendered by default.

34 changes: 14 additions & 20 deletions docs/source/notebooks/mofatalk.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -953,23 +953,19 @@
}
],
"source": [
"dc.get_metadata_associations(\n",
"dc.tl.rankby_obsm(\n",
" mdata,\n",
" obs_keys = ['patient', 'condition'], # Metadata columns to associate to PCs\n",
" obsm_key='X_mofa', # Where the PCs are stored\n",
" uns_key='mofa_anova', # Where the results are stored\n",
" inplace=True,\n",
" key='X_mofa', # Where the PCs are stored\n",
" uns_key='rank_obsm', # Where the results are stored\n",
")\n",
"\n",
"dc.plot_associations(\n",
"dc.pl.obsm(\n",
" mdata,\n",
" uns_key='mofa_anova', # Summary statistics from the anova tests\n",
" obsm_key='X_mofa', # where the PCs are stored\n",
" stat_col='p_adj', # Which summary statistic to plot\n",
" obs_annotation_cols = ['patient', 'condition'], # which sample annotations to plot\n",
" key='rank_obsm',\n",
" names = ['patient', 'condition'], # which sample annotations to plot\n",
" titles=['Principle component scores', 'Adjusted p-values from ANOVA'],\n",
" figsize=(7, 5),\n",
" n_factors=10,\n",
" nvar=10\n",
")"
]
},
Expand Down Expand Up @@ -1532,7 +1528,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -1551,14 +1547,14 @@
],
"source": [
"# load PROGENy pathways\n",
"net = dc.get_progeny(organism='human', top=5000)\n",
"net = dc.op.progeny(organism='human', top=5000)\n",
"# load full list of ligand-receptor pairs\n",
"lr_pairs = li.resource.select_resource('consensus')"
]
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1638,7 +1634,7 @@
],
"source": [
"# generate ligand-receptor geneset\n",
"lr_progeny = li.rs.generate_lr_geneset(lr_pairs, net, lr_sep=\"^\")\n",
"lr_progeny = li.rs.generate_lr_geneset(lr_pairs, net, lr_sep=\"^\").rename(columns = {'interaction': 'target'})\n",
"lr_progeny.head()"
]
},
Expand Down Expand Up @@ -1897,14 +1893,12 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# run pathway enrichment analysis\n",
"estimate, pvals = dc.run_mlm(lr_loadings.transpose(), lr_progeny,\n",
" source=\"source\", target=\"interaction\",\n",
" use_raw=False, min_n=5)\n",
"estimate, pvals = dc.op.mlm(lr_loadings.transpose(), lr_progeny, raw=False, tmin=5)\n",
"# pivot columns to long\n",
"estimate = (estimate.\n",
" melt(ignore_index=False, value_name='estimate', var_name='pathway').\n",
Expand Down
10 changes: 5 additions & 5 deletions docs/source/notebooks/prior_knowledge.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -850,7 +850,7 @@
],
"source": [
"# load PROGENy pathways, we use decoupler as a proxy as it formats the data in a more convenient way\n",
"progeny = dc.get_progeny(top=2500)\n",
"progeny = dc.op.progeny(top=2500)\n",
"progeny.head()"
]
},
Expand All @@ -873,7 +873,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1412,7 +1412,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1497,7 +1497,7 @@
}
],
"source": [
"dc.get_collectri().head()"
"dc.op.collectri(organism='human', remove_complexes=False, license='academic', verbose=False).head()"
]
},
{
Expand Down
Loading
Loading