Skip to content

Commit

Permalink
figure s7
Browse files Browse the repository at this point in the history
  • Loading branch information
armaan-abraham committed Feb 2, 2024
1 parent 1759172 commit 54d3779
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 106 deletions.
11 changes: 7 additions & 4 deletions ddmc/figures/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ def get_pvals_across_clusters(
label: pd.Series | np.ndarray[bool], centers: pd.DataFrame | np.ndarray
) -> np.ndarray[float]:
pvals = []
if isinstance(centers, pd.DataFrame):
centers = centers.values
centers_pos = centers[label]
centers_neg = centers[~label]
for i in range(centers.shape[1]):
Expand All @@ -212,14 +214,15 @@ def get_pvals_across_clusters(


def plot_p_signal_across_clusters_and_binary_feature(
label: pd.Series | np.ndarray[bool],
feature: pd.Series | np.ndarray[bool],
centers: pd.DataFrame | np.ndarray,
label_name: str,
ax,
) -> None:
centers = centers.copy()
centers[label_name] = label
df_violin = centers.reset_index().melt(
centers_labeled = centers.copy()
centers_labeled[label_name] = feature
df_violin = centers_labeled.reset_index().melt(
id_vars=label_name,
value_vars=centers.columns,
value_name="p-signal",
Expand All @@ -236,7 +239,7 @@ def plot_p_signal_across_clusters_and_binary_feature(
)
ax.legend(prop={"size": 8})
annotation_height = df_violin["p-signal"].max() + 0.02
for i, pval in enumerate(get_pvals_across_clusters(label, centers)):
for i, pval in enumerate(get_pvals_across_clusters(feature, centers)):
if pval < 0.05:
annotation = "*"
elif pval < 0.01:
Expand Down
100 changes: 0 additions & 100 deletions ddmc/figures/figureMS6.py

This file was deleted.

58 changes: 58 additions & 0 deletions ddmc/figures/figureMS7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import numpy as np
from sklearn.linear_model import LogisticRegressionCV
from sklearn.preprocessing import StandardScaler

from ddmc.clustering import DDMC
from ddmc.datasets import CPTAC, select_peptide_subset
from ddmc.figures.common import (
plot_cluster_kinase_distances,
plot_p_signal_across_clusters_and_binary_feature,
getSetup,
)
from ddmc.logistic_regression import plot_roc, plot_cluster_regression_coefficients


def makeFigure():
axes, f = getSetup((11, 7), (2, 3), multz={0: 1})
cptac = CPTAC()
p_signal = select_peptide_subset(cptac.get_p_signal(), keep_num=50)
stk11m = cptac.get_mutations(["STK11.mutation.status"])["STK11.mutation.status"]

model = DDMC(n_components=30, seq_weight=100).fit(p_signal)
centers = model.transform(as_df=True)
centers = centers.loc[stk11m.index]
plot_p_signal_across_clusters_and_binary_feature(
stk11m.values, centers, "STK11M", axes[0]
)

centers.iloc[:, :] = StandardScaler(with_std=False).fit_transform(
centers.iloc[:, :]
)

# Logistic Regression
lr = LogisticRegressionCV(
cv=5,
solver="saga",
max_iter=10000,
n_jobs=-1,
penalty="l1",
class_weight="balanced",
random_state=10,
)

plot_roc(
lr, centers.values, stk11m.values, cv_folds=4, title="ROC STK11", ax=axes[1]
)

plot_cluster_regression_coefficients(
axes[2],
lr,
)

top_clusters = np.argsort(np.abs(lr.coef_.squeeze()))[-3:]
plot_cluster_kinase_distances(
model.predict_upstream_kinases()[top_clusters],
model.get_pssms(PsP_background=True, clusters=top_clusters)[0],
ax=axes[3],
)
return f
4 changes: 2 additions & 2 deletions ddmc/logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sklearn.metrics import RocCurveDisplay
from sklearn.model_selection import StratifiedKFold, RepeatedKFold

def plot_cluster_regression_coefficients(ax: Axes, lr, hue=None, xlabels=False, title=False):
def plot_cluster_regression_coefficients(ax: Axes, lr, hue=None, title=False):
"""Plot LR coeficients of clusters."""
coefs_ = pd.DataFrame(lr.coef_.T, columns=["LR Coefficient"])
if hue:
Expand All @@ -20,7 +20,7 @@ def plot_cluster_regression_coefficients(ax: Axes, lr, hue=None, xlabels=False,
hue = "Sample"
else:
coefs_["Cluster"] = np.arange(coefs_.shape[0])
if xlabels:
if xlabels is not None:
coefs_["Cluster"] = xlabels
p = sns.barplot(
ax=ax,
Expand Down

0 comments on commit 54d3779

Please sign in to comment.