Skip to content
CAI
Software that uses CAICheck a score

MomentsLD/moments

56.8

Adequate · 3 October 2026

33.7k

lines of production code

Python

primary language

1

measurement over time

CAI band scale
CAI lens gauges

What this system is

This system is a Python library for population genetics that infers demographic history and selection from genetic data using diffusion approximations. It provides core capabilities for computing and analyzing site frequency spectra (SFS) and linkage disequilibrium (LD) across single and multiple populations. The package supports complex modeling scenarios, including admixture, variable migration, and time-series data, with performance-critical components implemented in Cython.

How it got here

2015–2016 — Initial release and core development

7 changes.

This period marks the initial release of the moments package, establishing the core framework for demographic history and selection inference using diffusion approximations. It involved implementing the primary Python and Cython modules for site frequency spectrum calculations, alongside comprehensive unit tests and example scripts for data extraction and model inference.

2017–2019 — Linkage disequilibrium and multi-allele modeling

5 changes.

The project expanded its population genetics capabilities by introducing modules for three-allele frequency spectra and linkage disequilibrium (LD) inference. These features enabled the simulation and statistical analysis of complex demographic scenarios, including multi-locus interactions and migration models. The period also included modernizing the build system and updating core dependencies.

2020–2022 — Demes integration and example expansion

6 changes.

This period focused on integrating the Demes package for demographic modeling and expanding the library's example suite. Key additions included a new Demes submodule for defining demographic histories and computing statistics, alongside diverse examples covering ANGSD data processing, variable migration rates, and time-series SFS inference.

Features

Add demes-based SFS inference example

The examples/demes\_inference directory now includes a complete workflow for performing demographic inference using the site frequency spectrum (SFS) with demes graphs. This includes a Python script (run\_optimization.py) that demonstrates how to load a demes YAML file (gutenkunst\_ooa.yml), apply inference options (inference\_options.yml), and optimize parameters against observed SFS data (data.uL\_0.36.fs).

_examples/demes\inference · high confidence

Add example for variable migration rates in isolation-with-migration model

A new example script, examples/variable\_migration.py, demonstrates an isolation-with-migration model where migration rates are defined as constant proportions of source demes rather than fixed values. The script implements time-dependent migration functions that rescale source migration rates to maintain constant proportions of migrants relative to population sizes, illustrating how to handle variable migration dynamics in the moments library.

examples · high confidence

Add fs\_from\_data example for extracting and correcting population frequency spectra

The examples/fs\_from\_data directory now includes a complete example demonstrating how to extract a site frequency spectrum from SNP data files using the moments library. The example script (fs\_from\_data.py) shows how to parse a data file (data.txt) containing allele counts for multiple populations (ASW, YRI, CEU, MXL, CHB, JPT) and extract a folded or unfolded spectrum for specific populations (YRI and CEU) projected to 20 samples each. It also demonstrates how to apply statistical corrections for ancestral state misidentification using a trinucleotide transition rate matrix (Q.HwangGreen.human.dat) and trinucleotide frequencies (tri\_freq.dat) to generate a corrected frequency spectrum (fux\_table.dat).

_examples/fs\_from\data · high confidence

Add time-series SFS inference example

Introduces a new example in the \examples/sfs\_inference\_time\_series\ directory that demonstrates how to simulate and infer demographic history using time-series site frequency spectra. The example includes configuration files (\model.yaml\, \options.yaml\) defining a single-deme model with three epochs and a Python script (\simulate\_data.py\) that uses \msprime\ and \moments\ to generate synthetic data, perform parameter inference, and compute uncertainty estimates via bootstrapping.

_examples/sfs\_inference\_time\series · high confidence

Added YRI\_CEU demographic inference example

Added a new example in the examples/YRI\_CEU directory that demonstrates demographic model inference using the moments library. The example includes a custom demographic model (prior\_onegrow\_mig) featuring population growth, split, bottleneck, and migration, along with a Python script that optimizes parameters against YRI/CEU site frequency spectrum data, calculates likelihoods, estimates parameter uncertainties using the Godambe Information Matrix, and performs a likelihood-ratio test comparing models with and without migration.

