Skip to content

Package — I/O

Reading and writing auxiliary files (LDSC logs, pickles, tabular formats).

read_ldsc

Read LDSC output files and parse heritability or genetic correlation results.

Parameters:

Name Type Description Default
filelist list of str

List of paths to LDSC output files

None
mode str

Mode to parse: "h2" for heritability, "rg" for genetic correlation

"h2"

Returns:

Type Description
DataFrame

Parsed LDSC results

load_pickle

Load a previously saved GWASLab object from a pickle file.

Automatically detects and loads Sumstats, SumstatsPair, or SumstatsMulti objects.

Parameters:

Name Type Description Default
path str

File path to the pickle file. Supports ~ for home directory expansion.

required

Returns:

Type Description
Optional[Union[Sumstats, SumstatsPair, SumstatsMulti]]

The loaded GWASLab object (type is automatically detected). Returns None if the file does not exist.

dump_pickle

load_gsf

Load GWAS sumstats from GSF (GWASLab Standard Format) file.

Parameters:

Name Type Description Default
path str or Path

Path to .gsf file or directory (for partitioned)

required
columns list of str

Columns to read (None = all columns)

None
filters str

Filter string for predicate pushdown. Supports: - Operators: ==, !=, <, <=, >, >=, in - Logical operators: & (AND), | (OR) Examples "P < 5e-8" "CHR == 1" "P < 5e-8 & CHR == 1" "CHR in [1, 2, 3]" "P < 5e-8 | P > 0.99"

None
verbose bool

Print progress messages

True

Returns:

Type Description
Sumstats

GWASLab Sumstats object

Examples:

>>> mysumstats = gl.load_gsf("sumstats.gsf")
>>> mysumstats = gl.load_gsf("sumstats.gsf", columns=["CHR", "POS", "BETA", "P"])
>>> mysumstats = gl.load_gsf("sumstats.gsf", filters="CHR == 1")
>>> mysumstats = gl.load_gsf("sumstats.gsf", filters="P < 5e-8 & CHR == 1")
>>> mysumstats = gl.load_gsf("sumstats.gsf", filters="CHR in [1, 2, 3]")

read_gtf

Fast GTF file reader using Polars.

Returns a pandas DataFrame for compatibility.

Parameters:

Name Type Description Default
filepath_or_buffer str or buffer

Path to GTF file (may be gzip compressed) or buffer object

required
usecols list of str or None

Restrict which columns are loaded. If None, load all columns. Common columns: seqname, start, end, strand, feature, gene_biotype, gene_id, gene_name

None
features set of str or None

Drop rows which aren't one of the features in the supplied set (e.g., {'gene', 'transcript', 'exon'})

None
chrom str or None

Filter by chromosome/seqname early for speed. If None, load all chromosomes. Can be chromosome number (e.g., "1", "23" for X) or name (e.g., "X", "chr1"). For X chromosome, can use "X", "chrX", or "23". For Y chromosome, can use "Y", "chrY", or "24". For MT chromosome, can use "MT", "chrMT", "M", "chrM", or "25".

None
expand_attribute_column bool

Expand the 'attribute' column into separate columns (default: True)

True
infer_biotype_column bool

Infer biotype from 'source' column if gene_biotype/transcript_biotype missing

False

Returns:

Type Description
DataFrame

DataFrame containing parsed GTF data

read_bed

Read a BED file into a pandas DataFrame.

BED files use 0-based, half-open intervals [chromStart, chromEnd).
The chromEnd position is exclusive (not included in the feature).

Parameters:

Name Type Description Default
bed_path str

Path to BED file. Supports uncompressed (.bed) and gzipped (.bed.gz) files.

required
usecols list of int

Column indices to read (0-based). If None, reads all columns. Default columns: chrom (0), chromStart (1), chromEnd (2), and optional fields.

None
header bool

Whether the file has a header line. BED files typically don't have headers, but custom tracks may have "browser" or "track" lines. If None, auto-detects by checking for "browser" or "track" lines.

None
comment str

Character(s) that indicate comment lines to skip. Default is "#". BED custom tracks may have "browser" or "track" header lines.

None
verbose bool

If True, prints information about the file being read.

False
log Log

Logger instance for messages.

None

Returns:

Type Description
DataFrame

DataFrame with BED data. Column names depend on number of columns: - BED3: chrom, chromStart, chromEnd - BED4+: chrom, chromStart, chromEnd, name, ... Columns are named according to BED specification.

Notes
BED format specification:
- chrom: Chromosome name (e.g., chr1, chrX, 1, X)
- chromStart: Starting position (0-based)
- chromEnd: Ending position (1-based, exclusive)
- Optional fields follow the standard BED12 format

Coordinate system:
- BED uses 0-based, half-open intervals [chromStart, chromEnd)
- For example, chromStart=0, chromEnd=100 spans bases 0-99
- In 1-based coordinates, this corresponds to positions 1-100
References
UCSC BED format: https://genome.ucsc.edu/FAQ/FAQformat.html#format1