File size: 14,410 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
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
356
357
358
359
360
361
362
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ac10222c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:23:05.927969Z",
     "iopub.status.busy": "2025-03-25T06:23:05.927750Z",
     "iopub.status.idle": "2025-03-25T06:23:06.097756Z",
     "shell.execute_reply": "2025-03-25T06:23:06.097386Z"
    }
   },
   "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 = \"Age-Related_Macular_Degeneration\"\n",
    "cohort = \"GSE67899\"\n",
    "\n",
    "# Input paths\n",
    "in_trait_dir = \"../../input/GEO/Age-Related_Macular_Degeneration\"\n",
    "in_cohort_dir = \"../../input/GEO/Age-Related_Macular_Degeneration/GSE67899\"\n",
    "\n",
    "# Output paths\n",
    "out_data_file = \"../../output/preprocess/Age-Related_Macular_Degeneration/GSE67899.csv\"\n",
    "out_gene_data_file = \"../../output/preprocess/Age-Related_Macular_Degeneration/gene_data/GSE67899.csv\"\n",
    "out_clinical_data_file = \"../../output/preprocess/Age-Related_Macular_Degeneration/clinical_data/GSE67899.csv\"\n",
    "json_path = \"../../output/preprocess/Age-Related_Macular_Degeneration/cohort_info.json\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "78a18157",
   "metadata": {},
   "source": [
    "### Step 1: Initial Data Loading"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2f92248e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:23:06.099141Z",
     "iopub.status.busy": "2025-03-25T06:23:06.098991Z",
     "iopub.status.idle": "2025-03-25T06:23:06.196319Z",
     "shell.execute_reply": "2025-03-25T06:23:06.196012Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Background Information:\n",
      "!Series_title\t\"Delay and restoration of persistent wound-induced retinal pigmented epithelial-to-mesenchymal transition by TGF-beta pathway inhibitors: Implications for age-related macular degeneration\"\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: ['donor id: hfRPE-020207-2', 'donor id: hfRPE-071709', 'donor id: hfRPE-081309', 'donor id: hfRPE-111109'], 1: ['plating density: 4,000 cells/cm2', 'plating density: 80,000 cells/cm2'], 2: ['passage number: 0', 'passage number: 5'], 3: ['culture time: 3 Days', 'culture time: 16 Days', 'culture time: 32 Days', 'culture time: 64 Days'], 4: ['cultureware: T75-Flask', 'cultureware: Micropourous Membrane', 'cultureware: 6-well Multiwell Plate'], 5: ['treatment: None', 'treatment: DMSO', 'treatment: 2 ng/ml FGF2', 'treatment: 500 nM A83-01', 'treatment: 500 nM A83-01 + 2ng FGF', 'treatment: 500 nM Thiazovivin', 'treatment: 500 nM Thiazovivin + 2ng FGF', 'treatment: 200 nM LDN193189', 'treatment: 200 nM LDN193189 + 2ng FGF', 'treatment: 5 mM XAV939', 'treatment: 5 mM XAV939 + 2ng FGF']}\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": "22385422",
   "metadata": {},
   "source": [
    "### Step 2: Dataset Analysis and Clinical Feature Extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "56a70fe3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:23:06.197712Z",
     "iopub.status.busy": "2025-03-25T06:23:06.197601Z",
     "iopub.status.idle": "2025-03-25T06:23:06.205405Z",
     "shell.execute_reply": "2025-03-25T06:23:06.205100Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preview of selected clinical features:\n",
      "{'Sample_1': [0.0], 'Sample_2': [0.0], 'Sample_3': [1.0], 'Sample_4': [1.0], 'Sample_5': [1.0], 'Sample_6': [1.0], 'Sample_7': [1.0], 'Sample_8': [1.0], 'Sample_9': [1.0], 'Sample_10': [1.0], 'Sample_11': [1.0]}\n",
      "Clinical data saved to ../../output/preprocess/Age-Related_Macular_Degeneration/clinical_data/GSE67899.csv\n"
     ]
    }
   ],
   "source": [
    "# 1. Gene Expression Data Availability\n",
    "# Based on the series title and summary, this dataset seems to focus on RPE cells and the TGF-beta pathway\n",
    "# It appears to contain gene expression data related to AMD\n",
    "is_gene_available = True\n",
    "\n",
    "# 2.1 Data Availability\n",
    "# After analyzing the sample characteristics dictionary, I see:\n",
    "# - No direct trait classification (AMD vs control) is provided\n",
    "# - No age information\n",
    "# - No gender information\n",
    "# The dataset appears to be about cell culture experiments rather than human subjects directly\n",
    "\n",
    "# The treatment key (index 5) seems to contain information about various treatments \n",
    "# which could be used to infer disease vs. control conditions\n",
    "trait_row = 5  # Using treatment as proxy for trait\n",
    "age_row = None  # No age data available\n",
    "gender_row = None  # No gender data available\n",
    "\n",
    "# 2.2 Data Type Conversion\n",
    "def convert_trait(value):\n",
    "    \"\"\"\n",
    "    Convert treatment information to binary where:\n",
    "    0 = control condition (None or DMSO)\n",
    "    1 = treatment condition (any treatment agent)\n",
    "    \"\"\"\n",
    "    if value is None:\n",
    "        return None\n",
    "    \n",
    "    # Extract value after colon if present\n",
    "    if ':' in value:\n",
    "        value = value.split(':', 1)[1].strip()\n",
    "    \n",
    "    # Control conditions\n",
    "    if value in ['None', 'DMSO']:\n",
    "        return 0\n",
    "    # Treatment conditions (any other treatment)\n",
    "    else:\n",
    "        return 1\n",
    "\n",
    "# No conversion functions needed for age and gender as they're not available\n",
    "convert_age = None\n",
    "convert_gender = None\n",
    "\n",
    "# 3. Save Metadata\n",
    "# The trait is available (inferred from treatment data)\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",
    "if trait_row is not None:\n",
    "    import pandas as pd\n",
    "    import os\n",
    "    \n",
    "    # Create a transposed DataFrame that geo_select_clinical_features can process\n",
    "    # In this format, rows are feature types and columns are samples\n",
    "    # For this dataset, we don't have sample-by-sample data, so we'll create a synthetic version\n",
    "    # based on the unique values in the sample characteristics\n",
    "    \n",
    "    # Create a mock samples dataframe where each unique treatment gets a sample\n",
    "    sample_chars_dict = {0: ['donor id: hfRPE-020207-2', 'donor id: hfRPE-071709', 'donor id: hfRPE-081309', 'donor id: hfRPE-111109'], \n",
    "                        1: ['plating density: 4,000 cells/cm2', 'plating density: 80,000 cells/cm2'], \n",
    "                        2: ['passage number: 0', 'passage number: 5'], \n",
    "                        3: ['culture time: 3 Days', 'culture time: 16 Days', 'culture time: 32 Days', 'culture time: 64 Days'], \n",
    "                        4: ['cultureware: T75-Flask', 'cultureware: Micropourous Membrane', 'cultureware: 6-well Multiwell Plate'], \n",
    "                        5: ['treatment: None', 'treatment: DMSO', 'treatment: 2 ng/ml FGF2', 'treatment: 500 nM A83-01', 'treatment: 500 nM A83-01 + 2ng FGF', \n",
    "                            'treatment: 500 nM Thiazovivin', 'treatment: 500 nM Thiazovivin + 2ng FGF', 'treatment: 200 nM LDN193189', \n",
    "                            'treatment: 200 nM LDN193189 + 2ng FGF', 'treatment: 5 mM XAV939', 'treatment: 5 mM XAV939 + 2ng FGF']}\n",
    "    \n",
    "    # Extract the treatments (trait values) to use as samples\n",
    "    treatments = sample_chars_dict[trait_row]\n",
    "    \n",
    "    # Create sample columns\n",
    "    sample_ids = [f\"Sample_{i+1}\" for i in range(len(treatments))]\n",
    "    \n",
    "    # Create a dataframe with feature types as rows and samples as columns\n",
    "    data = {}\n",
    "    for i, sample_id in enumerate(sample_ids):\n",
    "        data[sample_id] = [None] * 6  # 6 feature types (0-5)\n",
    "        data[sample_id][trait_row] = treatments[i]  # Only set the treatment\n",
    "    \n",
    "    # Create the clinical dataframe in transposed format\n",
    "    clinical_data = pd.DataFrame(data)\n",
    "    \n",
    "    # Extract clinical features\n",
    "    selected_clinical_df = geo_select_clinical_features(\n",
    "        clinical_df=clinical_data,\n",
    "        trait=\"Treatment\",  # Using \"Treatment\" as the trait name\n",
    "        trait_row=trait_row,\n",
    "        convert_trait=convert_trait,\n",
    "        age_row=age_row,\n",
    "        convert_age=convert_age,\n",
    "        gender_row=gender_row,\n",
    "        convert_gender=convert_gender\n",
    "    )\n",
    "    \n",
    "    # Preview the selected clinical features\n",
    "    preview = preview_df(selected_clinical_df)\n",
    "    print(\"Preview of selected clinical features:\")\n",
    "    print(preview)\n",
    "    \n",
    "    # Save the clinical data\n",
    "    os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)\n",
    "    selected_clinical_df.to_csv(out_clinical_data_file, index=False)\n",
    "    print(f\"Clinical data saved to {out_clinical_data_file}\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5121070c",
   "metadata": {},
   "source": [
    "### Step 3: Gene Data Extraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "abdd1c77",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:23:06.206619Z",
     "iopub.status.busy": "2025-03-25T06:23:06.206513Z",
     "iopub.status.idle": "2025-03-25T06:23:06.329980Z",
     "shell.execute_reply": "2025-03-25T06:23:06.329632Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "First 20 gene/probe identifiers:\n",
      "Index(['12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23',\n",
      "       '24', '26', '27', '28', '29', '30', '31', '32'],\n",
      "      dtype='object', name='ID')\n"
     ]
    }
   ],
   "source": [
    "# 1. First get the file paths again to access the matrix file\n",
    "soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)\n",
    "\n",
    "# 2. Use the get_genetic_data function from the library to get the gene_data from the matrix_file\n",
    "gene_data = get_genetic_data(matrix_file)\n",
    "\n",
    "# 3. Print the first 20 row IDs (gene or probe identifiers) for future observation\n",
    "print(\"First 20 gene/probe identifiers:\")\n",
    "print(gene_data.index[:20])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "680ec474",
   "metadata": {},
   "source": [
    "### Step 4: Gene Identifier Review"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a2c1843e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-03-25T06:23:06.331401Z",
     "iopub.status.busy": "2025-03-25T06:23:06.331277Z",
     "iopub.status.idle": "2025-03-25T06:23:06.333289Z",
     "shell.execute_reply": "2025-03-25T06:23:06.332995Z"
    }
   },
   "outputs": [],
   "source": [
    "# Based on the provided identifiers, I can see these are numeric values like '12', '13', '14', etc.\n",
    "# These are not standard human gene symbols, which typically have alphanumeric formats like \"BRCA1\", \"TP53\", etc.\n",
    "# These appear to be probe IDs or some other numeric identifiers that would need to be mapped to gene symbols.\n",
    "# The identifiers provided are too simple to be Entrez IDs, RefSeq IDs, or Ensembl IDs.\n",
    "# They require mapping to proper gene symbols before meaningful analysis.\n",
    "\n",
    "requires_gene_mapping = True\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5e10e252",
   "metadata": {},
   "source": [
    "### Step 5: Gene Annotation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "430ba2a7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "4affe331",
   "metadata": {},
   "source": [
    "### Step 6: Gene Identifier Mapping"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6c66a7bd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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
}