{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "4cd766e3", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:46:49.686107Z", "iopub.status.busy": "2025-03-25T05:46:49.685997Z", "iopub.status.idle": "2025-03-25T05:46:49.851418Z", "shell.execute_reply": "2025-03-25T05:46:49.851024Z" } }, "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 = \"Huntingtons_Disease\"\n", "cohort = \"GSE71220\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Huntingtons_Disease\"\n", "in_cohort_dir = \"../../input/GEO/Huntingtons_Disease/GSE71220\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Huntingtons_Disease/GSE71220.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Huntingtons_Disease/gene_data/GSE71220.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Huntingtons_Disease/clinical_data/GSE71220.csv\"\n", "json_path = \"../../output/preprocess/Huntingtons_Disease/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "0cf809e9", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "95073aa0", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:46:49.852647Z", "iopub.status.busy": "2025-03-25T05:46:49.852501Z", "iopub.status.idle": "2025-03-25T05:46:50.257287Z", "shell.execute_reply": "2025-03-25T05:46:50.256764Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"The effect of statins on blood gene expression in COPD\"\n", "!Series_summary\t\"Background: COPD is currently the fourth leading cause of death worldwide and predicted to rank third by 2020. Statins are commonly used lipid lowering agents with documented benefits on cardiovascular morbidity and mortality, and have also been shown to have pleiotropic effects including anti-inflammatory and anti-oxidant activity. Objective: Identify a gene signature associated with statin use in the blood of COPD patients, and identify molecular mechanisms and pathways underpinning this signature that could explain any potential benefits in COPD. Methods: Whole blood gene expression was measured on 168 statin users and 452 non-users from the ECLIPSE (Evaluation of COPD Longitudinally to Identify Predictive Surrogate Endpoints) study. Gene expression was measured using the Affymetrix Human Gene 1.1 ST microarray chips. Factor Analysis for Robust Microarray Summarization (FARMS) was used to process the expression data and to filter out non-informative probe sets. Differential gene expression analysis was undertaken using the Linear Models for Microarray data (Limma) package adjusting for propensity score and employing a surrogate variable analysis. Similarity of the expression signal with published gene expression profiles was performed in ProfileChaser. Results: 18 genes were differentially expressed between statin users and non-users at a false discovery rate of 10%. Top genes included LDLR, ABCA1, ABCG1, MYLIP, SC4MOL, and DHCR24. The 18 genes were significantly enriched in pathways and biological processes related to cholesterol homeostasis and metabolism, and were enriched for transcription factor binding sites for sterol regulatory element binding protein 2 (SREBP-2). The resulting gene signature showed correlation with Huntington disease, Parkinson’s disease and acute myeloid leukemia. Conclusion: Statins gene signature was not enriched in any pathways related to respiratory diseases, beyond the drug’s effect on cholesterol homeostasis.\"\n", "!Series_overall_design\t\"Study subjects were a subset of those with COPD from the Evaluation of COPD Longitudinally to Identify Predictive Surrogate Endpoints (ECLIPSE) study (Vestbo et al.), funded by GlaxoSmithKline (GSK Study No. SCO104960, NCT00292552). ECLIPSE is a non-interventional, observational, multicentre, three-year study in people with COPD. Blood was collected in PAXGene tubes and frozen at -80oC. In this work we have looked at the effect of statins on gene expression in 620 subjects of whom 168 were statin users. ECLIPSE study was described in: Vestbo J, Anderson W, Coxson HO, et al.: Evaluation of COPD Longitudinally to Identify Predictive Surrogate End-points (ECLIPSE). Eur Respir J. 2008;31(4):869-73\"\n", "Sample Characteristics Dictionary:\n", "{0: ['statin user (y/n): N', 'statin user (y/n): Y'], 1: ['disease: COPD', 'disease: Control'], 2: ['age: 57', 'age: 72', 'age: 70', 'age: 62', 'age: 67', 'age: 60', 'age: 66', 'age: 74', 'age: 61', 'age: 68', 'age: 71', 'age: 49', 'age: 69', 'age: 75', 'age: 63', 'age: 51', 'age: 65', 'age: 73', 'age: 59', 'age: 55', 'age: 58', 'age: 52', 'age: 53', 'age: 50', 'age: 56', 'age: 54', 'age: 64'], 3: ['Sex: F', 'Sex: M'], 4: ['smoking status: Former smoker', 'smoking status: Never smoked', 'smoking status: Current smoker'], 5: ['fev1% predicted: 48.4', 'fev1% predicted: 54', 'fev1% predicted: 61.8', 'fev1% predicted: 38.9', 'fev1% predicted: 109.2', 'fev1% predicted: 75.1', 'fev1% predicted: 31.9', 'fev1% predicted: 40.6', 'fev1% predicted: 62.8', 'fev1% predicted: 31.1', 'fev1% predicted: 32.2', 'fev1% predicted: 60.1', 'fev1% predicted: 66', 'fev1% predicted: 93.3', 'fev1% predicted: 53.9', 'fev1% predicted: 35', 'fev1% predicted: 73.7', 'fev1% predicted: 93.4', 'fev1% predicted: NA', 'fev1% predicted: 43', 'fev1% predicted: 102.7', 'fev1% predicted: 119.2', 'fev1% predicted: 116.6', 'fev1% predicted: 105.6', 'fev1% predicted: 65.9', 'fev1% predicted: 74.2', 'fev1% predicted: 55.9', 'fev1% predicted: 30', 'fev1% predicted: 70.3', 'fev1% predicted: 62.1'], 6: ['fev1/fvc: 43.13', 'fev1/fvc: 48.21', 'fev1/fvc: 59.93', 'fev1/fvc: 40.2', 'fev1/fvc: 76.93', 'fev1/fvc: 43.07', 'fev1/fvc: 28.97', 'fev1/fvc: 43.52', 'fev1/fvc: 66.02', 'fev1/fvc: 42.04', 'fev1/fvc: 36.72', 'fev1/fvc: 45.52', 'fev1/fvc: 57.02', 'fev1/fvc: 81.57', 'fev1/fvc: 34.85', 'fev1/fvc: 29.03', 'fev1/fvc: 71.87', 'fev1/fvc: 72.68', 'fev1/fvc: NA', 'fev1/fvc: 45.4', 'fev1/fvc: 80.28', 'fev1/fvc: 93.01', 'fev1/fvc: 76.11', 'fev1/fvc: 79.15', 'fev1/fvc: 43.85', 'fev1/fvc: 70.65', 'fev1/fvc: 61.37', 'fev1/fvc: 35.84', 'fev1/fvc: 51.82', 'fev1/fvc: 48.91']}\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": "8725ea54", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "93484048", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:46:50.258794Z", "iopub.status.busy": "2025-03-25T05:46:50.258683Z", "iopub.status.idle": "2025-03-25T05:46:50.275339Z", "shell.execute_reply": "2025-03-25T05:46:50.274959Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No direct Huntingtons_Disease information available in this dataset.\n", "This is primarily a COPD study with some gene signature correlation to Huntingtons_Disease mentioned in the background.\n" ] } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on the background information, the dataset contains gene expression data measured using Affymetrix Human Gene 1.1 ST microarray chips\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "\n", "# 2.1 Data Availability\n", "# The background information indicates this is actually a COPD study, not a direct Huntington's Disease study\n", "# While there's mention of gene signature correlation with Huntington's, there's no direct Huntington's Disease trait data\n", "trait_row = None # No direct Huntington's Disease information available\n", "\n", "# Age information is available in row 2\n", "age_row = 2\n", "\n", "# Gender information is available in row 3 (labeled as 'Sex')\n", "gender_row = 3\n", "\n", "# 2.2 Data Type Conversion Functions\n", "\n", "def convert_trait(value):\n", " \"\"\"\n", " Convert disease status to binary representation.\n", " However, in this dataset, there's no direct Huntington's Disease information.\n", " \"\"\"\n", " return None # No direct Huntington's Disease information\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age to a continuous value.\"\"\"\n", " if value is None or \":\" not in value:\n", " return None\n", " \n", " age_str = value.split(\": \")[1].strip()\n", " try:\n", " return float(age_str)\n", " except:\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender to binary: 0 for female, 1 for male.\"\"\"\n", " if value is None or \":\" not in value:\n", " return None\n", " \n", " gender = value.split(\": \")[1].strip()\n", " if gender.upper() == \"F\":\n", " return 0\n", " elif gender.upper() == \"M\":\n", " return 1\n", " else:\n", " return None\n", "\n", "# 3. Save metadata for 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. Clinical Feature Extraction (only if trait_row is not None)\n", "# Since trait_row is None, we'll skip the clinical feature extraction step\n", "print(f\"No direct {trait} information available in this dataset.\")\n", "print(f\"This is primarily a COPD study with some gene signature correlation to {trait} mentioned in the background.\")\n" ] }, { "cell_type": "markdown", "id": "b62ab3e1", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "9baddcc6", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:46:50.276599Z", "iopub.status.busy": "2025-03-25T05:46:50.276496Z", "iopub.status.idle": "2025-03-25T05:46:51.067419Z", "shell.execute_reply": "2025-03-25T05:46:51.066821Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matrix file found: ../../input/GEO/Huntingtons_Disease/GSE71220/GSE71220_series_matrix.txt.gz\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape: (12381, 617)\n", "First 20 gene/probe identifiers:\n", "Index(['7892501', '7892504', '7892507', '7892508', '7892509', '7892510',\n", " '7892514', '7892515', '7892516', '7892517', '7892520', '7892521',\n", " '7892527', '7892530', '7892531', '7892533', '7892534', '7892535',\n", " '7892536', '7892538'],\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": "18462f2e", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "bd545e92", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:46:51.069238Z", "iopub.status.busy": "2025-03-25T05:46:51.069124Z", "iopub.status.idle": "2025-03-25T05:46:51.071355Z", "shell.execute_reply": "2025-03-25T05:46:51.070931Z" } }, "outputs": [], "source": [ "# The gene identifiers shown are numerical codes (like \"7892501\") that appear to be probe IDs\n", "# rather than standard human gene symbols (which would be alphabetical like \"GAPDH\", \"TP53\", etc.)\n", "# These are likely microarray probe identifiers that need to be mapped to gene symbols.\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "228b23c8", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "8c6fc7ec", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:46:51.073040Z", "iopub.status.busy": "2025-03-25T05:46:51.072898Z", "iopub.status.idle": "2025-03-25T05:47:02.221384Z", "shell.execute_reply": "2025-03-25T05:47:02.220918Z" } }, "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", "Examining potential gene mapping columns:\n", "\n", "Sample values from 'gene_assignment' column:\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 /// 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']\n", "\n", "Sample values from 'mrna_assignment' column:\n", "['---', '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']\n" ] } ], "source": [ "# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\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", "# Look more closely at columns that might contain gene information\n", "print(\"\\nExamining potential gene mapping columns:\")\n", "potential_gene_columns = ['gene_assignment', 'mrna_assignment', 'swissprot', 'unigene']\n", "for col in potential_gene_columns:\n", " if col in gene_annotation.columns:\n", " print(f\"\\nSample values from '{col}' column:\")\n", " print(gene_annotation[col].head(3).tolist())\n" ] }, { "cell_type": "markdown", "id": "89f865ec", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "1877d200", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:47:02.222885Z", "iopub.status.busy": "2025-03-25T05:47:02.222764Z", "iopub.status.idle": "2025-03-25T05:47:03.164459Z", "shell.execute_reply": "2025-03-25T05:47:03.163859Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape after mapping: (23114, 617)\n", "First 10 gene symbols after mapping:\n", "Index(['A-', 'A-52', 'A-I', 'A1', 'A1-', 'A10', 'A11', 'A12', 'A13', 'A14'], dtype='object', name='Gene')\n" ] } ], "source": [ "# 1. Determine which columns to use for mapping\n", "# From the preview, we see:\n", "# - 'ID' column in gene_annotation contains probe IDs that match gene expression data index\n", "# - 'gene_assignment' column contains gene symbols embedded in a complex string format\n", "\n", "# 2. Create gene mapping dataframe\n", "# Extract the mapping between probe IDs and gene symbols\n", "mapping_df = get_gene_mapping(gene_annotation, 'ID', 'gene_assignment')\n", "\n", "# 3. Apply gene mapping to convert probe-level measurements to gene expression data\n", "# This function handles the many-to-many relationship as specified\n", "gene_data = apply_gene_mapping(gene_data, mapping_df)\n", "\n", "# Print gene data shape before and after mapping\n", "print(f\"Gene data shape after mapping: {gene_data.shape}\")\n", "print(\"First 10 gene symbols after mapping:\")\n", "print(gene_data.index[:10])\n" ] }, { "cell_type": "markdown", "id": "c1e5ef14", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "966ee7e7", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:47:03.165619Z", "iopub.status.busy": "2025-03-25T05:47:03.165496Z", "iopub.status.idle": "2025-03-25T05:47:06.716893Z", "shell.execute_reply": "2025-03-25T05:47:06.716374Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalizing gene symbols...\n", "Gene data shape after normalization: (7901, 617)\n", "First 10 normalized gene symbols:\n", "Index(['A2M', 'A4GALT', 'AAA1', 'AAK1', 'AARS1', 'AASDH', 'AASDHPPT', 'AATF',\n", " 'ABAT', 'ABCA1'],\n", " dtype='object', name='Gene')\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to: ../../output/preprocess/Huntingtons_Disease/gene_data/GSE71220.csv\n", "\n", "This dataset does not contain relevant Huntington's Disease trait information.\n", "As determined in Step 2, this dataset is about COPD with only a mention of gene signature correlation to Huntington's Disease.\n", "\n", "Preparing documentation of clinical data availability...\n", "Clinical data documentation saved to: ../../output/preprocess/Huntingtons_Disease/clinical_data/GSE71220.csv\n", "\n", "Skipping data linking since trait information is not available.\n", "Abnormality detected in the cohort: GSE71220. Preprocessing failed.\n", "Dataset usability validation completed. Is usable: False\n", "Dataset does not contain Huntington's Disease trait information, so linked data not created or saved.\n" ] } ], "source": [ "# 1. Normalize gene symbols using NCBI database\n", "print(\"Normalizing 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", "print(\"First 10 normalized gene symbols:\")\n", "print(gene_data_normalized.index[:10])\n", "\n", "# Save the normalized gene 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 data saved to: {out_gene_data_file}\")\n", "\n", "# Since Step 2 determined that trait_row is None, this dataset doesn't contain\n", "# relevant Huntington's Disease trait information\n", "print(\"\\nThis dataset does not contain relevant Huntington's Disease trait information.\")\n", "print(\"As determined in Step 2, this dataset is about COPD with only a mention of gene signature correlation to Huntington's Disease.\")\n", "\n", "# Create a minimal clinical data structure to document the absence of trait data\n", "print(\"\\nPreparing documentation of clinical data availability...\")\n", "empty_clinical_df = pd.DataFrame({trait: []})\n", "os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", "empty_clinical_df.to_csv(out_clinical_data_file)\n", "print(f\"Clinical data documentation saved to: {out_clinical_data_file}\")\n", "\n", "# No linking is possible since trait data is not available\n", "print(\"\\nSkipping data linking since trait information is not available.\")\n", "\n", "# Create a minimal dataframe with proper structure for validation\n", "minimal_df = pd.DataFrame({trait: [0]}) # At least one row with trait column\n", "\n", "# Conduct final quality validation - we already know this dataset is not usable for our specific trait\n", "note = \"This GSE71220 dataset contains gene expression data from COPD patients and mentions a correlation of gene signatures with Huntington's Disease in its description, but does not contain direct Huntington's Disease trait information.\"\n", "is_usable = validate_and_save_cohort_info(\n", " is_final=True,\n", " cohort=cohort,\n", " info_path=json_path,\n", " is_gene_available=True,\n", " is_trait_available=False,\n", " is_biased=False, # Set to False since trait unavailability is not a bias issue\n", " df=minimal_df, # Provide minimally structured dataframe\n", " note=note\n", ")\n", "\n", "print(f\"Dataset usability validation completed. Is usable: {is_usable}\")\n", "print(\"Dataset does not contain Huntington's Disease trait information, so linked data not created or 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 }