File size: 6,699 Bytes
6bc7e45 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
{
"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
}
|