replace_region

Replace the entire content of a named region with sequences drawn from a content pool. Every combination of background sequence and content sequence is produced (Cartesian product). The region tags are removed in the output; only the new content occupies that position.

import poolparty as pp
pp.init()

Parameters

Parameter

Type

Default

Description

pool

Pool | str

(required)

The background Pool whose named region will be replaced.

content_pool

Pool

(required)

Pool whose sequences replace the region content.

region_name

str

(required)

Name of the region to replace (must exist in the background pool).

rc

bool

False

When True, reverse-complement each content sequence before inserting it.

sync

bool

False

When True, pair background and content states 1:1 (lockstep iteration) instead of taking the Cartesian product.

keep_tags

bool

False

When True, preserve the region tags around the replaced content so the region can still be referenced by downstream operations.

iter_order

int | None

None

Dimension-name ordering for downstream multi-pool iteration.

prefix

str | None

None

Prefix for the operation node name in the pool graph.


Note

Only the most commonly used parameters are shown above. For the full parameter list, see replace_region() in the API Reference.

Examples

Replace a region with all 4-mers

Enumerate all 256 4-mers inside the cre region using from_iupac().

import poolparty as pp
pp.init()

wt      = pp.from_seq("AAAA<cre>ATCG</cre>TTTT")
inserts = pp.from_iupac("NNNN", mode="sequential")
library = pp.replace_region(wt, inserts, region_name="cre")
library.print_library()
library: seq_length=12, num_states=256 AAAAAAAATTTT
AAAAAAACTTTT
AAAAAAAGTTTT
AAAAAAATTTTT
AAAAAACATTTT
... (256 total)

Replace with a small explicit set

Supply from_seqs() to substitute only specific sequences.

import poolparty as pp
pp.init()

wt      = pp.from_seq("AAAA<cre>ATCG</cre>TTTT")
inserts = pp.from_seqs(["AAA", "TTT", "CCC"], mode="sequential")
library = pp.replace_region(wt, inserts, region_name="cre")
library.print_library()
library: seq_length=11, num_states=3 AAAAAAAATTTT
AAAATTTTTTT
AAAACCCTTTT

Replace a zero-length point tag (pure insertion)

When the region is a zero-length point tag, replace_region inserts without deleting any bases.

import poolparty as pp
pp.init()

wt      = pp.from_seq("AAAA<ins/>TTTT")
inserts = pp.from_seqs(["GC", "AT"], mode="sequential")
library = pp.replace_region(wt, inserts, region_name="ins")
library.print_library()
library: seq_length=10, num_states=2 AAAAGCTTTT
AAAAATTTTT

Insert reverse-complemented content (rc=True)

rc=True reverse-complements each content sequence before insertion.

import poolparty as pp
pp.init()

wt      = pp.from_seq("AAAA<cre>ATCG</cre>TTTT")
inserts = pp.from_seqs(["GCGC", "ATAT"], mode="sequential")
library = pp.replace_region(wt, inserts, region_name="cre", rc=True)
library.print_library()
library: seq_length=12, num_states=2 AAAAGCGCTTTT
AAAAATATTTTT

See replace_region().