|
292 | 292 | "id": "7d808534", |
293 | 293 | "metadata": {}, |
294 | 294 | "source": [ |
295 | | - "In the above matrix, `0` values represent cells where there aren't any forward or reverse-complement $k$-mer matches, and `1` values represent cells where there is at least one such match.\n", |
| 295 | + "In the above matrix: `0` values represent cells where there aren't any forward or reverse-complement $k$-mer matches, and `1` values represent cells where there is at least one such match.\n", |
296 | 296 | "\n", |
297 | 297 | "For more details about these values, you can run `help(wotplot.DotPlotMatrix)`." |
298 | 298 | ] |
|
440 | 440 | "id": "ec251ecc", |
441 | 441 | "metadata": {}, |
442 | 442 | "source": [ |
443 | | - "# 2. Visualizing matrices in color\n", |
| 443 | + "# 2. Visualizing matrices using multiple colors of matches\n", |
444 | 444 | "\n", |
445 | | - "If we set `binary=False` when creating a `DotPlotMatrix` object, then wotplot will distinguish between forward, reverse-complementary, and palindromic matches. This can be useful for certain analyses; also, we can color these matches differently in the visualization! `viz_imshow()` will automatically do this for you.\n", |
| 445 | + "If we set `binary=False` when creating a `DotPlotMatrix` object, then wotplot will distinguish between forward, reverse-complementary, and palindromic matches. This can be useful for certain analyses; also, we can color these matches differently in the visualization!\n", |
446 | 446 | "\n", |
447 | | - "## 2.1. Using `binary=False` with the same dataset as above\n", |
448 | | - "\n", |
449 | | - "The default colormap used colors non-match cells white, forward match cells red, reverse-complementary match cells blue, and palindromic match cells purple. This is based on Figure 6.20 in Chapter 6 of _Bioinformatics Algorithms_ (Compeau & Pevzner), edition 2." |
| 447 | + "## 2.1. Using `binary=False` with the same dataset as above" |
450 | 448 | ] |
451 | 449 | }, |
452 | 450 | { |
453 | 451 | "cell_type": "code", |
454 | 452 | "execution_count": 14, |
| 453 | + "id": "dd5c9aa8", |
| 454 | + "metadata": {}, |
| 455 | + "outputs": [], |
| 456 | + "source": [ |
| 457 | + "n = wotplot.DotPlotMatrix(s1, s2, k, binary=False)" |
| 458 | + ] |
| 459 | + }, |
| 460 | + { |
| 461 | + "cell_type": "markdown", |
| 462 | + "id": "9f3f163a", |
| 463 | + "metadata": {}, |
| 464 | + "source": [ |
| 465 | + "If we convert `n`'s matrix to a dense format, we see that now it doesn't just contain `0` and `1` values:" |
| 466 | + ] |
| 467 | + }, |
| 468 | + { |
| 469 | + "cell_type": "code", |
| 470 | + "execution_count": 15, |
| 471 | + "id": "b830209a", |
| 472 | + "metadata": {}, |
| 473 | + "outputs": [ |
| 474 | + { |
| 475 | + "data": { |
| 476 | + "text/plain": [ |
| 477 | + "array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],\n", |
| 478 | + " [ 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],\n", |
| 479 | + " [ 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],\n", |
| 480 | + " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],\n", |
| 481 | + " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n", |
| 482 | + " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n", |
| 483 | + " [ 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n", |
| 484 | + " [ 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0],\n", |
| 485 | + " [ 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0],\n", |
| 486 | + " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0],\n", |
| 487 | + " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0],\n", |
| 488 | + " [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0],\n", |
| 489 | + " [ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0],\n", |
| 490 | + " [ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0],\n", |
| 491 | + " [ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n", |
| 492 | + " [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])" |
| 493 | + ] |
| 494 | + }, |
| 495 | + "execution_count": 15, |
| 496 | + "metadata": {}, |
| 497 | + "output_type": "execute_result" |
| 498 | + } |
| 499 | + ], |
| 500 | + "source": [ |
| 501 | + "n.mat.toarray()" |
| 502 | + ] |
| 503 | + }, |
| 504 | + { |
| 505 | + "cell_type": "markdown", |
| 506 | + "id": "aad2225c", |
| 507 | + "metadata": {}, |
| 508 | + "source": [ |
| 509 | + "In this not-binary matrix:\n", |
| 510 | + "\n", |
| 511 | + "- `1` values indicate forward matches,\n", |
| 512 | + "- `-1` values indicate reverse-complementary matches, and\n", |
| 513 | + "- `2` values indicate palindromic matches (there aren't any of those in this example).\n", |
| 514 | + "\n", |
| 515 | + "For reference, these values actually correspond to constants in wotplot's package (`wotplot.FWD`, `wotplot.REV`, and `wotplot.BOTH`, respectively; for binary matrices, `1` values correspond to `wotplot.MATCH`). If you're writing code that works with these matrices, I suggest using these constants instead of `1`, `-1`, etc.; this might improve readability a bit. (But it's not a huge deal.)\n", |
| 516 | + "\n", |
| 517 | + "Okay, now let's draw this matrix! `viz_imshow()` will automatically notice that this matrix was created using `binary=False`, and will draw it in color." |
| 518 | + ] |
| 519 | + }, |
| 520 | + { |
| 521 | + "cell_type": "code", |
| 522 | + "execution_count": 16, |
455 | 523 | "id": "def90ddc", |
456 | 524 | "metadata": {}, |
457 | 525 | "outputs": [ |
|
467 | 535 | } |
468 | 536 | ], |
469 | 537 | "source": [ |
470 | | - "n = wotplot.DotPlotMatrix(s1, s2, k, binary=False)\n", |
471 | 538 | "fig, ax = wotplot.viz_imshow(n)\n", |
472 | | - "# Save the visualization to a file -- we can do this using the fig object returned by\n", |
473 | | - "# viz_imshow() or viz_spy() \n", |
| 539 | + "# Since we include it in the README, we'l save this drawing to a file.\n", |
| 540 | + "# We can do this using the fig object returned by viz_imshow() (or by viz_spy()).\n", |
474 | 541 | "fig.savefig(os.path.join(\"img\", \"small_example_dotplot.png\"), **savefig_kwargs)" |
475 | 542 | ] |
476 | 543 | }, |
|
479 | 546 | "id": "d4bfc908", |
480 | 547 | "metadata": {}, |
481 | 548 | "source": [ |
482 | | - "Note that `viz_spy()` can only use one color for all match cells (by default this is set to black), so visualizing a `binary=False` matrix with `viz_spy()` doesn't look different from visualizing the equivalent `binary=True` (default) matrix:" |
| 549 | + "Note that `viz_spy()` can only use one color for all match cells (by default this color is set to black), so visualizing a `binary=False` matrix with `viz_spy()` doesn't look different from visualizing the equivalent `binary=True` (default) matrix:" |
483 | 550 | ] |
484 | 551 | }, |
485 | 552 | { |
486 | 553 | "cell_type": "code", |
487 | | - "execution_count": 15, |
| 554 | + "execution_count": 17, |
488 | 555 | "id": "2e1c70c9", |
489 | | - "metadata": {}, |
| 556 | + "metadata": { |
| 557 | + "scrolled": true |
| 558 | + }, |
490 | 559 | "outputs": [ |
491 | 560 | { |
492 | 561 | "data": { |
|
495 | 564 | " <AxesSubplot:xlabel='$s_1$ (18 nt) →', ylabel='$s_2$ (18 nt) →'>)" |
496 | 565 | ] |
497 | 566 | }, |
498 | | - "execution_count": 15, |
| 567 | + "execution_count": 17, |
499 | 568 | "metadata": {}, |
500 | 569 | "output_type": "execute_result" |
501 | 570 | }, |
|
524 | 593 | }, |
525 | 594 | { |
526 | 595 | "cell_type": "code", |
527 | | - "execution_count": 16, |
| 596 | + "execution_count": 18, |
528 | 597 | "id": "1b419201", |
529 | 598 | "metadata": {}, |
530 | 599 | "outputs": [ |
|
535 | 604 | " <AxesSubplot:xlabel='$s_1$ (21 nt) →', ylabel='$s_2$ (21 nt) →'>)" |
536 | 605 | ] |
537 | 606 | }, |
538 | | - "execution_count": 16, |
| 607 | + "execution_count": 18, |
539 | 608 | "metadata": {}, |
540 | 609 | "output_type": "execute_result" |
541 | 610 | }, |
|
569 | 638 | }, |
570 | 639 | { |
571 | 640 | "cell_type": "code", |
572 | | - "execution_count": 17, |
| 641 | + "execution_count": 19, |
573 | 642 | "id": "c6bd2bbe", |
574 | 643 | "metadata": {}, |
575 | 644 | "outputs": [ |
|
580 | 649 | " <AxesSubplot:xlabel='$s_1$ (21 nt) →', ylabel='$s_2$ (21 nt) →'>)" |
581 | 650 | ] |
582 | 651 | }, |
583 | | - "execution_count": 17, |
| 652 | + "execution_count": 19, |
584 | 653 | "metadata": {}, |
585 | 654 | "output_type": "execute_result" |
586 | 655 | }, |
|
615 | 684 | }, |
616 | 685 | { |
617 | 686 | "cell_type": "code", |
618 | | - "execution_count": 18, |
| 687 | + "execution_count": 20, |
619 | 688 | "id": "40a1ea34", |
620 | 689 | "metadata": {}, |
621 | 690 | "outputs": [ |
|
659 | 728 | }, |
660 | 729 | { |
661 | 730 | "cell_type": "code", |
662 | | - "execution_count": 19, |
| 731 | + "execution_count": 21, |
663 | 732 | "id": "9a6c3f79", |
664 | 733 | "metadata": {}, |
665 | 734 | "outputs": [ |
|
670 | 739 | " <AxesSubplot:xlabel='$s_1$ (18 nt) →', ylabel='$s_2$ (18 nt) →'>)" |
671 | 740 | ] |
672 | 741 | }, |
673 | | - "execution_count": 19, |
| 742 | + "execution_count": 21, |
674 | 743 | "metadata": {}, |
675 | 744 | "output_type": "execute_result" |
676 | 745 | }, |
|
694 | 763 | }, |
695 | 764 | { |
696 | 765 | "cell_type": "code", |
697 | | - "execution_count": 20, |
| 766 | + "execution_count": 22, |
698 | 767 | "id": "30be1fa7", |
699 | 768 | "metadata": {}, |
700 | 769 | "outputs": [ |
|
705 | 774 | " <AxesSubplot:xlabel='$s_1$ (18 nt) →', ylabel='$s_2$ (18 nt) →'>)" |
706 | 775 | ] |
707 | 776 | }, |
708 | | - "execution_count": 20, |
| 777 | + "execution_count": 22, |
709 | 778 | "metadata": {}, |
710 | 779 | "output_type": "execute_result" |
711 | 780 | }, |
|
0 commit comments