File size: 11,863 Bytes
53eb596 |
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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
{
"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
}
|