Simulation¶
Haplotype-based simulation of admixed mosaics from phased founder panels. Requires PyTorch (pip install "snputils[torch]"). OnlineSimulator draws crossover breakpoints from an optional genetic map and returns batched haplotype labels with SNP matrices on CPU or GPU.
OnlineSimulator¶
- class snputils.simulation.simulator.simulator.OnlineSimulator(snp_data, meta, genetic_map=None, make_haploid=True, window_size=None, store_latlon_as_nvec=False, cp_tolerance=0)[source]¶
Bases:
objectA refactored ‘OnlineSimulator’ for haplotype simulation with window-based SNP data.¶
- Core Functionality:
Simulates admixed haplotypes.
- Supports:
discrete labels (e.g., population codes), or
lat/lon (converted to n-vectors) stored per window of SNPs.
Example usage:¶
- sim = OnlineSimulator(
snp_data=my_snpobj, meta=metadata_df, genetic_map=genetic_map_df, # optional …
) # Then to simulate: snps, labels_discrete, labels_continuous, changepoints = sim.simulate(batch_size=32)
- simulate(batch_size=256, num_generation_max=10, balanced=False, single_ancestry=False, device='cpu', pool_method='mode')[source]¶
- Returns a tuple of:
( batch_snps, final_discrete_labels_window, final_continuous_labels_window )
- where:
batch_snps.shape == (B, D)
final_discrete_labels_window == (B, n_windows) if discrete was present, else None
final_continuous_labels_window == (B, n_windows, cdim) if continuous was present, else None
See Analysis for a Python example and the Command-Line Interface simulate subcommand for file-backed batch generation.