Skip to content

Commit

Permalink
Fixed figure2, figure2 still in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel-github committed May 31, 2024
1 parent 9de5e69 commit f00c15c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions spatialpf2/figures/commonFuncs/plotFactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def plot_condition_factors(
yt = pd.Series(np.unique(data.obs["Condition"]))
X = np.array(data.uns["Pf2_A"])

X = np.log10(X)

X -= np.median(X, axis=0)
X /= np.std(X, axis=0)

X = np.log10(X)

ind = reorder_table(X)
X = X[ind]
yt = yt.iloc[ind]
Expand Down
19 changes: 12 additions & 7 deletions spatialpf2/figures/figure2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@
from ..imports import import_HTAN
from ..factorization import pf2
from .commonFuncs.plotFactors import (
bot_top_genes
plot_gene_factors_partial
)
import pandas as pd


def makeFigure():
ax, f = getSetup((10, 12), (4, 5))
ax, f = getSetup((10, 12), (8, 5))

rank = 20
X = import_HTAN()

X = pf2(X, rank, doEmbedding=False)

for i in range(rank):
genes = bot_top_genes(X, i+1)
df = pd.DataFrame(
data=X.varm["Pf2_C"][:, i], index=X.var_names, columns=["Component"]
)
ax[i].barh(genes, df.loc[genes, "Component"])
plot_gene_factors_partial(i + 1, X, ax[i])
ax[i].set(title=f"Component {i+1}")
ax[i].set_xlabel("Gene")
ax[i].set_ylabel("Weight")

for i in range(rank, 2 * rank):
plot_gene_factors_partial(i - rank + 1, X, ax[i], top=False)
ax[i].set(title=f"Component {i - rank + 1}")
ax[i].set_xlabel("Gene")
ax[i].set_ylabel("Weight")

return f

0 comments on commit f00c15c

Please sign in to comment.