Skip to content
CAI
Software that uses CAICheck a score

MomentsLD/moments

53.8

Adequate · 15 November 2026

32.9k

lines of production code

Python

primary language

4

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

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 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

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

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. Also in this area: 1 commit (1 fix) fixing examples.

examples/LD · medium confidence · unverified

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

Behavioural changes

2 commits (0 fixes) modifying examples

A change to existing behaviour in examples — 2 commits, 1 file: “Apply black formatting throughout”; “conform with demes”.

examples · medium confidence · unverified

2 commits (0 fixes) modifying examples/sfs\_inference\_time\_series

A change to existing behaviour in examples/sfs\_inference\_time\_series — 2 commits, 3 files: “Bump to 1.1.9”; “Apply black formatting throughout”.

_examples/sfs\_inference\_time\series · medium confidence · unverified

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 cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Score

  • CAI 56 → 54 (-2.0)
  • Rubric changed (rubric-2026.10.5 → rubric-2026.11.4) — scores are not directly comparable.

Lenses

  • Code Health 68 → 60 (-7.7)
  • Architecture 89 → 100 (+11.3)
  • Maturity 49 → 49 (+0.3)
  • Readiness 50 → 49 (-1.9)
  • Security 75 → 63 (-11.8)

Resolved (84)

  • Change coupling: TriSpectrum_mod.py ↔ TLSpectrum_mod.py (moments/Triallele/TriSpectrum_mod.py)
  • Demes._augment_with_ancient_samples (cyclomatic 18) (moments/Demes/Demes.py)
  • Duplicated block (13 lines × 6) (moments/LD/Matrices.py)
  • Duplicated block (14 lines × 3) (moments/TwoLocus/Util.py)
  • Duplicated block (14 lines × 4) (moments/Demes/Inference.py)
  • Duplicated block (14–26 lines × 2) (bench/report.py)
  • Duplicated block (21 lines × 4) (moments/Inference.py)
  • Duplicated block (21 lines × 6) (moments/LD/Matrices.py)
  • Duplicated block (23–25 lines × 2) (moments/Demes/Inference.py)
  • Duplicated block (26 lines × 2) (moments/Demes/Inference.py)
  • Duplicated block (26–27 lines × 2) (moments/LD/Godambe.py)
  • Duplicated block (5 lines × 14) (moments/LD/Matrices.py)
  • Duplicated block (5 lines × 2) (moments/Integration.py)
  • Duplicated block (5 lines × 2) (moments/LD/stats_from_genotype_counts.py)
  • Duplicated block (5 lines × 2) (moments/LD/stats_from_genotype_counts.py)
  • Duplicated block (5 lines × 2) (moments/LD/stats_from_genotype_counts.py)
  • Duplicated block (5 lines × 2) (moments/LD/stats_from_genotype_counts.py)
  • Duplicated block (5 lines × 2) (moments/LD/stats_from_genotype_counts.py)
  • Duplicated block (5 lines × 2) (moments/TwoLocus/Util.py)
  • Duplicated block (5 lines × 5) (moments/Triallele/Jackknife.py)
  • …and 64 more

New (86)

  • Demes._get_integration_parameters (cognitive 22) (moments/Demes/Demes.py)
  • Duplicated block (11 lines × 2) (moments/LD/init.py)
  • Duplicated block (11 lines × 5) (moments/LD/Matrices.py)
  • Duplicated block (13 lines × 6) (moments/LD/Matrices.py)
  • Duplicated block (13–14 lines × 3) (moments/TwoLocus/Util.py)
  • Duplicated block (54 lines × 4) (moments/Inference.py)
  • Duplicated block (59 lines × 3) (moments/LD/Inference.py)
  • Duplicated block (6 lines × 14) (moments/LD/Matrices.py)
  • Duplicated block (70 lines × 2) (moments/Inference.py)
  • Duplicated block (73 lines × 2) (moments/Demes/Inference.py)
  • Duplicated block (8 lines × 5) (moments/Triallele/Jackknife.py)
  • Duplicated block (91–93 lines × 2) (moments/Inference.py)
  • Edited copies of one member (3 members, 17+ corresponding lines) (moments/Inference.py)
  • Edited copies of one member (3 members, 46+ corresponding lines) (moments/Spectrum_mod.py)
  • Edited copies of one member (3 members, 5+ corresponding lines) (moments/Integration_nomig.py)
  • Edited copies of one member (4 members, 18+ corresponding lines) (moments/TwoLocus/Util.py)
  • Edited copies of one member (4 members, 20+ corresponding lines) (moments/Integration.py)
  • Edited copies of one member (4 members, 47+ corresponding lines) (moments/Demes/Inference.py)
  • Edited copies of one member (4 members, 5+ corresponding lines) (moments/Integration.py)
  • Edited copies of one member (4 members, 5+ corresponding lines) (moments/Integration.py)
  • …and 66 more

Changes since last survey

  • 82 commits — 69 feature/other, 13 fixes

By area

  • (repo) — 26 commits
  • docs/introduction.rst — 10 commits
  • moments/Demes — 9 commits
  • moments/LD — 6 commits
  • .github/workflows — 5 commits
  • (root) — 4 commits
  • docs/ld — 3 commits
  • docs/sfs — 3 commits
  • moments/TwoLocus — 3 commits
  • docs/extensions — 2 commits
  • bench/bench.py — 1 commit
  • docs/api — 1 commit
  • docs/data — 1 commit
  • docs/installation.rst — 1 commit
  • examples/LD — 1 commit
  • moments/ModelPlot.py — 1 commit
  • moments/Plotting.py — 1 commit
  • moments/Spectrum_mod.py — 1 commit
  • tests/readme.md — 1 commit
  • tests/test_LD.py — 1 commit

Notable commits

  • fix: Check compute_le_statistics arguments. Fixes #286.
  • fix: Fix Demes integration when all samples are ancient
  • fix: Fix L-BFGS-B bounds in Demes inference when not optimizing in log space
  • fix: Fix LD LRT_adjust and use 2*(ll difference) as the LRT statistic
  • fix: Fix ModelPlot bug with newer matplotlib
  • fix: Fix bug in TwoLocus integration with gamma<0
  • fix: Fix floating unused code block in sfs/parsing docs
  • fix: Fix matplotlib colormap deprecation in 2D SFS plotting
  • fix: Fix parsing of ancient sample popids in Demes Inference
  • fix: Fix rec_map_file format in compute_ld_statistics docstring.
  • fix: Fixes cache names for TwoLocus precomputed TLSpectrum objects
  • fix: Pin setuptools>-77 and fix license field in pyproject.toml
  • fix: TwoLocus docs and bug audit
  • change: Add black formatting check to CI
  • change: Add documentation about contributing code
  • change: Add missing functions to API reference, convert optimizer and LD plotting docstrings to Sphinx format.
  • change: Add python 3.15 support, update CI python versions
  • change: Add requirements/docs.txt for building the docs, and use it in CI and the install docs.
  • change: Add tests for Demes Inference and raise error for two params pointing to same value in a graph
  • change: Apply black formatting throughout
  • …and 62 more

Written by cca.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 15 November 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit c9853099d04e22da531b4fb9eb764954691ad4a7 — the exact code this score is about.
  • Scored under rubric-2026.11.4 — the same rubric and the same method as every other entry in this index.
  • Measured by Canine Code Analyzer (cca.canine.dev) using cca measure-2026.11.65+preprod-3c33c1882dc1.