_examples/YRI\CEU · high confidence

Added benchmark suite for comparing dadi and Moments demographic simulations

The bench directory now contains a complete set of scripts to benchmark and compare the performance of the dadi and Moments libraries. This includes demographic model definitions for both libraries (in demographic\_models\_dadi.py and demographic\_models\_moments.py), a main runner script (bench.py) that executes simulations and calculates metrics like execution time, entropy, and likelihood differences, and a report generator (report.py) that produces LaTeX tables comparing the two tools. Additionally, gen\_lim\_fs\_extrap.py provides scripts to generate limit files for various 1D and 2D scenarios using dadi's Richardson extrapolation.

bench · high confidence

Example demonstrating LD parsing across multiple chromosomes

Added a new example script and BED file that demonstrate how to parse linkage disequilibrium (LD) statistics from VCF files containing multiple chromosomes. The example simulates data across four chromosomes, generates separate and combined VCFs, and verifies that LD statistics computed per-chromosome match those computed from the combined file using a specific BED file for region definition.

_examples/parsing\_ld\_from\_multiple\chromosomes · high confidence

Initial release of moments demographic modeling library

This change introduces the core moments library for population genetics inference, providing a complete framework for computing and integrating site frequency spectra (SFS) under various demographic models. The release includes modules for defining demographic scenarios in \Demographics1D\, \Demographics2D\, and \Demographics3D\ (such as standard neutral models, population splits, isolation-with-migration, and the Out-of-Africa model), as well as the underlying numerical integration engines in \Integration.py\ and \Integration\_nomig.py\. It also adds support for selection and dominance via \LinearSystem\ modules, parameter uncertainty estimation using Godambe information in \Godambe.py\, and optimization routines in \Inference.py\. The library is implemented with performance-critical components in Cython (\Jackknife.pyx\, \LinearSystem\_1D.pyx\, \LinearSystem\_2D.pyx\) to handle the computation of drift, mutation, and selection matrices for multidimensional SFS.

moments · high confidence

Initial release of moments population genetics package

This entry marks the initial commit of the \moments\ package, introducing a suite of methods for demographic history and selection inference from genetic data using diffusion approximations. The release includes the core Python modules (\moments\, \moments.LD\, \moments.Triallele\, \moments.TwoLocus\, \moments.Demes\), Cython extensions for performance-critical calculations (Jackknife, LinearSystem, Tridiag\_solve, genotype calculations), and comprehensive documentation (README, epydoc config, MANIFEST). It also establishes the project's licensing (MIT), build configuration (setup.py, requirements.txt), and repository hygiene (.gitignore). The package supports Python 3 and provides tools for both single-locus (SFS) and two-locus (LD) analyses, including multi-population inference and admixture modeling.

(repo-wide) · high confidence

Introduce Triallele frequency spectrum module with integration and jackknife support

The moments library now includes a new Triallele module that enables the simulation and analysis of three-allele frequency spectra under the infinite sites model. This addition introduces the TriSpectrum class for managing triallelic data, a Crank-Nicolson integration scheme in Integration.py that supports adaptive timesteps and variable population sizes, and a Jackknife module for extrapolating spectrum values to higher sample sizes. The module also provides basic demographic models (Demographics.py) and numerical utilities (Numerics.py) to handle drift and mutation operators for these three-allele systems.

moments/Triallele · high confidence

Introduce moments.LD module for linkage disequilibrium-based demographic inference

This change introduces the new \moments.LD\ package, enabling users to compute and infer demographic parameters from linkage disequilibrium (LD) statistics. The module provides a core \LDstats\ class to manage multi-population LD and heterozygosity data, alongside \Parsing\ tools to extract these statistics from VCF files. It includes \Demographics\ modules (1D, 2D, and 3D) for simulating models such as the Out-of-Africa scenario, split with migration, and exponential growth. Additionally, it offers \Inference\ routines for fitting these models to data using optimization methods and \Godambe\ information for computing parameter uncertainties.

moments/LD · high confidence

Introduce two-locus linkage disequilibrium modeling and inference

