allelign 0.1.0__py3-none-any.whl
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.
- allelign/__init__.py +69 -0
- allelign/__main__.py +5 -0
- allelign/_common.py +95 -0
- allelign/_numba.py +22 -0
- allelign/align.py +1252 -0
- allelign/alleles.py +90 -0
- allelign/build.py +57 -0
- allelign/catalog.py +88 -0
- allelign/cli.py +323 -0
- allelign/download.py +525 -0
- allelign/genotypes.py +241 -0
- allelign/ldcheck.py +771 -0
- allelign/qc.py +638 -0
- allelign/status.py +130 -0
- allelign/sumstats.py +1207 -0
- allelign/variants.py +155 -0
- allelign/warning_markers.py +15 -0
- allelign/weights.py +614 -0
- allelign-0.1.0.dist-info/METADATA +175 -0
- allelign-0.1.0.dist-info/RECORD +24 -0
- allelign-0.1.0.dist-info/WHEEL +5 -0
- allelign-0.1.0.dist-info/entry_points.txt +2 -0
- allelign-0.1.0.dist-info/licenses/LICENSE +21 -0
- allelign-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: allelign
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Read, align and quality-control GWAS summary statistics and PGS weights
|
|
5
|
+
Author: bvilhjal
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/bvilhjal/allelign
|
|
8
|
+
Project-URL: Repository, https://github.com/bvilhjal/allelign
|
|
9
|
+
Project-URL: Issues, https://github.com/bvilhjal/allelign/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/bvilhjal/allelign/blob/main/docs/guide.md
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: numpy>=1.20
|
|
24
|
+
Provides-Extra: fast
|
|
25
|
+
Requires-Dist: numba>=0.59; extra == "fast"
|
|
26
|
+
Requires-Dist: scipy>=1.7; extra == "fast"
|
|
27
|
+
Provides-Extra: test
|
|
28
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
29
|
+
Requires-Dist: scipy>=1.7; extra == "test"
|
|
30
|
+
Provides-Extra: lint
|
|
31
|
+
Requires-Dist: ruff>=0.5; extra == "lint"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# allelign
|
|
35
|
+
|
|
36
|
+
[](https://github.com/bvilhjal/allelign/actions/workflows/ci.yml)
|
|
37
|
+
|
|
38
|
+
Read, align and quality-control GWAS summary statistics and PGS effect sizes.
|
|
39
|
+
|
|
40
|
+
Every method in this family starts the same way: parse a summary-statistics file in one of many dialects, get the effect alleles right against a reference, and catch bad input before it turns into a confident wrong number. allelign does those steps once, for all of them. It is extracted from ldpred3, plus the PGS Catalog reader from multipgs and the long-range LD table from bipred. On the inputs ldpred3 already handles it reproduces ldpred3 bit for bit; `tests/test_parity_ldpred3.py` checks that.
|
|
41
|
+
|
|
42
|
+
NumPy is the only dependency. Numba speeds up the parser about threefold, and SciPy provides float32 eigensolves for the LD screen; both are optional (`[fast]`).
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
From GitHub:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install "allelign[fast] @ git+https://github.com/bvilhjal/allelign.git"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
From a sibling checkout, as with the rest of the family:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install -e "../allelign[fast]"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Quick start
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import allelign as al
|
|
62
|
+
|
|
63
|
+
ss = al.read_sumstats("gwas.tsv.gz") # any common dialect
|
|
64
|
+
keep, qc_log = al.qc_sumstats(ss) # validity, duplicates, N, MAF, INFO
|
|
65
|
+
ref = al.read_bim("reference.bim").freeze() # or read_pvar, or al.Variants(...)
|
|
66
|
+
h = al.harmonize(ss.subset(keep), ref) # beta now counts ref.a1
|
|
67
|
+
print(al.coverage_message(al.reference_coverage(ss.subset(keep), ref, h)) or "coverage ok")
|
|
68
|
+
|
|
69
|
+
# Checks against the reference panel (af_ref: frequency of ref.a1).
|
|
70
|
+
sd_keep, sd_log, _ = al.sd_consistency_mask(h.beta, h.se, h.n_eff, af_ref[h.var_index])
|
|
71
|
+
|
|
72
|
+
# LD consistency: z-scores their LD neighbours contradict. LD comes from the
|
|
73
|
+
# reference's genotypes, one block at a time; or pass your own [(R, idx), ...]
|
|
74
|
+
# blocks to al.ld_consistency_screen.
|
|
75
|
+
bed = al.Bed("reference.bed", variants=ref, samples=eur_iids)
|
|
76
|
+
ld_keep = al.ld_consistency_screen_genotypes(bed, h.var_index, h.beta / h.se)
|
|
77
|
+
|
|
78
|
+
# PGS effect sizes
|
|
79
|
+
score = al.read_scoring_file("PGS000001_hmPOS_GRCh37.txt.gz")
|
|
80
|
+
w = al.harmonize_weights(score, ref) # also aligns AF, reports matched weight mass
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Every filter can stamp a per-row status array (`al.new_status(len(ss))`, passed as `status=`), so you can see which stage dropped each variant and write the table with `al.write_status_table`.
|
|
84
|
+
|
|
85
|
+
## Command line
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
allelign inspect gwas.tsv.gz
|
|
89
|
+
allelign clean gwas.tsv.gz -o clean.tsv.gz --status-out status.tsv
|
|
90
|
+
allelign align gwas.tsv.gz --reference ref.bim -o aligned.tsv.gz --sumstats-build GRCh38 --reference-build GRCh37 --reanchor-on-identifier
|
|
91
|
+
allelign align gwas.tsv.gz --reference ref.bim -o aligned.tsv.gz --ld-screen --ld-keep eur_samples.txt --status-out status.tsv
|
|
92
|
+
allelign pgs-export prs.weights.tsv -o PGS_my.txt --genome-build GRCh37
|
|
93
|
+
allelign download GCST91000728 -o gwas.h.tsv.gz # GWAS Catalog
|
|
94
|
+
allelign download FINNGEN:R11:I9_AF -o finngen.tsv.gz # FinnGen, and the providers below
|
|
95
|
+
allelign download EQTL:QTS000001:QTD000001:ENSG00000008128 -o eqtl.tsv.gz
|
|
96
|
+
allelign download GCST91000728 -o gwas.h.tsv.gz --keep-ids ref.bim
|
|
97
|
+
allelign download PGS000337 -o score.txt.gz --build GRCh38 --dry-run
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Each command writes `<out>.log.json` with the parse, QC, harmonisation and coverage records; `download` writes a `<out>.meta.json` provenance sidecar (URL, provider, trait, SHA-256, filter counts) instead.
|
|
101
|
+
|
|
102
|
+
## What it covers
|
|
103
|
+
|
|
104
|
+
- **Reading.** ldpred3's alias table and dialect rules (SAIGE, BOLT, METAL, GWAS-SSF, PGC), OR to log-OR, SE recovered from p without underflow. allelign adds:
|
|
105
|
+
- PLINK2 `A1` against `REF`/`ALT` or `OMITTED`;
|
|
106
|
+
- REGENIE `GENPOS` and `LOG10P`;
|
|
107
|
+
- GWAS Catalog `hm_` columns as one consistent set;
|
|
108
|
+
- PGC `FRQ_U_*`;
|
|
109
|
+
- Neale `chr:pos:ref:alt`;
|
|
110
|
+
- FinnGen;
|
|
111
|
+
- effective N from case and control counts.
|
|
112
|
+
- **Downloading.** `allelign download` resolves a published study by reference — GWAS Catalog (`GCST…`), PGS Catalog (`PGS…`), FinnGen, COVID-HGI, GBMI, eQTL Catalogue — checks the URL, streams it locally with a provenance sidecar, and can keep only the rows a reference can match.
|
|
113
|
+
- **Alignment.** ldpred3's harmoniser:
|
|
114
|
+
- identifier matching with coordinate checks, so a build mix-up is unmatched rather than silently accepted;
|
|
115
|
+
- strand flips;
|
|
116
|
+
- ambiguous pairs dropped;
|
|
117
|
+
- multi-allelic sites;
|
|
118
|
+
- coverage diagnosis that names a build mismatch;
|
|
119
|
+
- identifier re-anchoring;
|
|
120
|
+
- a declared-build check.
|
|
121
|
+
- **QC.**
|
|
122
|
+
- File-level filters.
|
|
123
|
+
- SD consistency against reference frequencies.
|
|
124
|
+
- Allele-frequency concordance, with a safety valve for ancestry mismatch.
|
|
125
|
+
- Imputed per-variant N, the genomic-control undo, implied N, λGC and long-range LD regions.
|
|
126
|
+
- The split-half LD-consistency screen (DENTIST-style) with full-window confirmation, on dense, int8, low-rank or lazily provided LD, or on LD formed block by block from a PLINK `.bed` reference.
|
|
127
|
+
- **Effect sizes.** ldpred3 weight tables, PGS Catalog reading and writing, and alignment of either to a reference.
|
|
128
|
+
|
|
129
|
+
[docs/guide.md](docs/guide.md) has the rules, defaults and the deliberate differences from ldpred3. A hands-on pass over download → inspect → clean → align is [docs/walkthrough.md](docs/walkthrough.md), with the same flow as a notebook in [docs/walkthrough.ipynb](docs/walkthrough.ipynb).
|
|
130
|
+
|
|
131
|
+
## Consumers
|
|
132
|
+
|
|
133
|
+
- **ldpred3** reads, aligns, QCs and writes weights through allelign. Its modules re-export allelign under their old names, so sibling imports keep working. It keeps the pipeline-specific parts: whole-block DENTIST with low-rank Woodbury updates, the BLAS gate for a pooled screen, its float32 eigensolver (passed to the screen), and the qc_log report blocks. allelign's parity tests are the contract.
|
|
134
|
+
- **ppb** takes chromosome labels, reverse complements and strand ambiguity from `allelign.alleles` and keeps its own position-only join.
|
|
135
|
+
- **bipred** takes the region table, long-range mask, strict implied-N diagnostic and weight-file I/O from allelign. Its wrapper includes APOE by default; its LDpred2-style SD diagnostic stays in bipred. Trait preparation still goes through ldpred3.
|
|
136
|
+
- **gwfm, multipgs and SMARTpred** use allelign for reading, alignment, QC and weight-file I/O. multipgs aligns both scoring files and fitted weights with `harmonize_weights`. SMARTpred and the LDpred3 harvester share the header-only `resolve_gwas_catalog_columns` rules while retaining streamed filtering. LD caches, prepared traits, the fit and pipeline reports stay in ldpred3.
|
|
137
|
+
|
|
138
|
+
## References
|
|
139
|
+
|
|
140
|
+
The methods allelign implements:
|
|
141
|
+
|
|
142
|
+
- Chen W, Wu Y, Zheng Z, et al. [Improved analyses of GWAS summary
|
|
143
|
+
statistics by reducing data heterogeneity and
|
|
144
|
+
errors](https://doi.org/10.1038/s41467-021-27438-7). *Nature
|
|
145
|
+
Communications* (2021). The DENTIST statistic behind the LD-consistency
|
|
146
|
+
screen.
|
|
147
|
+
- Privé F, Arbel J, Aschard H, et al. [Identifying and correcting for
|
|
148
|
+
misspecifications in GWAS summary statistics and polygenic
|
|
149
|
+
scores](https://doi.org/10.1016/j.xhgg.2022.100136). *HGG Advances*
|
|
150
|
+
(2022). The SD-consistency and frequency checks, and the per-variant N
|
|
151
|
+
imputation.
|
|
152
|
+
- Lambert SA, Gil L, Jupp S, et al. [The Polygenic Score Catalog as an open
|
|
153
|
+
database for reproducibility and systematic
|
|
154
|
+
evaluation](https://doi.org/10.1038/s41588-021-00783-5). *Nature
|
|
155
|
+
Genetics* (2021). The scoring-file format `read_scoring_file` parses.
|
|
156
|
+
- Sollis E, Mosaku A, Abid A, et al. [The NHGRI-EBI GWAS Catalog:
|
|
157
|
+
knowledgebase and deposition
|
|
158
|
+
resource](https://doi.org/10.1093/nar/gkac1010). *Nucleic Acids Research*
|
|
159
|
+
(2023). The harmonised `hm_` deposit layout.
|
|
160
|
+
- Yengo L, Vedantam S, Marouli E, et al. [A saturated map of common genetic
|
|
161
|
+
variants associated with human
|
|
162
|
+
height](https://doi.org/10.1038/s41586-022-05275-y). *Nature* (2022).
|
|
163
|
+
The LD-screen example in the guide.
|
|
164
|
+
|
|
165
|
+
## AI assistance
|
|
166
|
+
|
|
167
|
+
Parts of allelign's code and documentation were generated with the assistance
|
|
168
|
+
of AI tools and reviewed by the maintainer. As with any analysis software,
|
|
169
|
+
validate its behaviour on inputs you understand before relying on it; see the
|
|
170
|
+
[LICENSE](LICENSE) for the warranty terms.
|
|
171
|
+
|
|
172
|
+
## Status
|
|
173
|
+
|
|
174
|
+
Version 0.1.0. MIT licence. If you use allelign, please cite it — see
|
|
175
|
+
[CITATION.cff](CITATION.cff).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
allelign/__init__.py,sha256=K02oT4iSnGfBDI_TeRyOral4hzZIlMnZPkSgueapY8c,3684
|
|
2
|
+
allelign/__main__.py,sha256=E6Gls0DNz8GQK2K-kOUIx8cYhgANW_CH54VKrfCfs14,52
|
|
3
|
+
allelign/_common.py,sha256=qCRGxMyyFHc4QzlznHdhGWadqTLjto3CEHagZFQ7MHg,3398
|
|
4
|
+
allelign/_numba.py,sha256=QogvpGChjwTxTo1C_ehGBKDDR90S6rIm5ulS1ICwhWc,722
|
|
5
|
+
allelign/align.py,sha256=VzVq3TLLKEKHW4sxLD6IwYPY4zsZLgNPGsjjnM_9Rzs,49930
|
|
6
|
+
allelign/alleles.py,sha256=VMY0VhoWxH-5KXrsLmjAey-OKmxs4lucgW2imbiI3XY,3470
|
|
7
|
+
allelign/build.py,sha256=DuuN2DG90HUQr-UWKAh5uRR_2qObRK65ZpF7R72O-dA,2293
|
|
8
|
+
allelign/catalog.py,sha256=_a5v16oEjSEm8rRa-gGHTHjxfGV90T3mX8PNZk-Lka8,4229
|
|
9
|
+
allelign/cli.py,sha256=OmQSwZVYnjp_yoXoXyUDYuJUdZ6no69606_-rpBGC8w,13705
|
|
10
|
+
allelign/download.py,sha256=_7f7ahwuh2Vhh_fZffYf7VW8sst7qOxTYi_4EFwz51I,21849
|
|
11
|
+
allelign/genotypes.py,sha256=0WlEzZ6wgB2eEHz5efRmL-_rvcSvnY0iaRLzgacjWIQ,10999
|
|
12
|
+
allelign/ldcheck.py,sha256=5L6v13--WZ3lQFKJMXL2n_xHHassUSY3icQIQdLdB94,34418
|
|
13
|
+
allelign/qc.py,sha256=G5FJy5a4HaqyrX19_gZJX_GJbBcEDAHxVZ57GMCFrvY,27721
|
|
14
|
+
allelign/status.py,sha256=cripSLjAnfgN7nasNIMZ_WZFZVXsQzTBQtvZByIHE90,5397
|
|
15
|
+
allelign/sumstats.py,sha256=aa_AFqOlLnqRRfktqCUpD4Xm7kVTXKJrbiGX4DXNfaU,49906
|
|
16
|
+
allelign/variants.py,sha256=eeHEt2lI0oEeiiSLGfCGZyEWk9t2oniCwUfwB-wFryw,5796
|
|
17
|
+
allelign/warning_markers.py,sha256=cZaAOHPUFxempsIWLk7waKhCG5khF9e77fbaY1pWRHY,663
|
|
18
|
+
allelign/weights.py,sha256=aNq4GgxricsAelxpCsMhhyG2FxkXc4qrOJ0j3BSmY5w,26839
|
|
19
|
+
allelign-0.1.0.dist-info/licenses/LICENSE,sha256=9a8DTdnidoIJuGl05RzKVKee7y99of1ZgEa8wt1ylC8,1077
|
|
20
|
+
allelign-0.1.0.dist-info/METADATA,sha256=4tIlJNjoTIFtmwkENNzzvWLjtGTGDqsSuOcq2a18Xc0,9663
|
|
21
|
+
allelign-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
22
|
+
allelign-0.1.0.dist-info/entry_points.txt,sha256=xOp0unYr6_8QtArk_611NGH6MrxTGc61HZku1U5dl_4,47
|
|
23
|
+
allelign-0.1.0.dist-info/top_level.txt,sha256=CyHIWG7HWTXhlH7a-ENkJS66D0y3K0FfeC7L-2E8kAU,9
|
|
24
|
+
allelign-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bjarni Vilhjálmsson
|
|
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 @@
|
|
|
1
|
+
allelign
|