{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "7236afe5", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:41:08.231431Z", "iopub.status.busy": "2025-03-25T06:41:08.231210Z", "iopub.status.idle": "2025-03-25T06:41:08.399434Z", "shell.execute_reply": "2025-03-25T06:41:08.399084Z" } }, "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 = \"Asthma\"\n", "cohort = \"GSE184382\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Asthma\"\n", "in_cohort_dir = \"../../input/GEO/Asthma/GSE184382\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Asthma/GSE184382.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Asthma/gene_data/GSE184382.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Asthma/clinical_data/GSE184382.csv\"\n", "json_path = \"../../output/preprocess/Asthma/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "0cbdc1b6", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "8d1164a0", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:41:08.400863Z", "iopub.status.busy": "2025-03-25T06:41:08.400724Z", "iopub.status.idle": "2025-03-25T06:41:08.568600Z", "shell.execute_reply": "2025-03-25T06:41:08.568182Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Sputum microRNA‐screening reveals Prostaglandin EP3 receptor as selective target in allergen‐specific immunotherapy\"\n", "!Series_summary\t\"Several microRNAs (miRs) have been described as potential biomarkers in liquid biopsies and in the context of allergic asthma, while therapeutic effects on the airway expression of miRs remain elusive. In this study, we investigated epigenetic miR-associated mechanisms in the sputum of grass pollen allergic patients with and without allergen specific immunotherapy (AIT). Induced sputum samples of healthy controls (HC), AIT treated and untreated grass pollen allergic rhinitis patients with (AA) and without asthma (AR) were profiled using miR microarray and transcriptome microarray analysis of the same samples. miR targets were predicted in silico and used to identify inverse regulation. Local PGE2 levels were measured using ELISA.\"\n", "!Series_summary\t\"Two Hundred and fifty nine miRs were upregulated in the sputum of AA patients compared with HC, while only one was downregulated. The inverse picture was observed in induced sputum of AIT-treated patients: while 21 miRs were downregulated, only 4 miRs were upregulated in asthmatics upon AIT. Of these 4 miRs, miR3935 stood out, as its predicted target PTGER3, the prostaglandin EP3 receptor, was downregulated in treated AA patients compared with untreated. The levels of its ligand PGE2 in the sputum supernatants of these samples were increased in allergic patients, especially asthmatics, and downregulated after AIT. Finally, local PGE2 levels correlated with ILC2 frequencies, secreted sputum IL13 levels, inflammatory cell load, sputum eosinophils and symptom burden.While profiling the sputum of allergic patients for novel miR expression patterns, we uncovered an association between miR3935 and its predicted target gene, the prostaglandin E3 receptor, which might mediate AIT effects through suppression of the PGE2-PTGER3 axis.\"\n", "!Series_overall_design\t\"Induced sputa were performed in healthy controls, allergic rhinitis with and without concomittant asthma in grass pollen season. Some of the patients received allergen-specific immunotherapy (AIT).\"\n", "Sample Characteristics Dictionary:\n", "{0: ['season: in season'], 1: ['ait treatment: yes', 'ait treatment: no']}\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": "73124588", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "51f2876a", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:41:08.569954Z", "iopub.status.busy": "2025-03-25T06:41:08.569843Z", "iopub.status.idle": "2025-03-25T06:41:08.576140Z", "shell.execute_reply": "2025-03-25T06:41:08.575856Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Step 1: Analyze if gene expression data is likely to be available\n", "is_gene_available = False # This dataset appears to be focused on microRNA profiling, not gene expression\n", "\n", "# Step 2: Determine availability and data conversion for trait, age, and gender\n", "# Looking at the sample characteristics, we see:\n", "# {0: ['season: in season'], 1: ['ait treatment: yes', 'ait treatment: no']}\n", "\n", "# 2.1 Data Availability\n", "# For trait (Asthma), the data can be inferred from the background mentioning \"AA\" (allergic asthma)\n", "# and \"AR\" (allergic rhinitis without asthma), but not directly available in the sample characteristics\n", "trait_row = None # Asthma status not directly available in the sample characteristics\n", "age_row = None # Age information not available\n", "gender_row = None # Gender information not available\n", "\n", "# 2.2 Data Type Conversion Functions\n", "# Since trait data is not available, we still define a conversion function but it won't be used\n", "def convert_trait(value):\n", " if value is None:\n", " return None\n", " value = value.lower().split(':', 1)[-1].strip()\n", " if 'asthma' in value or 'aa' in value:\n", " return 1\n", " elif 'no asthma' in value or 'ar' in value:\n", " return 0\n", " return None\n", "\n", "def convert_age(value):\n", " if value is None:\n", " return None\n", " try:\n", " # Extract numeric value after colon\n", " age_str = value.split(':', 1)[-1].strip()\n", " return float(age_str)\n", " except:\n", " return None\n", "\n", "def convert_gender(value):\n", " if value is None:\n", " return None\n", " value = value.lower().split(':', 1)[-1].strip()\n", " if 'female' in value or 'f' == value:\n", " return 0\n", " elif 'male' in value or 'm' == value:\n", " return 1\n", " return None\n", "\n", "# Step 3: Save metadata\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", "# Step 4: Clinical Feature Extraction\n", "# Since trait_row is None, we'll skip this substep\n" ] }, { "cell_type": "markdown", "id": "2bdd0885", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "e981904a", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:41:08.577234Z", "iopub.status.busy": "2025-03-25T06:41:08.577130Z", "iopub.status.idle": "2025-03-25T06:41:08.841888Z", "shell.execute_reply": "2025-03-25T06:41:08.841500Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matrix file found: ../../input/GEO/Asthma/GSE184382/GSE184382_series_matrix.txt.gz\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape: (58341, 39)\n", "First 20 gene/probe identifiers:\n", "Index(['(+)E1A_r60_1', '(+)E1A_r60_3', '(+)E1A_r60_a104', '(+)E1A_r60_a107',\n", " '(+)E1A_r60_a135', '(+)E1A_r60_a20', '(+)E1A_r60_a22', '(+)E1A_r60_a97',\n", " '(+)E1A_r60_n11', '(+)E1A_r60_n9', '3xSLv1', 'A_19_P00315452',\n", " 'A_19_P00315492', 'A_19_P00315493', 'A_19_P00315502', 'A_19_P00315506',\n", " 'A_19_P00315518', 'A_19_P00315519', 'A_19_P00315529', 'A_19_P00315541'],\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": "830220ae", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "597dc8c3", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:41:08.843313Z", "iopub.status.busy": "2025-03-25T06:41:08.843198Z", "iopub.status.idle": "2025-03-25T06:41:08.845136Z", "shell.execute_reply": "2025-03-25T06:41:08.844843Z" } }, "outputs": [], "source": [ "# Examining the gene identifiers in the gene expression data\n", "# The identifiers like \"(+)E1A_r60_1\", \"A_19_P00315452\" are not standard human gene symbols\n", "# These appear to be Agilent microarray probe IDs that need to be mapped to gene symbols\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "16403830", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "e5220228", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:41:08.846369Z", "iopub.status.busy": "2025-03-25T06:41:08.846266Z", "iopub.status.idle": "2025-03-25T06:41:13.160532Z", "shell.execute_reply": "2025-03-25T06:41:13.160140Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene annotation preview:\n", "{'ID': ['GE_BrightCorner', 'DarkCorner', 'A_21_P0014386', 'A_33_P3396872', 'A_33_P3267760'], 'CONTROL_TYPE': ['pos', 'pos', 'FALSE', 'FALSE', 'FALSE'], 'REFSEQ': [nan, nan, nan, 'NM_001105533', nan], 'GB_ACC': [nan, nan, nan, 'NM_001105533', nan], 'LOCUSLINK_ID': [nan, nan, nan, 79974.0, 54880.0], 'GENE_SYMBOL': [nan, nan, nan, 'CPED1', 'BCOR'], 'GENE_NAME': [nan, nan, nan, 'cadherin-like and PC-esterase domain containing 1', 'BCL6 corepressor'], 'UNIGENE_ID': [nan, nan, nan, 'Hs.189652', nan], 'ENSEMBL_ID': [nan, nan, nan, nan, 'ENST00000378463'], 'ACCESSION_STRING': [nan, nan, nan, 'ref|NM_001105533|gb|AK025639|gb|BC030538|tc|THC2601673', 'ens|ENST00000378463'], 'CHROMOSOMAL_LOCATION': [nan, nan, 'unmapped', 'chr7:120901888-120901947', 'chrX:39909128-39909069'], 'CYTOBAND': [nan, nan, nan, 'hs|7q31.31', 'hs|Xp11.4'], 'DESCRIPTION': [nan, nan, nan, 'Homo sapiens cadherin-like and PC-esterase domain containing 1 (CPED1), transcript variant 2, mRNA [NM_001105533]', 'BCL6 corepressor [Source:HGNC Symbol;Acc:HGNC:20893] [ENST00000378463]'], 'GO_ID': [nan, nan, nan, 'GO:0005783(endoplasmic reticulum)', 'GO:0000122(negative regulation of transcription from RNA polymerase II promoter)|GO:0000415(negative regulation of histone H3-K36 methylation)|GO:0003714(transcription corepressor activity)|GO:0004842(ubiquitin-protein ligase activity)|GO:0005515(protein binding)|GO:0005634(nucleus)|GO:0006351(transcription, DNA-dependent)|GO:0007507(heart development)|GO:0008134(transcription factor binding)|GO:0030502(negative regulation of bone mineralization)|GO:0031072(heat shock protein binding)|GO:0031519(PcG protein complex)|GO:0035518(histone H2A monoubiquitination)|GO:0042476(odontogenesis)|GO:0042826(histone deacetylase binding)|GO:0044212(transcription regulatory region DNA binding)|GO:0045892(negative regulation of transcription, DNA-dependent)|GO:0051572(negative regulation of histone H3-K4 methylation)|GO:0060021(palate development)|GO:0065001(specification of axis polarity)|GO:0070171(negative regulation of tooth mineralization)'], 'SEQUENCE': [nan, nan, 'AATACATGTTTTGGTAAACACTCGGTCAGAGCACCCTCTTTCTGTGGAATCAGACTGGCA', 'GCTTATCTCACCTAATACAGGGACTATGCAACCAAGAAACTGGAAATAAAAACAAAGATA', 'CATCAAAGCTACGAGAGATCCTACACACCCAGATTTAAAAAATAATAAAAACTTAAGGGC'], 'SPOT_ID': ['GE_BrightCorner', 'DarkCorner', 'A_21_P0014386', 'A_33_P3396872', 'A_33_P3267760']}\n" ] } ], "source": [ "# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.\n", "gene_annotation = get_gene_annotation(soft_file)\n", "\n", "# 2. Use the 'preview_df' function from the library to preview the data and print out the results.\n", "print(\"Gene annotation preview:\")\n", "print(preview_df(gene_annotation))\n" ] }, { "cell_type": "markdown", "id": "446daaf7", "metadata": {}, "source": [ "### Step 6: Gene Identifier Mapping" ] }, { "cell_type": "code", "execution_count": 7, "id": "7746934a", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:41:13.161966Z", "iopub.status.busy": "2025-03-25T06:41:13.161841Z", "iopub.status.idle": "2025-03-25T06:41:13.407980Z", "shell.execute_reply": "2025-03-25T06:41:13.407585Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene mapping shape: (48862, 2)\n", "First few rows of the mapping dataframe:\n", " ID Gene\n", "3 A_33_P3396872 CPED1\n", "4 A_33_P3267760 BCOR\n", "5 A_32_P194264 CHAC2\n", "6 A_23_P153745 IFI30\n", "10 A_21_P0014180 GPR146\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Processed gene_data shape: (29222, 39)\n", "First few gene symbols:\n", "Index(['A1BG', 'A1BG-AS1', 'A1CF', 'A1CF-2', 'A1CF-3', 'A2M', 'A2M-1',\n", " 'A2M-AS1', 'A2ML1', 'A2MP1'],\n", " dtype='object', name='Gene')\n" ] } ], "source": [ "# 1. Identify relevant columns for mapping\n", "# Looking at the gene annotation preview:\n", "# 'ID' appears to contain identifiers similar to those in gene_data index (e.g., A_19_P... format)\n", "# 'GENE_SYMBOL' contains the human gene symbols we want to map to\n", "\n", "# 2. Extract gene mapping from annotation data\n", "mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL')\n", "print(f\"Gene mapping shape: {mapping_df.shape}\")\n", "print(\"First few rows of the mapping dataframe:\")\n", "print(mapping_df.head())\n", "\n", "# 3. Apply gene mapping to convert probe-level data to gene-level data\n", "gene_data = apply_gene_mapping(gene_data, mapping_df)\n", "print(f\"Processed gene_data shape: {gene_data.shape}\")\n", "print(\"First few gene symbols:\")\n", "print(gene_data.index[:10])\n" ] }, { "cell_type": "markdown", "id": "07365d76", "metadata": {}, "source": [ "### Step 7: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 8, "id": "2d079814", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:41:13.409345Z", "iopub.status.busy": "2025-03-25T06:41:13.409231Z", "iopub.status.idle": "2025-03-25T06:41:13.996798Z", "shell.execute_reply": "2025-03-25T06:41:13.996406Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Asthma/gene_data/GSE184382.csv\n", "Abnormality detected in the cohort: GSE184382. Preprocessing failed.\n", "Dataset is not usable for analysis due to missing trait information. Gene data was saved, but no linked data file was created.\n" ] } ], "source": [ "# 1. Normalize gene symbols in the gene expression data\n", "gene_data = normalize_gene_symbols_in_index(gene_data)\n", "os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n", "gene_data.to_csv(out_gene_data_file)\n", "print(f\"Normalized gene data saved to {out_gene_data_file}\")\n", "\n", "# Since trait_row was determined to be None in Step 2, the dataset lacks the trait information\n", "# we need for our analysis. We'll save the gene data but won't attempt to create linked data.\n", "\n", "# Create a minimal dataframe with the trait column\n", "dummy_df = pd.DataFrame({trait: []})\n", "\n", "# 5. Validate and save cohort information - with final assessment\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, # We do have gene expression data\n", " is_trait_available=False, # But we lack the trait information\n", " is_biased=True, # A dataset without trait information is considered biased for our purposes\n", " df=dummy_df, # Minimal dataframe with trait column\n", " note=\"Dataset contains gene expression data but lacks explicit Asthma trait information in the sample characteristics.\"\n", ")\n", "\n", "print(\"Dataset is not usable for analysis due to missing trait information. Gene data was saved, but no linked data file was created.\")" ] } ], "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 }