The training sequences. Empty strings, strings longer than max_length and strings with characters outside the alphabet are skipped and counted in n_skipped.
abundances
How many cells (templates, reads) carry each sequence. Default: 1 each. Non-positive or non-finite values skip the sequence.
alphabet
"aa" (the 20 amino acids, upper case) or "nt" (A C G T N, either case). Always named; never detected.
order
How many neighbouring residues each expert looks at: 2 to 4 for aa, 2 to 9 for nt. Default 4 and 6.
weights
(wF,wB): how much the start-anchored and end-anchored experts count in each residue’s factor qFwFqBwB, where qF and qB are the two experts’ probabilities of the residue. The default (½,½) is their geometric mean. Keep them summing to 1; (1, 0) or (0, 1) uses one expert alone.
max_length
Longest sequence represented, 2 to 255. Default 27 for aa, 81 for nt. "data" takes the longest training sequence the alphabet accepts (not with from_sequence_file, from_parquet or builder, which read the data once).
A parquet file, one batch at a time (needs pyarrow).
BeamModel.builder(**config)
A Builder that accumulates counts batch by batch, for corpora of any size.
BeamModel.from_file(path)
A model saved with save.
from_dataframe and from_parquet read the column cdr3_aa when no sequence_column is
given (cdr3 for nucleotides), and count every row once when no abundance_column is given. To
compare with the reference model, name junction_aa explicitly: AIRR’s cdr3_aa leaves out the
conserved start and end residues.
A Builder takes batches with b.observe(sequences, abundances=None); b.build() returns the
model and closes the builder, and b.snapshot() returns the model so far and keeps it open.
Every sequence of a delimited file or a parquet column (default cdr3_aa, cdr3 for nucleotides), in file order. out= fills a preallocated array or memory map.
explain(seq)
For each residue, the log probability from each expert (forward, backward) and their weighted combination (combined = wF·forward + wB·backward), with log_length_prior and log_partition; together they rebuild log_pseq, which is also returned. Raises ValueError naming why a sequence cannot be scored. See Which residues drive a score.
log_pseq_by_position(seq)
The score split per position; the sum is the score.
A score comparable across lengths: −log10 of the share of same-length sequences at least as surprising, computed from the model’s own distribution of surprisal at each length. A score of 2 means the rarest 1% at any length.
n sequences drawn in proportion to their probability. Without a seed the draw uses seed 0, so repeated calls return the same sequences; pass different seeds for independent draws.
simulate(n, *, length=None, seed=None)
The same draws with their log probabilities (.sequences, .log_probs).
top_k_sequences(k=20, *, length=None)
The k most probable sequences with their log probabilities.
tempered(t)
A new model with Pt(s)∝P(s)t, for t>0: sharper for t>1, flatter for t<1. It scores, samples and computes like any model, but cannot be saved, copied or combined.
Effective numbers of sequences (Hill numbers) at order q.
hill_profile(orders)
Hill numbers at many orders at once, faster than hill_numbers.
path_count(length=None)
Number of distinct sequences the model can produce. Every sequence up to max_length has some probability, so this is RL at length L (R = 20 amino acids or 5 nucleotides), summed over lengths by default. For diversity, use Hill numbers.
positional_marginals(length, *, clamp=None)
An array with one row per position and one column per residue: P(xi=a∣L), the probability that position i holds residue a at length L; the basis of a sequence logo. clamp={position: residue} conditions on residues pinned at some positions.
log_clamp_probability(length, clamp)
lnP(clamp∣L): the log probability that a length-L sequence has the residues pinned by clamp.
surprisal_stats()
Mean, variance, standard deviation, skewness and excess kurtosis of the surprisal −lnP(s) over the model’s sequences.
surprisal_range(), dynamic_range(*, base=10)
The smallest and largest surprisal of any sequence, and their span in orders of magnitude.
pseq_analysis()
The model’s probability spectrum: .atoms(bins) gives (probability, number of sequences) pairs, the input to publicness spectra.
A new model with both models’ counts: one pooled repertoire.
add(other), subtract(other)
Add or remove another model’s counts, in place.
without(other, *, abundances=None)
A new model with other’s counts removed; other is a model or a list of sequences.
with_prior(prior, kappa=100)
A new model updated towards prior’s probabilities; posterior(prior, kappa=100) does the same in place.
copy()
An independent copy.
Combined models need the same alphabet, order and max_length (ModelMismatch otherwise);
the result keeps the first model’s weights and prior settings. To mix probabilities rather
than pool counts, use Mixture; see
Merging counts or mixing models.
Writes counts and configuration; .beam is added when the path has no suffix.
compact()
Drops the raw counts to save memory. The model still scores, samples and computes, but can no longer be saved, copied, combined or given new prior strengths.
memory_bytes
Approximate memory of the model’s tables.
config
The configuration it was built with, including the prior strengths chosen.
alphabet, n_residues
"aa" or "nt", and its number of residues (20 or 5).
n_observed (also len(model)), n_skipped
Sequence records accepted and rejected while building.
total_weight (alias n_sequences)
Total abundance counted.
metadata()
Everything the model records about itself, including when it was built.
set_alpha(alpha=None, alpha_length=None)
Rebuilds the prior with new strengths (numbers, or "auto"); an argument left out keeps its setting.