gpl_main.ipynb 9.09 KB
Newer Older
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 32 33 34 35 36 37 38 39 40 41 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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "41a9395c-0e12-4e7a-85b8-1eac4f02870d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from Bio import Entrez\n",
    "import GEOparse\n",
    "import pandas as pd\n",
    "import os\n",
    "import preprocess_functions\n",
    "import insert_tables\n",
    "import mysql.connector\n",
    "from mysql.connector import errorcode"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "34bc052f-3e52-4a26-8946-0c12a9317bde",
   "metadata": {},
   "outputs": [],
   "source": [
    "gpl_path=\"/home/lmasa/GEO_Laura/data/gpl\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "4981165e-a2bf-462b-8b1d-8573872e930b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "06-Jul-2024 13:30:43 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL94.annot: \n",
      "06-Jul-2024 13:30:43 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:43 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL571.annot: \n",
      "06-Jul-2024 13:30:43 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:43 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL570.annot: \n",
      "06-Jul-2024 13:30:43 DEBUG GEOparse - ANNOTATION: \n",
      "/home/lmasa/miniconda3/lib/python3.12/site-packages/GEOparse/GEOparse.py:401: DtypeWarning: Columns (12) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  return read_csv(StringIO(data), index_col=None, sep=\"\\t\")\n",
      "06-Jul-2024 13:30:43 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL93.annot: \n",
      "06-Jul-2024 13:30:43 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:44 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL96.annot: \n",
      "06-Jul-2024 13:30:44 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:44 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL1426.annot: \n",
      "06-Jul-2024 13:30:44 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:44 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL201.annot: \n",
      "06-Jul-2024 13:30:44 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:44 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL8300.annot: \n",
      "06-Jul-2024 13:30:44 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:44 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL4191.annot: \n",
      "06-Jul-2024 13:30:44 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:44 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL97.annot: \n",
      "06-Jul-2024 13:30:44 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:44 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL10526.annot: \n",
      "06-Jul-2024 13:30:44 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:45 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL92.annot: \n",
      "06-Jul-2024 13:30:45 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:45 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL95.annot: \n",
      "06-Jul-2024 13:30:45 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:45 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL74.annot: \n",
      "06-Jul-2024 13:30:45 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:45 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL4133.annot: \n",
      "06-Jul-2024 13:30:45 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:45 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL80.annot: \n",
      "06-Jul-2024 13:30:45 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:45 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL10558.annot: \n",
      "06-Jul-2024 13:30:46 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:46 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL91.annot: \n",
      "06-Jul-2024 13:30:46 DEBUG GEOparse - ANNOTATION: \n",
      "06-Jul-2024 13:30:46 INFO GEOparse - Parsing /home/lmasa/GEO_Laura/data/gpl/GPL246.annot: \n",
      "06-Jul-2024 13:30:46 DEBUG GEOparse - ANNOTATION: \n"
     ]
    }
   ],
   "source": [
    "gpl_data=preprocess_functions.fetch_gpl_annot(gpl_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "23f1d834-caeb-4f0e-a28c-95d258f8ea53",
   "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>gpl_id</th>\n",
       "      <th>gpl_title</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GPL94</td>\n",
       "      <td>[HG_U95D] Affymetrix Human Genome U95D Array</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>GPL571</td>\n",
       "      <td>[HG-U133A_2] Affymetrix Human Genome U133A 2.0...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>GPL570</td>\n",
       "      <td>[HG-U133_Plus_2] Affymetrix Human Genome U133 ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>GPL93</td>\n",
       "      <td>[HG_U95C] Affymetrix Human Genome U95C Array</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>GPL96</td>\n",
       "      <td>[HG-U133A] Affymetrix Human Genome U133A Array</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   gpl_id                                          gpl_title\n",
       "0   GPL94       [HG_U95D] Affymetrix Human Genome U95D Array\n",
       "1  GPL571  [HG-U133A_2] Affymetrix Human Genome U133A 2.0...\n",
       "2  GPL570  [HG-U133_Plus_2] Affymetrix Human Genome U133 ...\n",
       "3   GPL93       [HG_U95C] Affymetrix Human Genome U95C Array\n",
       "4   GPL96     [HG-U133A] Affymetrix Human Genome U133A Array"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gpl_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6389c1a1-c443-4774-bd9d-0fb65af45bee",
   "metadata": {},
   "outputs": [],
   "source": [
    "##Insert GPL data into database"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d5785dba-71d0-4269-9ae7-b1968b8e9a19",
   "metadata": {},
   "outputs": [],
   "source": [
    "#The connection details needed to insert data into the database\n",
    "host = \"{host}\"  # Host where the MySQL server is located. Example: 'localhost' or '127.0.0.1'\n",
    "user = \"{user_name}\"  # Username for accessing the MySQL database. Example: 'root' or 'my_user'\n",
    "password = \"{password}\"  # Password for the MySQL user. Ensure to use a secure password for database access.\n",
    "database = \"{database}\"  # Name of the database to connect to. Example: 'disnet_biolayer'\n",
    "port = \"{port}\"  # Port number for the MySQL server. Default is 3306, but it may vary depending on the setup."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b823d154-7c31-4aee-80b1-89bb933edb58",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Initialize the connection variable to None\n",
    "conn = None\n",
    "\n",
    "try:\n",
    "    # Attempt to establish a connection to the MySQL database\n",
    "    conn = mysql.connector.connect(\n",
    "        host=host,\n",
    "        user=user,\n",
    "        password=password,\n",
    "        database=database,\n",
    "        port=port\n",
    "    )\n",
    "        # Insert GPL data into the database\n",
    "        insert_tables.insert_gpl_main(conn, df)\n",
    "\n",
    "# Handle any MySQL errors that occur during the connection or insertion process\n",
    "except mysql.connector.Error as err:\n",
    "        print(f\"Error connecting to MySQL: {err}\")\n",
    "\n",
    "# Ensure the connection is closed properly even if an error occurs\n",
    "finally:\n",
    "        if conn and conn.is_connected():\n",
    "            conn.close()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}