Sequence distance models¶
DDMC supports two interchangeable ways of scoring how well a peptide
sequence matches a cluster's motif, selected via DDMC(..., distance_method=...).
ddmc.binomial¶
ddmc.binomial ¶
Binomial sequence-distance model used by ddmc.clustering.DDMC.
Contains
AAfreq/AAlist: reference amino acid frequencies and the fixed amino acid ordering used throughout the package.- Position weight matrix helpers (
position_weight_matrix,fast_position_weight_matrix,frequencies,GenerateBinarySeqID). - Background phosphosite sequence sampling from PhosphoSitePlus
(
BackgroundSeqs,BackgProportions,CountPsiteTypes, and their cached loaders). - The
Binomialclass: for each cluster, models how enriched each amino acid is at each position (relative to the background) using the binomial-probability approach of Schwartz & Gygi, Nat Biotechnol 2005 (doi:10.1038/nbt1146), and scores every peptide sequence against each cluster's model.
Binomial ¶
Binomial(seqs: ndarray)
Binomial sequence-distance model, used by ddmc.clustering.DDMC when
distance_method="Binomial".
For each cluster, scores how enriched each amino acid is at each position of a peptide's sequence relative to a background distribution of phosphosites, following Schwartz & Gygi, Nat Biotechnol 2005 (doi:10.1038/nbt1146).
Attributes:
| Name | Type | Description |
|---|---|---|
background |
Background PWM (amino acid frequency per position) of
shape (len(AAlist), n_pos), built from |
|
n_aa |
Number of amino acids (len(AAlist)). |
|
n_pos |
Number of sequence positions (11). |
|
foreground_flat |
Flattened one-hot encoding of |
|
logWeights |
Log-probability of each sequence under each cluster's
current binomial model, of shape (n_seqs, n_clusters). Set to
the scalar |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seqs
|
ndarray
|
The length-11 peptide sequences being clustered. |
required |
Source code in ddmc/binomial.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
from_summaries ¶
from_summaries(weightsIn: ndarray) -> None
Refit each cluster's binomial model from the current soft cluster
assignments, and update self.logWeights with each sequence's
log-probability under its (updated) cluster model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weightsIn
|
ndarray
|
Soft cluster assignments (responsibilities) of shape
(n_seqs, n_clusters), i.e. |
required |
Source code in ddmc/binomial.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
BackgroundSeqs ¶
BackgroundSeqs(forseqs: ndarray) -> list[str]
Build a background data set of length-11 phosphosite motifs sampled from PhosphoSitePlus, matching the proportion of pY, pT, and pS sites found in the foreground set of sequences.
Note this PsP data set contains 51976 pY, 226131 pS, 81321 pT Source: https://www.phosphosite.org/staticDownloads.action - Phosphorylation_site_dataset.gz - Last mod: Wed Dec 04 14:56:35 EST 2019 Cite: Hornbeck PV, Zhang B, Murray B, Kornhauser JM, Latham V, Skrzypek E PhosphoSitePlus, 2014: mutations, PTMs and recalibrations. Nucleic Acids Res. 2015 43:D512-20. PMID: 25514926
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
forseqs
|
ndarray
|
The foreground peptide sequences whose pY/pS/pT proportions the background set should match. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Length-11 background peptide sequences sampled from PhosphoSitePlus, |
list[str]
|
with the phosphoacceptor lowercased, in pY/pS/pT order. |
Source code in ddmc/binomial.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 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 | |
BackgProportions ¶
BackgProportions(
refseqs: list[str], pYn: int, pSn: int, pTn: int
) -> list[str]
Slice length-11 motifs out of the +/-7 AA reference sequences, keeping up to the requested number of pY, pS, and pT sites.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
refseqs
|
list[str]
|
Raw +/-7 AA PhosphoSitePlus reference sequences. |
required |
pYn
|
int
|
Maximum number of pY motifs to keep. |
required |
pSn
|
int
|
Maximum number of pS motifs to keep. |
required |
pTn
|
int
|
Maximum number of pT motifs to keep. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The length-11 background motifs (phosphoacceptor lowercased), |
list[str]
|
concatenated in pY, pS, pT order. |
Source code in ddmc/binomial.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
CountPsiteTypes ¶
CountPsiteTypes(X) -> tuple[int, int, int]
Count the number of different phosphorylation types in an MS data set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
list[str]
|
The list of peptide sequences. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int, int]
|
tuple[int, int, int]: The number of pY, pS, and pT sites. |
Source code in ddmc/binomial.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
position_weight_matrix ¶
position_weight_matrix(
seqs: list[str],
pseudoC: OrderedDict[str, float] = AAfreq,
) -> Any
Build a position weight matrix (PWM) of a given set of same-length sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seqs
|
list[str]
|
Sequences (all the same length) to build the PWM from. |
required |
pseudoC
|
OrderedDict[str, float]
|
Per-amino-acid pseudocounts to add before normalizing,
keyed by one-letter amino acid code. Defaults to |
AAfreq
|
Returns:
| Type | Description |
|---|---|
Any
|
A Biopython |
Any
|
position, normalized to sum to 1 down each column) of shape |
Any
|
(len(AAlist), sequence length). |
Source code in ddmc/binomial.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
fast_position_weight_matrix ¶
fast_position_weight_matrix(seqs: list[str]) -> np.ndarray
Build a (len(AAlist), seq_length) PWM of a given set of same-length
sequences, equivalent to position_weight_matrix but without the
overhead of Biopython's general-purpose alignment machinery.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seqs
|
list[str]
|
Sequences, all of the same length, to build the PWM from. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of shape (len(AAlist), sequence length) giving the |
ndarray
|
pseudocount-smoothed frequency of each amino acid at each position. |
Source code in ddmc/binomial.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
frequencies ¶
frequencies(seqs: list[str]) -> Any
Build a per-position amino acid counts matrix of a given set of same-length sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seqs
|
list[str]
|
Sequences, all of the same length, to count. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A Biopython |
Any
|
amino acid at each position across |
Source code in ddmc/binomial.py
110 111 112 113 114 115 116 117 118 119 120 | |
GenerateBinarySeqID ¶
GenerateBinarySeqID(
seqs: list[str] | ndarray,
) -> np.ndarray
Build a one-hot encoding of amino acid identity at each position, for every sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seqs
|
list[str] | ndarray
|
Length-11 peptide sequences to encode. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Boolean array of shape (len(seqs), len(AAlist), 11), where |
ndarray
|
|
ndarray
|
at position |
Source code in ddmc/binomial.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
ddmc.pam250¶
ddmc.pam250 ¶
PAM250 sequence-distance model used by ddmc.clustering.DDMC.
Contains the PAM250 class, which scores peptide sequences against each
cluster by their average PAM250 substitution-matrix similarity to the other
sequences currently assigned to that cluster, and get_pam250_scores, which
precomputes the full pairwise PAM250 similarity matrix used to do so.
PAM250 ¶
PAM250(seqs: list[str])
PAM250 sequence-distance model, used by ddmc.clustering.DDMC when
distance_method="PAM250".
Scores each peptide sequence against a cluster by its (responsibility weighted) average pairwise PAM250 substitution score against every other sequence, using the fixed set of pairwise scores computed once at construction time.
Attributes:
| Name | Type | Description |
|---|---|---|
background |
Pairwise PAM250 similarity matrix between all input sequences, of shape (n_seqs, n_seqs). |
|
logWeights |
Log-probability (average PAM250 score) of each sequence
under each cluster's current model, of shape
(n_seqs, n_clusters). Set to the scalar |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seqs
|
list[str]
|
The length-11 peptide sequences being clustered. |
required |
Source code in ddmc/pam250.py
31 32 33 34 35 36 37 38 39 40 | |
from_summaries ¶
from_summaries(weightsIn: ndarray) -> None
Update self.logWeights with each sequence's responsibility
weighted average PAM250 similarity to all sequences, per cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weightsIn
|
ndarray
|
Soft cluster assignments (responsibilities) of shape
(n_seqs, n_clusters), i.e. |
required |
Source code in ddmc/pam250.py
42 43 44 45 46 47 48 49 50 51 52 | |
get_pam250_scores ¶
get_pam250_scores(seqs: list[str]) -> np.ndarray
Compute the full pairwise PAM250 similarity matrix between sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seqs
|
list[str]
|
Sequences (all the same length) to score pairwise. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Symmetric array of shape (len(seqs), len(seqs)), where entry |
ndarray
|
|
ndarray
|
|
Source code in ddmc/pam250.py
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 | |