{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f3fe6adb", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:05:13.330141Z", "iopub.status.busy": "2025-03-25T04:05:13.330024Z", "iopub.status.idle": "2025-03-25T04:05:13.499371Z", "shell.execute_reply": "2025-03-25T04:05:13.498850Z" } }, "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 = \"GSE48424\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Stroke\"\n", "in_cohort_dir = \"../../input/GEO/Stroke/GSE48424\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Stroke/GSE48424.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Stroke/gene_data/GSE48424.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Stroke/clinical_data/GSE48424.csv\"\n", "json_path = \"../../output/preprocess/Stroke/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "f1f2538f", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "851829f1", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:05:13.501088Z", "iopub.status.busy": "2025-03-25T04:05:13.500918Z", "iopub.status.idle": "2025-03-25T04:05:14.011812Z", "shell.execute_reply": "2025-03-25T04:05:14.011268Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Severe preeclampsia: new blood circulating biomarkers\"\n", "!Series_summary\t\"Background: Preeclampsia (PE) is a placental disease characterized by hypertension and proteinuria in pregnant women, which is associated with a high maternal and infantile morbidity. However, circulating biomarkers able to predict the prognosis of PE are lacking.\"\n", "!Series_summary\t\"Methods: Thirty-eight women were included in the study. They consisted of 19 patients with PE (13 with severe PE and 6 women with non-severe PE) and 19 gestational age-matched normal pregnancy controls. We measured coagulation pathway, endothelial responses and microparticle release and circulating gene expression in PE patient groups and normotensive controls.\"\n", "!Series_summary\t\"Results: The measurement of markers associated with coagulation pathway, endothelial activation and circulating microparticles enabled to discriminate PE from normal pregnancy but were not sufficient to distinguish severe from non-severe PE. PE patients also exhibited a specific transcriptional program distinct from that of control women and subtle differences were observed between severe and non-severe PE. Functional annotation of the up-modulated signature in PE highlighted two main functions related to ribosome and complement. Importantly, we found that 8 genes were specifically up-modulated in severe preeclampsia. Among these genes, the expression of VSIG4 was significantly increased in patients with severe preeclampsia in comparison with controls and patients with non-severe preeclampsia.\"\n", "!Series_summary\t\"Conclusion: Using transcriptional signatures of blood samples, we identified the gene encoding the estrogen receptor as a potential diagnostic marker of severe preeclampsia. In addition, the determination of this gene may improve the prognostic assessment of severe preeclampsia.\"\n", "!Series_overall_design\t\"Thirty-eight women were included in the study: 19 patients with PE, including 6 women with non-severe PE and 13 with severe PE, and 19 women with normal pregnancy (NP) selected according to age, weight, smoking status, race, gestational age at the inclusion, and blood pH (Table 1 of manuscript). Women with NP had no history of medical illness or medication, and received routing prenatal care. The diagnostic of PE was based on a blood pressure of ≥ 140/90 mmHg taken twice, uricemia above normal laboratory range (120-420 µmol/L), and proteinuria higher than 300 mg in a 24 hour-collection, occurring after 20 gestational weeks in previously normotensive women (Table 2). The criteria used to define severe PE included one of the following conditions: a blood pressure higher than 160/110 mmHg, a proteinuria higher than 1500 mg/24h), a multisystem disorder, maternal cerebral symptoms (seizures, stroke) or intrauterine growth restriction below the 3° percentile. Women with multiple gestations, fetal congenital malformations/chromosomal abnormalities, recent infection, antiphospholipid antibodies, trauma, drug or alcohol abuse during pregnancy, preexisting hypertension, thrombophilia with PE history, or women receiving anticoagulant or antiaggregation therapy were excluded from the study.\"\n", "!Series_overall_design\t\"Two microarrays (one non-severe PE and one normal) were discarded from the analysis for technical reasons. Thus, only 36 microarrays are included here.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['tissue: blood'], 1: ['disease status: preeclampsia', 'disease status: healthy'], 2: ['matching: A', 'matching: B', 'matching: C'], 3: ['age: 32', 'age: 25', 'age: 30', 'age: 28', 'age: 27', 'age: 23', 'age: 21', 'age: 31', 'age: 34', 'age: 33', 'age: 38', 'age: 43', 'age: 29', 'age: 26', 'age: 37', 'age: 40'], 4: ['severity: S', 'severity: NA', 'severity: NS'], 5: ['gestational age (weeks): 36', 'gestational age (weeks): 37', 'gestational age (weeks): 33', 'gestational age (weeks): 28', 'gestational age (weeks): 34', 'gestational age (weeks): 31', 'gestational age (weeks): 38', 'gestational age (weeks): 27', 'gestational age (weeks): 29', 'gestational age (weeks): 16', 'gestational age (weeks): 18', 'gestational age (weeks): 40', 'gestational age (weeks): 23', 'gestational age (weeks): 35']}\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": "2047fc7e", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "7ccd19c0", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:05:14.013667Z", "iopub.status.busy": "2025-03-25T04:05:14.013532Z", "iopub.status.idle": "2025-03-25T04:05:14.020989Z", "shell.execute_reply": "2025-03-25T04:05:14.020546Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "import numpy as np\n", "import os\n", "import re\n", "import json\n", "from typing import Optional, Callable, Dict, Any, List\n", "\n", "# Analyze the data availability and setup conversion functions\n", "\n", "# 1. Determine gene expression data availability\n", "# Based on the background information about preeclampsia research with gene expression mentioned,\n", "# the dataset likely contains gene expression data\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "\n", "# 2.1 Data Availability\n", "# For trait (Stroke), we need to determine if it's available in this dataset\n", "# Looking at the sample characteristics dictionary, key 1 has 'disease status' which shows preeclampsia vs healthy\n", "# This dataset is about preeclampsia, not stroke, so it's not directly relevant to our trait\n", "trait_row = None\n", "\n", "# For age, the sample characteristics dictionary key 3 has multiple age values\n", "age_row = 3\n", "\n", "# For gender, there's no explicit mention in the sample characteristics\n", "# Based on the background information, this is a study of pregnant women, so all subjects are female\n", "# Since gender is constant, we consider it not available for our analysis\n", "gender_row = None\n", "\n", "# 2.2 Data Type Conversion Functions\n", "# Since trait data is not available for our stroke study, we'll still define a function\n", "# but it won't be used in further analysis\n", "def convert_trait(value):\n", " # This won't be used since trait_row is None, but we define it as required\n", " if value is None or pd.isna(value):\n", " return None\n", " \n", " value_str = str(value).lower()\n", " if ':' in value_str:\n", " value_str = value_str.split(':', 1)[1].strip()\n", " \n", " if 'preeclampsia' in value_str or 'pe' in value_str:\n", " return 1 # affected\n", " elif 'healthy' in value_str or 'normal' in value_str:\n", " return 0 # unaffected\n", " else:\n", " return None\n", "\n", "def convert_age(value):\n", " if value is None or pd.isna(value):\n", " return None\n", " \n", " value_str = str(value)\n", " if ':' in value_str:\n", " value_str = value_str.split(':', 1)[1].strip()\n", " \n", " try:\n", " return float(value_str) # Age is continuous\n", " except ValueError:\n", " return None\n", "\n", "def convert_gender(value):\n", " # This won't be used since gender_row is None, but we define it as required\n", " # All subjects in this study are female\n", " return 0 # Female = 0\n", "\n", "# 3. Save Metadata\n", "# Determine if trait data is available (it's not for our stroke study)\n", "is_trait_available = trait_row is not None\n", "\n", "# Conduct initial filtering\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", "# Skip this substep since trait_row is None (clinical data for stroke is not available)\n" ] }, { "cell_type": "markdown", "id": "aaaa69ba", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "27eb37c3", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:05:14.022471Z", "iopub.status.busy": "2025-03-25T04:05:14.022358Z", "iopub.status.idle": "2025-03-25T04:05:14.274621Z", "shell.execute_reply": "2025-03-25T04:05:14.273914Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matrix file found: ../../input/GEO/Stroke/GSE48424/GSE48424_series_matrix.txt.gz\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape: (41000, 36)\n", "First 20 gene/probe identifiers:\n", "Index(['A_23_P100001', 'A_23_P100011', 'A_23_P100022', 'A_23_P100056',\n", " 'A_23_P100074', 'A_23_P100092', 'A_23_P100103', 'A_23_P100111',\n", " 'A_23_P100127', 'A_23_P100133', 'A_23_P100141', 'A_23_P100156',\n", " 'A_23_P100177', 'A_23_P100189', 'A_23_P100196', 'A_23_P100203',\n", " 'A_23_P100220', 'A_23_P100240', 'A_23_P10025', 'A_23_P100263'],\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": "3bb4465a", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "1cc082d3", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:05:14.276661Z", "iopub.status.busy": "2025-03-25T04:05:14.276330Z", "iopub.status.idle": "2025-03-25T04:05:14.278671Z", "shell.execute_reply": "2025-03-25T04:05:14.278226Z" } }, "outputs": [], "source": [ "# Looking at the gene identifiers, they appear to be Agilent microarray probe IDs (A_23_P format)\n", "# These are not human gene symbols and will need to be mapped to gene symbols\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "e924bc58", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "3692ebbc", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:05:14.280152Z", "iopub.status.busy": "2025-03-25T04:05:14.280046Z", "iopub.status.idle": "2025-03-25T04:05:16.890806Z", "shell.execute_reply": "2025-03-25T04:05:16.890239Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene annotation preview:\n", "Columns in gene annotation: ['ID', 'SPOT_ID', 'CONTROL_TYPE', 'REFSEQ', 'GB_ACC', 'GENE', 'GENE_SYMBOL', 'GENE_NAME', 'UNIGENE_ID', 'ENSEMBL_ID', 'TIGR_ID', 'ACCESSION_STRING', 'CHROMOSOMAL_LOCATION', 'CYTOBAND', 'DESCRIPTION', 'GO_ID', 'SEQUENCE']\n", "{'ID': ['A_23_P100001', 'A_23_P100011', 'A_23_P100022', 'A_23_P100056', 'A_23_P100074'], 'SPOT_ID': ['A_23_P100001', 'A_23_P100011', 'A_23_P100022', 'A_23_P100056', 'A_23_P100074'], 'CONTROL_TYPE': ['FALSE', 'FALSE', 'FALSE', 'FALSE', 'FALSE'], 'REFSEQ': ['NM_207446', 'NM_005829', 'NM_014848', 'NM_194272', 'NM_020371'], 'GB_ACC': ['NM_207446', 'NM_005829', 'NM_014848', 'NM_194272', 'NM_020371'], 'GENE': [400451.0, 10239.0, 9899.0, 348093.0, 57099.0], 'GENE_SYMBOL': ['FAM174B', 'AP3S2', 'SV2B', 'RBPMS2', 'AVEN'], 'GENE_NAME': ['family with sequence similarity 174, member B', 'adaptor-related protein complex 3, sigma 2 subunit', 'synaptic vesicle glycoprotein 2B', 'RNA binding protein with multiple splicing 2', 'apoptosis, caspase activation inhibitor'], 'UNIGENE_ID': ['Hs.27373', 'Hs.632161', 'Hs.21754', 'Hs.436518', 'Hs.555966'], 'ENSEMBL_ID': ['ENST00000557398', nan, 'ENST00000557410', 'ENST00000300069', 'ENST00000306730'], 'TIGR_ID': [nan, nan, nan, nan, nan], 'ACCESSION_STRING': ['ref|NM_207446|ens|ENST00000557398|ens|ENST00000553393|ens|ENST00000327355', 'ref|NM_005829|ref|NM_001199058|ref|NR_023361|ref|NR_037582', 'ref|NM_014848|ref|NM_001167580|ens|ENST00000557410|ens|ENST00000330276', 'ref|NM_194272|ens|ENST00000300069|gb|AK127873|gb|AK124123', 'ref|NM_020371|ens|ENST00000306730|gb|AF283508|gb|BC010488'], 'CHROMOSOMAL_LOCATION': ['chr15:93160848-93160789', 'chr15:90378743-90378684', 'chr15:91838329-91838388', 'chr15:65032375-65032316', 'chr15:34158739-34158680'], 'CYTOBAND': ['hs|15q26.1', 'hs|15q26.1', 'hs|15q26.1', 'hs|15q22.31', 'hs|15q14'], 'DESCRIPTION': ['Homo sapiens family with sequence similarity 174, member B (FAM174B), mRNA [NM_207446]', 'Homo sapiens adaptor-related protein complex 3, sigma 2 subunit (AP3S2), transcript variant 1, mRNA [NM_005829]', 'Homo sapiens synaptic vesicle glycoprotein 2B (SV2B), transcript variant 1, mRNA [NM_014848]', 'Homo sapiens RNA binding protein with multiple splicing 2 (RBPMS2), mRNA [NM_194272]', 'Homo sapiens apoptosis, caspase activation inhibitor (AVEN), mRNA [NM_020371]'], 'GO_ID': ['GO:0016020(membrane)|GO:0016021(integral to membrane)', 'GO:0005794(Golgi apparatus)|GO:0006886(intracellular protein transport)|GO:0008565(protein transporter activity)|GO:0016020(membrane)|GO:0016192(vesicle-mediated transport)|GO:0030117(membrane coat)|GO:0030659(cytoplasmic vesicle membrane)|GO:0031410(cytoplasmic vesicle)', 'GO:0001669(acrosomal vesicle)|GO:0006836(neurotransmitter transport)|GO:0016020(membrane)|GO:0016021(integral to membrane)|GO:0022857(transmembrane transporter activity)|GO:0030054(cell junction)|GO:0030672(synaptic vesicle membrane)|GO:0031410(cytoplasmic vesicle)|GO:0045202(synapse)', 'GO:0000166(nucleotide binding)|GO:0003676(nucleic acid binding)', 'GO:0005515(protein binding)|GO:0005622(intracellular)|GO:0005624(membrane fraction)|GO:0006915(apoptosis)|GO:0006916(anti-apoptosis)|GO:0012505(endomembrane system)|GO:0016020(membrane)'], 'SEQUENCE': ['ATCTCATGGAAAAGCTGGATTCCTCTGCCTTACGCAGAAACACCCGGGCTCCATCTGCCA', 'TCAAGTATTGGCCTGACATAGAGTCCTTAAGACAAGCAAAGACAAGCAAGGCAAGCACGT', 'ATGTCGGCTGTGGAGGGTTAAAGGGATGAGGCTTTCCTTTGTTTAGCAAATCTGTTCACA', 'CCCTGTCAGATAAGTTTAATGTTTAGTTTGAGGCATGAAGAAGAAAAGGGTTTCCATTCT', 'GACCAGCCAGTTTACAAGCATGTCTCAAGCTAGTGTGTTCCATTATGCTCACAGCAGTAA']}\n", "\n", "Searching for platform information in SOFT file:\n", "!Series_platform_id = GPL6480\n", "\n", "Searching for gene symbol information in SOFT file:\n", "Found references to gene symbols:\n", "#GENE_SYMBOL = Gene Symbol\n", "ID\tSPOT_ID\tCONTROL_TYPE\tREFSEQ\tGB_ACC\tGENE\tGENE_SYMBOL\tGENE_NAME\tUNIGENE_ID\tENSEMBL_ID\tTIGR_ID\tACCESSION_STRING\tCHROMOSOMAL_LOCATION\tCYTOBAND\tDESCRIPTION\tGO_ID\tSEQUENCE\n", "A_23_P102607\tA_23_P102607\tFALSE\t\tBC039860\t84181\tCHD6\tchromodomain helicase DNA binding protein 6\tHs.730855\tENST00000373222\t\tens|ENST00000373222|ens|ENST00000470470|gb|BC039860|gb|BC040016\tchr20:40126054-40125995\ths|20q12\tchromodomain helicase DNA binding protein 6 [Source:HGNC Symbol;Acc:19057] [ENST00000373222]\tGO:0000166(nucleotide binding)|GO:0003677(DNA binding)|GO:0003682(chromatin binding)|GO:0004386(helicase activity)|GO:0005524(ATP binding)|GO:0005634(nucleus)|GO:0006338(chromatin remodeling)|GO:0006355(regulation of transcription, DNA-dependent)|GO:0007399(nervous system development)|GO:0008026(ATP-dependent helicase activity)|GO:0016817(hydrolase activity, acting on acid anhydrides)\tACAAGCCCAGATGAAGCACATTTTTACGGAGGTGAAGCAATATTTACTGACTCATTTGAC\n", "A_23_P103897\tA_23_P103897\tFALSE\t\tXM_003118960\t\t\t\tHs.584956\tENST00000431031\t\tens|ENST00000431031|ens|ENST00000490879|ens|ENST00000460286|ens|ENST00000263717\tchr1:85009909-85009968\ths|1p22.3\tspermatogenesis associated 1 [Source:HGNC Symbol;Acc:14682] [ENST00000431031]\t\tCTACCAGATCACCCTTCACTTCCTTGTCAACCTGTTCTTTCTTCAGGAATAACTGATATA\n", "A_23_P104335\tA_23_P104335\tFALSE\t\tU79304\t220965\tFAM13C\tfamily with sequence similarity 13, member C\tHs.607594\tENST00000422313\t\tens|ENST00000422313|gb|U79304|tc|THC2733885\tchr10:61014017-61013958\ths|10q21.1\tfamily with sequence similarity 13, member C [Source:HGNC Symbol;Acc:19371] [ENST00000422313]\t\tCATGGCAGTATATACTGCAAACAAGGCTAGTTGTCATTTCAAAAAGTGAAAATTTGGTCT\n", "\n", "Checking for additional annotation files in the directory:\n", "[]\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. Analyze the gene annotation dataframe to identify which columns contain the gene identifiers and gene symbols\n", "print(\"\\nGene annotation preview:\")\n", "print(f\"Columns in gene annotation: {gene_annotation.columns.tolist()}\")\n", "print(preview_df(gene_annotation, n=5))\n", "\n", "# Let's look for platform information in the SOFT file to understand the annotation better\n", "print(\"\\nSearching for platform information in SOFT file:\")\n", "with gzip.open(soft_file, 'rt') as f:\n", " for i, line in enumerate(f):\n", " if '!Series_platform_id' in line:\n", " print(line.strip())\n", " break\n", " if i > 100: # Limit search to first 100 lines\n", " print(\"Platform ID not found in first 100 lines\")\n", " break\n", "\n", "# Check if the SOFT file includes any reference to gene symbols\n", "print(\"\\nSearching for gene symbol information in SOFT file:\")\n", "with gzip.open(soft_file, 'rt') as f:\n", " gene_symbol_lines = []\n", " for i, line in enumerate(f):\n", " if 'GENE_SYMBOL' in line or 'gene_symbol' in line.lower() or 'symbol' in line.lower():\n", " gene_symbol_lines.append(line.strip())\n", " if i > 1000 and len(gene_symbol_lines) > 0: # Limit search but ensure we found something\n", " break\n", " \n", " if gene_symbol_lines:\n", " print(\"Found references to gene symbols:\")\n", " for line in gene_symbol_lines[:5]: # Show just first 5 matches\n", " print(line)\n", " else:\n", " print(\"No explicit gene symbol references found in first 1000 lines\")\n", "\n", "# Look for alternative annotation files or references in the directory\n", "print(\"\\nChecking for additional annotation files in the directory:\")\n", "all_files = os.listdir(in_cohort_dir)\n", "print([f for f in all_files if 'annotation' in f.lower() or 'platform' in f.lower() or 'gpl' in f.lower()])\n" ] }, { "cell_type": "markdown", "id": "527925b5", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "9744a4f7", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:05:16.892702Z", "iopub.status.busy": "2025-03-25T04:05:16.892571Z", "iopub.status.idle": "2025-03-25T04:05:17.596770Z", "shell.execute_reply": "2025-03-25T04:05:17.596028Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene mapping dataframe shape: (30936, 2)\n", "First few rows of gene mapping dataframe:\n", " ID Gene\n", "0 A_23_P100001 FAM174B\n", "1 A_23_P100011 AP3S2\n", "2 A_23_P100022 SV2B\n", "3 A_23_P100056 RBPMS2\n", "4 A_23_P100074 AVEN\n", "Gene expression dataframe shape after mapping: (18488, 36)\n", "First few rows of gene expression dataframe:\n", " GSM1177776 GSM1177777 GSM1177778 GSM1177779 GSM1177780 \\\n", "Gene \n", "A1BG 13.191333 11.225844 13.194065 12.276784 11.186062 \n", "A1BG-AS1 7.266653 6.900023 6.468707 6.847638 7.573267 \n", "A1CF 2.140806 2.034748 4.770635 4.082254 1.471878 \n", "A2LD1 6.948963 6.910073 6.219797 7.122556 7.056264 \n", "A2M 3.595800 3.276375 3.455032 3.937070 3.930950 \n", "\n", " GSM1177781 GSM1177782 GSM1177783 GSM1177784 GSM1177785 ... \\\n", "Gene ... \n", "A1BG 12.370441 13.186556 11.184960 12.125299 12.323756 ... \n", "A1BG-AS1 7.191150 7.217039 6.688492 7.366197 7.832534 ... \n", "A1CF 3.728567 3.539863 2.919945 1.488859 2.737571 ... \n", "A2LD1 6.428839 6.031170 5.706793 6.530993 6.207082 ... \n", "A2M 2.770054 3.176001 3.101843 5.275287 3.404202 ... \n", "\n", " GSM1177802 GSM1177803 GSM1177804 GSM1177805 GSM1177806 \\\n", "Gene \n", "A1BG 13.019509 14.049770 13.512138 12.007308 12.941017 \n", "A1BG-AS1 6.715186 6.797771 6.875800 7.142049 6.149959 \n", "A1CF 2.505474 2.478460 1.524342 3.565981 3.572230 \n", "A2LD1 6.147545 6.454377 6.270419 6.141975 6.290769 \n", "A2M 3.917569 3.769770 3.789713 4.014216 4.166948 \n", "\n", " GSM1177807 GSM1177808 GSM1177809 GSM1177810 GSM1177811 \n", "Gene \n", "A1BG 13.238611 13.008843 14.007356 13.698969 15.716180 \n", "A1BG-AS1 7.729975 7.025670 7.031475 7.035060 7.323792 \n", "A1CF 1.454475 1.419986 1.541513 2.349526 1.525540 \n", "A2LD1 7.276083 6.893767 6.499272 6.219501 6.633174 \n", "A2M 5.212388 3.674757 4.881107 3.906627 4.159279 \n", "\n", "[5 rows x 36 columns]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data saved to ../../output/preprocess/Stroke/gene_data/GSE48424.csv\n" ] } ], "source": [ "# 1. Identify which columns in the annotation dataframe contain probe IDs and gene symbols\n", "# Based on the preview, 'ID' contains probe identifiers (like A_23_P100001) that match the gene expression data\n", "# 'GENE_SYMBOL' contains the human gene symbols we need to map to\n", "\n", "# 2. Get a gene mapping dataframe with the relevant columns\n", "gene_mapping = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL')\n", "print(f\"Gene mapping dataframe shape: {gene_mapping.shape}\")\n", "print(\"First few rows of gene mapping dataframe:\")\n", "print(gene_mapping.head())\n", "\n", "# 3. Apply the gene mapping to convert probe-level measurements to gene expression\n", "# This function distributes probe values to genes and aggregates across multiple probes\n", "gene_data = apply_gene_mapping(gene_data, gene_mapping)\n", "print(f\"Gene expression dataframe shape after mapping: {gene_data.shape}\")\n", "print(\"First few rows of gene expression dataframe:\")\n", "print(gene_data.head())\n", "\n", "# Optional: Save the processed gene expression 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" ] }, { "cell_type": "markdown", "id": "d7db7cde", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "de62a5ba", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T04:05:17.599008Z", "iopub.status.busy": "2025-03-25T04:05:17.598856Z", "iopub.status.idle": "2025-03-25T04:05:18.225482Z", "shell.execute_reply": "2025-03-25T04:05:18.224888Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Original gene data shape: (18488, 36)\n", "Gene data shape after normalization: (18247, 36)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene expression data saved to ../../output/preprocess/Stroke/gene_data/GSE48424.csv\n", "No trait data available. Can't proceed with linking clinical and genetic data.\n", "Abnormality detected in the cohort: GSE48424. Preprocessing failed.\n", "Dataset deemed not usable due to missing trait data.\n" ] } ], "source": [ "# 1. Normalize gene symbols in the obtained gene expression data\n", "# Use the gene_data variable that was already loaded in Step 4\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\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. No clinical data available (trait_row is None from previous steps)\n", "# We can't proceed with linking clinical and genetic data\n", "print(\"No trait data available. Can't proceed with linking clinical and genetic data.\")\n", "\n", "# Create a minimal dataframe for validation purposes \n", "# (since we need a valid DataFrame when is_final=True)\n", "empty_df = pd.DataFrame({\"dummy\": [0]})\n", "\n", "# Since trait data is not available, the dataset is not usable for our purposes\n", "# We pass is_biased=True to indicate unusable data\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=False,\n", " is_biased=True, # Setting is_biased to True since missing trait data makes dataset unusable\n", " df=empty_df,\n", " note=\"No stroke-specific trait data available in this dataset. Contains gene expression data from peripheral blood of older adults, but without clear stroke indicators.\"\n", ")\n", "print(\"Dataset deemed not usable due to missing trait data.\")" ] } ], "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 }