mkt.databases.pssm.SubstitutionPseudocounts
- class mkt.databases.pssm.SubstitutionPseudocounts(matrix: str = 'BLOSUM62', beta: float = 10.0, background: ndarray | None = None)[source]
Bases:
objectSubstitution-aware pseudocount / information-content scorer for MSA columns.
- Parameters:
matrix (str) – Biopython substitution matrix name (default
"BLOSUM62"); its implied background and conditional target probabilitiesP(a | b)are recovered from the matrix itself (no hardcoded frequency tables).beta (float) – Henikoff/PSI-BLAST pseudocount strength; the total pseudocount mass is
beta * (distinct residue types observed)per column (default 10).background (np.ndarray | None) – KL background
q_a(length-20,STR_AA20order) forcolumn_information(); defaults toARR_SWISSPROT_BG. Supply a dataset-specific composition for “surprising relative to this dataset”.
- __init__(matrix: str = 'BLOSUM62', beta: float = 10.0, background: ndarray | None = None) None
Methods
__eq__(other)Return self==value.
__init__([matrix, beta, background])__post_init__()Conditional target probabilities
P(a | b)recovered from the matrix.column_information(counts)Background-relative information content of a column, in bits.
pseudocounts(counts)Substitution-aware pseudocount vector
B * g_afor a column.smoothed_freqs(counts)Posterior-mean residue frequencies
p_a = (n_a + B g_a) / (N + B).Attributes
__dataclass_fields____dataclass_params____match_args__20 x 20conditional target probabilitiesP[a, b] = P(a | b)(columns sum to 1).- __init__(matrix: str = 'BLOSUM62', beta: float = 10.0, background: ndarray | None = None) None
- _build_target_probs() ndarray[source]
Conditional target probabilities
P(a | b)recovered from the matrix.From the log-odds scores
S_ab(half-bits) form the oddsQ_ab = 2^(S_ab/2). The implied backgroundfis the distribution whose jointf_a f_b Q_abhas marginalf– i.e.Q f = 1– andP(a | b) = f_a Q_ab, column-normalized to absorb the log-odds rounding.
- background: ndarray | None = None
- beta: float = 10.0
- column_information(counts: ndarray) float | None[source]
Background-relative information content of a column, in bits.
IC = sum_a p_a log2(p_a / q_a)(KL of the smoothed column againstbackground); >= 0, higher = more conserved-and-surprising. An empty column returnsNonerather than scoring the bare pseudocount against the background.- Parameters:
counts (np.ndarray) – Length-20 (weighted) residue counts
n_a.- Returns:
Information content in bits, or
Nonefor an empty column.- Return type:
float | None
- matrix: str = 'BLOSUM62'
- pseudocounts(counts: ndarray) ndarray[source]
Substitution-aware pseudocount vector
B * g_afor a column.g_a = sum_b (n_b / N) P(a | b)spreads each observed residue’s mass onto its substitution neighbors;B = beta * (# distinct residue types observed).- Parameters:
counts (np.ndarray) – Length-20 (weighted) residue counts
n_ainSTR_AA20order.- Returns:
Length-20 pseudocount vector
B * g_a(zeros for an empty column).- Return type:
np.ndarray
- smoothed_freqs(counts: ndarray) ndarray | None[source]
Posterior-mean residue frequencies
p_a = (n_a + B g_a) / (N + B).- Returns:
Length-20 smoothed distribution, or
Nonefor an empty column (N = 0).- Return type:
np.ndarray | None
- property target_probs: ndarray
20 x 20conditional target probabilitiesP[a, b] = P(a | b)(columns sum to 1).