-
Notifications
You must be signed in to change notification settings - Fork 0
Parse data #28
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
Parse data #28
Changes from all commits
4d2386e
511bb1b
6891983
0a19c53
c46f7c9
678dd24
732989c
f93781e
af62abe
ab1c69d
1988607
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aarmey I have just been building this figure to test out the regularization. I have a decomposition at rank 100 saved as "/home/nicoleb/ParsePf2_100_D11_filt.h5ad" then calling deconvolution_cytokine where the alpha(regularization strength) can be adjusted. The deconvoluted matrix, original matrix, and convolution matrix is plotted out. It should also print out the MSE at every 100 iterations and final sparsity. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """ | ||
| Parse data: Plotting factors | ||
| """ | ||
|
|
||
| import numpy as np | ||
nbedanova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import pandas as pd | ||
| import seaborn as sns | ||
| from anndata import read_h5ad | ||
| from matplotlib import pyplot as plt | ||
|
|
||
| from ..factorization import correct_conditions, deconvolution_cytokine | ||
| from .common import getSetup, subplotLabel | ||
| from .commonFuncs.plotFactors import ( | ||
| plot_condition_factors, | ||
| ) | ||
|
|
||
|
|
||
| def samples_only(X) -> pd.DataFrame: | ||
| """Obtain samples once only with corresponding observations""" | ||
| samples = X.obs | ||
| df_samples = samples.drop_duplicates(subset="condition_unique_idxs") | ||
| df_samples = df_samples.sort_values("condition_unique_idxs") | ||
| return df_samples | ||
|
|
||
|
|
||
| def makeFigure(): | ||
| """Get a list of the axis objects and create a figure.""" | ||
| # Get list of axis objects | ||
| ax, f = getSetup((22, 15), (1, 3)) | ||
|
|
||
| # Add subplot labels | ||
| subplotLabel(ax) | ||
|
|
||
| # Load data | ||
| X = read_h5ad("/home/nicoleb/ParsePf2_100_D11_filt.h5ad") | ||
nbedanova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| X.uns["Pf2_A"] = correct_conditions(X) | ||
|
|
||
| W, H = deconvolution_cytokine(X.uns["Pf2_A"], alpha=1e-1, max_iter=5000) | ||
|
|
||
| # Get cytokine names in correct order | ||
| samples_df = samples_only(X) | ||
|
|
||
| # Create deconvolved version for plotting | ||
| X_deconv = X.copy() | ||
| X_deconv.uns["Pf2_A"] = H # Use primary effects only | ||
|
|
||
| plot_condition_factors( | ||
| X_deconv, | ||
| ax[0], | ||
| samples_df["cytokine"], | ||
| groupConditions=True, | ||
| cond="cytokine", | ||
| log_scale=False, | ||
| ) | ||
| ax[0].set_title("Deconvolved matrix (H)", fontsize=12, fontweight="bold") | ||
|
|
||
| plot_condition_factors( | ||
| X, | ||
| ax[1], | ||
| samples_df["cytokine"], | ||
| groupConditions=True, | ||
| cond="cytokine", | ||
| log_scale=False, | ||
| ) | ||
| ax[1].set_title("Original Effects (A)", fontsize=12, fontweight="bold") | ||
|
|
||
| cytokine_names = samples_df["cytokine"].values | ||
|
|
||
| # Plot 2: W heatmap (primary effects) | ||
| sns.heatmap( | ||
| W, | ||
| ax=ax[2], | ||
| cmap="YlOrRd", | ||
| robust=True, | ||
| square=True, | ||
| cbar_kws={"label": "Signaling Strength"}, | ||
| xticklabels=cytokine_names, | ||
| yticklabels=cytokine_names, | ||
| ) | ||
| ax[2].set_title("Cytokine Signaling (W)", fontsize=12, fontweight="bold") | ||
| ax[2].set_xlabel("Inducing Cytokine →", fontsize=10) | ||
| ax[2].set_ylabel("← Induced Cytokine", fontsize=10) | ||
| plt.setp(ax[2].get_xticklabels(), rotation=90, ha="center", fontsize=6) | ||
| plt.setp(ax[2].get_yticklabels(), rotation=0, fontsize=6) | ||
|
|
||
| return f | ||
Uh oh!
There was an error while loading. Please reload this page.