{ "cells": [ { "cell_type": "markdown", "id": "888b937bdfe73748", "metadata": {}, "source": [ "# Tutorial 3: visualization of multi-omics networks\n", "\n", "In this tutorial, we will use the built-in functions in iDDN package to visualize the common and differential networks. The visualization function of iDDN allows us to quickly make some simple plots, while it also allows the incorporation of multiple components and the customization of many details of the graph. We will use four examples in this tutorial." ] }, { "cell_type": "code", "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2024-08-26T14:57:19.311733Z", "start_time": "2024-08-26T14:57:17.707751Z" } }, "source": [ "from collections import Counter # Find the degree of each node\n", "import numpy as np\n", "from IPython.display import Image\n", "from iddn_data import load_data\n", "from iddn import tools, visualize_multi # visualize_multi is the main function for making plots\n", "\n", "%load_ext autoreload\n", "%autoreload 2" ], "outputs": [], "execution_count": 1 }, { "metadata": {}, "cell_type": "markdown", "source": "We will use the same example as the previous tutorial. But here we will run iDDN again with a larger panelty this time to make the graph sparser and easier to read. Recall that we have three omics type (mRNA + TF + miNRA), each with 50 nodes. We use the convenient `iddn_basic_pipeline` function. All we need for the visualization is the raw output of iDDN (`out_iddn`), as well as the names of all nodes (`node_names`).", "id": "f4eb9df7ac95a97e" }, { "metadata": { "ExecuteTime": { "end_time": "2024-08-26T14:57:22.152537Z", "start_time": "2024-08-26T14:57:19.316613Z" } }, "cell_type": "code", "source": [ "example = load_data.load_example()\n", "\n", "dat1 = example[\"dat1\"]\n", "dat2 = example[\"dat2\"]\n", "dep_mat = example[\"dep_mat\"]\n", "node_names = example['node_names']\n", "\n", "res = tools.iddn_basic_pipeline(dat1, dat2, dep_mat, lambda1=0.3, lambda2=0.05)\n", "out_iddn = res[\"out_iddn\"]" ], "id": "77a0948987e8324a", "outputs": [], "execution_count": 2 }, { "metadata": {}, "cell_type": "markdown", "source": "Next we convert the iDDN output to common and differential network data frames, which are useful for drawing figures. This function was also used in the previous tutorial for us to save and share the iDDN results. `df_edge_comm` and `df_edge_diff` are Pandas dataframes that contain all edges in each graph. `nodes_comm` and `nodes_diff` give the lists of nodes that are present in the networks. Note that due to the usage of sparsity penalties, usually some nodes will not connect to any other node.", "id": "75fa70976dee5abf" }, { "metadata": { "ExecuteTime": { "end_time": "2024-08-26T14:57:23.407397Z", "start_time": "2024-08-26T14:57:22.406860Z" } }, "cell_type": "code", "source": "df_edge_comm, df_edge_diff, nodes_comm, nodes_diff = tools.iddn_output_to_csv(out_iddn, node_names)", "id": "ec6f5127ac9d6a9a", "outputs": [], "execution_count": 3 }, { "metadata": {}, "cell_type": "markdown", "source": "We can take a look at the content of `df_edge_comm`", "id": "c966988dffc5aafa" }, { "metadata": { "ExecuteTime": { "end_time": "2024-08-26T14:57:24.011212Z", "start_time": "2024-08-26T14:57:23.916470Z" } }, "cell_type": "code", "source": "df_edge_comm", "id": "2f642630353d667d", "outputs": [ { "data": { "text/plain": [ " gene1 gene2 condition weight color\n", "0 mrna0 mrna1 0 -0.047618 blue\n", "1 mrna0 mrna4 0 -0.016814 blue\n", "2 mrna0 mrna43 0 -0.004087 blue\n", "3 mrna0 mrna44 0 -0.034142 blue\n", "4 mrna1 mrna2 0 -0.147875 blue\n", ".. ... ... ... ... ...\n", "62 mrna46 tf36 0 0.020251 blue\n", "63 mrna46 tf47 0 0.017000 blue\n", "64 mrna48 tf29 0 -0.011418 blue\n", "65 mrna48 mirna12 0 0.025847 blue\n", "66 mrna48 mirna37 0 0.025156 blue\n", "\n", "[67 rows x 5 columns]" ], "text/html": [ "
| \n", " | gene1 | \n", "gene2 | \n", "condition | \n", "weight | \n", "color | \n", "
|---|---|---|---|---|---|
| 0 | \n", "mrna0 | \n", "mrna1 | \n", "0 | \n", "-0.047618 | \n", "blue | \n", "
| 1 | \n", "mrna0 | \n", "mrna4 | \n", "0 | \n", "-0.016814 | \n", "blue | \n", "
| 2 | \n", "mrna0 | \n", "mrna43 | \n", "0 | \n", "-0.004087 | \n", "blue | \n", "
| 3 | \n", "mrna0 | \n", "mrna44 | \n", "0 | \n", "-0.034142 | \n", "blue | \n", "
| 4 | \n", "mrna1 | \n", "mrna2 | \n", "0 | \n", "-0.147875 | \n", "blue | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 62 | \n", "mrna46 | \n", "tf36 | \n", "0 | \n", "0.020251 | \n", "blue | \n", "
| 63 | \n", "mrna46 | \n", "tf47 | \n", "0 | \n", "0.017000 | \n", "blue | \n", "
| 64 | \n", "mrna48 | \n", "tf29 | \n", "0 | \n", "-0.011418 | \n", "blue | \n", "
| 65 | \n", "mrna48 | \n", "mirna12 | \n", "0 | \n", "0.025847 | \n", "blue | \n", "
| 66 | \n", "mrna48 | \n", "mirna37 | \n", "0 | \n", "0.025156 | \n", "blue | \n", "
67 rows × 5 columns
\n", "