graphld.clumping¶
LD clumping for identifying independent variants.
LD clumping identifies independent index variants by iteratively selecting the variant with the highest χ² statistic and pruning all variants in high LD with it. Clumping + thresholding is a popular (though suboptimal) way of computing polygenic scores.
For usage examples, see the LD Clumping guide.
clumping
¶
LD clumping implementation using ParallelProcessor framework.
LDClumper
¶
Bases: ParallelProcessor
Fast LD clumping to find unlinked lead SNPs from GWAS summary statistics.
prepare_block_data
classmethod
¶
Split summary statistics into blocks whose positions match the LDGMs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
DataFrame
|
DataFrame containing LDGM metadata |
required |
**kwargs
|
Any
|
Additional arguments from run(), including: sumstats: DataFrame containing summary statistics |
{}
|
Returns:
| Type | Description |
|---|---|
list[tuple]
|
List of block-specific sumstats DataFrames and their offsets |
Source code in src/graphld/clumping.py
create_shared_memory
staticmethod
¶
Create output array with length number of variants in the summary statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
DataFrame
|
Metadata DataFrame containing block information |
required |
block_data
|
list[tuple]
|
List of block-specific sumstats DataFrames |
required |
**kwargs
|
Any
|
Not used |
{}
|
Returns:
| Type | Description |
|---|---|
SharedData
|
SharedData containing arrays for clumping results |
Source code in src/graphld/clumping.py
process_block
classmethod
¶
process_block(ldgm: PrecisionOperator, flag: Value, shared_data: SharedData, block_offset: int, block_data: tuple, worker_params: tuple) -> None
Process single block for LD clumping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ldgm
|
PrecisionOperator
|
LDGM object |
required |
flag
|
Value
|
Worker flag |
required |
shared_data
|
SharedData
|
Dictionary-like shared data object |
required |
block_offset
|
int
|
Offset for this block |
required |
block_data
|
tuple
|
Tuple of (sumstats DataFrame, variant_offset) |
required |
worker_params
|
tuple
|
Tuple of (rsq_threshold, chisq_threshold, z_col, match_by_position, variant_id_col) |
required |
Source code in src/graphld/clumping.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
supervise
classmethod
¶
supervise(manager: Union[WorkerManager, SerialManager], shared_data: SharedData, block_data: list, **kwargs: Any) -> pl.DataFrame
Monitor workers and process results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manager
|
Union[WorkerManager, SerialManager]
|
Worker manager for controlling processes |
required |
shared_data
|
SharedData
|
Shared memory data |
required |
block_data
|
list
|
List of block-specific data |
required |
**kwargs
|
Any
|
Additional arguments passed from run() |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with clumping results |
Source code in src/graphld/clumping.py
clump
classmethod
¶
clump(sumstats: DataFrame, ldgm_metadata_path: str = 'data/ldgms/metadata.csv', rsq_threshold: float = 0.1, chisq_threshold: float = 30.0, populations: Optional[Union[str, List[str]]] = None, chromosomes: Optional[Union[int, List[int]]] = None, run_in_serial: bool = False, num_processes: Optional[int] = None, z_col: str = 'Z', match_by_position: bool = True, variant_id_col: str = 'SNP', verbose: bool = False) -> pl.DataFrame
Perform LD clumping on summary statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sumstats
|
DataFrame
|
Summary statistics DataFrame containing Z scores |
required |
ldgm_metadata_path
|
str
|
Path to metadata CSV file (default 'data/ldgms/metadata.csv') |
'data/ldgms/metadata.csv'
|
rsq_threshold
|
float
|
r² threshold for clumping (default 0.1) |
0.1
|
chisq_threshold
|
float
|
χ² threshold for significance (default 30.0) |
30.0
|
populations
|
Optional[Union[str, List[str]]]
|
Optional population name(s) |
None
|
chromosomes
|
Optional[Union[int, List[int]]]
|
Optional chromosome(s) |
None
|
run_in_serial
|
bool
|
Whether to run in serial mode |
False
|
num_processes
|
Optional[int]
|
Optional number of processes |
None
|
z_col
|
str
|
Name of column containing Z scores |
'Z'
|
match_by_position
|
bool
|
Whether to match SNPs by position instead of ID |
True
|
variant_id_col
|
str
|
Name of column containing variant IDs if not matching by position |
'SNP'
|
verbose
|
bool
|
Whether to print progress information |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Input DataFrame in its original row order with an additional boolean |
DataFrame
|
'is_index' column indicating index variants. Variants outside the |
DataFrame
|
selected LDGM blocks, unmatched variants, and allele-mismatched |
DataFrame
|
variants are retained with 'is_index=False'. |
Source code in src/graphld/clumping.py
run_clump
¶
Perform LD-based clumping on summary statistics.
Positional and keyword arguments are forwarded to :meth:LDClumper.clump.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments for :meth: |
()
|
**kwargs
|
Any
|
Keyword arguments for :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Input DataFrame in its original row order with an additional boolean |
DataFrame
|
'is_index' column. Variants outside the selected LDGM blocks, |
DataFrame
|
unmatched variants, and allele-mismatched variants are retained with |
DataFrame
|
'is_index=False'. |