ExtantApe

studbook

by ExtantApe
OnePedigree
Other
v3
^3.80.0
NOASSERTION

Overview

Summary generated from the README

Adds studbook records and pedigree-based genetics analysis to Payload collections through a GET endpoint that computes and redacts results. Your app supplies the data and every access decision through callbacks. Optional numbering endpoints store studbook numbers in a collection that needs two unique database indexes; only MongoDB is tested. Early alpha, licensed PolyForm Noncommercial.

Features

  • Computes kinship, inbreeding, mean kinship, gene diversity, founder genome equivalents and pedigree completeness
  • Handles uncertain parents with probabilities, plus unknown and wild founders
  • Redacts private animals and gates genetics visibility by per-request access callbacks
  • Exports PMx .ped files for users permitted by an export callback
  • Numbering endpoints assign permanent and temporary studbook numbers and renumber while keeping old ones
  • Checks studbook numbers for duplicates, reuse and malformed values

Use cases

  • Manage a conservation breeding studbook with genetic analysis inside a Payload app
  • Export a population pedigree to PMx for breeding program planning
  • Share studbook data with keepers while hiding private animals and genetics from other readers

From the author

OnePedigree studbook: species-neutral studbook numbering, pedigree-based kinship, inbreeding, mean kinship, gene diversity and founder analysis, and PMx export, for any managed population.

Installation

npm i @extantape/onepedigree-studbook

0

Stars

0

Forks

4

Open Issues

Yesterday

Last Updated

961

Weekly Downloads

v0.1.0-alpha.27

npm Version

51.8 KB

Unpacked Size

1

Dependencies

Repository stars

00 since Oct 25

Show data
Repository stars by day (UTC)
DateStars
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
Nov 14, 20260
Nov 13, 20260
Nov 12, 20260
Nov 11, 20260
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
Nov 7, 20260
Nov 6, 20260
Nov 5, 20260
Nov 4, 20260
Nov 3, 20260
Nov 2, 20260
Nov 1, 20260
Oct 31, 20260
Oct 30, 20260
Oct 29, 20260
Oct 28, 20260
Oct 27, 20260
Oct 26, 20260
Oct 25, 20260

Shared by 2 plugins in ExtantApe/OnePedigree.

npm weekly downloads

1K+1K since Nov 15

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 20261,011
Dec 4, 20261,311
Dec 3, 20261,332
Dec 2, 20261,308
Dec 1, 2026817
Nov 30, 2026684
Nov 29, 2026753
Nov 28, 2026687
Nov 27, 2026325
Nov 26, 2026269
Nov 25, 2026231
Nov 24, 2026189
Nov 23, 2026300
Nov 22, 2026192
Nov 21, 2026190
Nov 20, 2026186
Nov 19, 2026181
Nov 18, 2026175
Nov 17, 2026161
Nov 16, 20260
Nov 15, 20260

Each point is npm's rolling 7-day download count.

Health Score

