Skip to content

Commit

Permalink
DOC: binary=False / vals updates in tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
fedarko committed Sep 2, 2023
1 parent 6a3fdb2 commit 858b29f
Showing 1 changed file with 91 additions and 22 deletions.
113 changes: 91 additions & 22 deletions docs/Tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
"id": "7d808534",
"metadata": {},
"source": [
"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",
"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",
"\n",
"For more details about these values, you can run `help(wotplot.DotPlotMatrix)`."
]
Expand Down Expand Up @@ -440,18 +440,86 @@
"id": "ec251ecc",
"metadata": {},
"source": [
"# 2. Visualizing matrices in color\n",
"# 2. Visualizing matrices using multiple colors of matches\n",
"\n",
"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",
"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",
"\n",
"## 2.1. Using `binary=False` with the same dataset as above\n",
"\n",
"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."
"## 2.1. Using `binary=False` with the same dataset as above"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "dd5c9aa8",
"metadata": {},
"outputs": [],
"source": [
"n = wotplot.DotPlotMatrix(s1, s2, k, binary=False)"
]
},
{
"cell_type": "markdown",
"id": "9f3f163a",
"metadata": {},
"source": [
"If we convert `n`'s matrix to a dense format, we see that now it doesn't just contain `0` and `1` values:"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "b830209a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],\n",
" [ 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],\n",
" [ 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],\n",
" [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],\n",
" [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
" [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
" [ 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
" [ 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0],\n",
" [ 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0],\n",
" [ 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0],\n",
" [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0],\n",
" [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0],\n",
" [ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0],\n",
" [ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0],\n",
" [ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
" [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"n.mat.toarray()"
]
},
{
"cell_type": "markdown",
"id": "aad2225c",
"metadata": {},
"source": [
"In this not-binary matrix:\n",
"\n",
"- `1` values indicate forward matches,\n",
"- `-1` values indicate reverse-complementary matches, and\n",
"- `2` values indicate palindromic matches (there aren't any of those in this example).\n",
"\n",
"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",
"\n",
"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."
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "def90ddc",
"metadata": {},
"outputs": [
Expand All @@ -467,10 +535,9 @@
}
],
"source": [
"n = wotplot.DotPlotMatrix(s1, s2, k, binary=False)\n",
"fig, ax = wotplot.viz_imshow(n)\n",
"# Save the visualization to a file -- we can do this using the fig object returned by\n",
"# viz_imshow() or viz_spy() \n",
"# Since we include it in the README, we'l save this drawing to a file.\n",
"# We can do this using the fig object returned by viz_imshow() (or by viz_spy()).\n",
"fig.savefig(os.path.join(\"img\", \"small_example_dotplot.png\"), **savefig_kwargs)"
]
},
Expand All @@ -479,14 +546,16 @@
"id": "d4bfc908",
"metadata": {},
"source": [
"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:"
"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:"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 17,
"id": "2e1c70c9",
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
Expand All @@ -495,7 +564,7 @@
" <AxesSubplot:xlabel='$s_1$ (18 nt) →', ylabel='$s_2$ (18 nt) →'>)"
]
},
"execution_count": 15,
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -524,7 +593,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 18,
"id": "1b419201",
"metadata": {},
"outputs": [
Expand All @@ -535,7 +604,7 @@
" <AxesSubplot:xlabel='$s_1$ (21 nt) →', ylabel='$s_2$ (21 nt) →'>)"
]
},
"execution_count": 16,
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -569,7 +638,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 19,
"id": "c6bd2bbe",
"metadata": {},
"outputs": [
Expand All @@ -580,7 +649,7 @@
" <AxesSubplot:xlabel='$s_1$ (21 nt) →', ylabel='$s_2$ (21 nt) →'>)"
]
},
"execution_count": 17,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -615,7 +684,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 20,
"id": "40a1ea34",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -659,7 +728,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 21,
"id": "9a6c3f79",
"metadata": {},
"outputs": [
Expand All @@ -670,7 +739,7 @@
" <AxesSubplot:xlabel='$s_1$ (18 nt) →', ylabel='$s_2$ (18 nt) →'>)"
]
},
"execution_count": 19,
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
},
Expand All @@ -694,7 +763,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 22,
"id": "30be1fa7",
"metadata": {},
"outputs": [
Expand All @@ -705,7 +774,7 @@
" <AxesSubplot:xlabel='$s_1$ (18 nt) →', ylabel='$s_2$ (18 nt) →'>)"
]
},
"execution_count": 20,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
},
Expand Down

0 comments on commit 858b29f

Please sign in to comment.