gnomad-api-cache 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gnomad_api_cache-0.1.0/.gitattributes +2 -0
- gnomad_api_cache-0.1.0/.github/workflows/workflow.yml +109 -0
- gnomad_api_cache-0.1.0/.gitignore +12 -0
- gnomad_api_cache-0.1.0/LICENSE +21 -0
- gnomad_api_cache-0.1.0/PKG-INFO +115 -0
- gnomad_api_cache-0.1.0/README.md +103 -0
- gnomad_api_cache-0.1.0/pixi.lock +1078 -0
- gnomad_api_cache-0.1.0/pixi.toml +22 -0
- gnomad_api_cache-0.1.0/pyproject.toml +29 -0
- gnomad_api_cache-0.1.0/pyrightconfig.json +10 -0
- gnomad_api_cache-0.1.0/src/gnomad_api_cache/__init__.py +35 -0
- gnomad_api_cache-0.1.0/src/gnomad_api_cache/__main__.py +8 -0
- gnomad_api_cache-0.1.0/src/gnomad_api_cache/_utils.py +14 -0
- gnomad_api_cache-0.1.0/src/gnomad_api_cache/adapters/__init__.py +0 -0
- gnomad_api_cache-0.1.0/src/gnomad_api_cache/adapters/vcf_adapter.py +147 -0
- gnomad_api_cache-0.1.0/src/gnomad_api_cache/cache.py +328 -0
- gnomad_api_cache-0.1.0/src/gnomad_api_cache/cli.py +284 -0
- gnomad_api_cache-0.1.0/src/gnomad_api_cache/client.py +20 -0
- gnomad_api_cache-0.1.0/src/gnomad_api_cache/export.py +319 -0
- gnomad_api_cache-0.1.0/src/gnomad_api_cache/fetch.py +149 -0
- gnomad_api_cache-0.1.0/src/gnomad_api_cache/keys.py +78 -0
- gnomad_api_cache-0.1.0/src/gnomad_api_cache/query.py +305 -0
- gnomad_api_cache-0.1.0/typings/cyvcf2/__init__.pyi +60 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
# Build once, verify that single artifact across the whole supported Python
|
|
4
|
+
# range, then publish it: TestPyPI on a manual run (a dry run you can repeat),
|
|
5
|
+
# PyPI when a GitHub Release is published. Authentication is PyPI Trusted
|
|
6
|
+
# Publishing (OIDC) — no API tokens and no stored secrets.
|
|
7
|
+
on:
|
|
8
|
+
release:
|
|
9
|
+
types: [published]
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
# Least privilege by default; the two publish jobs opt into id-token below.
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
|
|
16
|
+
# Never let two publish runs race for the same version.
|
|
17
|
+
concurrency:
|
|
18
|
+
group: publish-${{ github.ref }}
|
|
19
|
+
cancel-in-progress: false
|
|
20
|
+
|
|
21
|
+
jobs:
|
|
22
|
+
build:
|
|
23
|
+
name: Build distribution
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v7
|
|
27
|
+
- uses: actions/setup-python@v7
|
|
28
|
+
with:
|
|
29
|
+
python-version: "3.12"
|
|
30
|
+
- name: Install build backend
|
|
31
|
+
run: python -m pip install --upgrade build
|
|
32
|
+
- name: Build sdist and wheel
|
|
33
|
+
run: python -m build
|
|
34
|
+
- name: Check metadata renders on PyPI
|
|
35
|
+
run: |
|
|
36
|
+
python -m pip install --upgrade twine
|
|
37
|
+
python -m twine check dist/*
|
|
38
|
+
- name: Upload distribution artifacts
|
|
39
|
+
uses: actions/upload-artifact@v7
|
|
40
|
+
with:
|
|
41
|
+
name: dist
|
|
42
|
+
path: dist/
|
|
43
|
+
|
|
44
|
+
verify:
|
|
45
|
+
name: Verify wheel on Python ${{ matrix.python-version }}
|
|
46
|
+
needs: build
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
strategy:
|
|
49
|
+
fail-fast: false
|
|
50
|
+
matrix:
|
|
51
|
+
python-version: ["3.11", "3.12", "3.13", "3.14"]
|
|
52
|
+
steps:
|
|
53
|
+
- name: Download distribution artifacts
|
|
54
|
+
uses: actions/download-artifact@v8
|
|
55
|
+
with:
|
|
56
|
+
name: dist
|
|
57
|
+
path: dist/
|
|
58
|
+
- uses: actions/setup-python@v7
|
|
59
|
+
with:
|
|
60
|
+
python-version: ${{ matrix.python-version }}
|
|
61
|
+
- name: Install the built wheel
|
|
62
|
+
run: |
|
|
63
|
+
WHEEL=$(ls dist/*.whl)
|
|
64
|
+
python -m pip install "${WHEEL}"
|
|
65
|
+
- name: Smoke-test both entry points
|
|
66
|
+
run: |
|
|
67
|
+
gnomad-api-cache --version
|
|
68
|
+
python -m gnomad_api_cache --help > /dev/null
|
|
69
|
+
python -c "from gnomad_api_cache import VariantCache, read_vcf, fetch_gnomad"
|
|
70
|
+
|
|
71
|
+
publish-testpypi:
|
|
72
|
+
name: Publish to TestPyPI
|
|
73
|
+
needs: [build, verify]
|
|
74
|
+
if: github.event_name == 'workflow_dispatch'
|
|
75
|
+
runs-on: ubuntu-latest
|
|
76
|
+
environment:
|
|
77
|
+
name: testpypi
|
|
78
|
+
url: https://test.pypi.org/p/gnomad-api-cache
|
|
79
|
+
permissions:
|
|
80
|
+
id-token: write # required for OIDC trusted publishing
|
|
81
|
+
steps:
|
|
82
|
+
- name: Download distribution artifacts
|
|
83
|
+
uses: actions/download-artifact@v8
|
|
84
|
+
with:
|
|
85
|
+
name: dist
|
|
86
|
+
path: dist/
|
|
87
|
+
- name: Publish to TestPyPI
|
|
88
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
89
|
+
with:
|
|
90
|
+
repository-url: https://test.pypi.org/legacy/
|
|
91
|
+
|
|
92
|
+
publish-pypi:
|
|
93
|
+
name: Publish to PyPI
|
|
94
|
+
needs: [build, verify]
|
|
95
|
+
if: github.event_name == 'release'
|
|
96
|
+
runs-on: ubuntu-latest
|
|
97
|
+
environment:
|
|
98
|
+
name: pypi
|
|
99
|
+
url: https://pypi.org/p/gnomad-api-cache
|
|
100
|
+
permissions:
|
|
101
|
+
id-token: write # required for OIDC trusted publishing
|
|
102
|
+
steps:
|
|
103
|
+
- name: Download distribution artifacts
|
|
104
|
+
uses: actions/download-artifact@v8
|
|
105
|
+
with:
|
|
106
|
+
name: dist
|
|
107
|
+
path: dist/
|
|
108
|
+
- name: Publish to PyPI
|
|
109
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 limenode
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: gnomad-api-cache
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fetch and cache gnomAD annotations for VCF variants.
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: cyvcf2<0.35,>=0.34.0
|
|
8
|
+
Requires-Dist: pyarrow<26,>=25.0.0
|
|
9
|
+
Requires-Dist: requests<3,>=2.32
|
|
10
|
+
Requires-Dist: tqdm<5,>=4.66
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# gnomad-api-cache
|
|
14
|
+
|
|
15
|
+
Fetch gnomAD annotations for the variants in a VCF, cache them in SQLite, and
|
|
16
|
+
export to various output formats (parquet, csv, tsv, json).
|
|
17
|
+
|
|
18
|
+
The public gnomAD API allows roughly 10 requests (of 25 variants each) per minute.
|
|
19
|
+
Annotating a cohort twice — or exporting a second format — fetches from the locally
|
|
20
|
+
built cache rather than requerying.
|
|
21
|
+
|
|
22
|
+
Re-running into an existing cache fetches only what is missing.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install gnomad-api-cache
|
|
28
|
+
|
|
29
|
+
# or with uv
|
|
30
|
+
uv pip install gnomad-api-cache # into the active environment
|
|
31
|
+
uv add gnomad-api-cache # into a project
|
|
32
|
+
uv tool install gnomad-api-cache # just the CLI
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Requires Python 3.11 or newer.
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
### Command line
|
|
40
|
+
|
|
41
|
+
Inputs are any VCF-like file (VCF, BCF, or bgzipped VCF) and a SQLite database to store the cache. The output retrieves all variants from the cache and writes them to a file in the specified format.
|
|
42
|
+
```bash
|
|
43
|
+
gnomad-api-cache -i cohort.vcf.gz -c gnomad.sqlite -o annotations.parquet
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The output format is inferred from the file extension (`.csv`, `.tsv`,
|
|
47
|
+
`.parquet`, `.json`, `.jsonl`) and can be forced with `-f`:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
gnomad-api-cache -i cohort.vcf.gz -c gnomad.sqlite -o annotations.txt -f tsv
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Omit `-o` to populate the cache without writing a table:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
gnomad-api-cache -i cohort.vcf.gz -c gnomad.sqlite
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`python -m gnomad_api_cache` accepts the same arguments. Run
|
|
60
|
+
`gnomad-api-cache --help` for the full list, including `--dataset`,
|
|
61
|
+
`--include-populations`, and `--require-build`.
|
|
62
|
+
|
|
63
|
+
### Python
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from gnomad_api_cache import VariantCache
|
|
67
|
+
|
|
68
|
+
with VariantCache("gnomad.sqlite") as cache:
|
|
69
|
+
summary = cache.fetch_vcf("cohort.vcf.gz")
|
|
70
|
+
print(summary) # 1234 requested, 0 already cached, 1200 fetched, ...
|
|
71
|
+
|
|
72
|
+
cache.to_parquet("annotations.parquet")
|
|
73
|
+
cache.to_csv("annotations.csv")
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Pass a `filter_function(cyvcf2.Variant) -> bool` to decide which variants are worth querying:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from cyvcf2 import Variant
|
|
80
|
+
from gnomad_api_cache import VariantCache
|
|
81
|
+
|
|
82
|
+
def rare_only(variant: Variant) -> bool:
|
|
83
|
+
af = variant.INFO.get("gnomad41_exome_AF", 0)
|
|
84
|
+
return float(0 if af == "." else af) <= 0.05
|
|
85
|
+
|
|
86
|
+
with VariantCache("gnomad.sqlite") as cache:
|
|
87
|
+
cache.fetch_vcf("cohort.vcf.gz", filter_function=rare_only)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
An open cache is a read-only `Mapping` keyed by `chrom-pos-ref-alt`, so cached
|
|
91
|
+
records are available without another request:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
record = cache["1-55051215-G-A"] # None if gnomAD has no such variant
|
|
95
|
+
print(len(cache), cache.status_counts())
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Acknowledgement & Citation
|
|
99
|
+
|
|
100
|
+
This is an unofficial client. It queries the public gnomAD GraphQL API at
|
|
101
|
+
<https://gnomad.broadinstitute.org/api> and is not affiliated with or endorsed
|
|
102
|
+
by the Broad Institute or the gnomAD project. Please use the shared API
|
|
103
|
+
considerately — the default delay between requests is set to stay within the
|
|
104
|
+
documented rate limit.
|
|
105
|
+
|
|
106
|
+
If you use gnomAD data obtained through this tool, cite the current flagship
|
|
107
|
+
gnomAD paper. As of the latest release, it is as follows (v4 Preprint, Vancouver):
|
|
108
|
+
|
|
109
|
+
> Guez J, Goodrich JK, Moldovan MA, Chao KR, Kar P, Panchal R, Wilson MW, Laricchia KM, Rohlicek G, Biba D, Marten D. Integrating 730,947 exome sequences with clinical literature improves gene discovery. Medrxiv. 2026 Mar 25. <https://doi.org/10.64898/2026.03.23.26349081>
|
|
110
|
+
|
|
111
|
+
gnomAD data use terms: <https://gnomad.broadinstitute.org/terms>
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# gnomad-api-cache
|
|
2
|
+
|
|
3
|
+
Fetch gnomAD annotations for the variants in a VCF, cache them in SQLite, and
|
|
4
|
+
export to various output formats (parquet, csv, tsv, json).
|
|
5
|
+
|
|
6
|
+
The public gnomAD API allows roughly 10 requests (of 25 variants each) per minute.
|
|
7
|
+
Annotating a cohort twice — or exporting a second format — fetches from the locally
|
|
8
|
+
built cache rather than requerying.
|
|
9
|
+
|
|
10
|
+
Re-running into an existing cache fetches only what is missing.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install gnomad-api-cache
|
|
16
|
+
|
|
17
|
+
# or with uv
|
|
18
|
+
uv pip install gnomad-api-cache # into the active environment
|
|
19
|
+
uv add gnomad-api-cache # into a project
|
|
20
|
+
uv tool install gnomad-api-cache # just the CLI
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Requires Python 3.11 or newer.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Command line
|
|
28
|
+
|
|
29
|
+
Inputs are any VCF-like file (VCF, BCF, or bgzipped VCF) and a SQLite database to store the cache. The output retrieves all variants from the cache and writes them to a file in the specified format.
|
|
30
|
+
```bash
|
|
31
|
+
gnomad-api-cache -i cohort.vcf.gz -c gnomad.sqlite -o annotations.parquet
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The output format is inferred from the file extension (`.csv`, `.tsv`,
|
|
35
|
+
`.parquet`, `.json`, `.jsonl`) and can be forced with `-f`:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
gnomad-api-cache -i cohort.vcf.gz -c gnomad.sqlite -o annotations.txt -f tsv
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Omit `-o` to populate the cache without writing a table:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
gnomad-api-cache -i cohort.vcf.gz -c gnomad.sqlite
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`python -m gnomad_api_cache` accepts the same arguments. Run
|
|
48
|
+
`gnomad-api-cache --help` for the full list, including `--dataset`,
|
|
49
|
+
`--include-populations`, and `--require-build`.
|
|
50
|
+
|
|
51
|
+
### Python
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from gnomad_api_cache import VariantCache
|
|
55
|
+
|
|
56
|
+
with VariantCache("gnomad.sqlite") as cache:
|
|
57
|
+
summary = cache.fetch_vcf("cohort.vcf.gz")
|
|
58
|
+
print(summary) # 1234 requested, 0 already cached, 1200 fetched, ...
|
|
59
|
+
|
|
60
|
+
cache.to_parquet("annotations.parquet")
|
|
61
|
+
cache.to_csv("annotations.csv")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Pass a `filter_function(cyvcf2.Variant) -> bool` to decide which variants are worth querying:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from cyvcf2 import Variant
|
|
68
|
+
from gnomad_api_cache import VariantCache
|
|
69
|
+
|
|
70
|
+
def rare_only(variant: Variant) -> bool:
|
|
71
|
+
af = variant.INFO.get("gnomad41_exome_AF", 0)
|
|
72
|
+
return float(0 if af == "." else af) <= 0.05
|
|
73
|
+
|
|
74
|
+
with VariantCache("gnomad.sqlite") as cache:
|
|
75
|
+
cache.fetch_vcf("cohort.vcf.gz", filter_function=rare_only)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
An open cache is a read-only `Mapping` keyed by `chrom-pos-ref-alt`, so cached
|
|
79
|
+
records are available without another request:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
record = cache["1-55051215-G-A"] # None if gnomAD has no such variant
|
|
83
|
+
print(len(cache), cache.status_counts())
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Acknowledgement & Citation
|
|
87
|
+
|
|
88
|
+
This is an unofficial client. It queries the public gnomAD GraphQL API at
|
|
89
|
+
<https://gnomad.broadinstitute.org/api> and is not affiliated with or endorsed
|
|
90
|
+
by the Broad Institute or the gnomAD project. Please use the shared API
|
|
91
|
+
considerately — the default delay between requests is set to stay within the
|
|
92
|
+
documented rate limit.
|
|
93
|
+
|
|
94
|
+
If you use gnomAD data obtained through this tool, cite the current flagship
|
|
95
|
+
gnomAD paper. As of the latest release, it is as follows (v4 Preprint, Vancouver):
|
|
96
|
+
|
|
97
|
+
> Guez J, Goodrich JK, Moldovan MA, Chao KR, Kar P, Panchal R, Wilson MW, Laricchia KM, Rohlicek G, Biba D, Marten D. Integrating 730,947 exome sequences with clinical literature improves gene discovery. Medrxiv. 2026 Mar 25. <https://doi.org/10.64898/2026.03.23.26349081>
|
|
98
|
+
|
|
99
|
+
gnomAD data use terms: <https://gnomad.broadinstitute.org/terms>
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
MIT — see [LICENSE](LICENSE).
|