Liu-Hy commited on
Commit
a568759
·
verified ·
1 Parent(s): a24f460

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +16 -0
  2. p1/preprocess/Hypothyroidism/TCGA.csv +3 -0
  3. p1/preprocess/Hypothyroidism/gene_data/TCGA.csv +3 -0
  4. p1/preprocess/Kidney_Papillary_Cell_Carcinoma/TCGA.csv +3 -0
  5. p1/preprocess/LDL_Cholesterol_Levels/gene_data/GSE28893.csv +3 -0
  6. p1/preprocess/Large_B-cell_Lymphoma/gene_data/GSE159472.csv +3 -0
  7. p1/preprocess/Liver_Cancer/GSE164760.csv +3 -0
  8. p1/preprocess/Liver_Cancer/GSE178201.csv +3 -0
  9. p1/preprocess/Liver_Cancer/GSE228783.csv +3 -0
  10. p1/preprocess/Liver_Cancer/code/GSE228783.py +164 -0
  11. p1/preprocess/Liver_Cancer/gene_data/GSE164760.csv +3 -0
  12. p1/preprocess/Liver_Cancer/gene_data/GSE174570.csv +3 -0
  13. p1/preprocess/Liver_Cancer/gene_data/GSE178201.csv +3 -0
  14. p1/preprocess/Liver_Cancer/gene_data/GSE228782.csv +3 -0
  15. p1/preprocess/Liver_Cancer/gene_data/GSE228783.csv +3 -0
  16. p1/preprocess/Liver_Cancer/gene_data/GSE45032.csv +0 -0
  17. p1/preprocess/Liver_Cancer/gene_data/GSE66843.csv +0 -0
  18. p1/preprocess/Liver_cirrhosis/GSE139602.csv +0 -0
  19. p1/preprocess/Liver_cirrhosis/GSE163211.csv +0 -0
  20. p1/preprocess/Liver_cirrhosis/GSE285291.csv +0 -0
  21. p1/preprocess/Liver_cirrhosis/clinical_data/GSE139602.csv +2 -0
  22. p1/preprocess/Liver_cirrhosis/clinical_data/GSE163211.csv +4 -0
  23. p1/preprocess/Liver_cirrhosis/clinical_data/GSE285291.csv +2 -0
  24. p1/preprocess/Liver_cirrhosis/code/GSE139602.py +186 -0
  25. p1/preprocess/Liver_cirrhosis/code/GSE150734.py +75 -0
  26. p1/preprocess/Liver_cirrhosis/code/GSE163211.py +167 -0
  27. p1/preprocess/Liver_cirrhosis/code/GSE182060.py +73 -0
  28. p1/preprocess/Liver_cirrhosis/code/GSE182065.py +141 -0
  29. p1/preprocess/Liver_cirrhosis/code/GSE185529.py +73 -0
  30. p1/preprocess/Liver_cirrhosis/code/GSE212047.py +189 -0
  31. p1/preprocess/Liver_cirrhosis/code/GSE285291.py +157 -0
  32. p1/preprocess/Liver_cirrhosis/code/GSE66843.py +159 -0
  33. p1/preprocess/Liver_cirrhosis/code/GSE85550.py +135 -0
  34. p1/preprocess/Liver_cirrhosis/code/TCGA.py +138 -0
  35. p1/preprocess/Liver_cirrhosis/cohort_info.json +1 -0
  36. p1/preprocess/Liver_cirrhosis/gene_data/GSE139602.csv +0 -0
  37. p1/preprocess/Liver_cirrhosis/gene_data/GSE163211.csv +0 -0
  38. p1/preprocess/Liver_cirrhosis/gene_data/GSE285291.csv +0 -0
  39. p1/preprocess/Longevity/GSE48264.csv +3 -0
  40. p1/preprocess/Longevity/clinical_data/GSE16717.csv +4 -0
  41. p1/preprocess/Longevity/clinical_data/GSE48264.csv +2 -0
  42. p1/preprocess/Longevity/code/GSE16717.py +215 -0
  43. p1/preprocess/Longevity/code/GSE44147.py +212 -0
  44. p1/preprocess/Longevity/code/GSE48264.py +205 -0
  45. p1/preprocess/Longevity/code/TCGA.py +70 -0
  46. p1/preprocess/Longevity/cohort_info.json +1 -0
  47. p1/preprocess/Longevity/gene_data/GSE16717.csv +1 -0
  48. p1/preprocess/Longevity/gene_data/GSE48264.csv +3 -0
  49. p1/preprocess/Lower_Grade_Glioma/GSE24072.csv +0 -0
  50. p1/preprocess/Lower_Grade_Glioma/clinical_data/GSE24072.csv +4 -0
.gitattributes CHANGED
@@ -1244,3 +1244,19 @@ p1/preprocess/Kidney_Papillary_Cell_Carcinoma/gene_data/GSE19949.csv filter=lfs
1244
  p1/preprocess/Large_B-cell_Lymphoma/gene_data/GSE142494.csv filter=lfs diff=lfs merge=lfs -text
1245
  p1/preprocess/Large_B-cell_Lymphoma/gene_data/GSE156309.csv filter=lfs diff=lfs merge=lfs -text
1246
  p1/preprocess/Large_B-cell_Lymphoma/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1244
  p1/preprocess/Large_B-cell_Lymphoma/gene_data/GSE142494.csv filter=lfs diff=lfs merge=lfs -text
1245
  p1/preprocess/Large_B-cell_Lymphoma/gene_data/GSE156309.csv filter=lfs diff=lfs merge=lfs -text
1246
  p1/preprocess/Large_B-cell_Lymphoma/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1247
