{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "83439ddb", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:23:12.760599Z", "iopub.status.busy": "2025-03-25T06:23:12.760212Z", "iopub.status.idle": "2025-03-25T06:23:12.931670Z", "shell.execute_reply": "2025-03-25T06:23:12.931230Z" } }, "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 = \"Allergies\"\n", "cohort = \"GSE184382\"\n", "\n", "# Input paths\n", "in_trait_dir = \"../../input/GEO/Allergies\"\n", "in_cohort_dir = \"../../input/GEO/Allergies/GSE184382\"\n", "\n", "# Output paths\n", "out_data_file = \"../../output/preprocess/Allergies/GSE184382.csv\"\n", "out_gene_data_file = \"../../output/preprocess/Allergies/gene_data/GSE184382.csv\"\n", "out_clinical_data_file = \"../../output/preprocess/Allergies/clinical_data/GSE184382.csv\"\n", "json_path = \"../../output/preprocess/Allergies/cohort_info.json\"\n" ] }, { "cell_type": "markdown", "id": "b11688ef", "metadata": {}, "source": [ "### Step 1: Initial Data Loading" ] }, { "cell_type": "code", "execution_count": 2, "id": "e9dad0a2", "metadata": { "execution": { "iopub.execute_input": "2025-03-25T06:23:12.932961Z", "iopub.status.busy": "2025-03-25T06:23:12.932811Z", "iopub.status.idle": "2025-03-25T06:23:12.961239Z", "shell.execute_reply": "2025-03-25T06:23:12.960845Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Files in trait directory ../../input/GEO/Allergies:\n", "['GSE169149', 'GSE182740', 'GSE184382', 'GSE185658', 'GSE192454', 'GSE203196', 'GSE203409', 'GSE205151', 'GSE230164', 'GSE270312', 'GSE84046']\n", "\n", "Potential cohort paths containing 'GSE184382':\n", "../../input/GEO/Allergies/GSE184382\n", " Contents: []\n", "\n", "Looking for files in trait directory that might be relevant to this cohort:\n", "Found 0 files for cohort GSE184382: []\n", "No files found for cohort GSE184382. Cannot proceed with preprocessing.\n" ] } ], "source": [ "# 1. Check what files are actually in the directory\n", "import os\n", "\n", "# Check the parent directory (trait directory) in case cohort is a subdirectory\n", "print(f\"Files in trait directory {in_trait_dir}:\")\n", "trait_dir_files = os.listdir(in_trait_dir)\n", "print(trait_dir_files)\n", "\n", "# Search for the cohort data in the parent directory\n", "potential_cohort_paths = []\n", "for item in trait_dir_files:\n", " if cohort in item:\n", " potential_cohort_paths.append(os.path.join(in_trait_dir, item))\n", "\n", "print(f\"\\nPotential cohort paths containing '{cohort}':\")\n", "for path in potential_cohort_paths:\n", " print(path)\n", " if os.path.isdir(path):\n", " print(f\" Contents: {os.listdir(path)}\")\n", "\n", "# Try to find files directly in the trait directory that might match this cohort\n", "print(\"\\nLooking for files in trait directory that might be relevant to this cohort:\")\n", "cohort_files = []\n", "for file in trait_dir_files:\n", " if cohort in file and os.path.isfile(os.path.join(in_trait_dir, file)):\n", " cohort_files.append(file)\n", " \n", "print(f\"Found {len(cohort_files)} files for cohort {cohort}: {cohort_files}\")\n", "\n", "# If we found cohort files, use the first file that looks like a matrix or SOFT file\n", "if cohort_files:\n", " # Sort files to prioritize SOFT or matrix files\n", " soft_files = [f for f in cohort_files if 'soft' in f.lower()]\n", " matrix_files = [f for f in cohort_files if 'matrix' in f.lower() or 'series' in f.lower()]\n", " \n", " if soft_files:\n", " soft_file = os.path.join(in_trait_dir, soft_files[0])\n", " print(f\"Using soft file: {soft_file}\")\n", " else:\n", " print(\"No soft file found directly.\")\n", " soft_file = None\n", " \n", " if matrix_files:\n", " matrix_file = os.path.join(in_trait_dir, matrix_files[0])\n", " print(f\"Using matrix file: {matrix_file}\")\n", " else:\n", " print(\"No matrix file found directly.\")\n", " # If no clear matrix file, use the first file as a fallback\n", " matrix_file = os.path.join(in_trait_dir, cohort_files[0])\n", " print(f\"Using fallback file for matrix: {matrix_file}\")\n", " \n", " # 2. Read the matrix file to obtain background information and sample characteristics data\n", " try:\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(\"\\nBackground Information:\")\n", " print(background_info)\n", " print(\"\\nSample Characteristics Dictionary:\")\n", " print(sample_characteristics_dict)\n", " except Exception as e:\n", " print(f\"Error processing file: {e}\")\n", "else:\n", " print(f\"No files found for cohort {cohort}. Cannot proceed with preprocessing.\")\n", " \n", " # Set variables to allow code to continue without errors\n", " background_info = \"No background information available\"\n", " clinical_data = pd.DataFrame()\n", " sample_characteristics_dict = {}" ] } ], "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 }