{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "3d96eb55", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:19:29.714173Z", "iopub.status.busy": "2025-03-25T07:19:29.714065Z", "iopub.status.idle": "2025-03-25T07:19:29.874139Z", "shell.execute_reply": "2025-03-25T07:19:29.873779Z" } }, "outputs": [], "source": [ "import sys\n", "import os\n", "sys.path.append(os.path.abspath(os.path.join(os.getcwd(), '../..')))\n", "\n", "# Path Configuration\n", "from tools.preprocess import *\n", "\n", "# Processing context\n", "trait = \"Kidney_Papillary_Cell_Carcinoma\"\n", "cohort = \"GSE42977\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Kidney_Papillary_Cell_Carcinoma\"\n", "in_cohort_dir = \"../../input/GEO/Kidney_Papillary_Cell_Carcinoma/GSE42977\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Kidney_Papillary_Cell_Carcinoma/GSE42977.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Kidney_Papillary_Cell_Carcinoma/gene_data/GSE42977.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Kidney_Papillary_Cell_Carcinoma/clinical_data/GSE42977.csv\"\n", "json_path = \"../../output/preprocess/Kidney_Papillary_Cell_Carcinoma/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "1f9b5ffe", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "9bfb0adc", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:19:29.875650Z", "iopub.status.busy": "2025-03-25T07:19:29.875422Z", "iopub.status.idle": "2025-03-25T07:19:30.206912Z", "shell.execute_reply": "2025-03-25T07:19:30.206469Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Sequential Binary Gene-Ratio Tests Define a Novel Molecular Diagnostic Strategy for Malignant Pleural Mesothelioma\"\n", "!Series_summary\t\"The gene-expression ratio technique was used to design a molecular signature to diagnose MPM from among other potentially confounding diagnoses and differentiate the epithelioid from the sarcomatoid histological subtype of MPM.\"\n", "!Series_overall_design\t\"Microarray analysis was performed on 113 specimens including MPMs and a spectrum of tumors and benign tissues comprising the differential diagnosis of MPM. A sequential combination of binary gene-expression ratio tests was developed to discriminate MPM from other thoracic malignancies . This method was compared to other bioinformatic tools and this signature was validated in an independent set of 170 samples. Functional enrichment analysis was performed to identify differentially expressed probes.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['tissue: control', 'tissue: Spindle Cell Sarcoma', 'tissue: Sarcoma', 'tissue: Metastatic Melanoma', 'tissue: Pleomorphic Sarcoma', 'tissue: Renal Cell Carcinoma-Clear Cell', 'tissue: Synovial Sarcoma', 'tissue: Metastatic Thymoma', 'tissue: Metastatic Prostate Cancer', 'tissue: Stomach Cancer-Stromal Sarcoma', 'tissue: Non-Hodgkins Lymphoma', 'tissue: Hemangioendothelioma', 'tissue: Papillary Thyroid Carcinoma', 'tissue: Metastatic Thyroid Cancer', 'tissue: Lymphocytic Lymphoma', 'tissue: Thymoma', 'tissue: Melanoma-Malignant', 'tissue: Hemangiopericytoma', 'tissue: Thyroid Carcinoma', 'tissue: Monophasic Synovial Sarcoma', 'tissue: Metastatic Alveolar Soft Part Sarcoma', 'tissue: Metastatic Meningeal Hemangiopericytoma', 'tissue: Follicular Lymphoma', 'tissue: Rhabdomyosarcoma', 'tissue: Myofibrosarcoma', 'tissue: Renal Cell Carcinoma - Chromophobe', 'tissue: MPM Epithelioid', 'tissue: MPM Sarcomatoid', 'tissue: MPM Biphasic', 'tissue: Normal Lung']}\n" ] } ], "source": [ "from tools.preprocess import *\n", "# 1. Identify the paths to the SOFT file and the matrix file\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# 2. Read the matrix file to obtain background information and sample characteristics data\n", "background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']\n", "clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']\n", "background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)\n", "\n", "# 3. Obtain the sample characteristics dictionary from the clinical dataframe\n", "sample_characteristics_dict = get_unique_values_by_row(clinical_data)\n", "\n", "# 4. Explicitly print out all the background information and the sample characteristics dictionary\n", "print(\"Background Information:\")\n", "print(background_info)\n", "print(\"Sample Characteristics Dictionary:\")\n", "print(sample_characteristics_dict)\n" ] }, { "cell_type": "markdown", "id": "378fed3d", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "a54985fd", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:19:30.208325Z", "iopub.status.busy": "2025-03-25T07:19:30.208215Z", "iopub.status.idle": "2025-03-25T07:19:30.213112Z", "shell.execute_reply": "2025-03-25T07:19:30.212806Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No relevant clinical data available for extraction for the specified trait.\n" ] } ], "source": [ "import pandas as pd\n", "import numpy as np\n", "import os\n", "import json\n", "from typing import Optional, Callable, Dict, Any, List, Union\n", "\n", "# Let's analyze the sample characteristics dictionary to determine data availability\n", "sample_chars = {0: ['tissue: control', 'tissue: Spindle Cell Sarcoma', 'tissue: Sarcoma', 'tissue: Metastatic Melanoma', 'tissue: Pleomorphic Sarcoma', 'tissue: Renal Cell Carcinoma-Clear Cell', 'tissue: Synovial Sarcoma', 'tissue: Metastatic Thymoma', 'tissue: Metastatic Prostate Cancer', 'tissue: Stomach Cancer-Stromal Sarcoma', 'tissue: Non-Hodgkins Lymphoma', 'tissue: Hemangioendothelioma', 'tissue: Papillary Thyroid Carcinoma', 'tissue: Metastatic Thyroid Cancer', 'tissue: Lymphocytic Lymphoma', 'tissue: Thymoma', 'tissue: Melanoma-Malignant', 'tissue: Hemangiopericytoma', 'tissue: Thyroid Carcinoma', 'tissue: Monophasic Synovial Sarcoma', 'tissue: Metastatic Alveolar Soft Part Sarcoma', 'tissue: Metastatic Meningeal Hemangiopericytoma', 'tissue: Follicular Lymphoma', 'tissue: Rhabdomyosarcoma', 'tissue: Myofibrosarcoma', 'tissue: Renal Cell Carcinoma - Chromophobe', 'tissue: MPM Epithelioid', 'tissue: MPM Sarcomatoid', 'tissue: MPM Biphasic', 'tissue: Normal Lung']}\n", "\n", "# 1. Gene Expression Data Availability\n", "# Based on the background information, it appears that this dataset contains microarray analysis,\n", "# which suggests gene expression data is likely available\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Trait (Kidney Papillary Cell Carcinoma)\n", "# From the sample characteristic dictionary, we can see that row 0 contains 'tissue' information\n", "trait_row = 0\n", "\n", "# Check for Kidney Papillary Cell Carcinoma in the data\n", "renal_samples = [val for val in sample_chars[0] if \"Renal\" in val or \"Kidney\" in val]\n", "papillary_samples = [val for val in sample_chars[0] if \"Papillary\" in val]\n", "\n", "# We find \"Renal Cell Carcinoma-Clear Cell\" and \"Renal Cell Carcinoma - Chromophobe\"\n", "# but not specifically Kidney Papillary Cell Carcinoma\n", "# Looking at the data, it seems this study is about Malignant Pleural Mesothelioma (MPM)\n", "# The trait we are looking for (Kidney_Papillary_Cell_Carcinoma) is not present\n", "is_trait_available = False\n", "\n", "# 2.2 Age\n", "# There doesn't appear to be age information in the sample characteristics\n", "age_row = None\n", "\n", "# 2.3 Gender\n", "# There doesn't appear to be gender information in the sample characteristics\n", "gender_row = None\n", "\n", "# Function to convert trait values - this won't be used since trait data is not available\n", "# but we define it for completeness\n", "def convert_trait(value):\n", " if value is None:\n", " return None\n", " \n", " # Extract the part after colon\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Since we're looking for Kidney Papillary Cell Carcinoma but the data is about MPM,\n", " # we have to mark trait as not available\n", " return None\n", "\n", "# Define convert_age and convert_gender as placeholders\n", "def convert_age(value):\n", " return None\n", "\n", "def convert_gender(value):\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Save metadata using the validate_and_save_cohort_info function\n", "validate_and_save_cohort_info(\n", " is_final=False,\n", " cohort=cohort,\n", " info_path=json_path,\n", " is_gene_available=is_gene_available,\n", " is_trait_available=is_trait_available\n", ")\n", "\n", "# 4. Clinical Feature Extraction (if trait_row is not None and is_trait_available is True)\n", "if trait_row is not None and is_trait_available:\n", " # Since we determined that this dataset doesn't contain our trait of interest,\n", " # we won't need to extract clinical features\n", " # This block won't execute due to is_trait_available being False\n", " pass\n", "else:\n", " print(\"No relevant clinical data available for extraction for the specified trait.\")\n" ] }, { "cell_type": "markdown", "id": "5a3d304e", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "6abf4550", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:19:30.214245Z", "iopub.status.busy": "2025-03-25T07:19:30.214141Z", "iopub.status.idle": "2025-03-25T07:19:30.814396Z", "shell.execute_reply": "2025-03-25T07:19:30.814001Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Examining matrix file structure...\n", "Line 0: !Series_title\t\"Sequential Binary Gene-Ratio Tests Define a Novel Molecular Diagnostic Strategy for Malignant Pleural Mesothelioma\"\n", "Line 1: !Series_geo_accession\t\"GSE42977\"\n", "Line 2: !Series_status\t\"Public on May 01 2013\"\n", "Line 3: !Series_submission_date\t\"Dec 18 2012\"\n", "Line 4: !Series_last_update_date\t\"Feb 16 2021\"\n", "Line 5: !Series_pubmed_id\t\"23493352\"\n", "Line 6: !Series_pubmed_id\t\"33540554\"\n", "Line 7: !Series_summary\t\"The gene-expression ratio technique was used to design a molecular signature to diagnose MPM from among other potentially confounding diagnoses and differentiate the epithelioid from the sarcomatoid histological subtype of MPM.\"\n", "Line 8: !Series_overall_design\t\"Microarray analysis was performed on 113 specimens including MPMs and a spectrum of tumors and benign tissues comprising the differential diagnosis of MPM. A sequential combination of binary gene-expression ratio tests was developed to discriminate MPM from other thoracic malignancies . This method was compared to other bioinformatic tools and this signature was validated in an independent set of 170 samples. Functional enrichment analysis was performed to identify differentially expressed probes.\"\n", "Line 9: !Series_type\t\"Expression profiling by array\"\n", "Found table marker at line 69\n", "First few lines after marker:\n", "\"ID_REF\"\t\"GSM1054230\"\t\"GSM1054231\"\t\"GSM1054232\"\t\"GSM1054233\"\t\"GSM1054234\"\t\"GSM1054235\"\t\"GSM1054236\"\t\"GSM1054237\"\t\"GSM1054238\"\t\"GSM1054239\"\t\"GSM1054240\"\t\"GSM1054241\"\t\"GSM1054242\"\t\"GSM1054243\"\t\"GSM1054244\"\t\"GSM1054245\"\t\"GSM1054246\"\t\"GSM1054247\"\t\"GSM1054248\"\t\"GSM1054249\"\t\"GSM1054250\"\t\"GSM1054251\"\t\"GSM1054252\"\t\"GSM1054253\"\t\"GSM1054254\"\t\"GSM1054255\"\t\"GSM1054256\"\t\"GSM1054257\"\t\"GSM1054258\"\t\"GSM1054259\"\t\"GSM1054260\"\t\"GSM1054261\"\t\"GSM1054262\"\t\"GSM1054263\"\t\"GSM1054264\"\t\"GSM1054265\"\t\"GSM1054266\"\t\"GSM1054267\"\t\"GSM1054268\"\t\"GSM1054269\"\t\"GSM1054270\"\t\"GSM1054271\"\t\"GSM1054272\"\t\"GSM1054273\"\t\"GSM1054274\"\t\"GSM1054275\"\t\"GSM1054276\"\t\"GSM1054277\"\t\"GSM1054278\"\t\"GSM1054279\"\t\"GSM1054280\"\t\"GSM1054281\"\t\"GSM1054282\"\t\"GSM1054283\"\t\"GSM1054284\"\t\"GSM1054285\"\t\"GSM1054286\"\t\"GSM1054287\"\t\"GSM1054288\"\t\"GSM1054289\"\t\"GSM1054290\"\t\"GSM1054291\"\t\"GSM1054292\"\t\"GSM1054293\"\t\"GSM1054294\"\t\"GSM1054295\"\t\"GSM1054296\"\t\"GSM1054297\"\t\"GSM1054298\"\t\"GSM1054299\"\t\"GSM1054300\"\t\"GSM1054301\"\t\"GSM1054302\"\t\"GSM1054303\"\t\"GSM1054304\"\t\"GSM1054305\"\t\"GSM1054306\"\t\"GSM1054307\"\t\"GSM1054308\"\t\"GSM1054309\"\t\"GSM1054310\"\t\"GSM1054311\"\t\"GSM1054312\"\t\"GSM1054313\"\t\"GSM1054314\"\t\"GSM1054315\"\t\"GSM1054316\"\t\"GSM1054317\"\t\"GSM1054318\"\t\"GSM1054319\"\t\"GSM1054320\"\t\"GSM1054321\"\t\"GSM1054322\"\t\"GSM1054323\"\t\"GSM1054324\"\t\"GSM1054325\"\t\"GSM1054326\"\t\"GSM1054327\"\t\"GSM1054328\"\t\"GSM1054329\"\t\"GSM1054330\"\t\"GSM1054331\"\t\"GSM1054332\"\t\"GSM1054333\"\t\"GSM1054334\"\t\"GSM1054335\"\t\"GSM1054336\"\t\"GSM1054337\"\t\"GSM1054338\"\t\"GSM1054339\"\t\"GSM1054340\"\t\"GSM1054341\"\t\"GSM1054342\"\t\"GSM1054343\"\t\"GSM1054344\"\t\"GSM1054345\"\t\"GSM1054346\"\n", "\"ILMN_10000\"\t1.97213678\t1.511342476\t2.845651882\t1.183205546\t2.740848227\t3.472878707\t3.876484332\t7.543180329\t3.854738929\t1.886200927\t3.463953213\t5.009033047\t0.652744551\t2.114305503\t2.171265516\t4.312902395\t2.526042772\t2.21828988\t1.748731769\t3.390602055\t2.167970522\t2.867077265\t2.668538237\t1.87834735\t1.517465811\t1.526428268\t2.641493225\t1.601177336\t1.899241911\t2.057682839\t1.729543277\t1.572387983\t1.369905494\t3.534366631\t1.960147422\t1.355204423\t5.23211452\t1.132382838\t2.025588539\t4.69338109\t1.388931172\t1.151198515\t2.681944174\t1.471433778\t4.533027383\t1.400423011\t1.393079958\t1.293658931\t2.643580654\t1.893566637\t1.568312477\t1.440933553\t1.366866281\t3.75681099\t2.909262789\t7.484452158\t6.374769835\t1.089388086\t2.845397523\t7.924368108\t2.300052019\t6.396018468\t5.429759709\t7.700056226\t13.48266276\t17.83795479\t3.765746078\t4.687909929\t16.98876371\t6.63767068\t4.567333432\t7.360926877\t5.038957706\t11.61986329\t4.260168956\t8.918941826\t3.85705572\t6.462894335\t6.241039537\t3.425260745\t11.13660786\t4.990788284\t4.368996487\t5.709112121\t3.164785769\t3.047859526\t2.821096246\t4.749434563\t4.278474216\t4.634040931\t4.838990727\t1.946007781\t4.91331214\t1.955014643\t6.348106162\t13.62871552\t1.701540381\t2.818438947\t4.896714265\t4.1522303\t3.004485206\t1.245584086\t2.16650936\t5.031600849\t1.518207125\t1.708252887\t1.36859432\t2.208187047\t1.678539883\t2.347179321\t2.308058933\t4.152523002\t4.434661658\t5.518134453\t15.22208821\t8.603092224\t4.540210079\n", "\"ILMN_100000\"\t0.92430452\t0.812419844\t0.937917438\t0.942640233\t0.916635616\t0.87086486\t0.775435804\t0.872981905\t0.897949083\t0.925115393\t0.931406936\t0.784042448\t0.774249283\t0.836470663\t0.829560206\t0.918726729\t0.862447673\t0.864610916\t0.81441991\t0.935047502\t0.798505824\t0.829253983\t0.828126754\t0.921106204\t0.864696333\t0.991548763\t0.811747147\t0.797322359\t0.894742144\t0.868583606\t0.804572415\t0.741236494\t0.863846277\t0.947228086\t0.808751621\t0.950878604\t0.97118564\t0.886984726\t0.942521221\t0.94958604\t0.916177499\t0.880652872\t0.854477439\t0.902331241\t0.93828505\t0.931194683\t0.964259177\t0.909557178\t0.991269968\t0.877717928\t0.950183625\t0.891273639\t1.019485363\t0.879219933\t0.733322886\t0.893194982\t0.721130652\t0.896341003\t0.816557273\t0.88985386\t0.86046412\t0.927248927\t0.857711633\t0.86671828\t0.795698517\t0.859368762\t0.808144915\t0.921266438\t0.961120212\t0.945243959\t0.828783123\t0.872947954\t0.898335969\t0.834877864\t0.851244625\t0.83590174\t0.85290923\t0.855935278\t0.803549503\t0.970600882\t0.863387545\t0.790645777\t0.92801072\t0.90724361\t0.925591331\t0.931092364\t0.941554823\t0.944761444\t0.841500553\t0.879791096\t0.92621795\t0.848519874\t0.804978795\t0.857752948\t0.953408\t0.877683333\t0.868533006\t0.910194167\t0.971557706\t0.799937135\t0.858798839\t0.857350692\t0.871848592\t0.821087684\t0.87038577\t0.885425506\t0.878169578\t0.824272365\t0.884152914\t0.874213575\t0.856159702\t0.943487047\t0.948833934\t0.86990765\t0.857905759\t0.757039644\t0.872258722\n", "\"ILMN_100007\"\t0.909786321\t0.795458125\t0.936011096\t0.857262836\t0.870995257\t0.775896101\t0.81694443\t0.830887223\t0.811599576\t0.82059828\t0.935788237\t0.855341419\t1.115168136\t0.974418777\t0.853854114\t1.003760546\t0.85607859\t0.963998525\t0.99566563\t0.842222466\t0.911135195\t1.10771765\t0.814399691\t0.858283983\t0.774292389\t0.817921564\t0.907429754\t0.998873304\t1.037707071\t1.063768369\t0.824943869\t0.832206831\t0.872858544\t0.965018642\t0.853986266\t0.913750119\t0.81290436\t0.930612992\t0.891027581\t0.825640133\t0.976818589\t0.935508723\t1.026759025\t0.848890939\t0.936306224\t1.036700764\t0.821194689\t0.997210583\t0.905197704\t0.926714787\t0.997120652\t0.984734741\t0.887064131\t0.901188697\t0.97639379\t0.876922204\t0.863696227\t0.843607255\t0.972969247\t0.865164426\t0.994439083\t0.940918803\t0.901515267\t0.817208659\t0.774701508\t0.908237833\t0.857414593\t0.928528278\t0.784531722\t0.792801968\t0.958554064\t0.814403397\t0.987138604\t0.848577187\t0.944243544\t0.89233837\t0.818557459\t0.886612408\t0.918009304\t0.899749522\t0.951491071\t0.929843822\t0.884678617\t0.810501481\t1.025054023\t0.919697112\t0.741046621\t0.898440639\t0.802020313\t0.825674556\t0.859297682\t0.85310639\t0.857281774\t0.857242839\t0.750705359\t0.827882567\t0.957001088\t0.883343779\t0.80298964\t0.885805261\t0.898386711\t0.934957662\t0.781461802\t0.976208289\t0.980613503\t0.779245709\t0.86237471\t0.711004381\t0.835415017\t0.913357161\t0.890036148\t0.805675323\t0.930804249\t0.894137948\t0.817027455\t0.977992642\t0.944993005\n", "\"ILMN_100009\"\t0.883831052\t0.857332875\t0.81142415\t0.90736247\t0.763149102\t0.764960851\t0.845054526\t0.898741032\t0.932021459\t0.951831606\t0.828451916\t0.855877008\t0.949477447\t0.917500318\t0.885066367\t0.847048081\t0.867589567\t0.889560136\t0.84070671\t0.872976176\t0.885128167\t0.800693236\t0.785880395\t0.844421095\t0.841346973\t0.929749096\t0.919272773\t0.798937637\t0.737722529\t0.876440734\t0.986532369\t0.864524189\t0.830362012\t0.975389609\t0.964750444\t0.908679103\t0.912979309\t0.932735938\t0.884577592\t1.278726279\t0.894676286\t0.935256179\t0.858972862\t0.987516012\t0.858850558\t0.936666682\t0.91328371\t0.920458045\t0.841369475\t0.957167316\t0.90230103\t0.9614905\t0.982090672\t0.945635998\t0.858187572\t0.919636763\t0.88269148\t0.791189394\t0.830802469\t0.933524391\t0.857845158\t1.004157359\t0.768124687\t0.852479415\t0.804523555\t0.826549763\t0.947970898\t0.828796223\t0.885129554\t0.872216667\t0.945315529\t0.921683349\t0.987251878\t0.890224848\t0.873469513\t0.875693804\t0.842353003\t1.033890503\t0.868394423\t1.081568869\t0.853121642\t0.937923961\t1.013435777\t0.901807192\t0.87368564\t0.898000812\t0.754216684\t0.781487402\t0.775712729\t1.029647927\t0.896382812\t0.934922943\t0.905984358\t1.0324987\t0.796110438\t0.99527351\t0.845518872\t0.818793283\t0.782257737\t0.900917763\t0.788367344\t0.883951464\t0.901154475\t0.929818283\t0.885141552\t0.774776085\t0.900839438\t0.779347737\t0.912257572\t0.887889168\t0.879680401\t0.869803833\t0.685800368\t0.786593721\t0.752266183\t0.791207807\t0.868820745\n", "Total lines examined: 70\n", "\n", "Attempting to extract gene data from matrix file...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Successfully extracted gene data with 46713 rows\n", "First 20 gene IDs:\n", "Index(['ILMN_10000', 'ILMN_100000', 'ILMN_100007', 'ILMN_100009', 'ILMN_10001',\n", " 'ILMN_100010', 'ILMN_10002', 'ILMN_100028', 'ILMN_100030',\n", " 'ILMN_100031', 'ILMN_100034', 'ILMN_100037', 'ILMN_10004', 'ILMN_10005',\n", " 'ILMN_100054', 'ILMN_100059', 'ILMN_10006', 'ILMN_100075',\n", " 'ILMN_100079', 'ILMN_100083'],\n", " dtype='object', name='ID')\n", "\n", "Gene expression data available: True\n" ] } ], "source": [ "# 1. Get the file paths for the SOFT file and matrix file\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# Add diagnostic code to check file content and structure\n", "print(\"Examining matrix file structure...\")\n", "with gzip.open(matrix_file, 'rt') as file:\n", " table_marker_found = False\n", " lines_read = 0\n", " for i, line in enumerate(file):\n", " lines_read += 1\n", " if '!series_matrix_table_begin' in line:\n", " table_marker_found = True\n", " print(f\"Found table marker at line {i}\")\n", " # Read a few lines after the marker to check data structure\n", " next_lines = [next(file, \"\").strip() for _ in range(5)]\n", " print(\"First few lines after marker:\")\n", " for next_line in next_lines:\n", " print(next_line)\n", " break\n", " if i < 10: # Print first few lines to see file structure\n", " print(f\"Line {i}: {line.strip()}\")\n", " if i > 100: # Don't read the entire file\n", " break\n", " \n", " if not table_marker_found:\n", " print(\"Table marker '!series_matrix_table_begin' not found in first 100 lines\")\n", " print(f\"Total lines examined: {lines_read}\")\n", "\n", "# 2. Try extracting gene expression data from the matrix file again with better diagnostics\n", "try:\n", " print(\"\\nAttempting to extract gene data from matrix file...\")\n", " gene_data = get_genetic_data(matrix_file)\n", " if gene_data.empty:\n", " print(\"Extracted gene expression data is empty\")\n", " is_gene_available = False\n", " else:\n", " print(f\"Successfully extracted gene data with {len(gene_data.index)} rows\")\n", " print(\"First 20 gene IDs:\")\n", " print(gene_data.index[:20])\n", " is_gene_available = True\n", "except Exception as e:\n", " print(f\"Error extracting gene data: {str(e)}\")\n", " print(\"This dataset appears to have an empty or malformed gene expression matrix\")\n", " is_gene_available = False\n", "\n", "print(f\"\\nGene expression data available: {is_gene_available}\")\n", "\n", "# If data extraction failed, try an alternative approach using pandas directly\n", "if not is_gene_available:\n", " print(\"\\nTrying alternative approach to read gene expression data...\")\n", " try:\n", " with gzip.open(matrix_file, 'rt') as file:\n", " # Skip lines until we find the marker\n", " for line in file:\n", " if '!series_matrix_table_begin' in line:\n", " break\n", " \n", " # Try to read the data directly with pandas\n", " gene_data = pd.read_csv(file, sep='\\t', index_col=0)\n", " \n", " if not gene_data.empty:\n", " print(f\"Successfully extracted gene data with alternative method: {gene_data.shape}\")\n", " print(\"First 20 gene IDs:\")\n", " print(gene_data.index[:20])\n", " is_gene_available = True\n", " else:\n", " print(\"Alternative extraction method also produced empty data\")\n", " except Exception as e:\n", " print(f\"Alternative extraction failed: {str(e)}\")\n" ] }, { "cell_type": "markdown", "id": "a9a16013", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "cabba910", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:19:30.815742Z", "iopub.status.busy": "2025-03-25T07:19:30.815619Z", "iopub.status.idle": "2025-03-25T07:19:30.817497Z", "shell.execute_reply": "2025-03-25T07:19:30.817213Z" } }, "outputs": [], "source": [ "# Examining the gene identifiers in the gene expression data\n", "# The identifiers start with \"ILMN_\" which indicates they are Illumina probe IDs\n", "# These are not standard human gene symbols and need to be mapped to gene symbols\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "b3f48989", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "0b8fd438", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:19:30.818703Z", "iopub.status.busy": "2025-03-25T07:19:30.818588Z", "iopub.status.idle": "2025-03-25T07:19:37.930701Z", "shell.execute_reply": "2025-03-25T07:19:37.930270Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Extracting gene annotation data from SOFT file...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Successfully extracted gene annotation data with 5512256 rows\n", "\n", "Gene annotation preview (first few rows):\n", "{'ID': ['ILMN_89282', 'ILMN_35826', 'ILMN_25544', 'ILMN_132331', 'ILMN_105017'], 'GB_ACC': ['BU678343', 'XM_497527.2', 'NM_018433.3', 'AW629334', 'AI818233'], 'Symbol': [nan, 'LOC441782', 'JMJD1A', nan, nan], 'SEQUENCE': ['CTCTCTAAAGGGACAACAGAGTGGACAGTCAAGGAACTCCACATATTCAT', 'GGGGTCAAGCCCAGGTGAAATGTGGATTGGAAAAGTGCTTCCCTTGCCCC', 'CCAGGCTGTAAAAGCAAAACCTCGTATCAGCTCTGGAACAATACCTGCAG', 'CCAGACAGGAAGCATCAAGCCCTTCAGGAAAGAATATGCGAGAGTGCTGC', 'TGTGCAGAAAGCTGATGGAAGGGAGAAAGAATGGAAGTGGGTCACACAGC'], 'Definition': ['UI-CF-EC0-abi-c-12-0-UI.s1 UI-CF-EC0 Homo sapiens cDNA clone UI-CF-EC0-abi-c-12-0-UI 3, mRNA sequence', 'PREDICTED: Homo sapiens similar to spectrin domain with coiled-coils 1 (LOC441782), mRNA.', 'Homo sapiens jumonji domain containing 1A (JMJD1A), mRNA.', 'hi56g05.x1 Soares_NFL_T_GBC_S1 Homo sapiens cDNA clone IMAGE:2976344 3, mRNA sequence', 'wk77d04.x1 NCI_CGAP_Pan1 Homo sapiens cDNA clone IMAGE:2421415 3, mRNA sequence'], 'Ontology': [nan, nan, nan, nan, nan], 'Synonym': [nan, nan, 'TSGA; JMJD1; KIAA0742; DKFZp686A24246; DKFZp686P07111', nan, nan]}\n", "\n", "Column names in gene annotation data:\n", "['ID', 'GB_ACC', 'Symbol', 'SEQUENCE', 'Definition', 'Ontology', 'Synonym']\n", "\n", "The dataset contains GenBank accessions (GB_ACC) that could be used for gene mapping.\n", "Number of rows with GenBank accessions: 5512256 out of 5512256\n" ] } ], "source": [ "# 1. Extract gene annotation data from the SOFT file\n", "print(\"Extracting gene annotation data from SOFT file...\")\n", "try:\n", " # Use the library function to extract gene annotation\n", " gene_annotation = get_gene_annotation(soft_file)\n", " print(f\"Successfully extracted gene annotation data with {len(gene_annotation.index)} rows\")\n", " \n", " # Preview the annotation DataFrame\n", " print(\"\\nGene annotation preview (first few rows):\")\n", " print(preview_df(gene_annotation))\n", " \n", " # Show column names to help identify which columns we need for mapping\n", " print(\"\\nColumn names in gene annotation data:\")\n", " print(gene_annotation.columns.tolist())\n", " \n", " # Check for relevant mapping columns\n", " if 'GB_ACC' in gene_annotation.columns:\n", " print(\"\\nThe dataset contains GenBank accessions (GB_ACC) that could be used for gene mapping.\")\n", " # Count non-null values in GB_ACC column\n", " non_null_count = gene_annotation['GB_ACC'].count()\n", " print(f\"Number of rows with GenBank accessions: {non_null_count} out of {len(gene_annotation)}\")\n", " \n", " if 'SPOT_ID' in gene_annotation.columns:\n", " print(\"\\nThe dataset contains genomic regions (SPOT_ID) that could be used for location-based gene mapping.\")\n", " print(\"Example SPOT_ID format:\", gene_annotation['SPOT_ID'].iloc[0])\n", " \n", "except Exception as e:\n", " print(f\"Error processing gene annotation data: {e}\")\n", " is_gene_available = False\n" ] }, { "cell_type": "markdown", "id": "3eab320e", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "e2d3f091", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:19:37.932276Z", "iopub.status.busy": "2025-03-25T07:19:37.932148Z", "iopub.status.idle": "2025-03-25T07:19:39.612059Z", "shell.execute_reply": "2025-03-25T07:19:39.611686Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Creating gene mapping dataframe...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Created mapping dataframe with 28566 entries\n", "\n", "Gene mapping preview (first few rows):\n", "{'ID': ['ILMN_35826', 'ILMN_25544', 'ILMN_10519', 'ILMN_17234', 'ILMN_19244'], 'Gene': ['LOC441782', 'JMJD1A', 'NCOA3', 'LOC389834', 'C17orf77']}\n", "\n", "Applying gene mapping to convert probe-level measurements to gene expression data...\n", "Successfully created gene expression data with 18401 genes and 117 samples\n", "\n", "Preview of mapped gene expression data (first few genes):\n", "{'GSM1054230': [0.90327597, 1.719921405, 27.15464165, 0.893225647, 1.357178552], 'GSM1054231': [0.821579705, 8.432092685, 17.07091413, 0.963601712, 1.423178661], 'GSM1054232': [0.865428376, 1.797851622, 34.4908899, 0.996713509, 1.518340034], 'GSM1054233': [0.890772454, 6.514503905, 9.773920808, 1.108153429, 1.352149752], 'GSM1054234': [0.986433802, 1.802559848, 31.28273099, 0.855068422, 1.415984108], 'GSM1054235': [1.197420108, 1.728039444, 20.56960997, 1.076571746, 1.592974841], 'GSM1054236': [0.886271319, 1.944330061, 65.49547785, 0.943271425, 1.484344839], 'GSM1054237': [1.117455448, 1.763054276, 77.84267419, 1.01799184, 1.446382162], 'GSM1054238': [1.003215076, 1.8563891799999999, 30.99583781, 0.925794425, 1.389944357], 'GSM1054239': [0.8657004, 1.85434886, 41.2363808, 0.964498975, 1.31492275], 'GSM1054240': [0.920886682, 1.794471636, 33.85992784, 0.994252201, 1.37597465], 'GSM1054241': [1.041469217, 2.398637294, 21.83155725, 1.115562525, 1.464492594], 'GSM1054242': [0.862234219, 1.789859385, 34.39943961, 1.075635555, 1.439014749], 'GSM1054243': [0.975141487, 1.8464787239999998, 11.35204913, 1.011128717, 1.318847312], 'GSM1054244': [0.97632683, 1.7940997310000002, 16.37900347, 1.075788757, 1.333629705], 'GSM1054245': [0.941206957, 2.030280769, 19.40561644, 0.986493099, 1.276655121], 'GSM1054246': [0.952951484, 1.692139176, 13.08533851, 1.026407969, 1.403822735], 'GSM1054247': [1.052144378, 1.6537894400000002, 44.92530828, 1.057747381, 1.202822513], 'GSM1054248': [1.06901898, 1.8034191800000001, 16.27079017, 0.934226059, 1.275000407], 'GSM1054249': [0.817575891, 1.656417737, 29.0755566, 0.914980088, 1.177920654], 'GSM1054250': [0.923228893, 1.723610769, 35.4819638, 0.912702783, 1.209597233], 'GSM1054251': [1.0619905, 1.7020051729999999, 8.427137827, 0.954152521, 1.125693411], 'GSM1054252': [0.902078949, 1.6684246159999998, 21.94745336, 0.951926704, 1.081380357], 'GSM1054253': [1.130372463, 1.82854029, 20.5988375, 0.924802602, 1.274450986], 'GSM1054254': [0.890391635, 1.897389974, 16.00861124, 0.999029193, 1.160098526], 'GSM1054255': [0.91809387, 1.6422701370000001, 11.79361529, 0.998139809, 1.174763654], 'GSM1054256': [0.987420948, 2.1985615370000002, 4.870497655, 0.895641194, 1.304058271], 'GSM1054257': [0.925706766, 1.696486357, 30.84609759, 0.940458568, 1.360171178], 'GSM1054258': [0.884802924, 1.6601248339999999, 9.044961629, 0.94399641, 1.323157527], 'GSM1054259': [1.050568499, 1.727040237, 18.60270805, 0.999773583, 1.59523651], 'GSM1054260': [0.852329662, 1.7650923880000002, 64.07088227, 1.122273399, 1.150640915], 'GSM1054261': [0.74138757, 1.831124557, 3.088465321, 1.118586165, 1.149357949], 'GSM1054262': [0.972487442, 1.819879728, 6.447222978, 1.219898987, 1.258655504], 'GSM1054263': [0.84891427, 1.733686695, 70.23525491, 1.068080297, 1.279363562], 'GSM1054264': [0.983269193, 1.9594389840000002, 9.852659528, 1.036503326, 1.376039264], 'GSM1054265': [0.993313903, 1.6961195660000001, 6.006681294, 1.041101756, 1.294475454], 'GSM1054266': [0.856049963, 1.813856055, 7.372134477, 1.05024199, 1.377369235], 'GSM1054267': [0.945501746, 1.8645604759999999, 28.8496831, 1.271095625, 1.127551134], 'GSM1054268': [0.937282293, 1.7764429019999999, 44.43823232, 1.091532944, 1.298084533], 'GSM1054269': [1.043230126, 2.064904422, 26.15425343, 1.05527449, 1.338862893], 'GSM1054270': [0.925125715, 1.796533259, 11.8193806, 0.994589658, 1.20369047], 'GSM1054271': [0.887935557, 1.844441623, 4.364104988, 1.088725035, 1.413264676], 'GSM1054272': [0.86078311, 1.709824642, 51.35679913, 1.054120194, 1.446405166], 'GSM1054273': [0.879984681, 1.802505238, 17.61946959, 1.009420611, 1.396662859], 'GSM1054274': [0.990567807, 1.9786616700000002, 3.39162897, 0.930753086, 1.283837186], 'GSM1054275': [0.844597204, 1.7188247190000001, 8.557410667, 0.976632566, 1.484398616], 'GSM1054276': [0.877467514, 5.272151963, 3.086842146, 1.033423069, 1.336847845], 'GSM1054277': [0.873767443, 1.8926725660000001, 3.914997062, 1.057540535, 1.490713772], 'GSM1054278': [0.984425034, 1.8094490580000002, 18.80268275, 1.126990612, 1.199882396], 'GSM1054279': [0.8292923, 1.899462925, 33.94322435, 1.000074063, 1.297542879], 'GSM1054280': [0.909251661, 1.8606761980000002, 14.00076549, 1.064594383, 1.162216087], 'GSM1054281': [0.906282504, 1.7826964379999999, 30.32396908, 1.013825279, 1.204899934], 'GSM1054282': [0.885847428, 1.7346323300000002, 8.23070521, 1.16244182, 1.431629798], 'GSM1054283': [0.798346959, 1.679732606, 51.79804713, 1.023892447, 1.276746461], 'GSM1054284': [0.934321032, 1.680003026, 184.018555, 0.976162341, 1.469861272], 'GSM1054285': [0.928852206, 4.3149474119999995, 88.20377361, 1.029250442, 1.285264181], 'GSM1054286': [0.962766949, 2.33713382, 4.83595157, 1.02034898, 1.166387542], 'GSM1054287': [0.892718442, 1.8118692210000003, 12.94806987, 1.087984677, 1.227845838], 'GSM1054288': [1.166702259, 1.690196785, 62.14703322, 1.082039215, 1.324330504], 'GSM1054289': [1.001282333, 1.9322206729999998, 2.853788164, 1.05405931, 1.305681571], 'GSM1054290': [0.950291173, 1.741444258, 37.5353194, 1.025750029, 1.276569592], 'GSM1054291': [0.815483457, 1.847955186, 25.72854706, 0.965352557, 1.321914342], 'GSM1054292': [0.883435912, 1.7941480309999998, 29.47260653, 1.232206454, 1.374922569], 'GSM1054293': [0.8590696, 1.8013292669999998, 23.60185428, 1.157716254, 1.392822008], 'GSM1054294': [0.873441587, 1.781106231, 23.86460011, 1.004470058, 1.367830515], 'GSM1054295': [0.915059349, 1.694289234, 53.92729435, 1.006244731, 1.235820813], 'GSM1054296': [0.94831139, 1.890085524, 6.254716055, 1.077018725, 1.094385545], 'GSM1054297': [0.774934749, 1.72334974, 14.37620071, 1.06500779, 1.264698532], 'GSM1054298': [1.09303552, 1.7959108129999999, 82.41286172, 0.930053647, 1.220911792], 'GSM1054299': [0.875206244, 1.768146476, 54.4014954, 1.039324135, 1.246832312], 'GSM1054300': [0.923089501, 1.827368067, 69.97849307, 1.00770527, 1.099447941], 'GSM1054301': [0.923481581, 1.726372293, 51.16281917, 0.992299849, 1.070480197], 'GSM1054302': [0.956046522, 1.794795028, 13.3423642, 0.995728561, 1.096099737], 'GSM1054303': [0.856466351, 2.186983115, 27.46221349, 0.93184917, 1.232729415], 'GSM1054304': [0.844187889, 2.015159296, 11.92524808, 1.013397695, 1.333740922], 'GSM1054305': [0.902270578, 1.728670395, 48.42092777, 1.039977721, 1.246349304], 'GSM1054306': [0.876351564, 2.06265051, 14.5771708, 0.994830459, 1.107707154], 'GSM1054307': [0.927569379, 1.820702701, 37.17106882, 0.881774007, 1.079198478], 'GSM1054308': [0.871306059, 1.973887374, 14.76510917, 1.100763225, 1.433394927], 'GSM1054309': [0.95856352, 1.6950422669999998, 43.94979343, 0.966476759, 1.43266769], 'GSM1054310': [0.860755365, 1.746536237, 30.02884859, 0.981404694, 1.238391801], 'GSM1054311': [0.882104356, 1.800275557, 27.33775619, 0.972366617, 1.33168691], 'GSM1054312': [0.887314075, 1.782551165, 72.17489915, 0.954029701, 1.681058877], 'GSM1054313': [1.017168717, 1.883909197, 30.07254639, 1.016846367, 1.229764915], 'GSM1054314': [0.824439136, 1.942868023, 6.79789901, 1.053501626, 0.945116822], 'GSM1054315': [0.875594747, 1.819213515, 17.28166643, 1.030544153, 1.046340241], 'GSM1054316': [0.834611628, 1.996283204, 7.618171427, 1.100482348, 1.349101786], 'GSM1054317': [0.883481364, 1.93530208, 22.02778029, 1.182168349, 1.134976755], 'GSM1054318': [0.932256938, 1.7107700780000001, 11.77628842, 1.173428524, 1.070526307], 'GSM1054319': [0.895504508, 1.69534505, 26.3679573, 1.060125009, 1.388124148], 'GSM1054320': [1.005772667, 1.823580848, 30.28610376, 0.985401831, 1.424969135], 'GSM1054321': [1.039865671, 1.773514604, 116.2325841, 1.003518176, 1.477547154], 'GSM1054322': [0.941116355, 1.9163148429999999, 26.17940414, 0.997899688, 1.240736301], 'GSM1054323': [0.81848852, 1.77035441, 84.5888097, 1.089781735, 1.282122116], 'GSM1054324': [1.085220286, 1.9155829839999998, 27.61866381, 1.03826735, 1.19996765], 'GSM1054325': [1.018671251, 1.995078332, 34.34295245, 1.091120921, 1.300126959], 'GSM1054326': [0.866952758, 1.683057166, 8.399355486, 1.131556826, 1.0872441], 'GSM1054327': [0.941202973, 1.654332872, 53.39261845, 1.097743039, 1.384221835], 'GSM1054328': [1.100714527, 1.811275653, 43.37536178, 1.090127439, 1.524535072], 'GSM1054329': [0.884145969, 1.724862497, 29.77831561, 0.969565313, 1.750502141], 'GSM1054330': [0.86434383, 1.802196844, 5.747376637, 1.129029539, 1.363649633], 'GSM1054331': [0.962813346, 2.884386969, 46.88678433, 0.915450861, 1.407816095], 'GSM1054332': [1.0625479, 1.692611353, 22.17475025, 1.051505895, 1.254324751], 'GSM1054333': [1.026116861, 1.6769867719999998, 132.224517, 0.955340512, 1.564768137], 'GSM1054334': [1.001319954, 1.8507945829999999, 35.04825102, 0.930194918, 1.177505784], 'GSM1054335': [0.997883151, 1.8414863559999999, 28.26388495, 0.941592048, 1.322204691], 'GSM1054336': [0.964322644, 1.861324666, 27.71599682, 0.953907518, 1.489267878], 'GSM1054337': [0.85599028, 1.788184322, 35.78189512, 1.070994352, 1.488361478], 'GSM1054338': [0.897685722, 1.782778518, 43.58090099, 1.050752456, 1.419630848], 'GSM1054339': [0.884723021, 1.929291724, 32.65168926, 1.000574114, 1.59399], 'GSM1054340': [0.925664052, 1.9300754310000001, 25.6556241, 1.029542146, 1.41424754], 'GSM1054341': [1.061454739, 1.844572978, 28.99630264, 1.056356877, 1.362292327], 'GSM1054342': [0.868971862, 1.753931842, 22.16511598, 1.102939995, 1.279548347], 'GSM1054343': [0.96121084, 1.8590752030000002, 21.97249737, 0.976782146, 1.113989558], 'GSM1054344': [0.802412406, 1.5231825749999999, 22.61825781, 1.146317464, 1.113299053], 'GSM1054345': [0.964032906, 1.742776603, 22.30283591, 1.128792893, 1.135270664], 'GSM1054346': [1.097807274, 1.799859096, 34.70312323, 0.950304892, 1.320154528]}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data saved to ../../output/preprocess/Kidney_Papillary_Cell_Carcinoma/gene_data/GSE42977.csv\n" ] } ], "source": [ "# 1. Identify the relevant columns for gene mapping\n", "# From the gene annotation preview, we can see:\n", "# - 'ID' column contains probe IDs with 'ILMN_' prefix (matching our gene expression data)\n", "# - 'Symbol' column contains the gene symbols we need\n", "\n", "print(\"Creating gene mapping dataframe...\")\n", "try:\n", " # Extract the mapping data from gene annotation\n", " mapping_df = get_gene_mapping(gene_annotation, 'ID', 'Symbol')\n", " print(f\"Created mapping dataframe with {len(mapping_df)} entries\")\n", " \n", " # Preview the mapping data\n", " print(\"\\nGene mapping preview (first few rows):\")\n", " print(preview_df(mapping_df))\n", " \n", " # 3. Apply the gene mapping to convert probe-level data to gene expression data\n", " print(\"\\nApplying gene mapping to convert probe-level measurements to gene expression data...\")\n", " gene_data = apply_gene_mapping(gene_data, mapping_df)\n", " \n", " # Check the resulting gene expression data\n", " print(f\"Successfully created gene expression data with {len(gene_data.index)} genes and {gene_data.shape[1]} samples\")\n", " print(\"\\nPreview of mapped gene expression data (first few genes):\")\n", " print(preview_df(gene_data.head()))\n", " \n", " # Create the output directory if it doesn't exist\n", " os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", " \n", " # Save the gene expression data\n", " gene_data.to_csv(out_gene_data_file)\n", " print(f\"Gene expression data saved to {out_gene_data_file}\")\n", " \n", "except Exception as e:\n", " print(f\"Error during gene mapping: {e}\")\n", " is_gene_available = False\n" ] }, { "cell_type": "markdown", "id": "827b12f2", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "6588d685", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:19:39.613474Z", "iopub.status.busy": "2025-03-25T07:19:39.613334Z", "iopub.status.idle": "2025-03-25T07:19:41.009395Z", "shell.execute_reply": "2025-03-25T07:19:41.009019Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Normalizing gene symbols...\n", "Loaded gene data with 18401 genes and 117 samples\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "After normalization: 17207 genes\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Kidney_Papillary_Cell_Carcinoma/gene_data/GSE42977.csv\n", "\n", "Checking clinical data availability...\n", "\n", "Performing final validation...\n", "Abnormality detected in the cohort: GSE42977. Preprocessing failed.\n", "Dataset usability for Kidney_Papillary_Cell_Carcinoma association studies: False\n", "Reason: Dataset does not contain kidney papillary cell carcinoma samples. It focuses on Malignant Pleural Mesothelioma (MPM).\n" ] } ], "source": [ "# 1. Normalize gene symbols in the gene expression data\n", "print(\"\\nNormalizing gene symbols...\")\n", "try:\n", " # Load gene data that was saved in step 6\n", " gene_data = pd.read_csv(out_gene_data_file, index_col=0)\n", " print(f\"Loaded gene data with {gene_data.shape[0]} genes and {gene_data.shape[1]} samples\")\n", " \n", " # Normalize gene symbols using NCBI Gene database\n", " gene_data = normalize_gene_symbols_in_index(gene_data)\n", " print(f\"After normalization: {gene_data.shape[0]} genes\")\n", " \n", " # Save the normalized gene data\n", " os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", " gene_data.to_csv(out_gene_data_file)\n", " print(f\"Normalized gene data saved to {out_gene_data_file}\")\n", " \n", " is_gene_available = True\n", "except Exception as e:\n", " print(f\"Error normalizing gene data: {e}\")\n", " is_gene_available = False\n", "\n", "# 2. Handle clinical data - based on step 2 determination that trait is not available\n", "print(\"\\nChecking clinical data availability...\")\n", "# From step 2: \"The trait we are looking for (Kidney_Papillary_Cell_Carcinoma) is not present\"\n", "is_trait_available = False\n", "note = \"Dataset does not contain kidney papillary cell carcinoma samples. It focuses on Malignant Pleural Mesothelioma (MPM).\"\n", "\n", "# 3. Validate and save the cohort information\n", "print(\"\\nPerforming final validation...\")\n", "is_biased = True # Not applicable since trait is unavailable\n", "linked_data = pd.DataFrame() # Empty DataFrame since we can't link without trait data\n", "\n", "is_usable = validate_and_save_cohort_info(\n", " is_final=True,\n", " cohort=cohort,\n", " info_path=json_path,\n", " is_gene_available=is_gene_available,\n", " is_trait_available=is_trait_available,\n", " is_biased=is_biased,\n", " df=linked_data,\n", " note=note\n", ")\n", "\n", "print(f\"Dataset usability for {trait} association studies: {is_usable}\")\n", "if not is_usable:\n", " print(f\"Reason: {note}\")" ] } ], "metadata": { "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.10.16" } }, "nbformat": 4, "nbformat_minor": 5 }