From be7949c1c44231fbf7c737fe944eca2a57b37cf1 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Thu, 9 Aug 2018 20:16:15 +0000 Subject: [PATCH] debug notebooks --- notebooks/debug_graphs.ipynb | 102 ++++++ notebooks/nodegraph_similarity.ipynb | 445 +++++++++++++++++++++++++++ 2 files changed, 547 insertions(+) create mode 100644 notebooks/debug_graphs.ipynb create mode 100644 notebooks/nodegraph_similarity.ipynb diff --git a/notebooks/debug_graphs.ipynb b/notebooks/debug_graphs.ipynb new file mode 100644 index 0000000000..9b2168c580 --- /dev/null +++ b/notebooks/debug_graphs.ipynb @@ -0,0 +1,102 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "from khmer import Nodegraph, Countgraph" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "ng = Nodegraph(3, 10, 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 171, 134, 226, 57, 127, 0]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ng.get_raw_tables()[0].tolist()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "cg = Countgraph(3, 10, 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 0, 0, 0, 0, 0, 0]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cg.get_raw_tables()[0].tolist()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.5" + }, + "nav_menu": {}, + "toc": { + "navigate_menu": true, + "number_sections": true, + "sideBar": true, + "threshold": 6, + "toc_cell": false, + "toc_section_display": "block", + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/notebooks/nodegraph_similarity.ipynb b/notebooks/nodegraph_similarity.ipynb new file mode 100644 index 0000000000..d566318206 --- /dev/null +++ b/notebooks/nodegraph_similarity.ipynb @@ -0,0 +1,445 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [], + "source": [ + "from khmer import Nodegraph" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 139, 170, 240, 110, 127, 0]" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ng = Nodegraph(3, 10, 1)\n", + "ng.get_raw_tables()[0].tolist()" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 139, 170, 240, 110, 127, 0]" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ng.count('AAA')\n", + "ng.get_raw_tables()[0].tolist()" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[17, 139, 170, 240, 110, 127, 0]" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ng.count('CGC')\n", + "ng.get_raw_tables()[0].tolist()" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.5" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "other_ng = Nodegraph(3, 10, 1)\n", + "other_ng.count('AAA')\n", + "ng.similarity(other_ng)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 139, 170, 240, 110, 127, 0]" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "other_ng.get_raw_tables()[0].tolist()" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[17, 139, 170, 240, 110, 127, 0]" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ng.get_raw_tables()[0].tolist()" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [], + "source": [ + "def py_similarity(a, b):\n", + " a_tables = a.get_raw_tables()\n", + " b_tables = b.get_raw_tables()\n", + " \n", + " intersection = 0\n", + " union_size = 0\n", + " for i, (me, other) in enumerate(zip(a_tables, b_tables)):\n", + " for v, t in zip(me.tolist(), other.tolist()):\n", + " intersection += bin(v & t).count('1')\n", + " union_size += bin(v | t).count('1')\n", + " print(v, t, intersection, union_size)\n", + " if union_size == 0:\n", + " union_size = 1\n", + " \n", + " return intersection / union_size" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "17 1 1 2\n", + "139 139 5 6\n", + "170 170 9 10\n", + "240 240 13 14\n", + "110 110 18 19\n", + "127 127 25 26\n", + "0 0 25 26\n" + ] + }, + { + "data": { + "text/plain": [ + "0.9615384615384616" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "py_similarity(ng, other_ng)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "def similarity(a, b):\n", + " return bin(a & b).count('1') / (bin(a | b).count('1') or 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.0" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "similarity(0b0101,\n", + " 0b1010)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.0" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "similarity(0b0000,\n", + " 0b0000)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.0" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "similarity(0b0000,\n", + " 0b0000)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1.0" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "similarity(0b1111,\n", + " 0b1111)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.5" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "similarity(0b1010,\n", + " 0b1111)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "def containment(a, b):\n", + " return bin(a & b).count('1') / (bin(a).count('1') or 1)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.0" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "containment(0b0101,\n", + " 0b1010)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.0" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "containment(0b0000,\n", + " 0b0000)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.0" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "containment(0b0000,\n", + " 0b0000)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1.0" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "containment(0b1111,\n", + " 0b1111)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1.0" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "containment(0b1010,\n", + " 0b1111)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}