{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "fcee1a85", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:55:23.216187Z", "iopub.status.busy": "2025-03-25T05:55:23.216085Z", "iopub.status.idle": "2025-03-25T05:55:23.376351Z", "shell.execute_reply": "2025-03-25T05:55:23.376022Z" } }, "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 = \"Obesity\"\n", "cohort = \"GSE281144\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Obesity\"\n", "in_cohort_dir = \"../../input/GEO/Obesity/GSE281144\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Obesity/GSE281144.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Obesity/gene_data/GSE281144.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Obesity/clinical_data/GSE281144.csv\"\n", "json_path = \"../../output/preprocess/Obesity/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "407e4b1a", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "7edc2268", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:55:23.377716Z", "iopub.status.busy": "2025-03-25T05:55:23.377583Z", "iopub.status.idle": "2025-03-25T05:55:23.539274Z", "shell.execute_reply": "2025-03-25T05:55:23.538938Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Gut Adaptation After Gastric Bypass in Humans Reveals Metabolically Significant Shift in Fuel Metabolism\"\n", "!Series_summary\t\"Objective: Roux-en-Y gastric bypass surgery (RYGB) is among the most effective therapies for obesity and type 2 diabetes (T2D), and intestinal adaptation is a proposed mechanism for these effects. We hypothesized that intestinal adaptation precedes and relates to metabolic improvement in humans after RYGB.\"\n", "!Series_summary\t\"Methods: This was a prospective, longitudinal first-in-human study of gene expression (GE) in Roux limb (RL) collected surgically/endoscopically from 19 patients with and without diabetes. GE was determined by microarray across 6 postoperative months, including at an early postoperative (1 month  15 days) timepoint.\"\n", "!Series_summary\t\"Results: RL GE demonstrated tissue remodeling and metabolic reprogramming, including increased glucose and amino acid utilization. RL GE signatures were established early, before maximal clinical response, and persisted. Distinct GE fingerprints predicted concurrent and future improvements in HbA1c and in weight. Human RL exhibits GE changes characterized by anabolic growth and shift in metabolic substrate utilization. Paradoxically, anabolic growth in RL appears to contribute to the catabolic state elicited by RYGB.\"\n", "!Series_summary\t\"Conclusions: These data support a role for a direct effect of intestinal energy metabolism to contribute to the beneficial clinical effects of RYGB, suggesting that related pathways might be potential targets of therapeutic interest for patients with obesity with or without T2D.\"\n", "!Series_overall_design\t\"This was a prospective, longitudinal first-in-human study of gene expression (GE) in Roux limb (RL) collected surgically/endoscopically from 19 patients with and without diabetes. GE was determined by microarray across 6 postoperative months, including at an early postoperative (1 month  15 days) timepoint.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['Sex: Female', 'Sex: Male'], 1: ['diabetes status: Control', 'diabetes status: Diabetic'], 2: ['treatment: Roux-en-Y gastric bypass surgery (RYGB)']}\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": "058a254f", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "9dd37735", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:55:23.540439Z", "iopub.status.busy": "2025-03-25T05:55:23.540335Z", "iopub.status.idle": "2025-03-25T05:55:23.544097Z", "shell.execute_reply": "2025-03-25T05:55:23.543821Z" } }, "outputs": [], "source": [ "# Analysis of data availability and preparation for feature extraction\n", "import pandas as pd\n", "\n", "# 1. Gene Expression Data Availability\n", "# Based on the background information, this dataset contains gene expression (GE) data\n", "# from microarray analysis, which is suitable for our study.\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "\n", "# Trait (Obesity): \n", "# The dataset is about gastric bypass in patients with obesity (with or without diabetes).\n", "# The trait is constant (all subjects have obesity) according to the background information.\n", "# Therefore, we cannot use this dataset for association studies of obesity vs. non-obesity.\n", "trait_row = None # Obesity status is not available as a variable (all subjects have obesity)\n", "\n", "# Diabetes status is available in row 1\n", "# This could be considered as an alternative trait since it varies among subjects\n", "diabetes_row = 1\n", "\n", "# Age:\n", "# There's no information about age in the sample characteristics\n", "age_row = None\n", "\n", "# Gender:\n", "# Gender information is available in row 0\n", "gender_row = 0\n", "\n", "# 2.2 Data Type Conversion\n", "\n", "# Since we can't use obesity as our trait variable (all subjects have it),\n", "# we'll use diabetes status instead, which is binary\n", "def convert_trait(value):\n", " if isinstance(value, str) and \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " if value.lower() == \"diabetic\":\n", " return 1\n", " elif value.lower() == \"control\":\n", " return 0\n", " return None\n", "\n", "# Age conversion function (not used in this dataset)\n", "def convert_age(value):\n", " return None\n", "\n", "# Gender conversion function\n", "def convert_gender(value):\n", " if isinstance(value, str) and \":\" in value:\n", " value = value.split(\":\", 1)[1].strip()\n", " if value.lower() == \"female\":\n", " return 0\n", " elif value.lower() == \"male\":\n", " return 1\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Since trait_row is None (all subjects have obesity), we'll set is_trait_available to False\n", "is_trait_available = False\n", "\n", "# Validate and save cohort info\n", "initial_validation = 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 skip this step\n" ] }, { "cell_type": "markdown", "id": "8da762ad", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "95ddca14", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:55:23.545223Z", "iopub.status.busy": "2025-03-25T05:55:23.545122Z", "iopub.status.idle": "2025-03-25T05:55:23.750064Z", "shell.execute_reply": "2025-03-25T05:55:23.749693Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "First 20 gene/probe identifiers:\n", "Index(['2824546_st', '2824549_st', '2824551_st', '2824554_st', '2827992_st',\n", " '2827995_st', '2827996_st', '2828010_st', '2828012_st', '2835442_st',\n", " '2835447_st', '2835453_st', '2835456_st', '2835459_st', '2835461_st',\n", " '2839509_st', '2839511_st', '2839513_st', '2839515_st', '2839517_st'],\n", " dtype='object', name='ID')\n" ] } ], "source": [ "# 1. First get the file paths again to access the matrix file\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# 2. Use the get_genetic_data function from the library to get the gene_data from the matrix_file\n", "gene_data = get_genetic_data(matrix_file)\n", "\n", "# 3. Print the first 20 row IDs (gene or probe identifiers) for future observation\n", "print(\"First 20 gene/probe identifiers:\")\n", "print(gene_data.index[:20])\n" ] }, { "cell_type": "markdown", "id": "b9cb1b68", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "602461fb", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:55:23.751279Z", "iopub.status.busy": "2025-03-25T05:55:23.751173Z", "iopub.status.idle": "2025-03-25T05:55:23.752960Z", "shell.execute_reply": "2025-03-25T05:55:23.752699Z" } }, "outputs": [], "source": [ "# These identifiers (e.g., \"2824546_st\") appear to be Affymetrix probe IDs \n", "# rather than standard human gene symbols like BRCA1, TP53, etc.\n", "# Affymetrix probe IDs typically need to be mapped to gene symbols for biological interpretation.\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "8bc92390", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "5777f34f", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:55:23.754004Z", "iopub.status.busy": "2025-03-25T05:55:23.753904Z", "iopub.status.idle": "2025-03-25T05:55:29.298215Z", "shell.execute_reply": "2025-03-25T05:55:29.297834Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['TC01000001.hg.1', 'TC01000002.hg.1', 'TC01000003.hg.1', 'TC01000004.hg.1', 'TC01000005.hg.1'], 'probeset_id': ['TC01000001.hg.1', 'TC01000002.hg.1', 'TC01000003.hg.1', 'TC01000004.hg.1', 'TC01000005.hg.1'], 'seqname': ['chr1', 'chr1', 'chr1', 'chr1', 'chr1'], 'strand': ['+', '+', '+', '+', '+'], 'start': ['11869', '29554', '69091', '160446', '317811'], 'stop': ['14409', '31109', '70008', '161525', '328581'], 'total_probes': [49.0, 60.0, 30.0, 30.0, 191.0], 'gene_assignment': ['NR_046018 // DDX11L1 // DEAD/H (Asp-Glu-Ala-Asp/His) box helicase 11 like 1 // 1p36.33 // 100287102 /// ENST00000456328 // DDX11L5 // DEAD/H (Asp-Glu-Ala-Asp/His) box helicase 11 like 5 // 9p24.3 // 100287596 /// ENST00000456328 // DDX11L1 // DEAD/H (Asp-Glu-Ala-Asp/His) box helicase 11 like 1 // 1p36.33 // 100287102', 'ENST00000408384 // MIR1302-11 // microRNA 1302-11 // --- // 100422919 /// ENST00000408384 // MIR1302-10 // microRNA 1302-10 // --- // 100422834 /// ENST00000408384 // MIR1302-9 // microRNA 1302-9 // --- // 100422831 /// ENST00000408384 // MIR1302-2 // microRNA 1302-2 // --- // 100302278 /// ENST00000469289 // MIR1302-11 // microRNA 1302-11 // --- // 100422919 /// ENST00000469289 // MIR1302-10 // microRNA 1302-10 // --- // 100422834 /// ENST00000469289 // MIR1302-9 // microRNA 1302-9 // --- // 100422831 /// ENST00000469289 // MIR1302-2 // microRNA 1302-2 // --- // 100302278 /// ENST00000473358 // MIR1302-11 // microRNA 1302-11 // --- // 100422919 /// ENST00000473358 // MIR1302-10 // microRNA 1302-10 // --- // 100422834 /// ENST00000473358 // MIR1302-9 // microRNA 1302-9 // --- // 100422831 /// ENST00000473358 // MIR1302-2 // microRNA 1302-2 // --- // 100302278 /// OTTHUMT00000002841 // OTTHUMG00000000959 // NULL // --- // --- /// OTTHUMT00000002841 // RP11-34P13.3 // NULL // --- // --- /// OTTHUMT00000002840 // OTTHUMG00000000959 // NULL // --- // --- /// OTTHUMT00000002840 // RP11-34P13.3 // NULL // --- // ---', 'NM_001005484 // OR4F5 // olfactory receptor, family 4, subfamily F, member 5 // 1p36.33 // 79501 /// ENST00000335137 // OR4F5 // olfactory receptor, family 4, subfamily F, member 5 // 1p36.33 // 79501 /// OTTHUMT00000003223 // OR4F5 // NULL // --- // ---', 'OTTHUMT00000007169 // OTTHUMG00000002525 // NULL // --- // --- /// OTTHUMT00000007169 // RP11-34P13.9 // NULL // --- // ---', 'NR_028322 // LOC100132287 // uncharacterized LOC100132287 // 1p36.33 // 100132287 /// NR_028327 // LOC100133331 // uncharacterized LOC100133331 // 1p36.33 // 100133331 /// ENST00000425496 // LOC101060495 // uncharacterized LOC101060495 // --- // 101060495 /// ENST00000425496 // LOC101060494 // uncharacterized LOC101060494 // --- // 101060494 /// ENST00000425496 // LOC101059936 // uncharacterized LOC101059936 // --- // 101059936 /// ENST00000425496 // LOC100996502 // uncharacterized LOC100996502 // --- // 100996502 /// ENST00000425496 // LOC100996328 // uncharacterized LOC100996328 // --- // 100996328 /// ENST00000425496 // LOC100287894 // uncharacterized LOC100287894 // 7q11.21 // 100287894 /// NR_028325 // LOC100132062 // uncharacterized LOC100132062 // 5q35.3 // 100132062 /// OTTHUMT00000346878 // OTTHUMG00000156968 // NULL // --- // --- /// OTTHUMT00000346878 // RP4-669L17.10 // NULL // --- // --- /// OTTHUMT00000346879 // OTTHUMG00000156968 // NULL // --- // --- /// OTTHUMT00000346879 // RP4-669L17.10 // NULL // --- // --- /// OTTHUMT00000346880 // OTTHUMG00000156968 // NULL // --- // --- /// OTTHUMT00000346880 // RP4-669L17.10 // NULL // --- // --- /// OTTHUMT00000346881 // OTTHUMG00000156968 // NULL // --- // --- /// OTTHUMT00000346881 // RP4-669L17.10 // NULL // --- // ---'], 'mrna_assignment': ['NR_046018 // RefSeq // Homo sapiens DEAD/H (Asp-Glu-Ala-Asp/His) box helicase 11 like 1 (DDX11L1), non-coding RNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000456328 // ENSEMBL // cdna:known chromosome:GRCh37:1:11869:14409:1 gene:ENSG00000223972 gene_biotype:pseudogene transcript_biotype:processed_transcript // chr1 // 100 // 100 // 0 // --- // 0 /// uc001aaa.3 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0 /// uc010nxq.1 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0 /// uc010nxr.1 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0', 'ENST00000408384 // ENSEMBL // ncrna:miRNA chromosome:GRCh37:1:30366:30503:1 gene:ENSG00000221311 gene_biotype:miRNA transcript_biotype:miRNA // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000469289 // ENSEMBL // havana:lincRNA chromosome:GRCh37:1:30267:31109:1 gene:ENSG00000243485 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000473358 // ENSEMBL // havana:lincRNA chromosome:GRCh37:1:29554:31097:1 gene:ENSG00000243485 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000002841 // Havana transcript // cdna:all chromosome:VEGA52:1:30267:31109:1 Gene:OTTHUMG00000000959 // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000002840 // Havana transcript // cdna:all chromosome:VEGA52:1:29554:31097:1 Gene:OTTHUMG00000000959 // chr1 // 100 // 100 // 0 // --- // 0', 'NM_001005484 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 5 (OR4F5), mRNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000335137 // ENSEMBL // cdna:known chromosome:GRCh37:1:69091:70008:1 gene:ENSG00000186092 gene_biotype:protein_coding transcript_biotype:protein_coding // chr1 // 100 // 100 // 0 // --- // 0 /// uc001aal.1 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000003223 // Havana transcript // cdna:all chromosome:VEGA52:1:69091:70008:1 Gene:OTTHUMG00000001094 // chr1 // 100 // 100 // 0 // --- // 0', 'ENST00000496488 // ENSEMBL // havana:lincRNA chromosome:GRCh37:1:160446:161525:1 gene:ENSG00000241599 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000007169 // Havana transcript // cdna:all chromosome:VEGA52:1:160446:161525:1 Gene:OTTHUMG00000002525 // chr1 // 100 // 100 // 0 // --- // 0', 'NR_028322 // RefSeq // Homo sapiens uncharacterized LOC100132287 (LOC100132287), non-coding RNA. // chr1 // 100 // 100 // 0 // --- // 0 /// NR_028327 // RefSeq // Homo sapiens uncharacterized LOC100133331 (LOC100133331), non-coding RNA. // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000425496 // ENSEMBL // ensembl:lincRNA chromosome:GRCh37:1:324756:328453:1 gene:ENSG00000237094 gene_biotype:lincRNA transcript_biotype:lincRNA // chr1 // 100 // 100 // 0 // --- // 0 /// ENST00000426316 // ENSEMBL // [retired] cdna:known chromosome:GRCh37:1:317811:328455:1 gene:ENSG00000240876 gene_biotype:processed_transcript transcript_biotype:processed_transcript // chr1 // 100 // 100 // 0 // --- // 0 /// NR_028325 // RefSeq // Homo sapiens uncharacterized LOC100132062 (LOC100132062), non-coding RNA. // chr1 // 100 // 100 // 0 // --- // 0 /// uc009vjk.2 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0 /// uc021oeh.1 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0 /// uc021oei.1 // UCSC Genes // --- // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000346906 // Havana transcript // [retired] cdna:all chromosome:VEGA50:1:317811:328455:1 Gene:OTTHUMG00000156972 // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000346878 // Havana transcript // cdna:all chromosome:VEGA52:1:320162:321056:1 Gene:OTTHUMG00000156968 // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000346879 // Havana transcript // cdna:all chromosome:VEGA52:1:320162:324461:1 Gene:OTTHUMG00000156968 // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000346880 // Havana transcript // cdna:all chromosome:VEGA52:1:317720:324873:1 Gene:OTTHUMG00000156968 // chr1 // 100 // 100 // 0 // --- // 0 /// OTTHUMT00000346881 // Havana transcript // cdna:all chromosome:VEGA52:1:322672:324955:1 Gene:OTTHUMG00000156968 // chr1 // 100 // 100 // 0 // --- // 0'], 'swissprot': ['NR_046018 // B7ZGX0 /// NR_046018 // B7ZGX2 /// NR_046018 // B7ZGX7 /// NR_046018 // B7ZGX8 /// ENST00000456328 // B7ZGX0 /// ENST00000456328 // B7ZGX2 /// ENST00000456328 // B7ZGX3 /// ENST00000456328 // B7ZGX7 /// ENST00000456328 // B7ZGX8 /// ENST00000456328 // Q6ZU42', '---', 'NM_001005484 // Q8NH21 /// ENST00000335137 // Q8NH21', '---', 'NR_028325 // B4DYM5 /// NR_028325 // B4E0H4 /// NR_028325 // B4E3X0 /// NR_028325 // B4E3X2 /// NR_028325 // Q6ZQS4'], 'unigene': ['NR_046018 // Hs.714157 // testis| normal| adult /// ENST00000456328 // Hs.719844 // brain| testis| normal /// ENST00000456328 // Hs.714157 // testis| normal| adult /// ENST00000456328 // Hs.618434 // testis| normal', 'ENST00000469289 // Hs.622486 // eye| normal| adult /// ENST00000469289 // Hs.729632 // testis| normal /// ENST00000469289 // Hs.742718 // testis /// ENST00000473358 // Hs.622486 // eye| normal| adult /// ENST00000473358 // Hs.729632 // testis| normal /// ENST00000473358 // Hs.742718 // testis', 'NM_001005484 // Hs.554500 // --- /// ENST00000335137 // Hs.554500 // ---', '---', 'NR_028322 // Hs.446409 // adrenal gland| blood| bone| brain| connective tissue| embryonic tissue| eye| intestine| kidney| larynx| lung| lymph node| mouth| pharynx| placenta| prostate| skin| testis| thymus| thyroid| uterus| bladder carcinoma| chondrosarcoma| colorectal tumor| germ cell tumor| head and neck tumor| kidney tumor| leukemia| lung tumor| normal| primitive neuroectodermal tumor of the CNS| uterine tumor|embryoid body| blastocyst| fetus| neonate| adult /// NR_028327 // Hs.733048 // ascites| bladder| blood| brain| embryonic tissue| eye| intestine| kidney| larynx| liver| lung| mammary gland| mouth| pancreas| placenta| prostate| skin| stomach| testis| thymus| thyroid| trachea| uterus| bladder carcinoma| breast (mammary gland) tumor| colorectal tumor| gastrointestinal tumor| head and neck tumor| kidney tumor| leukemia| liver tumor| lung tumor| normal| pancreatic tumor| prostate cancer| retinoblastoma| skin tumor| soft tissue/muscle tissue tumor| uterine tumor|embryoid body| blastocyst| fetus| adult /// ENST00000425496 // Hs.744556 // mammary gland| normal| adult /// ENST00000425496 // Hs.660700 // eye| placenta| testis| normal| adult /// ENST00000425496 // Hs.518952 // blood| brain| intestine| lung| mammary gland| mouth| muscle| pharynx| placenta| prostate| spleen| testis| thymus| thyroid| trachea| breast (mammary gland) tumor| colorectal tumor| head and neck tumor| leukemia| lung tumor| normal| prostate cancer| fetus| adult /// ENST00000425496 // Hs.742131 // testis| normal| adult /// ENST00000425496 // Hs.636102 // uterus| uterine tumor /// ENST00000425496 // Hs.646112 // brain| intestine| larynx| lung| mouth| prostate| testis| thyroid| colorectal tumor| head and neck tumor| lung tumor| normal| prostate cancer| adult /// ENST00000425496 // Hs.647795 // brain| lung| lung tumor| adult /// ENST00000425496 // Hs.684307 // --- /// ENST00000425496 // Hs.720881 // testis| normal /// ENST00000425496 // Hs.729353 // brain| lung| placenta| testis| trachea| lung tumor| normal| fetus| adult /// ENST00000425496 // Hs.735014 // ovary| ovarian tumor /// NR_028325 // Hs.732199 // ascites| blood| brain| connective tissue| embryonic tissue| eye| intestine| kidney| lung| ovary| placenta| prostate| stomach| testis| thymus| uterus| chondrosarcoma| colorectal tumor| gastrointestinal tumor| kidney tumor| leukemia| lung tumor| normal| ovarian tumor| fetus| adult'], 'category': ['main', 'main', 'main', 'main', 'main'], 'locus type': ['Coding', 'Coding', 'Coding', 'Coding', 'Coding'], 'notes': ['---', '---', '---', '---', '2 retired transcript(s) from ENSEMBL, Havana transcript'], 'SPOT_ID': ['chr1(+):11869-14409', 'chr1(+):29554-31109', 'chr1(+):69091-70008', 'chr1(+):160446-161525', 'chr1(+):317811-328581']}\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": "aa502d1f", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "e1256585", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:55:29.299542Z", "iopub.status.busy": "2025-03-25T05:55:29.299421Z", "iopub.status.idle": "2025-03-25T05:55:31.846386Z", "shell.execute_reply": "2025-03-25T05:55:31.846017Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Expression data index example: 2824546_st\n", "Number of probes in expression data: 70523\n", "Number of probes in annotation data: 2468569\n", "First few rows of mapping before extraction:\n", " ID Gene\n", "0 TC01000001.hg.1 NR_046018 // DDX11L1 // DEAD/H (Asp-Glu-Ala-As...\n", "1 TC01000002.hg.1 ENST00000408384 // MIR1302-11 // microRNA 1302...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene expression data after mapping:\n", "Number of genes: 24018\n", "Number of samples: 34\n", "First few genes:\n", "Index(['A1BG', 'A1BG-AS1', 'A1CF', 'A2M', 'A2M-AS1', 'A2ML1', 'A2ML1-AS1',\n", " 'A2ML1-AS2', 'A2MP1', 'A4GALT'],\n", " dtype='object', name='Gene')\n" ] } ], "source": [ "# From examining the gene expression data and annotation data:\n", "# 1. The gene expression data's index contains probe IDs like '2824546_st'\n", "# 2. The gene annotation data has columns:\n", "# - 'ID': These appear to be transcript IDs like 'TC01000001.hg.1'\n", "# - 'probeset_id': Same as ID\n", "# - 'gene_assignment': Contains gene symbols with additional information\n", "\n", "# The identifiers in gene expression data don't directly match the 'ID' column in annotation\n", "# This is a common issue with Affymetrix arrays, where the actual probe IDs in the expression matrix\n", "# may not match exactly with the annotation file IDs\n", "\n", "# First, let's see how the IDs from gene expression data map to the annotation file\n", "print(\"Expression data index example:\", gene_data.index[0])\n", "print(\"Number of probes in expression data:\", len(gene_data.index))\n", "print(\"Number of probes in annotation data:\", len(gene_annotation))\n", "\n", "# We need to establish a mapping between probe IDs and gene symbols\n", "# The 'gene_assignment' column contains gene symbols\n", "\n", "# Let's examine if there's a way to extract just the gene symbols from the gene_assignment column\n", "# Extract gene mapping using ID column and gene_assignment column\n", "gene_mapping = gene_annotation[['ID', 'gene_assignment']].copy()\n", "gene_mapping = gene_mapping.rename(columns={'gene_assignment': 'Gene'})\n", "\n", "# The 'Gene' column contains complex strings with gene symbols embedded\n", "# We'll use the extract_human_gene_symbols function to extract gene symbols\n", "print(\"First few rows of mapping before extraction:\")\n", "print(gene_mapping.head(2))\n", "\n", "# Apply the gene mapping\n", "gene_data_mapped = apply_gene_mapping(gene_data, gene_mapping)\n", "\n", "# Normalize gene symbols in the index to handle cases where different probe IDs map to the same gene\n", "gene_data = normalize_gene_symbols_in_index(gene_data_mapped)\n", "\n", "# Print statistics about the resulting gene expression data\n", "print(\"\\nGene expression data after mapping:\")\n", "print(f\"Number of genes: {len(gene_data.index)}\")\n", "print(f\"Number of samples: {gene_data.shape[1]}\")\n", "print(\"First few genes:\")\n", "print(gene_data.index[:10])\n" ] }, { "cell_type": "markdown", "id": "36edb06f", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "f99f3bc9", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:55:31.847740Z", "iopub.status.busy": "2025-03-25T05:55:31.847635Z", "iopub.status.idle": "2025-03-25T05:55:32.421124Z", "shell.execute_reply": "2025-03-25T05:55:32.420747Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Obesity/gene_data/GSE281144.csv\n", "No trait data available for this dataset (all subjects have obesity). Skipping clinical feature extraction.\n", "Dataset usability status: False\n", "Dataset is not usable for obesity trait-gene association studies.\n" ] } ], "source": [ "# 1. Normalize the obtained gene data with the 'normalize_gene_symbols_in_index' function from the library.\n", "normalized_gene_data = normalize_gene_symbols_in_index(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", "# Since trait_row is None (as determined in Step 2), we skip the clinical feature extraction\n", "# and data linking steps as instructed.\n", "print(\"No trait data available for this dataset (all subjects have obesity). Skipping clinical feature extraction.\")\n", "\n", "# Create a linked_data DataFrame with only gene expression data for the final validation\n", "# This matches the expected input format for validate_and_save_cohort_info\n", "linked_data = normalized_gene_data.copy()\n", "\n", "# Final validation - mark the dataset as not usable for trait studies\n", "note = \"All subjects in this dataset have obesity, making it unsuitable for obesity vs. non-obesity association studies.\"\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, # False as determined in Step 2\n", " is_biased=True, # No variability in the trait (all have obesity)\n", " df=linked_data,\n", " note=note\n", ")\n", "\n", "print(f\"Dataset usability status: {is_usable}\")\n", "if is_usable:\n", " os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n", " linked_data.to_csv(out_data_file)\n", " print(f\"Linked data saved to {out_data_file}\")\n", "else:\n", " print(\"Dataset is not usable for obesity trait-gene 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 }