Skip to content

Commit

Permalink
binarize motif activity
Browse files Browse the repository at this point in the history
  • Loading branch information
simonvh committed Dec 5, 2019
1 parent 3b923ec commit 07d1748
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions scepia/sc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
LogisticRegression,
LassoCV,
)
from sklearn.mixture import GaussianMixture
from sklearn.model_selection import KFold
from sklearn.preprocessing import scale
from sklearn.utils import shuffle
Expand Down Expand Up @@ -587,6 +588,8 @@ def infer_motifs(

correlate_tf_motifs(adata)

add_activity(adata)

return MotifAnnData(adata)


Expand Down Expand Up @@ -634,6 +637,20 @@ def correlate_tf_motifs(adata: AnnData) -> None:
adata.uns["motif"]["factor2motif"] = cor


def add_activity(adata: AnnData):
"""Get factor activity"""
gm = GaussianMixture(n_components=2, covariance_type="full")
f2m = adata.uns["motif"]["factor2motif"]
for factor in f2m["factor"].unique():
motif = (
f2m[f2m["factor"] == factor].sort_values("pval").head(1)["motif"].values[0]
)
gm.fit(adata.obs[motif].values.reshape(-1, 1) * 10)
adata.obs[f"{factor}_activity"] = gm.predict_proba(adata.obs[[motif]] * 10)[
:, gm.means_.argmax()
]


def assign_cell_types(adata: AnnData, min_annotated: int = 50) -> None:
adata.obs["cell_annotation"] = (
pd.Series(adata.uns["motif"]["cell_types"])
Expand Down

0 comments on commit 07d1748

Please sign in to comment.