{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "ed7d250d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:12:50.632137Z", "iopub.status.busy": "2025-03-25T06:12:50.632031Z", "iopub.status.idle": "2025-03-25T06:12:50.790109Z", "shell.execute_reply": "2025-03-25T06:12:50.789772Z" } }, "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 = \"Polycystic_Kidney_Disease\"\n", "cohort = \"GSE74451\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Polycystic_Kidney_Disease\"\n", "in_cohort_dir = \"../../input/GEO/Polycystic_Kidney_Disease/GSE74451\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Polycystic_Kidney_Disease/GSE74451.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Polycystic_Kidney_Disease/gene_data/GSE74451.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Polycystic_Kidney_Disease/clinical_data/GSE74451.csv\"\n", "json_path = \"../../output/preprocess/Polycystic_Kidney_Disease/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "aaee57ff", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "e2942b56", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:12:50.791497Z", "iopub.status.busy": "2025-03-25T06:12:50.791355Z", "iopub.status.idle": "2025-03-25T06:12:50.908471Z", "shell.execute_reply": "2025-03-25T06:12:50.908065Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Identification of a novel risk factor for intracranial aneurysms in ADPKD using iPSC models [Agilent]\"\n", "!Series_summary\t\"Cardiovascular complications are the leading cause of death in autosomal dominant polycystic kidney disease (ADPKD), and intracranial aneurysm (ICA) causing subarachnoid hemorrhage is among the most serious complications. The diagnostic and therapeutic strategies for ICAs in ADPKD have not been fully established. We here generated induced pluripotent stem cells (iPSCs) from seven ADPKD patients, including four with ICAs. The vascular cells differentiated from ADPKD-iPSCs showed altered Ca2+ entry and gene expression profiles compared with those from control-iPSCs. We found that the expression level of a metalloenzyme gene, matrix metalloproteinase (MMP) 1, was specifically elevated in the iPSC-derived endothelia from ADPKD patients with ICAs. Furthermore, we confirmed a statistically significant correlation between the serum MMP1 levels and the development of ICAs in 354 ADPKD patients, indicating that the serum MMP1 levels may be a novel risk factor and become more beneficial when combined with other risk factors. These results suggest that cellular disease models with ADPKD-specific iPSCs can be used to study the disease mechanisms and to identify novel disease-related molecules or risk factors.\"\n", "!Series_overall_design\t\"The gene expression profiles of vascular endothelia and smooth muscle cells derived from control- and ADPKD-iPSCs were analyzed. Seven control-iPSC derived endothelial cells (ECs), seven ADPKD-iPSC derived ECs, ten control-iPSC derived vascular smooth muscle cells (SMCs), and seven ADPKD-iPSC derived SMCs were analyzed.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['subject/sample source id: TIG114 4F1', 'subject/sample source id: TIG118 4F1', 'subject/sample source id: TIG119 4F1', 'subject/sample source id: TIG121 4F4', 'subject/sample source id: TIG975E4', 'subject/sample source id: 585A1', 'subject/sample source id: 585B1', 'subject/sample source id: TIG107 4F1', 'subject/sample source id: TIG120 4F1', 'subject/sample source id: TIG120 3F7', 'subject/sample source id: TIG975E2', 'subject/sample source id: CiRA00004', 'subject/sample source id: CiRA00005', 'subject/sample source id: CiRA00006', 'subject/sample source id: CiRA00007', 'subject/sample source id: CiRA00008', 'subject/sample source id: CiRA00009', 'subject/sample source id: CiRA00010'], 1: ['subject status: healthy control', 'subject status: autosomal dominant polycystic kidney disease (ADPKD) patient'], 2: ['gender: Male', 'gender: Female'], 3: ['cell type: iPSC derived endothelial cells', 'cell type: iPSC derived vascular smooth muscle cells'], 4: ['gender: Male', 'gender: Female']}\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": "bbfcd6fb", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "53aa30df", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:12:50.909995Z", "iopub.status.busy": "2025-03-25T06:12:50.909891Z", "iopub.status.idle": "2025-03-25T06:12:50.918394Z", "shell.execute_reply": "2025-03-25T06:12:50.918117Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Selected Clinical Data Preview:\n", "{'GSM1920920': [0.0, 1.0], 'GSM1920921': [0.0, 1.0], 'GSM1920922': [0.0, 1.0], 'GSM1920923': [0.0, 1.0], 'GSM1920924': [0.0, 1.0], 'GSM1920925': [0.0, 1.0], 'GSM1920926': [0.0, 1.0], 'GSM1920927': [0.0, 1.0], 'GSM1920928': [0.0, 1.0], 'GSM1920929': [0.0, 1.0], 'GSM1920930': [0.0, 1.0], 'GSM1920931': [0.0, 1.0], 'GSM1920932': [0.0, 1.0], 'GSM1920933': [0.0, 1.0], 'GSM1920934': [0.0, 1.0], 'GSM1920935': [0.0, 1.0], 'GSM1920936': [0.0, 1.0], 'GSM1920937': [1.0, 1.0], 'GSM1920938': [1.0, 1.0], 'GSM1920939': [1.0, 1.0], 'GSM1920940': [1.0, 1.0], 'GSM1920941': [1.0, 1.0], 'GSM1920942': [1.0, 1.0], 'GSM1920943': [1.0, 1.0], 'GSM1920944': [1.0, 1.0], 'GSM1920945': [1.0, 1.0], 'GSM1920946': [1.0, 1.0], 'GSM1920947': [1.0, 1.0], 'GSM1920948': [1.0, 1.0], 'GSM1920949': [1.0, 1.0], 'GSM1920950': [1.0, 1.0]}\n", "Clinical data saved to ../../output/preprocess/Polycystic_Kidney_Disease/clinical_data/GSE74451.csv\n" ] } ], "source": [ "import pandas as pd\n", "import os\n", "import numpy as np\n", "from typing import Optional, Callable, Dict, Any\n", "import json\n", "\n", "# 1. Gene Expression Data Availability\n", "# From the background info, this dataset appears to contain gene expression data from iPSC-derived cells\n", "is_gene_available = True\n", "\n", "# 2.1 Data Availability\n", "# Trait (ADPKD status) is at index 1 in the Sample Characteristics Dictionary\n", "trait_row = 1\n", "\n", "# Age is not available in the sample characteristics dictionary\n", "age_row = None\n", "\n", "# Gender is at index 2 and 4 (duplicate) in the Sample Characteristics Dictionary\n", "gender_row = 2\n", "\n", "# 2.2 Data Type Conversion\n", "def convert_trait(value):\n", " \"\"\"Convert ADPKD trait status to binary (0 = control, 1 = ADPKD)\"\"\"\n", " if isinstance(value, str) and ':' in value:\n", " value = value.split(':', 1)[1].strip().lower()\n", " if 'adpkd' in value or 'polycystic kidney disease' in value:\n", " return 1\n", " elif 'control' in value or 'healthy' in value:\n", " return 0\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender to binary (0 = female, 1 = male)\"\"\"\n", " if isinstance(value, str) and ':' in value:\n", " value = value.split(':', 1)[1].strip().lower()\n", " if 'male' in value:\n", " return 1\n", " elif 'female' in value:\n", " return 0\n", " return None\n", "\n", "# Age conversion function (not used as age data is not available)\n", "def convert_age(value):\n", " \"\"\"Convert age to continuous value\"\"\"\n", " if isinstance(value, str) and ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " try:\n", " return float(value)\n", " except ValueError:\n", " pass\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Trait data is available since trait_row is not None\n", "is_trait_available = trait_row is not None\n", "\n", "# Initial filtering on the usability of the dataset\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", " # Assuming clinical_data is already available from previous steps\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", " preview = preview_df(selected_clinical_df)\n", " print(\"Selected Clinical Data Preview:\")\n", " print(preview)\n", " \n", " # Save the processed clinical data\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" ] }, { "cell_type": "markdown", "id": "f0e92d34", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "fa993dd0", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:12:50.919526Z", "iopub.status.busy": "2025-03-25T06:12:50.919428Z", "iopub.status.idle": "2025-03-25T06:12:51.099460Z", "shell.execute_reply": "2025-03-25T06:12:51.099091Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['(+)E1A_r60_1', '(+)E1A_r60_3', '(+)E1A_r60_a104', '(+)E1A_r60_a107',\n", " '(+)E1A_r60_a135', '(+)E1A_r60_a20', '(+)E1A_r60_a22', '(+)E1A_r60_a97',\n", " '(+)E1A_r60_n11', '(+)E1A_r60_n9', '3xSLv1', 'A_19_P00315452',\n", " 'A_19_P00315459', 'A_19_P00315482', 'A_19_P00315492', 'A_19_P00315493',\n", " 'A_19_P00315502', 'A_19_P00315506', 'A_19_P00315518', 'A_19_P00315519'],\n", " dtype='object', name='ID')\n" ] } ], "source": [ "# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.\n", "gene_data = get_genetic_data(matrix_file)\n", "\n", "# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.\n", "print(gene_data.index[:20])\n" ] }, { "cell_type": "markdown", "id": "09727ed2", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "73ac00a2", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:12:51.100776Z", "iopub.status.busy": "2025-03-25T06:12:51.100663Z", "iopub.status.idle": "2025-03-25T06:12:51.102564Z", "shell.execute_reply": "2025-03-25T06:12:51.102285Z" } }, "outputs": [], "source": [ "# Examining the gene identifiers\n", "# These gene identifiers appear to be probe IDs from a microarray platform, not standard human gene symbols\n", "# The identifiers have formats like \"(+)E1A_r60_1\" and \"A_19_P00315452\" which are not standard gene symbols\n", "# They need to be mapped to proper human gene symbols for analysis\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "f88b555f", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "5bf47770", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:12:51.103704Z", "iopub.status.busy": "2025-03-25T06:12:51.103607Z", "iopub.status.idle": "2025-03-25T06:12:53.942553Z", "shell.execute_reply": "2025-03-25T06:12:53.942181Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['GE_BrightCorner', 'DarkCorner', 'A_23_P117082', 'A_33_P3246448', 'A_33_P3318220'], 'SPOT_ID': ['CONTROL', 'CONTROL', 'A_23_P117082', 'A_33_P3246448', 'A_33_P3318220'], 'CONTROL_TYPE': ['pos', 'pos', 'FALSE', 'FALSE', 'FALSE'], 'REFSEQ': [nan, nan, 'NM_015987', 'NM_080671', 'NM_178466'], 'GB_ACC': [nan, nan, 'NM_015987', 'NM_080671', 'NM_178466'], 'LOCUSLINK_ID': [nan, nan, 50865.0, 23704.0, 128861.0], 'GENE_SYMBOL': [nan, nan, 'HEBP1', 'KCNE4', 'BPIFA3'], 'GENE_NAME': [nan, nan, 'heme binding protein 1', 'potassium voltage-gated channel, Isk-related family, member 4', 'BPI fold containing family A, member 3'], 'UNIGENE_ID': [nan, nan, 'Hs.642618', 'Hs.348522', 'Hs.360989'], 'ENSEMBL_ID': [nan, nan, 'ENST00000014930', 'ENST00000281830', 'ENST00000375454'], 'ACCESSION_STRING': [nan, nan, 'ref|NM_015987|ens|ENST00000014930|gb|AF117615|gb|BC016277', 'ref|NM_080671|ens|ENST00000281830|tc|THC2655788', 'ref|NM_178466|ens|ENST00000375454|ens|ENST00000471233|tc|THC2478474'], 'CHROMOSOMAL_LOCATION': [nan, nan, 'chr12:13127906-13127847', 'chr2:223920197-223920256', 'chr20:31812208-31812267'], 'CYTOBAND': [nan, nan, 'hs|12p13.1', 'hs|2q36.1', 'hs|20q11.21'], 'DESCRIPTION': [nan, nan, 'Homo sapiens heme binding protein 1 (HEBP1), mRNA [NM_015987]', 'Homo sapiens potassium voltage-gated channel, Isk-related family, member 4 (KCNE4), mRNA [NM_080671]', 'Homo sapiens BPI fold containing family A, member 3 (BPIFA3), transcript variant 1, mRNA [NM_178466]'], 'GO_ID': [nan, nan, 'GO:0005488(binding)|GO:0005576(extracellular region)|GO:0005737(cytoplasm)|GO:0005739(mitochondrion)|GO:0005829(cytosol)|GO:0007623(circadian rhythm)|GO:0020037(heme binding)', 'GO:0005244(voltage-gated ion channel activity)|GO:0005249(voltage-gated potassium channel activity)|GO:0006811(ion transport)|GO:0006813(potassium ion transport)|GO:0016020(membrane)|GO:0016021(integral to membrane)|GO:0016324(apical plasma membrane)', 'GO:0005576(extracellular region)|GO:0008289(lipid binding)'], 'SEQUENCE': [nan, nan, 'AAGGGGGAAAATGTGATTTGTGCCTGATCTTTCATCTGTGATTCTTATAAGAGCTTTGTC', 'GCAAGTCTCTCTGCACCTATTAAAAAGTGATGTATATACTTCCTTCTTATTCTGTTGAGT', 'CATTCCATAAGGAGTGGTTCTCGGCAAATATCTCACTTGAATTTGACCTTGAATTGAGAC']}\n" ] } ], "source": [ "# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.\n", "gene_annotation = get_gene_annotation(soft_file)\n", "\n", "# 2. Use the 'preview_df' function from the library to preview the data and print out the results.\n", "print(\"Gene annotation preview:\")\n", "print(preview_df(gene_annotation))\n" ] }, { "cell_type": "markdown", "id": "dad5948e", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "925386a5", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:12:53.943810Z", "iopub.status.busy": "2025-03-25T06:12:53.943690Z", "iopub.status.idle": "2025-03-25T06:12:54.487298Z", "shell.execute_reply": "2025-03-25T06:12:54.486918Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene mapping dataframe shape: (46204, 2)\n", "First few rows of gene mapping:\n", " ID Gene\n", "2 A_23_P117082 HEBP1\n", "3 A_33_P3246448 KCNE4\n", "4 A_33_P3318220 BPIFA3\n", "5 A_33_P3236322 LOC100129869\n", "6 A_33_P3319925 IRG1\n", "Gene expression data shape after mapping: (20353, 31)\n", "First few rows of gene expression data after mapping:\n", " GSM1920920 GSM1920921 GSM1920922 GSM1920923 GSM1920924 \\\n", "Gene \n", "A1BG 1.555157 0.039984 -0.678945 -2.468467 -0.687164 \n", "A1BG-AS1 -0.031899 0.399478 0.491183 -0.043165 0.327540 \n", "A1CF -7.052572 -6.938511 -6.495134 -6.282820 -6.263671 \n", "A2LD1 -2.554118 -2.768966 -1.938280 -2.780313 -0.552746 \n", "A2M 2.396515 3.753389 2.026154 2.604408 3.323712 \n", "\n", " GSM1920925 GSM1920926 GSM1920927 GSM1920928 GSM1920929 ... \\\n", "Gene ... \n", "A1BG -1.150444 -1.119194 3.409858 1.953408 3.432645 ... \n", "A1BG-AS1 0.279196 0.482973 0.393608 0.875047 0.422757 ... \n", "A1CF -6.794781 -5.904637 -5.973920 -5.512413 -6.017731 ... \n", "A2LD1 0.414121 -0.094048 -3.004901 -2.897878 -2.704821 ... \n", "A2M 4.253478 2.590855 0.750266 1.676453 -1.409772 ... \n", "\n", " GSM1920941 GSM1920942 GSM1920943 GSM1920944 GSM1920945 \\\n", "Gene \n", "A1BG 1.167614 0.855238 0.981959 2.674137 2.270285 \n", "A1BG-AS1 0.366627 0.738049 0.834407 0.534394 0.920760 \n", "A1CF -6.463429 -6.777850 -6.708805 -6.682463 -6.467661 \n", "A2LD1 -3.179345 -1.802912 -3.433977 -1.717523 -3.201257 \n", "A2M 3.554608 4.270979 0.565773 -1.091934 0.449732 \n", "\n", " GSM1920946 GSM1920947 GSM1920948 GSM1920949 GSM1920950 \n", "Gene \n", "A1BG 3.537616 2.371358 3.012788 2.423548 3.041033 \n", "A1BG-AS1 0.774964 1.268185 0.653735 0.696221 0.787017 \n", "A1CF -6.758943 -6.654989 -6.953169 -6.562128 -6.582874 \n", "A2LD1 -3.107660 -1.538983 -3.150377 -1.081631 -2.969094 \n", "A2M -1.348838 -0.202032 -0.598002 1.618083 -0.051316 \n", "\n", "[5 rows x 31 columns]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data saved to ../../output/preprocess/Polycystic_Kidney_Disease/gene_data/GSE74451.csv\n", "Found 4 common genes out of 4 checked: ['TP53', 'BRCA1', 'KRAS', 'TNF']\n" ] } ], "source": [ "# 1. Identify columns in gene_annotation containing gene identifiers and gene symbols\n", "# From the preview, 'ID' contains probe identifiers (e.g., A_23_P117082) matching the gene expression data\n", "# 'GENE_SYMBOL' contains the human gene symbols (e.g., HEBP1, KCNE4)\n", "id_column = 'ID'\n", "gene_symbol_column = 'GENE_SYMBOL'\n", "\n", "# 2. Create gene mapping dataframe by extracting the two relevant columns\n", "gene_mapping = get_gene_mapping(gene_annotation, id_column, gene_symbol_column)\n", "print(f\"Gene mapping dataframe shape: {gene_mapping.shape}\")\n", "print(\"First few rows of gene mapping:\")\n", "print(gene_mapping.head())\n", "\n", "# 3. Apply gene mapping to convert probe-level measurements to gene expression data\n", "# This handles the many-to-many relationship between probes and genes\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "print(f\"Gene expression data shape after mapping: {gene_data.shape}\")\n", "print(\"First few rows of gene expression data after mapping:\")\n", "print(gene_data.head())\n", "\n", "# Save the processed gene data\n", "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", "gene_data.to_csv(out_gene_data_file)\n", "print(f\"Gene expression data saved to {out_gene_data_file}\")\n", "\n", "# Check for some common gene symbols to verify mapping worked properly\n", "common_genes = ['TP53', 'BRCA1', 'KRAS', 'TNF']\n", "found_genes = [gene for gene in common_genes if gene in gene_data.index]\n", "print(f\"Found {len(found_genes)} common genes out of {len(common_genes)} checked: {found_genes}\")\n" ] }, { "cell_type": "markdown", "id": "91a13bd4", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "af6d235b", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:12:54.488639Z", "iopub.status.busy": "2025-03-25T06:12:54.488514Z", "iopub.status.idle": "2025-03-25T06:13:03.138059Z", "shell.execute_reply": "2025-03-25T06:13:03.137395Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data shape: (19847, 31)\n", "First few normalized gene symbols: ['A1BG', 'A1BG-AS1', 'A1CF', 'A2M', 'A2ML1', 'A2MP1', 'A4GALT', 'A4GNT', 'AA06', 'AAA1']\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Polycystic_Kidney_Disease/gene_data/GSE74451.csv\n", "Loaded clinical data shape: (2, 31)\n", " GSM1920920 GSM1920921 GSM1920922 GSM1920923 GSM1920924 GSM1920925 \\\n", "0 0.0 0.0 0.0 0.0 0.0 0.0 \n", "1 1.0 1.0 1.0 1.0 1.0 1.0 \n", "\n", " GSM1920926 GSM1920927 GSM1920928 GSM1920929 ... GSM1920941 \\\n", "0 0.0 0.0 0.0 0.0 ... 1.0 \n", "1 1.0 1.0 1.0 1.0 ... 1.0 \n", "\n", " GSM1920942 GSM1920943 GSM1920944 GSM1920945 GSM1920946 GSM1920947 \\\n", "0 1.0 1.0 1.0 1.0 1.0 1.0 \n", "1 1.0 1.0 1.0 1.0 1.0 1.0 \n", "\n", " GSM1920948 GSM1920949 GSM1920950 \n", "0 1.0 1.0 1.0 \n", "1 1.0 1.0 1.0 \n", "\n", "[2 rows x 31 columns]\n", "Transposed clinical data shape: (30, 2)\n", " Polycystic_Kidney_Disease Gender\n", "GSM1920921 0.0 1.0\n", "GSM1920922 0.0 1.0\n", "GSM1920923 0.0 1.0\n", "GSM1920924 0.0 1.0\n", "GSM1920925 0.0 1.0\n", "Linked data shape: (31, 19849)\n", " Polycystic_Kidney_Disease Gender A1BG A1BG-AS1 A1CF\n", "GSM1920921 0.0 1.0 0.039984 0.399478 -6.938511\n", "GSM1920922 0.0 1.0 -0.678945 0.491183 -6.495134\n", "GSM1920923 0.0 1.0 -2.468467 -0.043165 -6.282820\n", "GSM1920924 0.0 1.0 -0.687164 0.327540 -6.263671\n", "GSM1920925 0.0 1.0 -1.150444 0.279196 -6.794781\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Shape after handling missing values: (30, 19849)\n", "For the feature 'Polycystic_Kidney_Disease', the least common label is '1.0' with 14 occurrences. This represents 46.67% of the dataset.\n", "The distribution of the feature 'Polycystic_Kidney_Disease' in this dataset is fine.\n", "\n", "For the feature 'Gender', the least common label is '1.0' with 30 occurrences. This represents 100.00% of the dataset.\n", "The distribution of the feature 'Gender' in this dataset is severely biased.\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "A new JSON file was created at: ../../output/preprocess/Polycystic_Kidney_Disease/cohort_info.json\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Linked data saved to ../../output/preprocess/Polycystic_Kidney_Disease/GSE74451.csv\n" ] } ], "source": [ "# 1. Normalize gene symbols in the gene expression data\n", "normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n", "print(f\"Normalized gene data shape: {normalized_gene_data.shape}\")\n", "print(f\"First few normalized gene symbols: {list(normalized_gene_data.index[:10])}\")\n", "\n", "# Save the normalized gene data\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 data saved to {out_gene_data_file}\")\n", "\n", "# 2. Load the clinical data that was processed in step 2\n", "clinical_df = pd.read_csv(out_clinical_data_file)\n", "print(f\"Loaded clinical data shape: {clinical_df.shape}\")\n", "print(clinical_df.head())\n", "\n", "# The clinical dataframe has samples as columns. Need to properly transpose and name columns\n", "clinical_df_t = clinical_df.set_index(clinical_df.columns[0]).T\n", "# Row 0 corresponds to the trait (Polycystic_Kidney_Disease) and row 1 corresponds to Gender\n", "clinical_df_t.columns = [trait, 'Gender']\n", "print(f\"Transposed clinical data shape: {clinical_df_t.shape}\")\n", "print(clinical_df_t.head())\n", "\n", "# 3. Link the clinical and genetic data\n", "linked_data = pd.concat([clinical_df_t, normalized_gene_data.T], axis=1)\n", "print(f\"Linked data shape: {linked_data.shape}\")\n", "print(linked_data.iloc[:5, :5]) # Print first 5 rows and 5 columns\n", "\n", "# 4. Handle missing values in the linked data\n", "linked_data = handle_missing_values(linked_data, trait)\n", "print(f\"Shape after handling missing values: {linked_data.shape}\")\n", "\n", "# 5. Determine whether the trait and demographic features are severely biased\n", "is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, trait)\n", "\n", "# 6. Conduct quality check and save the cohort information\n", "is_usable = validate_and_save_cohort_info(\n", " is_final=True, \n", " cohort=cohort, \n", " info_path=json_path, \n", " is_gene_available=True, \n", " is_trait_available=True,\n", " is_biased=is_trait_biased, \n", " df=unbiased_linked_data,\n", " note=f\"Dataset contains gene expression data from iPSC-derived endothelial and smooth muscle cells from ADPKD patients and controls.\"\n", ")\n", "\n", "# 7. Save the data if it's usable\n", "if is_usable:\n", " # Create directory if it doesn't exist\n", " os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n", " # Save the data\n", " unbiased_linked_data.to_csv(out_data_file)\n", " print(f\"Linked data saved to {out_data_file}\")\n", "else:\n", " print(f\"Data quality check failed. The dataset is not suitable for association studies.\")" ] } ], "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 }