score ===== Evaluate a user-supplied function on each sequence and record the result as a design card column. The sequence passes through unchanged — ``score`` is a passthrough operation that adds metadata without altering content. The function receives the clean (tag-stripped) sequence string, or the clean content of a named region when ``region`` is specified. Compatible with built-in utilities such as ``pp.calc_gc``, ``pp.calc_dust``, and ``pp.calc_complexity``. .. code-block:: python import poolparty as pp pp.init() ---- Parameters ---------- .. list-table:: :header-rows: 1 :widths: auto * - Parameter - Type - Default - Description * - ``pool`` - ``Pool | str`` - *(required)* - The Pool or sequence string to score. * - ``fn`` - ``callable`` - *(required)* - Scoring function ``(str) -> any``. Receives a clean (tag-free) sequence string and returns any scalar value to record. * - ``card_key`` - ``str`` - ``'score'`` - Design card column name under which the result is stored. * - ``region`` - ``str | list | None`` - ``None`` - Region to score. A named tag (str), ``[start, stop]`` interval, or ``None`` to score the full sequence. * - ``prefix`` - ``str | None`` - ``None`` - Prefix for auto-generated sequence names. * - ``cards`` - ``list | dict | None`` - ``None`` - Design card keys to include. The available key is the value of ``card_key`` (default ``'score'``). ---- .. note:: Only the most commonly used parameters are shown above. For the full parameter list, see :func:`~poolparty.score` in the :doc:`API Reference `. Examples -------- GC content with ``pp.calc_gc`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Record the GC fraction of every sequence using the built-in utility. Design cards are opt-in — pass ``cards={"gc": "gc"}`` (a dict mapping the card key to the desired column name) to include the column in the output. Using a list ``["gc"]`` also works but prefixes the column name with the operation id (e.g. ``op[12]:score.gc``); the dict form avoids this. .. code-block:: python wt = pp.from_iupac("NNNN", mode="sequential") scored = pp.score(wt, pp.calc_gc, card_key="gc", cards={"gc": "gc"}) scored.print_library() # scored.generate_library() adds a "gc" column per sequence .. raw:: html
| name | seq | gc | op[2]:score.complexity |
|---|---|---|---|
| None | AAAAAAAA | 0.000 | 0.186508 |
| None | AAAAAAAC | 0.125 | 0.373016 |
| None | AAAAAAAG | 0.125 | 0.373016 |
| None | AAAAAAAT | 0.000 | 0.373016 |
| None | AAAAAACA | 0.125 | 0.476190 |
| None | AAAAAACC | 0.250 | 0.476190 |
| None | AAAAAACG | 0.250 | 0.559524 |
| None | AAAAAACT | 0.125 | 0.559524 |
| None | AAAAAAGA | 0.125 | 0.476190 |
| None | AAAAAAGC | 0.250 | 0.559524 |