reproduce

Below is an auto-generated summary of the xftsim.reproduce submodule API.

class xftsim.reproduce.RecombinationMap(p=None, m=None, vid=None, chrom=None, pos_bp=None)[source]

Bases: object

A class to represent a diploid recombination map.

Parameters:
  • p (float or numpy.ndarray, optional) – Probabilities, either a float or a numpy.ndarray, default is None. A single value results in an exchangeable map, an array corresponds to probabilities of recombination between specified loci.

  • m (int, optional) – Number of variants. Required if p is a float.

  • vid (numpy.ndarray, optional) – Variant IDs, default is None.

  • chrom (numpy.ndarray, optional) – Chromosomes, default is None.

  • pos_bp (numpy.ndarray, optional) – Per-variant base-pair positions, default is None. When provided, any locus j where pos_bp[j] == pos_bp[j-1] has its recombination probability forced to 0: crossover cannot occur between two mutations at the same physical site (e.g., multi-allelic sites where two ALT entries share a position, or msprime-discretized positions that collide). Without this guard, the GRG-native meiosis path’s interval-based mutation filter (bisect_left on positions) silently groups all same-position variants into whichever segment claims the position, producing wrong-hap assignments at the few duplicate-position cells.

Parameters:
  • m (int)

  • vid (Any))

  • chrom (Int64))

  • pos_bp (Int64))

static constant_map(m, p=0.5, pos_bp=None)[source]

Create a constant recombination map.

Parameters:
  • m (int) – Number of variants.

  • p (float, optional) – Recombination probability, default is 0.5.

  • pos_bp (numpy.ndarray, optional) – Per-variant base-pair positions; forwarded to RecombinationMap.__init__ to suppress crossovers between same-position variants. See class docstring.

Return type:

RecombinationMap

Returns:

RecombinationMap – A constant recombination map.

Parameters:
static from_haplotypes(haplotypes, p=0.5)[source]

Create a constant recombination map from haplotypes.

Threads haplotypes.variants.pos_bp into the constructor when available so that same-position variants are properly handled (see class docstring). Falls back to None when the haplotype object lacks position metadata, which preserves the historical behavior.

Parameters:
  • haplotypes (DenseHaplotypeArray or GraphHaplotypeOperator) – Haplotypes data. Any object with .m and .vid; if it also exposes .variants.pos_bp, that’s used.

  • p (float, optional) – Probability, default is 0.5.

Return type:

RecombinationMap

Returns:

RecombinationMap – A constant recombination map.

Parameters:

p (float)

xftsim.reproduce.meiosis(parental_haplotypes, recombination_map, maternal_inds, paternal_inds, rng=None)[source]

Performs meiosis on parental haplotypes.

Parameters:
  • parental_haplotypes (DenseHaplotypeArray) – Parental haplotype data.

  • recombination_map (RecombinationMap) – Recombination probabilities.

  • maternal_inds (numpy.ndarray[int64]) – An array of maternal parent indices.

  • paternal_inds (numpy.ndarray[int64]) – An array of paternal parent indices.

  • rng (numpy.random.RandomState, optional) – Master RNG. Used to derive per-offspring seeds via SeedSequence.spawn so that crossover sampling is deterministic given the master state (independent of how nb.prange schedules offspring across threads). If None (the default), a fresh RandomState is constructed, preserving the historical non-deterministic behavior for callers that don’t pass an rng.

Return type:

Int8)

Returns:

numpy.ndarray[int8] – 3D array of offspring genotypes (n_offspring, m, 2).

Parameters: