Sumstats — Filter
Variant subsetting and region extraction.
filter_value
filter_value(expr: str, inplace: bool = False, **kwargs: Any) -> typing.Optional[ForwardRef(Sumstats)]
Filter variants based on a query expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sumstats_obj
|
Sumstats
|
Sumstats object containing the data to filter. |
required |
expr
|
str
|
Query expression using pandas.DataFrame.query syntax |
required |
remove
|
bool
|
If True, removes variants meeting the condition |
False
|
verbose
|
bool
|
If True, writes progress to log |
True
|
inplace
|
bool
|
If False, return a new |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Filtered summary statistics table.
When called via :meth: |
filter_in
Filter in variants based on threshold values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sumstats_obj
|
Sumstats
|
Sumstats object containing the data to filter. |
required |
lt
|
dict
|
Dictionary of {column: threshold} for lower bounds (variant values < threshold will be kept) |
{}
|
gt
|
dict
|
Dictionary of {column: threshold} for upper bounds (variant values > threshold will be kept) |
{}
|
eq
|
dict
|
Dictionary of {column: value} for equality checks (variant values == value will be kept) |
{}
|
remove
|
bool
|
If True, removes variants meeting the condition |
False
|
verbose
|
bool
|
If True, writes progress to log |
True
|
inplace
|
bool
|
If False, return a new |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Filtered summary statistics table.
When called via :meth: |
filter_out
Filter out variants based on threshold values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sumstats_obj
|
Sumstats
|
Sumstats object containing the data to filter. |
required |
lt
|
dict
|
Dictionary of {column: threshold} for lower bounds (variant values < threshold will be removed) |
{}
|
gt
|
dict
|
Dictionary of {column: threshold} for upper bounds (variant values > threshold will be removed) |
{}
|
eq
|
dict
|
Dictionary of {column: value} for equality checks (variant values == value will be removed) |
{}
|
remove
|
bool
|
If True, removes variants meeting the condition |
False
|
verbose
|
bool
|
If True, writes progress to log |
True
|
inplace
|
bool
|
If False, return a new |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Filtered summary statistics table |
filter_region
Filter variants within a specific genomic region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sumstats_or_dataframe
|
Sumstats or DataFrame
|
Sumstats object or DataFrame to process. |
required |
region
|
List, str, or None
|
Genomic region to filter. Can be: - List/tuple [chr, start, end]: Specific genomic region coordinates - String formats (normalized automatically): - "chr:start-end" (e.g., "chr1:1000-5000") - "chr:pos:flanking" (e.g., "1:5000:2000" or "1:5000:2kb") - "snpid:flanking" (e.g., "rs123:500" or "1:5000:C:T:2000") - Special strings: - "HLA": Filter variants in HLA region (excludes HLA) - "HIGH_LD": Filter variants in high LD regions (excludes high LD) - "PAR": Filter variants in pseudo-autosomal regions (excludes PAR) |
None
|
chrom
|
str
|
Column name for chromosome information |
"CHR"
|
pos
|
str
|
Column name for position information |
"POS"
|
build
|
str
|
Genome build version (19 or 38) for HLA/HIGH_LD/PAR regions |
"19"
|
verbose
|
bool
|
If True, writes progress to log |
True
|
log
|
Log
|
Logger instance |
Log()
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Subset of summary statistics in the specified region (or with specified regions excluded).
When called via :meth: |
filter_region_in
Keep variants located within specified genomic regions from a BED file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sumstats_or_dataframe
|
Sumstats or DataFrame
|
Sumstats object or DataFrame to process. |
required |
path
|
str or None
|
Path to BED file containing regions of interest |
None
|
chrom
|
str
|
Column name for chromosome information |
"CHR"
|
pos
|
str
|
Column name for position information |
"POS"
|
high_ld
|
bool
|
If True, uses high LD regions from the specified build |
False
|
build
|
str
|
Genome build version (19 or 38) for high LD regions |
"19"
|
verbose
|
bool
|
If True, writes progress to log |
True
|
log
|
Log
|
Logger instance |
Log()
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Filtered summary statistics table containing only variants in the specified regions.
When called via :meth: |
filter_region_out
Remove variants located within specified genomic regions from a BED file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sumstats_or_dataframe
|
Sumstats or DataFrame
|
Sumstats object or DataFrame to process. |
required |
path
|
str or None
|
Path to BED file containing regions to exclude |
None
|
chrom
|
str
|
Column name for chromosome information |
"CHR"
|
pos
|
str
|
Column name for position information |
"POS"
|
high_ld
|
bool
|
If True, excludes variants in high LD regions from the specified build |
False
|
build
|
str
|
Genome build version (19 or 38) for high LD regions |
"19"
|
verbose
|
bool
|
If True, writes progress to log |
True
|
log
|
Log
|
Logger instance |
Log()
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Filtered summary statistics table with variants in specified regions removed.
When called via :meth: |
filter_flanking
Extract variants in flanking regions around a specified variant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sumstats_or_dataframe
|
Sumstats or DataFrame
|
Sumstats object or DataFrame to process. |
required |
snpid
|
str
|
ID of the central variant (must exist in SNPID column) |
required |
windowsizekb
|
int
|
Size of flanking region in kilobases |
500
|
verbose
|
bool
|
If True, writes progress to log |
True
|
inplace
|
bool
|
If False, return a new |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Variants in flanking regions.
When called via :meth: |
filter_flanking_by_chrpos
filter_flanking_by_chrpos(chrpos: Tuple[int, int], inplace: bool = False, **kwargs: Any) -> typing.Optional[ForwardRef(Sumstats)]
Extract variants in flanking regions using chromosome and position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chrpos
|
list or list of lists
|
Chromosome and position coordinate(s) to use as center |
required |
Format
|
[chromosome, position]
|
|
required |
windowsizekb
|
int
|
Size of flanking region in kilobases |
500
|
verbose
|
bool
|
If True, writes progress to log |
True
|
inplace
|
bool
|
If False, return a new |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Variants in flanking regions.
When called via :meth: |
filter_flanking_by_id
filter_flanking_by_id(snpid: str, inplace: bool = False, **kwargs: Any) -> typing.Optional[ForwardRef(Sumstats)]
Extract variants in flanking regions using rsID or SNPID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sumstats_or_dataframe
|
Sumstats or DataFrame
|
Sumstats object or DataFrame to process. |
required |
snpid
|
str or list
|
Variant ID(s) to use as center (searches in rsID/SNPID columns) |
required |
windowsizekb
|
int
|
Size of flanking region in kilobases |
500
|
verbose
|
bool
|
If True, writes progress to log |
True
|
inplace
|
bool
|
If False, return a new |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Variants in flanking regions.
When called via :meth: |
filter_palindromic
Filter palindromic variants based on allele symmetry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
"in" to keep palindromic variants, "out" to remove them |
"in"
|
verbose
|
bool
|
If True, writes progress to log |
True
|
inplace
|
bool
|
If False, return a new |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Filtered summary statistics table.
When called via :meth: |
filter_snp
Filter SNPs based on allele length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
"in" to keep SNPs, "out" to remove SNPs |
"in"
|
verbose
|
bool
|
If True, writes progress to log |
True
|
inplace
|
bool
|
If False, return a new |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Filtered summary statistics table.
When called via :meth: |
filter_indel
Filter indels based on allele length differences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
"in" to keep indels, "out" to remove indels |
"in"
|
verbose
|
bool
|
If True, writes progress to log |
True
|
inplace
|
bool
|
If False, return a new |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Filtered summary statistics table.
When called via :meth: |
filter_hapmap3
Extract HapMap3 SNPs from summary statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sumstats_or_dataframe
|
Sumstats or DataFrame
|
Input summary statistics. |
required |
rsid
|
str
|
rsID column name. |
"rsID"
|
chrom
|
str
|
Chromosome column name. |
"CHR"
|
pos
|
str
|
Base-pair position column name. |
"POS"
|
ea
|
str
|
Effect allele column name. |
"EA"
|
nea
|
str
|
Non-effect allele column name. |
"NEA"
|
build
|
str
|
Genome build ( |
"19"
|
verbose
|
bool
|
Print progress messages. |
True
|
match_allele
|
bool
|
Require allele agreement with the HapMap3 reference. |
True
|
how
|
str
|
pandas merge type ( |
"inner"
|
log
|
Log
|
Logging object. |
Log()
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Rows matching HapMap3 variants. |
exclude_hla
Exclude variants in HLA regions based on genomic coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chrom
|
str
|
Column name for chromosome information |
"CHR"
|
pos
|
str
|
Column name for position information |
"POS"
|
lower
|
int or None
|
Lower bound of genomic region |
None
|
upper
|
int or None
|
Upper bound of genomic region |
None
|
build
|
str or None
|
Genome build version (19 or 38) |
None
|
mode
|
str
|
"xmhc" for extended MHC region, "hla" or "mhc" for classical HLA region |
"xmhc"
|
verbose
|
bool
|
If True, writes progress to log |
True
|
inplace
|
bool
|
If False, return a new |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Filtered summary statistics table with HLA variants removed.
When called via :meth: |
search
Search for variants in summary statistics using multiple identifier formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sumstats
|
DataFrame
|
GWAS summary statistics table |
required |
snplist
|
list or None
|
List of variant identifiers to search for. Accepts multiple formats: - CHR:POS (e.g., '1:123456') - CHR-POS (e.g., '1_123456') - rsID (e.g., 'rs12345') - SNPID (e.g., '1:123456:A:G') - List of [CHR, POS] - Full variant IDs with alleles (e.g., 'chr1:123456:A:G') |
None
|
verbose
|
bool
|
If True, writes progress to log |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Subset of summary statistics containing matching variants.
When called via :meth: |
Examples:
>>> variants = _search_variants(sumstats, snplist=["rs1234", "1:100500", [2, 202000], "19:45100000:C:T"])
>>> print(variants.shape)
random_variants
Randomly sample variants from summary statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of variants to sample |
1
|
p
|
float
|
Fraction of variants to sample (alternative to n) |
None
|
verbose
|
bool
|
If True, writes progress to log |
True
|
inplace
|
bool
|
If False, return a new |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Subsampled summary statistics table.
When called via :meth: |
get_proxy
Find LD proxies within the sumstats for SNPs in the list using a VCF reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snplist
|
list or None
|
List of full SNPIDs to find proxies for. |
required |
common_sumstats
|
Sumstats or DataFrame or None
|
Sumstats object or DataFrame with summary statistics for existing SNPs. |
required |
vcf_path
|
str or None
|
Path to the VCF file for reference genotypes. |
required |
verbose
|
bool
|
If True, write detailed logs. |
required |
windowsizekb
|
int
|
Size in kb for the flanking region around each SNP. |
required |
ld_threshold
|
float
|
Minimum R^2 value to consider a proxy valid. |
required |
include_all
|
bool
|
If True, include proxy variants from VCF that are not in common_sumstats. When False, only returns proxies that are already in common_sumstats. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Extracted summary statistics including matched proxies sorted by LD strength. |
Less used parametrs
vcf_chr_dict : dict or None Dictionary mapping chromosomes to VCF region strings. log : gwaslab.g_Log.Log Logging object. tabix : str or None Path to tabix executable.
get_region_start_and_end
Determine the [chr, start, end] for a region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chrom
|
str or int
|
Chromosome identifier. |
required |
pos
|
int or float or str
|
Base-pair position. |
required |
windowsizekb
|
int
|
Window size in kilobases. |
500
|
verbose
|
bool
|
Print log message. |
True
|
Returns:
| Type | Description |
|---|---|
list
|
[chrom, start, end], where start and end are base-pair coordinates (int). |