ddmc.clustering¶
The core DDMC model and its supporting functions.
ddmc.clustering ¶
Dual data and motif clustering (DDMC).
Contains the DDMC model itself — a sklearn.mixture.GaussianMixture
subclass that jointly clusters peptides on their phosphorylation signal and
their sequence motif — and get_pspl_pssm_distances, the helper it uses to
compare cluster motifs against kinase specificity profiles.
DDMC ¶
DDMC(
n_components: int,
seq_weight: float,
distance_method: Literal[
"PAM250", "Binomial"
] = "Binomial",
random_state: int | RandomState | None = None,
max_iter: int = 200,
tol: float = 0.0001,
)
Bases: GaussianMixture
Cluster peptides by both sequence similarity and condition-wise phosphorylation following an expectation-maximization algorithm.
DDMC subclasses sklearn.mixture.GaussianMixture and reuses its EM
loop, but scores each peptide against each cluster using both the usual
Gaussian mixture log-probability over its phosphorylation signal and a
sequence-motif term (weighted by seq_weight), and refits both the
Gaussian mixture parameters and the per-cluster sequence motif at every
M step. See ddmc.binomial.Binomial and ddmc.pam250.PAM250 for the
two available motif models.
Attributes set by fit:
p_signal: The p_signal DataFrame passed to fit.
sequences: p_signal.index, as an upper-cased numpy array.
seq_dist: The fitted Binomial or PAM250 sequence-distance model.
scores_: Per-peptide, per-cluster responsibilities (soft cluster
assignments) of shape (n_peptides, n_components).
seq_scores_: Per-peptide, per-cluster weighted sequence
log-probabilities (seq_weight * seq_dist.logWeights) from the
last E step, of shape (n_peptides, n_components).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_components
|
int
|
The number of clusters to fit. |
required |
seq_weight
|
float
|
Weight applied to the sequence-motif log-probability
relative to the Gaussian mixture log-probability when
scoring each peptide against each cluster. |
required |
distance_method
|
Literal['PAM250', 'Binomial']
|
Which sequence-distance model to use for the
motif term: |
'Binomial'
|
random_state
|
int | RandomState | None
|
Seed or |
None
|
max_iter
|
int
|
Maximum number of EM iterations to run. |
200
|
tol
|
float
|
Convergence threshold on the change in per-sample average log-likelihood between EM iterations. |
0.0001
|
Source code in ddmc/clustering.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
fit ¶
fit(p_signal: DataFrame) -> DDMC
Compute EM clustering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_signal
|
DataFrame
|
Dataframe of shape (number of peptides, number of samples)
containing the phosphorylation signal. |
required |
Returns:
| Type | Description |
|---|---|
DDMC
|
self, fit to |
Source code in ddmc/clustering.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_nonempty_clusters ¶
get_nonempty_clusters() -> np.ndarray
List the clusters that at least one peptide is assigned to.
Returns:
| Type | Description |
|---|---|
ndarray
|
Sorted array of the distinct cluster indices present in |
ndarray
|
|
ndarray
|
are empty. |
Source code in ddmc/clustering.py
372 373 374 375 376 377 378 379 380 | |
get_pssms ¶
get_pssms(
PsP_background: bool = False, clusters: None = None
) -> tuple[np.ndarray, np.ndarray]
get_pssms(
PsP_background: bool = False, *, clusters: list[int]
) -> np.ndarray
get_pssms(
PsP_background: bool = False,
clusters: list[int] | None = None,
) -> tuple[np.ndarray, np.ndarray] | np.ndarray
Compute position-specific scoring matrix of each cluster. Note, to normalize by amino acid frequency this uses either all the sequences in the data set or a collection of random MS phosphosites in PhosphoSitePlus.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
PsP_background
|
bool
|
Whether or not PhosphoSitePlus should be used for background frequency. |
False
|
clusters
|
list[int] | None
|
cluster indices to get pssms for |
None
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray] | ndarray
|
If the clusters argument is used, an array of shape (len(clusters), 20, 11), |
tuple[ndarray, ndarray] | ndarray
|
else two arrays, where the first (of shape (n_pssms,)) |
tuple[ndarray, ndarray] | ndarray
|
contains the clusters of the pssms in the second |
tuple[ndarray, ndarray] | ndarray
|
(of shape (n_pssms, 20, 11)). |
Source code in ddmc/clustering.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
has_empty_clusters ¶
has_empty_clusters() -> bool
Checks whether the most recent call to fit() resulted in empty clusters.
Returns:
| Type | Description |
|---|---|
bool
|
True if any of the |
bool
|
assigned to it. |
Source code in ddmc/clustering.py
382 383 384 385 386 387 388 389 390 391 | |
impute ¶
impute() -> pd.DataFrame
Imputes missing values in the dataset passed in fit() and returns the imputed dataset.
Returns:
| Type | Description |
|---|---|
DataFrame
|
A copy of the |
DataFrame
|
missing samples filled in from its assigned cluster's center. |
Source code in ddmc/clustering.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
labels ¶
labels() -> np.ndarray
Find cluster assignment with highest likelihood for each peptide.
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of shape (n_peptides,) giving each peptide's cluster |
ndarray
|
index. Equivalent to |
Source code in ddmc/clustering.py
403 404 405 406 407 408 409 410 | |
predict ¶
predict() -> np.ndarray
Provided the current model parameters, predict the cluster each peptide belongs to.
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of shape (n_peptides,) giving the index of the |
ndarray
|
highest-likelihood cluster for each peptide in |
Source code in ddmc/clustering.py
393 394 395 396 397 398 399 400 401 | |
predict_upstream_kinases ¶
predict_upstream_kinases(
PsP_background: bool = True,
) -> pd.DataFrame
Compute matrix-matrix similarity between kinase specificity profiles and cluster PSSMs to identify upstream kinases regulating clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
PsP_background
|
bool
|
Whether or not PhosphoSitePlus should be used
for the background amino acid frequency when building each
cluster's PSSM (see |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame of shape (n_kinases, n_nonempty_clusters) with a |
DataFrame
|
Frobenius distance between each kinase's specificity profile and |
DataFrame
|
each cluster's PSSM; smaller values indicate a better match. |
Source code in ddmc/clustering.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
score ¶
score() -> float
Generate score of the fitting.
Returns:
| Type | Description |
|---|---|
float
|
The lower bound on the log-likelihood of the fitted model |
float
|
( |
Source code in ddmc/clustering.py
412 413 414 415 416 417 418 419 420 | |
transform ¶
transform(as_df: Literal[False] = False) -> np.ndarray
transform(as_df: Literal[True]) -> pd.DataFrame
transform(as_df: bool = False) -> np.ndarray | pd.DataFrame
Return cluster centers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
as_df
|
bool
|
Whether or not the result should be wrapped in a dataframe with labeled axes. |
False
|
Returns:
| Type | Description |
|---|---|
ndarray | DataFrame
|
The cluster centers, either a np array or pd df of shape (n_samples, n_components). |
Source code in ddmc/clustering.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
get_pspl_pssm_distances ¶
get_pspl_pssm_distances(
pspls: ndarray,
pssms: ndarray,
as_df: Literal[False] = False,
pssm_names: Sequence | ndarray | None = None,
kinases: Sequence | ndarray | None = None,
) -> np.ndarray
get_pspl_pssm_distances(
pspls: ndarray,
pssms: ndarray,
as_df: Literal[True],
pssm_names: Sequence | ndarray | None = None,
kinases: Sequence | ndarray | None = None,
) -> pd.DataFrame
get_pspl_pssm_distances(
pspls: ndarray,
pssms: ndarray,
as_df: bool = False,
pssm_names: Sequence | ndarray | None = None,
kinases: Sequence | ndarray | None = None,
) -> np.ndarray | pd.DataFrame
Computes a distance matrix between PSPLs and PSSMs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pspls
|
ndarray
|
kinase specificity profiles of shape (n_kinase, 20, 9) |
required |
pssms
|
ndarray
|
position-specific scoring matrices of shape (n_pssms, 20, 11) |
required |
as_df
|
bool
|
Whether or not the returned matrix should be returned as a dataframe. Requires pssm_names and kinases. |
False
|
pssm_names
|
Sequence | ndarray | None
|
list of names for the pssms of shape (n_pssms,) |
None
|
kinases
|
Sequence | ndarray | None
|
list of names for the pspls of shape (n_kinase,) |
None
|
Returns:
| Type | Description |
|---|---|
ndarray | DataFrame
|
Distance matrix of shape (n_kinase, n_pssms). |
Source code in ddmc/clustering.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |