### Install msprime using Pip (User Install) Source: https://tskit.dev/msprime/docs/latest/installation.html Installs msprime into the user's local Python installation, which is useful when root access is not available. Ensure '~/.local/bin' is in your PATH. ```bash $ python3 -m pip install msprime --user ``` -------------------------------- ### Install Dependencies and Build C Module Source: https://tskit.dev/msprime/docs/latest/development.html Installs all necessary Python development dependencies and builds the low-level C extension module. This command is essential for a functional development setup. ```bash $ uv sync ``` -------------------------------- ### Install msprime using Pip (User Install) Source: https://tskit.dev/msprime/docs/latest/_sources/installation.md Installs msprime into the user's local Python installation, which is useful when root access is not available. Ensure that '~/.local/bin' is in your PATH to use executables like 'mspms'. ```bash $ python3 -m pip install msprime --user ``` -------------------------------- ### Install Meson Build System Source: https://tskit.dev/msprime/docs/latest/_sources/development.md Install the Meson build system using the uv tool. Meson is used in conjunction with ninja-build for compiling C code. ```bash $ uv tool install meson ``` -------------------------------- ### Install Meson build system Source: https://tskit.dev/msprime/docs/latest/development.html Install the Meson build system, which is used in conjunction with ninja-build for compiling C code and unit tests. ```bash $ uv tool install meson ``` -------------------------------- ### INFO log output example Source: https://tskit.dev/msprime/docs/latest/logging.html Example of INFO level log messages during msprime simulation. ```log 2026-04-16 12:13:36,067 [3347] INFO msprime.ancestry: Sampling 10 individuals with ploidy 2 in population 0 (name='pop_0') at time 0 ``` ```log 2026-04-16 12:13:36,070 [3347] INFO msprime.ancestry: Starting replicate 0 ``` ```log 2026-04-16 12:13:36,070 [3347] INFO msprime.ancestry: model[0] {'name': 'dtwf'} started at time=0 nodes=20 edges=0 ``` ```log 2026-04-16 12:13:36,071 [3347] INFO msprime.ancestry: Running model {'name': 'dtwf'} until max time: 100.000000 ``` ```log 2026-04-16 12:13:36,073 [3347] INFO msprime.ancestry: model[1] {'name': 'hudson'} started at time=100 nodes=25 edges=10 ``` ```log 2026-04-16 12:13:36,073 [3347] INFO msprime.ancestry: Running model {'name': 'hudson'} until max time: inf ``` ```log 2026-04-16 12:13:36,073 [3347] INFO msprime.ancestry: Completed at time=5876.22 nodes=39 edges=38 ``` -------------------------------- ### Install GSL on FreeBSD Source: https://tskit.dev/msprime/docs/latest/_sources/installation.md Installs the GNU Scientific Library package on FreeBSD. ```bash pkg install gsl ``` -------------------------------- ### Install msprime from source Source: https://tskit.dev/msprime/docs/latest/_sources/installation.md Installs the msprime package from source using pip, ensuring no pre-built binaries are used. This command should be run after installing necessary system dependencies like GSL. ```bash python3 -m pip install msprime --no-binary msprime ``` -------------------------------- ### Build Documentation Locally Source: https://tskit.dev/msprime/docs/latest/development.html Navigate to the 'docs' directory and run 'make' to build the HTML documentation. Ensure all requirements are installed before building. ```bash make ``` -------------------------------- ### Install C Development Libraries Source: https://tskit.dev/msprime/docs/latest/_sources/development.md Install necessary libraries for compiling C code and running unit tests on Debian/Ubuntu systems. Libconfig and CUnit are required for development CLI and unit tests respectively. ```bash $ sudo apt-get install libcunit1-dev libconfig-dev ninja-build ``` -------------------------------- ### Install Dependencies and Build C Extension Source: https://tskit.dev/msprime/docs/latest/_sources/development.md Installs all necessary Python development packages and builds the low-level C extension module required for msprime development. ```bash uv sync ``` -------------------------------- ### Create Conda Environment and Install msprime Source: https://tskit.dev/msprime/docs/latest/_sources/installation.md Creates a new conda environment named 'msprime-env' and installs msprime from the conda-forge channel. Always use a dedicated environment for package installations to avoid conflicts. ```bash $ conda create --name msprime-env ... environment location: /home/jean/miniconda3/envs/msprime-env Proceed ([y]/n)? y Preparing transaction: ...working... done Verifying transaction: ...working... done Executing transaction: ...working... done # # To activate this environment, use # # $ conda activate msprime-env # # To deactivate an active environment, use # # $ conda deactivate $ conda activate msprime-env (msprime-env) $ conda install -c conda-forge msprime ... added / updated specs: - msprime The following NEW packages will be INSTALLED: ... Proceed ([y]/n)? y Downloading and Extracting Packages Preparing transaction: ...working... done Verifying transaction: ...working... done Executing transaction: ...working... done ``` -------------------------------- ### Install C development libraries on Debian/Ubuntu Source: https://tskit.dev/msprime/docs/latest/development.html Install necessary development libraries for compiling the C code, including CUnit for unit tests and libconfig for the development CLI. ```bash $ sudo apt-get install libcunit1-dev libconfig-dev ninja-build ``` -------------------------------- ### Population Metadata Example Source: https://tskit.dev/msprime/docs/latest/demography.html Example output of population metadata, showing the 'name' and 'description' for each population defined in the simulation. ```python { 'description': '', 'name': 'human' } { 'description': '', 'name': 'chimpanzee' } { 'description': '', 'name': 'gorilla' } { 'description': '', 'name': 'orangutan' } { 'description': '', 'name': 'pop_4' } { 'description': '', 'name': 'pop_5' } { 'description': '', 'name': 'pop_6' } ``` -------------------------------- ### Install msprime using Pip Source: https://tskit.dev/msprime/docs/latest/_sources/installation.md Installs the msprime package using pip. It is generally recommended to use 'python3 -m pip' to ensure the correct Python installation is targeted. This command installs the package for the current user. ```bash $ python3 -m pip install msprime ``` -------------------------------- ### Setup INFO logging with daiquiri Source: https://tskit.dev/msprime/docs/latest/logging.html Use this to set the logging level to INFO for high-level simulation status. Requires importing daiquiri and msprime. ```python import daiquiri import msprime daiquiri.setup(level="INFO") ts = msprime.sim_ancestry( 10, population_size=1000, model=[ msprime.DiscreteTimeWrightFisher(duration=100), msprime.StandardCoalescent(), ], random_seed=1234 ) ``` -------------------------------- ### Check Pip Installation Source: https://tskit.dev/msprime/docs/latest/_sources/installation.md Verifies that pip is installed and accessible. If Python {{ min_python_version }} or greater is not detected, it is recommended to use the conda installation method instead. ```bash $ python3 -m pip --version ``` -------------------------------- ### Verify msprime Installation with Python Source: https://tskit.dev/msprime/docs/latest/_sources/installation.md After activating the conda environment, this snippet shows how to import msprime and simulate a simple ancestry, then draw it as text. This confirms the installation was successful and the library is functional. ```python (msprime-env) $ python Python 3.8.5 [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> import msprime >>> ts = msprime.sim_ancestry(3) >>> print(ts.draw_text()) 3.18┊ 10 ┊ ┊ ┏━━┻━━┓ ┊ 2.08┊ 9 ┃ ┊ ┊ ┏━┻━┓ ┃ ┊ 0.80┊ ┃ ┃ 8 ┊ ┊ ┃ ┃ ┏┻┓ ┊ 0.42┊ ┃ 7 ┃ ┃ ┊ ┊ ┃ ┏┻┓ ┃ ┃ ┊ 0.34┊ 6 ┃ ┃ ┃ ┃ ┊ ┊ ┏┻┓ ┃ ┃ ┃ ┃ ┊ 0.00┊ 0 4 1 3 2 5 ┊ 0.00 1.00 ``` -------------------------------- ### Install GSL on Debian/Ubuntu Source: https://tskit.dev/msprime/docs/latest/_sources/installation.md Installs the GNU Scientific Library and Python development headers on Debian-based systems. ```bash apt-get install python-dev libgsl0-dev ``` -------------------------------- ### Install GSL on Redhat/Fedora Source: https://tskit.dev/msprime/docs/latest/_sources/installation.md Installs the GNU Scientific Library development package on Red Hat or Fedora systems. ```bash yum install gsl-devel ``` -------------------------------- ### Install Pre-commit Hook Source: https://tskit.dev/msprime/docs/latest/_sources/development.md Installs the pre-commit hook for the project. This helps maintain code quality by running checks before each commit. ```bash uv run prek install ``` -------------------------------- ### Install msprime using Pip Source: https://tskit.dev/msprime/docs/latest/installation.html Installs the msprime package using pip. It is recommended to use 'python3 -m pip' to ensure the package is installed for the correct Python interpreter. ```bash $ python3 -m pip install msprime ``` -------------------------------- ### Example Output of Segregating Sites Calculation Source: https://tskit.dev/msprime/docs/latest/replication.html This is the expected output format for the mean and variance of segregating sites (S) from the generator-based simulation example. ```python (np.float64(1.52), np.float64(1.5495999999999999)) ``` -------------------------------- ### Verify msprime Installation with Python Source: https://tskit.dev/msprime/docs/latest/installation.html After activating the msprime conda environment, this snippet shows how to import msprime, simulate ancestry, and draw the resulting tree. This confirms a successful installation. ```python (msprime-env) $ python Python 3.8.5 [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> import msprime >>> ts = msprime.sim_ancestry(3) >>> print(ts.draw_text()) 3.18┊ 10 ┊ ┊ ┏━━┻━━┓ ┊ 2.08┊ 9 ┃ ┊ ┊ ┏━┻━┓ ┃ ┊ 0.80┊ ┃ ┃ 8 ┊ ┊ ┃ ┃ ┏┻┓ ┊ 0.42┊ ┃ 7 ┃ ┃ ┊ ┊ ┃ ┏┻┓ ┃ ┃ ┊ 0.34┊ 6 ┃ ┃ ┃ ┃ ┊ ┊ ┏┻┓ ┃ ┃ ┃ ┃ ┊ 0.00┊ 0 4 1 3 2 5 ┊ 0.00 1.00 ``` -------------------------------- ### Setup DEBUG logging with daiquiri Source: https://tskit.dev/msprime/docs/latest/logging.html Use this to set the logging level to DEBUG for detailed simulation progress. Useful for large simulations. ```python daiquiri.setup(level="DEBUG") ts = msprime.sim_ancestry( 10 ** 5, population_size=10000, recombination_rate=2e-8, sequence_length=1e6, random_seed=32 ) ``` -------------------------------- ### Install GSL on OS X using Homebrew Source: https://tskit.dev/msprime/docs/latest/_sources/installation.md Installs the GNU Scientific Library on OS X using the Homebrew package manager after updating Homebrew. ```bash brew update brew install gsl ``` -------------------------------- ### Get Sample Configuration Source: https://tskit.dev/msprime/docs/latest/_modules/msprime/ancestry.html Returns a list of the number of samples in each population. It iterates through nodes to count samples flagged as such. ```python @property def sample_configuration(self): """ Returns a list of the number of samples in each of the populations. """ tables = self.copy_tables() num_samples = [0 for _ in tables.populations] for node in tables.nodes: if (node.flags & tskit.NODE_IS_SAMPLE) != 0: num_samples[node.population] += 1 return num_samples ``` -------------------------------- ### Simulate Ancestry with Custom Start Time Source: https://tskit.dev/msprime/docs/latest/_sources/ancestry.md Simulates ancestry for 2 samples, but advances the simulation to a start time of 10 before generating random events. This is an advanced feature for specific simulation needs. ```python ts = msprime.sim_ancestry(2, start_time=10, random_seed=42) ts.tables.nodes ``` -------------------------------- ### Run Tests Source: https://tskit.dev/msprime/docs/latest/development.html Executes the test suite to verify that the project is working correctly after setup or changes. This is a standard step to ensure code integrity. ```bash $ uv run pytest ``` -------------------------------- ### Get Epoch Start Times Source: https://tskit.dev/msprime/docs/latest/_modules/msprime/demography.html Returns a numpy array containing the start times for each epoch defined in the demographic model. ```python @property def epoch_start_time(self): """ The array of epoch start_times defined by the demographic model. """ return np.array([x.start_time for x in self.epochs]) ``` -------------------------------- ### Set up Meson build directory Source: https://tskit.dev/msprime/docs/latest/development.html Initialize the build directory for the C library using Meson. This command should be run from the 'lib' directory. ```bash cd lib meson build ``` -------------------------------- ### Initialize Meson Build Directory Source: https://tskit.dev/msprime/docs/latest/_sources/development.md Set up the build directory for the C library using Meson. This command should be run from the 'lib' directory. ```bash cd lib meson build ``` -------------------------------- ### Get Population Size History Source: https://tskit.dev/msprime/docs/latest/_modules/msprime/demography.html Returns a numpy array representing the starting population size for each population across all epochs. The shape is (number of populations, number of epochs). ```python @property def population_size_history(self): """ Returns a (num_pops, num_epochs) numpy array giving the starting population size for each population in each epoch. """ pop_size = np.zeros((self.num_populations, self.num_epochs)) for j, epoch in enumerate(self.epochs): for k, pop in enumerate(epoch.populations): pop_size[k, j] = pop.start_size return pop_size ``` -------------------------------- ### Format All Files Source: https://tskit.dev/msprime/docs/latest/development.html Manually format all project files using the 'prek --all-files' command. ```bash $ uv run prek --all-files ``` -------------------------------- ### Simulate using development CLI Source: https://tskit.dev/msprime/docs/latest/development.html Run a simulation using the development CLI, specifying a configuration file and an output file path. The configuration file uses libconfig syntax. ```bash ./build/dev-cli simulate dev-tools/example.cfg -o out.trees ``` -------------------------------- ### Publish and Preview Benchmark Reports Source: https://tskit.dev/msprime/docs/latest/_sources/development.md Generate a browsable report of benchmark results. Use 'asv publish' to create the report and 'asv preview' to view it. ```bash asv publish ``` ```bash asv preview ``` -------------------------------- ### Set up INFO level logging for msprime Source: https://tskit.dev/msprime/docs/latest/_sources/logging.md Initializes daiquiri logging to INFO level and runs a basic msprime simulation. Use this for high-level simulation status. ```python import daiquiri import msprime daiquiri.setup(level="INFO") ts = msprime.sim_ancestry( 10, population_size=1000, model=[ msprime.DiscreteTimeWrightFisher(duration=100), msprime.StandardCoalescent(), ], random_seed=1234 ) ``` -------------------------------- ### DEBUG log output example Source: https://tskit.dev/msprime/docs/latest/logging.html Example of DEBUG level log messages during a larger msprime simulation. ```log 2026-04-16 12:13:36,080 [3347] INFO msprime.ancestry: Sampling 100000 individuals with ploidy 2 in population 0 (name='pop_0') at time 0 ``` ```log 2026-04-16 12:13:36,173 [3347] INFO msprime.ancestry: Starting replicate 0 ``` ```log 2026-04-16 12:13:36,183 [3347] INFO msprime.ancestry: model[0] {'name': 'hudson'} started at time=0 nodes=200000 edges=0 ``` ```log 2026-04-16 12:13:36,184 [3347] INFO msprime.ancestry: Running model {'name': 'hudson'} until max time: inf ``` ```log 2026-04-16 12:13:36,223 [3347] DEBUG msprime.ancestry: time=0.0104295 ancestors=190080 ret=1 ``` ```log 2026-04-16 12:13:36,256 [3347] DEBUG msprime.ancestry: time=0.0219435 ancestors=180166 ret=1 ``` ```log 2026-04-16 12:13:36,288 [3347] DEBUG msprime.ancestry: time=0.0346803 ancestors=170256 ret=1 ``` ```log 2026-04-16 12:13:36,321 [3347] DEBUG msprime.ancestry: time=0.0491285 ancestors=160336 ret=1 ``` ```log 2026-04-16 12:13:36,356 [3347] DEBUG msprime.ancestry: time=0.0657941 ancestors=150418 ret=1 ``` ```log 2026-04-16 12:13:36,391 [3347] DEBUG msprime.ancestry: time=0.0847891 ancestors=140540 ret=1 ``` ```log 2026-04-16 12:13:36,428 [3347] DEBUG msprime.ancestry: time=0.106283 ancestors=130644 ret=1 ``` ```log 2026-04-16 12:13:36,467 [3347] DEBUG msprime.ancestry: time=0.131827 ancestors=120740 ret=1 ``` ```log 2026-04-16 12:13:36,509 [3347] DEBUG msprime.ancestry: time=0.161742 ancestors=110874 ret=1 ``` ```log 2026-04-16 12:13:36,552 [3347] DEBUG msprime.ancestry: time=0.197291 ancestors=101020 ret=1 ``` ```log 2026-04-16 12:13:36,599 [3347] DEBUG msprime.ancestry: time=0.240122 ancestors=91192 ret=1 ``` ```log 2026-04-16 12:13:36,649 [3347] DEBUG msprime.ancestry: time=0.293227 ancestors=81390 ret=1 ``` ```log 2026-04-16 12:13:36,702 [3347] DEBUG msprime.ancestry: time=0.361519 ancestors=71580 ret=1 ``` ```log 2026-04-16 12:13:36,760 [3347] DEBUG msprime.ancestry: time=0.45156 ancestors=61818 ret=1 ``` ```log 2026-04-16 12:13:36,822 [3347] DEBUG msprime.ancestry: time=0.573763 ancestors=52074 ret=1 ``` ```log 2026-04-16 12:13:36,890 [3347] DEBUG msprime.ancestry: time=0.755864 ancestors=42402 ret=1 ``` ```log 2026-04-16 12:13:36,963 [3347] DEBUG msprime.ancestry: time=1.03995 ancestors=32814 ret=1 ``` ```log 2026-04-16 12:13:37,038 [3347] DEBUG msprime.ancestry: time=1.54834 ancestors=23356 ret=1 ``` ```log 2026-04-16 12:13:37,126 [3347] DEBUG msprime.ancestry: time=2.72085 ancestors=14190 ret=1 ``` ```log 2026-04-16 12:13:37,237 [3347] DEBUG msprime.ancestry: time=7.38436 ancestors=5736 ret=1 ``` ```log 2026-04-16 12:13:37,336 [3347] DEBUG msprime.ancestry: time=150.174 ancestors=558 ret=1 ``` ```log 2026-04-16 12:13:37,354 [3347] DEBUG msprime.ancestry: time=4639.98 ancestors=154 ret=1 ``` ```log 2026-04-16 12:13:37,365 [3347] DEBUG msprime.ancestry: time=17020.3 ancestors=100 ret=1 ``` ```log 2026-04-16 12:13:37,374 [3347] DEBUG msprime.ancestry: time=35240.4 ancestors=96 ret=1 ``` ```log 2026-04-16 12:13:37,381 [3347] DEBUG msprime.ancestry: time=66125.6 ancestors=62 ret=1 ``` -------------------------------- ### Initialize Submodules in Existing Repository Source: https://tskit.dev/msprime/docs/latest/development.html If you have already cloned the repository, use this command to initialize and update all submodules. This is crucial for ensuring all necessary components are present. ```bash $ git submodule update --init --recursive ``` -------------------------------- ### Example Output of Ancestry Simulation Source: https://tskit.dev/msprime/docs/latest/replication.html This is the expected output format for the mean and variance of TMRCA from the ancestry simulation example. ```python (np.float64(3.799291711240622), np.float64(3.920289255957004)) ``` -------------------------------- ### Example Output for Beta-Coalescent TMRCA Source: https://tskit.dev/msprime/docs/latest/ancestry.html Example numerical output for TMRCA calculations from Beta-coalescent simulations with different population sizes. ```text 0.14959691919068155 14.286394871874865 ``` -------------------------------- ### Simulate Ancestry with Start Time and Duration Source: https://tskit.dev/msprime/docs/latest/_sources/ancestry.md Illustrates how start_time affects the total simulation duration when a model duration is specified. The simulation continues for the specified duration from the start_time. ```python ts = msprime.sim_ancestry( 3, population_size=10, start_time=5, model=msprime.DiscreteTimeWrightFisher(duration=10), random_seed=1234) SVG(ts.draw_svg(y_axis=True)) ``` -------------------------------- ### Example Output for Beta-Coalescent TMRCA (Alpha=1.1) Source: https://tskit.dev/msprime/docs/latest/ancestry.html Example numerical output for TMRCA calculations from Beta-coalescent simulations with alpha=1.1 and different population sizes. ```text 16.311807036386615 25.85247192870844 ``` -------------------------------- ### Create initial state tree sequence Source: https://tskit.dev/msprime/docs/latest/_sources/ancestry.md Create an initial tree sequence by simulating ancestry for a specified duration. This sets up the base state for further simulations. ```python initial_ts = msprime.sim_ancestry(1, end_time=0) initial_ts ``` -------------------------------- ### Create and Visualize Island Model with Demes Source: https://tskit.dev/msprime/docs/latest/_sources/demography.md Creates an msprime island model, converts it to a Demes Graph, and visualizes it using demesdraw. Requires matplotlib for plotting. ```python import demesdraw import matplotlib.pyplot as plt demography = msprime.Demography.island_model([300] * 3, 1e-5) demography.add_population(name="ancestral", initial_size=1000) demography.add_population_split(time=500, derived=[0, 1, 2], ancestral="ancestral") graph = msprime.Demography.to_demes(demography) fig, ax = plt.subplots() # use plt.rcParams["figure.figsize"] demesdraw.tubes(graph, ax=ax, seed=1) plt.show() ``` -------------------------------- ### Initialize and Configure Demography Object Source: https://tskit.dev/msprime/docs/latest/_sources/demography.md Create a Demography object and add populations with their initial sizes, growth rates, and descriptions. The 'initially_active' flag is crucial for populations that are ancestral and contemporary. ```python import msprime demography = msprime.Demography() demography.add_population( name="YRI", description="Africa", initial_size=12300, initially_active=True, ); demography.add_population( name="CEU", description="European", initial_size=N_CEU, growth_rate=r_CEU, ) demography.add_population( name="CHB", description="East Asian", initial_size=N_CHB, growth_rate=r_CHB, ) demography.add_population( name="OOA", description="Bottleneck out-of-Africa population", initial_size=2100, ) ``` -------------------------------- ### Check Pip Version Source: https://tskit.dev/msprime/docs/latest/installation.html Verifies that pip is installed and reports its version. This is a prerequisite check before installing msprime using pip, ensuring Python 3.11 or greater is available. ```bash $ python3 -m pip --version ``` -------------------------------- ### Initialize Submodules in Existing Repository Source: https://tskit.dev/msprime/docs/latest/_sources/development.md If you have already cloned the repository without submodules, use this command to initialize and update them recursively. ```bash git submodule update --init --recursive ``` -------------------------------- ### Run msprime program with User Install Source: https://tskit.dev/msprime/docs/latest/installation.html Executes the 'mspms' program installed via pip with the '--user' flag. This requires the '~/.local/bin' directory to be in your system's PATH. ```bash $ ~/.local/bin/mspms ``` -------------------------------- ### Get the mean rate of a RateMap Source: https://tskit.dev/msprime/docs/latest/_sources/rate_maps.md Access the mean_rate attribute to get the weighted average rate across the entire RateMap. This provides a single value representing the overall rate. ```python rate_map.mean_rate ``` -------------------------------- ### Simulate ancestry with default parameters Source: https://tskit.dev/msprime/docs/latest/_sources/ancestry.md Runs a simple ancestry simulation with 2 samples and displays a summary of the resulting tree sequence. ```python ts = msprime.sim_ancestry(2) ts ``` -------------------------------- ### Initialize msprime Simulator with Demography Source: https://tskit.dev/msprime/docs/latest/ancestry.html Initializes the msprime Simulator with various parameters, including demographic models, recombination and gene conversion maps, and simulation time bounds. Ensure that the demography object is correctly configured before simulation. ```python return Simulator( tables=initial_state, recombination_map=recombination_map, gene_conversion_map=gene_conversion_map, gene_conversion_tract_length=gene_conversion_tract_length, discrete_genome=discrete_genome, ploidy=ploidy, demography=demography, models=models, store_migrations=record_migrations, additional_nodes=additional_nodes, coalescing_segments_only=coalescing_segments_only, start_time=start_time, end_time=end_time, num_labels=num_labels, random_generator=random_generator, stop_at_local_mrca=stop_at_local_mrca, ) ``` -------------------------------- ### Publish Benchmark Report Source: https://tskit.dev/msprime/docs/latest/development.html Generate a browsable report of benchmark results. ```bash asv publish ``` ```bash asv preview ``` -------------------------------- ### Simulate Ancestry with Demography and Start Time Source: https://tskit.dev/msprime/docs/latest/_sources/ancestry.md Simulates ancestry with a defined population demography and samples taken at specific times before the simulation's start time. This demonstrates how fixed-time events are handled relative to the start_time. ```python demography = msprime.Demography() demography.add_population(name="A", initial_size=100) demography.add_population(name="B", initial_size=100) demography.add_population(name="C", initial_size=100) demography.add_population_split(time=5, derived=["A", "B"], ancestral="C") ts = msprime.sim_ancestry( samples=[ msprime.SampleSet(1, population="A", time=1), msprime.SampleSet(1, population="B", time=2), msprime.SampleSet(1, population="C", time=6), ], demography=demography, ploidy=1, start_time=10, random_seed=1) ts.tables.nodes ``` -------------------------------- ### Getting the First Tree Source: https://tskit.dev/msprime/docs/latest/_sources/CHANGELOG.md The `TreeSequence.first()` method returns the first tree in the sequence. ```python ts.first() ``` -------------------------------- ### Initialize Out of Africa Demography Model Source: https://tskit.dev/msprime/docs/latest/_sources/demography.md Sets up the 'Out of Africa' demographic model using msprime's built-in function. This is a prerequisite for comparing inverse coalescence rates to actual population sizes. ```python demography = msprime.Demography._ooa_model() ``` -------------------------------- ### Get Number of Epochs Source: https://tskit.dev/msprime/docs/latest/_modules/msprime/demography.html Returns the total number of epochs defined within the demographic model. ```python @property def num_epochs(self): """ Returns the number of epochs defined by the demographic model. """ return len(self.epochs) ``` -------------------------------- ### Get Sequence Length Source: https://tskit.dev/msprime/docs/latest/_modules/msprime/intervals.html Returns the total physical length of the chromosome represented by the recombination map. ```python def get_sequence_length(self): return self.map.sequence_length ```