nbl
navis.nbl.compress_scores #
Compress scores.
This will not necessarily reduce the in-memory footprint but will lead to much smaller file sizes when saved to disk.
| PARAMETER | DESCRIPTION |
|---|---|
scores | TYPE: |
threshold | TYPE: |
digits | TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
scores_comp | Copy of the original dataframe with the data cast to 32bit floats and the optional filters (see TYPE: |
Source code in navis/nbl/utils.py
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 | |
navis.nbl.dendrogram #
Plot dendrogram.
This is just a convenient thin wrapper around scipy's dendrogram function that lets you feed NBLAST scores directly. Note that this causes some overhead for very large NBLASTs.
| PARAMETER | DESCRIPTION |
|---|---|
x | TYPE: |
method | TYPE: |
**kwargs | DEFAULT: |
| RETURNS | DESCRIPTION |
|---|---|
dendrogram | |
Source code in navis/nbl/utils.py
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 | |
navis.nbl.extract_matches #
Extract top matches from score matrix.
See N, threshold or percentage for the criterion.
| PARAMETER | DESCRIPTION |
|---|---|
scores | TYPE: |
N | TYPE: |
threshold | TYPE: |
percentage | TYPE: |
axis | TYPE: |
distances | TYPE: |
max_matches | TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
pd.DataFrame | Note that the format is slightly different depending on the criterion. |
Notes
Uses navis-fastcore (~20-90x faster for N, ~4-10x for percentage), falling back to numpy for a score matrix whose buffer fastcore cannot read directly - a mixed-dtype or non-contiguous frame - rather than copying it. The two agree except where scores tie, in which case which of the equal matches comes first is arbitrary and differs between the two routes.
NaNs are skipped, not ranked: a query scored against some targets but not others gets its best valid matches rather than a NaN match. If a query has fewer than N valid scores, the remaining match_k/score_k come back empty - None or NaN depending on your pandas version.
Source code in navis/nbl/utils.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 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 | |
navis.nbl.make_clusters #
Form flat clusters.
This is a thin wrapper around scipy.cluster.hierarchy.cut_tree and scipy.cluster.hierarchy.fcluster functions.
| PARAMETER | DESCRIPTION |
|---|---|
x | TYPE: |
t | TYPE: |
criterion | TYPE: |
method | TYPE: |
**kwargs | DEFAULT: |
| RETURNS | DESCRIPTION |
|---|---|
clusters | |
Source code in navis/nbl/utils.py
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 | |
navis.nbl.nblast_prime #
Generate a smoothed version of the NBLAST scores.
In brief: 1. Run PCA on the NBLAST scores and extract the first N components. 2. From that calulate a new similarity matrix.
Requires scikit-learn.
| PARAMETER | DESCRIPTION |
|---|---|
scores | TYPE: |
n_dim | TYPE: |
metric | TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
scores_new | |
Source code in navis/nbl/utils.py
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 | |
navis.nbl.update_scores #
Update score matrix by running only new query->target pairs.
| PARAMETER | DESCRIPTION |
|---|---|
queries | TYPE: |
targets | TYPE: |
scores_ex | TYPE: |
nblast_func | TYPE: |
**kwargs | DEFAULT: |
| RETURNS | DESCRIPTION |
|---|---|
pandas.DataFrame | Updated scores. |
Examples:
Mostly for testing but also illustrates the principle:
>>> import navis
>>> import numpy as np
>>> nl = navis.example_neurons(n=5)
>>> dp = navis.make_dotprops(nl, k=5) / 125
>>> # Full NBLAST
>>> scores = navis.nblast(dp, dp, n_cores=1)
>>> # Subset and fill in
>>> scores2 = navis.nbl.update_scores(dp, dp,
... scores_ex=scores.iloc[:3, 2:],
... nblast_func=navis.nblast,
... n_cores=1)
>>> bool(np.all(scores == scores2))
True
Source code in navis/nbl/utils.py
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 | |