{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "6bf709ef", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:18:36.957518Z", "iopub.status.busy": "2025-03-25T07:18:36.957329Z", "iopub.status.idle": "2025-03-25T07:18:37.126100Z", "shell.execute_reply": "2025-03-25T07:18:37.125716Z" } }, "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_Clear_Cell_Carcinoma\"\n", "cohort = \"GSE245862\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Kidney_Clear_Cell_Carcinoma\"\n", "in_cohort_dir = \"../../input/GEO/Kidney_Clear_Cell_Carcinoma/GSE245862\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Kidney_Clear_Cell_Carcinoma/GSE245862.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Kidney_Clear_Cell_Carcinoma/gene_data/GSE245862.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Kidney_Clear_Cell_Carcinoma/clinical_data/GSE245862.csv\"\n", "json_path = \"../../output/preprocess/Kidney_Clear_Cell_Carcinoma/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "8f7d0f9b", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "f2d94b93", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:18:37.127591Z", "iopub.status.busy": "2025-03-25T07:18:37.127446Z", "iopub.status.idle": "2025-03-25T07:18:37.224717Z", "shell.execute_reply": "2025-03-25T07:18:37.224371Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"STAT3 phosphorylation at serine 727 activates specific genetic programs and promotes clear cell renal cell carcinoma (ccRCC) aggressiveness\"\n", "!Series_summary\t\"The signal transducer and activator of transcription 3 (STAT3) is a transcription factor mainly activated by phosphorylation in either tyrosine 705 (Y705) or serine 727 (S727) residues that regulates essential processes such as cell differentiation, apoptosis inhibition, or cell survival.\"\n", "!Series_summary\t\"we used microarrays to evaluate the effects of the STAT3 phosphomutants on global gene expression and identify the genes and pathways regulated by different STAT3 phosphorylation states in the 769-P cell line.\"\n", "!Series_overall_design\t\"we have generated human-derived ccRCC cell lines carrying STAT3 Y705 and S727 phosphomutants to identify genes and pathways regulated by pS727 that could be distinguished from those regulated by pY705 or by the combination of both. First, 769-P cells were depleted of endogenous STAT3 using shRNA and STAT3 WT form was then rescued. On this rescued STAT3 gene backbone, Y705 and S727 STAT3 phosphomutants were generated by introducing structurally similar amino acids that prevent (phosphoablative) or mimic (phosphomimetic) phosphorylation for each residue. A phosphomimetic substitution for Y705, however, was not possible since tyrosine is an aromatic amino acid and neither aspartic nor glutamic acid resembles the structure or charge density of a phosphotyrosine. To overcome this, we used interleukin-6 (IL6), a classic activator of the JAK/STAT3 pathway via pY705.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['phenotype: Normal expression of endogenous STAT3', 'phenotype: Absence (reduction) of endogenous STAT3', 'phenotype: Normal activity of STAT3', 'phenotype: Tyr705 cannot be phosphorylated, free Ser727', 'phenotype: Ser727 cannot be phosphorylated, free Tyr705', 'phenotype: Ser727 artificially phosphorylated, free Tyr705', 'phenotype: Both, Tyr705 and Ser727, cannot be phosphorylated', 'phenotype: Tyr705 cannot be phosphorylated, Ser727 artificially phosphorylated']}\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": "547d1f94", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "9ede595c", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:18:37.226019Z", "iopub.status.busy": "2025-03-25T07:18:37.225887Z", "iopub.status.idle": "2025-03-25T07:18:37.234220Z", "shell.execute_reply": "2025-03-25T07:18:37.233880Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Clinical Data Preview:\n", "{'GSM7850012': [0.0], 'GSM7850013': [1.0], 'GSM7850014': [1.0], 'GSM7850015': [0.0], 'GSM7850016': [1.0], 'GSM7850017': [1.0], 'GSM7850018': [1.0], 'GSM7850019': [1.0], 'GSM7850020': [1.0], 'GSM7850021': [0.0], 'GSM7850022': [1.0], 'GSM7850023': [1.0], 'GSM7850024': [0.0], 'GSM7850025': [1.0], 'GSM7850026': [1.0], 'GSM7850027': [1.0], 'GSM7850028': [1.0], 'GSM7850029': [1.0], 'GSM7850030': [0.0], 'GSM7850031': [1.0], 'GSM7850032': [1.0], 'GSM7850033': [0.0], 'GSM7850034': [1.0], 'GSM7850035': [1.0], 'GSM7850036': [1.0], 'GSM7850038': [1.0], 'GSM7850039': [1.0], 'GSM7850040': [0.0], 'GSM7850041': [1.0], 'GSM7850042': [1.0], 'GSM7850043': [0.0], 'GSM7850044': [1.0], 'GSM7850045': [1.0], 'GSM7850046': [1.0], 'GSM7850047': [1.0], 'GSM7850048': [1.0], 'GSM7850049': [0.0], 'GSM7850050': [1.0], 'GSM7850051': [1.0], 'GSM7850052': [0.0], 'GSM7850053': [1.0], 'GSM7850054': [1.0], 'GSM7850055': [1.0], 'GSM7850056': [1.0], 'GSM7850057': [1.0]}\n", "Clinical data saved to ../../output/preprocess/Kidney_Clear_Cell_Carcinoma/clinical_data/GSE245862.csv\n" ] } ], "source": [ "import pandas as pd\n", "import os\n", "import numpy as np\n", "import re\n", "import json\n", "from typing import Callable, Optional, Dict, Any\n", "\n", "# 1. Gene Expression Data Availability\n", "# Based on the background information, this dataset contains gene expression data from microarray experiments\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# Looking at the sample characteristics dictionary, we can see different phenotypes at index 0\n", "# These phenotypes describe different STAT3 phosphorylation states in the ccRCC cell line\n", "\n", "# 2.1 Data Availability\n", "# For the trait (kidney clear cell carcinoma), we can use the phenotype information at index 0\n", "trait_row = 0\n", "\n", "# Age and gender information are not available in this dataset\n", "age_row = None\n", "gender_row = None\n", "\n", "# 2.2 Data Type Conversion Functions\n", "def convert_trait(value):\n", " if not isinstance(value, str):\n", " return None\n", " \n", " # Extract value after colon if present\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Based on the phenotypes, we can categorize into normal vs altered STAT3 states\n", " # Normal STAT3 will be 0, altered STAT3 will be 1\n", " if \"Normal expression of endogenous STAT3\" in value or \"Normal activity of STAT3\" in value:\n", " return 0 # Control/normal\n", " elif any(term in value for term in [\n", " \"Absence\", \"reduction\", \"cannot be phosphorylated\", \"artificially phosphorylated\"\n", " ]):\n", " return 1 # Altered STAT3 state\n", " else:\n", " return None\n", "\n", "def convert_age(value):\n", " # Not available in this dataset\n", " return None\n", "\n", "def convert_gender(value):\n", " # Not available in this dataset\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Conduct initial filtering on the usability of the dataset\n", "is_trait_available = trait_row is not None\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\n", "if trait_row is not None:\n", " try:\n", " # Use the clinical_data variable directly from the previous step\n", " # Extract clinical features\n", " selected_clinical_df = geo_select_clinical_features(\n", " clinical_df=clinical_data,\n", " trait=trait,\n", " trait_row=trait_row,\n", " convert_trait=convert_trait,\n", " age_row=age_row,\n", " convert_age=convert_age,\n", " gender_row=gender_row,\n", " convert_gender=convert_gender\n", " )\n", " \n", " # Preview the data\n", " print(\"Clinical Data Preview:\")\n", " print(preview_df(selected_clinical_df))\n", " \n", " # Save the extracted clinical features\n", " os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", " selected_clinical_df.to_csv(out_clinical_data_file, index=False)\n", " print(f\"Clinical data saved to {out_clinical_data_file}\")\n", " except Exception as e:\n", " print(f\"Error extracting clinical features: {str(e)}\")\n", "else:\n", " print(\"Clinical data is not available for this dataset.\")\n" ] }, { "cell_type": "markdown", "id": "dc1733a5", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "48d82e2d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:18:37.235279Z", "iopub.status.busy": "2025-03-25T07:18:37.235167Z", "iopub.status.idle": "2025-03-25T07:18:37.386135Z", "shell.execute_reply": "2025-03-25T07:18:37.385498Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Extracting gene data from matrix file:\n", "Successfully extracted gene data with 27189 rows\n", "First 20 gene IDs:\n", "Index(['23064070', '23064071', '23064072', '23064073', '23064074', '23064075',\n", " '23064076', '23064077', '23064078', '23064079', '23064080', '23064081',\n", " '23064083', '23064084', '23064085', '23064086', '23064087', '23064088',\n", " '23064089', '23064090'],\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", "# 2. Extract gene expression data from the matrix file\n", "try:\n", " print(\"Extracting 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: {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" ] }, { "cell_type": "markdown", "id": "3e0a84b9", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "d9a9d57c", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:18:37.387560Z", "iopub.status.busy": "2025-03-25T07:18:37.387440Z", "iopub.status.idle": "2025-03-25T07:18:37.389705Z", "shell.execute_reply": "2025-03-25T07:18:37.389287Z" } }, "outputs": [], "source": [ "# Looking at the gene identifiers, these appear to be probe IDs or numeric identifiers,\n", "# not standard human gene symbols (which would be alphanumeric like BRCA1, TP53, etc.)\n", "# These numeric IDs (23064070, etc.) would need to be mapped to gene symbols for biological interpretation.\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "f0a01096", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "74c255f5", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:18:37.390867Z", "iopub.status.busy": "2025-03-25T07:18:37.390758Z", "iopub.status.idle": "2025-03-25T07:18:40.310878Z", "shell.execute_reply": "2025-03-25T07:18:40.310225Z" } }, "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 1250739 rows\n", "\n", "Gene annotation preview (first few rows):\n", "{'ID': ['TC0100006437.hg.1', 'TC0100006476.hg.1', 'TC0100006479.hg.1', 'TC0100006480.hg.1', 'TC0100006483.hg.1'], 'probeset_id': ['TC0100006437.hg.1', 'TC0100006476.hg.1', 'TC0100006479.hg.1', 'TC0100006480.hg.1', 'TC0100006483.hg.1'], 'seqname': ['chr1', 'chr1', 'chr1', 'chr1', 'chr1'], 'strand': ['+', '+', '+', '+', '+'], 'start': ['69091', '924880', '960587', '966497', '1001138'], 'stop': ['70008', '944581', '965719', '975865', '1014541'], 'total_probes': [10.0, 10.0, 10.0, 10.0, 10.0], 'category': ['main', 'main', 'main', 'main', 'main'], 'SPOT_ID': ['Coding', 'Multiple_Complex', 'Multiple_Complex', 'Multiple_Complex', 'Multiple_Complex'], 'SPOT_ID.1': ['NM_001005484 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 5 (OR4F5), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000335137 // ENSEMBL // olfactory receptor, family 4, subfamily F, member 5 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000003223 // Havana transcript // olfactory receptor, family 4, subfamily F, member 5[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// uc001aal.1 // UCSC Genes // Homo sapiens olfactory receptor, family 4, subfamily F, member 5 (OR4F5), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS30547.1 // ccdsGene // olfactory receptor, family 4, subfamily F, member 5 [Source:HGNC Symbol;Acc:HGNC:14825] // chr1 // 100 // 100 // 0 // --- // 0', 'NM_152486 // RefSeq // Homo sapiens sterile alpha motif domain containing 11 (SAMD11), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000341065 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000342066 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000420190 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000437963 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000455979 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000464948 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000466827 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000474461 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000478729 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:processed_transcript] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000616016 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000616125 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000617307 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000618181 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000618323 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000618779 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000620200 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000622503 // ENSEMBL // sterile alpha motif domain containing 11 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// BC024295 // GenBank // Homo sapiens sterile alpha motif domain containing 11, mRNA (cDNA clone MGC:39333 IMAGE:3354502), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// BC033213 // GenBank // Homo sapiens sterile alpha motif domain containing 11, mRNA (cDNA clone MGC:45873 IMAGE:5014368), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097860 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097862 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097863 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097865 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:processed_transcript] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097866 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097867 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097868 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000276866 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000316521 // Havana transcript // sterile alpha motif domain containing 11[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS2.2 // ccdsGene // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009185 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009186 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009187 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009188 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009189 // circbase // Salzman2013 ALT_DONOR, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009190 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009191 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009192 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009193 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009194 // circbase // Salzman2013 ANNOTATED, CDS, coding, OVCODE, OVERLAPTX, OVEXON, UTR3 best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009195 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVERLAPTX, OVEXON best transcript NM_152486 // chr1 // 100 // 100 // 0 // --- // 0 /// uc001abw.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pjt.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pju.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pkg.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pkh.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pkk.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pkm.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc031pko.2 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axs.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axt.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axu.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axv.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axw.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axx.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axy.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057axz.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057aya.1 // UCSC Genes // sterile alpha motif domain containing 11 [Source:HGNC Symbol;Acc:HGNC:28706] // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000212 // lncRNAWiki // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000212 // NONCODE // Non-coding transcript identified by NONCODE: Exonic // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000213 // lncRNAWiki // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000213 // NONCODE // Non-coding transcript identified by NONCODE: Exonic // chr1 // 100 // 100 // 0 // --- // 0', 'NM_198317 // RefSeq // Homo sapiens kelch-like family member 17 (KLHL17), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000338591 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000463212 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000466300 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:nonsense_mediated_decay] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000481067 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000622660 // ENSEMBL // kelch-like family member 17 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097875 // Havana transcript // kelch-like 17 (Drosophila)[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097877 // Havana transcript // kelch-like 17 (Drosophila)[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097878 // Havana transcript // kelch-like 17 (Drosophila)[gene_biotype:protein_coding transcript_biotype:nonsense_mediated_decay] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097931 // Havana transcript // kelch-like 17 (Drosophila)[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// BC166618 // GenBank // Synthetic construct Homo sapiens clone IMAGE:100066344, MGC:195481 kelch-like 17 (Drosophila) (KLHL17) mRNA, encodes complete protein. // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS30550.1 // ccdsGene // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009209 // circbase // Salzman2013 ANNOTATED, CDS, coding, INTERNAL, OVCODE, OVEXON best transcript NM_198317 // chr1 // 100 // 100 // 0 // --- // 0 /// uc001aca.3 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc001acb.2 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayg.1 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayh.1 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayi.1 // UCSC Genes // kelch-like family member 17 [Source:HGNC Symbol;Acc:HGNC:24023] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayj.1 // UCSC Genes // N/A // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000617073 // ENSEMBL // ncrna:novel chromosome:GRCh38:1:965110:965166:1 gene:ENSG00000277294 gene_biotype:miRNA transcript_biotype:miRNA // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000216 // lncRNAWiki // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000216 // NONCODE // Non-coding transcript identified by NONCODE: Exonic // chr1 // 100 // 100 // 0 // --- // 0', 'NM_001160184 // RefSeq // Homo sapiens pleckstrin homology domain containing, family N member 1 (PLEKHN1), transcript variant 2, mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// NM_032129 // RefSeq // Homo sapiens pleckstrin homology domain containing, family N member 1 (PLEKHN1), transcript variant 1, mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000379407 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000379409 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000379410 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000480267 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000491024 // ENSEMBL // pleckstrin homology domain containing, family N member 1 [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// BC101386 // GenBank // Homo sapiens pleckstrin homology domain containing, family N member 1, mRNA (cDNA clone MGC:120613 IMAGE:40026400), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// BC101387 // GenBank // Homo sapiens pleckstrin homology domain containing, family N member 1, mRNA (cDNA clone MGC:120616 IMAGE:40026404), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097940 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097941 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:retained_intron] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097942 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000473255 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000473256 // Havana transcript // pleckstrin homology domain containing, family N member 1[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS4.1 // ccdsGene // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS53256.1 // ccdsGene // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// PLEKHN1.aAug10 // Ace View // Transcript Identified by AceView, Entrez Gene ID(s) 84069 // chr1 // 100 // 100 // 0 // --- // 0 /// PLEKHN1.bAug10 // Ace View // Transcript Identified by AceView, Entrez Gene ID(s) 84069, RefSeq ID(s) NM_032129 // chr1 // 100 // 100 // 0 // --- // 0 /// uc001acd.4 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// uc001ace.4 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// uc001acf.4 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayk.1 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayl.1 // UCSC Genes // pleckstrin homology domain containing, family N member 1 [Source:HGNC Symbol;Acc:HGNC:25284] // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000217 // lncRNAWiki // Non-coding transcript identified by NONCODE // chr1 // 100 // 100 // 0 // --- // 0 /// NONHSAT000217 // NONCODE // Non-coding transcript identified by NONCODE: Exonic // chr1 // 100 // 100 // 0 // --- // 0', 'NM_005101 // RefSeq // Homo sapiens ISG15 ubiquitin-like modifier (ISG15), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000379389 // ENSEMBL // ISG15 ubiquitin-like modifier [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000624652 // ENSEMBL // ISG15 ubiquitin-like modifier [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000624697 // ENSEMBL // ISG15 ubiquitin-like modifier [gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// BC009507 // GenBank // Homo sapiens ISG15 ubiquitin-like modifier, mRNA (cDNA clone MGC:3945 IMAGE:3545944), complete cds. // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000097989 // Havana transcript // ISG15 ubiquitin-like modifier[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000479384 // Havana transcript // ISG15 ubiquitin-like modifier[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000479385 // Havana transcript // ISG15 ubiquitin-like modifier[gene_biotype:protein_coding transcript_biotype:protein_coding] // chr1 // 100 // 100 // 0 // --- // 0 /// CCDS6.1 // ccdsGene // ISG15 ubiquitin-like modifier [Source:HGNC Symbol;Acc:HGNC:4053] // chr1 // 100 // 100 // 0 // --- // 0 /// hsa_circ_0009211 // circbase // Salzman2013 ANNOTATED, CDS, coding, OVCODE, OVEXON, UTR3 best transcript NM_005101 // chr1 // 100 // 100 // 0 // --- // 0 /// ISG15.bAug10 // Ace View // Transcript Identified by AceView, Entrez Gene ID(s) 9636 // chr1 // 100 // 100 // 0 // --- // 0 /// ISG15.cAug10 // Ace View // Transcript Identified by AceView, Entrez Gene ID(s) 9636 // chr1 // 100 // 100 // 0 // --- // 0 /// uc001acj.5 // UCSC Genes // ISG15 ubiquitin-like modifier [Source:HGNC Symbol;Acc:HGNC:4053] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayq.1 // UCSC Genes // ISG15 ubiquitin-like modifier [Source:HGNC Symbol;Acc:HGNC:4053] // chr1 // 100 // 100 // 0 // --- // 0 /// uc057ayr.1 // UCSC Genes // ISG15 ubiquitin-like modifier [Source:HGNC Symbol;Acc:HGNC:4053] // chr1 // 100 // 100 // 0 // --- // 0']}\n", "\n", "Column names in gene annotation data:\n", "['ID', 'probeset_id', 'seqname', 'strand', 'start', 'stop', 'total_probes', 'category', 'SPOT_ID', 'SPOT_ID.1']\n", "\n", "The dataset contains genomic regions (SPOT_ID) that could be used for location-based gene mapping.\n", "Example SPOT_ID format: Coding\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": "009d8e48", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "9b4f57e5", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:18:40.312568Z", "iopub.status.busy": "2025-03-25T07:18:40.312425Z", "iopub.status.idle": "2025-03-25T07:18:44.006489Z", "shell.execute_reply": "2025-03-25T07:18:44.006122Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Extracting gene mapping from annotation data...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Found 24285 annotation entries with valid gene symbols\n", "\n", "Using probe IDs as gene identifiers for downstream analysis...\n", "Created mapping dataframe with 27189 rows\n", "Sample of mapping data:\n", "{'ID': ['23064070', '23064071', '23064072', '23064073', '23064074'], 'Gene': [['23064070'], ['23064071'], ['23064072'], ['23064073'], ['23064074']]}\n", "\n", "Preserving gene expression data with probe IDs as identifiers...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data saved to ../../output/preprocess/Kidney_Clear_Cell_Carcinoma/gene_data/GSE245862.csv\n", "NOTE: Due to platform-specific ID format mismatch, probe IDs are being used as gene identifiers.\n", "The dataset contains 27189 probes and 45 samples.\n" ] } ], "source": [ "# Extracting gene mapping information from the annotation data\n", "print(\"Extracting gene mapping from annotation data...\")\n", "\n", "# The gene expression data IDs are numeric (e.g., 23064070)\n", "# The annotation IDs are in a different format (e.g., TC0100006437.hg.1)\n", "# This mismatch prevents direct mapping between the datasets\n", "\n", "# Since standard mapping is failing, we need to create our own mapping approach\n", "# 1. Create a reference mapping by extracting gene symbols from annotation data\n", "# 2. Apply the mapping to gene expression data\n", "\n", "# First extract gene symbols from the SPOT_ID.1 column which contains gene information\n", "gene_annotation['Gene'] = gene_annotation['SPOT_ID.1'].apply(extract_human_gene_symbols)\n", "\n", "# Check how many annotation entries have valid gene symbols\n", "valid_symbols = gene_annotation[gene_annotation['Gene'].apply(len) > 0]\n", "print(f\"Found {len(valid_symbols)} annotation entries with valid gene symbols\")\n", "\n", "# Since we can't match IDs directly, we'll treat our numeric probe IDs as native identifiers\n", "# and continue analysis with these IDs\n", "print(\"\\nUsing probe IDs as gene identifiers for downstream analysis...\")\n", "\n", "# Create a simplified mapping where probe IDs map to themselves\n", "# This allows the pipeline to continue while preserving the expression data\n", "gene_ids = list(gene_data.index)\n", "mapping_df = pd.DataFrame({\n", " 'ID': gene_ids,\n", " 'Gene': [[id] for id in gene_ids] # Each ID maps to itself as a \"gene\"\n", "})\n", "\n", "# Convert ID column to string for consistency\n", "mapping_df['ID'] = mapping_df['ID'].astype(str)\n", "\n", "# Preview the mapping approach\n", "print(f\"Created mapping dataframe with {len(mapping_df)} rows\")\n", "print(\"Sample of mapping data:\")\n", "print(preview_df(mapping_df.head()))\n", "\n", "# Apply the simplified mapping to preserve the expression data\n", "# Since we're using probe IDs as genes, this essentially keeps the original data structure\n", "print(\"\\nPreserving gene expression data with probe IDs as identifiers...\")\n", "gene_data_preserved = gene_data.copy()\n", "\n", "# Save the gene expression data with original probe IDs\n", "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", "gene_data_preserved.to_csv(out_gene_data_file)\n", "print(f\"Gene expression data saved to {out_gene_data_file}\")\n", "\n", "# Add a note about the mapping approach \n", "print(\"NOTE: Due to platform-specific ID format mismatch, probe IDs are being used as gene identifiers.\")\n", "print(f\"The dataset contains {gene_data_preserved.shape[0]} probes and {gene_data_preserved.shape[1]} samples.\")\n" ] }, { "cell_type": "markdown", "id": "cab31781", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "8c952560", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:18:44.007863Z", "iopub.status.busy": "2025-03-25T07:18:44.007739Z", "iopub.status.idle": "2025-03-25T07:18:44.096851Z", "shell.execute_reply": "2025-03-25T07:18:44.096533Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Normalizing gene symbols...\n", "Using original gene expression data with 27189 probe IDs\n", "Note: These are probe IDs, not gene symbols, due to mapping limitations\n", "\n", "Loading clinical data...\n", "Loaded clinical data with shape: (1, 45)\n", "Clinical data columns: ['GSM7850012', 'GSM7850013', 'GSM7850014', 'GSM7850015', 'GSM7850016', 'GSM7850017', 'GSM7850018', 'GSM7850019', 'GSM7850020', 'GSM7850021', 'GSM7850022', 'GSM7850023', 'GSM7850024', 'GSM7850025', 'GSM7850026', 'GSM7850027', 'GSM7850028', 'GSM7850029', 'GSM7850030', 'GSM7850031', 'GSM7850032', 'GSM7850033', 'GSM7850034', 'GSM7850035', 'GSM7850036', 'GSM7850038', 'GSM7850039', 'GSM7850040', 'GSM7850041', 'GSM7850042', 'GSM7850043', 'GSM7850044', 'GSM7850045', 'GSM7850046', 'GSM7850047', 'GSM7850048', 'GSM7850049', 'GSM7850050', 'GSM7850051', 'GSM7850052', 'GSM7850053', 'GSM7850054', 'GSM7850055', 'GSM7850056', 'GSM7850057']\n", "Transposed clinical data shape: (45, 1)\n", "Transposed clinical data columns: ['Kidney_Clear_Cell_Carcinoma']\n", "\n", "Linking clinical and genetic data...\n", "Linked data shape: (46, 27234)\n", "WARNING: Trait column 'Kidney_Clear_Cell_Carcinoma' not found in linked data\n", "Available columns: ['GSM7850012', 'GSM7850013', 'GSM7850014', 'GSM7850015', 'GSM7850016', 'GSM7850017', 'GSM7850018', 'GSM7850019', 'GSM7850020', 'GSM7850021'] (first 10 shown)\n", "Error in linking or processing data: Trait column 'Kidney_Clear_Cell_Carcinoma' missing from linked data\n", "\n", "Performing final validation...\n", "Abnormality detected in the cohort: GSE245862. Preprocessing failed.\n", "Dataset not usable for Kidney_Clear_Cell_Carcinoma association studies. Data not saved.\n" ] } ], "source": [ "# 1. Normalize gene symbols in the gene expression data\n", "print(\"\\nNormalizing gene symbols...\")\n", "try:\n", " # Since we couldn't map the probe IDs to gene symbols in Step 6,\n", " # we need to use the gene expression data with original probe IDs\n", " # We'll note this limitation in our validation\n", " \n", " # Use the gene_data_preserved from Step 6 which contains the original probe IDs\n", " gene_data_preserved = pd.read_csv(out_gene_data_file, index_col=0)\n", " \n", " print(f\"Using original gene expression data with {len(gene_data_preserved.index)} probe IDs\")\n", " print(\"Note: These are probe IDs, not gene symbols, due to mapping limitations\")\n", " \n", " # Since these are probe IDs and not gene symbols, we skip normalization\n", " # but keep the variable name for consistency with the rest of the pipeline\n", " normalized_gene_data = gene_data_preserved\n", " \n", "except Exception as e:\n", " print(f\"Error loading gene expression data: {e}\")\n", " normalized_gene_data = pd.DataFrame()\n", "\n", "# 2. Load clinical data from the file saved in Step 2\n", "print(\"\\nLoading clinical data...\")\n", "try:\n", " clinical_df = pd.read_csv(out_clinical_data_file)\n", " print(f\"Loaded clinical data with shape: {clinical_df.shape}\")\n", " print(f\"Clinical data columns: {clinical_df.columns.tolist()}\")\n", " \n", " # Transpose and explicitly set the column name to match the expected trait name\n", " clinical_df_t = clinical_df.T\n", " clinical_df_t.columns = [trait] # This ensures the column is named correctly\n", " \n", " print(f\"Transposed clinical data shape: {clinical_df_t.shape}\")\n", " print(f\"Transposed clinical data columns: {clinical_df_t.columns.tolist()}\")\n", " \n", " is_trait_available = True\n", "except Exception as e:\n", " print(f\"Error loading clinical data: {e}\")\n", " clinical_df = pd.DataFrame()\n", " clinical_df_t = pd.DataFrame()\n", " is_trait_available = False\n", "\n", "# 3. Link clinical and genetic data\n", "print(\"\\nLinking clinical and genetic data...\")\n", "try:\n", " if is_trait_available and not normalized_gene_data.empty:\n", " # Link clinical and genetic data\n", " linked_data = geo_link_clinical_genetic_data(clinical_df_t, normalized_gene_data)\n", " print(f\"Linked data shape: {linked_data.shape}\")\n", " \n", " # Verify trait column exists in linked data\n", " if trait in linked_data.columns:\n", " print(f\"Trait column '{trait}' found in linked data\")\n", " else:\n", " print(f\"WARNING: Trait column '{trait}' not found in linked data\")\n", " print(f\"Available columns: {linked_data.columns.tolist()[:10]} (first 10 shown)\")\n", " raise ValueError(f\"Trait column '{trait}' missing from linked data\")\n", " \n", " # 4. Handle missing values systematically\n", " print(\"\\nHandling missing values...\")\n", " linked_data = handle_missing_values(linked_data, trait)\n", " print(f\"After handling missing values, data shape: {linked_data.shape}\")\n", " \n", " # 5. Check for bias in features\n", " print(\"\\nChecking for bias in features...\")\n", " is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)\n", " else:\n", " print(\"Cannot link data: clinical or genetic data is missing.\")\n", " linked_data = pd.DataFrame()\n", " is_biased = True\n", "except Exception as e:\n", " print(f\"Error in linking or processing data: {e}\")\n", " linked_data = pd.DataFrame()\n", " is_biased = True\n", "\n", "# 6. Final quality validation\n", "print(\"\\nPerforming final validation...\")\n", "note = \"This dataset uses probe IDs instead of gene symbols for analysis due to platform-specific \"\n", "note += \"mapping limitations. The biological interpretation may be limited without proper gene symbol mapping.\"\n", "\n", "# Update gene availability based on whether we have usable expression data\n", "is_gene_available = not normalized_gene_data.empty\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 if 'is_biased' in locals() else True,\n", " df=linked_data if 'linked_data' in locals() else pd.DataFrame(),\n", " note=note\n", ")\n", "\n", "# 7. Save linked data if usable\n", "if is_usable and 'linked_data' in locals() and not linked_data.empty:\n", " # Create directory if it doesn't exist\n", " os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n", " \n", " # Save linked data\n", " linked_data.to_csv(out_data_file)\n", " print(f\"Linked data saved to {out_data_file}\")\n", "else:\n", " print(f\"Dataset not usable for {trait} association studies. Data not saved.\")" ] } ], "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 }