Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snplist support in the ld command #245

Open
aryarm opened this issue Jun 5, 2024 · 0 comments
Open

snplist support in the ld command #245

aryarm opened this issue Jun 5, 2024 · 0 comments

Comments

@aryarm
Copy link
Member

aryarm commented Jun 5, 2024

It would be nice if the ld command could compute LD between SNPs. For now, I've just been using the haptools API:

import numpy as np
from haptools.data import GenotypesVCF
from haptools.ld import pearson_corr_ld

causal_SNP = "rs429358"

gts = GenotypesVCF.load("tests/data/apoe.vcf.gz")
get_snp_gts = lambda snp: gts.subset(variants=(snp,)).data[:, 0, :2].sum(axis=1)
target_gts = get_snp_gts(causal_SNP)
other_snps = set(gts.variants["id"])
other_snps.remove(causal_SNP)
ld = {vr: np.abs(pearson_corr_ld(target_gts, get_snp_gts(vr))) for vr in other_snps}

# get the top ten SNPs that have the highest LD with the causal SNP
sorted(ld, key=ld.get, reverse=True)[:10]

on second thought, I'm not sure the snplist file format is the best either, since it requires that you provide a beta for each SNP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant