Skip to content

Package — Reference data

Reference download and path resolution (gl.download_ref, gl.get_path, …).

download_ref

Download a reference file based on its identifier from reference.json.

Parameters:

Name Type Description Default
name str

Reference file identifier

required

Returns:

Type Description
str or None

Local path where the file was saved, or None if download failed

get_path

Retrieve the local file path for a specified reference file using keywords.

Returns the file path if found, otherwise False (or raises if raise_on_missing).

check_format

Check the header conversion dictionary between a given format and GWASLab format.

Parameters:

Name Type Description Default
fmt str

Format name to check

required
log Log

Logger instance

required

Returns:

Type Description
Dict[str, str]

Dictionary mapping format headers to GWASLab headers

download_sumstats

Download GWAS Catalog summary statistics for a given GCST accession.

Parameters:

Name Type Description Default
gcst_id str

GWAS Catalog study accession (e.g. "GCST90002446").

required
output_dir str

Directory to store downloaded file. If None, uses the GWASLab default data directory from options.paths["data_directory"]. Files are then stored under <output_dir>/<GCST_ID>/.

required
directory str

Alias for output_dir.

required
filename str

Output filename. If None, defaults to "{GCST}_sumstats.tsv.gz".

required
harmonised bool

If True, prioritize harmonised files. If harmonised files are not available, fall back to raw files. If False, select raw files directly (default: True).

required
timeout int

HTTP request timeout in seconds (default: 60).

required
chunk_size int

Download chunk size in bytes (default: 1MB).

required
overwrite bool

Whether to overwrite existing output file (default: False).

required
verbose bool

Whether to print log messages (default: True).

required
log Log

Logger object. If None, a new logger is created.

required

Returns:

Type Description
str

Absolute path of downloaded file.

Raises:

Type Description
ValueError
If GCST ID format is invalid.

RuntimeError If no downloadable summary statistics URL can be found. requests.exceptions.RequestException If the download request fails.

get_power

Calculate statistical power for genetic association studies.

Parameters:

Name Type Description Default
mode (b, q)

Calculation mode: - 'b' for binary traits (case-control) - 'q' for quantitative traits

'b'
genotype_rr float

Genotype relative risk (GRR) for risk allele for binary traits

required
genotype_or float

Genotype odds ratio (OR) for risk allele for binary traits

required
beta float

Effect size (log scale) for quantitative traits

required
eaf float

Effect allele frequency for quantitative traits

required
n int

Total sample size for quantitative traits

required
ncase int

Number of cases for binary mode

required
ncontrol int

Number of controls for binary mode

required
prevalence float

Disease prevalence in population

required
or_to_rr bool

Convert OR to GRR using prevalence (Zhang & Kai method)

required
daf float

Derived allele frequency

required
sig_level float

Significance threshold (default: 5e-8)

required
vary float

Phenotype variance for quantitative traits

required

Returns:

Type Description
float or array - like

Calculated statistical power (0-1)

References
Skol, A. D., Scott, L. J., Abecasis, G. R., & Boehnke, M. (2006). 
Joint analysis is more efficient than replication-based analysis 
for two-stage genome-wide association studies. Nature genetics, 38(2), 209-213.

Zhang, J., & Kai, F. Y. (1998). What's the relative risk? 
A method of correcting the odds ratio in cohort studies of common outcomes. 
Jama, 280(19), 1690-1691.