{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "072d1ebb", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:34.155037Z", "iopub.status.busy": "2025-03-25T05:27:34.154918Z", "iopub.status.idle": "2025-03-25T05:27:34.329442Z", "shell.execute_reply": "2025-03-25T05:27:34.329082Z" } }, "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 = \"Head_and_Neck_Cancer\"\n", "cohort = \"GSE156915\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Head_and_Neck_Cancer\"\n", "in_cohort_dir = \"../../input/GEO/Head_and_Neck_Cancer/GSE156915\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Head_and_Neck_Cancer/GSE156915.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Head_and_Neck_Cancer/gene_data/GSE156915.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Head_and_Neck_Cancer/clinical_data/GSE156915.csv\"\n", "json_path = \"../../output/preprocess/Head_and_Neck_Cancer/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "e6da70b7", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "45dc47d5", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:34.330932Z", "iopub.status.busy": "2025-03-25T05:27:34.330757Z", "iopub.status.idle": "2025-03-25T05:27:34.872119Z", "shell.execute_reply": "2025-03-25T05:27:34.871685Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"In-depth clinical and biological exploration of DNA Damage Immune Response (DDIR) as a biomarker for oxaliplatin use in colorectal cancer\"\n", "!Series_summary\t\"Purpose: The DNA Damage Immune Response (DDIR) assay was developed in breast cancer (BC) based on biology associated with deficiencies in homologous recombination and Fanconi Anemia (HR/FA) pathways. A positive DDIR call identifies patients likely to respond to platinum-based chemotherapies in breast and oesophageal cancers. In colorectal cancer (CRC) there is currently no biomarker to predict response to oxaliplatin. We tested the ability of the DDIR assay to predict response to oxaliplatin-based chemotherapy in CRC and characterised the biology in DDIR-positive CRC.\"\n", "!Series_summary\t\"Methods: Samples and clinical data were assessed according to DDIR status from patients who received either 5FU or FOLFOX within the FOCUS trial (n=361, stage 4), or neo-adjuvant FOLFOX in the FOxTROT trial (n=97, stage 2/3). Whole transcriptome, mutation and immunohistochemistry data of these samples were used to interrogate the biology of DDIR in CRC.\"\n", "!Series_summary\t\"Results: Contrary to our hypothesis, DDIR negative patients displayed a trend towards improved outcome for oxaliplatin-based chemotherapy compared to DDIR positive patients. DDIR positivity was associated with Microsatellite Instability (MSI) and Colorectal Molecular Subtype 1 (CMS1). Refinement of the DDIR signature, based on overlapping interferon-related chemokine signalling associated with DDIR positivity across CRC and BC cohorts, further confirmed that the DDIR assay did not have predictive value for oxaliplatin-based chemotherapy in CRC.\"\n", "!Series_summary\t\"Conclusions: DDIR positivity does not predict improved response following oxaliplatin treatment in CRC. However, data presented here suggests the potential of the DDIR assay in identifying immune-rich tumours that may benefit from immune checkpoint blockade, beyond current use of MSI status.\"\n", "!Series_overall_design\t\"361 Samples analysed, no replicates nor reference samples used\"\n", "Sample Characteristics Dictionary:\n", "{0: ['dna damage immune response call: DDIR NEG', 'dna damage immune response call: DDIR POS'], 1: ['dna damage repair deficient score: -0.0113183', 'dna damage repair deficient score: -0.205899', 'dna damage repair deficient score: -0.121106', 'dna damage repair deficient score: -0.000462728', 'dna damage repair deficient score: -0.195244', 'dna damage repair deficient score: -0.184334', 'dna damage repair deficient score: -0.161188', 'dna damage repair deficient score: -0.101508', 'dna damage repair deficient score: -0.0944435', 'dna damage repair deficient score: -0.108303', 'dna damage repair deficient score: 0.0381147', 'dna damage repair deficient score: 0.0232011', 'dna damage repair deficient score: 0.122896', 'dna damage repair deficient score: 0.0772034', 'dna damage repair deficient score: 0.202876', 'dna damage repair deficient score: -0.0872516', 'dna damage repair deficient score: -0.0465576', 'dna damage repair deficient score: -0.00224569', 'dna damage repair deficient score: -0.101036', 'dna damage repair deficient score: -0.164303', 'dna damage repair deficient score: -0.141767', 'dna damage repair deficient score: -0.0587852', 'dna damage repair deficient score: -0.051247', 'dna damage repair deficient score: 0.252609', 'dna damage repair deficient score: -0.0289021', 'dna damage repair deficient score: 0.102956', 'dna damage repair deficient score: 0.0314631', 'dna damage repair deficient score: -0.0387756', 'dna damage repair deficient score: 0.0584488', 'dna damage repair deficient score: 0.181194'], 2: ['consensus molecular subtype: Unclassified', 'consensus molecular subtype: CMS4', 'consensus molecular subtype: CMS2', 'consensus molecular subtype: CMS3', 'consensus molecular subtype: CMS1'], 3: ['colorectal cancer intrinsic sub-type: CRIS-B', 'colorectal cancer intrinsic sub-type: CRIS-A', 'colorectal cancer intrinsic sub-type: Unclassified', 'colorectal cancer intrinsic sub-type: CRIS-E', 'colorectal cancer intrinsic sub-type: CRIS-D', 'colorectal cancer intrinsic sub-type: CRIS-C'], 4: ['msi: MSS', 'msi: ', 'msi: MSI'], 5: ['tissue: Formalin-Fixed Paraffin-Embedded tumour'], 6: ['kras: Wt', 'kras: Mut', nan], 7: ['nras: Wt', nan, 'nras: Mut'], 8: ['braf: Mut', 'braf: Wt', nan], 9: ['pik3ca: Wt', nan, 'pik3ca: Mut'], 10: ['tp53: Wt', nan, 'tp53: Mut']}\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": "057b82a9", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "41d0ac74", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:34.873423Z", "iopub.status.busy": "2025-03-25T05:27:34.873306Z", "iopub.status.idle": "2025-03-25T05:27:34.880596Z", "shell.execute_reply": "2025-03-25T05:27:34.880191Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "import numpy as np\n", "import os\n", "import re\n", "from typing import Dict, Any, Optional, Callable\n", "\n", "# 1. Gene Expression Data Availability\n", "# Based on the background information, this dataset appears to be gene expression data\n", "# The study explores DNA Damage Immune Response and has transcriptome data\n", "is_gene_available = True\n", "\n", "# 2.1 Data Availability\n", "# From the sample characteristics dictionary:\n", "\n", "# For trait (Head and Neck Cancer):\n", "# There's no direct mention of head and neck cancer in the sample characteristics\n", "# This dataset appears to be for colorectal cancer, not head and neck cancer\n", "trait_row = None\n", "\n", "# For age:\n", "# No age information is present in the sample characteristics\n", "age_row = None\n", "\n", "# For gender:\n", "# No gender information is present in the sample characteristics\n", "gender_row = None\n", "\n", "# 2.2 Data Type Conversion\n", "# Since trait data is not available for head and neck cancer, we'll create a simple function\n", "def convert_trait(value):\n", " if value is None or pd.isna(value):\n", " return None\n", " # Extract value after colon if present\n", " if ':' in str(value):\n", " value = value.split(':', 1)[1].strip()\n", " # This would be a placeholder as the dataset doesn't contain head and neck cancer information\n", " return None\n", "\n", "# Age conversion function (not used but defined for completeness)\n", "def convert_age(value):\n", " if value is None or pd.isna(value):\n", " return None\n", " # Extract value after colon if present\n", " if ':' in str(value):\n", " value = value.split(':', 1)[1].strip()\n", " try:\n", " return float(value) # Continuous variable\n", " except:\n", " return None\n", "\n", "# Gender conversion function (not used but defined for completeness)\n", "def convert_gender(value):\n", " if value is None or pd.isna(value):\n", " return None\n", " # Extract value after colon if present\n", " if ':' in str(value):\n", " value = value.split(':', 1)[1].strip()\n", " # Convert to binary: female=0, male=1\n", " value = value.lower()\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", "# 3. Save Metadata\n", "# Initial filtering to determine if dataset is usable\n", "# Since trait_row is None, the trait data is not available for head and neck cancer\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=(trait_row is not None)\n", ")\n", "\n", "# 4. Clinical Feature Extraction\n", "# Since trait_row is None, we skip this substep\n" ] }, { "cell_type": "markdown", "id": "595e8b90", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "9db22189", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:34.881782Z", "iopub.status.busy": "2025-03-25T05:27:34.881668Z", "iopub.status.idle": "2025-03-25T05:27:35.971247Z", "shell.execute_reply": "2025-03-25T05:27:35.970612Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matrix file found: ../../input/GEO/Head_and_Neck_Cancer/GSE156915/GSE156915_series_matrix.txt.gz\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape: (27054, 361)\n", "First 20 gene/probe identifiers:\n", "Index(['1060P11.3 /// KIR3DP1', 'A1BG', 'A1BG-AS1', 'A1CF', 'A2M', 'A2M-AS1',\n", " 'A2ML1', 'A2MP1', 'A3GALT2', 'A4GALT', 'A4GNT', 'AA06', 'AAAS', 'AACS',\n", " 'AACSP1', 'AADAC', 'AADACL2', 'AADACL3', 'AADACL4', 'AADACP1'],\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": "3615a17a", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "bfccc51a", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:35.973077Z", "iopub.status.busy": "2025-03-25T05:27:35.972908Z", "iopub.status.idle": "2025-03-25T05:27:35.975948Z", "shell.execute_reply": "2025-03-25T05:27:35.975430Z" } }, "outputs": [], "source": [ "# Analyze gene identifiers\n", "# These appear to be standard human gene symbols (like A1BG, AAAS, AACS, etc.)\n", "# The format follows official HGNC gene symbol nomenclature\n", "# There are some composite identifiers (e.g. \"1060P11.3 /// KIR3DP1\") that contain\n", "# multiple gene symbols separated by \"///\" which is a common format in microarray data\n", "# indicating cross-hybridization, but the identifiers themselves are gene symbols\n", "\n", "requires_gene_mapping = False\n" ] }, { "cell_type": "markdown", "id": "259b70ec", "metadata": {}, "source": [ "### Step 5: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 6, "id": "ca1655e5", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:27:35.977591Z", "iopub.status.busy": "2025-03-25T05:27:35.977479Z", "iopub.status.idle": "2025-03-25T05:27:41.251577Z", "shell.execute_reply": "2025-03-25T05:27:41.251025Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape before normalization: (27054, 361)\n", "Gene data shape after normalization: (22171, 361)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene expression data saved to ../../output/preprocess/Head_and_Neck_Cancer/gene_data/GSE156915.csv\n", "Abnormality detected in the cohort: GSE156915. Preprocessing failed.\n", "Dataset is not usable for Head and Neck Cancer analysis as it contains data for a different trait (colorectal cancer).\n" ] } ], "source": [ "# 1. Normalize gene symbols in the gene expression data\n", "# Use normalize_gene_symbols_in_index to standardize gene symbols\n", "normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n", "print(f\"Gene data shape before normalization: {gene_data.shape}\")\n", "print(f\"Gene data shape after normalization: {normalized_gene_data.shape}\")\n", "\n", "# Save the normalized gene data to file\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 expression data saved to {out_gene_data_file}\")\n", "\n", "# Since we determined in Step 2 that this dataset doesn't contain our target trait (Head and Neck Cancer),\n", "# we should validate this and finish the process without attempting to link data.\n", "\n", "# 5. Conduct final quality validation\n", "note = \"Dataset contains gene expression data related to colorectal cancer and DNA Damage Immune Response (DDIR), not Head and Neck Cancer.\"\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, # We confirmed trait_row is None in Step 2\n", " is_biased=True, # Set to True since we can't use data without our target trait\n", " df=pd.DataFrame(), # Empty DataFrame since we're not processing linked data\n", " note=note\n", ")\n", "\n", "print(\"Dataset is not usable for Head and Neck Cancer analysis as it contains data for a different trait (colorectal cancer).\")" ] } ], "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 }