{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "64429969", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:06:48.816670Z", "iopub.status.busy": "2025-03-25T06:06:48.816435Z", "iopub.status.idle": "2025-03-25T06:06:48.979068Z", "shell.execute_reply": "2025-03-25T06:06:48.978690Z" } }, "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 = \"Pancreatic_Cancer\"\n", "cohort = \"GSE222788\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Pancreatic_Cancer\"\n", "in_cohort_dir = \"../../input/GEO/Pancreatic_Cancer/GSE222788\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Pancreatic_Cancer/GSE222788.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Pancreatic_Cancer/gene_data/GSE222788.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Pancreatic_Cancer/clinical_data/GSE222788.csv\"\n", "json_path = \"../../output/preprocess/Pancreatic_Cancer/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "57015d2f", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "9afdce12", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:06:48.980508Z", "iopub.status.busy": "2025-03-25T06:06:48.980368Z", "iopub.status.idle": "2025-03-25T06:06:49.004445Z", "shell.execute_reply": "2025-03-25T06:06:49.004140Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Addition of losartan to FOLFIRINOX and chemoradiation reduces immunosuppression-associated genes, Tregs and FOXP3+ cancer cells in locally advanced pancreatic cancer\"\n", "!Series_summary\t\"Purpose: Adding losartan (LOS) to FOLFIRINOX (FFX) chemotherapy followed by chemoradiation (CRT) resulted in 61% R0 surgical resection in our phase II trial in patients with locally advanced pancreatic cancer (LAPC). Here we identify potential mechanisms of benefit by assessing the effects of neoadjuvant losartan on the stromal tumor microenvironment. Experimental Design: We performed a gene expression and immunofluorescence (IF) analysis using archived surgical samples from patients treated with LOS+FFX+CRT (NCT01821729), FFX+CRT (NCT01591733) or surgery upfront, without any neoadjuvant therapy. We also conducted a longitudinal analysis of multiple biomarkers in the plasma of treated patients. Results: In comparison to FFX+CRT, LOS+FFX+CRT downregulated immunosuppression and pro-invasion genes. Overall survival (OS) was associated with DC and antigen presentation genes for patients treated with FFX+CRT, and with immunosuppression and invasion genes or DC– and blood vessel-related genes for those treated with LOS+FFX+CRT. Furthermore, losartan induced specific changes in circulating levels of IL-8, sTie2 and TGF-. IF revealed significantly less residual disease in lesions treated with LOS+FFX+CRT. Lastly, patients with a complete/near complete pathological response in the LOS+FFX+CRT-treated group had reduced CD4+FOXP3+ regulatory T cells (Tregs), fewer immunosuppressive FOXP3+ cancer cells (C-FOXP3) and increased CD8+ T cells in PDAC lesions. Conclusions: Adding losartan to FFX+CRT reduced pro-invasion and immunosuppression related genes which were associated with improved survival in patients with LAPC. Lesions from responders in the LOS+FFX+CRT-treated group had reduced Tregs, decreased C-FOXP3 and increased CD8+ T cells. These findings suggest that losartan may potentiate the benefit of FFX+CRT by reducing immunosuppression.\"\n", "!Series_overall_design\t\"Analysis of gene expression in the immune TME in resected PDAC samples. To characterize the effects and identify potential molecular mechanisms of cytotoxic agents in combination with losartan on the immune TME, we used the nCounter PanCancer Immune Profiling Panel of 730 genes (NanoString) to analyze the RNA extracted from formalin-fixed paraffin embedded (FFPE) PDAC tissue sections.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['treatment group: FFX_losartan', 'treatment group: FFX', 'treatment group: Untreated']}\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": "2ee955d8", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "3fdab1a3", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:06:49.005513Z", "iopub.status.busy": "2025-03-25T06:06:49.005405Z", "iopub.status.idle": "2025-03-25T06:06:49.012804Z", "shell.execute_reply": "2025-03-25T06:06:49.012493Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Preview of selected clinical data:\n", "{'GSM6932288': [1.0], 'GSM6932289': [1.0], 'GSM6932290': [1.0], 'GSM6932291': [1.0], 'GSM6932292': [1.0], 'GSM6932293': [1.0], 'GSM6932294': [1.0], 'GSM6932295': [1.0], 'GSM6932296': [1.0], 'GSM6932297': [1.0], 'GSM6932298': [1.0], 'GSM6932299': [1.0], 'GSM6932300': [1.0], 'GSM6932301': [1.0], 'GSM6932302': [1.0], 'GSM6932303': [1.0], 'GSM6932304': [1.0], 'GSM6932305': [1.0], 'GSM6932306': [1.0], 'GSM6932307': [1.0], 'GSM6932308': [1.0], 'GSM6932309': [1.0], 'GSM6932310': [1.0], 'GSM6932311': [1.0], 'GSM6932312': [1.0], 'GSM6932313': [1.0], 'GSM6932314': [1.0], 'GSM6932315': [1.0], 'GSM6932316': [1.0], 'GSM6932317': [1.0], 'GSM6932318': [1.0], 'GSM6932319': [1.0], 'GSM6932320': [1.0], 'GSM6932321': [1.0], 'GSM6932322': [1.0], 'GSM6932323': [1.0], 'GSM6932324': [1.0], 'GSM6932325': [1.0], 'GSM6932326': [1.0], 'GSM6932327': [1.0], 'GSM6932328': [1.0]}\n", "Clinical data saved to ../../output/preprocess/Pancreatic_Cancer/clinical_data/GSE222788.csv\n" ] } ], "source": [ "import pandas as pd\n", "import os\n", "import numpy as np\n", "\n", "# Let's analyze the dataset details and extract needed information\n", "\n", "# 1. Gene Expression Data Availability\n", "# Based on the background information, this dataset contains gene expression data using\n", "# nCounter PanCancer Immune Profiling Panel, so it's likely gene expression data.\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# Looking at the sample characteristics dictionary:\n", "# The dict shows {0: ['treatment group: FFX_losartan', 'treatment group: FFX', 'treatment group: Untreated']}\n", "\n", "# 2.1 Data Availability\n", "# - Trait (Pancreatic Cancer): Can be derived from the treatment group row (0)\n", "trait_row = 0 # The treatment group row, which can be used to infer trait status\n", "# - Age: Not explicitly mentioned in the characteristics\n", "age_row = None # Age data is not available\n", "# - Gender: Not explicitly mentioned in the characteristics\n", "gender_row = None # Gender data is not available\n", "\n", "# 2.2 Data Type Conversion Functions\n", "def convert_trait(value):\n", " \"\"\"Convert treatment group to binary trait indicator (cancer vs no cancer)\"\"\"\n", " if pd.isna(value):\n", " return None\n", " \n", " # Extract the value after colon if present\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # All samples appear to be from pancreatic cancer patients with different treatment groups\n", " # Since this is a study of LAPC (locally advanced pancreatic cancer) treatments, \n", " # all samples likely have pancreatic cancer\n", " return 1 # All are cancer patients\n", "\n", "def convert_age(value):\n", " \"\"\"Convert age to continuous value\"\"\"\n", " # This function isn't used since age_row is None\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"Convert gender to binary (0 for female, 1 for male)\"\"\"\n", " # This function isn't used since gender_row is None\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Trait data is available since trait_row is not None\n", "# Initial filtering on the usability of the dataset\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 not None, we need to extract clinical features\n", "if trait_row is not None:\n", " # Assuming we have the clinical_data DataFrame from a previous step\n", " # If not available, we need to load it\n", " try:\n", " # Try to access clinical_data which should have been defined in a previous step\n", " selected_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 dataframe\n", " preview = preview_df(selected_clinical_df)\n", " print(\"Preview of selected clinical data:\")\n", " print(preview)\n", " \n", " # Save the clinical data to CSV\n", " os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", " selected_clinical_df.to_csv(out_clinical_data_file, index=True)\n", " print(f\"Clinical data saved to {out_clinical_data_file}\")\n", " except NameError:\n", " print(\"Error: clinical_data DataFrame not found. It should be defined in a previous step.\")\n" ] }, { "cell_type": "markdown", "id": "764cdb8d", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "dc82d97f", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:06:49.013820Z", "iopub.status.busy": "2025-03-25T06:06:49.013715Z", "iopub.status.idle": "2025-03-25T06:06:49.024324Z", "shell.execute_reply": "2025-03-25T06:06:49.024013Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['A2M-mRNA', 'ABCB1-mRNA', 'ABL1-mRNA', 'ADA-mRNA', 'ADORA2A-mRNA',\n", " 'AICDA-mRNA', 'AIRE-mRNA', 'AKT3-mRNA', 'ALCAM-mRNA', 'AMBP-mRNA',\n", " 'AMICA1-mRNA', 'ANP32B-mRNA', 'ANXA1-mRNA', 'APOE-mRNA', 'APP-mRNA',\n", " 'ARG1-mRNA', 'ARG2-mRNA', 'ATF1-mRNA', 'ATF2-mRNA', 'ATG10-mRNA'],\n", " dtype='object', name='ID')\n" ] } ], "source": [ "# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.\n", "gene_data = get_genetic_data(matrix_file)\n", "\n", "# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.\n", "print(gene_data.index[:20])\n" ] }, { "cell_type": "markdown", "id": "02430089", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "460bd7c2", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:06:49.025293Z", "iopub.status.busy": "2025-03-25T06:06:49.025185Z", "iopub.status.idle": "2025-03-25T06:06:49.026965Z", "shell.execute_reply": "2025-03-25T06:06:49.026660Z" } }, "outputs": [], "source": [ "# Examining the gene identifiers\n", "# These appear to be human gene symbols with \"-mRNA\" appended to them\n", "# A2M, ABCB1, ABL1, etc. are standard human gene symbols\n", "# The \"-mRNA\" suffix indicates these are measuring mRNA expression levels of these genes\n", "# No mapping to gene symbols is required as these are already gene symbols with a suffix\n", "\n", "requires_gene_mapping = False\n" ] }, { "cell_type": "markdown", "id": "2b4b5dd3", "metadata": {}, "source": [ "### Step 5: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 6, "id": "27eb3835", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:06:49.027977Z", "iopub.status.busy": "2025-03-25T06:06:49.027873Z", "iopub.status.idle": "2025-03-25T06:06:49.116752Z", "shell.execute_reply": "2025-03-25T06:06:49.116388Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalized gene data saved to ../../output/preprocess/Pancreatic_Cancer/gene_data/GSE222788.csv\n", "Extracted clinical features with treatment group as trait\n", "Clinical features saved to ../../output/preprocess/Pancreatic_Cancer/clinical_data/GSE222788.csv\n", "Shape of linked data: (41, 1)\n", "Shape after handling missing values: (0, 1)\n", "Quartiles for 'Treatment_Group':\n", " 25%: nan\n", " 50% (Median): nan\n", " 75%: nan\n", "Min: nan\n", "Max: nan\n", "The distribution of the feature 'Treatment_Group' in this dataset is fine.\n", "\n", "Abnormality detected in the cohort: GSE222788. Preprocessing failed.\n", "Data quality check failed. Linked data not saved.\n" ] } ], "source": [ "# 1. Normalize gene symbols in the gene expression data\n", "normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n", "\n", "# Save the normalized gene 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", "# 2. Since this is a treatment comparison study, redefine trait extraction\n", "def convert_treatment_group(value):\n", " \"\"\"Convert treatment group to categorical values\"\"\"\n", " if pd.isna(value):\n", " return None\n", " \n", " # Extract the value after colon if present\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " # Map treatment groups to numeric values\n", " if 'FFX_losartan' in value:\n", " return 0 # FFX with losartan\n", " elif 'FFX' in value:\n", " return 1 # FFX without losartan\n", " elif 'Untreated' in value:\n", " return 2 # No treatment\n", " else:\n", " return None\n", "\n", "# Extract clinical features with treatment group as the trait\n", "clinical_features = geo_select_clinical_features(\n", " clinical_df=clinical_data,\n", " trait=\"Treatment_Group\", # Using a different trait name\n", " trait_row=0, # The treatment group row\n", " convert_trait=convert_treatment_group,\n", " age_row=None,\n", " convert_age=None,\n", " gender_row=None,\n", " convert_gender=None\n", ")\n", "print(\"Extracted clinical features with treatment group as trait\")\n", "\n", "# Save the clinical features\n", "os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n", "clinical_features.to_csv(out_clinical_data_file)\n", "print(f\"Clinical features saved to {out_clinical_data_file}\")\n", "\n", "# Link the clinical and genetic data\n", "linked_data = geo_link_clinical_genetic_data(clinical_features, normalized_gene_data)\n", "print(f\"Shape of linked data: {linked_data.shape}\")\n", "\n", "# 3. Handle missing values in the linked data\n", "linked_data = handle_missing_values(linked_data, \"Treatment_Group\")\n", "print(f\"Shape after handling missing values: {linked_data.shape}\")\n", "\n", "# 4. Determine whether the trait and demographic features are severely biased\n", "is_trait_biased, unbiased_linked_data = judge_and_remove_biased_features(linked_data, \"Treatment_Group\")\n", "\n", "# 5. Conduct quality check and save the cohort 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=True, \n", " is_biased=is_trait_biased, \n", " df=unbiased_linked_data,\n", " note=\"This dataset contains only pancreatic cancer patients with different treatment groups (FFX_losartan, FFX, Untreated). The trait is treatment group rather than cancer status.\"\n", ")\n", "\n", "# 6. If the linked data is usable, save it as a CSV file\n", "if is_usable:\n", " # Create directory if it doesn't exist\n", " os.makedirs(os.path.dirname(out_data_file), exist_ok=True)\n", " # Save the data\n", " unbiased_linked_data.to_csv(out_data_file)\n", " print(f\"Linked data saved to {out_data_file}\")\n", "else:\n", " print(\"Data quality check failed. Linked data not 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 }