# Population Genetics API
> Population-genetics maths as an API, computed locally and deterministically. The hardy-weinberg endpoint applies the Hardy-Weinberg principle, p² + 2pq + q² = 1 — give a dominant allele frequency p, a recessive q, or the homozygous-recessive (affected) frequency q² and it returns all the allele and genotype frequencies, including the carrier frequency 2pq. The punnett endpoint crosses two parent genotypes and returns the offspring genotype and phenotype ratios, handling a single gene (a monohybrid 1:2:1 / 3:1 cross), two genes (a dihybrid 9:3:3:1 cross) and up to four genes by independent assortment. The carrier endpoint takes the incidence of a recessive disease — as a fraction or one-in-N — and returns the recessive allele frequency q = √incidence, the carrier frequency 2pq, the one-in-N carrier rate and, for a given population, the expected number of carriers and affected individuals. Everything is computed locally and deterministically, so it is instant and private. Ideal for genetics-education, genetic-counselling, breeding and biology app developers, inheritance and risk tools, and biology teaching. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 3 endpoints. This is population genetics; for DNA sequence analysis use a DNA API.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/genetics-api/..."
```

## Pricing
- **Free** (Free) — 2,000 calls/Mo, 2 req/s
- **Starter** ($5/Mo) — 25,000 calls/Mo, 5 req/s
- **Pro** ($15/Mo) — 150,000 calls/Mo, 15 req/s
- **Mega** ($49/Mo) — 759,000 calls/Mo, 40 req/s

## Endpoints

### Genetics

#### `GET /v1/carrier` — Carrier frequency

**Parameters:**
- `incidence` (query, optional, string) — Affected fraction (q²) Example: `0.0004`
- `one_in` (query, optional, string) — Or 1 in N affected
- `population` (query, optional, string) — Population for expected counts

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/genetics-api/v1/carrier?incidence=0.0004"
```

**Response:**
```json
{
    "data": {
        "note": "For a recessive disease, q = √(affected frequency); the carrier frequency is 2pq. Carriers vastly outnumber the affected.",
        "inputs": {
            "incidence": 0.0004
        },
        "carrier_one_in": 25.51,
        "carrier_frequency": 0.0392,
        "affected_frequency": 0.0004,
        "dominant_allele_freq_p": 0.98,
        "recessive_allele_freq_q": 0.02
    },
    "meta": {
        "timestamp": "2026-06-05T03:09:02.163Z",
        "request_id": "b6fe5a3f-f49d-4599-97b6-3e44730122ef"
    },
    "status": "ok",
    "message": "Carrier frequency",
    "success": true
}
```

#### `GET /v1/hardy-weinberg` — Hardy-Weinberg

**Parameters:**
- `p` (query, optional, string) — Dominant allele frequency (0–1) Example: `0.6`
- `q` (query, optional, string) — Or recessive allele frequency
- `aa_frequency` (query, optional, string) — Or homozygous-recessive frequency q²

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/genetics-api/v1/hardy-weinberg?p=0.6"
```

**Response:**
```json
{
    "data": {
        "note": "Hardy-Weinberg: p² + 2pq + q² = 1. q² is the recessive (affected) frequency; 2pq is the carrier frequency.",
        "inputs": {
            "source": "p"
        },
        "heterozygous_Aa": 0.48,
        "carrier_frequency": 0.48,
        "dominant_allele_freq_p": 0.6,
        "homozygous_dominant_AA": 0.36,
        "homozygous_recessive_aa": 0.16,
        "recessive_allele_freq_q": 0.4
    },
    "meta": {
        "timestamp": "2026-06-05T03:09:02.263Z",
        "request_id": "59cfb750-e965-490a-958a-1bb749ae33db"
    },
    "status": "ok",
    "message": "Hardy-Weinberg",
    "success": true
}
```

#### `GET /v1/punnett` — Punnett cross

**Parameters:**
- `parent1` (query, required, string) — Parent 1 genotype (e.g. Aa, AaBb) Example: `Aa`
- `parent2` (query, required, string) — Parent 2 genotype Example: `Aa`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/genetics-api/v1/punnett?parent1=Aa&parent2=Aa"
```

**Response:**
```json
{
    "data": {
        "note": "Offspring distribution from independent assortment. Phenotype 'A_' means at least one dominant allele; 'aa' is homozygous recessive.",
        "inputs": {
            "genes": 1,
            "parent1": "Aa",
            "parent2": "Aa"
        },
        "genotypes": [
            {
                "percent": 25,
                "fraction": 0.25,
                "genotype": "AA",
                "out_of_16": 4
            },
            {
                "percent": 50,
                "fraction": 0.5,
                "genotype": "Aa",
                "out_of_16": 8
            },
            {
                "percent": 25,
                "fraction": 0.25,
                "genotype": "aa",
                "out_of_16": 4
            }
        ],
        "phenotypes": [
            {
                "percent": 75,
                "fraction": 0.75,
                "phenotype": "A_"
            },
            {
                "percent": 25,
                "fraction": 0.25,
                "phenotype": "aa"
            }
        ]
    },
    "meta": {
        "timestamp": "2026-06-05T03:09:02.361Z",
        "request_id": "ad52aa69-be45-4afd-a9d2-4c7ceef0ca2e"
    },
    "status": "ok",
    "message": "Punnett cross",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Spec

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/genetics-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "notes": "Frequencies are 0–1. Genotypes are written as allele pairs (Aa, AaBb …); a capital letter is the dominant allele. Independent assortment is assumed.",
        "service": "genetics-api",
        "formulae": {
            "hardy_weinberg": "p² + 2pq + q² = 1",
            "carrier_frequency": "2pq, with q = √(affected frequency)"
        },
        "endpoints": {
            "GET /v1/meta": "This document.",
            "GET /v1/carrier": "Carrier frequency and counts from a recessive-disease incidence.",
            "GET /v1/punnett": "Offspring genotype and phenotype ratios from two parent genotypes.",
            "GET /v1/hardy-weinberg": "Genotype frequencies from an allele frequency (or the recessive incidence)."
        },
        "description": "Population-genetics calculator: Hardy-Weinberg genotype and allele frequencies, Punnett-square crosses for one or more genes, and carrier frequency from a recessive-disease incidence."
    },
    "meta": {
        "timestamp": "2026-06-05T03:09:02.424Z",
        "request_id": "0c43b2ca-8442-4654-9ac4-cc8792e21a13"
    },
    "status": "ok",
    "message": "Meta",
    "success": true
}
```


---
Marketplace page: https://www.oanor.com/api/genetics-api
OpenAPI spec: https://www.oanor.com/api/genetics-api/openapi.json
