### Test PolyFun Installation Source: https://github.com/omerwe/polyfun/blob/master/README.md Verify the installation by running the test script, optionally specifying the Python executable or FINEMAP path. ```bash python test_polyfun.py --python3 ``` ```bash python test_polyfun.py --python3 --finemap-exe ``` -------------------------------- ### Test PolyFun Installation in Bash Source: https://context7.com/omerwe/polyfun/llms.txt Verifies that PolyFun and all dependencies are correctly installed and functioning. Supports basic testing and testing with FINEMAP integration. ```bash # Basic test python test_polyfun.py --python3 python # Test with FINEMAP integration python test_polyfun.py \ --python3 python \ --finemap-exe /path/to/finemap_v1.4 ``` -------------------------------- ### Install LDstore 2.0 Source: https://github.com/omerwe/polyfun/blob/master/README.md Download and extract the LDstore executable for Linux or Mac OS X. ```bash wget http://www.christianbenner.com/ldstore_v2.0_x86_64.tgz tar xzvf ldstore_v2.0_x86_64.tgz ``` ```bash wget http://www.christianbenner.com/ldstore_v2.0_MacOSX.tgz tar xzvf ldstore_v2.0_MacOSX.tgz ``` -------------------------------- ### Install PolyFun using Mamba and Conda Lockfile Source: https://github.com/omerwe/polyfun/blob/master/README.md This command creates a new Conda environment named 'polyfun-lock' using a lockfile, ensuring specific, known-to-work software versions are installed. It then activates this environment. Mamba is recommended for faster installation. ```bash mamba create --name polyfun-lock --file polyfun.yml.lock conda activate polyfun-lock ``` -------------------------------- ### Install FINEMAP v1.4.1 Source: https://github.com/omerwe/polyfun/blob/master/README.md Download and extract the FINEMAP executable for Linux or Mac OS X. ```bash wget http://christianbenner.com/finemap_v1.4.1_x86_64.tgz tar xvf finemap_v1.4.1_x86_64.tgz ``` ```bash wget http://christianbenner.com/finemap_v1.4.1_MacOSX.tgz tar xvf finemap_v1.4.1_MacOSX.tgz ``` -------------------------------- ### Fine-mapping with SuSiE using UK Biobank LD data Source: https://github.com/omerwe/polyfun/wiki/3.-Functionally-informed-fine-mapping-with-finemapper This example demonstrates fine-mapping with SuSiE using pre-computed LD information from the UK Biobank. It requires downloading ~1GB of LD data. ```bash #download an LD matrix mkdir -p LD_cache mkdir -o output mkdir -p LD_temp cd LD_temp wget https://broad-alkesgroup-ukbb-ld.s3.amazonaws.com/UKBB_LD/chr1_46000001_49000001.npz wget https://broad-alkesgroup-ukbb-ld.s3.amazonaws.com/UKBB_LD/chr1_46000001_49000001.gz cd .. #run fine-mapper python finemapper.py \ --ld LD_temp/chr1_46000001_49000001 \ --sumstats example_data/chr1.finemap_sumstats.txt.gz \ --n 383290 \ --chr 1 \ --start 46000001 \ --end 49000001 \ --method susie \ --max-num-causal 5 \ --out output/finemap.UKB.1.46000001.49000001.gz ``` -------------------------------- ### Install PolyFun using Anaconda Source: https://github.com/omerwe/polyfun/blob/master/README.md This command sequence clones the repository, navigates into the directory, and creates a new Anaconda environment named 'polyfun' using the provided YAML file. It then activates this environment. ```bash git clone https://github.com/omerwe/polyfun cd polyfun conda env create -f polyfun.yml conda activate polyfun ``` -------------------------------- ### Example: Estimate Functional Enrichment Source: https://github.com/omerwe/polyfun/wiki/5.-Estimating-functional-enrichment-using-S-LDSC A concrete example demonstrating how to run S-LDSC for functional enrichment analysis using specific example data files and output directory. This command creates a temporary directory and specifies input files for heritability, LD scores, and weights. ```bash mkdir -p temp python ldsc.py \ --h2 example_data/sumstats.parquet \ --ref-ld-chr example_data/annotations. \ --w-ld-chr example_data/weights. \ --out temp/enrichment \ --overlap-annot \ --not-M-5-50 ``` -------------------------------- ### Example PolyLoc Input Data Source: https://github.com/omerwe/polyfun/wiki/4.-Polygenic-Localization-with-PolyLoc This is an example of the input file format for posterior means and standard deviations of causal effect sizes, as generated by run_finemapper. The columns CHR, SNP, BP, A1, A2, Z, N, BETA_MEAN, and BETA_SD are required. ```text CHR SNP BP A1 A2 Z N BETA_MEAN BETA_SD 1 rs3748597 888659 T C 0.85233 383290 0.00021 0.00005 1 rs6661956 2465912 C T 0.98513 383290 0.00161 0.00006 1 rs2376821 2974852 T C -0.73402 383290 -0.00186 0.00111 1 rs10797386 3168280 A G -0.59635 383290 -0.00057 0.00006 1 rs7548372 4943523 C A 2.60293 383290 0.00643 0.00014 1 rs6678838 5003147 G T 1.10294 383290 0.00135 0.00008 1 rs6675995 5226752 G A -1.22154 383290 -0.00027 0.00034 1 rs2012852 5541205 C A 0.30166 383290 0.00022 0.00027 1 rs10864271 7135268 A G 2.03717 383290 0.00471 0.00031 ``` -------------------------------- ### Check rpy2 Installation and R Link Source: https://github.com/omerwe/polyfun/wiki/7.-FAQ Diagnose rpy2 installation issues by checking its link to R. This command should show matching versions or indicate a PATH problem. ```python python -m rpy2.situation ``` -------------------------------- ### Annotation output format Source: https://github.com/omerwe/polyfun/wiki/3.-Functionally-informed-fine-mapping-with-finemapper Example of the expected output structure for extracted annotations. ```text PIP CHR SNP BP A1 A2 Coding_UCSC_lowfreq Coding_UCSC_common 1.0000e+00 1 rs2088102 46032974 T C 0 0 9.9786e-01 1 rs7528714 47966058 G A 0 0 9.7377e-01 1 rs7528075 47870271 G A 0 0 ``` -------------------------------- ### Check Pandas Version Source: https://github.com/omerwe/polyfun/wiki/7.-FAQ Verify your pandas installation version. Ensure it is at least 0.25.0, as older versions may lack necessary features for PolyFun. ```python import pandas as pd print(pd.__version__) ``` -------------------------------- ### S-LDSC Functional Enrichment Output Example Source: https://github.com/omerwe/polyfun/wiki/5.-Estimating-functional-enrichment-using-S-LDSC This is an example of the expected output format from the S-LDSC functional enrichment analysis. It includes columns for category, proportion of SNPs, heritability, standard errors, enrichment values, and p-values. ```text Category Prop._SNPs Prop._h2 Prop._h2_std_error Enrichment Enrichment_std_error Enrichment_p Coding_UCSC_common_0 5.2671e-03 3.0045e-01 4.7188e-02 5.7043e+01 8.9590e+00 3.1728e-09 Coding_UCSC_lowfreq_0 1.1581e-02 -3.3554e-03 4.0509e-02 -2.8973e-01 3.4979e+00 7.0952e-01 Conserved_LindbladToh_common_0 8.8296e-03 4.3129e-01 4.7615e-02 4.8846e+01 5.3927e+00 3.0678e-16 Conserved_LindbladToh_lowfreq_0 2.0367e-02 5.5681e-02 5.4985e-02 2.7339e+00 2.6997e+00 5.2303e-01 Repressed_Hoffman_common_0 1.7496e-01 -9.9906e-03 3.2406e-02 -5.7102e-02 1.8522e-01 1.9314e-07 Repressed_Hoffman_lowfreq_0 2.7381e-01 -4.0496e-01 5.7435e-02 -1.4790e+00 2.0977e-01 6.3585e-23 base_0 1.0000e+00 1.0000e+00 5.4703e-09 1.0000e+00 5.4703e-09 NA ``` -------------------------------- ### View PolyLoc help documentation Source: https://github.com/omerwe/polyfun/wiki/4.-Polygenic-Localization-with-PolyLoc Displays all available parameters and configuration options for the PolyLoc script. ```bash python polyloc.py --help ``` -------------------------------- ### Example Output of Per-SNP Heritabilities (Constrained) Source: https://github.com/omerwe/polyfun/wiki/1.-Computing-prior-causal-probabilities-with-PolyFun This is an example of the output for truncated per-SNP heritabilities (SNPVAR column) for chromosome 22, which can be used as prior causal probabilities in fine-mapping. The 'Z' column represents the Z-score. ```text CHR SNP BP A1 A2 SNPVAR Z N 22 rs139069276 16866502 G A 7.1906e-09 -1.2188e-02 383290 22 rs34747326 16870173 A G 7.1906e-09 -1.8948e+00 383290 22 rs4010550 16900134 G A 1.4878e-08 1.3657e+00 383290 22 rs5994099 16905044 G A 7.1906e-09 7.2224e-01 383290 22 rs59750689 16936369 T C 7.1906e-09 9.4481e-02 383290 22 rs148021587 16939232 C T 1.4878e-08 8.0397e-01 383290 22 rs3954635 17024983 A C 1.4878e-08 -3.4335e-01 383290 22 rs371202053 17034394 G A 1.4878e-08 -7.8644e-01 383290 22 rs200071370 17037779 C T 1.4878e-08 3.5049e-01 383290 ``` -------------------------------- ### Step 1: Genome-wide fine-mapping (PolyPred) Source: https://context7.com/omerwe/polyfun/llms.txt Prepares sumstats for fine-mapping and creates jobs for fine-mapping. Requires sumstats, sample size (n), and desired fine-mapping method. ```bash mkdir -p output python munge_polyfun_sumstats.py \ --sumstats polypred_example/bolt.sumstats.txt.gz \ --out output/bolt.sumstats.munged.parquet \ --n 337491 python create_finemapper_jobs.py \ --sumstats output/bolt.sumstats.munged.parquet \ --n 337491 \ --method susie \ --non-funct \ --max-num-causal 2 \ --out-prefix output/polyfun_output \ --jobs-file output/jobs.txt bash output/jobs.txt python aggregate_finemapper_results.py \ --out-prefix output/polyfun_output \ --sumstats output/bolt.sumstats.munged.parquet \ --out output/polyfun_output.agg.txt.gz \ --adjust-beta-freq ``` -------------------------------- ### Create Custom Annotation Files in Python Source: https://context7.com/omerwe/polyfun/llms.txt Generates annotation files with required columns and corresponding .M files containing column sums. Recommended to save as parquet. ```python import pandas as pd import numpy as np # Create annotation DataFrame annotations = pd.DataFrame({ 'SNP': ['rs139069276', 'rs34747326', 'rs4010550'], 'CHR': [22, 22, 22], 'BP': [16866502, 16870173, 16900134], 'A1': ['G', 'A', 'G'], 'A2': ['A', 'G', 'A'], 'MyAnnotation_common': [1, 0, 0], 'MyAnnotation_lowfreq': [0, 1, 0], 'base': [1, 1, 1] }) # Save as parquet (recommended) or gzipped text annotations.to_parquet('my_annotations.22.annot.parquet', index=False) # Create .l2.M file with column sums for annotations (excluding CHR, SNP, BP, A1, A2) annotation_cols = ['MyAnnotation_common', 'MyAnnotation_lowfreq', 'base'] sums = annotations[annotation_cols].sum().values with open('my_annotations.22.l2.M', 'w') as f: f.write(' '.join(map(str, sums))) ``` -------------------------------- ### View generated fine-mapping commands Source: https://github.com/omerwe/polyfun/wiki/3.-Functionally-informed-fine-mapping-with-finemapper Displays the first three lines of the generated jobs file containing individual fine-mapping commands. ```bash python3 finemapper.py --chr 1 --start 1 --end 3000001 --out output/polyfun_all.chr1.1_3000001.gz --ld https://broad-alkesgroup-ukbb-ld.s3.amazonaws.com/UKBB_LD/chr1_1_3000001 --method susie --sumstats example_data/chr1.finemap_sumstats.txt.gz --n 383290 --memory 1 --max-num-causal 5 python3 finemapper.py --chr 1 --start 1000001 --end 4000001 --out output/polyfun_all.chr1.1000001_4000001.gz --ld https://broad-alkesgroup-ukbb-ld.s3.amazonaws.com/UKBB_LD/chr1_1000001_4000001 --method susie --sumstats example_data/chr1.finemap_sumstats.txt.gz --n 383290 --memory 1 --max-num-causal 5 python3 finemapper.py --chr 1 --start 2000001 --end 5000001 --out output/polyfun_all.chr1.2000001_5000001.gz --ld https://broad-alkesgroup-ukbb-ld.s3.amazonaws.com/UKBB_LD/chr1_2000001_5000001 --method susie --sumstats example_data/chr1.finemap_sumstats.txt.gz --n 383290 --memory 1 --max-num-causal 5 ``` -------------------------------- ### Fine-mapping with SuSiE using Local Genotypes Source: https://context7.com/omerwe/polyfun/llms.txt Performs fine-mapping using the SuSiE method with local genotypes. Requires specifying genotype data, summary statistics, sample size, chromosome, region boundaries, and an output directory. LD matrices are computed and cached locally. ```bash mkdir -p LD_cache mkdir -p output # Fine-mapping with SuSiE using local genotypes python finemapper.py \ --geno example_data/chr1 \ --sumstats example_data/chr1.finemap_sumstats.txt.gz \ --n 383290 \ --chr 1 \ --start 46000001 \ --end 49000001 \ --method susie \ --max-num-causal 5 \ --cache-dir LD_cache \ --out output/finemap.1.46000001.49000001.gz ``` ```bash # View fine-mapping results zcat output/finemap.1.46000001.49000001.gz | head ``` -------------------------------- ### Viewing SuSiE fine-mapping output Source: https://github.com/omerwe/polyfun/wiki/3.-Functionally-informed-fine-mapping-with-finemapper This command displays the first few lines of the SuSiE fine-mapping output file, which contains columns like PIP, BETA_MEAN, BETA_SD, and CREDIBLE_SET. ```bash cat output/finemap.1.46000001.49000001.gz | zcat | head ``` -------------------------------- ### View Minimal SNPs for Heritability Proportion Source: https://github.com/omerwe/polyfun/wiki/4.-Polygenic-Localization-with-PolyLoc Use the 'head' command to view the initial lines of the .Mp output file, which details the minimal number of top-ranked SNPs required to explain a given proportion of SNP heritability. ```bash head -51 output/polyloc_test.Mp ``` -------------------------------- ### Fine-mapping with FINEMAP Algorithm Source: https://context7.com/omerwe/polyfun/llms.txt Performs fine-mapping using the FINEMAP algorithm. This requires the FINEMAP executable to be available and specified via the `--finemap-exe` argument. It can be used with local genotypes or pre-computed LD. ```bash mkdir -p LD_cache output python finemapper.py \ --geno example_data/chr1 \ --sumstats example_data/chr1.finemap_sumstats.txt.gz \ --n 383290 \ --chr 1 \ --start 46000001 \ --end 49000001 \ --method finemap \ --finemap-exe /path/to/finemap_v1.4 \ --max-num-causal 5 \ --cache-dir LD_cache \ --out output/finemap.finemap.1.46000001.49000001.gz ``` -------------------------------- ### Displaying Annotation File Head Source: https://github.com/omerwe/polyfun/wiki/2.-Using-and-creating-functional-annotations Use pandas to read and display the first few rows of a .parquet annotation file. Ensure the file path is correct. ```python import pandas as pd df = pd.read_parquet('example_data/annotations.22.annot.parquet') print(df.head()) ``` -------------------------------- ### Clone PolyFun Repository Source: https://github.com/omerwe/polyfun/blob/master/README.md Download the PolyFun source code from GitHub to a local machine. ```bash git clone https://github.com/omerwe/polyfun ``` -------------------------------- ### Run PolyLoc to Compute SNP Partitions Source: https://github.com/omerwe/polyfun/wiki/4.-Polygenic-Localization-with-PolyLoc This command executes the first stage of PolyLoc, which partitions SNPs into bins based on their posterior heritability. It requires an output directory, a prefix for output files, the posterior data file, and optionally, plink .bim files for SNP assignment. ```bash mkdir -p output python polyloc.py \ --compute-partitions \ --output-prefix output/polyloc_test \ --posterior example_data/posterior_betas.gz \ --bfile-chr example_data/reference. ``` -------------------------------- ### Run and Aggregate Fine-mapping Jobs Source: https://context7.com/omerwe/polyfun/llms.txt Executes the fine-mapping jobs created previously and aggregates the results into a single output file. Jobs can be submitted to a cluster or run sequentially. ```bash # Step 2: Run each job (submit to cluster or run sequentially) bash output/polyfun_all_jobs.txt ``` ```bash # Step 3: Aggregate results python aggregate_finemapper_results.py \ --out-prefix output/polyfun_all \ --sumstats example_data/chr1.finemap_sumstats.txt.gz \ --out output/polyfun_agg.txt.gz ``` -------------------------------- ### View extracted annotations Source: https://github.com/omerwe/polyfun/wiki/3.-Functionally-informed-fine-mapping-with-finemapper Command to inspect the first few columns of the generated annotation file. ```bash cat output/top_annot.1.46000001.49000001.txt.gz | zcat | cut -f1,2,3,4,5,6,7,8 ``` -------------------------------- ### Compute LD-scores using a reference panel (Custom Annotations) Source: https://context7.com/omerwe/polyfun/llms.txt Computes LD-scores for custom functional annotations using a reference panel. Requires a bfile and annotation file. ```bash mkdir -p output python compute_ldscores.py \ --bfile example_data/reference.1 \ --annot example_data/annotations.1.annot.parquet \ --out output/ldscores_example.parquet ``` -------------------------------- ### Compute Weighted PRS using polypred.py Source: https://github.com/omerwe/polyfun/wiki/6.-Trans-ethnic-polygenic-risk-prediction-with-PolyPred Executes the PRS calculation using specified beta files, mixing weights, and PLINK input files. Ensure the --mixweights-prefix matches the --output-prefix used during the mixing weight estimation step. ```bash python polypred.py \ --predict \ --betas polypred_example/bolt.betas.gz,output/polyfun_output.agg.txt.gz \ --mixweights-prefix output/polypred \ --output-prefix output/polypred.predictions \ --plink-exe ~/plink/plink \ polypred_example/1000G.subset.*.bed ``` -------------------------------- ### Compute LD-scores using custom .bcor matrices (Custom Annotations) Source: https://context7.com/omerwe/polyfun/llms.txt Computes LD-scores for custom functional annotations using custom .bcor LD matrices. Requires an annotation file and the path to .bcor files. ```bash mkdir -p output python compute_ldscores_from_ld.py \ --annot example_data/annotations.1.annot.parquet \ --out output/ldscores_example3.parquet \ --n 10000 \ bcor_files/*.bcor ``` -------------------------------- ### Perform Genome-wide Fine-mapping with PolyFun Source: https://github.com/omerwe/polyfun/wiki/6.-Trans-ethnic-polygenic-risk-prediction-with-PolyPred Executes the end-to-end fine-mapping pipeline including munging, job creation, execution, and aggregation. ```bash mkdir -p output #created munged sumstats python munge_polyfun_sumstats.py \ --sumstats polypred_example/bolt.sumstats.txt.gz \ --out output/bolt.sumstats.munged.parquet \ --n 337491 #create fine-mapping jobs python create_finemapper_jobs.py \ --sumstats output/bolt.sumstats.munged.parquet \ --n 337491 \ --method susie \ --non-funct \ --max-num-causal 2 \ --out-prefix output/polyfun_output \ --jobs-file output/jobs.txt #run each and every fine-mapping job (could take several hours or more) bash output/jobs.txt #aggregate all of the results python aggregate_finemapper_results.py \ --out-prefix output/polyfun_output \ --sumstats output/bolt.sumstats.munged.parquet \ --out output/polyfun_output.agg.txt.gz \ --adjust-beta-freq ``` -------------------------------- ### Fine-mapping with FINEMAP using Plink genotypes Source: https://github.com/omerwe/polyfun/wiki/3.-Functionally-informed-fine-mapping-with-finemapper This command performs fine-mapping using the FINEMAP method with genotypes from a plink file. You need to provide the path to the FINEMAP executable. ```bash mkdir -p LD_cache mkdir -o output python finemapper.py \ --geno example_data/chr1 \ --sumstats example_data/chr1.finemap_sumstats.txt.gz \ --n 383290 \ --chr 1 \ --start 46000001 \ --end 49000001 \ --method finemap \ --finemap-exe \ --max-num-causal 5 \ --cache-dir LD_cache \ --out output/finemap.finemap_exe.1.46000001.49000001.gz ``` -------------------------------- ### Munge Summary Statistics with munge_polyfun_sumstats.py Source: https://github.com/omerwe/polyfun/wiki/1.-Computing-prior-causal-probabilities-with-PolyFun This script converts summary statistics files into a PolyFun-friendly parquet format. It accommodates various input formats and allows filtering by INFO score, MAF, and MHC region. ```bash python munge_polyfun_sumstats.py \ --sumstats example_data/boltlmm_sumstats.gz \ --n 327209 \ --out example_data/sumstats_munged.parquet \ --min-info 0.6 \ --min-maf 0.001 ``` ```python df = pd.read_parquet('example_data/sumstats_munged.parquet') ``` -------------------------------- ### Compute L2-regularized Per-SNP Heritabilities with PolyFun Source: https://github.com/omerwe/polyfun/wiki/1.-Computing-prior-causal-probabilities-with-PolyFun Use this command to run PolyFun for computing per-SNP heritabilities with L2-regularized S-LDSC. Ensure the output directory exists and provide paths to your sumstats, reference LD, and weights files. ```bash mkdir -p output python polyfun.py \ --compute-h2-L2 \ --no-partitions \ --output-prefix output/testrun \ --sumstats example_data/sumstats.parquet \ --ref-ld-chr example_data/annotations. \ --w-ld-chr example_data/weights. ``` -------------------------------- ### Run PolyLoc for Heritability Estimation Source: https://github.com/omerwe/polyfun/wiki/4.-Polygenic-Localization-with-PolyLoc Execute the polyloc.py script with the --compute-polyloc flag, specifying output prefix, LD weights, and summary statistics files. Ensure the summary statistics file is different from the one used for posterior causal effect sizes to avoid bias. ```bash python polyloc.py \ --output-prefix output/polyloc_test \ --compute-polyloc \ --w-ld-chr example_data/weights. \ --sumstats example_data/sumstats2.parquet ``` -------------------------------- ### Fine-mapping with SuSiE using Plink genotypes Source: https://github.com/omerwe/polyfun/wiki/3.-Functionally-informed-fine-mapping-with-finemapper This command performs fine-mapping using SuSiE with genotypes from a plink file. Ensure the A1 allele is the effect allele. Output and LD cache are specified. ```bash mkdir -p LD_cache mkdir -o output python finemapper.py \ --geno example_data/chr1 \ --sumstats example_data/chr1.finemap_sumstats.txt.gz \ --n 383290 \ --chr 1 \ --start 46000001 \ --end 49000001 \ --method susie \ --max-num-causal 5 \ --cache-dir LD_cache \ --out output/finemap.1.46000001.49000001.gz ``` -------------------------------- ### Create region-specific fine-mapping jobs Source: https://github.com/omerwe/polyfun/wiki/3.-Functionally-informed-fine-mapping-with-finemapper Generates a file containing commands for parallel fine-mapping across the genome. ```bash python create_finemapper_jobs.py \ --sumstats example_data/chr1.finemap_sumstats.txt.gz \ --n 383290 \ --method susie \ --max-num-causal 5 \ --out-prefix output/polyfun_all \ --jobs-file output/polyfun_all_jobs.txt ``` -------------------------------- ### View Heritability per Bin Estimates Source: https://github.com/omerwe/polyfun/wiki/4.-Polygenic-Localization-with-PolyLoc Display the contents of the .bin_h2 output file to see the estimated heritability explained by SNPs within each defined bin, along with standard errors and cumulative percentages. ```bash cat output/polyloc_test.bin_h2 ``` -------------------------------- ### Displaying .l2.M File Content Source: https://github.com/omerwe/polyfun/wiki/2.-Using-and-creating-functional-annotations View the contents of an .l2.M file from the shell to see the sums of annotation columns. This file contains whitespace-delimited sums. ```shell cat example_data/annotations.22.l2.M ``` -------------------------------- ### Stage 1: Partition SNPs into bins (Polyfun) Source: https://context7.com/omerwe/polyfun/llms.txt Partitions SNPs into bins based on posterior effect sizes. Requires posterior effect size data and a reference panel. ```bash python polyloc.py \ --compute-partitions \ --output-prefix output/polyloc_test \ --posterior example_data/posterior_betas.gz \ --bfile-chr example_data/reference. ``` -------------------------------- ### Aggregate fine-mapping results Source: https://github.com/omerwe/polyfun/wiki/3.-Functionally-informed-fine-mapping-with-finemapper Use this script to merge region-specific fine-mapping outputs into a single file. ```bash python aggregate_finemapper_results.py \ --out-prefix output/polyfun_all \ --sumstats example_data/chr1.finemap_sumstats.txt.gz \ --out output/polyfun_agg.txt.gz ``` -------------------------------- ### Run PolyFun with L2-regularized S-LDSC Source: https://github.com/omerwe/polyfun/wiki/1.-Computing-prior-causal-probabilities-with-PolyFun Executes the L2-regularized S-LDSC stage to estimate per-SNP heritabilities and partition SNPs into bins. ```bash mkdir -p output python polyfun.py \ --compute-h2-L2 \ --output-prefix output/testrun \ --sumstats example_data/sumstats.parquet \ --ref-ld-chr example_data/annotations. \ --w-ld-chr example_data/weights. ``` -------------------------------- ### Fine-mapping with Pre-computed UK Biobank LD Source: https://context7.com/omerwe/polyfun/llms.txt Runs fine-mapping using pre-computed summary LD matrices from the UK Biobank. This is suitable for British-ancestry summary statistics and requires downloading the relevant LD matrix files for the target region. ```bash # Download LD matrix for the target region mkdir -p LD_temp output cd LD_temp wget https://broad-alkesgroup-ukbb-ld.s3.amazonaws.com/UKBB_LD/chr1_46000001_49000001.npz wget https://broad-alkesgroup-ukbb-ld.s3.amazonaws.com/UKBB_LD/chr1_46000001_49000001.gz cd .. # Run fine-mapping with pre-computed LD python finemapper.py \ --ld LD_temp/chr1_46000001_49000001 \ --sumstats example_data/chr1.finemap_sumstats.txt.gz \ --n 383290 \ --chr 1 \ --start 46000001 \ --end 49000001 \ --method susie \ --max-num-causal 5 \ --out output/finemap.UKB.1.46000001.49000001.gz ``` -------------------------------- ### Compute LD-scores using UK Biobank matrices (Custom Annotations) Source: https://context7.com/omerwe/polyfun/llms.txt Computes LD-scores for custom functional annotations using pre-computed UK Biobank LD matrices. Requires an annotation file. ```bash mkdir -p output python compute_ldscores_from_ld.py \ --annot example_data/annotations.1.annot.parquet \ --ukb \ --out output/ldscores_example2.parquet ``` -------------------------------- ### Compute LD-scores with Reference Panel Source: https://github.com/omerwe/polyfun/wiki/2.-Using-and-creating-functional-annotations Compute LD-scores for annotations using the `compute_ldscores.py` script with a reference panel. Specify the plink binary file prefix, annotation file, and output path. Parquet format for annotations is recommended for speed. ```shell mkdir -p output python compute_ldscores.py \ --bfile example_data/reference.1 \ --annot example_data/annotations.1.annot.parquet \ --out output/ldscores_example.parquet ``` -------------------------------- ### Create Genome-wide Fine-mapping Jobs Source: https://context7.com/omerwe/polyfun/llms.txt Generates region-specific fine-mapping jobs for a genome-wide analysis. It can optionally filter for genome-wide significant loci using a p-value cutoff. The output includes a file listing the jobs to be executed. ```bash mkdir -p output # Step 1: Create region-specific jobs python create_finemapper_jobs.py \ --sumstats example_data/chr1.finemap_sumstats.txt.gz \ --n 383290 \ --method susie \ --max-num-causal 5 \ --out-prefix output/polyfun_all \ --jobs-file output/polyfun_all_jobs.txt ``` ```bash # Optional: Restrict to genome-wide significant loci python create_finemapper_jobs.py \ --sumstats example_data/chr1.finemap_sumstats.txt.gz \ --n 383290 \ --method susie \ --max-num-causal 5 \ --pvalue-cutoff 5e-8 \ --out-prefix output/polyfun_significant \ --jobs-file output/polyfun_significant_jobs.txt ``` -------------------------------- ### Estimate Tagging SNP Effect Sizes with BOLT-LMM Source: https://github.com/omerwe/polyfun/wiki/6.-Trans-ethnic-polygenic-risk-prediction-with-PolyPred Provides the command line arguments for estimating tagging SNP effect sizes using the BOLT-LMM software. ```bash bolt_v2.3.4 \ --bed=[plink_prefix].{1:22}.bed \ --bim=[plink_prefix].{1:22}.bed \ --fam=[fam_file] \ --remove=[file with individuals to remove] \ --covarFile=[covariates file] \ --covarCol=[discrete covariate name 1] --covarCol=[discrete covariate name 2] --covarCol=... \ --qcovarCol=[quantitative covariate name 1] --qcovarCol=[quantitative covariate name 2] --qcovarCol ... \ --phenoFile=[pheotype file] \ --phenoCol=[phenotype column] \ --LDscoresFile=[path to BOLT-LMM]/tables/LDSCORE.1000G_EUR.tab.gz \ --LDscoresMatchBp \ --lmmForceNonInf \ --numThreads=6 \ --verboseStats \ --covarMaxLevels=30 \ --maxModelSnps=1500000 \ --statsFile=[output summary statistics file] \ --predBetasFile=[output tagging effect sizes file] ``` -------------------------------- ### Compute LD-scores using UK Biobank precomputed matrices Source: https://github.com/omerwe/polyfun/wiki/4.-Polygenic-Localization-with-PolyLoc Computes LD-scores for a specific chromosome by downloading and using precomputed UK Biobank LD matrices. ```bash mkdir -p LD_cache python polyloc.py \ --output-prefix output/polyloc_test \ --compute-ldscores \ --ld-ukb \ --ld-dir LD_cache \ --chr 1 ``` -------------------------------- ### Munge Summary Statistics for PolyFun Source: https://context7.com/omerwe/polyfun/llms.txt Converts raw summary statistics to PolyFun-compatible parquet format. Handles various input formats and column names. Use for BOLT-LMM analyses. ```bash python munge_polyfun_sumstats.py \ --sumstats example_data/boltlmm_sumstats.gz \ --n 327209 \ --out example_data/sumstats_munged.parquet \ --min-info 0.6 \ --min-maf 0.001 ``` ```python import pandas as pd df = pd.read_parquet('example_data/sumstats_munged.parquet') print(df.head()) # Output columns: CHR, SNP, BP, A1, A2, Z, N ``` -------------------------------- ### Compute H2-L2 with Custom Annotations Source: https://github.com/omerwe/polyfun/wiki/7.-FAQ Use this command to compute heritability (h2) using L2 regularization, specifying output prefix, summary statistics, reference LD, and custom annotations. Ensure your custom annotations are in the specified format. ```bash python polyfun.py \ --compute-h2-L2 \ --output-prefix output/testrun \ --sumstats example_data/sumstats.parquet \ --ref-ld-chr example_data/annotations.,my_annot. \ --w-ld-chr example_data/weights. ``` -------------------------------- ### Inspect re-estimated heritability output Source: https://github.com/omerwe/polyfun/wiki/1.-Computing-prior-causal-probabilities-with-PolyFun Displays the first few lines of the generated per-SNP heritability file for chromosome 22. ```bash cat output/testrun.22.snpvar_constrained.gz | zcat | head ``` -------------------------------- ### Heritability per Bin Output Format Source: https://github.com/omerwe/polyfun/wiki/4.-Polygenic-Localization-with-PolyLoc This table shows the estimated heritability causally explained by SNPs in each bin. Columns include bin ID, bin size, cumulative bin size, percentage of heritability explained (%H2), its standard error (%H2_STDERR), and cumulative percentages. ```text BIN BIN_SIZE SUM_BINSIZE %H2 %H2_STDERR SUM_%H2 SUM_%H2_STDERR 1 10 10 0.17250 0.01015 0.17250 0.01015 2 32 42 0.13510 0.01878 0.30760 0.01970 3 70 112 0.12648 0.01779 0.43408 0.02313 4 110 222 0.13666 0.01394 0.57074 0.02198 5 193 415 0.15129 0.01394 0.72203 0.02134 6 255 670 0.09629 0.01070 0.81832 0.01907 7 315 985 0.07411 0.00857 0.89243 0.01611 8 410 1395 0.05337 0.00840 0.94580 0.01297 9 492 1887 0.05057 0.00877 0.99637 0.00807 10 639 2526 0.00363 0.00807 1.00000 0.00000 11 949 3475 0.00000 0.00000 1.00000 0.00000 ``` -------------------------------- ### Compute LD-scores with UK Biobank LD matrices Source: https://github.com/omerwe/polyfun/wiki/2.-Using-and-creating-functional-annotations Use this script to compute LD-scores with pre-computed UK Biobank LD matrices. The script automatically downloads necessary matrices. Specify the annotations file and the output file name. ```bash mkdir -p output python compute_ldscores_from_ld.py \ --annot example_data/annotations.1.annot.parquet \ --ukb \ --out output/ldscores_example2.parquet ``` -------------------------------- ### Compute LD-scores with custom .bcor LD matrices Source: https://github.com/omerwe/polyfun/wiki/2.-Using-and-creating-functional-annotations Compute LD-scores using your own pre-computed LD matrices in .bcor format. You need to specify the sample size used for LD computation and provide the path to the .bcor files. ```bash mkdir -p output python compute_ldscores_from_ld.py \ --annot example_data/annotations.1.annot.parquet \ --out output/ldscores_example3.parquet \ --n 10000 \ bcor_files/*.bcor ``` -------------------------------- ### Load LD Matrix and SNP Metadata Source: https://github.com/omerwe/polyfun/wiki/7.-FAQ Parses a pair of LD files identified by a prefix. Requires the .gz file to contain SNP metadata and the .npz file to contain a sparse LD matrix. ```python import numpy as np import pandas as pd import scipy.sparse as sparse def load_ld_npz(ld_prefix): ''' ld_prefix is the prefix of a pair of LD files (e.g. "chr10_102000001_105000001") ''' #load the SNPs metadata gz_file = '%s.gz'%(ld_prefix) df_ld_snps = pd.read_table(gz_file, sep='\s+') df_ld_snps.rename(columns={'rsid':'SNP', 'chromosome':'CHR', 'position':'BP', 'allele1':'A1', 'allele2':'A2'}, inplace=True, errors='ignore') assert 'SNP' in df_ld_snps.columns assert 'CHR' in df_ld_snps.columns assert 'BP' in df_ld_snps.columns assert 'A1' in df_ld_snps.columns assert 'A2' in df_ld_snps.columns df_ld_snps.index = df_ld_snps['CHR'].astype(str) + '.' + df_ld_snps['BP'].astype(str) + '.' + df_ld_snps['A1'] + '.' + df_ld_snps['A2'] #load the LD matrix npz_file = '%s.npz'%(ld_prefix) try: R = sparse.load_npz(npz_file).toarray() R += R.T except ValueError: raise IOError('Corrupt file: %s'%(npz_file)) #create df_R and return it df_R = pd.DataFrame(R, index=df_ld_snps.index, columns=df_ld_snps.index) return df_R, df_ld_snps ``` -------------------------------- ### Compute LD-scores for SNP bins Source: https://github.com/omerwe/polyfun/wiki/1.-Computing-prior-causal-probabilities-with-PolyFun Computes LD-scores for SNP bins using either local genotype files or precomputed UK Biobank LD matrices. ```bash python polyfun.py \ --compute-ldscores \ --output-prefix output/testrun \ --bfile-chr example_data/reference. \ --chr 1 ``` ```bash mkdir -p LD_cache python polyfun.py \ --compute-ldscores \ --output-prefix output/testrun \ --ld-ukb \ --ld-dir LD_cache \ --chr 1 ``` -------------------------------- ### Re-estimate per-SNP heritabilities Source: https://github.com/omerwe/polyfun/wiki/1.-Computing-prior-causal-probabilities-with-PolyFun Executes the S-LDSC estimation process. Requires LD-scores to be computed for all chromosomes prior to execution. ```bash python polyfun.py \ --compute-h2-bins \ --output-prefix output/testrun \ --sumstats example_data/sumstats.parquet \ --w-ld-chr example_data/weights. ```