2. Processed data DREGE.ipynb 8 KB
Newer Older
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "from sqlalchemy import create_engine\n",
    "from sklearn import preprocessing\n",
    "import mysql.connector\n",
    "from pandas import DataFrame"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. DATA "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
32
    "duples_repodb = pd.read_csv(\"./Data/Input/Drug Repurposing/repoDB_all_disdru.tsv\", sep='\\t')"
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
33 34 35 36 37 38 39 40
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
41
    "duples_csbj = pd.read_csv(\"./Data/Input/Drug Repurposing/duplas_CSBJ.tsv\")"
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "duples_csbj = duples_csbj.drop([\"Unnamed: 0\"],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "duples_csbj = duples_csbj.rename(columns={\"Disease CUI\": \"disease_id\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>disease_id</th>\n",
       "      <th>pathway_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>C0020538</td>\n",
       "      <td>WP554</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>C0018799</td>\n",
       "      <td>WP1544</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C0018799</td>\n",
       "      <td>WP1528</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>C0027947</td>\n",
       "      <td>WP229</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>C0013369</td>\n",
       "      <td>WP229</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>659</th>\n",
       "      <td>C0268274</td>\n",
       "      <td>WP4153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>660</th>\n",
       "      <td>C0085131</td>\n",
       "      <td>WP4153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>661</th>\n",
       "      <td>C0036161</td>\n",
       "      <td>WP4153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>662</th>\n",
       "      <td>C0268275</td>\n",
       "      <td>WP4153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>663</th>\n",
       "      <td>C0162666</td>\n",
       "      <td>WP4236</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>664 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    disease_id pathway_id\n",
       "0     C0020538      WP554\n",
       "1     C0018799     WP1544\n",
       "2     C0018799     WP1528\n",
       "3     C0027947      WP229\n",
       "4     C0013369      WP229\n",
       "..         ...        ...\n",
       "659   C0268274     WP4153\n",
       "660   C0085131     WP4153\n",
       "661   C0036161     WP4153\n",
       "662   C0268275     WP4153\n",
       "663   C0162666     WP4236\n",
       "\n",
       "[664 rows x 2 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
176
    "dis_path_direct = pd.read_csv('./Data/Input/DISNET/disease_pathway.tsv', sep='\\t')\n",
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
177 178 179 180 181 182 183 184 185
    "dis_path_direct"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
186
    "drug_gen = pd.read_csv('./Data/Input/DISNET/drug_gen.tsv', sep='\\t')"
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "drug_gen = drug_gen.drop([\"Unnamed: 0\"],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
204
    "dis_gen = pd.read_csv('./Data/Input/DISNET/dis_genes_gda.tsv', sep='\\t')"
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "dis_gen = dis_gen.drop([\"Unnamed: 0\"],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
222
    "dis_gen_sinfil = pd.read_csv('./Data/Input/DISNET/dis_genes.tsv', sep='\\t')"
Belen Otero Carrasco's avatar
Belen Otero Carrasco committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "dis_gen_sinfil = dis_gen_sinfil.drop([\"Unnamed: 0\"],axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### JOIN REPODB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "dis_drug_gen_sinfil = dis_gen_sinfil.merge(drug_gen, how =\"inner\", on = \"gene_id\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "duplas_target_repodb = dis_drug_path_fil.merge(dis_drug_gen_sinfil, how = \"inner\", on =[\"disease_id\",\"drug_id\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "cases_repodb_target = duples_repodb.merge(duplas_target_repodb,how = \"inner\",on = [\"disease_id\",\"drug_id\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "cases_repodb_target.to_csv(\"cases_repodb_target.tsv\", sep =\"\\t\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.27445783132529894"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cases_repodb_target[\"score\"].mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### JOIN CSBJ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "duplas_target_csbj = dis_drug_path_csbj_fil.merge(dis_drug_gen_sinfil, how = \"inner\", on =[\"disease_id\",\"drug_id\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "cases_csbj_target = duples_csbj.merge(duplas_target_csbj,how = \"inner\",on = [\"disease_id\",\"drug_id\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "cases_csbj_target.to_csv(\"cases_csbj_target.tsv\", sep =\"\\t\")"
   ]
  }
 ],
 "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.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}