{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "737774aa", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:09:20.466183Z", "iopub.status.busy": "2025-03-25T06:09:20.465955Z", "iopub.status.idle": "2025-03-25T06:09:20.631680Z", "shell.execute_reply": "2025-03-25T06:09:20.631350Z" } }, "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 = \"Parkinsons_Disease\"\n", "cohort = \"GSE71220\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Parkinsons_Disease\"\n", "in_cohort_dir = \"../../input/GEO/Parkinsons_Disease/GSE71220\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Parkinsons_Disease/GSE71220.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Parkinsons_Disease/gene_data/GSE71220.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Parkinsons_Disease/clinical_data/GSE71220.csv\"\n", "json_path = \"../../output/preprocess/Parkinsons_Disease/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "d632fd27", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "288b297b", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:09:20.633073Z", "iopub.status.busy": "2025-03-25T06:09:20.632925Z", "iopub.status.idle": "2025-03-25T06:09:21.027596Z", "shell.execute_reply": "2025-03-25T06:09:21.027251Z" } }, "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": "d6eccfa6", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "d0d004b7", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:09:21.028784Z", "iopub.status.busy": "2025-03-25T06:09:21.028679Z", "iopub.status.idle": "2025-03-25T06:09:21.033574Z", "shell.execute_reply": "2025-03-25T06:09:21.033284Z" } }, "outputs": [], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on the background information, this appears to be gene expression data\n", "# The information mentions \"Whole blood gene expression was measured on 168 statin users and 452 non-users\"\n", "# and \"Gene expression was measured using the Affymetrix Human Gene 1.1 ST microarray chips\"\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "\n", "# For Parkinson's Disease trait:\n", "# From the background information, this dataset is about COPD (Chronic Obstructive Pulmonary Disease),\n", "# not Parkinson's Disease. The dataset doesn't contain information relevant to Parkinson's Disease.\n", "trait_row = None # No relevant trait data for Parkinson's Disease\n", "\n", "# For age:\n", "# Age is available in row 2\n", "age_row = 2\n", "\n", "# For gender:\n", "# Gender is available in row 3 labeled as \"Sex\"\n", "gender_row = 3\n", "\n", "# 2.2 Data Type Conversion\n", "\n", "def convert_trait(value):\n", " \"\"\"Convert disease status to binary, where 1 represents having Parkinson's Disease and 0 represents control.\"\"\"\n", " # This dataset doesn't have PD information, so this function won't be used\n", " # But we define it for completeness\n", " if value is None:\n", " return None\n", " \n", " # Extract the value after the colon\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # This dataset doesn't contain PD data\n", " return None\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age to continuous numeric value.\"\"\"\n", " if value is None:\n", " return None\n", " \n", " # Extract the value after the colon\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " try:\n", " return float(value)\n", " except (ValueError, TypeError):\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender to binary, where 0 represents female and 1 represents male.\"\"\"\n", " if value is None:\n", " return None\n", " \n", " # Extract the value after the colon\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " if value.upper() == 'F':\n", " return 0\n", " elif value.upper() == 'M':\n", " return 1\n", " else:\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Since trait_row is None, we don't have relevant trait data available for Parkinson's Disease\n", "is_trait_available = trait_row is not None\n", "validate_and_save_cohort_info(\n", " is_final=False,\n", " cohort=cohort,\n", " info_path=json_path,\n", " is_gene_available=is_gene_available,\n", " is_trait_available=is_trait_available\n", ")\n", "\n", "# 4. Clinical Feature Extraction\n", "# Since trait_row is None (no relevant PD data), we skip this step\n", "if trait_row is not None:\n", " # Get clinical dataframe by selecting relevant features\n", " clinical_df = geo_select_clinical_features(\n", " clinical_df=clinical_data,\n", " trait=trait,\n", " trait_row=trait_row,\n", " convert_trait=convert_trait,\n", " age_row=age_row,\n", " convert_age=convert_age,\n", " gender_row=gender_row,\n", " convert_gender=convert_gender\n", " )\n", " \n", " # Preview the results\n", " preview = preview_df(clinical_df)\n", " print(\"Preview of clinical data:\")\n", " print(preview)\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, index=False)\n", " print(f\"Clinical data saved to {out_clinical_data_file}\")\n" ] }, { "cell_type": "markdown", "id": "047784f0", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "3ba8a8bb", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:09:21.034613Z", "iopub.status.busy": "2025-03-25T06:09:21.034512Z", "iopub.status.idle": "2025-03-25T06:09:21.806187Z", "shell.execute_reply": "2025-03-25T06:09:21.805815Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "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. 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": "4700274d", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "fa46eece", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:09:21.807422Z", "iopub.status.busy": "2025-03-25T06:09:21.807300Z", "iopub.status.idle": "2025-03-25T06:09:21.809278Z", "shell.execute_reply": "2025-03-25T06:09:21.808959Z" } }, "outputs": [], "source": [ "# The identifiers appear to be numeric probe IDs from a microarray platform\n", "# These are not human gene symbols, but rather platform-specific identifiers\n", "# They need to be mapped to gene symbols for proper analysis\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "daa68b9b", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "9a58aa4b", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:09:21.810336Z", "iopub.status.busy": "2025-03-25T06:09:21.810235Z", "iopub.status.idle": "2025-03-25T06:09:33.161315Z", "shell.execute_reply": "2025-03-25T06:09:33.160924Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\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" ] } ], "source": [ "# 1. First get the file paths using geo_get_relevant_filepaths function\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# 2. 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", "# 3. 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": "82575720", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "0b8e7892", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:09:33.162820Z", "iopub.status.busy": "2025-03-25T06:09:33.162698Z", "iopub.status.idle": "2025-03-25T06:09:34.100279Z", "shell.execute_reply": "2025-03-25T06:09:34.099899Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "First 20 gene symbols after mapping:\n", "Index(['A-', 'A-52', 'A-I', 'A1', 'A1-', 'A10', 'A11', 'A12', 'A13', 'A14',\n", " 'A18', 'A19', 'A2', 'A20', 'A22', 'A23', 'A24', 'A2M', 'A3', 'A33'],\n", " dtype='object', name='Gene')\n", "Gene expression data shape: (23114, 617)\n" ] } ], "source": [ "# 1. Determine which columns in the gene annotation DataFrame contain identifiers and gene symbols\n", "# From the preview, we can see:\n", "# - 'ID' column contains numeric identifiers that match the gene expression data's row indices\n", "# - 'gene_assignment' column contains gene symbols in a complex format that needs parsing\n", "\n", "# 2. Get a gene mapping dataframe\n", "# Create a mapping from probe IDs to gene symbols\n", "mapping_data = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='gene_assignment')\n", "\n", "# 3. Apply gene mapping to convert probe-level measurements to gene-level expression\n", "gene_data = apply_gene_mapping(gene_data, mapping_data)\n", "\n", "# Print the first few gene symbols after mapping to verify successful conversion\n", "print(\"First 20 gene symbols after mapping:\")\n", "print(gene_data.index[:20])\n", "\n", "# Get the dimensions of the gene expression data\n", "print(f\"Gene expression data shape: {gene_data.shape}\")\n" ] }, { "cell_type": "markdown", "id": "b3d22d6e", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "3ec06036", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:09:34.101581Z", "iopub.status.busy": "2025-03-25T06:09:34.101464Z", "iopub.status.idle": "2025-03-25T06:09:37.584211Z", "shell.execute_reply": "2025-03-25T06:09:37.583825Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape after normalization: (7901, 617)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Parkinsons_Disease/gene_data/GSE71220.csv\n", "This dataset doesn't contain relevant data for Parkinson's Disease.\n", "Dataset is not usable for target trait analysis. Linked data will not be saved.\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\"Gene data shape after normalization: {normalized_gene_data.shape}\")\n", "\n", "# Save the normalized gene expression 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 we determined in Step 2 that trait_row is None (this dataset doesn't contain Parkinson's Disease data),\n", "# we cannot link clinical and genetic data for our target trait\n", "print(\"This dataset doesn't contain relevant data for Parkinson's Disease.\")\n", "\n", "# Set is_trait_available to False since we don't have PD trait data\n", "is_trait_available = False\n", "\n", "# Validate using is_final=False since we're doing an initial validation for a dataset without our target trait\n", "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=is_trait_available\n", ")\n", "\n", "print(\"Dataset is not usable for target trait analysis. Linked data will not be 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 }