68/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1440463679-studbook.svg)](https://payloaddirectory.dev/plugins/1440463679-studbook)
HTML
<a href="https://payloaddirectory.dev/plugins/1440463679-studbook"><img src="https://payloaddirectory.dev/badge/1440463679-studbook.svg" alt="Payload Directory"></a>
Updated Dec 4, 2026Created Oct 31, 2026Published Nov 29, 2026

README

@extantape/onepedigree-studbook

Studbook-style records and analysis for any managed population, built on OnePedigree. Early alpha: the calculations below are tested against textbook values, and nothing here has been checked against a real studbook or PMx run yet.

  • Pedigree-based kinship and inbreeding, mean kinship (MK), gene diversity (GD), founder genome equivalents (FGE), founder representation and pedigree completeness ("Known"). Every number is pedigree-based: it assumes founders are unrelated unless the pedigree says otherwise.
  • Parents known only as candidates with probabilities (studbook MULT) count by expectation. Unknown and wild parents (UNK, WILD) are unique unrelated founders, unless clutchmates share one (UNK1, WILD1).
  • Studbook numbers kept as text: permanent numbers run 1, 2, 3… with no leading zeros or letters, temporary ones are T1, T2…, and no number is ever given twice. nextStudbookNumber, renumber (keeps every old number) and checkStudbookNumbers (duplicates, reuse, malformed numbers; gaps are a notice).

Payload

@extantape/onepedigree-studbook/payload adds GET /<collection>/studbook/:studbook to a Payload collection. Your app supplies the data and every access decision; the endpoint computes and redacts:

import { studbookEndpoint } from '@extantape/onepedigree-studbook/payload'

endpoints: [studbookEndpoint({
  source: ({ studbook, req }) => loadStudbook(studbook, req),          // read as the request's user; null is a 404
  geneticsVisibleFor: ({ animal, req }) => isCoordinator(req) || ownsAnimal(req, animal),
  canExport: ({ req }) => isCoordinatorOrKeeper(req),
  holderLabel: (code, req) => holderNameFor(code, req),            // or "Private holder"
})]
  • Private animals are counted in every number but come back as { private: true }, and are never named as a parent, founder or holder.
  • Parents come back as codes (a studbook number, Private, MULT, WILD or UNK), with a MULT parent's candidates and their probabilities in mult.
  • MK, F and Known come back only where geneticsVisibleFor says yes. Population GD, FGE and founders come back only when the reader may see every animal's numbers, private animals included, since GD would otherwise give the hidden ones away.
  • ?format=pmx returns the PMx .ped file to those canExport allows, and 403 to everyone else.
  • A callback that throws, or answers anything but true, counts as no.

studbookNumberEndpoints({ source, numbers }) keeps studbook numbers in a collection of yours, one document per studbook and animal. POST …/studbook/:studbook/numbers { animal, temporary?, number? } gives a first number. POST …/numbers/renumber { animal, to? } moves an animal to a new number and keeps the old one; it's only offered when you name an oldNumbersField. Writes use the reader's own access, and numbers held by animals they can't see are never reused.

Breaking change in the release after 0.1.0-alpha.27: numbering now needs the two unique indexes below in the database. Until they are there, both endpoints answer 500 and write nothing.

The number collection needs two unique indexes, which studbookNumberIndexes(numbers) declares: add indexes: [...studbookNumberIndexes(numbers)] to it. They are what keeps one number off two animals and one animal to one document when requests arrive together. The database enforces them for every server process; two real server processes were not tested, and the tests stand in for the second one with a write made while the endpoint's write is held. A request that meets a number someone else just took reads again and takes the next one. Requests for one studbook in one process run one at a time, and so do requests that share a transaction. A number an animal has moved off stays reserved through oldNumbersField, which is read before each write and again after it. A renumber reads and writes in one transaction, so two changes to one animal from two processes can't overwrite each other on MongoDB with transactions (a replica set). Without database transactions, or on a SQL adapter at its default isolation, that last case isn't guarded between processes. Only MongoDB is tested.

Declaring the indexes doesn't build them. The MongoDB adapter builds them at startup only with ensureIndexes: true; with it off they are built in the background, and a failed build is silent. So before every write the endpoints ask the database which indexes it has. Unless both are there, unique, on exactly those two fields each and not partial, the answer is 500, nothing is written, and the server log says which index is missing and names up to three stored duplicates for each if that is why. To set it up:

  1. Clear duplicates first, because the database can't build a unique index over them. In mongosh, with your own collection and field names:

    const twice = (field) => db.getCollection('studbook-numbers').aggregate([
      { $group: { _id: { studbook: '$studbook', value: '$' + field }, count: { $sum: 1 }, ids: { $push: '$_id' } } },
      { $match: { count: { $gt: 1 } } },
    ])
    twice('number') // one number on two animals
    twice('animal') // two documents for one animal
    

    Decide which document of each pair is right, and renumber or remove the other.

    The indexes cover the whole number collection, so one stored duplicate blocks numbering in every studbook of that collection, including studbooks with no duplicate of their own. Run both searches across the whole collection, as above, and clear everything they find.

  2. Start the server with ensureIndexes: true on the adapter. Payload then waits for the indexes before it finishes connecting.

If duplicates are still stored at step 2, the server doesn't start: Payload reports that it cannot connect to MongoDB, with MongoDB's own E11000 duplicate key error naming the index and the first duplicate value. That message is Payload's and MongoDB's, and this package can't reword it. Go back to step 1.

To get the clearer message at startup with ensureIndexes off, call studbookNumberIndexProblem(payload, numbers) in onInit. It gives null when both indexes are there, or the same text the endpoints log, and you can throw it. Just after a start with ensureIndexes off, the background build may still be running, so a message in onInit can come early, and numbering answers 500 for as long as the build takes. Turning ensureIndexes on avoids both.

On a database other than MongoDB the package can't list the indexes itself, so numbering is refused unless you pass indexesInDatabase in numbers: a function that answers true once the database has both. That path is not tested against a real SQL database.

When two server processes number the same animal at the same moment and pick the same number, one write is stored and the database refuses the other as a duplicate. The refused request answers 409 with "The number collection refused a write as a duplicate, and this animal already holds the number this request meant to give it. Either another request stored it at the same moment, or a hook of yours refused its own write to the number collection after this request stored it. Read the animal's current number before trying again." This is tested on MongoDB only.

A renumber can meet the same overlap: its write is refused because another animal just took the number, and before it reads again another request has moved this animal to that number. What it answers depends on database transactions. With transactions on, the refused write starts the renumber again from a fresh read. It finds the animal already moved and moves it once more, so it answers 200 with the next number, and the number the other request gave is kept among the old numbers. With transactions off, it answers the 409 above and stores nothing.

Only the number collection's own refusal counts for that 409: Payload's unique-value error for the number collection naming the studbook field with Payload's own "must be unique" wording, or MongoDB's duplicate-key error for that collection whose key is the studbook and number fields or the studbook and animal fields. A validation error that a hook of yours on the number collection raises with other wording is handled as the next paragraph says. A hook that copies Payload's wording exactly looks like a real refusal and gets the 409. A unique error from anywhere else, such as one a hook of yours raises after the write, is handled as the next paragraph says. A hook of yours that itself writes to the number collection can hit the same unique index. Payload's MongoDB adapter then raises the very error the endpoint counts. If the request's own number was already stored, the endpoint answers 409 although that number stays stored and only the hook's write was refused. The 409 text says both possibilities, so read the animal's current number after it. Better to keep such hooks from writing studbook numbers, or have them write to another collection.

With database transactions off, a hook of yours on the number collection that throws after a write (an afterChange, for example) can't undo the write. The endpoint then answers 201 or 200 with the stored number and a notices line saying a later step failed, and logs the error. With transactions on, the write is rolled back and the error is passed on.

Payload is an optional peer dependency; the main entry point doesn't use it.

Not affiliated with any zoo association or software vendor. "PMx" names the free analysis program whose input format this package will write.

License

PolyForm Noncommercial 1.0.0. See LICENSE.

Similar plugins