meta
Meta analysis of multi-ancestry gwas data.
compute_heterogeneity(locus_set)
¶
Compute heterogeneity metrics across cohorts before meta-analysis.
Parameters¶
locus_set : LocusSet LocusSet containing input data from multiple studies.
Returns¶
Dict[str, pd.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¶
locus_set : LocusSet LocusSet containing input data from multiple studies.
Returns¶
Dict[str, pd.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
heterogeneity_summary(het_metrics, locus_set)
¶
Generate per-cohort summary of heterogeneity metrics.
Parameters¶
het_metrics : Dict[str, pd.DataFrame] Dictionary of heterogeneity metrics from compute_heterogeneity(). locus_set : LocusSet LocusSet containing input data from multiple studies.
Returns¶
pd.DataFrame Summary DataFrame with one row per cohort.
Source code in credtools/meta.py
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 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
meta(inputs, meta_method='meta_all')
¶
Perform meta-analysis using the specified method.
Parameters¶
inputs : LocusSet LocusSet containing input data from multiple studies. meta_method : str, optional 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
Returns¶
LocusSet LocusSet containing meta-analyzed results.
Raises¶
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)
¶
Perform comprehensive meta-analysis of both summary statistics and LD matrices.
Parameters¶
inputs : LocusSet LocusSet containing input data from multiple studies.
Returns¶
Locus Meta-analyzed Locus object with combined population and cohort identifiers.
Notes¶
This function:
- Performs meta-analysis of summary statistics using inverse-variance weighting
- Performs meta-analysis of LD matrices using sample-size weighting
- 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)
¶
Perform meta-analysis within each population separately.
Parameters¶
inputs : LocusSet LocusSet containing input data from multiple studies.
Returns¶
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 intersection without meta-analysis
- 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_lds(inputs)
¶
Perform meta-analysis of LD matrices using sample-size weighted averaging.
Parameters¶
inputs : LocusSet LocusSet containing input data from multiple studies.
Returns¶
LDMatrix Meta-analyzed LD matrix with merged variant map.
Notes¶
This function performs the following operations:
- Identifies unique variants across all studies
- Creates a master variant list sorted by chromosome and position
- Performs sample-size weighted averaging of LD correlations
- Handles missing variants by setting weights to zero
- Optionally meta-analyzes allele frequencies if available
The meta-analysis formula: LD_meta[i,j] = Σ(LD_k[i,j] * N_k) / Σ(N_k)
where k indexes studies, N_k is sample size, and the sum is over studies that have both variants i and j.
Source code in credtools/meta.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
meta_loci(inputs, outdir, threads=1, meta_method='meta_all', calculate_lambda_s=False, skip=False)
¶
Perform meta-analysis on multiple loci in parallel.
Parameters¶
inputs : str Path to input file containing locus information. Must be a tab-separated file with columns including 'locus_id'. outdir : str Output directory path where results will be saved. threads : int, optional Number of parallel threads to use, by default 1. meta_method : str, optional Meta-analysis method to use, by default "meta_all". calculate_lambda_s : bool, optional Whether to calculate lambda_s parameter using estimate_s_rss function, by default False. See meta() function for available options. skip : bool, optional Skip loci already completed from a previous run, by default False.
Returns¶
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
717 718 719 720 721 722 723 724 725 726 727 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 | |
meta_locus(args)
¶
Process a single locus for meta-analysis.
Parameters¶
args : Tuple[str, pd.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
Returns¶
Tuple[List[List[Any]], pd.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
634 635 636 637 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 | |
meta_sumstats(inputs)
¶
Perform fixed effect meta-analysis of summary statistics.
Parameters¶
inputs : LocusSet LocusSet containing input data from multiple studies.
Returns¶
pd.DataFrame Meta-analysis summary statistics with columns: SNPID, BETA, SE, P, EAF, CHR, BP, EA, NEA.
Notes¶
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
recover_completed_locus(locus_id, outdir, prev_loci_info)
¶
Recover a previously completed locus from existing output files.
Parameters¶
locus_id : str The locus identifier. outdir : str Output directory path. prev_loci_info : Optional[pd.DataFrame] Previous loci_info DataFrame from a prior run, or None.
Returns¶
Optional[Tuple[List[List[Any]], pd.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¶
het_metrics : Dict[str, pd.DataFrame] Dictionary of heterogeneity metrics from compute_heterogeneity(). out_dir : str Output directory path. summary : pd.DataFrame, optional Per-cohort summary from heterogeneity_summary(). If provided, saved as heterogeneity.txt.gz.