+ p1/preprocess/LDL_Cholesterol_Levels/gene_data/GSE28893.csv filter=lfs diff=lfs merge=lfs -text
1248
+ p1/preprocess/Liver_Cancer/gene_data/GSE228782.csv filter=lfs diff=lfs merge=lfs -text
1249
+ p1/preprocess/Liver_Cancer/GSE228783.csv filter=lfs diff=lfs merge=lfs -text
1250
+ p1/preprocess/Liver_Cancer/GSE164760.csv filter=lfs diff=lfs merge=lfs -text
1251
+ p1/preprocess/Large_B-cell_Lymphoma/gene_data/GSE159472.csv filter=lfs diff=lfs merge=lfs -text
1252
+ p1/preprocess/Liver_Cancer/gene_data/GSE228783.csv filter=lfs diff=lfs merge=lfs -text
1253
+ p1/preprocess/Liver_Cancer/gene_data/GSE174570.csv filter=lfs diff=lfs merge=lfs -text
1254
+ p1/preprocess/Liver_Cancer/GSE178201.csv filter=lfs diff=lfs merge=lfs -text
1255
+ p1/preprocess/Liver_Cancer/gene_data/GSE164760.csv filter=lfs diff=lfs merge=lfs -text
1256
+ p1/preprocess/Liver_Cancer/gene_data/GSE178201.csv filter=lfs diff=lfs merge=lfs -text
1257
+ p1/preprocess/Kidney_Papillary_Cell_Carcinoma/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1258
+ p1/preprocess/Hypothyroidism/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1259
+ p1/preprocess/Lower_Grade_Glioma/gene_data/GSE35158.csv filter=lfs diff=lfs merge=lfs -text
1260
+ p1/preprocess/Longevity/GSE48264.csv filter=lfs diff=lfs merge=lfs -text
1261
+ p1/preprocess/Hypothyroidism/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1262
+ p1/preprocess/Longevity/gene_data/GSE48264.csv filter=lfs diff=lfs merge=lfs -text
p1/preprocess/Hypothyroidism/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:291fbb9e789469e928d5eb54d36e860f286cc4d64ffd237caf5b24912716f189
3
+ size 172250060
p1/preprocess/Hypothyroidism/gene_data/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:116506c96e07673dc76e9ed5290370c62b4b440443ef1e3d87b96279aa4b80e6
3
+ size 172246036
p1/preprocess/Kidney_Papillary_Cell_Carcinoma/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7764046897738cb808483810d5d13703b0fa8d104804ea15d171fc8febfc8c1d
3
+ size 97076351
p1/preprocess/LDL_Cholesterol_Levels/gene_data/GSE28893.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8b12983cd2dfb9d129074e58b622d836353b3c190170d6db0cd0771fbc1d4dd4
3
+ size 12605861
p1/preprocess/Large_B-cell_Lymphoma/gene_data/GSE159472.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c0e8bf0aa7749274fae66ba8a5801aefb4fe8aa154164d72e94ac194cf784ce3
3
+ size 46628103
p1/preprocess/Liver_Cancer/GSE164760.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b28407d2f0fc65cfa75fd38143d728a3d9bbe562507ef6267ce3108f90955453
3
+ size 44020771
p1/preprocess/Liver_Cancer/GSE178201.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:198ee6168f16cc2ff484d6a71d268371fd095fea854f79e4f8ae687bcdbc1788
3
+ size 48117464
p1/preprocess/Liver_Cancer/GSE228783.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:869104e0ebe8d067b9655070710eaf34cbd25fdfb3e8c33789cc6db7a21343eb
3
+ size 31578268
p1/preprocess/Liver_Cancer/code/GSE228783.py ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Liver_Cancer"
6
+ cohort = "GSE228783"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Liver_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Liver_Cancer/GSE228783"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Liver_Cancer/GSE228783.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Liver_Cancer/gene_data/GSE228783.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Liver_Cancer/clinical_data/GSE228783.csv"
16
+ json_path = "./output/preprocess/1/Liver_Cancer/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1) Assess gene expression data availability
37
+ is_gene_available = True # Based on the transcriptome context, we assume gene expression is available
38
+
39
+ # 2) Determine variable availability (row keys) and define conversion functions
40
+
41
+ # From the sample characteristics dictionary, row=2 appears to record multiple disease states (CRC Met, CCC, HCC, etc.),
42
+ # and we can map "HCC" → 1 for our trait of interest (Liver_Cancer) and everything else → 0
43
+ trait_row = 2
44
+ age_row = None # Not found
45
+ gender_row = None # Not found
46
+
47
+ def convert_trait(value: str) -> Optional[int]:
48
+ # Extract substring after colon
49
+ val = value.split(':')[-1].strip().lower()
50
+ if val == 'hcc':
51
+ return 1
52
+ elif val in ['crc met', 'ccc', 'other']:
53
+ return 0
54
+ else:
55
+ return None
56
+
57
+ # Age and gender data are unavailable, so return None
58
+ def convert_age(value: str) -> Optional[float]:
59
+ return None
60
+
61
+ def convert_gender(value: str) -> Optional[int]:
62
+ return None
63
+
64
+ # 3) Initial filtering and metadata saving
65
+ is_trait_available = (trait_row is not None)
66
+ is_usable = validate_and_save_cohort_info(
67
+ is_final=False,
68
+ cohort=cohort,
69
+ info_path=json_path,
70
+ is_gene_available=is_gene_available,
71
+ is_trait_available=is_trait_available
72
+ )
73
+
74
+ # 4) Clinical feature extraction (only if trait data is available)
75
+ if trait_row is not None:
76
+ selected_clinical_df = geo_select_clinical_features(
77
+ clinical_df=clinical_data,
78
+ trait=trait, # "Liver_Cancer"
79
+ trait_row=trait_row,
80
+ convert_trait=convert_trait,
81
+ age_row=age_row,
82
+ convert_age=convert_age,
83
+ gender_row=gender_row,
84
+ convert_gender=convert_gender
85
+ )
86
+
87
+ # Preview the extracted clinical features
88
+ preview = preview_df(selected_clinical_df, n=5, max_items=200)
89
+ print("Clinical Data Preview:", preview)
90
+
91
+ # Save clinical features to CSV
92
+ selected_clinical_df.to_csv(out_clinical_data_file, index=False)
93
+ # STEP3
94
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
95
+ gene_data = get_genetic_data(matrix_file)
96
+
97
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
98
+ print(gene_data.index[:20])
99
+ # Observing the given identifiers, they appear to be Affymetrix probe IDs rather than standard human gene symbols.
100
+ # Therefore, gene mapping to standard gene symbols is required.
101
+ print("requires_gene_mapping = True")
102
+ # STEP5
103
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
104
+ gene_annotation = get_gene_annotation(soft_file)
105
+
106
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
107
+ print("Gene annotation preview:")
108
+ print(preview_df(gene_annotation))
109
+ # STEP6
110
+ # 1) Identify the matching columns: "ID" matches the probe IDs in gene_data.index, and "Gene Symbol" provides the actual gene symbol.
111
+ probe_col = "ID"
112
+ symbol_col = "Gene Symbol"
113
+
114
+ # 2) Extract a mapping dataframe from gene_annotation
115
+ mapping_df = get_gene_mapping(gene_annotation, probe_col, symbol_col)
116
+
117
+ # 3) Convert probe-level measurements to gene-level expression data
118
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
119
+
120
+ # Print to verify the resulting gene_data structure
121
+ print("Mapped gene_data dimensions:", gene_data.shape)
122
+ print("Mapped gene_data preview:")
123
+ print(gene_data.head())
124
+ # STEP 7: Data Normalization and Linking
125
+
126
+ import pandas as pd
127
+
128
+ # 1. Normalize the mapped gene expression data using known gene symbol synonyms, then save.
129
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
130
+ normalized_gene_data.to_csv(out_gene_data_file)
131
+
132
+ # 2. Read the real clinical trait data (extracted in Step 2) from CSV.
133
+ # Recall that we saved it with index=False, so we rename the single row to be the trait name.
134
+ selected_clinical_df = pd.read_csv(out_clinical_data_file)
135
+ selected_clinical_df = selected_clinical_df.rename(index={0: trait})
136
+
137
+ # Since age_row and gender_row are None, there are no age or gender rows to merge.
138
+ # Our final clinical data is just the trait row.
139
+ combined_clinical_df = selected_clinical_df
140
+
141
+ # Link the clinical and genetic data by matching sample IDs in columns.
142
+ linked_data = geo_link_clinical_genetic_data(combined_clinical_df, normalized_gene_data)
143
+
144
+ # 3. Handle missing values in the linked data (drop incomplete rows/columns, then impute).
145
+ processed_data = handle_missing_values(linked_data, trait)
146
+
147
+ # 4. Check trait bias and remove any biased demographic features (none exist here, but code remains general).
148
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait)
149
+
150
+ # 5. Final validation and metadata saving. If the dataset is valid (not severely biased) and has enough data, mark usable.
151
+ is_usable = validate_and_save_cohort_info(
152
+ is_final=True,
153
+ cohort=cohort,
154
+ info_path=json_path,
155
+ is_gene_available=True,
156
+ is_trait_available=True,
157
+ is_biased=trait_biased,
158
+ df=processed_data,
159
+ note="Using true trait data extracted at Step 2."
160
+ )
161
+
162
+ # 6. If final dataset is usable, save it. Otherwise, skip saving.
163
+ if is_usable:
164
+ processed_data.to_csv(out_data_file)
p1/preprocess/Liver_Cancer/gene_data/GSE164760.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3d58b0de4f8a4a5d4b26baf5a61eedfe6bb95b30d2341be5fb0695a4cfcd3d38
3
+ size 44020082
p1/preprocess/Liver_Cancer/gene_data/GSE174570.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7f40d0d270798d85a2cb5f20ef300977c0d775a222f1f046308301ef9377a37f
3
+ size 29585356
p1/preprocess/Liver_Cancer/gene_data/GSE178201.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bb1a59cea40550c8057a150e424e1a7e9b62eab505e3338394c091055230efe3
3
+ size 48101519
p1/preprocess/Liver_Cancer/gene_data/GSE228782.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:747966e5ef3147062b76e3d4640b5a5c6bf1fc9196be79454cff0d63ae9964ac
3
+ size 17307954
p1/preprocess/Liver_Cancer/gene_data/GSE228783.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f2bf23a43d7dc835898cc3d3f388f1f187b5b187eb1df2048cd42229d690e1bd
3
+ size 31577651
p1/preprocess/Liver_Cancer/gene_data/GSE45032.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Liver_Cancer/gene_data/GSE66843.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Liver_cirrhosis/GSE139602.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Liver_cirrhosis/GSE163211.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Liver_cirrhosis/GSE285291.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Liver_cirrhosis/clinical_data/GSE139602.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ GSM4144550,GSM4144551,GSM4144552,GSM4144553,GSM4144554,GSM4144555,GSM4144556,GSM4144557,GSM4144558,GSM4144559,GSM4144560,GSM4144561,GSM4144562,GSM4144563,GSM4144564,GSM4144565,GSM4144566,GSM4144567,GSM4144568,GSM4144569,GSM4144570,GSM4144571,GSM4144572,GSM4144573,GSM4144574,GSM4144575,GSM4144576,GSM4144577,GSM4144578,GSM4144579,GSM4144580,GSM4144581,GSM4144582,GSM4144583,GSM4144584,GSM4144585,GSM4144586,GSM4144587,GSM4144588
2
+ 0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
p1/preprocess/Liver_cirrhosis/clinical_data/GSE163211.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ GSM4974854,GSM4974855,GSM4974856,GSM4974857,GSM4974858,GSM4974859,GSM4974860,GSM4974861,GSM4974862,GSM4974863,GSM4974864,GSM4974865,GSM4974866,GSM4974867,GSM4974868,GSM4974869,GSM4974870,GSM4974871,GSM4974872,GSM4974873,GSM4974874,GSM4974875,GSM4974876,GSM4974877,GSM4974878,GSM4974879,GSM4974880,GSM4974881,GSM4974882,GSM4974883,GSM4974884,GSM4974885,GSM4974886,GSM4974887,GSM4974888,GSM4974889,GSM4974890,GSM4974891,GSM4974892,GSM4974893,GSM4974894,GSM4974895,GSM4974896,GSM4974897,GSM4974898,GSM4974899,GSM4974900,GSM4974901,GSM4974902,GSM4974903,GSM4974904,GSM4974905,GSM4974906,GSM4974907,GSM4974908,GSM4974909,GSM4974910,GSM4974911,GSM4974912,GSM4974913,GSM4974914,GSM4974915,GSM4974916,GSM4974917,GSM4974918,GSM4974919,GSM4974920,GSM4974921,GSM4974922,GSM4974923,GSM4974924,GSM4974925,GSM4974926,GSM4974927,GSM4974928,GSM4974929,GSM4974930,GSM4974931,GSM4974932,GSM4974933,GSM4974934,GSM4974935,GSM4974936,GSM4974937,GSM4974938,GSM4974939,GSM4974940,GSM4974941,GSM4974942,GSM4974943,GSM4974944,GSM4974945,GSM4974946,GSM4974947,GSM4974948,GSM4974949,GSM4974950,GSM4974951,GSM4974952,GSM4974953,GSM4974954,GSM4974955,GSM4974956,GSM4974957,GSM4974958,GSM4974959,GSM4974960,GSM4974961,GSM4974962,GSM4974963,GSM4974964,GSM4974965,GSM4974966,GSM4974967,GSM4974968,GSM4974969,GSM4974970,GSM4974971,GSM4974972,GSM4974973,GSM4974974,GSM4974975,GSM4974976,GSM4974977,GSM4974978,GSM4974979,GSM4974980,GSM4974981,GSM4974982,GSM4974983,GSM4974984,GSM4974985,GSM4974986,GSM4974987,GSM4974988,GSM4974989,GSM4974990,GSM4974991,GSM4974992,GSM4974993,GSM4974994,GSM4974995,GSM4974996,GSM4974997,GSM4974998,GSM4974999,GSM4975000,GSM4975001,GSM4975002,GSM4975003,GSM4975004,GSM4975005,GSM4975006,GSM4975007,GSM4975008,GSM4975009,GSM4975010,GSM4975011,GSM4975012,GSM4975013,GSM4975014,GSM4975015,GSM4975016,GSM4975017,GSM4975018,GSM4975019,GSM4975020,GSM4975021,GSM4975022,GSM4975023,GSM4975024,GSM4975025,GSM4975026,GSM4975027,GSM4975028,GSM4975029,GSM4975030,GSM4975031,GSM4975032,GSM4975033,GSM4975034,GSM4975035,GSM4975036,GSM4975037,GSM4975038,GSM4975039,GSM4975040,GSM4975041,GSM4975042,GSM4975043,GSM4975044,GSM4975045,GSM4975046,GSM4975047,GSM4975048,GSM4975049,GSM4975050,GSM4975051,GSM4975052,GSM4975053,GSM4975054,GSM4975055,GSM4975056,GSM4975057,GSM4975058,GSM4975059,GSM4975060,GSM4975061,GSM4975062,GSM4975063,GSM4975064,GSM4975065,GSM4975066,GSM4975067,GSM4975068,GSM4975069,GSM4975070,GSM4975071,GSM4975072,GSM4975073,GSM4975074,GSM4975075,GSM4975076,GSM4975077,GSM4975078,GSM4975079,GSM4975080,GSM4975081,GSM4975082,GSM4975083,GSM4975084,GSM4975085,GSM4975086,GSM4975087,GSM4975088,GSM4975089,GSM4975090,GSM4975091,GSM4975092,GSM4975093,GSM4975094,GSM4975095,GSM4975096,GSM4975097,GSM4975098,GSM4975099,GSM4975100,GSM4975101,GSM4975102,GSM4975103,GSM4975104,GSM4975105,GSM4975106,GSM4975107,GSM4975108,GSM4975109,GSM4975110,GSM4975111,GSM4975112,GSM4975113,GSM4975114,GSM4975115,GSM4975116,GSM4975117,GSM4975118,GSM4975119,GSM4975120,GSM4975121,GSM4975122,GSM4975123,GSM4975124,GSM4975125,GSM4975126,GSM4975127,GSM4975128,GSM4975129,GSM4975130,GSM4975131,GSM4975132,GSM4975133,GSM4975134,GSM4975135,GSM4975136,GSM4975137,GSM4975138,GSM4975139,GSM4975140,GSM4975141,GSM4975142,GSM4975143,GSM4975144,GSM4975145,GSM4975146,GSM4975147,GSM4975148,GSM4975149,GSM4975150,GSM4975151,GSM4975152,GSM4975153,GSM4975154,GSM4975155,GSM4975156,GSM4975157,GSM4975158,GSM4975159,GSM4975160,GSM4975161,GSM4975162,GSM4975163,GSM4975164,GSM4975165,GSM4975166,GSM4975167,GSM4975168,GSM4975169,GSM4975170,GSM4975171
2
+ 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0
3
+ 35.0,33.0,55.0,49.0,27.0,44.0,58.0,53.0,46.0,61.0,29.0,19.0,33.0,64.0,16.0,25.0,72.0,24.0,60.0,58.0,70.0,33.0,44.0,29.0,46.0,58.0,16.0,32.0,17.0,44.0,56.0,34.0,61.0,34.0,45.0,30.0,58.0,39.0,25.0,21.0,31.0,49.0,37.0,48.0,35.0,56.0,49.0,46.0,29.0,35.0,36.0,18.0,60.0,63.0,39.0,53.0,35.0,62.0,28.0,60.0,44.0,41.0,50.0,40.0,51.0,56.0,50.0,34.0,26.0,51.0,33.0,41.0,47.0,32.0,49.0,38.0,56.0,43.0,61.0,51.0,27.0,37.0,57.0,27.0,56.0,44.0,54.0,36.0,53.0,59.0,29.0,43.0,46.0,26.0,60.0,58.0,59.0,60.0,59.0,51.0,35.0,32.0,43.0,52.0,38.0,47.0,40.0,47.0,43.0,41.0,26.0,26.0,51.0,44.0,38.0,57.0,51.0,32.0,41.0,53.0,27.0,58.0,50.0,58.0,36.0,50.0,43.0,38.0,47.0,50.0,60.0,41.0,33.0,37.0,34.0,42.0,56.0,43.0,38.0,60.0,54.0,49.0,53.0,46.0,48.0,74.0,41.0,57.0,31.0,54.0,23.0,49.0,62.0,35.0,62.0,46.0,40.0,62.0,56.0,35.0,48.0,60.0,41.0,43.0,47.0,57.0,36.0,17.0,29.0,36.0,39.0,41.0,30.0,43.0,31.0,53.0,41.0,35.0,65.0,49.0,51.0,48.0,32.0,38.0,18.0,34.0,35.0,40.0,49.0,56.0,30.0,33.0,55.0,52.0,50.0,24.0,63.0,33.0,37.0,37.0,33.0,53.0,69.0,39.0,47.0,52.0,50.0,55.0,35.0,47.0,54.0,32.0,45.0,27.0,64.0,54.0,52.0,46.0,33.0,48.0,47.0,38.0,56.0,28.0,40.0,43.0,65.0,54.0,48.0,36.0,33.0,38.0,52.0,64.0,37.0,44.0,71.0,38.0,50.0,41.0,52.0,30.0,42.0,43.0,26.0,59.0,64.0,34.0,48.0,34.0,34.0,36.0,43.0,52.0,62.0,23.0,45.0,64.0,59.0,39.0,60.0,53.0,28.0,27.0,42.0,41.0,34.0,54.0,32.0,36.0,33.0,47.0,51.0,46.0,50.0,50.0,32.0,59.0,42.0,25.0,59.0,45.0,20.0,31.0,36.0,30.0,29.0,47.0,25.0,61.0,48.0,68.0,39.0,35.0,34.0,43.0,65.0,55.0,57.0,57.0,54.0,53.0,24.0,35.0,54.0,44.0,36.0,33.0,60.0,45.0,53.0,33.0,57.0,52.0,37.0,56.0,41.0,31.0
4
+ 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0
p1/preprocess/Liver_cirrhosis/clinical_data/GSE285291.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ GSM8700031,GSM8700032,GSM8700033,GSM8700034,GSM8700035,GSM8700036,GSM8700037,GSM8700038,GSM8700039,GSM8700040,GSM8700041,GSM8700042,GSM8700043,GSM8700044,GSM8700045,GSM8700046,GSM8700047,GSM8700048,GSM8700049,GSM8700050,GSM8700051,GSM8700052,GSM8700053,GSM8700054,GSM8700055,GSM8700056,GSM8700057,GSM8700058,GSM8700059,GSM8700060,GSM8700061,GSM8700062,GSM8700063,GSM8700064,GSM8700065,GSM8700066,GSM8700067,GSM8700068,GSM8700069,GSM8700070,GSM8700071,GSM8700072,GSM8700073,GSM8700074,GSM8700075,GSM8700076,GSM8700077,GSM8700078,GSM8700079,GSM8700080,GSM8700081,GSM8700082,GSM8700083
2
+ 1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
p1/preprocess/Liver_cirrhosis/code/GSE139602.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Liver_cirrhosis"
6
+ cohort = "GSE139602"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Liver_cirrhosis"
10
+ in_cohort_dir = "../DATA/GEO/Liver_cirrhosis/GSE139602"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Liver_cirrhosis/GSE139602.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Liver_cirrhosis/gene_data/GSE139602.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Liver_cirrhosis/clinical_data/GSE139602.csv"
16
+ json_path = "./output/preprocess/1/Liver_cirrhosis/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Determine gene expression data availability
37
+ is_gene_available = True # Based on the series description (transcriptome analysis)
38
+
39
+ # 2. Identify rows for trait, age, and gender availability
40
+ trait_row = 0 # Disease states are found in key 0
41
+ age_row = None # No age information found
42
+ gender_row = None # No gender information found
43
+
44
+ # 2.2 Define conversion functions
45
+ def convert_trait(value: str):
46
+ # Extract the text after the colon
47
+ parts = value.split(':', 1)
48
+ if len(parts) < 2:
49
+ return None
50
+ val = parts[1].strip().lower()
51
+ # Binary encoding: 0 = healthy, 1 = disease
52
+ if val == 'healthy':
53
+ return 0
54
+ elif val in ['ecld', 'compensated cirrhosis', 'decompesated cirrhosis', 'acute-on-chronic liver failure']:
55
+ return 1
56
+ else:
57
+ return None
58
+
59
+ def convert_age(value: str):
60
+ # Not applicable since age data is not available
61
+ return None
62
+
63
+ def convert_gender(value: str):
64
+ # Not applicable since gender data is not available
65
+ return None
66
+
67
+ # 3. Save initial metadata
68
+ is_trait_available = (trait_row is not None)
69
+ is_usable = validate_and_save_cohort_info(
70
+ is_final=False,
71
+ cohort=cohort,
72
+ info_path=json_path,
73
+ is_gene_available=is_gene_available,
74
+ is_trait_available=is_trait_available
75
+ )
76
+
77
+ # 4. Clinical feature extraction if trait data is available
78
+ if trait_row is not None:
79
+ # Assume 'clinical_data' is already loaded in the environment
80
+ selected_clinical_df = geo_select_clinical_features(
81
+ clinical_df=clinical_data,
82
+ trait=trait,
83
+ trait_row=trait_row,
84
+ convert_trait=convert_trait,
85
+ age_row=age_row,
86
+ convert_age=convert_age,
87
+ gender_row=gender_row,
88
+ convert_gender=convert_gender
89
+ )
90
+ preview = preview_df(selected_clinical_df)
91
+ print(preview)
92
+ selected_clinical_df.to_csv(out_clinical_data_file, index=False)
93
+ # STEP3
94
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
95
+ gene_data = get_genetic_data(matrix_file)
96
+
97
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
98
+ print(gene_data.index[:20])
99
+ # Observing the gene identifiers, they appear to be Affymetrix probe IDs, not standard gene symbols.
100
+ requires_gene_mapping = True
101
+ # STEP5
102
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
103
+ gene_annotation = get_gene_annotation(soft_file)
104
+
105
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
106
+ print("Gene annotation preview:")
107
+ print(preview_df(gene_annotation))
108
+ # STEP: Gene Identifier Mapping
109
+
110
+ # 1. Identify the columns in the gene annotation dataframe corresponding to the probe IDs and the gene symbols.
111
+ # Here, "ID" is the same kind of probe ID as in the gene expression data, and "Gene Symbol" stores the gene symbols.
112
+
113
+ # 2. Get a gene mapping dataframe, extracting the two relevant columns and renaming the gene symbol column to "Gene".
114
+ mapping_df = get_gene_mapping(
115
+ annotation=gene_annotation,
116
+ prob_col="ID",
117
+ gene_col="Gene Symbol"
118
+ )
119
+
120
+ # 3. Convert probe-level to gene-level expression data by applying the mapping.
121
+ gene_data = apply_gene_mapping(
122
+ expression_df=gene_data,
123
+ mapping_df=mapping_df
124
+ )
125
+
126
+ # Optional: print shape and a small preview to observe the result
127
+ print("Mapped gene_data shape:", gene_data.shape)
128
+ print("Mapped gene_data preview:\n", gene_data.head())
129
+ import os
130
+ import pandas as pd
131
+
132
+ # STEP 7: Data Normalization and Linking
133
+
134
+ # First, check if the clinical CSV file exists. If it does not, we cannot proceed with trait-based linking.
135
+ if not os.path.exists(out_clinical_data_file):
136
+ # No trait data file => dataset is not usable for trait analysis
137
+ df_null = pd.DataFrame()
138
+ is_biased = True # Arbitrary boolean to satisfy function requirement
139
+ validate_and_save_cohort_info(
140
+ is_final=True,
141
+ cohort=cohort,
142
+ info_path=json_path,
143
+ is_gene_available=True,
144
+ is_trait_available=False,
145
+ is_biased=is_biased,
146
+ df=df_null,
147
+ note="No trait data file found; dataset not usable for trait analysis."
148
+ )
149
+
150
+ else:
151
+ # 1. Normalize the mapped gene expression data using known gene symbol synonyms, then save.
152
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
153
+ normalized_gene_data.to_csv(out_gene_data_file)
154
+
155
+ # 2. Load the previously extracted clinical CSV.
156
+ selected_clinical_df = pd.read_csv(out_clinical_data_file)
157
+ # If we had a single-row trait, rename row 0 to the trait name (example usage).
158
+ selected_clinical_df = selected_clinical_df.rename(index={0: trait})
159
+
160
+ # Combine these as our final clinical data; in this dataset, we only have trait info (if any).
161
+ combined_clinical_df = selected_clinical_df
162
+
163
+ # Link the clinical and genetic data by matching sample IDs in columns.
164
+ linked_data = geo_link_clinical_genetic_data(combined_clinical_df, normalized_gene_data)
165
+
166
+ # 3. Handle missing values in the linked data (drop incomplete rows/columns, then impute).
167
+ processed_data = handle_missing_values(linked_data, trait)
168
+
169
+ # 4. Check trait bias and remove any biased demographic features (if any).
170
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait)
171
+
172
+ # 5. Final validation and metadata saving.
173
+ is_usable = validate_and_save_cohort_info(
174
+ is_final=True,
175
+ cohort=cohort,
176
+ info_path=json_path,
177
+ is_gene_available=True,
178
+ is_trait_available=True,
179
+ is_biased=trait_biased,
180
+ df=processed_data,
181
+ note="Completed trait-based preprocessing."
182
+ )
183
+
184
+ # 6. If final dataset is usable, save. Otherwise, skip.
185
+ if is_usable:
186
+ processed_data.to_csv(out_data_file)
p1/preprocess/Liver_cirrhosis/code/GSE150734.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Liver_cirrhosis"
6
+ cohort = "GSE150734"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Liver_cirrhosis"
10
+ in_cohort_dir = "../DATA/GEO/Liver_cirrhosis/GSE150734"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Liver_cirrhosis/GSE150734.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Liver_cirrhosis/gene_data/GSE150734.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Liver_cirrhosis/clinical_data/GSE150734.csv"
16
+ json_path = "./output/preprocess/1/Liver_cirrhosis/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Gene Expression Data Availability
37
+ # Based on the background information "Gene expression profiling" we conclude this dataset likely has gene data.
38
+ is_gene_available = True
39
+
40
+ # 2. Variable Availability and Data Type Conversion
41
+ # Inspecting the sample characteristics dictionary:
42
+ # {0: ['fibrosis stage: 0', 'fibrosis stage: 1'],
43
+ # 1: ['pls risk prediction: High', 'pls risk prediction: Intermediate', 'pls risk prediction: Low']}
44
+ #
45
+ # None of these keys provide a direct or strongly inferable measure of "Liver_cirrhosis".
46
+ # Hence, trait, age, and gender data are considered not available.
47
+ trait_row = None
48
+ age_row = None
49
+ gender_row = None
50
+
51
+ # Define placeholder converter functions (they will simply return None here).
52
+ def convert_trait(raw_value: str):
53
+ return None
54
+
55
+ def convert_age(raw_value: str):
56
+ return None
57
+
58
+ def convert_gender(raw_value: str):
59
+ return None
60
+
61
+ # Check if trait is available
62
+ is_trait_available = (trait_row is not None)
63
+
64
+ # 3. Save Metadata (initial filtering)
65
+ # Since trait data is not available, this dataset fails initial filtering.
66
+ _ = validate_and_save_cohort_info(
67
+ is_final=False,
68
+ cohort=cohort,
69
+ info_path=json_path,
70
+ is_gene_available=is_gene_available,
71
+ is_trait_available=is_trait_available
72
+ )
73
+
74
+ # 4. Clinical Feature Extraction
75
+ # Skipped because trait_row is None (no clinical trait data available).
p1/preprocess/Liver_cirrhosis/code/GSE163211.py ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Liver_cirrhosis"
6
+ cohort = "GSE163211"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Liver_cirrhosis"
10
+ in_cohort_dir = "../DATA/GEO/Liver_cirrhosis/GSE163211"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Liver_cirrhosis/GSE163211.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Liver_cirrhosis/gene_data/GSE163211.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Liver_cirrhosis/clinical_data/GSE163211.csv"
16
+ json_path = "./output/preprocess/1/Liver_cirrhosis/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Gene Expression Data Availability
37
+ is_gene_available = True # Based on the Nanostring assay for gene expression
38
+
39
+ # 2. Variable Availability and Conversions
40
+ # From the sample characteristics, we identify:
41
+ # trait_row = 8 (nafld stage), age_row = 3, gender_row = 4
42
+ trait_row = 8
43
+ age_row = 3
44
+ gender_row = 4
45
+
46
+ def convert_trait(value: str):
47
+ parts = value.split(':', 1)
48
+ if len(parts) < 2:
49
+ return None
50
+ label = parts[1].strip().lower()
51
+ # Map "nash_f1_f4" to 1 (approx. cirrhosis if advanced) otherwise 0
52
+ if label == "nash_f1_f4":
53
+ return 1
54
+ elif label in ["normal", "steatosis", "nash_f0"]:
55
+ return 0
56
+ return None
57
+
58
+ def convert_age(value: str):
59
+ parts = value.split(':', 1)
60
+ if len(parts) < 2:
61
+ return None
62
+ label = parts[1].strip()
63
+ try:
64
+ return float(label)
65
+ except ValueError:
66
+ return None
67
+
68
+ def convert_gender(value: str):
69
+ parts = value.split(':', 1)
70
+ if len(parts) < 2:
71
+ return None
72
+ label = parts[1].strip().lower()
73
+ if label == "female":
74
+ return 0
75
+ elif label == "male":
76
+ return 1
77
+ return None
78
+
79
+ # 3. Save Metadata (initial filtering)
80
+ is_trait_available = (trait_row is not None)
81
+ is_usable = validate_and_save_cohort_info(
82
+ is_final=False,
83
+ cohort=cohort,
84
+ info_path=json_path,
85
+ is_gene_available=is_gene_available,
86
+ is_trait_available=is_trait_available
87
+ )
88
+
89
+ # 4. Clinical Feature Extraction (only if trait_row is not None)
90
+ if trait_row is not None:
91
+ clinical_data_selected = geo_select_clinical_features(
92
+ clinical_data,
93
+ trait=trait,
94
+ trait_row=trait_row,
95
+ convert_trait=convert_trait,
96
+ age_row=age_row,
97
+ convert_age=convert_age,
98
+ gender_row=gender_row,
99
+ convert_gender=convert_gender
100
+ )
101
+ print("Clinical Data Preview:", preview_df(clinical_data_selected))
102
+ clinical_data_selected.to_csv(out_clinical_data_file, index=False)
103
+ # STEP3
104
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
105
+ gene_data = get_genetic_data(matrix_file)
106
+
107
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
108
+ print(gene_data.index[:20])
109
+ requires_gene_mapping = False
110
+ import os
111
+ import pandas as pd
112
+
113
+ # STEP 7: Data Normalization and Linking
114
+
115
+ # First, check if the clinical CSV file exists. If it does not, we cannot proceed with trait-based linking.
116
+ if not os.path.exists(out_clinical_data_file):
117
+ # No trait data file => dataset is not usable for trait analysis
118
+ df_null = pd.DataFrame()
119
+ is_biased = True # Arbitrary boolean to satisfy function requirement
120
+ validate_and_save_cohort_info(
121
+ is_final=True,
122
+ cohort=cohort,
123
+ info_path=json_path,
124
+ is_gene_available=True,
125
+ is_trait_available=False,
126
+ is_biased=is_biased,
127
+ df=df_null,
128
+ note="No trait data file found; dataset not usable for trait analysis."
129
+ )
130
+
131
+ else:
132
+ # 1. Normalize the mapped gene expression data using known gene symbol synonyms, then save.
133
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
134
+ normalized_gene_data.to_csv(out_gene_data_file)
135
+
136
+ # 2. Load the previously extracted clinical CSV.
137
+ selected_clinical_df = pd.read_csv(out_clinical_data_file)
138
+ # If we had a single-row trait, rename row 0 to the trait name (example usage).
139
+ selected_clinical_df = selected_clinical_df.rename(index={0: trait})
140
+
141
+ # Combine these as our final clinical data; in this dataset, we only have trait info (if any).
142
+ combined_clinical_df = selected_clinical_df
143
+
144
+ # Link the clinical and genetic data by matching sample IDs in columns.
145
+ linked_data = geo_link_clinical_genetic_data(combined_clinical_df, normalized_gene_data)
146
+
147
+ # 3. Handle missing values in the linked data (drop incomplete rows/columns, then impute).
148
+ processed_data = handle_missing_values(linked_data, trait)
149
+
150
+ # 4. Check trait bias and remove any biased demographic features (if any).
151
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait)
152
+
153
+ # 5. Final validation and metadata saving.
154
+ is_usable = validate_and_save_cohort_info(
155
+ is_final=True,
156
+ cohort=cohort,
157
+ info_path=json_path,
158
+ is_gene_available=True,
159
+ is_trait_available=True,
160
+ is_biased=trait_biased,
161
+ df=processed_data,
162
+ note="Completed trait-based preprocessing."
163
+ )
164
+
165
+ # 6. If final dataset is usable, save. Otherwise, skip.
166
+ if is_usable:
167
+ processed_data.to_csv(out_data_file)
p1/preprocess/Liver_cirrhosis/code/GSE182060.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Liver_cirrhosis"
6
+ cohort = "GSE182060"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Liver_cirrhosis"
10
+ in_cohort_dir = "../DATA/GEO/Liver_cirrhosis/GSE182060"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Liver_cirrhosis/GSE182060.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Liver_cirrhosis/gene_data/GSE182060.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Liver_cirrhosis/clinical_data/GSE182060.csv"
16
+ json_path = "./output/preprocess/1/Liver_cirrhosis/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Determine gene expression data availability
37
+ is_gene_available = True # The series explicitly mentions "Gene expression profiling"
38
+
39
+ # 2. Variable Availability and Data Type Conversion
40
+
41
+ # From the sample characteristics, we do not see any row containing
42
+ # information about "Liver_cirrhosis", age, or gender. Hence:
43
+ trait_row = None
44
+ age_row = None
45
+ gender_row = None
46
+
47
+ # Define placeholder conversion functions. They won't be used since
48
+ # all rows are None, but we'll define them for completeness.
49
+
50
+ def convert_trait(value: str) -> Optional[int]:
51
+ # No data available, so always return None
52
+ return None
53
+
54
+ def convert_age(value: str) -> Optional[float]:
55
+ # No data available, so always return None
56
+ return None
57
+
58
+ def convert_gender(value: str) -> Optional[int]:
59
+ # No data available, so always return None
60
+ return None
61
+
62
+ # 3. Save Metadata (Initial Filtering)
63
+ is_trait_available = (trait_row is not None)
64
+ validate_and_save_cohort_info(
65
+ is_final=False,
66
+ cohort=cohort,
67
+ info_path=json_path,
68
+ is_gene_available=is_gene_available,
69
+ is_trait_available=is_trait_available
70
+ )
71
+
72
+ # 4. Clinical Feature Extraction
73
+ # Since trait_row is None, we do not extract clinical features and skip this step.
p1/preprocess/Liver_cirrhosis/code/GSE182065.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Liver_cirrhosis"
6
+ cohort = "GSE182065"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Liver_cirrhosis"
10
+ in_cohort_dir = "../DATA/GEO/Liver_cirrhosis/GSE182065"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Liver_cirrhosis/GSE182065.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Liver_cirrhosis/gene_data/GSE182065.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Liver_cirrhosis/clinical_data/GSE182065.csv"
16
+ json_path = "./output/preprocess/1/Liver_cirrhosis/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Determine gene expression data availability
37
+ # Based on the series_description mentioning "expression profiling" and a 20-gene signature,
38
+ # we assume gene expression data is available.
39
+ is_gene_available = True
40
+
41
+ # 2. Determine data availability for trait, age, and gender
42
+ # The sample characteristics dictionary does not provide fields indicating variability
43
+ # for cirrhosis status, age, or gender.
44
+ # Therefore, set all row indices to None, meaning not available.
45
+ trait_row = None
46
+ age_row = None
47
+ gender_row = None
48
+
49
+ # 2.2 Define conversion functions
50
+ def convert_trait(value: str) -> int:
51
+ # No relevant data; return None
52
+ return None
53
+
54
+ def convert_age(value: str) -> float:
55
+ # No relevant data; return None
56
+ return None
57
+
58
+ def convert_gender(value: str) -> int:
59
+ # No relevant data; return None
60
+ return None
61
+
62
+ # 3. Save initial metadata
63
+ is_trait_available = trait_row is not None
64
+ _ = validate_and_save_cohort_info(
65
+ is_final=False,
66
+ cohort=cohort,
67
+ info_path=json_path,
68
+ is_gene_available=is_gene_available,
69
+ is_trait_available=is_trait_available
70
+ )
71
+
72
+ # 4. Clinical feature extraction
73
+ # Since trait_row is None, we skip this substep.
74
+ # STEP3
75
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
76
+ gene_data = get_genetic_data(matrix_file)
77
+
78
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
79
+ print(gene_data.index[:20])
80
+ # Based on inspection of the gene identifiers (e.g., AARS, ABLIM1, ACOT2, etc.),
81
+ # these appear to be valid human gene symbols and do not require additional mapping.
82
+
83
+ requires_gene_mapping = False
84
+ import os
85
+ import pandas as pd
86
+
87
+ # STEP 7: Data Normalization and Linking
88
+
89
+ # First, check if the clinical CSV file exists. If it does not, we cannot proceed with trait-based linking.
90
+ if not os.path.exists(out_clinical_data_file):
91
+ # No trait data file => dataset is not usable for trait analysis
92
+ df_null = pd.DataFrame()
93
+ is_biased = True # Arbitrary boolean to satisfy function requirement
94
+ validate_and_save_cohort_info(
95
+ is_final=True,
96
+ cohort=cohort,
97
+ info_path=json_path,
98
+ is_gene_available=True,
99
+ is_trait_available=False,
100
+ is_biased=is_biased,
101
+ df=df_null,
102
+ note="No trait data file found; dataset not usable for trait analysis."
103
+ )
104
+
105
+ else:
106
+ # 1. Normalize the mapped gene expression data using known gene symbol synonyms, then save.
107
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
108
+ normalized_gene_data.to_csv(out_gene_data_file)
109
+
110
+ # 2. Load the previously extracted clinical CSV.
111
+ selected_clinical_df = pd.read_csv(out_clinical_data_file)
112
+ # If we had a single-row trait, rename row 0 to the trait name (example usage).
113
+ selected_clinical_df = selected_clinical_df.rename(index={0: trait})
114
+
115
+ # Combine these as our final clinical data; in this dataset, we only have trait info (if any).
116
+ combined_clinical_df = selected_clinical_df
117
+
118
+ # Link the clinical and genetic data by matching sample IDs in columns.
119
+ linked_data = geo_link_clinical_genetic_data(combined_clinical_df, normalized_gene_data)
120
+
121
+ # 3. Handle missing values in the linked data (drop incomplete rows/columns, then impute).
122
+ processed_data = handle_missing_values(linked_data, trait)
123
+
124
+ # 4. Check trait bias and remove any biased demographic features (if any).
125
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait)
126
+
127
+ # 5. Final validation and metadata saving.
128
+ is_usable = validate_and_save_cohort_info(
129
+ is_final=True,
130
+ cohort=cohort,
131
+ info_path=json_path,
132
+ is_gene_available=True,
133
+ is_trait_available=True,
134
+ is_biased=trait_biased,
135
+ df=processed_data,
136
+ note="Completed trait-based preprocessing."
137
+ )
138
+
139
+ # 6. If final dataset is usable, save. Otherwise, skip.
140
+ if is_usable:
141
+ processed_data.to_csv(out_data_file)
p1/preprocess/Liver_cirrhosis/code/GSE185529.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Liver_cirrhosis"
6
+ cohort = "GSE185529"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Liver_cirrhosis"
10
+ in_cohort_dir = "../DATA/GEO/Liver_cirrhosis/GSE185529"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Liver_cirrhosis/GSE185529.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Liver_cirrhosis/gene_data/GSE185529.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Liver_cirrhosis/clinical_data/GSE185529.csv"
16
+ json_path = "./output/preprocess/1/Liver_cirrhosis/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Gene Expression Data Availability
37
+ is_gene_available = True # Based on the information, it seems to contain gene expression data
38
+
39
+ # 2. Variable Availability and Data Type Conversion
40
+ # From the sample characteristics dictionary {0: ['treatment: siCTRL', 'treatment: siBNC2']},
41
+ # we see no mention of "Liver_cirrhosis", "age", or "gender." Therefore:
42
+ trait_row = None
43
+ age_row = None
44
+ gender_row = None
45
+
46
+ # Define conversion functions. These will simply return None given the unavailability of actual data.
47
+
48
+ def convert_trait(value: str) -> Optional[float]:
49
+ # No actual data is present, so return None
50
+ return None
51
+
52
+ def convert_age(value: str) -> Optional[float]:
53
+ # No actual age data is present, so return None
54
+ return None
55
+
56
+ def convert_gender(value: str) -> Optional[int]:
57
+ # No actual gender data is present, so return None
58
+ return None
59
+
60
+ # 3. Initial Filtering and Saving Metadata
61
+ # If trait_row is None, then trait data is not available.
62
+ is_trait_available = (trait_row is not None)
63
+
64
+ _ = validate_and_save_cohort_info(
65
+ is_final=False,
66
+ cohort=cohort,
67
+ info_path=json_path,
68
+ is_gene_available=is_gene_available,
69
+ is_trait_available=is_trait_available
70
+ )
71
+
72
+ # 4. Clinical Feature Extraction
73
+ # Since trait_row is None, we skip the clinical feature extraction.
p1/preprocess/Liver_cirrhosis/code/GSE212047.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Liver_cirrhosis"
6
+ cohort = "GSE212047"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Liver_cirrhosis"
10
+ in_cohort_dir = "../DATA/GEO/Liver_cirrhosis/GSE212047"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Liver_cirrhosis/GSE212047.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Liver_cirrhosis/gene_data/GSE212047.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Liver_cirrhosis/clinical_data/GSE212047.csv"
16
+ json_path = "./output/preprocess/1/Liver_cirrhosis/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Gene Expression Data Availability
37
+ # Based on the background and the general context (focusing on hepatic stellate cell gene expression),
38
+ # we'll assume this dataset contains some form of gene expression data.
39
+ is_gene_available = True
40
+
41
+ # 2. Variable Availability and Data Type Conversion
42
+
43
+ # From the sample characteristics dictionary:
44
+ # {
45
+ # 0: ['strain: Lhx2 floxed; C57BL/6J background', 'strain: Mx1Cre+; Lhx2 floxed; C57BL/6J background'],
46
+ # 1: ['treatment: 2 weeks after poly:IC induce Mx1Cre activation'],
47
+ # 2: ['cell type: FACS-sorted VitA+ Hepatic Stellate Cells']
48
+ # }
49
+ # There is no row indicating "Liver_cirrhosis", age, or gender information. Thus these variables
50
+ # are not available for associative study. So we set them to None.
51
+
52
+ trait_row = None
53
+ age_row = None
54
+ gender_row = None
55
+
56
+ # Even though we have no rows for these variables, we still define the conversion functions as requested.
57
+
58
+ def convert_trait(val: str):
59
+ # Attempt to parse value
60
+ parts = val.split(':', 1)
61
+ if len(parts) < 2:
62
+ return None
63
+ raw_value = parts[1].strip().lower()
64
+ # This dataset does not provide a trait distinction, so return None
65
+ return None
66
+
67
+ def convert_age(val: str):
68
+ # Attempt to parse value
69
+ parts = val.split(':', 1)
70
+ if len(parts) < 2:
71
+ return None
72
+ raw_value = parts[1].strip().lower()
73
+ # No actual age data here, so return None
74
+ return None
75
+
76
+ def convert_gender(val: str):
77
+ # Attempt to parse value
78
+ parts = val.split(':', 1)
79
+ if len(parts) < 2:
80
+ return None
81
+ raw_value = parts[1].strip().lower()
82
+ # No actual gender data here, so return None
83
+ return None
84
+
85
+ # 3. Save Metadata (initial filtering)
86
+ # Trait data availability depends on trait_row.
87
+ is_trait_available = (trait_row is not None)
88
+
89
+ is_usable = validate_and_save_cohort_info(
90
+ is_final=False,
91
+ cohort=cohort,
92
+ info_path=json_path,
93
+ is_gene_available=is_gene_available,
94
+ is_trait_available=is_trait_available
95
+ )
96
+
97
+ # 4. Clinical Feature Extraction
98
+ # Because trait_row is None, we skip clinical feature extraction.
99
+ # STEP3
100
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
101
+ gene_data = get_genetic_data(matrix_file)
102
+
103
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
104
+ print(gene_data.index[:20])
105
+ print("requires_gene_mapping = True")
106
+ # STEP5
107
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
108
+ gene_annotation = get_gene_annotation(soft_file)
109
+
110
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
111
+ print("Gene annotation preview:")
112
+ print(preview_df(gene_annotation))
113
+ # STEP6: Gene Identifier Mapping
114
+
115
+ # 1) Identify the matching columns for probe IDs and gene symbols
116
+ # From the annotation preview, "ID" matches the probe identifiers in our gene_data index,
117
+ # and "gene_assignment" contains text strings from which gene symbols can be extracted.
118
+
119
+ # 2) Get the gene mapping dataframe using the library function
120
+ mapping_df = get_gene_mapping(
121
+ annotation=gene_annotation,
122
+ prob_col="ID",
123
+ gene_col="gene_assignment"
124
+ )
125
+
126
+ # 3) Convert probe-level measurements to gene-level expression values
127
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
128
+
129
+ # For checking, let's print the shape and a few gene symbols
130
+ print("Mapped gene_data shape:", gene_data.shape)
131
+ print("First 20 gene symbols:", list(gene_data.index[:20]))
132
+ import os
133
+ import pandas as pd
134
+
135
+ # STEP 7: Data Normalization and Linking
136
+
137
+ # First, check if the clinical CSV file exists. If it does not, we cannot proceed with trait-based linking.
138
+ if not os.path.exists(out_clinical_data_file):
139
+ # No trait data file => dataset is not usable for trait analysis
140
+ df_null = pd.DataFrame()
141
+ is_biased = True # Arbitrary boolean to satisfy function requirement
142
+ validate_and_save_cohort_info(
143
+ is_final=True,
144
+ cohort=cohort,
145
+ info_path=json_path,
146
+ is_gene_available=True,
147
+ is_trait_available=False,
148
+ is_biased=is_biased,
149
+ df=df_null,
150
+ note="No trait data file found; dataset not usable for trait analysis."
151
+ )
152
+
153
+ else:
154
+ # 1. Normalize the mapped gene expression data using known gene symbol synonyms, then save.
155
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
156
+ normalized_gene_data.to_csv(out_gene_data_file)
157
+
158
+ # 2. Load the previously extracted clinical CSV.
159
+ selected_clinical_df = pd.read_csv(out_clinical_data_file)
160
+ # If we had a single-row trait, rename row 0 to the trait name (example usage).
161
+ selected_clinical_df = selected_clinical_df.rename(index={0: trait})
162
+
163
+ # Combine these as our final clinical data; in this dataset, we only have trait info (if any).
164
+ combined_clinical_df = selected_clinical_df
165
+
166
+ # Link the clinical and genetic data by matching sample IDs in columns.
167
+ linked_data = geo_link_clinical_genetic_data(combined_clinical_df, normalized_gene_data)
168
+
169
+ # 3. Handle missing values in the linked data (drop incomplete rows/columns, then impute).
170
+ processed_data = handle_missing_values(linked_data, trait)
171
+
172
+ # 4. Check trait bias and remove any biased demographic features (if any).
173
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait)
174
+
175
+ # 5. Final validation and metadata saving.
176
+ is_usable = validate_and_save_cohort_info(
177
+ is_final=True,
178
+ cohort=cohort,
179
+ info_path=json_path,
180
+ is_gene_available=True,
181
+ is_trait_available=True,
182
+ is_biased=trait_biased,
183
+ df=processed_data,
184
+ note="Completed trait-based preprocessing."
185
+ )
186
+
187
+ # 6. If final dataset is usable, save. Otherwise, skip.
188
+ if is_usable:
189
+ processed_data.to_csv(out_data_file)
p1/preprocess/Liver_cirrhosis/code/GSE285291.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Liver_cirrhosis"
6
+ cohort = "GSE285291"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Liver_cirrhosis"
10
+ in_cohort_dir = "../DATA/GEO/Liver_cirrhosis/GSE285291"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Liver_cirrhosis/GSE285291.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Liver_cirrhosis/gene_data/GSE285291.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Liver_cirrhosis/clinical_data/GSE285291.csv"
16
+ json_path = "./output/preprocess/1/Liver_cirrhosis/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Determine if gene expression data is available
37
+ is_gene_available = True # Based on the series design mentioning OXPHOS gene expression
38
+
39
+ # 2. Identify rows for trait, age, and gender
40
+ trait_row = 1 # "status: Control/Compensated/Decompensated" indicates variation for cirrhosis
41
+ age_row = None # No age info found; all are "age-matched"
42
+ gender_row = None # All participants are men; no variation
43
+
44
+ # 2.2 Define data type conversion functions
45
+ def convert_trait(raw_value: str):
46
+ """Convert 'Control' -> 0, 'Compensated' or 'Decompensated' -> 1, else None."""
47
+ parts = raw_value.split(':', 1)
48
+ if len(parts) < 2:
49
+ return None
50
+ val = parts[1].strip().lower()
51
+ if val == 'control':
52
+ return 0
53
+ elif val in ['compensated', 'decompensated']:
54
+ return 1
55
+ return None
56
+
57
+ def convert_age(raw_value: str):
58
+ """No age info; always return None."""
59
+ return None
60
+
61
+ def convert_gender(raw_value: str):
62
+ """No gender variation; always return None."""
63
+ return None
64
+
65
+ # 3. Conduct initial filtering and save metadata
66
+ is_trait_available = (trait_row is not None)
67
+ validate_and_save_cohort_info(
68
+ is_final=False,
69
+ cohort=cohort,
70
+ info_path=json_path,
71
+ is_gene_available=is_gene_available,
72
+ is_trait_available=is_trait_available
73
+ )
74
+
75
+ # 4. Extract clinical features if trait data is available
76
+ if trait_row is not None:
77
+ clinical_features_df = geo_select_clinical_features(
78
+ clinical_df=clinical_data,
79
+ trait=trait,
80
+ trait_row=trait_row,
81
+ convert_trait=convert_trait,
82
+ age_row=age_row,
83
+ convert_age=convert_age,
84
+ gender_row=gender_row,
85
+ convert_gender=convert_gender
86
+ )
87
+ # Preview and save the clinical dataframe
88
+ print(preview_df(clinical_features_df, n=5))
89
+ clinical_features_df.to_csv(out_clinical_data_file, index=False)
90
+ # STEP3
91
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
92
+ gene_data = get_genetic_data(matrix_file)
93
+
94
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
95
+ print(gene_data.index[:20])
96
+ # Based on observation, these gene identifiers (e.g., A2M, AADAT, AANAT, etc.) appear to be standard human gene symbols.
97
+ # Hence, they do not require additional mapping to gene symbols.
98
+ print("These gene identifiers are standard human gene symbols.")
99
+ print("requires_gene_mapping = False")
100
+ import os
101
+ import pandas as pd
102
+
103
+ # STEP 7: Data Normalization and Linking
104
+
105
+ # First, check if the clinical CSV file exists. If it does not, we cannot proceed with trait-based linking.
106
+ if not os.path.exists(out_clinical_data_file):
107
+ # No trait data file => dataset is not usable for trait analysis
108
+ df_null = pd.DataFrame()
109
+ is_biased = True # Arbitrary boolean to satisfy function requirement
110
+ validate_and_save_cohort_info(
111
+ is_final=True,
112
+ cohort=cohort,
113
+ info_path=json_path,
114
+ is_gene_available=True,
115
+ is_trait_available=False,
116
+ is_biased=is_biased,
117
+ df=df_null,
118
+ note="No trait data file found; dataset not usable for trait analysis."
119
+ )
120
+
121
+ else:
122
+ # 1. Normalize the mapped gene expression data using known gene symbol synonyms, then save.
123
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
124
+ normalized_gene_data.to_csv(out_gene_data_file)
125
+
126
+ # 2. Load the previously extracted clinical CSV.
127
+ selected_clinical_df = pd.read_csv(out_clinical_data_file)
128
+ # If we had a single-row trait, rename row 0 to the trait name (example usage).
129
+ selected_clinical_df = selected_clinical_df.rename(index={0: trait})
130
+
131
+ # Combine these as our final clinical data; in this dataset, we only have trait info (if any).
132
+ combined_clinical_df = selected_clinical_df
133
+
134
+ # Link the clinical and genetic data by matching sample IDs in columns.
135
+ linked_data = geo_link_clinical_genetic_data(combined_clinical_df, normalized_gene_data)
136
+
137
+ # 3. Handle missing values in the linked data (drop incomplete rows/columns, then impute).
138
+ processed_data = handle_missing_values(linked_data, trait)
139
+
140
+ # 4. Check trait bias and remove any biased demographic features (if any).
141
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait)
142
+
143
+ # 5. Final validation and metadata saving.
144
+ is_usable = validate_and_save_cohort_info(
145
+ is_final=True,
146
+ cohort=cohort,
147
+ info_path=json_path,
148
+ is_gene_available=True,
149
+ is_trait_available=True,
150
+ is_biased=trait_biased,
151
+ df=processed_data,
152
+ note="Completed trait-based preprocessing."
153
+ )
154
+
155
+ # 6. If final dataset is usable, save. Otherwise, skip.
156
+ if is_usable:
157
+ processed_data.to_csv(out_data_file)
p1/preprocess/Liver_cirrhosis/code/GSE66843.py ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Liver_cirrhosis"
6
+ cohort = "GSE66843"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Liver_cirrhosis"
10
+ in_cohort_dir = "../DATA/GEO/Liver_cirrhosis/GSE66843"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Liver_cirrhosis/GSE66843.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Liver_cirrhosis/gene_data/GSE66843.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Liver_cirrhosis/clinical_data/GSE66843.csv"
16
+ json_path = "./output/preprocess/1/Liver_cirrhosis/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Determine if the dataset likely contains gene expression data
37
+ is_gene_available = True # This dataset appears to be a gene expression study (not purely miRNA/methylation).
38
+
39
+ # 2. Variable Availability and Data Type Conversion
40
+
41
+ # Since the sample characteristics only mention time points, infection status, and cell lines,
42
+ # there is no clear reference to "Liver_cirrhosis", age, or gender. Hence, data for these variables is not available.
43
+ trait_row = None
44
+ age_row = None
45
+ gender_row = None
46
+
47
+ # Define data conversion functions. Even though no data is available, we still provide them.
48
+ def convert_trait(value: str):
49
+ """Convert trait values to a numeric or binary form. Not applicable here, returns None."""
50
+ # Typically, we might parse after the colon, but there's no relevant data in this dataset.
51
+ return None
52
+
53
+ def convert_age(value: str):
54
+ """Convert age values to floats. Not applicable here, returns None."""
55
+ return None
56
+
57
+ def convert_gender(value: str):
58
+ """Convert gender values to binary (female=0, male=1). Not applicable here, returns None."""
59
+ return None
60
+
61
+ # 3. Conduct initial filtering and save metadata
62
+ is_trait_available = (trait_row is not None) # No trait data found
63
+ validate_and_save_cohort_info(
64
+ is_final=False,
65
+ cohort=cohort,
66
+ info_path=json_path,
67
+ is_gene_available=is_gene_available,
68
+ is_trait_available=is_trait_available
69
+ )
70
+
71
+ # 4. Clinical Feature Extraction: Skip because trait_row is None (meaning no clinical data is available)
72
+ # STEP3
73
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
74
+ gene_data = get_genetic_data(matrix_file)
75
+
76
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
77
+ print(gene_data.index[:20])
78
+ # They appear to be Illumina microarray probe IDs, which are not standard human gene symbols.
79
+ # Therefore, they need to be mapped to gene symbols.
80
+ requires_gene_mapping = True
81
+ # STEP5
82
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
83
+ gene_annotation = get_gene_annotation(soft_file)
84
+
85
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
86
+ print("Gene annotation preview:")
87
+ print(preview_df(gene_annotation))
88
+ # STEP: Gene Identifier Mapping
89
+
90
+ # 1. Identify the columns in the gene_annotation dataframe:
91
+ # - The column containing the probe identifiers is "ID".
92
+ # - The column containing the gene symbols is "Symbol".
93
+ mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="Symbol")
94
+
95
+ # 2. Convert probe-level expression data to gene-level data using the mapping.
96
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
97
+
98
+ # Print some information to confirm the transformation.
99
+ print("Gene expression data shape after mapping:", gene_data.shape)
100
+ print("First 20 gene symbols in the mapped data:")
101
+ print(gene_data.index[:20])
102
+ import os
103
+ import pandas as pd
104
+
105
+ # STEP 7: Data Normalization and Linking
106
+
107
+ # First, check if the clinical CSV file exists. If it does not, we cannot proceed with trait-based linking.
108
+ if not os.path.exists(out_clinical_data_file):
109
+ # No trait data file => dataset is not usable for trait analysis
110
+ df_null = pd.DataFrame()
111
+ is_biased = True # Arbitrary boolean to satisfy function requirement
112
+ validate_and_save_cohort_info(
113
+ is_final=True,
114
+ cohort=cohort,
115
+ info_path=json_path,
116
+ is_gene_available=True,
117
+ is_trait_available=False,
118
+ is_biased=is_biased,
119
+ df=df_null,
120
+ note="No trait data file found; dataset not usable for trait analysis."
121
+ )
122
+
123
+ else:
124
+ # 1. Normalize the mapped gene expression data using known gene symbol synonyms, then save.
125
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
126
+ normalized_gene_data.to_csv(out_gene_data_file)
127
+
128
+ # 2. Load the previously extracted clinical CSV.
129
+ selected_clinical_df = pd.read_csv(out_clinical_data_file)
130
+ # If we had a single-row trait, rename row 0 to the trait name (example usage).
131
+ selected_clinical_df = selected_clinical_df.rename(index={0: trait})
132
+
133
+ # Combine these as our final clinical data; in this dataset, we only have trait info (if any).
134
+ combined_clinical_df = selected_clinical_df
135
+
136
+ # Link the clinical and genetic data by matching sample IDs in columns.
137
+ linked_data = geo_link_clinical_genetic_data(combined_clinical_df, normalized_gene_data)
138
+
139
+ # 3. Handle missing values in the linked data (drop incomplete rows/columns, then impute).
140
+ processed_data = handle_missing_values(linked_data, trait)
141
+
142
+ # 4. Check trait bias and remove any biased demographic features (if any).
143
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait)
144
+
145
+ # 5. Final validation and metadata saving.
146
+ is_usable = validate_and_save_cohort_info(
147
+ is_final=True,
148
+ cohort=cohort,
149
+ info_path=json_path,
150
+ is_gene_available=True,
151
+ is_trait_available=True,
152
+ is_biased=trait_biased,
153
+ df=processed_data,
154
+ note="Completed trait-based preprocessing."
155
+ )
156
+
157
+ # 6. If final dataset is usable, save. Otherwise, skip.
158
+ if is_usable:
159
+ processed_data.to_csv(out_data_file)
p1/preprocess/Liver_cirrhosis/code/GSE85550.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Liver_cirrhosis"
6
+ cohort = "GSE85550"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Liver_cirrhosis"
10
+ in_cohort_dir = "../DATA/GEO/Liver_cirrhosis/GSE85550"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Liver_cirrhosis/GSE85550.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Liver_cirrhosis/gene_data/GSE85550.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Liver_cirrhosis/clinical_data/GSE85550.csv"
16
+ json_path = "./output/preprocess/1/Liver_cirrhosis/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1) Determine if gene expression data is available
37
+ is_gene_available = True # Based on the series title and summary, it seems to be gene expression rather than other data
38
+
39
+ # 2) Identify data availability for trait, age, and gender
40
+ # After reviewing the sample characteristics dictionary, no columns exist for these variables,
41
+ # so set them to None.
42
+ trait_row = None
43
+ age_row = None
44
+ gender_row = None
45
+
46
+ # 2) Data type conversion functions
47
+ def convert_trait(val: str):
48
+ # No actual data to parse, return None
49
+ return None
50
+
51
+ def convert_age(val: str):
52
+ # No actual data to parse, return None
53
+ return None
54
+
55
+ def convert_gender(val: str):
56
+ # No actual data to parse, return None
57
+ return None
58
+
59
+ # 3) Conduct initial filtering and save metadata
60
+ is_usable = validate_and_save_cohort_info(
61
+ is_final=False,
62
+ cohort=cohort,
63
+ info_path=json_path,
64
+ is_gene_available=is_gene_available,
65
+ is_trait_available=(trait_row is not None) # Will be False
66
+ )
67
+
68
+ # 4) Since trait_row is None, we skip clinical features extraction.
69
+ # STEP3
70
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
71
+ gene_data = get_genetic_data(matrix_file)
72
+
73
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
74
+ print(gene_data.index[:20])
75
+ # Based on biomedical knowledge, these identifiers (AARS, ABLIM1, etc.) match standard human gene symbols.
76
+ # Therefore, no additional mapping is required.
77
+ print("requires_gene_mapping = False")
78
+ import os
79
+ import pandas as pd
80
+
81
+ # STEP 7: Data Normalization and Linking
82
+
83
+ # First, check if the clinical CSV file exists. If it does not, we cannot proceed with trait-based linking.
84
+ if not os.path.exists(out_clinical_data_file):
85
+ # No trait data file => dataset is not usable for trait analysis
86
+ df_null = pd.DataFrame()
87
+ is_biased = True # Arbitrary boolean to satisfy function requirement
88
+ validate_and_save_cohort_info(
89
+ is_final=True,
90
+ cohort=cohort,
91
+ info_path=json_path,
92
+ is_gene_available=True,
93
+ is_trait_available=False,
94
+ is_biased=is_biased,
95
+ df=df_null,
96
+ note="No trait data file found; dataset not usable for trait analysis."
97
+ )
98
+
99
+ else:
100
+ # 1. Normalize the mapped gene expression data using known gene symbol synonyms, then save.
101
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
102
+ normalized_gene_data.to_csv(out_gene_data_file)
103
+
104
+ # 2. Load the previously extracted clinical CSV.
105
+ selected_clinical_df = pd.read_csv(out_clinical_data_file)
106
+ # If we had a single-row trait, rename row 0 to the trait name (example usage).
107
+ selected_clinical_df = selected_clinical_df.rename(index={0: trait})
108
+
109
+ # Combine these as our final clinical data; in this dataset, we only have trait info (if any).
110
+ combined_clinical_df = selected_clinical_df
111
+
112
+ # Link the clinical and genetic data by matching sample IDs in columns.
113
+ linked_data = geo_link_clinical_genetic_data(combined_clinical_df, normalized_gene_data)
114
+
115
+ # 3. Handle missing values in the linked data (drop incomplete rows/columns, then impute).
116
+ processed_data = handle_missing_values(linked_data, trait)
117
+
118
+ # 4. Check trait bias and remove any biased demographic features (if any).
119
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait)
120
+
121
+ # 5. Final validation and metadata saving.
122
+ is_usable = validate_and_save_cohort_info(
123
+ is_final=True,
124
+ cohort=cohort,
125
+ info_path=json_path,
126
+ is_gene_available=True,
127
+ is_trait_available=True,
128
+ is_biased=trait_biased,
129
+ df=processed_data,
130
+ note="Completed trait-based preprocessing."
131
+ )
132
+
133
+ # 6. If final dataset is usable, save. Otherwise, skip.
134
+ if is_usable:
135
+ processed_data.to_csv(out_data_file)
p1/preprocess/Liver_cirrhosis/code/TCGA.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Liver_cirrhosis"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/1/Liver_cirrhosis/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/1/Liver_cirrhosis/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/1/Liver_cirrhosis/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/1/Liver_cirrhosis/cohort_info.json"
15
+
16
+ import os
17
+ import pandas as pd
18
+
19
+ # List of subdirectories provided in the instructions:
20
+ subdirectories = [
21
+ 'CrawlData.ipynb', '.DS_Store', 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
22
+ 'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)', 'TCGA_Thymoma_(THYM)',
23
+ 'TCGA_Testicular_Cancer_(TGCT)', 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
24
+ 'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)', 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)',
25
+ 'TCGA_Pancreatic_Cancer_(PAAD)', 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
26
+ 'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)', 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)',
27
+ 'TCGA_Lung_Cancer_(LUNG)', 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
28
+ 'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)', 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)',
29
+ 'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)', 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
30
+ 'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)', 'TCGA_Endometrioid_Cancer_(UCEC)',
31
+ 'TCGA_Colon_and_Rectal_Cancer_(COADREAD)', 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
32
+ 'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)', 'TCGA_Bile_Duct_Cancer_(CHOL)',
33
+ 'TCGA_Adrenocortical_Cancer_(ACC)', 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
34
+ ]
35
+
36
+ # Synonyms for "Liver_Cancer"
37
+ liver_synonyms = ["liver_cancer", "lihc", "hepatocellular", "hcc"]
38
+
39
+ selected_subdirectory = None
40
+ for subdir in subdirectories:
41
+ subdir_lower = subdir.lower()
42
+ if any(syn in subdir_lower for syn in liver_synonyms):
43
+ selected_subdirectory = subdir
44
+ break
45
+
46
+ if not selected_subdirectory:
47
+ # If no matching directory is found, mark dataset as unavailable
48
+ is_final = False
49
+ is_gene_available = False
50
+ is_trait_available = False
51
+ _ = validate_and_save_cohort_info(
52
+ is_final=is_final,
53
+ cohort="TCGA",
54
+ info_path=json_path,
55
+ is_gene_available=is_gene_available,
56
+ is_trait_available=is_trait_available
57
+ )
58
+ print(f"No suitable directory found for '{trait}'. Skipped this trait.")
59
+ else:
60
+ # Step 2: Identify clinicalMatrix file and PANCAN file
61
+ cohort_dir = os.path.join(tcga_root_dir, selected_subdirectory)
62
+ clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
63
+
64
+ # Step 3: Load both files as dataframes
65
+ clinical_df = pd.read_csv(clinical_file_path, index_col=0, sep='\t')
66
+ genetic_df = pd.read_csv(genetic_file_path, index_col=0, sep='\t')
67
+
68
+ # Step 4: Print the column names of the clinical data
69
+ print("Clinical data columns:")
70
+ print(list(clinical_df.columns))
71
+ # Identify candidate columns
72
+ candidate_age_cols = ["age_at_initial_pathologic_diagnosis", "days_to_birth"]
73
+ candidate_gender_cols = ["gender"]
74
+
75
+ # Extract the candidate columns and preview
76
+ age_data = clinical_df[candidate_age_cols] if candidate_age_cols else pd.DataFrame()
77
+ gender_data = clinical_df[candidate_gender_cols] if candidate_gender_cols else pd.DataFrame()
78
+
79
+ print("candidate_age_cols =", candidate_age_cols)
80
+ print("candidate_gender_cols =", candidate_gender_cols)
81
+
82
+ if not age_data.empty:
83
+ age_preview = preview_df(age_data, n=5, max_items=200)
84
+ print(age_preview)
85
+
86
+ if not gender_data.empty:
87
+ gender_preview = preview_df(gender_data, n=5, max_items=200)
88
+ print(gender_preview)
89
+ # Select the best column name for age
90
+ age_col = "age_at_initial_pathologic_diagnosis"
91
+
92
+ # Select the best column name for gender
93
+ gender_col = "gender"
94
+
95
+ # Print chosen columns
96
+ print("Chosen age_col:", age_col)
97
+ print("Chosen gender_col:", gender_col)
98
+ # 1. Extract and standardize the clinical features
99
+ selected_clinical_df = tcga_select_clinical_features(
100
+ clinical_df=clinical_df,
101
+ trait=trait,
102
+ age_col=age_col,
103
+ gender_col=gender_col
104
+ )
105
+
106
+ # 2. Normalize gene symbols in the expression data and save
107
+ gene_df = normalize_gene_symbols_in_index(genetic_df)
108
+ gene_df.to_csv(out_gene_data_file)
109
+
110
+ # 3. Link clinical and genetic data
111
+ # The genetic data has samples as columns, so transpose before joining
112
+ linked_data = selected_clinical_df.join(gene_df.T, how='inner')
113
+
114
+ # 4. Handle missing values
115
+ processed_data = handle_missing_values(linked_data, trait_col=trait)
116
+
117
+ # 5. Determine and remove biased features
118
+ biased_trait, processed_data = judge_and_remove_biased_features(processed_data, trait)
119
+
120
+ # 6. Final quality validation
121
+ gene_cols = [col for col in processed_data.columns if col not in [trait, "Age", "Gender"]]
122
+ is_gene_available = len(gene_cols) > 0
123
+ is_trait_available = trait in processed_data.columns
124
+
125
+ is_usable = validate_and_save_cohort_info(
126
+ is_final=True,
127
+ cohort="TCGA",
128
+ info_path=json_path,
129
+ is_gene_available=is_gene_available,
130
+ is_trait_available=is_trait_available,
131
+ is_biased=biased_trait,
132
+ df=processed_data,
133
+ note="Final data processing for Kidney_Chromophobe"
134
+ )
135
+
136
+ # 7. Save linked data if usable
137
+ if is_usable:
138
+ processed_data.to_csv(out_data_file)
p1/preprocess/Liver_cirrhosis/cohort_info.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"GSE85550": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "No trait data file found; dataset not usable for trait analysis."}, "GSE66843": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "No trait data file found; dataset not usable for trait analysis."}, "GSE285291": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 53, "note": "Completed trait-based preprocessing."}, "GSE212047": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "No trait data file found; dataset not usable for trait analysis."}, "GSE185529": {"is_usable": false, "is_gene_available": true, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}, "GSE182065": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "No trait data file found; dataset not usable for trait analysis."}, "GSE182060": {"is_usable": false, "is_gene_available": true, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}, "GSE163211": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 318, "note": "Completed trait-based preprocessing."}, "GSE150734": {"is_usable": false, "is_gene_available": true, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}, "GSE139602": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 39, "note": "Completed trait-based preprocessing."}, "TCGA": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": true, "sample_size": 423, "note": "Final data processing for Kidney_Chromophobe"}}
p1/preprocess/Liver_cirrhosis/gene_data/GSE139602.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Liver_cirrhosis/gene_data/GSE163211.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Liver_cirrhosis/gene_data/GSE285291.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Longevity/GSE48264.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:617823e2762ef477a7226f16072e929df795347ca06664e2fec294323b21a30d
3
+ size 24533417
p1/preprocess/Longevity/clinical_data/GSE16717.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ GSM418770,GSM418771,GSM418772,GSM418773,GSM418774,GSM418775,GSM418776,GSM418777,GSM418778,GSM418779,GSM418780,GSM418781,GSM418782,GSM418783,GSM418784,GSM418785,GSM418786,GSM418787,GSM418788,GSM418789,GSM418790,GSM418791,GSM418792,GSM418793,GSM418794,GSM418795,GSM418796,GSM418797,GSM418798,GSM418799,GSM418800,GSM418801,GSM418802,GSM418803,GSM418804,GSM418805,GSM418806,GSM418807,GSM418808,GSM418809,GSM418810,GSM418811,GSM418812,GSM418813,GSM418814,GSM418815,GSM418816,GSM418817,GSM418818,GSM418819,GSM418820,GSM418821,GSM418822,GSM418823,GSM418824,GSM418825,GSM418826,GSM418827,GSM418828,GSM418829,GSM418830,GSM418831,GSM418832,GSM418833,GSM418834,GSM418835,GSM418836,GSM418837,GSM418838,GSM418839,GSM418840,GSM418841,GSM418842,GSM418843,GSM418844,GSM418845,GSM418846,GSM418847,GSM418848,GSM418849,GSM418850,GSM418851,GSM418852,GSM418853,GSM418854,GSM418855,GSM418856,GSM418857,GSM418858,GSM418859,GSM418860,GSM418861,GSM418862,GSM418863,GSM418864,GSM418865,GSM418866,GSM418867,GSM418868,GSM418869,GSM418870,GSM418871,GSM418872,GSM418873,GSM418874,GSM418875,GSM418876,GSM418877,GSM418878,GSM418879,GSM418880,GSM418881,GSM418882,GSM418883,GSM418884,GSM418885,GSM418886,GSM418887,GSM418888,GSM418889,GSM418890,GSM418891,GSM418892,GSM418893,GSM418894,GSM418895,GSM418896,GSM418897,GSM418898,GSM418899,GSM418900,GSM418901,GSM418902,GSM418903,GSM418904,GSM418905,GSM418906,GSM418907,GSM418908,GSM418909,GSM418910,GSM418911,GSM418912,GSM418913,GSM418914,GSM418915,GSM418916,GSM418917,GSM418918,GSM418919
2
+ 1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0
3
+ 91.53,56.1,91.52,52.83,64.11,64.27,59.75,93.4,61.47,93.19,90.79,53.4,96.75,101.16,98.26,54.37,58.01,59.93,60.73,92.76,62.88,69.31,90.22,89.52,63.1,56.93,91.74,90.37,94.33,60.31,64.62,63.11,89.71,64.89,63.67,54.95,92.67,99.16,93.68,96.05,66.0,56.27,64.13,70.11,59.02,61.53,91.97,56.82,72.25,68.44,91.4,60.29,62.53,58.41,73.6,60.54,54.97,59.56,56.17,102.19,62.37,61.05,98.52,60.87,55.78,61.08,68.5,92.81,61.53,73.41,57.54,62.65,62.43,65.57,62.08,90.09,70.46,61.76,62.41,91.93,92.03,94.43,65.11,61.12,60.49,63.98,91.16,61.48,60.41,58.71,66.98,54.25,92.33,71.32,65.17,58.7,97.88,61.78,65.25,90.81,51.88,91.43,61.19,92.21,91.72,96.03,49.7,61.85,47.67,93.93,72.33,57.8,93.34,54.78,74.83,92.5,69.37,92.18,57.36,60.84,55.94,58.43,89.91,78.76,91.26,89.27,63.7,57.46,94.03,61.78,59.25,62.86,64.32,66.12,96.16,51.48,56.53,48.6,95.3,66.62,66.29,43.71,42.79,91.62,63.92,97.14,66.85,68.17,92.69,94.95
4
+ 0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0
p1/preprocess/Longevity/clinical_data/GSE48264.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ GSM1173505,GSM1173506,GSM1173507,GSM1173508,GSM1173509,GSM1173510,GSM1173511,GSM1173512,GSM1173513,GSM1173514,GSM1173515,GSM1173516,GSM1173517,GSM1173518,GSM1173519,GSM1173520,GSM1173521,GSM1173522,GSM1173523,GSM1173524,GSM1173525,GSM1173526,GSM1173527,GSM1173528,GSM1173529,GSM1173530,GSM1173531,GSM1173532,GSM1173533,GSM1173534,GSM1173535,GSM1173536,GSM1173537,GSM1173538,GSM1173539,GSM1173540,GSM1173541,GSM1173542,GSM1173543,GSM1173544,GSM1173545,GSM1173546,GSM1173547,GSM1173548,GSM1173549,GSM1173550,GSM1173551,GSM1173552,GSM1173553,GSM1173554,GSM1173555,GSM1173556,GSM1173557,GSM1173558,GSM1173559,GSM1173560,GSM1173561,GSM1173562,GSM1173563,GSM1173564,GSM1173565,GSM1173566,GSM1173567,GSM1173568,GSM1173569,GSM1173570,GSM1173571,GSM1173572,GSM1173573,GSM1173574,GSM1173575,GSM1173576,GSM1173577,GSM1173578,GSM1173579,GSM1173580,GSM1173581,GSM1173582,GSM1173583,GSM1173584,GSM1173585,GSM1173586,GSM1173587,GSM1173588,GSM1173589,GSM1173590,GSM1173591,GSM1173592,GSM1173593,GSM1173594,GSM1173595,GSM1173596,GSM1173597,GSM1173598,GSM1173599,GSM1173600,GSM1173601,GSM1173602,GSM1173603,GSM1173604,GSM1173605,GSM1173606,GSM1173607,GSM1173608,GSM1173609,GSM1173610,GSM1173611,GSM1173612
2
+ 0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0
p1/preprocess/Longevity/code/GSE16717.py ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Longevity"
6
+ cohort = "GSE16717"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Longevity"
10
+ in_cohort_dir = "../DATA/GEO/Longevity/GSE16717"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Longevity/GSE16717.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Longevity/gene_data/GSE16717.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Longevity/clinical_data/GSE16717.csv"
16
+ json_path = "./output/preprocess/1/Longevity/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Gene expression data availability
37
+ is_gene_available = True # Based on the background info indicating a microarray gene expression study
38
+
39
+ # 2.1 Data Availability
40
+ trait_row = 0 # 'group: long-lived sib', 'group: control', 'group: offspring'
41
+ age_row = 2 # 'age: <float> years'
42
+ gender_row = 1 # 'gender: female', 'gender: male'
43
+
44
+ # 2.2 Data Type Conversion
45
+ def convert_trait(value: str):
46
+ """
47
+ Convert 'group: <some_value>' to binary for longevity trait:
48
+ - 'long-lived sib' -> 1
49
+ - anything else -> 0
50
+ """
51
+ try:
52
+ val = value.split(":", 1)[1].strip().lower()
53
+ except (IndexError, AttributeError):
54
+ return None
55
+ if val == "long-lived sib":
56
+ return 1
57
+ else:
58
+ # 'control' or 'offspring'
59
+ return 0
60
+
61
+ def convert_age(value: str):
62
+ """
63
+ Convert 'age: <numeric> years' to float.
64
+ """
65
+ try:
66
+ val = value.split(":", 1)[1].strip().lower()
67
+ val = val.replace("years", "").strip()
68
+ return float(val)
69
+ except:
70
+ return None
71
+
72
+ def convert_gender(value: str):
73
+ """
74
+ Convert 'gender: male/female' to binary (female=0, male=1).
75
+ """
76
+ try:
77
+ val = value.split(":", 1)[1].strip().lower()
78
+ except (IndexError, AttributeError):
79
+ return None
80
+ if val == "female":
81
+ return 0
82
+ elif val == "male":
83
+ return 1
84
+ return None
85
+
86
+ # 3. Initial filtering and save metadata
87
+ is_trait_available = (trait_row is not None)
88
+ is_usable = validate_and_save_cohort_info(
89
+ is_final=False,
90
+ cohort=cohort,
91
+ info_path=json_path,
92
+ is_gene_available=is_gene_available,
93
+ is_trait_available=is_trait_available
94
+ )
95
+
96
+ # 4. Clinical Feature Extraction if trait_row is not None
97
+ if trait_row is not None:
98
+ clinical_selected = geo_select_clinical_features(
99
+ clinical_df=clinical_data,
100
+ trait=trait,
101
+ trait_row=trait_row,
102
+ convert_trait=convert_trait,
103
+ age_row=age_row,
104
+ convert_age=convert_age,
105
+ gender_row=gender_row,
106
+ convert_gender=convert_gender
107
+ )
108
+ # Observe preview
109
+ print("Preview of selected clinical data:", preview_df(clinical_selected, n=5))
110
+ # Save extracted clinical features
111
+ clinical_selected.to_csv(out_clinical_data_file, index=False)
112
+ # STEP3
113
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
114
+ gene_data = get_genetic_data(matrix_file)
115
+
116
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
117
+ print(gene_data.index[:20])
118
+ # Because these IDs appear numeric and do not match standard human gene symbols,
119
+ # they likely require mapping to standard gene symbols.
120
+ print("requires_gene_mapping = True")
121
+ # STEP5
122
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
123
+ gene_annotation = get_gene_annotation(soft_file)
124
+
125
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
126
+ print("Gene annotation preview:")
127
+ print(preview_df(gene_annotation))
128
+ # STEP: Gene Identifier Mapping
129
+
130
+ # 1 & 2. Identify which columns store the probe IDs and which store the gene identifiers/symbols.
131
+ # From the annotation preview, "ID" matches the numeric identifiers in gene_data.index, and
132
+ # "GB_LIST" stores the accession info (which we'll treat as the "gene symbol" here).
133
+
134
+ probe_column = "ID"
135
+ gene_column = "GB_LIST"
136
+
137
+ # Extract the mapping DataFrame from the annotation
138
+ mapping_df = get_gene_mapping(
139
+ annotation=gene_annotation,
140
+ prob_col=probe_column,
141
+ gene_col=gene_column
142
+ )
143
+
144
+ # 3. Convert probe-level measurements to gene-level expressions using the mapping
145
+ gene_data = apply_gene_mapping(
146
+ expression_df=gene_data,
147
+ mapping_df=mapping_df
148
+ )
149
+
150
+ # Print a quick preview of the resulting gene_data to confirm the transformation
151
+ print("Preview of mapped gene data (columns, first few rows):")
152
+ print(gene_data.iloc[:5, :5])
153
+ import os
154
+ import pandas as pd
155
+
156
+ # STEP 7: Data Normalization and Linking
157
+
158
+ # First, check if the clinical CSV file exists. If it does not, we cannot proceed with trait-based linking.
159
+ if not os.path.exists(out_clinical_data_file):
160
+ # No trait data file => dataset is not usable for trait analysis
161
+ df_null = pd.DataFrame()
162
+ is_biased = True # Arbitrary boolean to satisfy function requirement
163
+ validate_and_save_cohort_info(
164
+ is_final=True,
165
+ cohort=cohort,
166
+ info_path=json_path,
167
+ is_gene_available=True,
168
+ is_trait_available=False,
169
+ is_biased=is_biased,
170
+ df=df_null,
171
+ note="No trait data file found; dataset not usable for trait analysis."
172
+ )
173
+
174
+ else:
175
+ # 1. Normalize the mapped gene expression data using known gene symbol synonyms, then save.
176
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
177
+
178
+ # Clean possible extra quotes/spaces in the sample IDs to match with clinical data
179
+ normalized_gene_data.columns = normalized_gene_data.columns.str.strip().str.replace('"', '')
180
+
181
+ normalized_gene_data.to_csv(out_gene_data_file)
182
+
183
+ # 2. Load the previously extracted clinical CSV, which has shape (3, #samples).
184
+ # The first row corresponds to the Longevity trait, the second to Age, the third to Gender,
185
+ # and the columns are sample IDs.
186
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, header=0)
187
+ # Remove any stray quotes/spaces from the sample IDs (the columns)
188
+ selected_clinical_df.columns = selected_clinical_df.columns.str.strip().str.replace('"', '')
189
+ # Set the row labels (index)
190
+ selected_clinical_df.index = [trait, 'Age', 'Gender']
191
+
192
+ # 3. Link clinical and genetic data by matching sample IDs in columns.
193
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
194
+
195
+ # 4. Handle missing values in the linked data (drop incomplete rows/columns, then impute).
196
+ processed_data = handle_missing_values(linked_data, trait)
197
+
198
+ # 5. Check trait bias and remove any biased demographic features (if any).
199
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait)
200
+
201
+ # 6. Final validation and metadata saving.
202
+ is_usable = validate_and_save_cohort_info(
203
+ is_final=True,
204
+ cohort=cohort,
205
+ info_path=json_path,
206
+ is_gene_available=True,
207
+ is_trait_available=True,
208
+ is_biased=trait_biased,
209
+ df=processed_data,
210
+ note="Completed trait-based preprocessing."
211
+ )
212
+
213
+ # 7. If final dataset is usable, save. Otherwise, skip.
214
+ if is_usable:
215
+ processed_data.to_csv(out_data_file)
p1/preprocess/Longevity/code/GSE44147.py ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Longevity"
6
+ cohort = "GSE44147"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Longevity"
10
+ in_cohort_dir = "../DATA/GEO/Longevity/GSE44147"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Longevity/GSE44147.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Longevity/gene_data/GSE44147.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Longevity/clinical_data/GSE44147.csv"
16
+ json_path = "./output/preprocess/1/Longevity/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ import re
37
+
38
+ # 1. Gene Expression Data Availability
39
+ is_gene_available = True # This dataset uses Affymetrix Gene ST arrays, so it likely has gene expression data.
40
+
41
+ # 2.1 & 2.2 Variable Availability and Data Type Conversion
42
+ trait_row = None # No row for longevity/trait in the dictionary
43
+ age_row = 2 # Multiple distinct values under row 2 (ex: "age: 2 days", "age: 5 days", ...)
44
+ gender_row = None # No mention of gender in the dictionary
45
+
46
+ def convert_trait(x: str):
47
+ # No trait data available
48
+ return None
49
+
50
+ def convert_age(x: str):
51
+ """
52
+ Convert 'age: X days' -> float(X).
53
+ Unknown formats return None.
54
+ """
55
+ try:
56
+ # Get the substring after the first colon
57
+ val_str = x.split(':', 1)[1].strip() # e.g. "2 days"
58
+ # Look for a numeric value
59
+ match = re.search(r'(\d+)', val_str)
60
+ if match:
61
+ return float(match.group(1))
62
+ return None
63
+ except:
64
+ return None
65
+
66
+ def convert_gender(x: str):
67
+ # No gender data available
68
+ return None
69
+
70
+ # 3. Save Metadata (Initial Filtering)
71
+ is_trait_available = (trait_row is not None)
72
+ should_continue_preprocessing = validate_and_save_cohort_info(
73
+ is_final=False,
74
+ cohort=cohort,
75
+ info_path=json_path,
76
+ is_gene_available=is_gene_available,
77
+ is_trait_available=is_trait_available
78
+ )
79
+
80
+ # 4. Clinical Feature Extraction
81
+ # Skip this step because trait_row is None (no clinical trait data available).
82
+ # STEP3
83
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
84
+ gene_data = get_genetic_data(matrix_file)
85
+
86
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
87
+ print(gene_data.index[:20])
88
+ # These numeric values appear to be probe IDs rather than standard human gene symbols.
89
+ # Hence, gene mapping is required.
90
+ print("requires_gene_mapping = True")
91
+ # STEP5
92
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
93
+ gene_annotation = get_gene_annotation(soft_file)
94
+
95
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
96
+ print("Gene annotation preview:")
97
+ print(preview_df(gene_annotation))
98
+ import re
99
+
100
+ # STEP: Gene Identifier Mapping
101
+
102
+ # We will refine the "extract_human_gene_symbols" logic to avoid picking up partial tokens like "A-".
103
+ # Instead of switching columns, we keep using "gene_assignment" but parse it more restrictively.
104
+
105
+ # 1) Define a refined extraction function with a stricter regex, so short fragments like "A-" won't match.
106
+ def extract_human_gene_symbols_refined(text: str):
107
+ """
108
+ Refine the pattern to pick up valid uppercase gene symbols (e.g., DDX11L2) while avoiding partial tokens.
109
+ """
110
+ if not isinstance(text, str):
111
+ return []
112
+ pattern = (
113
+ r"\b"
114
+ r"(?!NR_|XR_|LOC\d+|LINC\d+)" # Exclude certain prefixes
115
+ r"(?:[A-Z][A-Z0-9]{1,8}|C\d+orf\d+)" # A stricter pattern: 2-9 alphanumeric chars, or 'C\d+orf\d+'
116
+ r"\b"
117
+ )
118
+ candidates = re.findall(pattern, text)
119
+ # Exclude trivial lab terms if needed (e.g., "DNA","RNA").
120
+ exclude_simple = {"DNA", "RNA", "PCR", "EST", "CHR"}
121
+ return [x for x in candidates if x not in exclude_simple]
122
+
123
+ # 2) Wrap the apply_gene_mapping function call but override the "Gene" extraction step to use our refined extractor.
124
+ def apply_gene_mapping_refined(expression_df, mapping_df):
125
+ # Filter mapping to only those probes present in expression_df
126
+ mapping_df = mapping_df[mapping_df['ID'].isin(expression_df.index)].copy()
127
+ # Extract refined gene symbols
128
+ mapping_df['Gene'] = mapping_df['Gene'].apply(extract_human_gene_symbols_refined)
129
+ # Count number of genes per probe
130
+ mapping_df['num_genes'] = mapping_df['Gene'].apply(len)
131
+ # Expand if a probe maps to multiple genes
132
+ mapping_df = mapping_df.explode('Gene')
133
+ mapping_df = mapping_df.dropna(subset=['Gene'])
134
+ mapping_df.set_index('ID', inplace=True)
135
+
136
+ # Distribute expression values equally among the mapped genes, then sum by gene
137
+ merged_df = mapping_df.join(expression_df)
138
+ expr_cols = [col for col in merged_df.columns if col not in ['Gene', 'num_genes']]
139
+ merged_df[expr_cols] = merged_df[expr_cols].div(merged_df['num_genes'].replace(0, 1), axis=0)
140
+ gene_expression_df = merged_df.groupby('Gene')[expr_cols].sum()
141
+ return gene_expression_df
142
+
143
+ # --- Main logic starts here ---
144
+
145
+ # 1 & 2. Identify the columns in the gene annotation for probe IDs and gene symbols,
146
+ # then create the mapping dataframe.
147
+ mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="gene_assignment")
148
+
149
+ # 3. Convert probe-level measurements into gene-level expression using the refined function.
150
+ gene_data = apply_gene_mapping_refined(gene_data, mapping_df)
151
+
152
+ # Optional: View the resulting gene_data structure
153
+ print("Mapped gene_data dimensions:", gene_data.shape)
154
+ print("First 10 mapped gene symbols:", list(gene_data.index[:10]))
155
+ import os
156
+ import pandas as pd
157
+
158
+ # STEP 7: Data Normalization and Linking
159
+
160
+ # First, check if the clinical CSV file exists. If it does not, we cannot proceed with trait-based linking.
161
+ if not os.path.exists(out_clinical_data_file):
162
+ # No trait data file => dataset is not usable for trait analysis
163
+ df_null = pd.DataFrame()
164
+ is_biased = True # Arbitrary boolean to satisfy function requirement
165
+ validate_and_save_cohort_info(
166
+ is_final=True,
167
+ cohort=cohort,
168
+ info_path=json_path,
169
+ is_gene_available=True,
170
+ is_trait_available=False,
171
+ is_biased=is_biased,
172
+ df=df_null,
173
+ note="No trait data file found; dataset not usable for trait analysis."
174
+ )
175
+
176
+ else:
177
+ # 1. Normalize the mapped gene expression data using known gene symbol synonyms, then save.
178
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
179
+ normalized_gene_data.to_csv(out_gene_data_file)
180
+
181
+ # 2. Load the previously extracted clinical CSV.
182
+ selected_clinical_df = pd.read_csv(out_clinical_data_file)
183
+ # If we had a single-row trait, rename row 0 to the trait name (example usage).
184
+ selected_clinical_df = selected_clinical_df.rename(index={0: trait})
185
+
186
+ # Combine these as our final clinical data; in this dataset, we only have trait info (if any).
187
+ combined_clinical_df = selected_clinical_df
188
+
189
+ # Link the clinical and genetic data by matching sample IDs in columns.
190
+ linked_data = geo_link_clinical_genetic_data(combined_clinical_df, normalized_gene_data)
191
+
192
+ # 3. Handle missing values in the linked data (drop incomplete rows/columns, then impute).
193
+ processed_data = handle_missing_values(linked_data, trait)
194
+
195
+ # 4. Check trait bias and remove any biased demographic features (if any).
196
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait)
197
+
198
+ # 5. Final validation and metadata saving.
199
+ is_usable = validate_and_save_cohort_info(
200
+ is_final=True,
201
+ cohort=cohort,
202
+ info_path=json_path,
203
+ is_gene_available=True,
204
+ is_trait_available=True,
205
+ is_biased=trait_biased,
206
+ df=processed_data,
207
+ note="Completed trait-based preprocessing."
208
+ )
209
+
210
+ # 6. If final dataset is usable, save. Otherwise, skip.
211
+ if is_usable:
212
+ processed_data.to_csv(out_data_file)
p1/preprocess/Longevity/code/GSE48264.py ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Longevity"
6
+ cohort = "GSE48264"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Longevity"
10
+ in_cohort_dir = "../DATA/GEO/Longevity/GSE48264"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Longevity/GSE48264.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Longevity/gene_data/GSE48264.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Longevity/clinical_data/GSE48264.csv"
16
+ json_path = "./output/preprocess/1/Longevity/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Determine if the dataset likely has gene expression data.
37
+ # From the background info, they used Affymetrix gene-chips, so it has gene expression data.
38
+ is_gene_available = True
39
+
40
+ # 2.1 Identify data availability for trait, age, and gender.
41
+ # - Trait ("Longevity") can be inferred from row 3, which has unique values: "None", "Hosp", "Death".
42
+ # These are not constant, so trait_row = 3.
43
+ # - Age data appears to be row 1 ("age(approx): 70 yr"), but since everyone is ~70 (only one unique value),
44
+ # it's effectively constant => not useful. age_row = None.
45
+ # - Gender is not explicitly listed, but from the study background, all subjects were men (no variation),
46
+ # so gender_row = None.
47
+
48
+ trait_row = 3
49
+ age_row = None
50
+ gender_row = None
51
+
52
+ # 2.2 Write conversion functions for the variables.
53
+ def convert_trait(value: str):
54
+ """
55
+ Convert the 'survival' field to a binary variable.
56
+ 'Death' -> 1, 'Hosp' or 'None' -> 0, otherwise -> None
57
+ """
58
+ parts = value.split(":", 1)
59
+ if len(parts) < 2:
60
+ return None
61
+ val = parts[1].strip().lower()
62
+ if val == "death":
63
+ return 1
64
+ elif val in ["none", "hosp"]:
65
+ return 0
66
+ else:
67
+ return None
68
+
69
+ def convert_age(value: str):
70
+ """
71
+ Since age data is effectively constant (~70 yr),
72
+ we won't use it. But here's a placeholder that attempts
73
+ to parse numerical age if needed.
74
+ """
75
+ return None # Ignored because age_row is None
76
+
77
+ def convert_gender(value: str):
78
+ """
79
+ All subjects are men (constant), so there's no variation.
80
+ Return None for demonstration.
81
+ """
82
+ return None
83
+
84
+ # 3. Conduct initial filtering using 'validate_and_save_cohort_info'.
85
+ # Trait data is considered available if trait_row is not None.
86
+ is_trait_available = (trait_row is not None)
87
+ is_usable = validate_and_save_cohort_info(
88
+ is_final=False,
89
+ cohort=cohort,
90
+ info_path=json_path,
91
+ is_gene_available=is_gene_available,
92
+ is_trait_available=is_trait_available
93
+ )
94
+
95
+ # 4. If trait_row is not None, extract clinical features and preview/save the clinical DataFrame.
96
+ if trait_row is not None:
97
+ selected_clinical_df = geo_select_clinical_features(
98
+ clinical_df=clinical_data,
99
+ trait=trait,
100
+ trait_row=trait_row,
101
+ convert_trait=convert_trait,
102
+ age_row=age_row,
103
+ convert_age=convert_age,
104
+ gender_row=gender_row,
105
+ convert_gender=convert_gender
106
+ )
107
+ preview = preview_df(selected_clinical_df, n=5)
108
+ print("Preview of selected clinical features:", preview)
109
+
110
+ # Save the clinical DataFrame
111
+ selected_clinical_df.to_csv(out_clinical_data_file, index=False)
112
+ # STEP3
113
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
114
+ gene_data = get_genetic_data(matrix_file)
115
+
116
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
117
+ print(gene_data.index[:20])
118
+ # Based on the numeric pattern (e.g., '2315251'), they are not standard human gene symbols.
119
+ # They appear to be probe IDs that require mapping to gene symbols.
120
+ print("They appear to be non-standard numeric IDs from a microarray platform.")
121
+ print("requires_gene_mapping = True")
122
+ # STEP5
123
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
124
+ gene_annotation = get_gene_annotation(soft_file)
125
+
126
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
127
+ print("Gene annotation preview:")
128
+ print(preview_df(gene_annotation))
129
+ # STEP: Gene Identifier Mapping
130
+
131
+ # 1. Determine the columns in the annotation dataframe that correspond to the probe identifiers and the gene symbols.
132
+ # From inspection, the "ID" column matches the probe IDs (same format as in gene_data.index),
133
+ # and "gene_assignment" contains strings from which we can parse gene symbols.
134
+
135
+ # 2. Get the gene mapping dataframe using the get_gene_mapping function.
136
+ # We specify prob_col='ID' and gene_col='gene_assignment'.
137
+ mapping_df = get_gene_mapping(
138
+ annotation=gene_annotation,
139
+ prob_col='ID',
140
+ gene_col='gene_assignment'
141
+ )
142
+
143
+ # 3. Apply the mapping to convert probe-level data to gene-level data.
144
+ gene_data = apply_gene_mapping(
145
+ expression_df=gene_data,
146
+ mapping_df=mapping_df
147
+ )
148
+ import os
149
+ import pandas as pd
150
+
151
+ # STEP 7: Data Normalization and Linking
152
+
153
+ # First, check if the clinical CSV file exists. If it does not, we cannot proceed with trait-based linking.
154
+ if not os.path.exists(out_clinical_data_file):
155
+ # No trait data file => dataset is not usable for trait analysis
156
+ df_null = pd.DataFrame()
157
+ is_biased = True # Arbitrary boolean to satisfy function requirement
158
+ validate_and_save_cohort_info(
159
+ is_final=True,
160
+ cohort=cohort,
161
+ info_path=json_path,
162
+ is_gene_available=True,
163
+ is_trait_available=False,
164
+ is_biased=is_biased,
165
+ df=df_null,
166
+ note="No trait data file found; dataset not usable for trait analysis."
167
+ )
168
+
169
+ else:
170
+ # 1. Normalize the mapped gene expression data using known gene symbol synonyms, then save.
171
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
172
+ normalized_gene_data.to_csv(out_gene_data_file)
173
+
174
+ # 2. Load the previously extracted clinical CSV.
175
+ selected_clinical_df = pd.read_csv(out_clinical_data_file)
176
+ # If we had a single-row trait, rename row 0 to the trait name (example usage).
177
+ selected_clinical_df = selected_clinical_df.rename(index={0: trait})
178
+
179
+ # Combine these as our final clinical data; in this dataset, we only have trait info (if any).
180
+ combined_clinical_df = selected_clinical_df
181
+
182
+ # Link the clinical and genetic data by matching sample IDs in columns.
183
+ linked_data = geo_link_clinical_genetic_data(combined_clinical_df, normalized_gene_data)
184
+
185
+ # 3. Handle missing values in the linked data (drop incomplete rows/columns, then impute).
186
+ processed_data = handle_missing_values(linked_data, trait)
187
+
188
+ # 4. Check trait bias and remove any biased demographic features (if any).
189
+ trait_biased, processed_data = judge_and_remove_biased_features(processed_data, trait)
190
+
191
+ # 5. Final validation and metadata saving.
192
+ is_usable = validate_and_save_cohort_info(
193
+ is_final=True,
194
+ cohort=cohort,
195
+ info_path=json_path,
196
+ is_gene_available=True,
197
+ is_trait_available=True,
198
+ is_biased=trait_biased,
199
+ df=processed_data,
200
+ note="Completed trait-based preprocessing."
201
+ )
202
+
203
+ # 6. If final dataset is usable, save. Otherwise, skip.
204
+ if is_usable:
205
+ processed_data.to_csv(out_data_file)
p1/preprocess/Longevity/code/TCGA.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Longevity"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/1/Longevity/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/1/Longevity/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/1/Longevity/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/1/Longevity/cohort_info.json"
15
+
16
+ import os
17
+ import pandas as pd
18
+
19
+ # List of subdirectories provided in the instructions:
20
+ subdirectories = [
21
+ 'CrawlData.ipynb', '.DS_Store', 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
22
+ 'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)', 'TCGA_Thymoma_(THYM)',
23
+ 'TCGA_Testicular_Cancer_(TGCT)', 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
24
+ 'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)', 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)',
25
+ 'TCGA_Pancreatic_Cancer_(PAAD)', 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
26
+ 'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)', 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)',
27
+ 'TCGA_Lung_Cancer_(LUNG)', 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
28
+ 'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)', 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)',
29
+ 'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)', 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
30
+ 'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)', 'TCGA_Endometrioid_Cancer_(UCEC)',
31
+ 'TCGA_Colon_and_Rectal_Cancer_(COADREAD)', 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
32
+ 'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)', 'TCGA_Bile_Duct_Cancer_(CHOL)',
33
+ 'TCGA_Adrenocortical_Cancer_(ACC)', 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
34
+ ]
35
+
36
+ # Possible synonyms or related terms for "Longevity"
37
+ longevity_synonyms = ["longevity", "long_life", "lifespan"]
38
+
39
+ selected_subdirectory = None
40
+ for subdir in subdirectories:
41
+ subdir_lower = subdir.lower()
42
+ if any(syn in subdir_lower for syn in longevity_synonyms):
43
+ selected_subdirectory = subdir
44
+ break
45
+
46
+ if not selected_subdirectory:
47
+ # If no matching directory is found, mark dataset as unavailable
48
+ is_final = False
49
+ is_gene_available = False
50
+ is_trait_available = False
51
+ _ = validate_and_save_cohort_info(
52
+ is_final=is_final,
53
+ cohort="TCGA",
54
+ info_path=json_path,
55
+ is_gene_available=is_gene_available,
56
+ is_trait_available=is_trait_available
57
+ )
58
+ print(f"No suitable directory found for '{trait}'. Skipped this trait.")
59
+ else:
60
+ # Step 2: Identify clinicalMatrix file and PANCAN file
61
+ cohort_dir = os.path.join(tcga_root_dir, selected_subdirectory)
62
+ clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
63
+
64
+ # Step 3: Load both files as dataframes
65
+ clinical_df = pd.read_csv(clinical_file_path, index_col=0, sep='\t')
66
+ genetic_df = pd.read_csv(genetic_file_path, index_col=0, sep='\t')
67
+
68
+ # Step 4: Print the column names of the clinical data
69
+ print("Clinical data columns:")
70
+ print(list(clinical_df.columns))
p1/preprocess/Longevity/cohort_info.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"GSE48264": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 108, "note": "Completed trait-based preprocessing."}, "GSE44147": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "No trait data file found; dataset not usable for trait analysis."}, "GSE16717": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "Completed trait-based preprocessing."}, "TCGA": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}}
p1/preprocess/Longevity/gene_data/GSE16717.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ Gene,GSM418770,GSM418771,GSM418772,GSM418773,GSM418774,GSM418775,GSM418776,GSM418777,GSM418778,GSM418779,GSM418780,GSM418781,GSM418782,GSM418783,GSM418784,GSM418785,GSM418786,GSM418787,GSM418788,GSM418789,GSM418790,GSM418791,GSM418792,GSM418793,GSM418794,GSM418795,GSM418796,GSM418797,GSM418798,GSM418799,GSM418800,GSM418801,GSM418802,GSM418803,GSM418804,GSM418805,GSM418806,GSM418807,GSM418808,GSM418809,GSM418810,GSM418811,GSM418812,GSM418813,GSM418814,GSM418815,GSM418816,GSM418817,GSM418818,GSM418819,GSM418820,GSM418821,GSM418822,GSM418823,GSM418824,GSM418825,GSM418826,GSM418827,GSM418828,GSM418829,GSM418830,GSM418831,GSM418832,GSM418833,GSM418834,GSM418835,GSM418836,GSM418837,GSM418838,GSM418839,GSM418840,GSM418841,GSM418842,GSM418843,GSM418844,GSM418845,GSM418846,GSM418847,GSM418848,GSM418849,GSM418850,GSM418851,GSM418852,GSM418853,GSM418854,GSM418855,GSM418856,GSM418857,GSM418858,GSM418859,GSM418860,GSM418861,GSM418862,GSM418863,GSM418864,GSM418865,GSM418866,GSM418867,GSM418868,GSM418869,GSM418870,GSM418871,GSM418872,GSM418873,GSM418874,GSM418875,GSM418876,GSM418877,GSM418878,GSM418879,GSM418880,GSM418881,GSM418882,GSM418883,GSM418884,GSM418885,GSM418886,GSM418887,GSM418888,GSM418889,GSM418890,GSM418891,GSM418892,GSM418893,GSM418894,GSM418895,GSM418896,GSM418897,GSM418898,GSM418899,GSM418900,GSM418901,GSM418902,GSM418903,GSM418904,GSM418905,GSM418906,GSM418907,GSM418908,GSM418909,GSM418910,GSM418911,GSM418912,GSM418913,GSM418914,GSM418915,GSM418916,GSM418917,GSM418918,GSM418919
p1/preprocess/Longevity/gene_data/GSE48264.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:97e26e70c844e19c2302a4083e91376c2addf302fddfee387f4b506b50e6615e
3
+ size 24532979
p1/preprocess/Lower_Grade_Glioma/GSE24072.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Lower_Grade_Glioma/clinical_data/GSE24072.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ GSM590744,GSM590745,GSM590746,GSM590747,GSM590748,GSM591700,GSM591701,GSM591702,GSM591703,GSM591704,GSM591705,GSM591706,GSM591707,GSM591722,GSM591792,GSM591793,GSM591796,GSM591798,GSM591800,GSM591808,GSM591809,GSM591811,GSM591812,GSM591815,GSM591817,GSM591818,GSM591819,GSM591829,GSM591830,GSM591831,GSM591832,GSM591833
2
+ 1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0
3
+ 72.0,70.0,34.0,54.0,34.0,68.0,30.0,60.0,73.0,52.0,65.0,70.0,76.0,51.0,73.0,70.0,43.0,67.0,66.0,69.0,74.0,43.0,69.0,36.0,38.0,63.0,74.0,67.0,54.0,46.0,55.0,72.0
4
+ 1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0