Meta-Analysis API¶
meta_all(inputs, ld_weighting="ess"), meta_by_population(...),
meta(inputs, meta_method="meta_all", ld_weighting="ess") and meta_loci(...)
share the matched geometric ESS/SE contract.
meta_lds(inputs, ld_weighting="ess") returns only the LD half of that contract;
use meta_all when preparing paired fine-mapping inputs. The standalone
meta_sumstats function remains an LD-independent IVW helper and must not be
used on unmatched cohorts to supply statistics for matched LD.
Meta analysis of multi-ancestry gwas data.
compute_heterogeneity(locus_set)
¶
Compute heterogeneity metrics across cohorts before meta-analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
locus_set
|
LocusSet
|
LocusSet containing input data from multiple studies. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, DataFrame]
|
Dictionary of heterogeneity metrics with keys: - 'ld_4th_moment': 4th moment of LD matrix - 'ld_decay': LD decay analysis - 'cochran_q': heterogeneity test (if multiple cohorts) - 'snp_missingness': missingness analysis (if multiple cohorts) |
Source code in credtools/meta.py
compute_heterogeneity_by_population(locus_set)
¶
Compute heterogeneity metrics with cochran_q and snp_missingness grouped by population.
LD metrics (ld_4th_moment, ld_decay) are computed globally across all cohorts. Cochran-Q and SNP missingness are computed within each population separately, since heterogeneity should measure differences between cohorts of the same population, not across populations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
locus_set
|
LocusSet
|
LocusSet containing input data from multiple studies. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, DataFrame]
|
Dictionary of heterogeneity metrics with keys: - 'ld_4th_moment': 4th moment of LD matrix (global) - 'ld_decay': LD decay analysis (global) - 'cochran_q': heterogeneity test per population (with 'population' column) - 'snp_missingness': missingness per population (with 'population' column) |
Source code in credtools/meta.py
ensure_meta_configuration(outdir, meta_method, ld_weighting)
¶
Refuse legacy/mixed-mode outputs; write a manifest for new output directories.
Source code in credtools/meta.py
heterogeneity_summary(het_metrics, locus_set)
¶
Generate per-cohort summary of heterogeneity metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
het_metrics
|
Dict[str, DataFrame]
|
Dictionary of heterogeneity metrics from compute_heterogeneity(). |
required |
locus_set
|
LocusSet
|
LocusSet containing input data from multiple studies. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Summary DataFrame with one row per cohort. |
Source code in credtools/meta.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | |
meta(inputs, meta_method='meta_all', ld_weighting='ess')
¶
Perform meta-analysis using the specified method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
LocusSet
|
LocusSet containing input data from multiple studies. |
required |
meta_method
|
str
|
Meta-analysis method to use, by default "meta_all". Options: - "meta_all": Meta-analyze all studies together - "meta_by_population": Meta-analyze within each population separately - "no_meta": No meta-analysis, just intersect individual studies |
'meta_all'
|
Returns:
| Type | Description |
|---|---|
LocusSet
|
LocusSet containing meta-analyzed results. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unsupported meta-analysis method is specified. |
Notes
The different methods serve different purposes:
- "meta_all": Maximizes power by combining all studies, but may be inappropriate if LD patterns differ substantially between populations
- "meta_by_population": Preserves population-specific LD while allowing meta-analysis within populations
- "no_meta": Keeps studies separate, useful for comparison or when meta-analysis is not appropriate
Source code in credtools/meta.py
meta_all(inputs, ld_weighting='ess')
¶
Perform comprehensive meta-analysis of both summary statistics and LD matrices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
LocusSet
|
LocusSet containing input data from multiple studies. |
required |
ld_weighting
|
(ess, se)
|
Geometric LD weights after within-cohort matching, by default "ess". Summary statistics always use matched inverse-variance weighting. |
"ess"
|
Returns:
| Type | Description |
|---|---|
Locus
|
Meta-analyzed Locus object with combined population and cohort identifiers. |
Notes
This function:
- Performs meta-analysis of summary statistics using inverse-variance weighting
- Merges LD using geometric ESS (default) or SE weights on the same contributions
- Combines population and cohort names from all input studies
- Sums sample sizes across studies
- Intersects the meta-analyzed data to ensure consistency
Population and cohort names are combined with "+" as separator and sorted alphabetically.
Source code in credtools/meta.py
meta_by_population(inputs, ld_weighting='ess')
¶
Perform meta-analysis within each population separately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
LocusSet
|
LocusSet containing input data from multiple studies. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Locus]
|
Dictionary mapping population codes to meta-analyzed Locus objects. |
Notes
This function:
- Groups studies by population code
- Performs meta-analysis within each population group
- For single-study populations, applies the same matching and validation
- Returns a dictionary with population codes as keys
This approach preserves population-specific LD patterns while still allowing meta-analysis of multiple cohorts within the same population.
Source code in credtools/meta.py
meta_configuration(meta_method, ld_weighting)
¶
Describe the input contract used to protect output reuse.
Source code in credtools/meta.py
meta_lds(inputs, ld_weighting='ess')
¶
Merge within-cohort GWAS/LD matches using geometric ESS or SE weights.
ESS (default) uses the supplied scalar sample_size; SE uses 1/SE**2. Normalize at each SNP, then multiply the square-root coefficients at both ends of each LD correlation. Missing contributions are zero, not pairwise renormalized. Use meta_all() to obtain the paired IVW summary statistics.
Source code in credtools/meta.py
meta_loci(inputs, outdir, threads=1, meta_method='meta_all', calculate_lambda_s=False, skip=False, ld_weighting='ess')
¶
Perform meta-analysis on multiple loci in parallel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
str
|
Path to input file containing locus information. Must be a tab-separated file with columns including 'locus_id'. |
required |
outdir
|
str
|
Output directory path where results will be saved. |
required |
threads
|
int
|
Number of parallel threads to use, by default 1. |
1
|
meta_method
|
str
|
Meta-analysis method to use, by default "meta_all". |
'meta_all'
|
calculate_lambda_s
|
bool
|
Whether to calculate lambda_s parameter using estimate_s_rss function, by default False. See meta() function for available options. |
False
|
skip
|
bool
|
Skip loci already completed from a previous run, by default False. |
False
|
ld_weighting
|
(ess, se)
|
Cohort-matched geometric LD weighting, by default "ess". |
"ess"
|
Returns:
| Type | Description |
|---|---|
None
|
Results are saved to files in the output directory. |
Notes
This function:
- Reads locus information from the input file
- Groups loci by locus_id for parallel processing
- Processes each locus group using the specified meta-analysis method
- Saves results with a progress bar for user feedback
- Creates a summary file (loci_info.txt) with all processed loci
The input file should contain columns: locus_id, prefix, popu, cohort, sample_size. Each locus_id can have multiple rows representing different cohorts/populations.
Output files are organized as: {outdir}/{locus_id}/{prefix}.{sumstats.gz,ld.npz,ldmap.gz}
Source code in credtools/meta.py
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
meta_locus(args)
¶
Process a single locus for meta-analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Tuple[str, DataFrame, str, str, bool]
|
A tuple containing: - locus_id : str The ID of the locus - locus_info : pd.DataFrame DataFrame containing locus information - outdir : str Output directory path - meta_method : str Method for meta-analysis - calculate_lambda_s : bool Whether to calculate lambda_s - ld_weighting : str, optional sixth item Geometric LD weighting, "ess" (default) or "se". |
required |
Returns:
| Type | Description |
|---|---|
Tuple[List[List[Any]], DataFrame]
|
A tuple of (results, het_summary) where results is a list of processed locus info and het_summary is the per-cohort heterogeneity summary DataFrame. |
Notes
This function is designed for parallel processing and:
- Loads the locus set from the provided information
- Computes heterogeneity metrics before meta-analysis
- Performs meta-analysis using the specified method
- Creates output directory for the locus
- Saves results to compressed files (sumstats.gz, ld.npz, ldmap.gz)
- Returns metadata for each processed locus and heterogeneity summary
Source code in credtools/meta.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 | |
meta_output_prefix(locus, meta_method, ld_weighting)
¶
Make matched LD weighting explicit in output filenames.
Source code in credtools/meta.py
meta_sumstats(inputs)
¶
Perform fixed effect meta-analysis of summary statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
LocusSet
|
LocusSet containing input data from multiple studies. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Meta-analysis summary statistics with columns: SNPID, BETA, SE, P, EAF, CHR, BP, EA, NEA. |
Notes
This standalone function does not match LD. For paired fine-mapping statistics and LD, use meta_all(), which shares contribution eligibility.
This function performs inverse-variance weighted fixed-effects meta-analysis:
- Merges summary statistics from all studies on SNPID
- Calculates inverse-variance weights (1/SE²)
- Computes weighted average effect size
- Calculates meta-analysis standard error
- Computes Z-scores and p-values
- Performs sample-size weighted averaging of effect allele frequencies
The meta-analysis formulas used: - Beta_meta = Σ(Beta_i * Weight_i) / Σ(Weight_i) - SE_meta = 1 / sqrt(Σ(Weight_i)) - Weight_i = 1 / SE_i²
Source code in credtools/meta.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
recover_completed_locus(locus_id, outdir, prev_loci_info, configuration=None)
¶
Recover a previously completed locus from existing output files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
locus_id
|
str
|
The locus identifier. |
required |
outdir
|
str
|
Output directory path. |
required |
prev_loci_info
|
Optional[DataFrame]
|
Previous loci_info DataFrame from a prior run, or None. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Tuple[List[List[Any]], DataFrame]]
|
(results, het_summary) if the locus is fully complete, else None. |
Source code in credtools/meta.py
save_heterogeneity(het_metrics, out_dir, summary=None)
¶
Save heterogeneity metrics to compressed TSV files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
het_metrics
|
Dict[str, DataFrame]
|
Dictionary of heterogeneity metrics from compute_heterogeneity(). |
required |
out_dir
|
str
|
Output directory path. |
required |
summary
|
DataFrame
|
Per-cohort summary from heterogeneity_summary(). If provided, saved as heterogeneity.txt.gz. |
None
|
Source code in credtools/meta.py
save_meta_audit(locus, out_prefix)
¶
Save SNP information retention and cohort contribution counts when available.