{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "00e4f3d7", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:01:29.869287Z", "iopub.status.busy": "2025-03-25T08:01:29.869184Z", "iopub.status.idle": "2025-03-25T08:01:30.026608Z", "shell.execute_reply": "2025-03-25T08:01:30.026169Z" } }, "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 = \"Celiac_Disease\"\n", "cohort = \"GSE193442\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Celiac_Disease\"\n", "in_cohort_dir = \"../../input/GEO/Celiac_Disease/GSE193442\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Celiac_Disease/GSE193442.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Celiac_Disease/gene_data/GSE193442.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Celiac_Disease/clinical_data/GSE193442.csv\"\n", "json_path = \"../../output/preprocess/Celiac_Disease/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "cc05f891", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "09044629", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:01:30.027907Z", "iopub.status.busy": "2025-03-25T08:01:30.027763Z", "iopub.status.idle": "2025-03-25T08:01:30.114411Z", "shell.execute_reply": "2025-03-25T08:01:30.113907Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Transcriptional profiling of human KIR+ CD8 T cells\"\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: ['tissue: PBMC'], 1: ['cell type: KIR+ CD8 T']}\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": "70766a65", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "12bf9605", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:01:30.115961Z", "iopub.status.busy": "2025-03-25T08:01:30.115848Z", "iopub.status.idle": "2025-03-25T08:01:30.122441Z", "shell.execute_reply": "2025-03-25T08:01:30.122016Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 1. Gene Expression Data Availability\n", "# Based on the background information, this seems to be a dataset about transcriptional profiling\n", "# which suggests gene expression data is likely available\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# From the sample characteristics dictionary, we don't see any clear indicators of \n", "# celiac disease status, age, or gender information\n", "\n", "# For trait (Celiac Disease)\n", "trait_row = None # Not available in the sample characteristics\n", "\n", "# For age\n", "age_row = None # Not available in the sample characteristics\n", "\n", "# For gender\n", "gender_row = None # Not available in the sample characteristics\n", "\n", "# Define conversion functions even though they won't be used in this case\n", "def convert_trait(value):\n", " if value is None:\n", " return None\n", " value = value.split(\": \")[-1].strip().lower()\n", " if \"celiac\" in value or \"coeliac\" in value:\n", " return 1\n", " elif \"control\" in value or \"healthy\" in value or \"normal\" 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 the numeric part after colon\n", " age_str = value.split(\": \")[-1].strip()\n", " # Try to convert to float\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.split(\": \")[-1].strip().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", "# Determine if trait data is available\n", "is_trait_available = trait_row is not None\n", "\n", "# Conduct initial filtering and save cohort information\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, we should skip this substep\n" ] }, { "cell_type": "markdown", "id": "ab9d81ad", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": null, "id": "25c9fb63", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "d67ee105", "metadata": {}, "source": [ "### Step 4: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "3b64f1ff", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T08:01:30.123959Z", "iopub.status.busy": "2025-03-25T08:01:30.123856Z", "iopub.status.idle": "2025-03-25T08:01:30.181234Z", "shell.execute_reply": "2025-03-25T08:01:30.180778Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matrix file found: ../../input/GEO/Celiac_Disease/GSE193442/GSE193442-GPL18573_series_matrix.txt.gz\n", "This dataset is a SuperSeries, which is a collection of related datasets rather than containing gene expression data directly.\n", "A SuperSeries typically doesn't contain the actual gene data, but rather references to SubSeries that contain the data.\n", "\n", "Checking for SubSeries information in the SOFT file...\n", "Found SubSeries information:\n", " !Series_relation = SuperSeries of: GSE168527\n", " !Series_relation = SuperSeries of: GSE193439\n", " !Series_relation = SuperSeries of: GSE193770\n", "\n", "This SuperSeries doesn't contain gene expression data directly.\n", "To process gene expression data, you would need to:\n", "1. Identify the relevant SubSeries\n", "2. Download and process those individual datasets separately\n", "3. Combine the results as needed for your analysis\n", "\n", "Gene data shape: (0, 0)\n", "First 20 gene/probe identifiers:\n", "Index([], dtype='object', name='ID')\n", "\n", "Based on this analysis, is_gene_available should be set to False for this dataset.\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. Check the file to understand its structure\n", "print(\"This dataset is a SuperSeries, which is a collection of related datasets rather than containing gene expression data directly.\")\n", "print(\"A SuperSeries typically doesn't contain the actual gene data, but rather references to SubSeries that contain the data.\")\n", "\n", "# 3. Look for subseries information in the SOFT file\n", "print(\"\\nChecking for SubSeries information in the SOFT file...\")\n", "try:\n", " with gzip.open(soft_file, 'rt') as f:\n", " subseries_lines = []\n", " for line in f:\n", " if \"!Series_relation\" in line and \"SuperSeries of:\" in line:\n", " subseries_lines.append(line.strip())\n", " # Also look for subseries IDs directly\n", " elif \"SubSeries\" in line and \"GSE\" in line:\n", " subseries_lines.append(line.strip())\n", " \n", " if subseries_lines:\n", " print(\"Found SubSeries information:\")\n", " for line in subseries_lines[:10]: # Show up to 10 subseries\n", " print(f\" {line}\")\n", " if len(subseries_lines) > 10:\n", " print(f\" ...and {len(subseries_lines) - 10} more\")\n", " else:\n", " print(\"No explicit SubSeries information found in SOFT file.\")\n", "except Exception as e:\n", " print(f\"Error reading SOFT file: {e}\")\n", "\n", "# 4. Since this is a SuperSeries without direct gene data, we need to set is_gene_available to False\n", "print(\"\\nThis SuperSeries doesn't contain gene expression data directly.\")\n", "print(\"To process gene expression data, you would need to:\")\n", "print(\"1. Identify the relevant SubSeries\")\n", "print(\"2. Download and process those individual datasets separately\")\n", "print(\"3. Combine the results as needed for your analysis\")\n", "\n", "# Set empty gene_data similar to what get_genetic_data returns for compatibility\n", "import pandas as pd\n", "gene_data = pd.DataFrame(index=pd.Index([], name='ID'))\n", "print(f\"\\nGene data shape: {gene_data.shape}\")\n", "print(\"First 20 gene/probe identifiers:\")\n", "print(gene_data.index[:20])\n", "\n", "# 5. Update the is_gene_available flag for step 2\n", "print(\"\\nBased on this analysis, is_gene_available should be set to False for this dataset.\")" ] } ], "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 }