{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "ea33696f", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:56:07.184862Z", "iopub.status.busy": "2025-03-25T07:56:07.184459Z", "iopub.status.idle": "2025-03-25T07:56:07.349548Z", "shell.execute_reply": "2025-03-25T07:56:07.349121Z" } }, "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 = \"Lupus_(Systemic_Lupus_Erythematosus)\"\n", "cohort = \"GSE193442\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Lupus_(Systemic_Lupus_Erythematosus)\"\n", "in_cohort_dir = \"../../input/GEO/Lupus_(Systemic_Lupus_Erythematosus)/GSE193442\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Lupus_(Systemic_Lupus_Erythematosus)/GSE193442.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Lupus_(Systemic_Lupus_Erythematosus)/gene_data/GSE193442.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Lupus_(Systemic_Lupus_Erythematosus)/clinical_data/GSE193442.csv\"\n", "json_path = \"../../output/preprocess/Lupus_(Systemic_Lupus_Erythematosus)/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "e5a48629", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "cf0623c8", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:56:07.351220Z", "iopub.status.busy": "2025-03-25T07:56:07.351084Z", "iopub.status.idle": "2025-03-25T07:56:07.439909Z", "shell.execute_reply": "2025-03-25T07:56:07.439436Z" } }, "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": "01f09e30", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "9527f20a", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:56:07.441198Z", "iopub.status.busy": "2025-03-25T07:56:07.441086Z", "iopub.status.idle": "2025-03-25T07:56:07.447669Z", "shell.execute_reply": "2025-03-25T07:56:07.447324Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Analyze the dataset based on the background information and sample characteristics\n", "\n", "# 1. Gene Expression Data Availability\n", "# Based on the series title and sample characteristics, this dataset seems to focus on transcriptional profiling\n", "# of human KIR+ CD8 T cells, which suggests it contains gene expression data.\n", "is_gene_available = True\n", "\n", "# 2. Variable Availability and Data Type Conversion\n", "# 2.1 Data Availability\n", "# From the sample characteristics, we don't see explicit fields for lupus/SLE status, age, or gender\n", "# The dataset appears to be focusing only on cell types rather than patient characteristics\n", "\n", "# For trait (SLE)\n", "# No explicit SLE status is provided in the sample characteristics\n", "trait_row = None # No explicit trait information available\n", "\n", "# For age\n", "# No age information is provided in the sample characteristics\n", "age_row = None # No age information available\n", "\n", "# For gender\n", "# No gender information is provided in the sample characteristics\n", "gender_row = None # No gender information available\n", "\n", "# 2.2 Data Type Conversion\n", "# Since we don't have access to these variables, we'll define placeholder conversion functions\n", "\n", "def convert_trait(value):\n", " # Placeholder function since trait data is not available\n", " if value is None:\n", " return None\n", " \n", " value = value.split(': ')[-1].strip().lower()\n", " if 'lupus' in value or 'sle' in value:\n", " return 1\n", " elif 'control' in value or 'healthy' in value or 'normal' in value:\n", " return 0\n", " else:\n", " return None\n", "\n", "def convert_age(value):\n", " # Placeholder function since age data is not available\n", " if value is None:\n", " return None\n", " \n", " try:\n", " # Extract value after colon and convert to float\n", " age_str = value.split(': ')[-1].strip()\n", " return float(age_str)\n", " except (ValueError, AttributeError):\n", " return None\n", "\n", "def convert_gender(value):\n", " # Placeholder function since gender data is not available\n", " if value is None:\n", " return None\n", " \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", " else:\n", " return None\n", "\n", "# 3. Save Metadata\n", "# Check if trait data is available\n", "is_trait_available = trait_row is not None\n", "\n", "# Save the initial filtering result\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. Since trait_row is None, we skip the clinical feature extraction step\n" ] }, { "cell_type": "markdown", "id": "4f35d3f2", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "d51a12ed", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T07:56:07.448860Z", "iopub.status.busy": "2025-03-25T07:56:07.448757Z", "iopub.status.idle": "2025-03-25T07:56:07.992086Z", "shell.execute_reply": "2025-03-25T07:56:07.991423Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "This appears to be a SuperSeries. Looking at the SOFT file to find potential subseries:\n", "No subseries references found in the first 1000 lines of the SOFT file.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Gene data extraction result:\n", "Number of rows: 0\n", "First 20 gene/probe identifiers:\n", "Index([], dtype='object', name='ID')\n" ] } ], "source": [ "# 1. First get the path to the soft and matrix files\n", "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n", "\n", "# 2. Looking more carefully at the background information\n", "# This is a SuperSeries which doesn't contain direct gene expression data\n", "# Need to investigate the soft file to find the subseries\n", "print(\"This appears to be a SuperSeries. Looking at the SOFT file to find potential subseries:\")\n", "\n", "# Open the SOFT file to try to identify subseries\n", "with gzip.open(soft_file, 'rt') as f:\n", " subseries_lines = []\n", " for i, line in enumerate(f):\n", " if 'Series_relation' in line and 'SuperSeries of' in line:\n", " subseries_lines.append(line.strip())\n", " if i > 1000: # Limit search to first 1000 lines\n", " break\n", "\n", "# Display the subseries found\n", "if subseries_lines:\n", " print(\"Found potential subseries references:\")\n", " for line in subseries_lines:\n", " print(line)\n", "else:\n", " print(\"No subseries references found in the first 1000 lines of the SOFT file.\")\n", "\n", "# Despite trying to extract gene data, we expect it might fail because this is a SuperSeries\n", "try:\n", " gene_data = get_genetic_data(matrix_file)\n", " print(\"\\nGene data extraction result:\")\n", " print(\"Number of rows:\", len(gene_data))\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", " print(\"This confirms the dataset is a SuperSeries without direct gene expression data.\")" ] } ], "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 }