{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "475d6297", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:56:42.339189Z", "iopub.status.busy": "2025-03-25T03:56:42.339063Z", "iopub.status.idle": "2025-03-25T03:56:42.507683Z", "shell.execute_reply": "2025-03-25T03:56:42.507318Z" } }, "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 = \"Schizophrenia\"\n", "cohort = \"GSE273630\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Schizophrenia\"\n", "in_cohort_dir = \"../../input/GEO/Schizophrenia/GSE273630\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Schizophrenia/GSE273630.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Schizophrenia/gene_data/GSE273630.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Schizophrenia/clinical_data/GSE273630.csv\"\n", "json_path = \"../../output/preprocess/Schizophrenia/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "cba0fd57", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "f368ceed", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:56:42.509176Z", "iopub.status.busy": "2025-03-25T03:56:42.509023Z", "iopub.status.idle": "2025-03-25T03:56:42.518541Z", "shell.execute_reply": "2025-03-25T03:56:42.518186Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Background Information:\n", "!Series_title\t\"Dopamine-regulated biomarkers in peripheral blood of HIV+ Methamphetamine users\"\n", "!Series_summary\t\"HIV and Methamphetamine study - Translational Methamphetamine AIDS Research Center - Dopamine-regulated inflammatory biomarkers\"\n", "!Series_summary\t\"A digital transcript panel was custom-made based on Hs_NeuroPath_v1 (Nanostring) to accommodate dopamine-regulated inflammatory genes that were previously identified in vitro, and hypothesized to cluster HIV+ Methamphetamine users.\"\n", "!Series_overall_design\t\"Specimens were peripheral blood leukocytes isolated from participants that included adults enrolled by NIH-funded studies at the University of California San Diego’s HIV Neurobehavioral Research Program (HNRP) and Translational Methamphetamine Research Center (TMARC) under informed consent and approved protocols. The subset of PWH and PWoH selected for this study were by design males, between 35 – 44 years old, due to cohort characteristics and to increase statistical power. The participants were divided based on HIV serostatus (HIV+/-) and Meth use (METH+/-). METH+ was defined as meeting lifetime DSM-IV criteria for methamphetamine use or dependence, and METH dependence or abuse within 18 months (LT Methamphetamine Dx), with 8.2% urine toxicology positive/current METH users. A cross-sectional design assembled the following groups: HIV-METH- , HIV+METH- , HIV-METH+ , and HIV+METH+. Exclusion criteria were a history of non-HIV-related neurological, medical, or psychiatric disorders that affect brain function (e.g., schizophrenia, traumatic brain injury, epilepsy), learning disabilities, or dementia.\"\n", "Sample Characteristics Dictionary:\n", "{0: ['tissue: Peripheral blood cells']}\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": "24d369d0", "metadata": {}, "source": [ "### Step 2: Dataset Analysis and Clinical Feature Extraction" ] }, { "cell_type": "code", "execution_count": 3, "id": "f9e3c56c", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:56:42.519635Z", "iopub.status.busy": "2025-03-25T03:56:42.519528Z", "iopub.status.idle": "2025-03-25T03:56:42.524608Z", "shell.execute_reply": "2025-03-25T03:56:42.524333Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "import os\n", "import json\n", "from typing import Callable, Optional, Dict, Any\n", "\n", "# Check gene expression data availability\n", "is_gene_available = False # Based on information, this seems to be a targeted panel of dopamine-regulated genes, not full gene expression\n", "\n", "# Check trait, age, and gender data availability\n", "# From the background information, we can infer:\n", "# - Participants are divided based on HIV and Meth use status\n", "# - All participants are males between 35-44 years old\n", "\n", "trait_row = None # The trait (schizophrenia) is not available in this dataset\n", "age_row = None # Age is constant (35-44 years) so not useful for association study\n", "gender_row = None # Gender is constant (all males) so not useful for association study\n", "\n", "# Define conversion functions\n", "def convert_trait(value: str) -> Optional[int]:\n", " # Not needed as trait data isn't available\n", " return None\n", "\n", "def convert_age(value: str) -> Optional[float]:\n", " # Not needed as age data isn't available\n", " return None\n", "\n", "def convert_gender(value: str) -> Optional[int]:\n", " # Not needed as gender data isn't available\n", " return None\n", "\n", "# Save metadata about dataset usability\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", "# We skip clinical feature extraction since trait_row is None\n" ] }, { "cell_type": "markdown", "id": "ae5a818a", "metadata": {}, "source": [ "### Step 3: Gene Data Extraction" ] }, { "cell_type": "code", "execution_count": 4, "id": "0c68bc27", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:56:42.525615Z", "iopub.status.busy": "2025-03-25T03:56:42.525512Z", "iopub.status.idle": "2025-03-25T03:56:42.544309Z", "shell.execute_reply": "2025-03-25T03:56:42.544006Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matrix file found: ../../input/GEO/Schizophrenia/GSE273630/GSE273630_series_matrix.txt.gz\n", "Gene data shape: (780, 99)\n", "First 20 gene/probe identifiers:\n", "Index(['ABAT', 'ABL1', 'ACAA1', 'ACHE', 'ACIN1', 'ACTN1', 'ACVRL1', 'ADAM10',\n", " 'ADCY5', 'ADCY8', 'ADCY9', 'ADCYAP1', 'ADORA1', 'ADORA2A', 'ADRA2A',\n", " 'ADRB2', 'AGER', 'AIF1', 'AKT1', 'AKT1S1'],\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": "fcf55a7a", "metadata": {}, "source": [ "### Step 4: Gene Identifier Review" ] }, { "cell_type": "code", "execution_count": 5, "id": "0914f257", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:56:42.545342Z", "iopub.status.busy": "2025-03-25T03:56:42.545238Z", "iopub.status.idle": "2025-03-25T03:56:42.546978Z", "shell.execute_reply": "2025-03-25T03:56:42.546704Z" } }, "outputs": [], "source": [ "# Based on the gene identifiers observed, these appear to be human gene symbols.\n", "# They follow standard HGNC gene symbol nomenclature (e.g., ABAT, ABL1, ACAA1).\n", "# These are official gene symbols, not probe IDs which would typically be numerical or have a different format.\n", "\n", "requires_gene_mapping = False\n" ] }, { "cell_type": "markdown", "id": "4f9163db", "metadata": {}, "source": [ "### Step 5: Data Normalization and Linking" ] }, { "cell_type": "code", "execution_count": 6, "id": "5328c635", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T03:56:42.547977Z", "iopub.status.busy": "2025-03-25T03:56:42.547875Z", "iopub.status.idle": "2025-03-25T03:56:42.668580Z", "shell.execute_reply": "2025-03-25T03:56:42.668227Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Gene data shape after normalization: (780, 99)\n", "Normalized gene expression data saved to ../../output/preprocess/Schizophrenia/gene_data/GSE273630.csv\n", "Clinical data for the trait 'Schizophrenia' is not available in this dataset.\n", "This dataset (GSE273630) contains information about HIV and Methamphetamine use, not Schizophrenia.\n", "Abnormality detected in the cohort: GSE273630. Preprocessing failed.\n", "Dataset is not usable for Schizophrenia analysis. No linked data file saved.\n" ] } ], "source": [ "# 1. Normalize gene symbols in the gene expression data\n", "gene_data = normalize_gene_symbols_in_index(gene_data)\n", "print(f\"Gene data shape after normalization: {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", "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 trait_row is None (no schizophrenia data available),\n", "# we cannot create proper clinical data for this trait\n", "print(\"Clinical data for the trait 'Schizophrenia' is not available in this dataset.\")\n", "\n", "# The dataset is about HIV and Methamphetamine use, not Schizophrenia\n", "print(\"This dataset (GSE273630) contains information about HIV and Methamphetamine use, not Schizophrenia.\")\n", "\n", "# Create an empty DataFrame to represent the missing clinical data\n", "empty_df = pd.DataFrame()\n", "\n", "# 5. Validate and save cohort information - mark as not usable for the trait\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, # No trait data for Schizophrenia\n", " is_biased=True, # Set to True to indicate an unusable dataset for this trait\n", " df=empty_df, # Empty DataFrame as there's no linked data\n", " note=\"Dataset contains gene expression from HIV and Methamphetamine users. No Schizophrenia data available.\"\n", ")\n", "\n", "print(\"Dataset is not usable for Schizophrenia analysis. No linked data file 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 }