Skip to content

Commit 858b29f

Browse files
committed
DOC: binary=False / vals updates in tutorial
1 parent 6a3fdb2 commit 858b29f

File tree

1 file changed

+91
-22
lines changed

1 file changed

+91
-22
lines changed

docs/Tutorial.ipynb

Lines changed: 91 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
"id": "7d808534",
293293
"metadata": {},
294294
"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",
296296
"\n",
297297
"For more details about these values, you can run `help(wotplot.DotPlotMatrix)`."
298298
]
@@ -440,18 +440,86 @@
440440
"id": "ec251ecc",
441441
"metadata": {},
442442
"source": [
443-
"# 2. Visualizing matrices in color\n",
443+
"# 2. Visualizing matrices using multiple colors of matches\n",
444444
"\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",
446446
"\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"
450448
]
451449
},
452450
{
453451
"cell_type": "code",
454452
"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,
455523
"id": "def90ddc",
456524
"metadata": {},
457525
"outputs": [
@@ -467,10 +535,9 @@
467535
}
468536
],
469537
"source": [
470-
"n = wotplot.DotPlotMatrix(s1, s2, k, binary=False)\n",
471538
"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",
474541
"fig.savefig(os.path.join(\"img\", \"small_example_dotplot.png\"), **savefig_kwargs)"
475542
]
476543
},
@@ -479,14 +546,16 @@
479546
"id": "d4bfc908",
480547
"metadata": {},
481548
"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:"
483550
]
484551
},
485552
{
486553
"cell_type": "code",
487-
"execution_count": 15,
554+
"execution_count": 17,
488555
"id": "2e1c70c9",
489-
"metadata": {},
556+
"metadata": {
557+
"scrolled": true
558+
},
490559
"outputs": [
491560
{
492561
"data": {
@@ -495,7 +564,7 @@
495564
" <AxesSubplot:xlabel='$s_1$ (18 nt) →', ylabel='$s_2$ (18 nt) →'>)"
496565
]
497566
},
498-
"execution_count": 15,
567+
"execution_count": 17,
499568
"metadata": {},
500569
"output_type": "execute_result"
501570
},
@@ -524,7 +593,7 @@
524593
},
525594
{
526595
"cell_type": "code",
527-
"execution_count": 16,
596+
"execution_count": 18,
528597
"id": "1b419201",
529598
"metadata": {},
530599
"outputs": [
@@ -535,7 +604,7 @@
535604
" <AxesSubplot:xlabel='$s_1$ (21 nt) →', ylabel='$s_2$ (21 nt) →'>)"
536605
]
537606
},
538-
"execution_count": 16,
607+
"execution_count": 18,
539608
"metadata": {},
540609
"output_type": "execute_result"
541610
},
@@ -569,7 +638,7 @@
569638
},
570639
{
571640
"cell_type": "code",
572-
"execution_count": 17,
641+
"execution_count": 19,
573642
"id": "c6bd2bbe",
574643
"metadata": {},
575644
"outputs": [
@@ -580,7 +649,7 @@
580649
" <AxesSubplot:xlabel='$s_1$ (21 nt) →', ylabel='$s_2$ (21 nt) →'>)"
581650
]
582651
},
583-
"execution_count": 17,
652+
"execution_count": 19,
584653
"metadata": {},
585654
"output_type": "execute_result"
586655
},
@@ -615,7 +684,7 @@
615684
},
616685
{
617686
"cell_type": "code",
618-
"execution_count": 18,
687+
"execution_count": 20,
619688
"id": "40a1ea34",
620689
"metadata": {},
621690
"outputs": [
@@ -659,7 +728,7 @@
659728
},
660729
{
661730
"cell_type": "code",
662-
"execution_count": 19,
731+
"execution_count": 21,
663732
"id": "9a6c3f79",
664733
"metadata": {},
665734
"outputs": [
@@ -670,7 +739,7 @@
670739
" <AxesSubplot:xlabel='$s_1$ (18 nt) →', ylabel='$s_2$ (18 nt) →'>)"
671740
]
672741
},
673-
"execution_count": 19,
742+
"execution_count": 21,
674743
"metadata": {},
675744
"output_type": "execute_result"
676745
},
@@ -694,7 +763,7 @@
694763
},
695764
{
696765
"cell_type": "code",
697-
"execution_count": 20,
766+
"execution_count": 22,
698767
"id": "30be1fa7",
699768
"metadata": {},
700769
"outputs": [
@@ -705,7 +774,7 @@
705774
" <AxesSubplot:xlabel='$s_1$ (18 nt) →', ylabel='$s_2$ (18 nt) →'>)"
706775
]
707776
},
708-
"execution_count": 20,
777+
"execution_count": 22,
709778
"metadata": {},
710779
"output_type": "execute_result"
711780
},

0 commit comments

Comments
 (0)