{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f54decef", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:48:30.159930Z", "iopub.status.busy": "2025-03-25T05:48:30.159823Z", "iopub.status.idle": "2025-03-25T05:48:30.322678Z", "shell.execute_reply": "2025-03-25T05:48:30.322325Z" } }, "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 = \"Hutchinson-Gilford_Progeria_Syndrome\"\n", "cohort = \"GSE84360\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Hutchinson-Gilford_Progeria_Syndrome\"\n", "in_cohort_dir = \"../../input/GEO/Hutchinson-Gilford_Progeria_Syndrome/GSE84360\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Hutchinson-Gilford_Progeria_Syndrome/GSE84360.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Hutchinson-Gilford_Progeria_Syndrome/gene_data/GSE84360.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Hutchinson-Gilford_Progeria_Syndrome/clinical_data/GSE84360.csv\"\n", "json_path = \"../../output/preprocess/Hutchinson-Gilford_Progeria_Syndrome/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "f0e2af6a", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "2b011625", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:48:30.324128Z", "iopub.status.busy": "2025-03-25T05:48:30.323971Z", "iopub.status.idle": "2025-03-25T05:48:30.533101Z", "shell.execute_reply": "2025-03-25T05:48:30.532739Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Reprogramming Hutchinson-Gilford Progeria Syndrome fibroblasts resets epigenomic landscape in patient-derived induced pluripotent stem cells Jan 01, 2018 pending None\"\n", "!Series_summary\t\"This SuperSeries is composed of the SubSeries listed below.\"\n", "!Series_overall_design\t\"Refer to individual Series\"\n", "Sample Characteristics Dictionary:\n", "{0: ['Sex: Male', 'Sex: Female', 'Sex: ?'], 1: ['cell line: HGADFN003', 'cell line: HGMDFN090', 'cell line: HGADFN167', 'cell line: HGFDFN168', 'cell line: AG01972', 'cell line: BJ1', 'cell line: H9'], 2: ['condition: HGPS', 'condition: Normal'], 3: ['cell type: iPSC', 'cell type: Vascular Smooth Muscle', 'cell type: Fibroblast', 'cell type: Embryonic Stem Cell']}\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": "b5d53ce4", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "cfff9b08", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:48:30.534317Z", "iopub.status.busy": "2025-03-25T05:48:30.534205Z", "iopub.status.idle": "2025-03-25T05:48:30.544568Z", "shell.execute_reply": "2025-03-25T05:48:30.544259Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Clinical Data Preview:\n", "{'GSM2232606': [1.0, 1.0], 'GSM2232607': [1.0, 1.0], 'GSM2232608': [1.0, 1.0], 'GSM2232609': [1.0, 1.0], 'GSM2232610': [1.0, 1.0], 'GSM2232611': [1.0, 1.0], 'GSM2232612': [1.0, 1.0], 'GSM2232613': [1.0, 1.0], 'GSM2232614': [1.0, 1.0], 'GSM2232615': [0.0, 0.0], 'GSM2232616': [0.0, 0.0], 'GSM2232617': [0.0, 0.0], 'GSM2232618': [0.0, 0.0], 'GSM2232619': [0.0, 0.0], 'GSM2232620': [0.0, 0.0], 'GSM2232621': [0.0, 0.0], 'GSM2232622': [0.0, 0.0], 'GSM2232623': [0.0, 0.0], 'GSM2232624': [1.0, 1.0], 'GSM2232625': [1.0, 1.0], 'GSM2232626': [1.0, 1.0], 'GSM2232627': [1.0, 1.0], 'GSM2232628': [1.0, 1.0], 'GSM2232629': [1.0, 1.0], 'GSM2232630': [1.0, 1.0], 'GSM2232631': [1.0, 1.0], 'GSM2232632': [1.0, 1.0], 'GSM2232633': [0.0, 1.0], 'GSM2232634': [0.0, 1.0], 'GSM2232635': [0.0, 1.0], 'GSM2232636': [0.0, 1.0], 'GSM2232637': [0.0, 1.0], 'GSM2232638': [0.0, 1.0], 'GSM2232639': [0.0, 1.0], 'GSM2232640': [0.0, 1.0], 'GSM2232641': [1.0, 0.0], 'GSM2232642': [1.0, 0.0], 'GSM2232643': [1.0, 0.0], 'GSM2232644': [1.0, 0.0], 'GSM2232645': [1.0, 0.0], 'GSM2232646': [1.0, 0.0], 'GSM2232647': [1.0, 0.0], 'GSM2232648': [1.0, 0.0], 'GSM2232649': [0.0, 1.0], 'GSM2232650': [0.0, 1.0], 'GSM2232651': [0.0, 1.0], 'GSM2232652': [0.0, 1.0], 'GSM2232653': [0.0, 1.0], 'GSM2232654': [0.0, 1.0], 'GSM2232655': [0.0, 1.0], 'GSM2232656': [0.0, 1.0], 'GSM2232657': [0.0, 1.0], 'GSM2232658': [0.0, nan], 'GSM2232659': [0.0, nan]}\n", "Clinical data saved to ../../output/preprocess/Hutchinson-Gilford_Progeria_Syndrome/clinical_data/GSE84360.csv\n" ] } ], "source": [ "# 1. Evaluate gene expression data availability\n", "# Given the dataset information and sample characteristics, it appears the data is about cell types from patients with HGPS\n", "# Since we have control and HGPS conditions, this dataset likely contains gene expression data\n", "is_gene_available = True\n", "\n", "# 2.1 Data availability and row identification\n", "\n", "# For trait (HGPS status)\n", "# Row 2 contains 'condition: HGPS' and 'condition: Normal', indicating disease status\n", "trait_row = 2\n", "\n", "# For gender\n", "# Row 0 contains 'Sex: Male', 'Sex: Female', 'Sex: ?', indicating gender information\n", "gender_row = 0\n", "\n", "# For age\n", "# No explicit age information is provided in the sample characteristics\n", "age_row = None\n", "\n", "# 2.2 Data type conversion functions\n", "\n", "def convert_trait(value):\n", " \"\"\"\n", " Convert HGPS trait status to binary (0=Normal, 1=HGPS)\n", " \"\"\"\n", " if not isinstance(value, str):\n", " return None\n", " \n", " # Extract the part after colon if present\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " if value.lower() == 'hgps':\n", " return 1\n", " elif value.lower() == 'normal':\n", " return 0\n", " else:\n", " return None\n", "\n", "def convert_gender(value):\n", " \"\"\"\n", " Convert gender to binary (0=Female, 1=Male)\n", " \"\"\"\n", " if not isinstance(value, str):\n", " return None\n", " \n", " # Extract the part after colon if present\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " if value.lower() == 'male':\n", " return 1\n", " elif value.lower() == 'female':\n", " return 0\n", " else:\n", " return None\n", "\n", "# Age conversion function is defined but not used since age data is not available\n", "def convert_age(value):\n", " \"\"\"\n", " Convert age to continuous value\n", " \"\"\"\n", " if not isinstance(value, str):\n", " return None\n", " \n", " # Extract the part after colon if present\n", " if ':' in value:\n", " value = value.split(':', 1)[1].strip()\n", " \n", " try:\n", " return float(value)\n", " except:\n", " return None\n", "\n", "# 3. Save metadata - 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\n", "if trait_row is not None:\n", " # Extract clinical features using the provided function\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 data\n", " preview = preview_df(clinical_df)\n", " print(\"Clinical Data Preview:\")\n", " print(preview)\n", " \n", " # Save clinical data to CSV\n", " clinical_df.to_csv(out_clinical_data_file)\n", " print(f\"Clinical data saved to {out_clinical_data_file}\")\n" ] }, { "cell_type": "markdown", "id": "4a664129", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "7d8f7f19", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:48:30.545691Z", "iopub.status.busy": "2025-03-25T05:48:30.545586Z", "iopub.status.idle": "2025-03-25T05:48:30.863440Z", "shell.execute_reply": "2025-03-25T05:48:30.863013Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Extracting gene data from matrix file:\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Successfully extracted gene data with 53617 rows\n", "First 20 gene IDs:\n", "Index(['16650001', '16650003', '16650005', '16650007', '16650009', '16650011',\n", " '16650013', '16650015', '16650017', '16650019', '16650021', '16650023',\n", " '16650025', '16650027', '16650029', '16650031', '16650033', '16650035',\n", " '16650037', '16650041'],\n", " dtype='object', name='ID')\n", "\n", "Gene expression data available: True\n" ] } ], "source": [ "# 1. Get the file paths for the SOFT file and matrix file\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# 2. Extract gene expression data from the matrix file\n", "try:\n", " print(\"Extracting gene data from matrix file:\")\n", " gene_data = get_genetic_data(matrix_file)\n", " if gene_data.empty:\n", " print(\"Extracted gene expression data is empty\")\n", " is_gene_available = False\n", " else:\n", " print(f\"Successfully extracted gene data with {len(gene_data.index)} rows\")\n", " print(\"First 20 gene IDs:\")\n", " print(gene_data.index[:20])\n", " is_gene_available = True\n", "except Exception as e:\n", " print(f\"Error extracting gene data: {e}\")\n", " print(\"This dataset appears to have an empty or malformed gene expression matrix\")\n", " is_gene_available = False\n", "\n", "print(f\"\\nGene expression data available: {is_gene_available}\")\n" ] }, { "cell_type": "markdown", "id": "3c2d1a53", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "1cc84637", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:48:30.864917Z", "iopub.status.busy": "2025-03-25T05:48:30.864788Z", "iopub.status.idle": "2025-03-25T05:48:30.866817Z", "shell.execute_reply": "2025-03-25T05:48:30.866531Z" } }, "outputs": [], "source": [ "# Reviewing the gene identifiers\n", "# These appear to be probe IDs (numeric identifiers) rather than human gene symbols\n", "# Human gene symbols typically follow naming conventions like BRCA1, TP53, etc.\n", "# These numeric identifiers (16650001, etc.) are likely probe IDs from a microarray platform\n", "# that need to be mapped to official gene symbols for biological interpretation\n", "\n", "requires_gene_mapping = True\n" ] }, { "cell_type": "markdown", "id": "3059b294", "metadata": {}, "source": [ "### Step 5: Gene Annotation" ] }, { "cell_type": "code", "execution_count": 6, "id": "c9ffdc40", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T05:48:30.867911Z", "iopub.status.busy": "2025-03-25T05:48:30.867808Z", "iopub.status.idle": "2025-03-25T05:48:34.572337Z", "shell.execute_reply": "2025-03-25T05:48:34.571882Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Extracting gene annotation data from SOFT file...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Successfully extracted gene annotation data with 2949353 rows\n", "\n", "Gene annotation preview (first few rows):\n", "{'ID': ['16657436', '16657440', '16657445', '16657447', '16657450'], 'RANGE_STRAND': ['+', '+', '+', '+', '+'], 'RANGE_START': [12190.0, 29554.0, 69091.0, 160446.0, 317811.0], 'RANGE_END': [13639.0, 31109.0, 70008.0, 161525.0, 328581.0], 'total_probes': [25.0, 28.0, 8.0, 13.0, 36.0], 'GB_ACC': ['NR_046018', nan, nan, nan, 'NR_024368'], 'SPOT_ID': ['chr1:12190-13639', 'chr1:29554-31109', 'chr1:69091-70008', 'chr1:160446-161525', 'chr1:317811-328581'], 'RANGE_GB': ['NC_000001.10', 'NC_000001.10', 'NC_000001.10', 'NC_000001.10', 'NC_000001.10']}\n", "\n", "Column names in gene annotation data:\n", "['ID', 'RANGE_STRAND', 'RANGE_START', 'RANGE_END', 'total_probes', 'GB_ACC', 'SPOT_ID', 'RANGE_GB']\n", "\n", "This dataset contains SNP identifiers (rs numbers), not gene expression probes.\n", "The data represents genetic variants, not gene expression levels.\n", "Looking at the columns, we can see Chr and Position information, but no direct gene mapping.\n", "\n", "The data contains genomic position information (Chr, Position) that could be used\n", "to map SNPs to genes, but this requires external genomic databases.\n", "\n", "Conclusion: This is SNP genotyping data, not gene expression data.\n", "Traditional gene mapping for expression data is not applicable.\n", "The initial assessment of is_gene_available=True was incorrect.\n", "A new JSON file was created at: ../../output/preprocess/Hutchinson-Gilford_Progeria_Syndrome/cohort_info.json\n" ] } ], "source": [ "# 1. Extract gene annotation data from the SOFT file\n", "print(\"Extracting gene annotation data from SOFT file...\")\n", "try:\n", " # First attempt - use the library function to extract gene annotation\n", " gene_annotation = get_gene_annotation(soft_file)\n", " print(f\"Successfully extracted gene annotation data with {len(gene_annotation.index)} rows\")\n", " \n", " # Preview the annotation DataFrame\n", " print(\"\\nGene annotation preview (first few rows):\")\n", " print(preview_df(gene_annotation))\n", " \n", " # Show column names to help identify which columns we need for mapping\n", " print(\"\\nColumn names in gene annotation data:\")\n", " print(gene_annotation.columns.tolist())\n", " \n", " # We can see this is SNP data, not gene expression data\n", " print(\"\\nThis dataset contains SNP identifiers (rs numbers), not gene expression probes.\")\n", " print(\"The data represents genetic variants, not gene expression levels.\")\n", " print(\"Looking at the columns, we can see Chr and Position information, but no direct gene mapping.\")\n", " \n", " # Check for genomic position information that could potentially be used for mapping\n", " print(\"\\nThe data contains genomic position information (Chr, Position) that could be used\")\n", " print(\"to map SNPs to genes, but this requires external genomic databases.\")\n", " \n", " # Concluding that this is SNP data, not gene expression data\n", " print(\"\\nConclusion: This is SNP genotyping data, not gene expression data.\")\n", " print(\"Traditional gene mapping for expression data is not applicable.\")\n", " print(\"The initial assessment of is_gene_available=True was incorrect.\")\n", " \n", " # Update the gene availability flag\n", " is_gene_available = False\n", " \n", " # Update the metadata to reflect that this is not gene expression data\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", " note=\"Dataset contains SNP data, not gene expression data.\"\n", " )\n", " \n", "except Exception as e:\n", " print(f\"Error processing gene annotation data: {e}\")\n", " is_gene_available = False" ] } ], "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 }