{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "88f7fb0f", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:22:06.112362Z", "iopub.status.busy": "2025-03-25T08:22:06.112165Z", "iopub.status.idle": "2025-03-25T08:22:06.279887Z", "shell.execute_reply": "2025-03-25T08:22:06.279493Z" } }, "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 = \"Chronic_obstructive_pulmonary_disease_(COPD)\"\n", "cohort = \"GSE84046\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Chronic_obstructive_pulmonary_disease_(COPD)\"\n", "in_cohort_dir = \"../../input/GEO/Chronic_obstructive_pulmonary_disease_(COPD)/GSE84046\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/GSE84046.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE84046.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE84046.csv\"\n", "json_path = \"../../output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "bd9fc991", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "8c4af887", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:22:06.281211Z", "iopub.status.busy": "2025-03-25T08:22:06.281061Z", "iopub.status.idle": "2025-03-25T08:22:06.401410Z", "shell.execute_reply": "2025-03-25T08:22:06.401073Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"The impact of protein quantity during energy restriction on genome-wide gene expression analysis in human adipose tissue\"\n", "!Series_summary\t\"Overweight is a growing health problem worldwide. The most effective strategy to reduce weight is energy restriction (ER): restriction of food intake without malnutrition. ER has been shown to be beneficial in disease prevention, healthy aging, and inflammation. Recent studies suggest that reducing the protein content of a diet contributes to the beneficial effects by ER. The first objective of our study was to assess the effect of energy restriction on changes in gene expression in adipose tissue. Secondly, the changes in gene expression were compared between a high protein diet and a normal protein diet during energy restriction. In a parallel double-blinded study, overweight older subjects adhered to a 25% ER diet, either combined with high protein intake (HP-ER, 1.7 g/kg per day), or with normal protein intake (NP-ER, 0.9 g/kg per day) for 12 weeks. From 10 HP-ER subjects and 12 NP-ER subjects subcutaneous adipose tissue biopsies were collected before and after the diet. Adipose tissue was used to isolate total RNA and to evaluate whole genome gene expression changes upon a HP-ER and NP-ER diet. Upon 25% ER, clusters of gene sets in energy metabolism, such as lipid metabolism and PPARα targets, NRF2 targets, glucose metabolism, and TCA cycle, as well as gene sets in oxidative phosphorylation, adaptive immune response, immune cell infiltration, and cell cycle were decreased, and RNA translation and processing gene sets were increased. A different gene expression response between HP-ER and NP-ER was observed for 530 genes. Pathway analysis revealed that after NP-ER a downregulation in expression of genes involved in adaptive immune response was present. HP-ER resulted in an upregulation of pathways involved in cell cycle, GPCR signalling, olfactory signalling and nitrogen metabolism. Based on the gene expression changes, we concluded that HP seems to be less beneficial for ER’s effect on immune-related gene expression in adipose tissue.\"\n", "!Series_overall_design\t\"In a parallel double-blinded study, overweight middle-aged subjects adhered to a 25% ER diet, either combined with high protein (HP-ER, 1.5 g/kg-bw/d), or with standard protein (SP-ER, 0.8 g/kg-bw/d) for 12 weeks. From 10 HP-ER subjects and 12 SP-ER subjects subcutaneous adipose tissue biopsies were collected before and after the diet. Adipose tissue was used to isolate total RNA and to evaluate whole genome gene expression changes upon a HP-ER and SP-ER diet.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['subjectid: 6053', 'subjectid: 6076', 'subjectid: 6039', 'subjectid: 6054', 'subjectid: 6077', 'subjectid: 6044', 'subjectid: 6055', 'subjectid: 6078', 'subjectid: 6064', 'subjectid: 6080', 'subjectid: 6084', 'subjectid: 6107', 'subjectid: 6124', 'subjectid: 6086', 'subjectid: 6108', 'subjectid: 6129', 'subjectid: 6087', 'subjectid: 6112', 'subjectid: 6012', 'subjectid: 6092', 'subjectid: 6121', 'subjectid: 6047'], 1: ['protein content restricted diet: high', 'protein content restricted diet: normal'], 2: ['time of sampling (before/after): before', 'time of sampling (before/after): after'], 3: ['time of sampling (wk): t=0 (baseline)', 'time of sampling (wk): t=12'], 4: ['sexe: Male', 'sexe: Female'], 5: ['date of birth (dd-mm-yyyy): 1952-06-17', 'date of birth (dd-mm-yyyy): 1944-12-11', 'date of birth (dd-mm-yyyy): 1955-07-23', 'date of birth (dd-mm-yyyy): 1947-11-29', 'date of birth (dd-mm-yyyy): 1944-07-19', 'date of birth (dd-mm-yyyy): 1943-02-09', 'date of birth (dd-mm-yyyy): 1952-07-07', 'date of birth (dd-mm-yyyy): 1954-06-07', 'date of birth (dd-mm-yyyy): 1944-03-17', 'date of birth (dd-mm-yyyy): 1951-03-09', 'date of birth (dd-mm-yyyy): 1953-10-01', 'date of birth (dd-mm-yyyy): 1952-12-04', 'date of birth (dd-mm-yyyy): 1944-02-01', 'date of birth (dd-mm-yyyy): 1955-04-30', 'date of birth (dd-mm-yyyy): 1946-03-25', 'date of birth (dd-mm-yyyy): 1954-12-12', 'date of birth (dd-mm-yyyy): 1954-05-04', 'date of birth (dd-mm-yyyy): 1946-06-04', 'date of birth (dd-mm-yyyy): 1947-07-14', 'date of birth (dd-mm-yyyy): 1952-09-30', 'date of birth (dd-mm-yyyy): 1946-12-13', 'date of birth (dd-mm-yyyy): 1953-04-25'], 6: ['screening bmi (kg/m2): 30.0', 'screening bmi (kg/m2): 30.3', 'screening bmi (kg/m2): 32.4', 'screening bmi (kg/m2): 29.2', 'screening bmi (kg/m2): 34.7', 'screening bmi (kg/m2): 33.0', 'screening bmi (kg/m2): 27.6', 'screening bmi (kg/m2): 33.1', 'screening bmi (kg/m2): 30.4', 'screening bmi (kg/m2): 30.5', 'screening bmi (kg/m2): 28.4', 'screening bmi (kg/m2): 28.9', 'screening bmi (kg/m2): 29.7', 'screening bmi (kg/m2): 28.8', 'screening bmi (kg/m2): 29.8', 'screening bmi (kg/m2): 35.2', 'screening bmi (kg/m2): 30.6', 'screening bmi (kg/m2): 28.2', 'screening bmi (kg/m2): 34.8'], 7: ['screening body fat percentage (fm): 32.9', 'screening body fat percentage (fm): 31.8', 'screening body fat percentage (fm): 46.8', 'screening body fat percentage (fm): 37.1', 'screening body fat percentage (fm): 28.2', 'screening body fat percentage (fm): 25.6', 'screening body fat percentage (fm): 31.5', 'screening body fat percentage (fm): 48.1', 'screening body fat percentage (fm): 32.1', 'screening body fat percentage (fm): 30.2', 'screening body fat percentage (fm): 29.4', 'screening body fat percentage (fm): 45', 'screening body fat percentage (fm): 32.2', 'screening body fat percentage (fm): 31.2', 'screening body fat percentage (fm): 48', 'screening body fat percentage (fm): 30.7', 'screening body fat percentage (fm): 47.3', 'screening body fat percentage (fm): 42.1', 'screening body fat percentage (fm): 46.7', 'screening body fat percentage (fm): 34.2'], 8: ['screening glucose (mmol/l): 6.28', 'screening glucose (mmol/l): 6.95', 'screening glucose (mmol/l): 6.34', 'screening glucose (mmol/l): 5.45', 'screening glucose (mmol/l): 5.67', 'screening glucose (mmol/l): 7.62', 'screening glucose (mmol/l): 5.78', 'screening glucose (mmol/l): 5.95', 'screening glucose (mmol/l): 6.23', 'screening glucose (mmol/l): 5.89', 'screening glucose (mmol/l): 5.62', 'screening glucose (mmol/l): 5.56', 'screening glucose (mmol/l): 6.56', 'screening glucose (mmol/l): 5.00', 'screening glucose (mmol/l): 5.50', 'screening glucose (mmol/l): 5.84']}\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": "44c2c984", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "1e3a12f8", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:22:06.402809Z", "iopub.status.busy": "2025-03-25T08:22:06.402691Z", "iopub.status.idle": "2025-03-25T08:22:06.409092Z", "shell.execute_reply": "2025-03-25T08:22:06.408764Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Review data availability and determine preprocessing approach\n", "\n", "# 1. Gene Expression Data Availability\n", "# Based on the background information, this study conducts genome-wide gene \n", "# expression analysis on adipose tissue\n", "is_gene_available = True # This is gene expression data, not just miRNA or methylation\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "\n", "# 2.1 Trait (COPD) Availability\n", "# This study is about protein content in diet during energy restriction\n", "# Not related to COPD, so trait data is not available\n", "trait_row = None\n", "\n", "# 2.2 Gender Availability\n", "# Gender is available in row 4, labeled as 'sexe'\n", "gender_row = 4\n", "\n", "def convert_gender(value):\n", " if value is None:\n", " return None\n", " if ':' in value:\n", " value = value.split(': ')[1].strip()\n", " if value.lower() == 'female':\n", " return 0\n", " elif value.lower() == 'male':\n", " return 1\n", " return None\n", "\n", "# 2.3 Age Availability\n", "# Age is not directly given but can be inferred from date of birth in row 5\n", "age_row = 5\n", "\n", "def convert_age(value):\n", " if value is None:\n", " return None\n", " if ':' in value:\n", " value = value.split(': ')[1].strip()\n", " \n", " # Extract birth year from format \"date of birth (dd-mm-yyyy): YYYY-MM-DD\"\n", " if '-' in value:\n", " try:\n", " birth_year = int(value.split('-')[0])\n", " # Assuming study was conducted around 2014 (based on context)\n", " # Most people in study are from 1940s-1950s which would make them ~60-70 years old\n", " study_year = 2014\n", " age = study_year - birth_year\n", " return age\n", " except:\n", " return None\n", " return None\n", "\n", "# No conversion function for trait since it's not available\n", "def convert_trait(value):\n", " return None\n", "\n", "# 3. Save Metadata - Initial filtering\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. Skip clinical feature extraction since trait data is not available\n", "# The function will return False since is_trait_available is False\n" ] }, { "cell_type": "markdown", "id": "5334e93f", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "59d1b1b5", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:22:06.410413Z", "iopub.status.busy": "2025-03-25T08:22:06.410299Z", "iopub.status.idle": "2025-03-25T08:22:06.581269Z", "shell.execute_reply": "2025-03-25T08:22:06.580897Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matrix file found: ../../input/GEO/Chronic_obstructive_pulmonary_disease_(COPD)/GSE84046/GSE84046_series_matrix.txt.gz\n", "Gene data shape: (33297, 44)\n", "First 20 gene/probe identifiers:\n", "Index(['7892501', '7892502', '7892503', '7892504', '7892505', '7892506',\n", " '7892507', '7892508', '7892509', '7892510', '7892511', '7892512',\n", " '7892513', '7892514', '7892515', '7892516', '7892517', '7892518',\n", " '7892519', '7892520'],\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": "b27a093b", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "95605f74", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:22:06.582731Z", "iopub.status.busy": "2025-03-25T08:22:06.582610Z", "iopub.status.idle": "2025-03-25T08:22:06.584520Z", "shell.execute_reply": "2025-03-25T08:22:06.584204Z" } }, "outputs": [], "source": [ "# The gene identifiers are microarray probe IDs, not human gene symbols\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "ec7dc819", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "a6dc0de1", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:22:06.586071Z", "iopub.status.busy": "2025-03-25T08:22:06.585954Z", "iopub.status.idle": "2025-03-25T08:22:09.861706Z", "shell.execute_reply": "2025-03-25T08:22:09.861331Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene annotation preview:\n", "Columns in gene annotation: ['ID', 'GB_LIST', 'SPOT_ID', 'seqname', 'RANGE_GB', 'RANGE_STRAND', 'RANGE_START', 'RANGE_STOP', 'total_probes', 'gene_assignment', 'mrna_assignment', 'category']\n", "{'ID': ['7896736', '7896738', '7896740', '7896742', '7896744'], 'GB_LIST': [nan, nan, 'NM_001005240,NM_001004195,NM_001005484,BC136848,BC136907', 'BC118988,AL137655', 'NM_001005277,NM_001005221,NM_001005224,NM_001005504,BC137547'], 'SPOT_ID': ['chr1:53049-54936', 'chr1:63015-63887', 'chr1:69091-70008', 'chr1:334129-334296', 'chr1:367659-368597'], 'seqname': ['chr1', 'chr1', 'chr1', 'chr1', 'chr1'], 'RANGE_GB': ['NC_000001.10', 'NC_000001.10', 'NC_000001.10', 'NC_000001.10', 'NC_000001.10'], 'RANGE_STRAND': ['+', '+', '+', '+', '+'], 'RANGE_START': [53049.0, 63015.0, 69091.0, 334129.0, 367659.0], 'RANGE_STOP': [54936.0, 63887.0, 70008.0, 334296.0, 368597.0], 'total_probes': [7.0, 31.0, 24.0, 6.0, 36.0], 'gene_assignment': ['---', '---', 'NM_001005240 // OR4F17 // olfactory receptor, family 4, subfamily F, member 17 // 19p13.3 // 81099 /// NM_001004195 // OR4F4 // olfactory receptor, family 4, subfamily F, member 4 // 15q26.3 // 26682 /// NM_001005484 // OR4F5 // olfactory receptor, family 4, subfamily F, member 5 // 1p36.33 // 79501 /// ENST00000318050 // OR4F17 // olfactory receptor, family 4, subfamily F, member 17 // 19p13.3 // 81099 /// ENST00000335137 // OR4F4 // olfactory receptor, family 4, subfamily F, member 4 // 15q26.3 // 26682 /// ENST00000326183 // OR4F5 // olfactory receptor, family 4, subfamily F, member 5 // 1p36.33 // 79501 /// BC136848 // OR4F17 // olfactory receptor, family 4, subfamily F, member 17 // 19p13.3 // 81099 /// BC136907 // OR4F4 // olfactory receptor, family 4, subfamily F, member 4 // 15q26.3 // 26682 /// ENST00000442916 // OR4F17 // olfactory receptor, family 4, subfamily F, member 17 // 19p13.3 // 81099', 'ENST00000388975 // SEPT14 // septin 14 // 7p11.2 // 346288 /// BC118988 // NCRNA00266 // non-protein coding RNA 266 // --- // 140849 /// AL137655 // LOC100134822 // similar to hCG1739109 // --- // 100134822', 'NM_001005277 // OR4F16 // olfactory receptor, family 4, subfamily F, member 16 // 1p36.33 // 81399 /// NM_001005221 // OR4F29 // olfactory receptor, family 4, subfamily F, member 29 // 1p36.33 // 729759 /// NM_001005224 // OR4F3 // olfactory receptor, family 4, subfamily F, member 3 // 5q35.3 // 26683 /// NM_001005504 // OR4F21 // olfactory receptor, family 4, subfamily F, member 21 // 8p23.3 // 441308 /// ENST00000320901 // OR4F21 // olfactory receptor, family 4, subfamily F, member 21 // 8p23.3 // 441308 /// BC137547 // OR4F3 // olfactory receptor, family 4, subfamily F, member 3 // 5q35.3 // 26683 /// BC137547 // OR4F16 // olfactory receptor, family 4, subfamily F, member 16 // 1p36.33 // 81399 /// BC137547 // OR4F29 // olfactory receptor, family 4, subfamily F, member 29 // 1p36.33 // 729759'], 'mrna_assignment': ['---', 'ENST00000328113 // ENSEMBL // cdna:pseudogene chromosome:GRCh37:15:102467008:102467910:-1 gene:ENSG00000183909 // chr1 // 100 // 100 // 31 // 31 // 0 /// ENST00000318181 // ENSEMBL // cdna:pseudogene chromosome:GRCh37:19:104601:105256:1 gene:ENSG00000176705 // chr1 // 100 // 100 // 31 // 31 // 0 /// ENST00000492842 // ENSEMBL // cdna:pseudogene chromosome:GRCh37:1:62948:63887:1 gene:ENSG00000240361 // chr1 // 100 // 100 // 31 // 31 // 0', 'NM_001005240 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 17 (OR4F17), mRNA. // chr1 // 100 // 100 // 24 // 24 // 0 /// NM_001004195 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 4 (OR4F4), mRNA. // chr1 // 100 // 100 // 24 // 24 // 0 /// NM_001005484 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 5 (OR4F5), mRNA. // chr1 // 100 // 100 // 24 // 24 // 0 /// ENST00000318050 // ENSEMBL // Olfactory receptor 4F17 gene:ENSG00000176695 // chr1 // 100 // 100 // 24 // 24 // 0 /// ENST00000335137 // ENSEMBL // Olfactory receptor 4F4 gene:ENSG00000186092 // chr1 // 100 // 100 // 24 // 24 // 0 /// ENST00000326183 // ENSEMBL // Olfactory receptor 4F5 gene:ENSG00000177693 // chr1 // 100 // 100 // 24 // 24 // 0 /// BC136848 // GenBank // Homo sapiens olfactory receptor, family 4, subfamily F, member 17, mRNA (cDNA clone MGC:168462 IMAGE:9020839), complete cds. // chr1 // 100 // 100 // 24 // 24 // 0 /// BC136907 // GenBank // Homo sapiens olfactory receptor, family 4, subfamily F, member 4, mRNA (cDNA clone MGC:168521 IMAGE:9020898), complete cds. // chr1 // 100 // 100 // 24 // 24 // 0 /// ENST00000442916 // ENSEMBL // OR4F4 (Fragment) gene:ENSG00000176695 // chr1 // 100 // 88 // 21 // 21 // 0', 'ENST00000388975 // ENSEMBL // Septin-14 gene:ENSG00000154997 // chr1 // 50 // 100 // 3 // 6 // 0 /// BC118988 // GenBank // Homo sapiens chromosome 20 open reading frame 69, mRNA (cDNA clone MGC:141807 IMAGE:40035995), complete cds. // chr1 // 100 // 100 // 6 // 6 // 0 /// AL137655 // GenBank // Homo sapiens mRNA; cDNA DKFZp434B2016 (from clone DKFZp434B2016). // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000428915 // ENSEMBL // cdna:known chromosome:GRCh37:10:38742109:38755311:1 gene:ENSG00000203496 // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000455207 // ENSEMBL // cdna:known chromosome:GRCh37:1:334129:446155:1 gene:ENSG00000224813 // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000455464 // ENSEMBL // cdna:known chromosome:GRCh37:1:334140:342806:1 gene:ENSG00000224813 // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000440200 // ENSEMBL // cdna:known chromosome:GRCh37:1:536816:655580:-1 gene:ENSG00000230021 // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000279067 // ENSEMBL // cdna:known chromosome:GRCh37:20:62921738:62934912:1 gene:ENSG00000149656 // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000499986 // ENSEMBL // cdna:known chromosome:GRCh37:5:180717576:180761371:1 gene:ENSG00000248628 // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000436899 // ENSEMBL // cdna:known chromosome:GRCh37:6:131910:144885:-1 gene:ENSG00000170590 // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000432557 // ENSEMBL // cdna:known chromosome:GRCh37:8:132324:150572:-1 gene:ENSG00000250210 // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000523795 // ENSEMBL // cdna:known chromosome:GRCh37:8:141690:150563:-1 gene:ENSG00000250210 // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000490482 // ENSEMBL // cdna:known chromosome:GRCh37:8:149942:163324:-1 gene:ENSG00000223508 // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000307499 // ENSEMBL // cdna:known supercontig::GL000227.1:57780:70752:-1 gene:ENSG00000229450 // chr1 // 100 // 100 // 6 // 6 // 0 /// ENST00000441245 // ENSEMBL // cdna:known chromosome:GRCh37:1:637316:655530:-1 gene:ENSG00000230021 // chr1 // 100 // 67 // 4 // 4 // 0 /// ENST00000425473 // ENSEMBL // cdna:known chromosome:GRCh37:20:62926294:62944485:1 gene:ENSG00000149656 // chr1 // 100 // 67 // 4 // 4 // 0 /// ENST00000471248 // ENSEMBL // cdna:known chromosome:GRCh37:1:110953:129173:-1 gene:ENSG00000238009 // chr1 // 75 // 67 // 3 // 4 // 0', 'NM_001005277 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 16 (OR4F16), mRNA. // chr1 // 100 // 100 // 36 // 36 // 0 /// NM_001005221 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 29 (OR4F29), mRNA. // chr1 // 100 // 100 // 36 // 36 // 0 /// NM_001005224 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 3 (OR4F3), mRNA. // chr1 // 100 // 100 // 36 // 36 // 0 /// NM_001005504 // RefSeq // Homo sapiens olfactory receptor, family 4, subfamily F, member 21 (OR4F21), mRNA. // chr1 // 89 // 100 // 32 // 36 // 0 /// ENST00000320901 // ENSEMBL // Olfactory receptor 4F21 gene:ENSG00000176269 // chr1 // 89 // 100 // 32 // 36 // 0 /// BC137547 // GenBank // Homo sapiens olfactory receptor, family 4, subfamily F, member 3, mRNA (cDNA clone MGC:169170 IMAGE:9021547), complete cds. // chr1 // 100 // 100 // 36 // 36 // 0 /// ENST00000426406 // ENSEMBL // cdna:known chromosome:GRCh37:1:367640:368634:1 gene:ENSG00000235249 // chr1 // 100 // 100 // 36 // 36 // 0 /// ENST00000332831 // ENSEMBL // cdna:known chromosome:GRCh37:1:621096:622034:-1 gene:ENSG00000185097 // chr1 // 100 // 100 // 36 // 36 // 0 /// ENST00000456475 // ENSEMBL // cdna:known chromosome:GRCh37:5:180794269:180795263:1 gene:ENSG00000230178 // chr1 // 100 // 100 // 36 // 36 // 0 /// ENST00000521196 // ENSEMBL // cdna:known chromosome:GRCh37:11:86612:87605:-1 gene:ENSG00000224777 // chr1 // 78 // 100 // 28 // 36 // 0'], 'category': ['---', 'main', 'main', 'main', 'main']}\n", "\n", "Searching for platform information in SOFT file:\n", "!Series_platform_id = GPL11532\n", "\n", "Searching for gene symbol information in SOFT file:\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "No explicit gene symbol references found in first 1000 lines\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": "5754b1c8", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "ac2698b4", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:22:09.863574Z", "iopub.status.busy": "2025-03-25T08:22:09.863419Z", "iopub.status.idle": "2025-03-25T08:22:10.361249Z", "shell.execute_reply": "2025-03-25T08:22:10.360875Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "First 5 IDs from gene expression data: ['7892501', '7892502', '7892503', '7892504', '7892505']\n", "First 5 IDs from gene annotation: ['7896736', '7896738', '7896740', '7896742', '7896744']\n", "\n", "Sample gene_assignment entries:\n", "---...\n", "---...\n", "NM_001005240 // OR4F17 // olfactory receptor, family 4, subfamily F, member 17 // 19p13.3 // 81099 /// NM_001004195 // OR4F4 // olfactory receptor, family 4, subfamily F, member 4 // 15q26.3 // 26682 ...\n", "\n", "Creating gene mapping dataframe...\n", "Original mapping shape: (33297, 2)\n", "Sample mapped entries:\n", " ID Gene\n", "0 7896736 ---\n", "1 7896738 ---\n", "2 7896740 NM_001005240 // OR4F17 // olfactory receptor, ...\n", "\n", "Applying gene mapping to gene expression data...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene-level expression data shape: (56391, 44)\n", "First 10 gene symbols after mapping:\n", "['A-', 'A-2', 'A-52', 'A-E', 'A-I', 'A-II', 'A-IV', 'A-V', 'A0', 'A1']\n", "\n", "Preview of gene expression data:\n", "{'GSM2226420': [33.68976687768011, 1.9937525379999999, 3.3021436486666667], 'GSM2226421': [33.80631276691363, 1.8987550603333334, 3.3720884666666664], 'GSM2226422': [34.00824614293309, 1.929899198, 3.3661534399999997], 'GSM2226423': [33.61255679126494, 1.9025789763333334, 3.3930164499999997], 'GSM2226424': [33.662630774239126, 2.024719238, 3.3526896666666666]}\n" ] } ], "source": [ "# Analyze the gene annotation dataframe to determine the mapping from probe IDs to gene symbols\n", "# First, confirm the columns containing probe IDs \n", "print(\"First 5 IDs from gene expression data:\", gene_data.index[:5].tolist())\n", "print(\"First 5 IDs from gene annotation:\", gene_annotation['ID'][:5].tolist())\n", "\n", "# Looking at the gene_assignment column which contains gene symbols\n", "gene_assignment_sample = gene_annotation['gene_assignment'].head(3).tolist()\n", "print(\"\\nSample gene_assignment entries:\")\n", "for entry in gene_assignment_sample:\n", " print(f\"{entry[:200]}...\")\n", "\n", "# Extract gene mapping from annotation\n", "# The ID column contains the probe identifiers\n", "# The gene_assignment column contains gene symbols but needs parsing\n", "print(\"\\nCreating gene mapping dataframe...\")\n", "mapping_df = get_gene_mapping(gene_annotation, 'ID', 'gene_assignment')\n", "print(f\"Original mapping shape: {mapping_df.shape}\")\n", "print(\"Sample mapped entries:\")\n", "print(mapping_df.head(3))\n", "\n", "# Apply the gene mapping to convert probe-level measurements to gene-level expression\n", "print(\"\\nApplying gene mapping to gene expression data...\")\n", "gene_data = apply_gene_mapping(gene_data, mapping_df)\n", "print(f\"Gene-level expression data shape: {gene_data.shape}\")\n", "print(\"First 10 gene symbols after mapping:\")\n", "print(list(gene_data.index[:10]))\n", "\n", "# Preview the gene expression data\n", "print(\"\\nPreview of gene expression data:\")\n", "preview_sample = preview_df(gene_data, n=3)\n", "preview_cols = list(preview_sample.keys())[:5] # Show only first 5 columns to avoid clutter\n", "preview_data = {col: preview_sample[col] for col in preview_cols}\n", "print(preview_data)\n" ] }, { "cell_type": "markdown", "id": "88369521", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "629a3a19", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:22:10.363074Z", "iopub.status.busy": "2025-03-25T08:22:10.362942Z", "iopub.status.idle": "2025-03-25T08:22:11.074587Z", "shell.execute_reply": "2025-03-25T08:22:11.074220Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data shape: (20124, 44)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene expression data saved to ../../output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/gene_data/GSE84046.csv\n", "\n", "No COPD-related trait data available in this dataset.\n", "Clinical data (demographic only) saved to ../../output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/clinical_data/GSE84046.csv\n", "\n", "Clinical data preview:\n", " Gender Age\n", "GSM2226420 1 62\n", "GSM2226421 1 70\n", "GSM2226422 1 62\n", "\n", "Dataset usability assessment: Not usable for COPD analysis\n", "Assessment details saved to ../../output/preprocess/Chronic_obstructive_pulmonary_disease_(COPD)/cohort_info.json\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", "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\"Gene expression data saved to {out_gene_data_file}\")\n", "\n", "# 2. Since we previously determined that trait data is not available (trait_row = None),\n", "# we can't create clinical features or linked data for this cohort\n", "print(\"\\nNo COPD-related trait data available in this dataset.\")\n", "\n", "# 3. Create a minimal clinical dataframe with just the demographic information\n", "# Get the sample IDs from gene data\n", "sample_ids = normalized_gene_data.columns.tolist()\n", "\n", "# Create clinical dataframe with gender and age if available\n", "clinical_features_list = []\n", "\n", "# Add gender information if available\n", "if gender_row is not None:\n", " gender_series = clinical_data.iloc[gender_row].drop('!Sample_geo_accession', errors='ignore')\n", " gender_series = gender_series.map(convert_gender)\n", " gender_series.name = 'Gender'\n", " clinical_features_list.append(gender_series)\n", "\n", "# Add age information if available\n", "if age_row is not None:\n", " age_series = clinical_data.iloc[age_row].drop('!Sample_geo_accession', errors='ignore') \n", " age_series = age_series.map(convert_age)\n", " age_series.name = 'Age'\n", " clinical_features_list.append(age_series)\n", "\n", "# Create clinical dataframe if we have features\n", "if clinical_features_list:\n", " clinical_df = pd.concat(clinical_features_list, axis=1)\n", " \n", " # Save clinical data\n", " os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", " clinical_df.to_csv(out_clinical_data_file)\n", " print(f\"Clinical data (demographic only) saved to {out_clinical_data_file}\")\n", " \n", " print(\"\\nClinical data preview:\")\n", " print(clinical_df.head(3))\n", "else:\n", " print(\"No usable clinical features found.\")\n", "\n", "# 4. Final validation - use is_final=False since this is an initial filter-out case\n", "note = \"This dataset contains gene expression from adipose tissue in a protein diet study, not related to COPD.\"\n", "is_usable = validate_and_save_cohort_info(\n", " is_final=False,\n", " cohort=cohort,\n", " info_path=json_path,\n", " is_gene_available=True,\n", " is_trait_available=False # No COPD trait data\n", ")\n", "\n", "print(f\"\\nDataset usability assessment: {'Usable' if is_usable else 'Not usable'} for COPD analysis\")\n", "print(f\"Assessment details saved to {json_path}\")" ] } ], "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 }