{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# ageas.Plot()\n", "\n", "This notebook demonstrate how to use ageas.Plot() to visualize GRNs or regulons reconstructed with key GRPs extracted with AGEAS." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ageas" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If visualization will be done in script after ageas.Launch() or ageas.Unit(), initialization Plot() object could be as simple as:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# ageas.Test() is a Launch() object using internalized data\n", "# This would take a few minutes to run\n", "test_launch_object = ageas.Test(cpu_mode = True)\n", "\n", "# Here we use first network in atlas, network_0 for example\n", "network = test_launch_object.atlas.nets[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Otherwise, we can load in networks from ***full_atlas.js*** or ***key_atalas.js*** output by [ageas.Launch()](https://JackSSK.github.io/Ageas/html/generated/ageas.Launch.html)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ageas.tool.grn as grn\n", "import ageas.tool.json as json\n", "\n", "# Loading in networks from atlas file\n", "# Here we use first network in atlas, network_0 for example\n", "network = grn.GRN()\n", "network.load_dict(\n", " json.decode(path = 'full_atlas.js')['network_0']\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then, a plotter object can be initialized as:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plotter = ageas.Plot(network = network,)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And graph of query network can be plotted and saved:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plotter.draw(\n", " legend_pos = (1.05, 0.3), # adjust legend position\n", " edge_width_scale = 1.0, # adjust edge(GRP) width\n", ")\n", "plotter.save(path = 'test_plot.png', format = 'png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, we should be able to get a network graph looks like: ![this one](../images/test.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Also, we can visualize GRPs by correlation strength calculated with class 1 samples or class 2 samples." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plotter = ageas.Plot(\n", " network = network,\n", " plot_class = 'class2', # using mef data here. 'class1' will be ipsc data\n", " hide_bridge = False, # unhide GRPs linking regulatory sources \n", ")\n", "plotter.draw(\n", " legend_pos = (1.15, 0.3), # adjust legend position\n", " edge_width_scale = 1.0, # adjust edge(GRP) width\n", ")\n", "plotter.save(path = 'test_plot.png', format = 'png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Output should looks like: ![next one](../images/class2_plot.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Surely, we can only visualize GRPs related to one specific gene of interest in order to avoid over-crowded graph." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plotter = ageas.Plot(\n", " network = network,\n", " hide_bridge = False, # unhide GRPs linking regulatory sources\n", " root_gene = 'Klf4', # Klf4 is our gene of interest\n", " depth = 1, # and we are visualizing all GRPs directly linked with Klf4\n", ")\n", "plotter.draw(\n", " figure_size = 10, # less GRPs here, smaller size would be better\n", " legend_pos = (1.3, 0.3), # adjust legend position\n", " edge_width_scale = 2.0, # adjust edge(GRP) width\n", ")\n", "plotter.save(path = 'test_plot_1.png', format = 'png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And we shoud get something looks like: ![klf4 one](../images/klf4.png)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.13 64-bit (windows store)", "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.9.13" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "2a9e64e061ab733f2e33056f37bf3f62a8dd02da99810729dff6b17cfb3a5e9f" } } }, "nbformat": 4, "nbformat_minor": 2 }