Skip to content

lukejoconnor/polygenicity_scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Scripts to reproduce results from O'Connor & Sella 2025

This repository contains scripts to reproduce results from O'Connor & Sella 2025. It relies upon the Fourier Mixture Regression repository.

Installation and data download

git clone https://github.com/lukejoconnor/FMR.git
git clone https://github.com/lukejoconnor/polygenicity_scripts.git
mkdir FMR/matfiles
curl -L -o FMR/matfiles.zip https://www.dropbox.com/sh/mclm1urkxs8ga80/AADDDABQYeGtyQxmom2raMkva
unzip FMR/matfiles.zip -d FMR/matfiles

Downloading the data from Dropbox will take several minutes. The size of the download is 6GB. The larger files with LD matrices and Fourier scores are not actually required for these scripts, so you may also choose to download individual files from the Dropbox link.

Contents

The MATLAB folder contains two scripts:

  • compare_polygenicities.m reproduces Figure 1 of the paper.
  • estimate_polygenicity.m reproduces Figure 3 of the paper.

A subdirectory MATLAB/as-is contains a simulation script which was used to produce Figure 2 of the paper. This script is provided as-is; reproducing results yourself will require multiple steps of installation and manual path manipulation.

The function which estimates polygenicity from FMR estimates is provided in FMR repository. This function in its entirety is:

function Pi = compute_polygenicity(x,w,f,finv)
%compute_polygenicity evaluates the function
% Pi_f(x,w) = h^2 / f^-1 (1/h^2 w_1*f(x_1)+...+w_k*f(x_k))
% where h^2 = w_1+...+w_k and f:(0,infty)->(0,infty) is a continuous
% function with inverse finv.
%   For example:
%   \Pi_{entropy}: f = @log and finv=@exp
%   \Pi_{effective}: f=@(x)x and finv=f
%   \Pi_{softmax}: f=@(x)exp(-1./x) and finv=@(x)-1./log(x)
%   \Pi_{softmax} alternative implementation that avoids overflow issues:
%       f=@(x)exp(1/max(x(:)) - 1./x) and finv=@(y,xmax)-1./(-1/xmax + log(y))
%   \Pi_0 [not recommended]: f=@inv and finv=@inv
% 
% Can be applied to matrix-valued x and w (e.g., the jackknife output of FMR),
% in which case it computes polygenicity for each row of the matrix.

h2 = sum(w,2);
w = w./h2;
y = sum(w .* f(x),2);
if nargin(finv) == 1
    Pi = h2 ./ finv(y);
else
    % To avoid overflow issues
    Pi = h2 ./ finv(y, max(x(:)));
end
end

Links and citations

About

Scripts accompanying O'Connor and Sella bioRxiv

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages