from_iupac
Create a pool from an IUPAC ambiguity-code string. Every ambiguous position
expands to its corresponding base set; the pool enumerates all possible
combinations. By default the pool samples uniformly at random; pass
mode='sequential' to enumerate in lexicographic order.
IUPAC codes: R = {A,G}, Y = {C,T}, S = {C,G}, W = {A,T}, K = {G,T}, M = {A,C}, B = {C,G,T}, D = {A,G,T}, H = {A,C,T}, V = {A,C,G}, N = {A,C,G,T}.
import poolparty as pp
pp.init()
Parameters
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
(required) |
IUPAC sequence string (case-insensitive). Unambiguous bases pass through unchanged. |
|
|
|
Background pool. When provided with |
|
|
|
Region to replace in |
|
|
|
Prefix for auto-generated sequence names. |
|
|
|
|
|
|
|
Cap on total states. With |
|
|
|
Dimension-name ordering for downstream multi-pool iteration. |
|
|
|
Display style applied to every generated sequence. |
|
|
|
Design card columns to include in library output. |
Note
Only the most commonly used parameters are shown above. For the full
parameter list, see from_iupac() in the
API Reference.
Examples
Random sampling from an ambiguous code
W = {A,T}, N = {A,C,G,T}: 2 × 4 = 8 total combinations.
Random mode draws one sequence per call.
pool = pp.from_iupac("WN", mode="random", num_states=4)
pool.print_library()
TT
AC
TC
Sequential enumeration
mode='sequential' iterates all combinations in lexicographic order,
giving exactly one draw per combination.
pool = pp.from_iupac("RY", mode="sequential")
pool.print_library()
# R={A,G}, Y={C,T}: 2x2=4 combinations
AT
GC
GT
Capping with num_states
Combine mode='sequential' with num_states to take only the first N
combinations — useful for prototyping with a large degenerate sequence.
pool = pp.from_iupac("NNNN", mode="sequential", num_states=8)
pool.print_library()
# NNNN has 256 total; take first 8
AAAC
AAAG
AAAT
AACA
AACC
AACG
AACT
Inserting into a named region
Provide pool and region to enumerate all IUPAC combinations into a
fixed flanking context.
bg = pp.from_seq("AAAA<cre>XXX</cre>TTTT")
pool = pp.from_iupac("NNN", mode="sequential", pool=bg, region="cre")
pool.print_library()
AAAA<cre>AAC</cre>TTTT
AAAA<cre>AAG</cre>TTTT
AAAA<cre>AAT</cre>TTTT
AAAA<cre>ACA</cre>TTTT ... (64 total)
Pool method shorthand
When inserting into a region, the same operation is available as a method
on any DnaPool. The call bg.insert_from_iupac(...) is equivalent
to pp.from_iupac(..., pool=bg) — it simply passes self as the
background pool.
bg = pp.from_seq("AAAA<cre>XXX</cre>TTTT")
pool = bg.insert_from_iupac("NNN", region="cre", mode="sequential")
pool.print_library()
AAAA<cre>AAC</cre>TTTT
AAAA<cre>AAG</cre>TTTT
AAAA<cre>AAT</cre>TTTT
AAAA<cre>ACA</cre>TTTT ... (64 total)
See from_iupac() and insert_from_iupac().