sync

Synchronize multiple pools so they iterate in lockstep — state i of every synced pool is always drawn together. This is an in-place operation (it modifies the pools and returns None).

import poolparty as pp
pp.init()

Note

All synced pools must have the same number of states, and no pool may be an ancestor of another in the DAG (which would create a circular dependency).


Parameters

Parameter

Type

Default

Description

pools

list[Pool]

(required)

Pools to synchronize. Must all have the same num_states.

Returns None — pools are modified in-place.


Note

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

Examples

Without sync: Cartesian product

By default, joining two pools produces every combination of their states. Two 3-state pools yield 3 × 3 = 9 sequences.

a = pp.from_seqs(["AAA", "CCC", "GGG"], mode="sequential")
b = pp.from_seqs(["TTT", "AAA", "CCC"], mode="sequential")

cross = pp.join([a, b])
cross.print_library()
cross: seq_length=6, num_states=9 AAATTT
AAAAAA
AAACCC
CCCTTT
CCCAAA
CCCCCC
GGGTTT
GGGAAA
GGGCCC

With sync: matched pairs

After syncing, the same join produces only the 3 matched pairs. State 0 of left is always drawn together with state 0 of right, and so on.

left  = pp.from_seqs(["AAA", "CCC", "GGG"], mode="sequential")
right = pp.from_seqs(["TTT", "AAA", "CCC"], mode="sequential")

pp.sync([left, right])
paired = pp.join([left, right])
paired.print_library()
paired: seq_length=6, num_states=3 AAATTT
CCCAAA
GGGCCC

Pair variants with identifiers

A common use case is to assign each variant a unique identifier sequence so that the pairing is fixed across the library.

variants = pp.from_seqs(["ATCG", "GCTA", "TTAA", "CCGG"],
                        mode="sequential")
tags     = pp.from_seqs(["AAAA", "CCCC", "GGGG", "TTTT"],
                        mode="sequential")

pp.sync([variants, tags])
library = pp.join([variants, tags])
library.print_library()
library: seq_length=8, num_states=4 ATCGAAAA
GCTACCCC
TTAAGGGG
CCGGTTTT

Sync three or more pools

sync accepts any number of pools. Here three 3-state pools are synchronized, reducing the join from 27 combinations to 3 matched triples.

a = pp.from_seqs(["AAAA", "CCCC", "GGGG"], mode="sequential")
b = pp.from_seqs(["TTTT", "AAAT", "CCCT"], mode="sequential")
c = pp.from_seqs(["ACGT", "TGCA", "GATC"], mode="sequential")

pp.sync([a, b, c])
combined = pp.join([a, b, c])
combined.print_library()
combined: seq_length=12, num_states=3 AAAATTTTACGT
CCCCAAATTGCA
GGGGCCCTGATC

See sync().