{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "4279c913", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:16:23.157496Z", "iopub.status.busy": "2025-03-25T07:16:23.157269Z", "iopub.status.idle": "2025-03-25T07:16:23.326555Z", "shell.execute_reply": "2025-03-25T07:16:23.326195Z" } }, "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_Chromophobe\"\n", "cohort = \"GSE68606\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Kidney_Chromophobe\"\n", "in_cohort_dir = \"../../input/GEO/Kidney_Chromophobe/GSE68606\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Kidney_Chromophobe/GSE68606.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Kidney_Chromophobe/gene_data/GSE68606.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Kidney_Chromophobe/clinical_data/GSE68606.csv\"\n", "json_path = \"../../output/preprocess/Kidney_Chromophobe/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "34591574", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "b8ac2edf", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:16:23.328044Z", "iopub.status.busy": "2025-03-25T07:16:23.327887Z", "iopub.status.idle": "2025-03-25T07:16:23.468823Z", "shell.execute_reply": "2025-03-25T07:16:23.468464Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"caArray_dobbi-00100: Interlaboratory comparability study of cancer gene expression analysis using oligonucleotide microarrays\"\n", "!Series_summary\t\"A key step in bringing gene expression data into clinical practice is the conduct of large studies to confirm preliminary models. The performance of such confirmatory studies and the transition to clinical practice requires that microarray data from different laboratories are comparable and reproducible. We designed a study to assess the comparability of data from four laboratories that will conduct a larger microarray profiling confirmation project in lung adenocarcinomas. To test the feasibility of combining data across laboratories, frozen tumor tissues, cell line pellets, and purified RNA samples were analyzed at each of the four laboratories. Samples of each type and several subsamples from each tumor and each cell line were blinded before being distributed. The laboratories followed a common protocol for all steps of tissue processing, RNA extraction, and microarray analysis using Affymetrix Human Genome U133A arrays. High within-laboratory and between-laboratory correlations were observed on the purified RNA samples, the cell lines, and the frozen tumor tissues. Intraclass correlation within laboratories was only slightly stronger than between laboratories, and the intraclass correlation tended to be weakest for genes expressed at low levels and showing small variation. Finally, hierarchical cluster analysis revealed that the repeated samples clustered together regardless of the laboratory in which the experiments were done. The findings indicate that under properly controlled conditions it is feasible to perform complete tumor microarray analysis, from tissue processing to hybridization and scanning, at multiple independent laboratories for a single study.\"\n", "!Series_overall_design\t\"dobbi-00100\"\n", "!Series_overall_design\t\"Assay Type: Gene Expression\"\n", "!Series_overall_design\t\"Provider: Affymetrix\"\n", "!Series_overall_design\t\"Array Designs: HG-U133A\"\n", "!Series_overall_design\t\"Organism: Homo sapiens (ncbitax)\"\n", "!Series_overall_design\t\"Tissue Sites: Kidney, Lung, Stomach, Uterus, Liver, Lymphoid tissue, Ovary, Skin, Adrenal Gland, Lymph_Node\"\n", "!Series_overall_design\t\"Material Types: cell, nuclear_RNA, synthetic_RNA, organism_part, total_RNA\"\n", "!Series_overall_design\t\"Disease States: Recurrent Renal Cell Carcinoma, Squamous Cell Carcinoma,Conventional_Clear_Cell_Renal_Cell_Carcinoma,Gastrointestinal_Stromal_Tumor, Lung_Adenocarcinoma, Leiomyoma, Non neoplastic liver with cirrosis, Stomach Adenocarcinoma, Large Cell Lymphoma, Ovarian Adenocarcinoma, Melanoma, Malignant G1 Stromal Tumor, Adrenal Cortical Adenoma, Metastatic Renal Cell Carcinoma, Malignant Melanoma\"\n", "Sample Characteristics Dictionary:\n", "{0: ['cell line: H2347', 'cell line: H1437', 'cell line: HCC78', 'cell line: H2087', 'cell line: H2009', 'cell line: --'], 1: ['disease state: --', 'disease state: Leiomyoma', 'disease state: Lung_Adenocarcinoma', 'disease state: Conventional_Clear_Cell_Renal_Cell_Carcinoma', 'disease state: Squamous Cell Carcinoma', 'disease state: Stomach Adenocarcinoma', 'disease state: Large Cell Lymphoma', 'disease state: Malignant Melanoma', 'disease state: Recurrent Renal Cell Carcinoma', 'disease state: Adrenal Cortical Adenoma', 'disease state: Ovarian Adenocarcinoma', 'disease state: Gastrointestinal_Stromal_Tumor', 'disease state: Metastatic Renal Cell Carcinoma', 'disease state: Non neoplastic liver with cirrosis', 'disease state: Malignant G1 Stromal Tumor', 'disease state: melanoma'], 2: ['tumor grading: --', 'tumor grading: G2/pT1pN0pMX', 'tumor grading: G3/pT2pN0pMX', 'tumor grading: G2/pT2pN0pMX', 'tumor grading: G3/pT4pNXpMX'], 3: ['disease stage: --', 'disease stage: Stage IA', 'disease stage: Stage IB', 'disease stage: Stage IIIB'], 4: ['organism part: --', 'organism part: Uterus', 'organism part: Lung', 'organism part: Stomach', 'organism part: Lymphoid tissue', 'organism part: Liver', 'organism part: Adrenal Gland', 'organism part: Ovary', 'organism part: Kidney', 'organism part: Skin', 'organism part: Lymph_Node'], 5: ['Sex: --', 'Sex: female', 'Sex: male'], 6: ['age: --', 'age: 67', 'age: 66', 'age: 72', 'age: 56', 'age: 48'], 7: ['histology: --', 'histology: Leiomyoma', 'histology: Lung_Adenocarcinoma', 'histology: Conventional_Clear_Cell_Renal_Cell_Carcinoma', 'histology: Stomach Adenocarcinoma', 'histology: Large Cell Lymphoma', 'histology: Metastatic Malignant Melanoma', 'histology: Recurrent Renal Cell Carcinoma, chromophobe cell type', 'histology: Non neoplastic liver with cirrosis', 'histology: Adrenal Cortical Adenoma', 'histology: Papillary Serous Adenocarcinoma', 'histology: Squamous cell carcinoma 85% tumor 15% Stroma', 'histology: Squamous Cell Carcinoma', 'histology: Malignant G1 Stromal Tumor', 'histology: metastatic renal cell carcinoma', 'histology: Lung Adenocarcinoma', 'histology: carcinoma', 'histology: Adenocarcinoma', 'histology: Squamous Cell carcinoma', 'histology: Metastatic Renal Cell Carcinoma, clear cell type', 'histology: Ovarian Adenocarcinoma', 'histology: Malignant G1 stromal tumor', 'histology: Adenocartcinoma of Lung', 'histology: Squamoous Cell Carcinoma', 'histology: Renal Cell Carcinoma', 'histology: Non neeoplastic liver with cirrosis', 'histology: Metastatic Renal Cell Carcinoma']}\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": "1f1acf4d", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "b26a7196", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:16:23.470084Z", "iopub.status.busy": "2025-03-25T07:16:23.469955Z", "iopub.status.idle": "2025-03-25T07:16:23.476553Z", "shell.execute_reply": "2025-03-25T07:16:23.476271Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on background information, this dataset contains gene expression data from Affymetrix Human Genome U133A arrays\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "\n", "# Trait (Kidney_Chromophobe)\n", "# Looking at the histology field (index 7), we can see there is data for \"Recurrent Renal Cell Carcinoma, chromophobe cell type\"\n", "trait_row = 7\n", "\n", "# Age data is available in the sample characteristics\n", "age_row = 6\n", "\n", "# Gender data is available as \"Sex\"\n", "gender_row = 5\n", "\n", "# 2.2 Data Type Conversion\n", "\n", "def convert_trait(value):\n", " \"\"\"Convert histology information to binary trait (Kidney_Chromophobe)\"\"\"\n", " if value is None or value == \"--\":\n", " return None\n", " \n", " # Extract the value after the colon if present\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " # Check if the value mentions chromophobe kidney cancer\n", " if \"chromophobe\" in value.lower() and \"renal\" in value.lower():\n", " return 1\n", " else:\n", " return 0\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age information to continuous values\"\"\"\n", " if value is None or value == \"--\":\n", " return None\n", " \n", " # Extract the value after the colon if present\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " try:\n", " return float(value)\n", " except:\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender information to binary (0=female, 1=male)\"\"\"\n", " if value is None or value == \"--\":\n", " return None\n", " \n", " # Extract the value after the colon if present\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " value = value.lower()\n", " if \"female\" in value:\n", " return 0\n", " elif \"male\" in value:\n", " return 1\n", " else:\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Determine if trait data is available\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", "# Note: We're skipping the clinical feature extraction step since we don't have\n", "# the properly formatted sample-level clinical data required for processing.\n", "# The sample characteristics dictionary only shows unique values for each characteristic,\n", "# not the actual data for each sample.\n" ] }, { "cell_type": "markdown", "id": "5c299c57", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "d910dc76", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:16:23.477688Z", "iopub.status.busy": "2025-03-25T07:16:23.477578Z", "iopub.status.idle": "2025-03-25T07:16:23.745835Z", "shell.execute_reply": "2025-03-25T07:16:23.745433Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Extracting gene data from matrix file:\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Successfully extracted gene data with 22283 rows\n", "First 20 gene IDs:\n", "Index(['1007_s_at', '1053_at', '117_at', '121_at', '1255_g_at', '1294_at',\n", " '1316_at', '1320_at', '1405_i_at', '1431_at', '1438_at', '1487_at',\n", " '1494_f_at', '1598_g_at', '160020_at', '1729_at', '1773_at', '177_at',\n", " '179_at', '1861_at'],\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": "b3f5bb8c", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "532b2ea5", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:16:23.747236Z", "iopub.status.busy": "2025-03-25T07:16:23.747104Z", "iopub.status.idle": "2025-03-25T07:16:23.749107Z", "shell.execute_reply": "2025-03-25T07:16:23.748810Z" } }, "outputs": [], "source": [ "# The gene identifiers '1007_s_at', '1053_at', etc. are Affymetrix probe IDs,\n", "# not standard human gene symbols. These are microarray probe identifiers from\n", "# the Affymetrix GeneChip Human Genome platform.\n", "# They need to be mapped to official gene symbols for standardized analysis.\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "1ab51b37", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "1e0f0173", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:16:23.750334Z", "iopub.status.busy": "2025-03-25T07:16:23.750221Z", "iopub.status.idle": "2025-03-25T07:16:28.862540Z", "shell.execute_reply": "2025-03-25T07:16:28.862164Z" } }, "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 3075191 rows\n", "\n", "Gene annotation preview (first few rows):\n", "{'ID': ['1007_s_at', '1053_at', '117_at', '121_at', '1255_g_at'], 'GB_ACC': ['U48705', 'M87338', 'X51757', 'X69699', 'L36861'], 'SPOT_ID': [nan, nan, nan, nan, nan], 'Species Scientific Name': ['Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens', 'Homo sapiens'], 'Annotation Date': ['Oct 6, 2014', 'Oct 6, 2014', 'Oct 6, 2014', 'Oct 6, 2014', 'Oct 6, 2014'], 'Sequence Type': ['Exemplar sequence', 'Exemplar sequence', 'Exemplar sequence', 'Exemplar sequence', 'Exemplar sequence'], 'Sequence Source': ['Affymetrix Proprietary Database', 'GenBank', 'Affymetrix Proprietary Database', 'GenBank', 'Affymetrix Proprietary Database'], 'Target Description': ['U48705 /FEATURE=mRNA /DEFINITION=HSU48705 Human receptor tyrosine kinase DDR gene, complete cds', 'M87338 /FEATURE= /DEFINITION=HUMA1SBU Human replication factor C, 40-kDa subunit (A1) mRNA, complete cds', \"X51757 /FEATURE=cds /DEFINITION=HSP70B Human heat-shock protein HSP70B' gene\", 'X69699 /FEATURE= /DEFINITION=HSPAX8A H.sapiens Pax8 mRNA', 'L36861 /FEATURE=expanded_cds /DEFINITION=HUMGCAPB Homo sapiens guanylate cyclase activating protein (GCAP) gene exons 1-4, complete cds'], 'Representative Public ID': ['U48705', 'M87338', 'X51757', 'X69699', 'L36861'], 'Gene Title': ['discoidin domain receptor tyrosine kinase 1 /// microRNA 4640', 'replication factor C (activator 1) 2, 40kDa', \"heat shock 70kDa protein 6 (HSP70B')\", 'paired box 8', 'guanylate cyclase activator 1A (retina)'], 'Gene Symbol': ['DDR1 /// MIR4640', 'RFC2', 'HSPA6', 'PAX8', 'GUCA1A'], 'ENTREZ_GENE_ID': ['780 /// 100616237', '5982', '3310', '7849', '2978'], 'RefSeq Transcript ID': ['NM_001202521 /// NM_001202522 /// NM_001202523 /// NM_001954 /// NM_013993 /// NM_013994 /// NR_039783 /// XM_005249385 /// XM_005249386 /// XM_005249387 /// XM_005249389 /// XM_005272873 /// XM_005272874 /// XM_005272875 /// XM_005272877 /// XM_005275027 /// XM_005275028 /// XM_005275030 /// XM_005275031 /// XM_005275162 /// XM_005275163 /// XM_005275164 /// XM_005275166 /// XM_005275457 /// XM_005275458 /// XM_005275459 /// XM_005275461 /// XM_006715185 /// XM_006715186 /// XM_006715187 /// XM_006715188 /// XM_006715189 /// XM_006715190 /// XM_006725501 /// XM_006725502 /// XM_006725503 /// XM_006725504 /// XM_006725505 /// XM_006725506 /// XM_006725714 /// XM_006725715 /// XM_006725716 /// XM_006725717 /// XM_006725718 /// XM_006725719 /// XM_006725720 /// XM_006725721 /// XM_006725722 /// XM_006725827 /// XM_006725828 /// XM_006725829 /// XM_006725830 /// XM_006725831 /// XM_006725832 /// XM_006726017 /// XM_006726018 /// XM_006726019 /// XM_006726020 /// XM_006726021 /// XM_006726022 /// XR_427836 /// XR_430858 /// XR_430938 /// XR_430974 /// XR_431015', 'NM_001278791 /// NM_001278792 /// NM_001278793 /// NM_002914 /// NM_181471 /// XM_006716080', 'NM_002155', 'NM_003466 /// NM_013951 /// NM_013952 /// NM_013953 /// NM_013992', 'NM_000409 /// XM_006715073'], 'Gene Ontology Biological Process': ['0001558 // regulation of cell growth // inferred from electronic annotation /// 0001952 // regulation of cell-matrix adhesion // inferred from electronic annotation /// 0006468 // protein phosphorylation // inferred from electronic annotation /// 0007155 // cell adhesion // traceable author statement /// 0007169 // transmembrane receptor protein tyrosine kinase signaling pathway // inferred from electronic annotation /// 0007565 // female pregnancy // inferred from electronic annotation /// 0007566 // embryo implantation // inferred from electronic annotation /// 0007595 // lactation // inferred from electronic annotation /// 0008285 // negative regulation of cell proliferation // inferred from electronic annotation /// 0010715 // regulation of extracellular matrix disassembly // inferred from mutant phenotype /// 0014909 // smooth muscle cell migration // inferred from mutant phenotype /// 0016310 // phosphorylation // inferred from electronic annotation /// 0018108 // peptidyl-tyrosine phosphorylation // inferred from electronic annotation /// 0030198 // extracellular matrix organization // traceable author statement /// 0038063 // collagen-activated tyrosine kinase receptor signaling pathway // inferred from direct assay /// 0038063 // collagen-activated tyrosine kinase receptor signaling pathway // inferred from mutant phenotype /// 0038083 // peptidyl-tyrosine autophosphorylation // inferred from direct assay /// 0043583 // ear development // inferred from electronic annotation /// 0044319 // wound healing, spreading of cells // inferred from mutant phenotype /// 0046777 // protein autophosphorylation // inferred from direct assay /// 0060444 // branching involved in mammary gland duct morphogenesis // inferred from electronic annotation /// 0060749 // mammary gland alveolus development // inferred from electronic annotation /// 0061302 // smooth muscle cell-matrix adhesion // inferred from mutant phenotype', '0000278 // mitotic cell cycle // traceable author statement /// 0000722 // telomere maintenance via recombination // traceable author statement /// 0000723 // telomere maintenance // traceable author statement /// 0006260 // DNA replication // traceable author statement /// 0006271 // DNA strand elongation involved in DNA replication // traceable author statement /// 0006281 // DNA repair // traceable author statement /// 0006283 // transcription-coupled nucleotide-excision repair // traceable author statement /// 0006289 // nucleotide-excision repair // traceable author statement /// 0006297 // nucleotide-excision repair, DNA gap filling // traceable author statement /// 0015979 // photosynthesis // inferred from electronic annotation /// 0015995 // chlorophyll biosynthetic process // inferred from electronic annotation /// 0032201 // telomere maintenance via semi-conservative replication // traceable author statement', '0000902 // cell morphogenesis // inferred from electronic annotation /// 0006200 // ATP catabolic process // inferred from direct assay /// 0006950 // response to stress // inferred from electronic annotation /// 0006986 // response to unfolded protein // traceable author statement /// 0034605 // cellular response to heat // inferred from direct assay /// 0042026 // protein refolding // inferred from direct assay /// 0070370 // cellular heat acclimation // inferred from mutant phenotype', '0001655 // urogenital system development // inferred from sequence or structural similarity /// 0001656 // metanephros development // inferred from electronic annotation /// 0001658 // branching involved in ureteric bud morphogenesis // inferred from expression pattern /// 0001822 // kidney development // inferred from expression pattern /// 0001823 // mesonephros development // inferred from sequence or structural similarity /// 0003337 // mesenchymal to epithelial transition involved in metanephros morphogenesis // inferred from expression pattern /// 0006351 // transcription, DNA-templated // inferred from direct assay /// 0006355 // regulation of transcription, DNA-templated // inferred from electronic annotation /// 0007275 // multicellular organismal development // inferred from electronic annotation /// 0007417 // central nervous system development // inferred from expression pattern /// 0009653 // anatomical structure morphogenesis // traceable author statement /// 0030154 // cell differentiation // inferred from electronic annotation /// 0030878 // thyroid gland development // inferred from expression pattern /// 0030878 // thyroid gland development // inferred from mutant phenotype /// 0038194 // thyroid-stimulating hormone signaling pathway // traceable author statement /// 0039003 // pronephric field specification // inferred from sequence or structural similarity /// 0042472 // inner ear morphogenesis // inferred from sequence or structural similarity /// 0042981 // regulation of apoptotic process // inferred from sequence or structural similarity /// 0045893 // positive regulation of transcription, DNA-templated // inferred from direct assay /// 0045893 // positive regulation of transcription, DNA-templated // inferred from sequence or structural similarity /// 0045944 // positive regulation of transcription from RNA polymerase II promoter // inferred from direct assay /// 0048793 // pronephros development // inferred from sequence or structural similarity /// 0071371 // cellular response to gonadotropin stimulus // inferred from direct assay /// 0071599 // otic vesicle development // inferred from expression pattern /// 0072050 // S-shaped body morphogenesis // inferred from electronic annotation /// 0072073 // kidney epithelium development // inferred from electronic annotation /// 0072108 // positive regulation of mesenchymal to epithelial transition involved in metanephros morphogenesis // inferred from sequence or structural similarity /// 0072164 // mesonephric tubule development // inferred from electronic annotation /// 0072207 // metanephric epithelium development // inferred from expression pattern /// 0072221 // metanephric distal convoluted tubule development // inferred from sequence or structural similarity /// 0072278 // metanephric comma-shaped body morphogenesis // inferred from expression pattern /// 0072284 // metanephric S-shaped body morphogenesis // inferred from expression pattern /// 0072289 // metanephric nephron tubule formation // inferred from sequence or structural similarity /// 0072305 // negative regulation of mesenchymal cell apoptotic process involved in metanephric nephron morphogenesis // inferred from sequence or structural similarity /// 0072307 // regulation of metanephric nephron tubule epithelial cell differentiation // inferred from sequence or structural similarity /// 0090190 // positive regulation of branching involved in ureteric bud morphogenesis // inferred from sequence or structural similarity /// 1900212 // negative regulation of mesenchymal cell apoptotic process involved in metanephros development // inferred from sequence or structural similarity /// 1900215 // negative regulation of apoptotic process involved in metanephric collecting duct development // inferred from sequence or structural similarity /// 1900218 // negative regulation of apoptotic process involved in metanephric nephron tubule development // inferred from sequence or structural similarity /// 2000594 // positive regulation of metanephric DCT cell differentiation // inferred from sequence or structural similarity /// 2000611 // positive regulation of thyroid hormone generation // inferred from mutant phenotype /// 2000612 // regulation of thyroid-stimulating hormone secretion // inferred from mutant phenotype', '0007165 // signal transduction // non-traceable author statement /// 0007601 // visual perception // inferred from electronic annotation /// 0007602 // phototransduction // inferred from electronic annotation /// 0007603 // phototransduction, visible light // traceable author statement /// 0016056 // rhodopsin mediated signaling pathway // traceable author statement /// 0022400 // regulation of rhodopsin mediated signaling pathway // traceable author statement /// 0030828 // positive regulation of cGMP biosynthetic process // inferred from electronic annotation /// 0031282 // regulation of guanylate cyclase activity // inferred from electronic annotation /// 0031284 // positive regulation of guanylate cyclase activity // inferred from electronic annotation /// 0050896 // response to stimulus // inferred from electronic annotation'], 'Gene Ontology Cellular Component': ['0005576 // extracellular region // inferred from electronic annotation /// 0005615 // extracellular space // inferred from direct assay /// 0005886 // plasma membrane // traceable author statement /// 0005887 // integral component of plasma membrane // traceable author statement /// 0016020 // membrane // inferred from electronic annotation /// 0016021 // integral component of membrane // inferred from electronic annotation /// 0043235 // receptor complex // inferred from direct assay /// 0070062 // extracellular vesicular exosome // inferred from direct assay', '0005634 // nucleus // inferred from electronic annotation /// 0005654 // nucleoplasm // traceable author statement /// 0005663 // DNA replication factor C complex // inferred from direct assay', '0005737 // cytoplasm // inferred from direct assay /// 0005814 // centriole // inferred from direct assay /// 0005829 // cytosol // inferred from direct assay /// 0008180 // COP9 signalosome // inferred from direct assay /// 0070062 // extracellular vesicular exosome // inferred from direct assay /// 0072562 // blood microparticle // inferred from direct assay', '0005634 // nucleus // inferred from direct assay /// 0005654 // nucleoplasm // inferred from sequence or structural similarity /// 0005730 // nucleolus // inferred from direct assay', '0001750 // photoreceptor outer segment // inferred from electronic annotation /// 0001917 // photoreceptor inner segment // inferred from electronic annotation /// 0005578 // proteinaceous extracellular matrix // inferred from electronic annotation /// 0005886 // plasma membrane // inferred from direct assay /// 0016020 // membrane // inferred from electronic annotation /// 0097381 // photoreceptor disc membrane // traceable author statement'], 'Gene Ontology Molecular Function': ['0000166 // nucleotide binding // inferred from electronic annotation /// 0004672 // protein kinase activity // inferred from electronic annotation /// 0004713 // protein tyrosine kinase activity // inferred from electronic annotation /// 0004714 // transmembrane receptor protein tyrosine kinase activity // traceable author statement /// 0005515 // protein binding // inferred from physical interaction /// 0005518 // collagen binding // inferred from direct assay /// 0005518 // collagen binding // inferred from mutant phenotype /// 0005524 // ATP binding // inferred from electronic annotation /// 0016301 // kinase activity // inferred from electronic annotation /// 0016740 // transferase activity // inferred from electronic annotation /// 0016772 // transferase activity, transferring phosphorus-containing groups // inferred from electronic annotation /// 0038062 // protein tyrosine kinase collagen receptor activity // inferred from direct assay /// 0046872 // metal ion binding // inferred from electronic annotation', '0000166 // nucleotide binding // inferred from electronic annotation /// 0003677 // DNA binding // inferred from electronic annotation /// 0005515 // protein binding // inferred from physical interaction /// 0005524 // ATP binding // inferred from electronic annotation /// 0016851 // magnesium chelatase activity // inferred from electronic annotation /// 0017111 // nucleoside-triphosphatase activity // inferred from electronic annotation', '0000166 // nucleotide binding // inferred from electronic annotation /// 0005524 // ATP binding // inferred from electronic annotation /// 0019899 // enzyme binding // inferred from physical interaction /// 0031072 // heat shock protein binding // inferred from physical interaction /// 0042623 // ATPase activity, coupled // inferred from direct assay /// 0051082 // unfolded protein binding // inferred from direct assay', '0000979 // RNA polymerase II core promoter sequence-specific DNA binding // inferred from direct assay /// 0003677 // DNA binding // inferred from direct assay /// 0003677 // DNA binding // inferred from mutant phenotype /// 0003700 // sequence-specific DNA binding transcription factor activity // inferred from direct assay /// 0004996 // thyroid-stimulating hormone receptor activity // traceable author statement /// 0005515 // protein binding // inferred from physical interaction /// 0044212 // transcription regulatory region DNA binding // inferred from direct assay', '0005509 // calcium ion binding // inferred from electronic annotation /// 0008048 // calcium sensitive guanylate cyclase activator activity // inferred from electronic annotation /// 0030249 // guanylate cyclase regulator activity // inferred from electronic annotation /// 0046872 // metal ion binding // inferred from electronic annotation']}\n", "\n", "Column names in gene annotation data:\n", "['ID', 'GB_ACC', 'SPOT_ID', 'Species Scientific Name', 'Annotation Date', 'Sequence Type', 'Sequence Source', 'Target Description', 'Representative Public ID', 'Gene Title', 'Gene Symbol', 'ENTREZ_GENE_ID', 'RefSeq Transcript ID', 'Gene Ontology Biological Process', 'Gene Ontology Cellular Component', 'Gene Ontology Molecular Function']\n", "\n", "The dataset contains GenBank accessions (GB_ACC) that could be used for gene mapping.\n", "Number of rows with GenBank accessions: 3075123 out of 3075191\n", "\n", "The dataset contains genomic regions (SPOT_ID) that could be used for location-based gene mapping.\n", "Example SPOT_ID format: nan\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": "09f9787a", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "c3b011ff", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:16:28.863872Z", "iopub.status.busy": "2025-03-25T07:16:28.863751Z", "iopub.status.idle": "2025-03-25T07:16:30.142433Z", "shell.execute_reply": "2025-03-25T07:16:30.142027Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Creating gene mapping between probe IDs and gene symbols...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Created gene mapping with 21225 entries\n", "\n", "First few rows of the probe-to-gene mapping:\n", "{'ID': ['1007_s_at', '1053_at', '117_at', '121_at', '1255_g_at'], 'Gene': ['DDR1 /// MIR4640', 'RFC2', 'HSPA6', 'PAX8', 'GUCA1A']}\n", "\n", "Converting probe-level data to gene-level expression data...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene-level expression data created with 13830 genes\n", "\n", "First few rows of gene-level expression data:\n", "{'GSM1676864': [411.658, 9.93369, 67.9692, 103.083, 253.048], 'GSM1676865': [328.766, 29.7297, 42.2613, 19.8402, 307.313], 'GSM1676866': [283.038, 31.5178, 103.195, 120.743, 301.599], 'GSM1676867': [441.273, 117.207, 34.8804, 233.94, 54.3385], 'GSM1676868': [456.17, 66.0545, 37.4472, 132.972, 292.66], 'GSM1676869': [356.891, 76.3685, 20.8323, 54.8785, 526.452], 'GSM1676870': [370.538, 8.34365, 63.0356, 86.0991, 285.639], 'GSM1676871': [391.2, 77.8802, 70.4974, 86.7128, 242.461], 'GSM1676872': [517.632, 96.8163, 25.5571, 132.283, 157.348], 'GSM1676873': [330.712, 76.7729, 77.6666, 123.381, 88.7403], 'GSM1676874': [567.981, 6309.08, 44.9647, 111.27, 191.89], 'GSM1676875': [451.008, 3399.73, 47.873, 201.969, 184.049], 'GSM1676876': [398.683, 6781.84, 43.8145, 156.659, 111.423], 'GSM1676877': [264.817, 3324.59, 83.583, 67.3656, 95.2435], 'GSM1676878': [316.144, 3792.41, 128.442, 198.628, 286.456], 'GSM1676879': [488.895, 1293.64, 28.4595, 78.1152, 349.306], 'GSM1676880': [698.865, 1362.23, 54.4839, 122.145, 299.555], 'GSM1676881': [333.237, 9146.15, 58.7308, 185.523, 107.854], 'GSM1676882': [297.906, 6235.78, 98.6307, 79.6398, 122.422], 'GSM1676883': [426.591, 615.75, 75.867, 154.066, 206.974], 'GSM1676884': [1046.28, 2273.67, 46.5488, 122.142, 173.092], 'GSM1676885': [408.635, 1306.79, 76.6154, 169.75, 165.98], 'GSM1676886': [490.634, 13630.8, 17.8017, 69.8781, 15.3784], 'GSM1676887': [485.801, 2170.9, 108.014, 276.327, 51.7832], 'GSM1676888': [7073.05, 18811.1, 50.4241, 228.137, 41.0295], 'GSM1676889': [448.217, 6199.11, 85.289, 111.181, 200.119], 'GSM1676890': [496.262, 1474.82, 60.6067, 182.587, 292.507], 'GSM1676891': [368.528, 10252.8, 55.7117, 174.227, 179.873], 'GSM1676892': [366.456, 789.978, 124.081, 26.7186, 142.962], 'GSM1676893': [398.117, 1166.74, 85.0643, 154.876, 232.988], 'GSM1676894': [492.446, 588.072, 65.9943, 144.726, 199.948], 'GSM1676895': [529.8, 9637.76, 152.448, 105.656, 327.083], 'GSM1676896': [489.649, 1282.5, 100.606, 163.901, 36.7272], 'GSM1676897': [358.349, 9001.25, 72.8388, 124.312, 566.06], 'GSM1676898': [277.109, 36.53, 79.5521, 71.4484, 110.654], 'GSM1676899': [340.047, 888.146, 90.4953, 258.709, 81.9113], 'GSM1676900': [322.451, 66.8521, 129.149, 127.424, 210.122], 'GSM1676901': [207.114, 3853.55, 106.207, 37.087, 114.987], 'GSM1676902': [271.05, 3690.27, 184.497, 70.8641, 262.136], 'GSM1676903': [453.679, 17490.9, 50.7492, 231.867, 253.9], 'GSM1676904': [707.385, 3652.89, 76.4571, 104.008, 101.273], 'GSM1676905': [310.087, 5705.11, 32.0617, 96.2652, 132.062], 'GSM1676906': [205.062, 2575.5, 145.593, 116.02, 550.274], 'GSM1676907': [238.29, 7622.48, 70.3304, 84.3832, 66.6815], 'GSM1676908': [326.584, 1081.52, 101.238, 93.9148, 122.813], 'GSM1676909': [311.495, 11435.7, 144.942, 100.306, 126.909], 'GSM1676910': [203.999, 3411.81, 121.158, 187.029, 337.819], 'GSM1676911': [340.632, 20017.6, 103.707, 93.6403, 313.29], 'GSM1676912': [242.136, 8672.49, 158.202, 131.488, 376.504], 'GSM1676913': [280.596, 8809.91, 78.0689, 30.8602, 95.363], 'GSM1676914': [261.235, 1176.41, 129.163, 150.927, 154.267], 'GSM1676915': [220.191, 6273.03, 157.018, 91.0523, 45.5751], 'GSM1676916': [154.287, 3097.01, 43.0369, 109.772, 60.4279], 'GSM1676917': [249.021, 6933.77, 52.9668, 157.301, 105.586], 'GSM1676918': [190.031, 3486.6, 57.8367, 114.927, 26.2389], 'GSM1676919': [244.185, 2980.77, 118.597, 134.063, 392.153], 'GSM1676920': [7221.55, 18847.1, 80.2683, 108.509, 39.7829], 'GSM1676921': [202.044, 1387.51, 9.62754, 125.816, 272.897], 'GSM1676922': [852.634, 3034.4, 170.968, 216.239, 538.312], 'GSM1676923': [219.541, 9.40839, 45.323, 117.042, 261.072], 'GSM1676924': [250.375, 61.9754, 75.1138, 72.1293, 260.959], 'GSM1676925': [194.1, 51.0271, 46.2237, 92.1945, 415.577], 'GSM1676926': [213.025, 45.7836, 90.0173, 163.828, 295.155], 'GSM1676927': [290.097, 11.2297, 84.8706, 104.089, 80.9239], 'GSM1676928': [191.475, 91.0237, 124.201, 92.3014, 551.452], 'GSM1676929': [280.591, 8.5694, 74.7421, 147.134, 214.273], 'GSM1676930': [1739.15, 183.661, 362.907, 408.082, 642.242], 'GSM1676931': [449.484, 1835.63, 78.6618, 81.7935, 624.106], 'GSM1676932': [653.538, 1519.91, 78.5968, 157.336, 479.329], 'GSM1676933': [615.66, 1503.23, 108.234, 126.582, 516.821], 'GSM1676934': [693.207, 1688.62, 92.7393, 54.9706, 261.094], 'GSM1676935': [365.857, 84.882, 35.9251, 200.44, 400.534], 'GSM1676936': [442.781, 191.093, 26.0975, 162.609, 105.456], 'GSM1676937': [405.489, 49.3506, 125.852, 271.26, 367.469], 'GSM1676938': [489.105, 123.179, 131.391, 159.286, 288.869], 'GSM1676939': [443.635, 15.984, 232.216, 120.931, 299.643], 'GSM1676940': [645.63, 7860.24, 154.485, 326.241, 321.78], 'GSM1676941': [889.046, 5411.44, 36.5647, 275.576, 175.98], 'GSM1676942': [8397.28, 15577.8, 67.6738, 235.874, 46.9544], 'GSM1676943': [785.366, 2010.27, 118.436, 177.267, 120.277], 'GSM1676944': [584.498, 9919.0, 108.023, 34.5491, 367.877], 'GSM1676945': [547.531, 12558.3, 68.4184, 263.105, 291.679], 'GSM1676946': [647.35, 1814.16, 87.0891, 292.051, 736.774], 'GSM1676947': [476.587, 5571.05, 235.025, 178.403, 294.389], 'GSM1676948': [359.179, 1349.74, 102.785, 144.944, 228.471], 'GSM1676949': [447.414, 9974.35, 135.993, 198.331, 311.793], 'GSM1676950': [326.465, 3208.07, 118.354, 62.2251, 255.6], 'GSM1676951': [497.948, 3511.17, 247.765, 79.8703, 321.115], 'GSM1676952': [569.141, 122.108, 177.351, 177.807, 239.583], 'GSM1676953': [257.992, 19.7566, 141.519, 135.802, 406.664], 'GSM1676954': [438.154, 15.6798, 36.5242, 330.335, 307.984], 'GSM1676955': [502.766, 5852.78, 15.947, 321.583, 530.432], 'GSM1676956': [902.321, 2614.02, 72.3786, 187.28, 101.546], 'GSM1676957': [9262.97, 17612.2, 45.2688, 343.362, 20.0233], 'GSM1676958': [628.991, 2264.06, 184.857, 254.54, 76.2398], 'GSM1676959': [508.451, 12051.1, 142.573, 167.731, 253.575], 'GSM1676960': [567.297, 4633.95, 139.302, 521.078, 320.057], 'GSM1676961': [505.107, 7716.77, 205.974, 234.631, 206.664], 'GSM1676962': [512.962, 3748.42, 101.432, 155.702, 58.0774], 'GSM1676963': [497.255, 726.028, 35.7099, 163.049, 102.588], 'GSM1676964': [523.926, 126.946, 55.0483, 120.441, 282.579], 'GSM1676965': [446.499, 46.9572, 54.8778, 225.537, 375.521], 'GSM1676966': [583.473, 8337.49, 167.649, 218.652, 243.252], 'GSM1676967': [258.732, 63.4673, 37.2341, 166.624, 444.043], 'GSM1676968': [257.569, 122.619, 33.7704, 92.9779, 317.679], 'GSM1676969': [252.815, 73.9788, 71.1948, 134.555, 318.59], 'GSM1676970': [300.93, 6464.48, 53.2396, 141.297, 177.81], 'GSM1676971': [166.687, 11340.9, 112.453, 105.408, 265.534], 'GSM1676972': [251.696, 3001.58, 135.064, 183.673, 154.655], 'GSM1676973': [466.504, 3285.68, 187.037, 208.184, 223.339], 'GSM1676974': [222.125, 4796.86, 78.745, 186.883, 251.38], 'GSM1676975': [281.152, 1963.26, 101.773, 172.205, 207.365], 'GSM1676976': [386.261, 10823.8, 84.5997, 154.438, 241.488], 'GSM1676977': [477.119, 2271.14, 45.2405, 126.882, 236.222], 'GSM1676978': [328.761, 4817.08, 51.3791, 145.916, 119.995], 'GSM1676979': [303.677, 7212.47, 76.4348, 144.997, 173.34], 'GSM1676980': [290.742, 2631.0, 357.811, 206.043, 930.561], 'GSM1676981': [300.057, 11337.8, 50.8535, 105.239, 274.501], 'GSM1676982': [427.548, 1549.26, 158.928, 217.139, 51.0172], 'GSM1676983': [600.066, 2140.9, 74.5121, 285.602, 292.743], 'GSM1676984': [9858.13, 17427.3, 78.4626, 85.1598, 153.286], 'GSM1676985': [207.015, 1882.66, 130.931, 127.032, 322.02], 'GSM1676986': [349.194, 4317.77, 96.286, 212.281, 300.345], 'GSM1676987': [255.187, 2580.29, 210.361, 125.169, 781.165], 'GSM1676988': [820.03, 4153.95, 139.315, 137.644, 231.496], 'GSM1676989': [197.047, 23496.5, 50.2633, 101.45, 25.6266], 'GSM1676990': [9358.58, 16900.8, 156.149, 107.628, 246.408], 'GSM1676991': [492.934, 1938.54, 73.6854, 375.393, 168.357], 'GSM1676992': [252.68, 34.1681, 85.0411, 129.996, 331.889], 'GSM1676993': [214.051, 41.0751, 131.085, 115.976, 455.359], 'GSM1676994': [172.401, 78.7446, 155.877, 82.1678, 512.032], 'GSM1676995': [360.667, 13.4254, 138.564, 157.912, 378.585], 'GSM1676996': [224.958, 113.818, 170.433, 148.86, 584.665], 'GSM1676997': [196.633, 80.4261, 96.1404, 60.4659, 611.119], 'GSM1676998': [423.316, 90.634, 115.264, 58.1038, 200.164], 'GSM1676999': [604.971, 1469.13, 131.866, 47.5079, 299.39], 'GSM1677000': [663.523, 1450.95, 22.6944, 122.016, 332.704]}\n", "\n", "Saving gene expression data to ../../output/preprocess/Kidney_Chromophobe/gene_data/GSE68606.csv\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data saved successfully\n" ] } ], "source": [ "# 1. Identify mapping columns based on previous output\n", "# In gene expression data, the identifiers are Affymetrix probe IDs like '1007_s_at'\n", "# From the gene annotation preview, we need 'ID' (for probe IDs) and 'Gene Symbol' columns\n", "\n", "print(\"Creating gene mapping between probe IDs and gene symbols...\")\n", "\n", "# 2. Extract the gene mapping from gene annotation data\n", "mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')\n", "print(f\"Created gene mapping with {len(mapping_df)} entries\")\n", "\n", "# Preview the mapping\n", "print(\"\\nFirst few rows of the probe-to-gene mapping:\")\n", "print(preview_df(mapping_df))\n", "\n", "# 3. Convert probe-level measurements to gene-level expression\n", "print(\"\\nConverting probe-level data to gene-level expression data...\")\n", "gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)\n", "print(f\"Gene-level expression data created with {len(gene_data.index)} genes\")\n", "\n", "# Preview the gene expression data\n", "print(\"\\nFirst few rows of gene-level expression data:\")\n", "print(preview_df(gene_data))\n", "\n", "# Save the gene data to file\n", "print(f\"\\nSaving gene expression data to {out_gene_data_file}\")\n", "# Make directory if it doesn't exist\n", "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", "gene_data.to_csv(out_gene_data_file)\n", "print(\"Gene expression data saved successfully\")\n" ] }, { "cell_type": "markdown", "id": "7eb79e37", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "4bd3ba11", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:16:30.143923Z", "iopub.status.busy": "2025-03-25T07:16:30.143795Z", "iopub.status.idle": "2025-03-25T07:16:34.745559Z", "shell.execute_reply": "2025-03-25T07:16:34.745217Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Normalizing gene symbols...\n", "After normalization: 13542 unique gene symbols\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene expression data saved to ../../output/preprocess/Kidney_Chromophobe/gene_data/GSE68606.csv\n", "\n", "Extracting clinical features...\n", "Clinical data extracted with shape: (3, 137)\n", "Clinical data preview:\n", "{'Kidney_Chromophobe': [0.0, 0.0, 0.0, 0.0, 0.0], 'Age': [nan, nan, nan, nan, nan], 'Gender': [nan, nan, 0.0, nan, nan]}\n", "Clinical data saved to ../../output/preprocess/Kidney_Chromophobe/clinical_data/GSE68606.csv\n", "\n", "Linking clinical and genetic data...\n", "First few clinical sample columns: ['GSM1676864', 'GSM1676865', 'GSM1676866', 'GSM1676867', 'GSM1676868']\n", "First few genetic sample columns: ['GSM1676864', 'GSM1676865', 'GSM1676866', 'GSM1676867', 'GSM1676868']\n", "Linked data shape: (137, 13545)\n", "Number of samples with trait values: 137\n", "\n", "Handling missing values...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "After handling missing values, data shape: (137, 13545)\n", "\n", "Checking for bias in features...\n", "For the feature 'Kidney_Chromophobe', the least common label is '1.0' with 4 occurrences. This represents 2.92% of the dataset.\n", "The distribution of the feature 'Kidney_Chromophobe' in this dataset is severely biased.\n", "\n", "Quartiles for 'Age':\n", " 25%: 61.8\n", " 50% (Median): 61.8\n", " 75%: 61.8\n", "Min: 48.0\n", "Max: 72.0\n", "The distribution of the feature 'Age' in this dataset is fine.\n", "\n", "For the feature 'Gender', the least common label is '0.0' with 9 occurrences. This represents 6.57% of the dataset.\n", "The distribution of the feature 'Gender' in this dataset is fine.\n", "\n", "\n", "Performing final validation...\n", "Dataset not usable for Kidney_Chromophobe association studies. Data not saved.\n" ] } ], "source": [ "# 1. Normalize gene symbols in the gene expression data\n", "print(\"\\nNormalizing gene symbols...\")\n", "try:\n", " normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n", " print(f\"After normalization: {len(normalized_gene_data.index)} unique gene symbols\")\n", " \n", " # Save the normalized gene data (this was already done in Step 6, but we'll save the normalized version now)\n", " os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", " normalized_gene_data.to_csv(out_gene_data_file)\n", " print(f\"Normalized gene expression data saved to {out_gene_data_file}\")\n", "except Exception as e:\n", " print(f\"Error normalizing gene symbols: {e}\")\n", " normalized_gene_data = gene_data # Use original data if normalization fails\n", "\n", "# 1. Extract clinical features first (since we didn't do this in earlier steps)\n", "print(\"\\nExtracting clinical features...\")\n", "try:\n", " # From sample characteristics dictionary in Step 1, histology is at index 7\n", " # We're looking for \"chromophobe\" in the kidney cancer descriptions\n", " trait_row = 7 # histology field\n", " \n", " def convert_trait(value):\n", " \"\"\"Convert histology information to binary trait (Kidney_Chromophobe)\"\"\"\n", " if value is None or value == \"--\":\n", " return None\n", " \n", " # Extract the value after the colon if present\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " # Check if the value mentions chromophobe kidney cancer\n", " if \"chromophobe\" in value.lower() and \"renal\" in value.lower():\n", " return 1\n", " else:\n", " return 0\n", " \n", " # Define gender conversion (from \"Sex:\" field at index 5)\n", " gender_row = 5\n", " \n", " def convert_gender(value):\n", " \"\"\"Convert gender information to binary (0=female, 1=male)\"\"\"\n", " if value is None or value == \"--\":\n", " return None\n", " \n", " # Extract the value after the colon if present\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " value = value.lower()\n", " if \"female\" in value:\n", " return 0\n", " elif \"male\" in value:\n", " return 1\n", " else:\n", " return None\n", " \n", " # Define age conversion (from \"age:\" field at index 6)\n", " age_row = 6\n", " \n", " def convert_age(value):\n", " \"\"\"Convert age information to continuous values\"\"\"\n", " if value is None or value == \"--\":\n", " return None\n", " \n", " # Extract the value after the colon if present\n", " if \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " \n", " try:\n", " return float(value)\n", " except:\n", " return None\n", " \n", " # Extract clinical features\n", " 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", " print(f\"Clinical data extracted with shape: {clinical_df.shape}\")\n", " print(\"Clinical data preview:\")\n", " print(preview_df(clinical_df.T))\n", " \n", " # Create directory if it doesn't exist\n", " os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", " \n", " # Save clinical data\n", " clinical_df.to_csv(out_clinical_data_file)\n", " print(f\"Clinical data saved to {out_clinical_data_file}\")\n", " is_trait_available = True\n", "except Exception as e:\n", " print(f\"Error extracting clinical features: {e}\")\n", " is_trait_available = False\n", " clinical_df = None\n", "\n", "# 2. Link clinical and genetic data if available\n", "print(\"\\nLinking clinical and genetic data...\")\n", "try:\n", " if clinical_df is not None and not normalized_gene_data.empty:\n", " # Print sample IDs from both datasets for debugging\n", " print(\"First few clinical sample columns:\", list(clinical_df.columns)[:5])\n", " print(\"First few genetic sample columns:\", list(normalized_gene_data.columns)[:5])\n", " \n", " # Link clinical and genetic data\n", " linked_data = geo_link_clinical_genetic_data(clinical_df, normalized_gene_data)\n", " print(f\"Linked data shape: {linked_data.shape}\")\n", " \n", " # Check if we have at least one sample with trait value\n", " trait_count = linked_data[trait].count()\n", " print(f\"Number of samples with trait values: {trait_count}\")\n", " \n", " if trait_count > 0:\n", " # 3. 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", " # Check if we still have samples after missing value handling\n", " if linked_data.shape[0] > 0:\n", " # 4. Determine whether the trait and demographic features are biased\n", " print(\"\\nChecking for bias in features...\")\n", " is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)\n", " else:\n", " print(\"Error: All samples were removed during missing value handling.\")\n", " is_biased = True\n", " else:\n", " print(\"No samples have valid trait values. Dataset cannot be used.\")\n", " is_biased = True\n", " else:\n", " print(\"Cannot link data: clinical or genetic data is missing\")\n", " linked_data = pd.DataFrame()\n", " is_biased = True\n", " \n", "except Exception as e:\n", " print(f\"Error in linking clinical and genetic data: {e}\")\n", " linked_data = pd.DataFrame()\n", " is_biased = True\n", "\n", "# 5. Final quality validation\n", "print(\"\\nPerforming final validation...\")\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() and not linked_data.empty else pd.DataFrame(),\n", " note=\"Dataset contains kidney tissue samples with histology data including chromophobe renal cell carcinoma\"\n", ")\n", "\n", "# 6. 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 }