This change adds a new \moments.TwoLocus\ module that enables the computation of two-locus frequency spectra, demographic integration, and statistical inference. Users can now model linkage disequilibrium (LD) under various demographic scenarios (two-epoch, three-epoch, exponential growth) and selection models (additive, general, dominance, finite genome/reversible mutation). The module includes caching for equilibrium spectra to improve performance, jackknife variance estimation, and likelihood-based inference frameworks supporting both Poisson and multinomial models over recombination rate bins.

moments/TwoLocus · high confidence

New Demes integration module for demographic modeling

Added a new \moments.Demes\ submodule that enables users to define demographic histories using the \demes\ YAML format and compute Site Frequency Spectra (SFS) and Linkage Disequilibrium (LD) statistics from those models. This module introduces functions to handle ancient samples, apply selection and dominance coefficients, and perform demographic inference by fitting \demes\ graph parameters to observed data, effectively bridging the \demes\ package with the \moments\ inference engine.

moments/Demes · high confidence

New LD inference examples for Out-of-Africa and split-migration models

Added two new example scripts in the examples/LD directory: OOA.py demonstrates an Out-of-Africa demographic model with time-varying population sizes and migration, while parsing-and-inference-example.py provides a complete workflow for simulating data with msprime, parsing LD statistics from VCF files, and performing parameter inference using moments.LD. These examples illustrate how to use the moments.LD module for both forward simulation of linkage disequilibrium patterns and reverse inference of demographic parameters from empirical data.

examples/LD · high confidence

New examples for inferring dog/wolf demography from ANGSD data

Added two new Python scripts in the \examples/fs\_from\_angsd\ directory to demonstrate how to use the \moments\ library with site frequency spectrum (SFS) data generated by ANGSD. \parse\_angsd\_output.py\ provides a command-line tool to convert ANGSD's n-dimensional SFS output into a \moments.Spectrum\ object, handling population labels, folding, and optional visualization. \demog\_infer\_moments.py\ provides a complete workflow for demographic inference, defining a specific model for gray wolf, Greenland dog, and Chinese dog populations, and optimizing parameters to fit the observed SFS.

_examples/fs\_from\angsd · high confidence

Test coverage

Added test fixtures for single and multi-population frequency spectra; Added test suite for Demes integration, F-statistics, and LD parsing.

Dependencies

Migration to pyproject.toml and dependency updates

The project has moved its build configuration from setup.py to pyproject.toml, establishing a modern build system requiring setuptools\_scm\>=8, numpy\>=2.0, and Cython\>=0.25.0. Minimum Python support is now set to 3.11 (up to \<3.15). Key dependencies have been updated or added: numpy is pinned to \>=2.0, Cython to \>=3.1 in pyproject.toml (though requirements.txt shows a pin to \~=0.29.0), and demes is added at \>=0.2. Additional dependencies like mpmath, scipy, matplotlib, ipython, pandas, jupyter\_sphinx, demesdraw, and ruamel.yaml are included in the requirements.

(dependencies) · high confidence

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Score

  • CAI 57 → 57 (+0.2)
  • Rubric changed (rubric-2026.09.15 → rubric-2026.10.1) — scores are not directly comparable.

Lenses

  • Code Health 68 → 68 (+0.0)
  • Architecture 99 → 87 (-11.5)
  • Maturity 51 → 52 (+1.1)
  • Readiness 50 → 50 (+0.8)
  • Security 75 → 75 (+0.0)

Resolved (5)

  • Coverage not measured — no coverage collector is wired up
  • Documentation: no installation or build instructions
  • Documentation: no usage examples
  • Hotspot: moments/LD/Parsing.py (moments/LD/Parsing.py)
  • Off-boarding risk: anonymized user #1

New (5)

  • Documentation: contradicts the code (docs/introduction.rst)
  • Documentation: hard to navigate (docs/api/api_moments.rst)
  • Documentation: no usage examples (docs/installation.rst)
  • Off-boarding risk: anonymized user #1
  • Projects may be oversized for their cohesion

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

MomentsLD/moments was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 3 October 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit 375eddb2ee017eca03ba77ad89f67365b5515d64 — the exact code this score is about.
  • Scored under rubric-2026.10.1 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer preprod-4f4226d619ea.