SeqOpt
- class SeqOpt(*, mode='importance', model=None, target_class=None, df_seq_ref=None, labels=None, df_scales=None, random_state=None, verbose=False)[source]
Sequence Optimizer (SeqOpt) class for multi-objective directed evolution over sequence variants [Breimann24a]. Core class; only the SHAP-guided
mode="impact"needsaaanalysis[pro](mode="importance"and everything else run in a base install).SeqOptperforms protein engineering, not de novo protein design. The two are distinct paradigms: de novo design builds new proteins from the ground up rather than repurposing an existing one – typically a structure-first deep-learning pipeline such as RFdiffusion [Watson23] (backbone generation) -> ProteinMPNN [Dauparas22] (sequence design) -> AlphaFold [Jumper21] (in-silico validation), reviewed in [Yang26]. Protein engineering instead optimizes an existing sequence through iterative mutation and selection (directed evolution).SeqOptis the machine-learning-guided flavour [Yang19], [Wittmann21]: a model predicts variant fitness so the search prioritizes which mutations to make – here as a multi-objective evolutionary search.SeqOptis the search/optimization counterpart ofSeqMut: whereSeqMutscores mutations,SeqOptsearches the space of multi-mutation variants of a single wild-type for the trade-off (Pareto) front that best satisfies several objectives at once. It runs a re-implementation of NSGA-II [Deb02] using a model-boundSeqMutas the fitness engine, guided each generation by residue-level model attribution:mode="impact"refitsShapModelunder fuzzy labeling,mode="importance"uses the staticfeat_importanceranking.The evolutionary machinery is a pure-Python re-implementation of DEAP (a dev/test-only parity oracle; the shipped runtime never imports DEAP). Each
runsetting selects the equivalent DEAP function:SeqOpt setting -> DEAP function SeqOpt (method / parameter = value)
DEAP
run(...)driveralgorithms.eaMuPlusLambda/eaMuCommaLambda/eaSimplealgorithm="nsga2"tools.selNSGA2(sortNondominated+assignCrowdingDist)mating selection
tools.selTournamentDCDsurvival="mu_plus_lambda" / "mu_comma_lambda" / "ea_simple"eaMuPlusLambda/eaMuCommaLambda/eaSimplevariation="and" / "or"algorithms.varAnd/algorithms.varOrcrossover="uniform" / "one_point" / "two_point"tools.cxUniform/cxOnePoint/cxTwoPointmutation="substitution"tools.mutUniformInt(categorical resampling analogue)constraints=[...], penalty="delta" / "closest_valid"tools.DeltaPenalty/tools.ClosestValidPenaltyobjectives=[(name, "max"/"min", src)]base.Fitnessweights(+1 / -1 per objective) +toolbox.register("evaluate")df_paretooutput /hall_of_fame_/trajectory_tools.ParetoFront/tools.HallOfFame/tools.Logbookevalhypervolume / convergence / spreaddeap.benchmarks.tools.hypervolume/convergence/diversityRows with no DEAP analogue are the aaanalysis value-add: the SHAP /
feat_importanceresidue guidance (mode), the sequence genome + domain constraints (n_mut_max,region,to_aa), thealgorithm="greedy"baseline, and anycallable(sequence)objective.Warning
Experimental. This class is part of the new v1.1.0 protein-design/optimization layer and is under active development; its API (signatures, defaults, return objects) may change between minor releases without the usual deprecation cycle. Pin a version if you depend on the current behaviour.
Added in version 1.1.0.
- Parameters:
Methods
eval(df_pareto, *[, ref_point, ref_front])Evaluate a Pareto front: hypervolume, front size, spread and (optionally) convergence.
run(df_seq, df_feat, objectives, *[, ...])Run multi-objective directed evolution and return the Pareto front of variants.
trace_lineage(lineage, candidate_id)Reconstruct the chain of lineage records that leads to one designed candidate.
- __init__(*, mode='importance', model=None, target_class=None, df_seq_ref=None, labels=None, df_scales=None, random_state=None, verbose=False)[source]
- Parameters:
mode ({'importance', 'impact'}, default='importance') –
Residue-guidance mode:
'importance': uses the staticfeat_importanceranking fromdf_feat(no SHAP, no refit) and walks positions highest-first. It needs no pro dependency, and is the default so that a bareSeqOpt()constructs in a base install.'impact': the headline mode, refitsShapModelevery generation under fuzzy labeling (the new variant’s prediction score as a soft label vs. the balanced reference) and mutates the strongest-feat_impactresidues. It is the only SeqOpt feature that needsaaanalysis[pro](SHAP), imported lazily, and requiresmodel,df_seq_refandlabels.
Changed in version 1.2.0: The default is
'importance'(was'impact'), soSeqOpt()constructs in a base install;'impact'stays the documented headline mode.model (object, optional) – A fitted classifier exposing
predict_probaused as the fitness engine (thedelta_predobjective) and, inmode='impact', as the model whose attribution guides the search. Required when an objective usesdelta_predormode='impact'.target_class (int or str, optional) – Class whose predicted probability the fitness tracks.
Noneselects the positive class.df_seq_ref (pd.DataFrame, optional) – Labeled, balanced reference sequences (position-based format) the per-generation
ShapModelrefit is anchored on. Required formode='impact'.labels (array-like, shape (n_ref,), optional) – Binary class labels (1=positive, 0=negative) aligned to
df_seq_ref. Required formode='impact'.df_scales (pd.DataFrame, optional) – Amino acid scales. Default from
load_scales().random_state (int, optional) – Seed threaded through the evolutionary RNG and
ShapModel.verbose (bool, default=False) – If
True, verbose outputs are enabled.
- Raises:
ValueError – If
mode,df_scales, orrandom_stateis invalid; if the model arguments are invalid; or ifmode='impact'lacksmodel,df_seq_ref, orlabels.ImportError – If
mode='impact'is selected without the optionalaaanalysis[pro]dependency.