diff --git a/notebooks/basics.ipynb b/notebooks/basics.ipynb index 8c237a3..ee719bc 100644 --- a/notebooks/basics.ipynb +++ b/notebooks/basics.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 21, "id": "63fb7d1a-cd49-4aac-8d4f-31bb54496a51", "metadata": { "tags": [] @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 22, "id": "2ab3cb32-e007-45c4-807e-b1b442ac1608", "metadata": { "tags": [] @@ -64,7 +64,6 @@ "outputs": [], "source": [ "from bigraph_viz import plot_bigraph, plot_flow, plot_multitimestep, pf\n", - "from bigraph_schema import TypeSystem\n", "from bigraph_viz.dict_utils import replace_regex_recursive\n", "\n", "plot_settings = {'remove_process_place_edges': True}\n", @@ -73,26 +72,6 @@ " plot_settings.update({'out_dir': 'out','dpi': '250'})" ] }, - { - "cell_type": "markdown", - "id": "a3b85fe8-899d-4c61-8c75-0d572e44e493", - "metadata": {}, - "source": [ - "### Initialize Type System" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "b1166de0-3811-4b35-90c1-3fbfa8343259", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "types = TypeSystem()" - ] - }, { "cell_type": "markdown", "id": "0e716c23-5fbe-4c08-a868-09611ca40ec4", @@ -114,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 23, "id": "d711b952-089a-4938-817d-d1ccad9de56e", "metadata": { "tags": [] @@ -145,10 +124,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 4, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -170,7 +149,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 24, "id": "f3e5fa71-7ffc-4a8f-a1a0-dc547c886f84", "metadata": {}, "outputs": [ @@ -199,10 +178,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 5, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -228,7 +207,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 25, "id": "0f3f0824-f89d-4c6e-830e-2c5a321f7b33", "metadata": {}, "outputs": [ @@ -322,10 +301,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 6, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -365,7 +344,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 26, "id": "7c74237b-0d66-4e8f-a8ca-79174fadad8b", "metadata": {}, "outputs": [ @@ -409,10 +388,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 7, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -442,7 +421,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 27, "id": "8c2457a3-fc47-4850-8b9e-9ee98e81567d", "metadata": {}, "outputs": [ @@ -530,10 +509,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 8, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -567,7 +546,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 28, "id": "a6ecad5d-8948-4636-910c-79284a3e8679", "metadata": {}, "outputs": [ @@ -634,10 +613,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 9, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -694,7 +673,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 29, "id": "781a84e6-bbe2-4708-b441-47efc611b46f", "metadata": {}, "outputs": [ @@ -768,10 +747,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 10, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -810,7 +789,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 30, "id": "701e759d-7f9b-41bb-911c-a8208c892462", "metadata": {}, "outputs": [ @@ -915,10 +894,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 11, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -965,7 +944,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 31, "id": "638c5dc7-4cfd-46e4-b66a-8c42ca98ff1d", "metadata": {}, "outputs": [ @@ -1088,10 +1067,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 12, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -1129,388 +1108,6 @@ "plot_bigraph(composite_process_spec, **plot_settings, filename='composite_process')" ] }, - { - "cell_type": "markdown", - "id": "137bf506-d71c-447b-9bf3-7f310c26a5c5", - "metadata": {}, - "source": [ - "## Updates\n", - "\n", - "- state update\n", - "- structure update" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "f28a8137-280e-4cd5-bfc3-d0d512684283", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "schemaa = {\n", - " 'base': {\n", - " 'a': {'_type': 'int'},\n", - " },\n", - "\n", - " # cannot override existing keys unless it is of a subtype\n", - " 'second': {\n", - " 'b': {'_type': 'int'},\n", - " '_super': 'base',\n", - " },\n", - "}\n", - "\n", - "types.type_registry.register_multiple(schemaa, force=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "1506f428-649d-4c38-aa47-9d85132faa99", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "bigraph\n", - "\n", - "\n", - "\n", - "('a',)\n", - "\n", - "a\n", - "11\n", - "\n", - "\n", - "\n", - "('b',)\n", - "\n", - "b\n", - "13\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "schema = {'_type': 'second'}\n", - "state = {\n", - " 'a': 11,\n", - " 'b': 13,\n", - "}\n", - "plot_bigraph(state, show_values=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "36f1fa08-5bb2-43c6-b9d8-3cba63646def", - "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "bigraph\n", - "\n", - "\n", - "\n", - "('a',)\n", - "\n", - "a\n", - "11\n", - "\n", - "\n", - "\n", - "('b',)\n", - "\n", - "b\n", - "8\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "update = {\n", - " 'b': -5\n", - "}\n", - "new_state = types.apply(\n", - " schema,\n", - " state,\n", - " update\n", - ")\n", - "plot_bigraph(new_state, show_values=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "aa40b177-e9c6-4722-b996-1c1dba40eca4", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "bigraph\n", - "\n", - "\n", - "\n", - "('a',)\n", - "\n", - "a\n", - "16\n", - "\n", - "\n", - "\n", - "('b',)\n", - "\n", - "b\n", - "8\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "update = {\n", - " 'a': 5\n", - "}\n", - "new_state = types.apply(\n", - " schema,\n", - " new_state,\n", - " update\n", - ")\n", - "plot_bigraph(new_state, show_values=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "be2541ae-d8a7-4926-8a18-6f9127f0744a", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# from bigraph_schema.registry import apply_registry\n", - "from bigraph_viz.dict_utils import deep_merge\n", - "def apply_merge(current, update, bindings=None, types=None):\n", - " assert isinstance(state, dict)\n", - " assert isinstance(update, dict)\n", - " updated = deep_merge(state, update)\n", - " return updated\n", - "types.apply_registry.register('merge', apply_merge, force=True)\n", - "\n", - "schemab = {\n", - " 'merge_branch': {\n", - " '_default': {'a1': 'any'},\n", - " '_apply': 'merge',\n", - " \n", - " },\n", - "\n", - " # cannot override existing keys unless it is of a subtype\n", - " 'second': {\n", - " 'a1': {'a2': 'any'},\n", - " '_super': 'merge_branch',\n", - " },\n", - "}\n", - "\n", - "types.type_registry.register_multiple(schemab, force=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "id": "ed5c34bf-b357-4800-b126-73a32b6646c2", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "bigraph\n", - "\n", - "\n", - "\n", - "('a1',)\n", - "\n", - "a1\n", - "\n", - "\n", - "\n", - "('a1', 'a2')\n", - "\n", - "a2\n", - "11\n", - "\n", - "\n", - "\n", - "('a1',)->('a1', 'a2')\n", - "\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "schema = {'_type': 'merge_branch'}\n", - "state = {\n", - " 'a1': {'a2': 11},\n", - "}\n", - "plot_bigraph(state, show_values=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "id": "072c2502-6fdd-4c10-af91-cf00e4de1656", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "bigraph\n", - "\n", - "\n", - "\n", - "('a1',)\n", - "\n", - "a1\n", - "\n", - "\n", - "\n", - "('a1', 'a2')\n", - "\n", - "a2\n", - "11\n", - "\n", - "\n", - "\n", - "('a1',)->('a1', 'a2')\n", - "\n", - "\n", - "\n", - "\n", - "('a1', 'a3')\n", - "\n", - "a3\n", - "-5\n", - "\n", - "\n", - "\n", - "('a1',)->('a1', 'a3')\n", - "\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "update = {\n", - " 'a1': {'a3': -5},\n", - "}\n", - "new_state = types.apply(\n", - " schema,\n", - " state,\n", - " update\n", - ")\n", - "# print(pf(new_state))\n", - "plot_bigraph(new_state, show_values=True)" - ] - }, { "cell_type": "markdown", "id": "847cef26-65a1-4da6-9dd3-eb5839277970", @@ -1521,7 +1118,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 32, "id": "e76c97a8-3037-464a-929e-ba4414c73c34", "metadata": {}, "outputs": [], @@ -1546,7 +1143,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 33, "id": "f0eff7b0-f0e2-4d56-8b16-ef0fc1ce5aba", "metadata": {}, "outputs": [ @@ -1718,10 +1315,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 21, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -1755,7 +1352,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 34, "id": "db45c99b-b97b-47bc-a73e-c669882f3969", "metadata": {}, "outputs": [ @@ -1819,20 +1416,15 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 22, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "step_schema = {\n", - " '_depends_on': 'list[string]',\n", - "}\n", - "types.type_registry.register('step_process', step_schema)\n", - "\n", "flow = {\n", " 'step1': {\n", " '_type': 'step_process',\n", @@ -1881,7 +1473,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 35, "id": "47bdf8e5-0bdd-4cac-b57e-2449c75fa178", "metadata": { "tags": [] @@ -2471,10 +2063,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 23, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -2532,7 +2124,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 36, "id": "ab431982-d156-4b7a-9918-384a5ea5132a", "metadata": { "tags": [] @@ -2564,7 +2156,7 @@ " 'nuclear transcriptional speckle': {'negative regulation of RNA biosynthesis process': {}}}}}" ] }, - "execution_count": 24, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -2575,7 +2167,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 37, "id": "5a76608a-fff0-4005-9f32-c02afef39d9e", "metadata": { "tags": [] @@ -3351,10 +2943,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 25, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -3500,19 +3092,57 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 38, "id": "fe3008ad-498e-449f-8521-6ea29fd903f1", "metadata": { "tags": [] }, "outputs": [ { - "ename": "SyntaxError", - "evalue": "invalid syntax (754939450.py, line 7)", - "output_type": "error", - "traceback": [ - "\u001b[0;36m Cell \u001b[0;32mIn[26], line 7\u001b[0;36m\u001b[0m\n\u001b[0;31m }s\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" - ] + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "bigraph\n", + "\n", + "\n", + "\n", + "('hypothesized<br/>mechanism',)\n", + "\n", + "hypothesized\n", + "mechanism\n", + "\n", + "\n", + "\n", + "\n", + "('hypothesized<br/>mechanism', '1')->('hypothesized<br/>mechanism',)\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "('hypothesized<br/>mechanism', '2')->('hypothesized<br/>mechanism',)\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -3522,7 +3152,7 @@ " '1': 'Any',\n", " '2': 'Any',\n", " }\n", - " }s\n", + " }\n", "}\n", "\n", "new_process = replace_regex_recursive(new_process)\n", @@ -3549,12 +3179,222 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "id": "b39417ce-d9a1-4985-abce-ce22df816897", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Writing out/cell\n" + ] + }, + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "bigraph\n", + "\n", + "\n", + "\n", + "('cell',)\n", + "\n", + "cell\n", + "\n", + "\n", + "\n", + "('cell', 'membrane')\n", + "\n", + "membrane\n", + "\n", + "\n", + "\n", + "('cell',)->('cell', 'membrane')\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm')\n", + "\n", + "cytoplasm\n", + "\n", + "\n", + "\n", + "('cell',)->('cell', 'cytoplasm')\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'nucleoid')\n", + "\n", + "nucleoid\n", + "\n", + "\n", + "\n", + "('cell',)->('cell', 'nucleoid')\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'membrane', 'transporters')\n", + "\n", + "transporters\n", + "\n", + "\n", + "\n", + "('cell', 'membrane')->('cell', 'membrane', 'transporters')\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'membrane', 'lipids')\n", + "\n", + "lipids\n", + "\n", + "\n", + "\n", + "('cell', 'membrane')->('cell', 'membrane', 'lipids')\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'membrane', 'transmembrane transport')\n", + "\n", + "transmembrane transport\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'membrane', 'transporters')->('cell', 'membrane', 'transmembrane transport')\n", + "\n", + "\n", + "transporters\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm', 'metabolites')\n", + "\n", + "metabolites\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm')->('cell', 'cytoplasm', 'metabolites')\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm', 'ribosomal complexes')\n", + "\n", + "ribosomal complexes\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm')->('cell', 'cytoplasm', 'ribosomal complexes')\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm', 'transcript regulation complex')\n", + "\n", + "transcript regulation complex\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm')->('cell', 'cytoplasm', 'transcript regulation complex')\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm', 'translation')\n", + "\n", + "translation\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm', 'metabolites')->('cell', 'membrane', 'transmembrane transport')\n", + "\n", + "\n", + "internal\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm', 'ribosomal complexes')->('cell', 'cytoplasm', 'translation')\n", + "\n", + "\n", + "p1\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm', 'transcript regulation complex', 'transcripts')\n", + "\n", + "transcripts\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm', 'transcript regulation complex')->('cell', 'cytoplasm', 'transcript regulation complex', 'transcripts')\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'cytoplasm', 'transcript regulation complex', 'transcripts')->('cell', 'cytoplasm', 'translation')\n", + "\n", + "\n", + "p2\n", + "\n", + "\n", + "\n", + "('cell', 'nucleoid', 'chromosome')\n", + "\n", + "chromosome\n", + "\n", + "\n", + "\n", + "('cell', 'nucleoid')->('cell', 'nucleoid', 'chromosome')\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'nucleoid', 'chromosome', 'genes')\n", + "\n", + "genes\n", + "\n", + "\n", + "\n", + "('cell', 'nucleoid', 'chromosome')->('cell', 'nucleoid', 'chromosome', 'genes')\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "('cell', 'membrane', 'transmembrane transport', 'external')->('cell', 'membrane', 'transmembrane transport')\n", + "\n", + "\n", + "external\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "cell_struct_func = {\n", " 'cell': {\n", @@ -3618,12 +3458,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "id": "16960d1b-6e35-421e-bb7d-3efe5052e4fc", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Writing out/ecoli\n" + ] + } + ], "source": [ "ecoli = { \n", " 'chromosome-structure': { \n",