numerics
advance1D(u, P)
tridiag breakdown for integration along the diagonal boundary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
density along that diagonal |
required | |
P
|
array
|
transition matrix |
required |
Source code in dadi/Triallele/numerics.py
423 424 425 426 427 428 429 430 431 432 433 434 435 | |
advance_adi(U, U01, P1, P2, x, ii)
Integrate the ADI components forward in time, alternating which direction occurs first
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
U
|
array - like
|
density function |
required |
U01
|
array - like
|
stores which points are in the domain |
required |
P1
|
array
|
transition matrix |
required |
P2
|
array
|
transition matrix |
required |
x
|
array - like
|
grid |
required |
ii
|
int
|
count of integration step |
required |
Source code in dadi/Triallele/numerics.py
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 | |
advance_cov(U, C, x, dx)
Explicit integration of the covariance term, using scipy's sparse matrix for C
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
U
|
array - like
|
density function |
required |
C
|
array - like
|
transition matrix |
required |
x
|
array - like
|
grid |
required |
dx
|
array - like
|
grid spacing |
required |
Returns:
| Name | Type | Description |
|---|---|---|
U |
array - like
|
updated density function |
Source code in dadi/Triallele/numerics.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
advance_line(x, phi, P)
Integrate along the diagonal boundary. Density gets fixed along the boundary, and then diffuses along that boundary until being fixed in one of the two corners
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array - like
|
grid |
required |
phi
|
array - like
|
density function |
required |
P
|
array
|
one dimensional transition matrix for the diagonal boundary |
required |
Source code in dadi/Triallele/numerics.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
bivariate_lognormal_pdf(xx, params)
mu_i = mu_yi and sigma_i = sigma_yi are the associated means and variances of the bivariate normal distr which gets exponentiated. We assume for our application that mu1=mu2 and sigma1=sigma2, though this isn't necessary for the general bivariate lognormal distribution.
Source code in dadi/Triallele/numerics.py
550 551 552 553 554 555 556 557 558 559 560 | |
cached_projection(proj_to, proj_from, hits)
Coefficients for projection from a larger size to smaller
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proj_to
|
int
|
Number of samples to project down to |
required |
proj_from
|
int
|
Number of samples to project from |
required |
hits
|
int
|
Number of derived alleles projecting from - tuple of (n1,n3) |
required |
Source code in dadi/Triallele/numerics.py
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 | |
domain(x)
Constructs a matrix with the same dimension as the density function discretization, a 1 indicates that the corresponding point is inside the triangular domain or on the boundary, while a 0 indicates that point falls outside the domain
Source code in dadi/Triallele/numerics.py
43 44 45 46 47 48 49 50 51 | |
fold(spectrum)
Note
This is now handled in the TriSpectrum class
Given a frequency spectrum over the full domain, fold into a spectrum with major and minor derived alleles
Source code in dadi/Triallele/numerics.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | |
fold_ancestral(F)
Note
This is now handled by the TriSpectrum class.
Don't know ancestral state, so track minor frequencies. Store spectrum of two minor allele frequencies.
Source code in dadi/Triallele/numerics.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
grid_dx(x)
We use uniform grids in x, using np.linspace(0,1,numpts) Grid spacing Delta, which is halved at the first and last grid points.
Source code in dadi/Triallele/numerics.py
16 17 18 19 20 21 | |
grid_dx_2d(x, dx)
The two dimensional grid spacing over the domain. Grid points lie along the diagonal boundary, and Delta for those points is halved
Source code in dadi/Triallele/numerics.py
23 24 25 26 27 28 29 30 31 | |
int2(DXX, U)
Integrate the density function over the domain
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
DXX
|
array - like
|
two dimensional grid |
required |
U
|
density function |
required |
Source code in dadi/Triallele/numerics.py
33 34 35 36 37 38 39 40 41 | |
misidentification(F, p)
Given folded spectrum, and probability p that one of the derived alleles is the actual ancestral allele Then refold to return folded spectrum
Source code in dadi/Triallele/numerics.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
move_density_to_bdry(x, phi, P)
P tells us how much should be removed, by multiplying phi*P Take that density and instead of deleting it, move straight to boundary P - stores how much denstity from each grid point should be moved to diagonal
Source code in dadi/Triallele/numerics.py
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 | |
ms_demo_params_to_dadi(nu_ms, tau_ms)
convert from ms parameters (which use current pop size) for nu and tau to dadi parameters (which use ancestral pop size)
Source code in dadi/Triallele/numerics.py
562 563 564 565 566 | |
remove_diag_density_weights_nonneutral(x, dt, nu, sig1, sig2)
Numerically determine the amount of density that should be lost to the diagonal boundary. Numerically integrate 1D array with initial point mass at z0, where z0 is the frequency x+y, integrated for time step dt. We then check the fraction of density that is lost to z=1. If sig1 or sig2 are nonzero, estimate the selection pressure on z as sig = sig1x/(x+y) + sig2y/(x+y)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array - like
|
grid. |
required |
dt
|
float
|
time step for integration. |
required |
nu
|
float
|
population size scaling factor. |
required |
sig1
|
float
|
population scaled selection coefficient for the first derived allele. |
required |
sig2
|
float
|
population scaled selection coefficients for the second derived allele. |
required |
Source code in dadi/Triallele/numerics.py
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 | |
sample(phi, ns, x)
Obtain the expected sample frequency spectrum from the density function
Source code in dadi/Triallele/numerics.py
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 | |
trinomial(ns, ii, jj)
Return ns!/(ii! * jj! * (ns-ii-jj)!) for large values
Source code in dadi/Triallele/numerics.py
498 499 500 501 502 | |
univariate_lognormal_pdf(x, sigma, mu)
Can compare to scipy.stats.lognorm.pdf(x,sigma,0,np.exp(mu))
Source code in dadi/Triallele/numerics.py
544 545 546 547 548 | |