graphld.blup¶
Best Linear Unbiased Prediction (BLUP) for effect size estimation.
Under the infinitesimal model with per-s.d. effect sizes $\beta \sim N(0, D)$, the BLUP effect sizes are:
$$E(\beta) = \sqrt{n} D (nD + R^{-1})^{-1} R^{-1}z$$
where $R^{-1}$ is approximated with the LDGM precision matrix. Public BLUP workflows take heritability for the analyzed variant scope and set $\mathrm{trace}(D)$ equal to that value across matched LDGM effect indices.
For usage examples, see the BLUP guide.
blup
¶
BLUP
¶
Bases: ParallelProcessor
Computes the best linear unbiased predictor using LDGMs and 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 tuples containing a block-specific summary-statistics |
list[tuple]
|
DataFrame and its offset in the concatenated output. |
Source code in src/graphld/blup.py
create_shared_memory
staticmethod
¶
Create the BLUP output array for partitioned summary statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
DataFrame
|
Metadata DataFrame containing block information |
required |
block_data
|
list[tuple]
|
List of block-specific summary-statistics DataFrames and offsets |
required |
**kwargs
|
Any
|
Not used |
{}
|
Returns:
| Type | Description |
|---|---|
SharedData
|
SharedData containing the BLUP weight array. |
Source code in src/graphld/blup.py
process_block
classmethod
¶
process_block(ldgm: PrecisionOperator, flag: Value, shared_data: SharedData, block_offset: int, block_data: tuple, worker_params: tuple) -> None
Run BLUP on a single block.
Source code in src/graphld/blup.py
supervise
classmethod
¶
supervise(manager: WorkerManager, shared_data: Dict[str, Any], block_data: list, **kwargs: Any) -> pl.DataFrame
Supervise worker processes and collect results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manager
|
WorkerManager
|
Worker manager |
required |
shared_data
|
Dict[str, Any]
|
Dictionary of shared memory arrays |
required |
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing summary statistics with BLUP weights |
Source code in src/graphld/blup.py
compute_blup
classmethod
¶
compute_blup(ldgm_metadata_path: str, sumstats: DataFrame, heritability: Optional[float] = None, sample_size: Optional[float] = None, populations: Optional[Union[str, List[str]]] = None, chromosomes: Optional[Union[int, List[int]]] = None, num_processes: Optional[int] = None, run_in_serial: bool = False, match_by_position: bool = False, verbose: bool = False, sigmasq: Optional[float] = None) -> pl.DataFrame
Compute BLUP weights for multiple LD blocks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ldgm_metadata_path
|
str
|
Path to metadata CSV file |
required |
sumstats
|
DataFrame
|
Summary-statistics DataFrame containing Z scores |
required |
heritability
|
Optional[float]
|
Heritability for the analyzed variant scope. Internally, BLUP uses D = (heritability / m) I, where m is the number of unique matched LDGM effect indices. |
None
|
sample_size
|
Optional[float]
|
GWAS sample size |
None
|
populations
|
Optional[Union[str, List[str]]]
|
Optional population name(s) |
None
|
chromosomes
|
Optional[Union[int, List[int]]]
|
Optional chromosome or list of chromosomes |
None
|
num_processes
|
Optional[int]
|
Optional number of processes |
None
|
run_in_serial
|
bool
|
Whether to run in serial mode |
False
|
match_by_position
|
bool
|
Whether to match variants by position instead of ID |
False
|
verbose
|
bool
|
Print additional information if True |
False
|
sigmasq
|
Optional[float]
|
Removed compatibility keyword. Passing it raises ValueError. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with BLUP weights added to the partitioned summary statistics. |
Source code in src/graphld/blup.py
run_blup
¶
Compute Best Linear Unbiased Prediction (BLUP) weights.
Positional and keyword arguments are forwarded to :meth:BLUP.compute_blup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments for :meth: |
()
|
**kwargs
|
Any
|
Keyword arguments for :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with BLUP weights and associated statistics. |