File size: 13,844 Bytes
32677ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e908d9d7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:38:25.999305Z",
     "iopub.status.busy": "2025-03-25T08:38:25.999198Z",
     "iopub.status.idle": "2025-03-25T08:38:26.155674Z",
     "shell.execute_reply": "2025-03-25T08:38:26.155338Z"
    }
   },
   "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 = \"Depression\"\n",
    "cohort = \"GSE273630\"\n",
    "\n",
    "# Input paths\n",
    "in_trait_dir = \"../../input/GEO/Depression\"\n",
    "in_cohort_dir = \"../../input/GEO/Depression/GSE273630\"\n",
    "\n",
    "# Output paths\n",
    "out_data_file = \"../../output/preprocess/Depression/GSE273630.csv\"\n",
    "out_gene_data_file = \"../../output/preprocess/Depression/gene_data/GSE273630.csv\"\n",
    "out_clinical_data_file = \"../../output/preprocess/Depression/clinical_data/GSE273630.csv\"\n",
    "json_path = \"../../output/preprocess/Depression/cohort_info.json\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c92923c1",
   "metadata": {},
   "source": [
    "### Step 1: Initial Data Loading"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "85857f23",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:38:26.156903Z",
     "iopub.status.busy": "2025-03-25T08:38:26.156771Z",
     "iopub.status.idle": "2025-03-25T08:38:26.188986Z",
     "shell.execute_reply": "2025-03-25T08:38:26.188718Z"
    }
   },
   "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": "e63a1c55",
   "metadata": {},
   "source": [
    "### Step 2: Dataset Analysis and Clinical Feature Extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d698b74c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:38:26.190138Z",
     "iopub.status.busy": "2025-03-25T08:38:26.190038Z",
     "iopub.status.idle": "2025-03-25T08:38:26.194946Z",
     "shell.execute_reply": "2025-03-25T08:38:26.194686Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import os\n",
    "from typing import Dict, Any, List, Optional, Callable\n",
    "import json\n",
    "\n",
    "# 1. Determine if this dataset contains gene expression data\n",
    "# Based on the background information, this appears to be a study of gene expression in peripheral blood leukocytes\n",
    "# The Series summary mentions \"dopamine-regulated inflammatory biomarkers\" and a \"digital transcript panel\"\n",
    "# This indicates gene expression data is likely present\n",
    "is_gene_available = True\n",
    "\n",
    "# 2. Variable availability and data type conversion\n",
    "# Analyzing the sample characteristics dictionary\n",
    "# Looking at the provided dictionary, we don't see explicit trait (Depression), age, or gender variables\n",
    "# However, the overall design indicates all participants are males between 35-44 years old\n",
    "# The study focuses on HIV status and Methamphetamine use, not depression\n",
    "\n",
    "# 2.1 Data Availability\n",
    "# No depression trait data is available\n",
    "trait_row = None\n",
    "\n",
    "# Age is not available as a variable (all participants are 35-44 years old per design)\n",
    "age_row = None\n",
    "\n",
    "# Gender is not available as a variable (all participants are males per design)\n",
    "gender_row = None\n",
    "\n",
    "# 2.2 Data Type Conversion\n",
    "# Since trait data (Depression) is not available, we define a placeholder function\n",
    "def convert_trait(value):\n",
    "    return None\n",
    "\n",
    "# Age conversion function (not used but defined for completeness)\n",
    "def convert_age(value):\n",
    "    return None\n",
    "\n",
    "# Gender conversion function (not used but defined for completeness)\n",
    "def convert_gender(value):\n",
    "    return None\n",
    "\n",
    "# 3. Save Metadata\n",
    "# Validate and save the cohort information\n",
    "# Since trait_row is None, is_trait_available is False\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",
    "# 4. Clinical Feature Extraction\n",
    "# We skip this step since trait_row is None, meaning clinical data for our trait is not available\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4392c2c2",
   "metadata": {},
   "source": [
    "### Step 3: Gene Data Extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "58abece7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:38:26.196081Z",
     "iopub.status.busy": "2025-03-25T08:38:26.195975Z",
     "iopub.status.idle": "2025-03-25T08:38:26.213547Z",
     "shell.execute_reply": "2025-03-25T08:38:26.213264Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Matrix file found: ../../input/GEO/Depression/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": "e5fcbe1b",
   "metadata": {},
   "source": [
    "### Step 4: Gene Identifier Review"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7275b72c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:38:26.214677Z",
     "iopub.status.busy": "2025-03-25T08:38:26.214577Z",
     "iopub.status.idle": "2025-03-25T08:38:26.216219Z",
     "shell.execute_reply": "2025-03-25T08:38:26.215953Z"
    }
   },
   "outputs": [],
   "source": [
    "# These identifiers appear to be standard human gene symbols (like ABAT, ABL1, etc.)\n",
    "# They match official HGNC gene symbols, so no mapping is necessary\n",
    "\n",
    "requires_gene_mapping = False\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b180b2d",
   "metadata": {},
   "source": [
    "### Step 5: Data Normalization and Linking"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "fbc15732",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T08:38:26.217316Z",
     "iopub.status.busy": "2025-03-25T08:38:26.217219Z",
     "iopub.status.idle": "2025-03-25T08:38:26.330427Z",
     "shell.execute_reply": "2025-03-25T08:38:26.330015Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Normalized gene data shape: (780, 99)\n",
      "Normalized gene data saved to ../../output/preprocess/Depression/gene_data/GSE273630.csv\n",
      "Skipping clinical-genetic data linking as trait data is not available\n",
      "Dataset usability for trait association studies: False\n"
     ]
    }
   ],
   "source": [
    "# 1. Normalize gene symbols in the gene expression data\n",
    "try:\n",
    "    # Since requires_gene_mapping is False (from step 4), we can use the gene data directly\n",
    "    # Still need to normalize the gene symbols using the NCBI Gene synonym information\n",
    "    normalized_gene_data = normalize_gene_symbols_in_index(gene_data)\n",
    "    print(f\"Normalized gene data shape: {normalized_gene_data.shape}\")\n",
    "    \n",
    "    # Save the normalized gene data\n",
    "    os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)\n",
    "    normalized_gene_data.to_csv(out_gene_data_file)\n",
    "    print(f\"Normalized gene data saved to {out_gene_data_file}\")\n",
    "    \n",
    "    # 2-6. Skip linking clinical and genetic data because trait data is not available\n",
    "    # This was determined in Step 2 (is_trait_available = False)\n",
    "    print(\"Skipping clinical-genetic data linking as trait data is not available\")\n",
    "    \n",
    "    # Use is_final=False since we can't provide required parameters for final validation\n",
    "    is_usable = validate_and_save_cohort_info(\n",
    "        is_final=False,\n",
    "        cohort=cohort,\n",
    "        info_path=json_path,\n",
    "        is_gene_available=True,\n",
    "        is_trait_available=False,\n",
    "        note=\"Dataset contains gene expression data but lacks information about depression. The study focuses on HIV status and methamphetamine use in male participants aged 35-44.\"\n",
    "    )\n",
    "    \n",
    "    print(f\"Dataset usability for trait association studies: {is_usable}\")\n",
    "    \n",
    "except Exception as e:\n",
    "    print(f\"Error processing gene data: {e}\")\n",
    "    # Record that this dataset is not usable\n",
    "    validate_and_save_cohort_info(\n",
    "        is_final=False,\n",
    "        cohort=cohort,\n",
    "        info_path=json_path,\n",
    "        is_gene_available=False,\n",
    "        is_trait_available=False,\n",
    "        note=f\"Error processing gene data: {str(e)}\"\n",
    "    )"
   ]
  }
 ],
 "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
}