snipar.pgs module

snipar.pgs.am_adj_2gen(estimates, estimate_cols, h2f, h2f_se, rk=None, rk_se=None, pg=None, y_std=1, pg_std=1)[source]

Adjust 2-generation model results for assortative mating (assuming equilibrium)

snipar.pgs.am_adj_2gen_calc(delta, delta_se, ab, ab_se, r_delta_ab, h2f, h2f_se, rk, rk_se, is_beta=False, verbose=True)[source]
snipar.pgs.compute(pgs, bedfile=None, bgenfile=None, par_gts_f=None, ped=None, sib=False, compute_controls=False, verbose=True, batch_size=None)[source]

Compute a polygenic score (PGS) for the individuals with observed genotypes and observed/imputed parental genotypes.

Args:
par_gts_fstr

path to HDF5 file with imputed parental genotypes

gts_fstr

path to bed file with observed genotypes

pgssnipar.pgs

the PGS, defined by the weights for a set of SNPs and the alleles of those SNPs

sibbool

Compute the PGS for genotyped individuals with at least one genotyped sibling and observed/imputed parental genotypes. Default False.

compute_controlsbool

Compute polygenic scores for control families (families with observed parental genotypes set to missing). Default False.

Returns:
pgsnipar.gtarray

Return the polygenic score as a genotype array with columns: individual’s PGS, mean of their siblings’ PGS, observed/imputed paternal PGS, observed/imputed maternal PGS

snipar.pgs.fit_pgs_model(y, pg, ngen, ibdrel_path=None, covariates=None, fit_sib=False, parsum=False, gparsum=False, outprefix=None, sparse_thresh=0.025)[source]
snipar.pgs.h2f_parse(h2f_str)[source]
snipar.pgs.make_and_fit_model(y, pg, pg_cols, ibdrel_path=None, covariates=None, sparse_thresh=0.025)[source]
snipar.pgs.make_grms(fams, ibdrel_path=None, id_dict=None, keep=None, sparse_thresh=0.05)[source]
snipar.pgs.npg_am_adj(r, n)[source]
snipar.pgs.opg_am_adj(pgi_imp, pgi_obs, r, n)[source]
class snipar.pgs.pgarray(garray, ids, sid=None, alleles=None, pos=None, chrom=None, map=None, error_probs=None, fams=None, par_status=None, ped=None)[source]

Bases: gtarray

add(garray)[source]

Adds another gtarray of the same dimension to this array and returns the sum. It matches IDs before summing.

am_adj()[source]
compute_grandpar(r)[source]
estimate_r(return_se=True, parents_only=False)[source]
filter_bpg()[source]
scale(sf=None)[source]

This normalises the SNPs/PGS columns to have variance 1.

write(filename, scale=False)[source]
class snipar.pgs.pgs(snp_ids, weights, alleles)[source]

Bases: object

Define a polygenic score based on a set of SNPs with weights and ref/alt allele pairs.

Args:
snp_idsarray

[L] vector of SNP ids

weightsarray

[L] vector of weights of equal length to snp_ids

allelesarray

[L x 2] matrix of ref and alt alleles for the SNPs. L must match size of snp_ids

Returns:

pgs : snipar.pgs

compute(garray, cols=None)[source]

Compute polygenic score values from a given genotype array. Finds the SNPs in the genotype array that have weights in the pgs and matching alleles, and computes the PGS based on these SNPs and the weights after allele-matching.

Args:
garraysbreg.gtarray

genotype array to compute PGS values for

colsnumpy:numpy.array

names to give the columns in the output gtarray

Returns:
pgsnipar.gtarray

2d gtarray with PGS values. If a 3d gtarray is input, then each column corresponds to the second dimension on the input gtarray (for example, individual, paternal, maternal PGS). If a 2d gtarray is input, then there will be only one column in the output gtarray. The names given in ‘cols’ are stored in ‘sid’ attribute of the output.

remove_zeros()[source]
snipar.pgs.pgs_cor_lik(r, *args)[source]
snipar.pgs.pgs_corr_likelihood(r, pgs_fam, is_sib, is_parent)[source]
snipar.pgs.pgs_corr_likelihood_fam(r, pg_fam, is_sib_fam, is_parent_fam)[source]
snipar.pgs.pgs_corr_matrix(r, is_sib_fam, is_parent_fam)[source]
snipar.pgs.read_pgs(pgs_file)[source]
snipar.pgs.read_weights(weights, SNP='SNP', beta_col='b', A1='A1', A2='A2', sep=None)[source]
snipar.pgs.simulate_r_inf(r, nfam, nsib, npar)[source]
snipar.pgs.write_2gen_adj_ests(estimates, ses, outprefix='')[source]
snipar.pgs.write_estimates(outprefix, alpha, cols)[source]