Skip to content

ddmc.motifs

Helpers for mapping peptides to their surrounding sequence motif via a reference proteome, and for loading kinase specificity profiles (PSPLs) used by DDMC.predict_upstream_kinases.

ddmc.motifs

Mapping to Uniprot's Proteome To Generate +/-5AA p-site Motifs.

Contains
  • get_proteome_name_to_seq: parses a UniProt FASTA proteome into a {protein name: sequence} dictionary; used by ddmc.datasets.EBDT.
  • get_pspls: loads kinase specificity profiles (position-specific peptide libraries) from ddmc/data/PSPL/, used by ddmc.clustering.DDMC.predict_upstream_kinases.
  • compute_control_pssm: builds a background PSSM from a set of sequences, used by ddmc.clustering.DDMC.get_pssms.
  • KinToPhosphotypeDict: maps each kinase named in the PSPL data set to the phosphoacceptor type(s) it targets (S/T or Y).
  • make_motif, get_keys_by_value: helper utilities for motif slicing and reverse dictionary lookup.

KinToPhosphotypeDict module-attribute

KinToPhosphotypeDict = {
    "ABL": "Y",
    "AKT": "S/T",
    "ALK": "Y",
    "BLK": "Y",
    "BRK": "Y",
    "CK2": "S/T",
    "ERK2": "S/T",
    "FRK": "Y",
    "HCK": "Y",
    "INSR": "Y",
    "LCK": "Y",
    "LYN": "Y",
    "MET": "Y",
    "NEK1": "S/T",
    "NEK2": "S/T",
    "NEK3": "S/T",
    "NEK4": "S/T",
    "NEK5": "S/T",
    "NEK6": "S/T",
    "NEK7": "S/T",
    "NEK8": "S/T",
    "NEK9": "S/T",
    "NEK10_S": "S/T",
    "NEK10_Y": "Y",
    "PKA": "S/T",
    "PKC-theta": "S/T",
    "PKD": "S/T",
    "PLM2": "S/T",
    "RET": "Y",
    "SRC": "Y",
    "TbetaRII": "S/T",
    "YES": "Y",
    "BRCA1": "S/T",
    "AMPK": "S/T",
    "CDK5": "S/T",
    "CK1": "S/T",
    "DMPK1": "S/T",
    "EGFR": "Y",
    "InsR": "Y",
    "p38": "S/T",
    "ERK1": "S/T",
    "SHC1": "Y",
    "SH2_PLCG1": "Y",
    "SH2_INPP5D": "Y",
    "SH2_SH3BP2": "Y",
    "SH2_SHC2": "Y",
    "SH2_SHE": "Y",
    "SH2_Syk": "Y",
    "SH2_TNS4": "Y",
    "CLK2": "S/T",
    "DAPK3": "S/T",
    "ICK": "S/T",
    "STK11": "S/T",
    "MST1": "S/T",
    "MST4": "S/T",
    "PAK2": "S/T",
    "Pim1": "S/T",
    "Pim2": "S/T",
    "SLK": "S/T",
    "TGFbR2": "S/T",
    "TLK1": "S/T",
    "TNIK": "S/T",
    "p70S6K": "S/T",
    "EphA3": "Y",
}

get_proteome_name_to_seq

get_proteome_name_to_seq(
    X: IO[str], n: str
) -> dict[str, str]

Parse a UniProt FASTA proteome into a name-to-sequence dictionary.

Parameters:

Name Type Description Default
X IO[str]

An open file handle to a UniProt FASTA file.

required
n str

Which identifier to key the dictionary by: "full" for the full human-readable protein name (parsed out of the FASTA description between "HUMAN " and " OS"), or "gene" for the gene symbol (parsed out of the GN= field). Records without a GN= field are skipped when n == "gene".

required

Returns:

Type Description
dict[str, str]

Dictionary mapping protein name or gene symbol to its amino acid

dict[str, str]

sequence.

Source code in ddmc/motifs.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def get_proteome_name_to_seq(X: IO[str], n: str) -> dict[str, str]:
    """Parse a UniProt FASTA proteome into a name-to-sequence dictionary.

    Args:
        X: An open file handle to a UniProt FASTA file.
        n: Which identifier to key the dictionary by: `"full"` for the
            full human-readable protein name (parsed out of the FASTA
            description between `"HUMAN "` and `" OS"`), or `"gene"` for
            the gene symbol (parsed out of the `GN=` field). Records
            without a `GN=` field are skipped when `n == "gene"`.

    Returns:
        Dictionary mapping protein name or gene symbol to its amino acid
        sequence.
    """
    DictProtToSeq_UP = {}
    for rec2 in SeqIO.parse(X, "fasta"):
        UP_seq = str(rec2.seq)
        if n == "full":
            UP_name = rec2.description.split("HUMAN ")[1].split(" OS")[0]
            DictProtToSeq_UP[UP_name] = str(UP_seq)
        if n == "gene":
            try:
                UP_name = rec2.description.split(" GN=")[1].split(" ")[0]
                DictProtToSeq_UP[UP_name] = str(UP_seq)
            except BaseException:
                continue
    return DictProtToSeq_UP

get_pspls

get_pspls(
    source: Literal[
        "kinome_atlas", "legacy"
    ] = "kinome_atlas",
) -> tuple[np.ndarray, np.ndarray]

Load kinase specificity profiles (PSPLs) bundled in ddmc/data/PSPL/.

Parameters:

Name Type Description Default
source Literal['kinome_atlas', 'legacy']

"kinome_atlas" (default) loads the complete 404-kinase human Ser/Thr (Johnson et al. 2023) and Tyr (Yaron-Barir et al. 2024) PSPL atlas. "legacy" loads the original 63-kinase set from ddmc/data/PSPL/*.csv and pssm_data.csv.

'kinome_atlas'

Returns:

Type Description
tuple[ndarray, ndarray]

A tuple (kinases, pspls): kinases: Kinase name for each profile, of shape (n_kinases,). pspls: Specificity profile for each kinase, of shape (n_kinases, 20, 9), aligned to kinases and to AAlist along the amino acid axis.

Source code in ddmc/motifs.py
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
def get_pspls(
    source: Literal["kinome_atlas", "legacy"] = "kinome_atlas",
) -> tuple[np.ndarray, np.ndarray]:
    """Load kinase specificity profiles (PSPLs) bundled in `ddmc/data/PSPL/`.

    Args:
        source: `"kinome_atlas"` (default) loads the complete 404-kinase human
            Ser/Thr (Johnson et al. 2023) and Tyr (Yaron-Barir et al. 2024)
            PSPL atlas. `"legacy"` loads the original 63-kinase set from
            `ddmc/data/PSPL/*.csv` and `pssm_data.csv`.

    Returns:
        A tuple `(kinases, pspls)`:
            kinases: Kinase name for each profile, of shape (n_kinases,).
            pspls: Specificity profile for each kinase, of shape
                (n_kinases, 20, 9), aligned to `kinases` and to `AAlist`
                along the amino acid axis.
    """
    kinases, pspls = _load_pspls_cached(source)
    return kinases.copy(), pspls.copy()

compute_control_pssm

compute_control_pssm(
    bg_sequences: Sequence[str],
) -> np.ndarray

Build a background position-specific scoring matrix (PSSM) from a set of (typically random/background) sequences, for use as the normalizing background in ddmc.clustering.DDMC.get_pssms.

Parameters:

Name Type Description Default
bg_sequences Sequence[str]

Length-11 background peptide sequences, e.g. from ddmc.binomial.BackgroundSeqs.

required

Returns:

Type Description
ndarray

Array of shape (len(AAlist), 11) giving the log2 amino acid

ndarray

enrichment at each position, normalized per-position across

ndarray

residues.

Source code in ddmc/motifs.py
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
def compute_control_pssm(bg_sequences: Sequence[str]) -> np.ndarray:
    """Build a background position-specific scoring matrix (PSSM) from a set
    of (typically random/background) sequences, for use as the normalizing
    background in `ddmc.clustering.DDMC.get_pssms`.

    Args:
        bg_sequences: Length-11 background peptide sequences, e.g. from
            `ddmc.binomial.BackgroundSeqs`.

    Returns:
        Array of shape (len(AAlist), 11) giving the log2 amino acid
        enrichment at each position, normalized per-position across
        residues.
    """
    back_pssm = np.zeros((len(AAlist), 11), dtype=float)
    for _, seq in enumerate(bg_sequences):
        for kk, aa in enumerate(seq):
            back_pssm[AAlist.index(aa.upper()), kk] += 1.0
    for pos in range(back_pssm.shape[1]):
        back_pssm[:, pos] /= np.mean(back_pssm[:, pos])
    back_pssm = np.log2(back_pssm)
    return np.nan_to_num(back_pssm)