cellink.tl.external.compute_ld_scores_with_annotations_from_bimfile#
- cellink.tl.external.compute_ld_scores_with_annotations_from_bimfile(bfile_prefix, annot_file, out_prefix, ld_wind_cm=1.0, ld_wind_kb=None, ld_wind_snp=None, print_snps=None, thin_annot=False, maf_min=0.01, yes_really=True, run=True, runner=None, **kwargs)#
Compute LD scores with cell-type-specific annotations from PLINK bfile
This is the first step in cell-type-specific LDSC analysis. It computes LD scores for SNPs while incorporating cell-type-specific gene annotations. This function should be run for each chromosome and each cell type.
Works with any PLINK bfile, including standard reference panels like 1000 Genomes.
- Parameters:
bfile_prefix (str) – Path to PLINK binary files (without .bed/.bim/.fam extension). Typically from 1000 Genomes reference panel, e.g., “1000G_EUR_Phase3_plink/1000G.EUR.QC.22”
annot_file (str) – Path to the annotation file created by make_annot_from_donor_data() or make_annot_from_bimfile(). Should end in .annot.gz Example: “CD8_Naive.22.annot.gz”
out_prefix (str) – Prefix for output files. Will create: - {out_prefix}.l2.ldscore.gz (LD scores) - {out_prefix}.l2.M (number of SNPs) - {out_prefix}.l2.M_5_50 (number of common SNPs) - {out_prefix}.log (log file)
ld_wind_cm (float, default 1.0) – LD window size in centiMorgans. Only one of ld_wind_cm, ld_wind_kb, or ld_wind_snp can be specified.
ld_wind_kb (int, optional) – LD window size in kilobases (alternative to ld_wind_cm)
ld_wind_snp (int, optional) – LD window size in number of SNPs (alternative to ld_wind_cm)
print_snps (str, optional) – Path to file with SNP IDs (one per row) to restrict LD score computation. Commonly used with HapMap3 SNPs (e.g., “hapmap3_snps/hm.22.snp”). The sum r^2 will still include all SNPs, but only listed SNPs will have LD scores computed.
thin_annot (bool, default False) – Assume annotation files only have annotations (no SNP, CM, CHR, BP columns). Should typically be False for annotations created by make_annot_from_bimfile / make_annot_from_donor_data, which write the full CHR/BP/SNP/CM/ANNOT format.
maf_min (float, default 0.01) – Minimum minor allele frequency threshold
yes_really (bool, default True) – Required flag for computing whole-chromosome LD scores
run (bool, default True) – Whether to execute the command or just return it
runner (LDSCRunner, optional) – Runner instance to use. If None, uses the global runner.
**kwargs – Additional command line arguments to pass to ldsc.py
- Return type:
- Returns:
dict Results dictionary containing: - ‘ld_scores_file’: Path to LD scores file (if run=True) - ‘files_created’: List of created files (if run=True) - ‘command’: Command string (if run=False)
Examples
Basic usage for chromosome 22: >>> result = compute_ld_scores_with_annotations_from_bimfile( … bfile_prefix=”1000G_EUR_Phase3_plink/1000G.EUR.QC.22”, … annot_file=”CD8_Naive.22.annot.gz”, … out_prefix=”CD8_Naive.22”, … print_snps=”hapmap3_snps/hm.22.snp”, … )
For all chromosomes (in a loop): >>> for chrom in range(1, 23): … result = compute_ld_scores_with_annotations_from_bimfile( … bfile_prefix=f”1000G_EUR/1000G.EUR.QC.{chrom}”, … annot_file=f”CD8_Naive.{chrom}.annot.gz”, … out_prefix=f”CD8_Naive.{chrom}”, … print_snps=f”hapmap3_snps/hm.{chrom}.snp”, … )
Just generate command without running: >>> result = compute_ld_scores_with_annotations_from_bimfile( … bfile_prefix=”1000G.EUR.QC.22”, annot_file=”CD8_Naive.22.annot.gz”, out_prefix=”CD8_Naive.22”, run=False … ) >>> print(result[“command”])
Notes
This function is specifically for cell-type-specific analysis workflow
Should be run separately for each chromosome (1-22)
The annotation file should be created first using make_annot_from_donor_data() or make_annot_from_bimfile()
print_snps is typically used to restrict to HapMap3 SNPs for better matching with standard reference LD scores
After computing LD scores for all chromosomes, use estimate_celltype_specific_heritability() for the actual analysis
See also
compute_ld_scores_with_annotations_from_donor_dataCompute from DonorData
make_annot_from_donor_dataCreate annotations from DonorData
estimate_celltype_specific_heritabilityRun cell-type-specific analysis