Individual-level inference¶
Classes and functions for fine-mapping individual-level data.
infer
¶
Prior
¶
Define the class for the prior parameter of SuShiE model.
Attributes:
| Name | Type | Description |
|---|---|---|
pi |
Array
|
The prior probability for one SNP to be causal. |
resid_var |
Array
|
The prior residual variance for all SNPs. |
effect_covar |
Array
|
The prior effect sizes covariance matrix for all SNPs. |
Posterior
¶
Define the class for the posterior parameter of SuShiE model.
Attributes:
| Name | Type | Description |
|---|---|---|
alpha |
Array
|
Posterior probability for SNP to be causal (i.e., \(\alpha\) in model description; \(L \times p\)). |
post_mean |
Array
|
The alpha-weighted posterior mean for each SNP (\(L \times p \times k\)). |
post_mean_sq |
Array
|
The alpha-weighted posterior mean square for each SNP (\(L \times p \times k \times k\) , a diagonal matrix for \(k \times k\)). |
weighted_sum_covar |
Array
|
The alpha-weighted sum of posterior effect covariance across SNPs (\(L \times k \times k\)). |
kl |
Array
|
The Kullback–Leibler (KL) divergence for each \(L\). |
log_bf |
Array
|
The log Bayes factor for each SNP (\(L \times p\)). |
SushieResult
¶
Define the class for the SuShiE inference results.
Attributes:
| Name | Type | Description |
|---|---|---|
priors |
Prior
|
The final prior parameter for the inference. |
posteriors |
Posterior
|
The final posterior parameter for the inference. |
pip_all |
Array
|
The PIP for each SNP across \(L\) credible sets. |
pip_cs |
Array
|
The PIP across credible sets that are not pruned. |
cs |
DataFrame
|
The credible sets output after filtering on purity. |
alphas |
DataFrame
|
The full credible sets before filtering on purity. |
sample_size |
Array
|
The sample size for each ancestry in the inference. |
elbo |
Array
|
The final ELBO. |
elbo_increase |
bool
|
A boolean to indicate whether ELBO increases during the optimizations. |
l_order |
Array
|
The original order that SuShiE infers. For example, if L=3 and it is 0,2,1, then the original SuShiE's second effect (0-based index 1) is now third, and the original SuShiE's third effect (0-based index 2) is now second after sorting use Frobenius norm. |
_PriorAdjustor
¶
_AbstractOptFunc
¶
_NoopOptFunc
¶
_EMOptFunc
¶
infer_sushie
¶
infer_sushie(
Xs: Sequence[ArrayLike],
ys: Sequence[ArrayLike],
covar: Sequence[ArrayLike] | None = None,
L: int = 10,
no_scale: bool = False,
no_regress: bool = False,
no_update: bool = False,
pi: ArrayLike | None = None,
resid_var: ListFloatOrNone = None,
effect_var: ListFloatOrNone = None,
rho: ListFloatOrNone = None,
max_iter: int = 500,
min_tol: float = 0.0001,
threshold: float = 0.95,
purity: float = 0.5,
purity_method: str = "weighted",
max_select: int = 250,
min_snps: int = 100,
no_reorder: bool = False,
seed: int = 12345,
) -> SushieResult
The main inference function for running SuShiE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Xs
|
Sequence[ArrayLike]
|
Genotype data for multiple ancestries. |
required |
ys
|
Sequence[ArrayLike]
|
Phenotype data for multiple ancestries. |
required |
covar
|
Sequence[ArrayLike] | None
|
Covariate data for multiple ancestries. |
None
|
L
|
int
|
Inferred number of eQTLs for the gene. |
10
|
no_scale
|
bool
|
Do not scale the genotype and phenotype. Default is to scale. |
False
|
no_regress
|
bool
|
Do not regress covariates on genotypes. Default is to regress. |
False
|
no_update
|
bool
|
Do not update the effect size prior. Default is to update. |
False
|
pi
|
ArrayLike | None
|
The probability prior for one SNP to be causal (\(\pi\) in model description).
Default is \(1\) over the number of SNPs by specifying it as |
None
|
resid_var
|
ListFloatOrNone
|
Prior residual variance (\(\sigma^2_e\) in model description).
Default is \(0.001\) by specifying it as |
None
|
effect_var
|
ListFloatOrNone
|
Prior causal effect size variance (\(\sigma^2_{i,b}\) in model description).
Default is \(0.001\) by specifying it as |
None
|
rho
|
ListFloatOrNone
|
Prior effect size correlation (\(\rho\) in model description).
Default is \(0.1\) by specifying it as |
None
|
max_iter
|
int
|
The maximum iteration for optimization. Default is \(500\). |
500
|
min_tol
|
float
|
The convergence tolerance. Default is \(10^{-4}\). |
0.0001
|
threshold
|
float
|
The credible set threshold. Default is \(0.95\). |
0.95
|
purity
|
float
|
The minimum pairwise correlation across SNPs to be eligible as output credible set. Default is \(0.5\). |
0.5
|
purity_method
|
str
|
The method to compute purity across ancestries. Default is |
'weighted'
|
max_select
|
int
|
The maximum number of selected SNPs to compute purity. Default is \(250\). |
250
|
min_snps
|
int
|
The minimum number of SNPs to fine-map. Default is \(100\). |
100
|
no_reorder
|
bool
|
Do not re-order single effects based on Frobenius norm of effect size covariance prior. Default is to re-order. |
False
|
seed
|
int
|
The randomization seed for selecting SNPs in the credible set to compute purity. Default is \(12345\). |
12345
|
Returns:
| Type | Description |
|---|---|
SushieResult
|
|
SushieResult
|
posterior ( |
Example
Basic usage with two-ancestry data:
import numpy as np
from sushie.infer import infer_sushie
# Generate example data for 2 ancestries
# Ancestry 1: 100 samples, 500 SNPs
X1 = np.random.randn(100, 500)
y1 = np.random.randn(100)
# Ancestry 2: 150 samples, 500 SNPs
X2 = np.random.randn(150, 500)
y2 = np.random.randn(150)
# Run SuShiE fine-mapping
result = infer_sushie(Xs=[X1, X2], ys=[y1, y2], L=5)
# Access results
print(result.pip_all) # Posterior inclusion probabilities
print(result.cs) # Credible sets
Source code in sushie/infer.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
make_cs
¶
make_cs(
alpha: ArrayLike,
log_bf: ArrayLike,
ns: ArrayLike,
Xs: ArrayLike | None = None,
lds: ArrayLike | None = None,
threshold: float = 0.9,
purity: float = 0.5,
purity_method: str = "weighted",
max_select: int = 500,
seed: int = 12345,
) -> tuple[DataFrame, DataFrame, Array, Array]
The function to compute the credible sets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
ArrayLike
|
\(L \times p\) matrix that contains posterior probability for SNP to be causal (i.e., \(\alpha\) in model description). |
required |
log_bf
|
ArrayLike
|
\(L \times p\) matrix that contains log Bayes factor for each SNP in each effect. |
required |
Xs
|
ArrayLike | None
|
Genotype data for multiple ancestries. It cannot be None if lds is None. |
None
|
lds
|
ArrayLike | None
|
LD matrix for multiple ancestries. It cannot be None if Xs is None. |
None
|
ns
|
ArrayLike
|
Sample size for each ancestry. |
required |
threshold
|
float
|
The credible set threshold. |
0.9
|
purity
|
float
|
The minimum pairwise correlation across SNPs to be eligible as output credible set. |
0.5
|
purity_method
|
str
|
The method to compute purity across ancestries. |
'weighted'
|
max_select
|
int
|
The maximum number of selected SNPs to compute purity. |
500
|
seed
|
int
|
The randomization seed for selecting SNPs in the credible set to compute purity. |
12345
|
Returns:
| Type | Description |
|---|---|
tuple[DataFrame, DataFrame, Array, Array]
|
|
Example
Compute credible sets from a SuShiE posterior:
import numpy as np
from sushie.infer import infer_sushie, make_cs
X1 = np.random.randn(100, 500)
X2 = np.random.randn(150, 500)
y1 = np.random.randn(100)
y2 = np.random.randn(150)
result = infer_sushie(Xs=[X1, X2], ys=[y1, y2], L=5)
cs, full_cs, pip_all, pip_cs = make_cs(
alpha=result.posteriors.alpha,
log_bf=result.posteriors.log_bf,
ns=np.array([X1.shape[0], X2.shape[0]]),
Xs=[X1, X2],
threshold=0.9,
purity=0.5,
)
Source code in sushie/infer.py
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 | |
_compute_posterior
¶
_compute_posterior(
rTZDinv: Array,
inv_shat2: Array,
priors: Prior,
posteriors: Posterior,
l_iter: int,
) -> tuple[Prior, Posterior]