{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "e835851a", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:04:46.030614Z", "iopub.status.busy": "2025-03-25T04:04:46.030494Z", "iopub.status.idle": "2025-03-25T04:04:46.197966Z", "shell.execute_reply": "2025-03-25T04:04:46.197593Z" } }, "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 = \"Stroke\"\n", "cohort = \"GSE273225\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Stroke\"\n", "in_cohort_dir = \"../../input/GEO/Stroke/GSE273225\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Stroke/GSE273225.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Stroke/gene_data/GSE273225.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Stroke/clinical_data/GSE273225.csv\"\n", "json_path = \"../../output/preprocess/Stroke/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "b8419082", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "17ec3d19", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:04:46.199381Z", "iopub.status.busy": "2025-03-25T04:04:46.199239Z", "iopub.status.idle": "2025-03-25T04:04:46.208721Z", "shell.execute_reply": "2025-03-25T04:04:46.208429Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"The effect of rewarming ischemia on tissue transcriptome signatures: a clinical observational study in lung transplantation\"\n", "!Series_summary\t\"BACKGROUND: In lung transplantation (LuTx), various ischemic phases exist, yet the rewarming ischemia time (RIT) during implantation has often been overlooked. During RIT, lungs are deflated and exposed to the body temperature in the recipient's chest cavity. Our prior clinical findings demonstrated that prolonged RIT increases the risk of primary graft dysfunction. However, the molecular mechanisms of rewarming ischemic injury in this context remain unexplored. We aimed to characterize the rewarming ischemia phase during LuTx by measuring organ temperature and comparing transcriptome and metabolome profiles in tissue obtained at the end versus the start of implantation.\"\n", "!Series_summary\t\"METHODS: In a clinical observational study, 34 double-LuTx with ice preservation were analyzed. Lung core and surface temperature (n=65 and 55 lungs) was measured during implantation. Biopsies (n=59 lungs) were wedged from right middle lobe and left lingula at start and end of implantation. Tissue transcriptomic and metabolomic profiling were performed.\"\n", "!Series_summary\t\"RESULTS: Temperature increased rapidly during implantation, reaching core/surface temperatures of 21.5°C/25.4°C within 30min. Transcriptomics showed increased pro-inflammatory signaling and oxidative stress at the end of implantation. Upregulation of NLRP3 and NFKB1 correlated with RIT. Metabolomics indicated elevated levels of amino acids, hypoxanthine, uric acid, cysteineglutathione disulfide alongside decreased levels of glucose and carnitines. Arginine, tyrosine, and 1-carboxyethylleucine showed correlation with incremental RIT.\"\n", "!Series_summary\t\"CONCLUSIONS: The final rewarming ischemia phase in LuTx involves rapid organ rewarming, accompanied by transcriptomic and metabolomic changes indicating pro-inflammatory signaling and disturbed cell metabolism. Limiting implantation time and lung cooling represent potential interventions to alleviate rewarming ischemic injury.\"\n", "!Series_overall_design\t\"Lung tissue biopsy pieces preserved at -80°C were homogenized in Total RNA Lysis Solution (Bio-Rad, Cat#7326820, US) with a 3mm tungsten carbide bead (Qiagen, Cat#69997, Netherlands) using the TissueLyser II (Qiagen, Netherlands). The homogenate underwent RNA extraction with TRIzol (Invitrogen, Cat#15596026, US) and RNA purification with the Aurum Total RNA mini Kit (Bio-Rad, Cat#7326820, US). RNA quality was verified using the NanoPhotometer NP80 Touch (Implen, Germany).\"\n", "!Series_overall_design\t\"We did nCounter (NanoString Technologies, US) digital gene expression analysis with the Immunology V2 panel targeting 579 immune system-associated genes. The workflow was carried out as established before in critical COVID-191, fatal COVID-19 nursing home outbreaks2, and respiratory infections at the emergency department3. In short, transcripts -including 15 housekeeping genes - were quantified by hybridization with specific fluorescent barcodes linked to a 50 bp reporter probe and an adjacent 50 bp capture probe.\"\n", "!Series_overall_design\t\"Data were normalized for background (negative control probes), internal positive control probes and housekeeping genes using nSolver software version 4.0 (NanoString Technologies, US). Differentially expressed genes and predefined biological pathway scores were determined using nSolver, with correction for multiple testing by the Benjamini-Hochberg method at a 5% false discovery rate for multiple comparisons cut-off. Comparison of baseline RNA levels for lung side, mechanical ventilation time, donation type and cold ischemia time was done according to the negative binomial distribution with generalized linear models.\"\n", "!Series_overall_design\t\"References\"\n", "!Series_overall_design\t\"1. Menezes SM, Braz M, Llorens-Rico V, Wauters J, Van Weyenbergh J. Endogenous IFNβ expression predicts outcome in critical patients with COVID-19. Lancet Microbe. Jun 2021;2(6):e235-e236. doi:10.1016/s2666-5247(21)00063-x\"\n", "!Series_overall_design\t\"2. Cuypers L, Keyaerts E, Hong SL, et al. Immunovirological and environmental screening reveals actionable risk factors for fatal COVID-19 during post-vaccination nursing home outbreaks. Nat Aging. Jun 2023;3(6):722-733. doi:10.1038/s43587-023-00421-1\"\n", "!Series_overall_design\t\"3. Fukutani KF, Nascimento-Carvalho CM, Bouzas ML, et al. In situ Immune Signatures and Microbial Load at the Nasopharyngeal Interface in Children With Acute Respiratory Infection. Front Microbiol. 2018;9:2475. doi:10.3389/fmicb.2018.02475\"\n", "Sample Characteristics Dictionary:\n", "{0: ['tissue: left lung', 'tissue: right lung'], 1: ['timepoint: start donor lung implantation', 'timepoint: end donor lung implantation'], 2: ['biopsy set: 1 left', 'biopsy set: 2 right', 'biopsy set: 3 left', 'biopsy set: 3 right', 'biopsy set: 4 left', 'biopsy set: 4 right', 'biopsy set: 5 left', 'biopsy set: 6 right', 'biopsy set: 7 left', 'biopsy set: 7 right', 'biopsy set: 8 left', 'biopsy set: 8 right', 'biopsy set: 9 left', 'biopsy set: 9 right', 'biopsy set: 10 left', 'biopsy set: 10 right', 'biopsy set: 11 left', 'biopsy set: 11 right', 'biopsy set: 12 left', 'biopsy set: 12 right', 'biopsy set: 14 left', 'biopsy set: 14 right', 'biopsy set: 15 left', 'biopsy set: 15 right', 'biopsy set: 16 left', 'biopsy set: 16 right', 'biopsy set: 20 left', 'biopsy set: 20 right', 'biopsy set: 21 right', 'biopsy set: 22 left'], 3: ['donor age (y): 51', 'donor age (y): 63', 'donor age (y): 66', 'donor age (y): 49', 'donor age (y): 73', 'donor age (y): 68', 'donor age (y): 42', 'donor age (y): 60', 'donor age (y): 29', 'donor age (y): 28', 'donor age (y): 59', 'donor age (y): 44', 'donor age (y): 39', 'donor age (y): 76', 'donor age (y): 48', 'donor age (y): 88', 'donor age (y): 64', 'donor age (y): 69', 'donor age (y): 36', 'donor age (y): 62', 'donor age (y): 56', 'donor age (y): 34', 'donor age (y): 50', 'donor age (y): 65', 'donor age (y): 75', 'donor age (y): 58'], 4: ['donor sex: male', 'donor sex: female'], 5: ['donor bmi: 24.7', 'donor bmi: 30.4', 'donor bmi: 26.3', 'donor bmi: 23.9', 'donor bmi: 22.6', 'donor bmi: 27', 'donor bmi: 27.8', 'donor bmi: 24.2', 'donor bmi: 21.3', 'donor bmi: 18', 'donor bmi: 30.7', 'donor bmi: 16.9', 'donor bmi: 17.8', 'donor bmi: 29.2', 'donor bmi: 23.1', 'donor bmi: 25.4', 'donor bmi: 19', 'donor bmi: 22.9', 'donor bmi: 30.8', 'donor bmi: 29.4', 'donor bmi: 29.8', 'donor bmi: 30.5', 'donor bmi: 24.8', 'donor bmi: 32.4', 'donor bmi: 21.2', 'donor bmi: 23.6', 'donor bmi: 27.2'], 6: ['donor smoking history: yes', 'donor smoking history: no'], 7: ['donor cause of death: hypoxic-ischemic encefalopathy', 'donor cause of death: intracranial bleeding', 'donor cause of death: head trauma', 'donor cause of death: ischemic stroke'], 8: ['donor mechanical ventilation (hours): 98', 'donor mechanical ventilation (hours): 265', 'donor mechanical ventilation (hours): 125', 'donor mechanical ventilation (hours): 165', 'donor mechanical ventilation (hours): 87', 'donor mechanical ventilation (hours): 50', 'donor mechanical ventilation (hours): 209', 'donor mechanical ventilation (hours): 51', 'donor mechanical ventilation (hours): 75', 'donor mechanical ventilation (hours): 212', 'donor mechanical ventilation (hours): 164', 'donor mechanical ventilation (hours): 80', 'donor mechanical ventilation (hours): 92', 'donor mechanical ventilation (hours): 26', 'donor mechanical ventilation (hours): 59', 'donor mechanical ventilation (hours): 210', 'donor mechanical ventilation (hours): 74', 'donor mechanical ventilation (hours): 82', 'donor mechanical ventilation (hours): 30', 'donor mechanical ventilation (hours): 124', 'donor mechanical ventilation (hours): 46', 'donor mechanical ventilation (hours): 78', 'donor mechanical ventilation (hours): 138', 'donor mechanical ventilation (hours): 557', 'donor mechanical ventilation (hours): 24', 'donor mechanical ventilation (hours): 141', 'donor mechanical ventilation (hours): 288', 'donor mechanical ventilation (hours): 580', 'donor mechanical ventilation (hours): 93', 'donor mechanical ventilation (hours): 60'], 9: ['donor pao2/fio2 ratio: 370', 'donor pao2/fio2 ratio: 336', 'donor pao2/fio2 ratio: 399', 'donor pao2/fio2 ratio: 453', 'donor pao2/fio2 ratio: 626', 'donor pao2/fio2 ratio: 529', 'donor pao2/fio2 ratio: 428', 'donor pao2/fio2 ratio: 607', 'donor pao2/fio2 ratio: 484', 'donor pao2/fio2 ratio: 392', 'donor pao2/fio2 ratio: 441', 'donor pao2/fio2 ratio: 431', 'donor pao2/fio2 ratio: 495', 'donor pao2/fio2 ratio: 393', 'donor pao2/fio2 ratio: 409', 'donor pao2/fio2 ratio: 386', 'donor pao2/fio2 ratio: 561', 'donor pao2/fio2 ratio: 507', 'donor pao2/fio2 ratio: 449', 'donor pao2/fio2 ratio: 530', 'donor pao2/fio2 ratio: 568', 'donor pao2/fio2 ratio: 332', 'donor pao2/fio2 ratio: 367', 'donor pao2/fio2 ratio: 546', 'donor pao2/fio2 ratio: 226', 'donor pao2/fio2 ratio: 112', 'donor pao2/fio2 ratio: 398', 'donor pao2/fio2 ratio: 497', 'donor pao2/fio2 ratio: 388', 'donor pao2/fio2 ratio: 352'], 10: ['donation type: DBD', 'donation type: DCD'], 11: ['donor warm ischemia time (min): NA', 'donor warm ischemia time (min): 10', 'donor warm ischemia time (min): 8', 'donor warm ischemia time (min): 12', 'donor warm ischemia time (min): 9', 'donor warm ischemia time (min): 11', 'donor warm ischemia time (min): 14', 'donor warm ischemia time (min): 15', 'donor warm ischemia time (min): 19'], 12: ['biopsy rewarming ischemia time (min): 59', 'biopsy rewarming ischemia time (min): 48', 'biopsy rewarming ischemia time (min): 73', 'biopsy rewarming ischemia time (min): 93', 'biopsy rewarming ischemia time (min): 61', 'biopsy rewarming ischemia time (min): 51', 'biopsy rewarming ischemia time (min): 94', 'biopsy rewarming ischemia time (min): 60', 'biopsy rewarming ischemia time (min): 69', 'biopsy rewarming ischemia time (min): 68', 'biopsy rewarming ischemia time (min): 76', 'biopsy rewarming ischemia time (min): 53', 'biopsy rewarming ischemia time (min): 82', 'biopsy rewarming ischemia time (min): 72', 'biopsy rewarming ischemia time (min): 70', 'biopsy rewarming ischemia time (min): 85', 'biopsy rewarming ischemia time (min): 65', 'biopsy rewarming ischemia time (min): 56', 'biopsy rewarming ischemia time (min): 75', 'biopsy rewarming ischemia time (min): 77', 'biopsy rewarming ischemia time (min): 98', 'biopsy rewarming ischemia time (min): 103', 'biopsy rewarming ischemia time (min): 67', 'biopsy rewarming ischemia time (min): 55', 'biopsy rewarming ischemia time (min): 62', 'biopsy rewarming ischemia time (min): 96', 'biopsy rewarming ischemia time (min): 87', 'biopsy rewarming ischemia time (min): 44', 'biopsy rewarming ischemia time (min): 80', 'biopsy rewarming ischemia time (min): 84'], 13: ['cold ischemia (min): 358', 'cold ischemia (min): 277', 'cold ischemia (min): 574', 'cold ischemia (min): 378', 'cold ischemia (min): 400', 'cold ischemia (min): 294', 'cold ischemia (min): 532', 'cold ischemia (min): 203', 'cold ischemia (min): 321', 'cold ischemia (min): 192', 'cold ischemia (min): 335', 'cold ischemia (min): 205', 'cold ischemia (min): 536', 'cold ischemia (min): 350', 'cold ischemia (min): 456', 'cold ischemia (min): 260', 'cold ischemia (min): 533', 'cold ischemia (min): 353', 'cold ischemia (min): 391', 'cold ischemia (min): 212', 'cold ischemia (min): 392', 'cold ischemia (min): 210', 'cold ischemia (min): 410', 'cold ischemia (min): 515', 'cold ischemia (min): 300', 'cold ischemia (min): 452', 'cold ischemia (min): 331', 'cold ischemia (min): 308', 'cold ischemia (min): 543', 'cold ischemia (min): 305']}\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": "5a3fdadb", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "85bd1d75", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:04:46.209790Z", "iopub.status.busy": "2025-03-25T04:04:46.209688Z", "iopub.status.idle": "2025-03-25T04:04:46.215420Z", "shell.execute_reply": "2025-03-25T04:04:46.215125Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 1. Gene Expression Data Availability\n", "# From the background information, this dataset contains transcriptome data from the nCounter Immunology V2 panel\n", "# which targets 579 immune system-associated genes. This is gene expression data.\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "\n", "# Looking for stroke-related variables in the sample characteristics\n", "# From reviewing the data, this dataset is about lung transplantation, not stroke\n", "# The rewarming ischemia time could potentially be used as a continuous variable related to ischemia\n", "# but it doesn't provide a binary stroke/non-stroke classification\n", "trait_row = None # No Stroke variable available\n", "\n", "# Age data is available in row 3\n", "age_row = 3\n", "\n", "# Gender data is available in row 4\n", "gender_row = 4\n", "\n", "# 2.2 Data Type Conversion\n", "\n", "# Since trait is not available, we'll define a function but it won't be used\n", "def convert_trait(value):\n", " return None\n", "\n", "# Convert age (extract numeric value after colon)\n", "def convert_age(value):\n", " if not value or ':' not in value:\n", " return None\n", " try:\n", " age_str = value.split(':')[1].strip()\n", " return float(age_str)\n", " except:\n", " return None\n", "\n", "# Convert gender (female=0, male=1)\n", "def convert_gender(value):\n", " if not value or ':' not in value:\n", " return None\n", " gender_str = value.split(':')[1].strip().lower()\n", " if 'female' in gender_str:\n", " return 0\n", " elif 'male' in gender_str:\n", " return 1\n", " else:\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Initial filtering - this dataset doesn't have stroke trait data\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", "# Since trait_row is None, we'll skip this step\n" ] }, { "cell_type": "markdown", "id": "9e9b56ff", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "80978d9d", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:04:46.216451Z", "iopub.status.busy": "2025-03-25T04:04:46.216344Z", "iopub.status.idle": "2025-03-25T04:04:46.232676Z", "shell.execute_reply": "2025-03-25T04:04:46.232388Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matrix file found: ../../input/GEO/Stroke/GSE273225/GSE273225_series_matrix.txt.gz\n", "Gene data shape: (608, 118)\n", "First 20 gene/probe identifiers:\n", "Index(['ABCB1', 'ABCF1', 'ABL1', 'ADA', 'AHR', 'AICDA', 'AIRE', 'ALAS1', 'APP',\n", " 'ARG1', 'ARG2', 'ARHGDIB', 'ATG10', 'ATG12', 'ATG16L1', 'ATG5', 'ATG7',\n", " 'ATM', 'B2M', 'B3GAT1'],\n", " dtype='object', name='ID')\n" ] } ], "source": [ "# 1. Get the SOFT and matrix file paths again \n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "print(f\"Matrix file found: {matrix_file}\")\n", "\n", "# 2. Use the get_genetic_data function from the library to get the gene_data\n", "try:\n", " gene_data = get_genetic_data(matrix_file)\n", " print(f\"Gene data shape: {gene_data.shape}\")\n", " \n", " # 3. Print the first 20 row IDs (gene or probe identifiers)\n", " print(\"First 20 gene/probe identifiers:\")\n", " print(gene_data.index[:20])\n", "except Exception as e:\n", " print(f\"Error extracting gene data: {e}\")\n" ] }, { "cell_type": "markdown", "id": "738c9810", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "0c41c280", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:04:46.233678Z", "iopub.status.busy": "2025-03-25T04:04:46.233577Z", "iopub.status.idle": "2025-03-25T04:04:46.235246Z", "shell.execute_reply": "2025-03-25T04:04:46.234973Z" } }, "outputs": [], "source": [ "# These appear to be standard human gene symbols\n", "# They include well-known genes like ABCB1 (multidrug resistance gene), \n", "# B2M (Beta-2-microglobulin), and ATM (ataxia telangiectasia mutated)\n", "# No mapping to gene symbols is required as these are already gene symbols\n", "\n", "requires_gene_mapping = False\n" ] }, { "cell_type": "markdown", "id": "0c360524", "metadata": {}, "source": [ "### Step 5: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 6, "id": "c4acc775", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:04:46.236197Z", "iopub.status.busy": "2025-03-25T04:04:46.236101Z", "iopub.status.idle": "2025-03-25T04:04:46.360678Z", "shell.execute_reply": "2025-03-25T04:04:46.360331Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Original gene data shape: (608, 118)\n", "Gene data shape after normalization: (576, 118)\n", "Normalized gene expression data saved to ../../output/preprocess/Stroke/gene_data/GSE273225.csv\n", "Created clinical data with shape: (1, 118)\n", "Clinical data sample:\n", " GSM8424381 GSM8424382 GSM8424383 GSM8424384 GSM8424385\n", "Stroke 1 1 1 1 1\n", "Linked data shape: (577, 118)\n", "Linked data preview (first 5 rows, 5 columns):\n", " GSM8424381 GSM8424382 GSM8424383 GSM8424384 GSM8424385\n", "Stroke 1.0 1.0 1.0 1.0 1.0\n", "ABCB1 846.0 1291.0 662.0 577.0 394.0\n", "ABCF1 695.0 971.0 586.0 384.0 757.0\n", "ABL1 1013.0 1262.0 799.0 721.0 969.0\n", "ACKR4 412.5 639.5 191.0 240.0 557.0\n", "\n", "Dataset contains only one class for Stroke (all patients have stroke). This makes it biased for case-control studies.\n", "Dataset deemed not usable for case-control studies. Linked data not saved.\n" ] } ], "source": [ "# 1. Normalize gene symbols in the obtained gene expression data\n", "# Note: Gene symbols were already normalized in Step 6, but we'll do it again to ensure consistency\n", "print(f\"Original gene data shape: {gene_data.shape}\")\n", "\n", "# Normalize gene symbols\n", "gene_data_normalized = normalize_gene_symbols_in_index(gene_data)\n", "print(f\"Gene data shape after normalization: {gene_data_normalized.shape}\")\n", "\n", "# Save the normalized gene expression data if not already done\n", "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", "gene_data_normalized.to_csv(out_gene_data_file)\n", "print(f\"Normalized gene expression data saved to {out_gene_data_file}\")\n", "\n", "# 2. Create clinical data with the trait information (all samples are stroke patients)\n", "# Extract sample IDs from gene data columns\n", "sample_ids = gene_data_normalized.columns.tolist()\n", "\n", "# Create a DataFrame with the Stroke trait (all samples are stroke patients)\n", "clinical_data = pd.DataFrame({\n", " trait: [1] * len(sample_ids)\n", "}, index=sample_ids)\n", "\n", "# Transpose clinical_data to have the right format for linking\n", "clinical_data = clinical_data.T\n", "\n", "print(f\"Created clinical data with shape: {clinical_data.shape}\")\n", "print(\"Clinical data sample:\")\n", "print(clinical_data.iloc[:, :5]) # Show first 5 columns\n", "\n", "# Link clinical and genetic data\n", "linked_data = pd.concat([clinical_data, gene_data_normalized], axis=0)\n", "print(f\"Linked data shape: {linked_data.shape}\")\n", "print(\"Linked data preview (first 5 rows, 5 columns):\")\n", "print(linked_data.iloc[:5, :5])\n", "\n", "# 3. Handle missing values\n", "# Note: Since we created the clinical data manually, there shouldn't be missing values in the trait column\n", "linked_data_clean = linked_data.copy()\n", "\n", "# 4. Check for bias in the dataset\n", "# Since all samples have stroke (trait=1), this is a single-class dataset\n", "# which is inherently biased for case-control studies\n", "is_biased = True\n", "print(\"\\nDataset contains only one class for Stroke (all patients have stroke). This makes it biased for case-control studies.\")\n", "\n", "# 5. Conduct final quality 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=True,\n", " is_trait_available=True, # Trait data is available (all samples are stroke patients)\n", " is_biased=is_biased,\n", " df=linked_data_clean,\n", " note=\"Dataset contains gene expression data from peripheral blood of stroke patients. All samples are stroke patients (trait=1), which makes it biased for case-control studies but might be useful for other analyses beyond case-control comparisons.\"\n", ")\n", "\n", "# 6. Save the linked data if it's usable\n", "if is_usable:\n", " os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n", " linked_data_clean.to_csv(out_data_file, index=True)\n", " print(f\"Linked data saved to {out_data_file}\")\n", "else:\n", " print(\"Dataset deemed not usable for case-control studies. Linked 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 }