cellink.tl.external.estimate_celltype_specific_heritability#
- cellink.tl.external.estimate_celltype_specific_heritability(sumstats_file, ref_ld_chr, w_ld_chr, ref_ld_chr_cts, out_prefix, print_all_cts=False, run=True, runner=None, **kwargs)#
Estimate cell-type-specific heritability using LD Score regression.
This is the second step in cell-type-specific LDSC analysis. It tests whether SNP heritability is enriched in specific cell types by regressing GWAS summary statistics against cell-type-specific LD scores.
This function requires that LD scores with cell-type annotations have already been computed using compute_ld_scores_with_annotations() for all chromosomes.
- Parameters:
sumstats_file (str) – Path to munged summary statistics file (.sumstats.gz) from munge_sumstats()
ref_ld_chr (str) – Prefix for baseline reference LD scores (with @, e.g., “baseline_v1.2/baseline.”). These are the standard LD scores used for controlling confounders.
w_ld_chr (str) – Prefix for regression weights (with @, e.g., “weights_hm3_no_hla/weights.”). These are standard weights files from the LDSC resources.
ref_ld_chr_cts (str) –
Path to control file listing cell-type-specific LD score prefixes. This file should have two tab-separated columns per line: - Cell type name - Prefix for that cell type’s LD scores (with @ for chromosome)
Example file content:
` CD8_Naive cts_ldscores/CD8_Naive. CD4_Memory cts_ldscores/CD4_Memory. B_cells cts_ldscores/B_cells. `LDSC will look for files like: cts_ldscores/CD8_Naive.1.l2.ldscore.gz through cts_ldscores/CD8_Naive.22.l2.ldscore.gz
out_prefix (str) – Prefix for output files. Will create: - {out_prefix}.cell_type_results.txt (main results) - {out_prefix}.log (log file)
print_all_cts (bool, default False) – Print results for all cell types (not just significant ones)
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: - ‘results_file’: Path to cell type results file (if run=True) - ‘log_file’: Path to log file (if run=True) - ‘files_created’: List of created files (if run=True) - ‘command’: Command string (if run=False)
Examples
Basic usage after computing LD scores: >>> # First create control file >>> with open(“celltype_ldscores.txt”, “w”) as f: … f.write(“CD8_Naive\tcts_ldscores/CD8_Naive.\n”) … f.write(“CD4_Memory\tcts_ldscores/CD4_Memory.\n”) … f.write(“B_cells\tcts_ldscores/B_cells.\n”)
>>> # Run cell-type-specific analysis >>> result = estimate_celltype_specific_heritability( ... sumstats_file="height_munged.sumstats.gz", ... ref_ld_chr="baseline_v1.2/baseline.", ... w_ld_chr="weights_hm3_no_hla/weights.", ... ref_ld_chr_cts="celltype_ldscores.txt", ... out_prefix="height_celltype_results", ... )
Complete workflow example: >>> # 1. Prepare annotations for each cell type and chromosome >>> for cell_type in [“CD8_Naive”, “CD4_Memory”]: … for chrom in range(1, 23): … make_annot_from_donor_data( … dd=dd_chr, … annot_file=f”annots/{cell_type}.{chrom}.annot.gz”, … gene_set_file=f”genesets/{cell_type}.GeneSet”, … gene_coord_file=”gene_coords.txt”, … )
>>> # 2. Compute LD scores for each cell type and chromosome >>> for cell_type in ["CD8_Naive", "CD4_Memory"]: ... for chrom in range(1, 23): ... compute_ld_scores_with_annotations( ... bfile_prefix=f"1000G/1000G.EUR.QC.{chrom}", ... annot_file=f"annots/{cell_type}.{chrom}.annot.gz", ... out_prefix=f"cts_ldscores/{cell_type}.{chrom}", ... print_snps=f"hapmap3/hm.{chrom}.snp", ... )
>>> # 3. Create control file >>> with open("celltype_ldscores.txt", "w") as f: ... f.write("CD8_Naive\\tcts_ldscores/CD8_Naive.\\n") ... f.write("CD4_Memory\\tcts_ldscores/CD4_Memory.\\n")
>>> # 4. Run cell-type-specific analysis >>> result = estimate_celltype_specific_heritability( ... sumstats_file="disease_munged.sumstats.gz", ... ref_ld_chr="baseline_v1.2/baseline.", ... w_ld_chr="weights_hm3_no_hla/weights.", ... ref_ld_chr_cts="celltype_ldscores.txt", ... out_prefix="disease_celltype", ... )
Notes
This function performs the final cell-type-specific heritability analysis
Requires baseline LD scores and weights (can be downloaded from LDSC resources)
The ref_ld_chr_cts file format is critical: tab-separated, cell type name then prefix with @ or chromosome numbers appended
Tests whether heritability is enriched in genes specific to each cell type
Results show coefficient estimates and p-values for each cell type
Significant positive coefficients indicate heritability enrichment in that cell type
See also
compute_ld_scores_with_annotationsCompute LD scores with annotations
make_annot_from_donor_dataCreate cell-type-specific annotations
munge_sumstatsPrepare GWAS summary statistics