Liu-Hy commited on
Commit
5bd5338
·
verified ·
1 Parent(s): ff3b0fa

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 +26 -0
  2. p3/preprocess/Depression/gene_data/TCGA.csv +3 -0
  3. p3/preprocess/Endometriosis/TCGA.csv +3 -0
  4. p3/preprocess/Endometriosis/gene_data/TCGA.csv +3 -0
  5. p3/preprocess/Epilepsy/gene_data/GSE123993.csv +3 -0
  6. p3/preprocess/Epilepsy/gene_data/GSE143272.csv +3 -0
  7. p3/preprocess/Epilepsy/gene_data/GSE29796.csv +3 -0
  8. p3/preprocess/Epilepsy/gene_data/GSE65106.csv +3 -0
  9. p3/preprocess/Epilepsy/gene_data/GSE74571.csv +3 -0
  10. p3/preprocess/Esophageal_Cancer/GSE100843.csv +3 -0
  11. p3/preprocess/Esophageal_Cancer/GSE75241.csv +3 -0
  12. p3/preprocess/Esophageal_Cancer/TCGA.csv +3 -0
  13. p3/preprocess/Esophageal_Cancer/clinical_data/GSE75241.csv +2 -0
  14. p3/preprocess/Esophageal_Cancer/clinical_data/GSE77790.csv +34 -0
  15. p3/preprocess/Esophageal_Cancer/code/GSE100843.py +158 -0
  16. p3/preprocess/Esophageal_Cancer/code/GSE104958.py +147 -0
  17. p3/preprocess/Esophageal_Cancer/code/GSE107754.py +167 -0
  18. p3/preprocess/Esophageal_Cancer/code/GSE131027.py +152 -0
  19. p3/preprocess/Esophageal_Cancer/code/GSE156915.py +144 -0
  20. p3/preprocess/Esophageal_Cancer/code/GSE218109.py +187 -0
  21. p3/preprocess/Esophageal_Cancer/code/GSE55857.py +99 -0
  22. p3/preprocess/Esophageal_Cancer/code/GSE66258.py +90 -0
  23. p3/preprocess/Esophageal_Cancer/code/GSE75241.py +160 -0
  24. p3/preprocess/Esophageal_Cancer/code/GSE77790.py +227 -0
  25. p3/preprocess/Esophageal_Cancer/code/TCGA.py +115 -0
  26. p3/preprocess/Esophageal_Cancer/gene_data/GSE100843.csv +3 -0
  27. p3/preprocess/Esophageal_Cancer/gene_data/GSE104958.csv +3 -0
  28. p3/preprocess/Esophageal_Cancer/gene_data/GSE107754.csv +3 -0
  29. p3/preprocess/Esophageal_Cancer/gene_data/GSE131027.csv +3 -0
  30. p3/preprocess/Esophageal_Cancer/gene_data/GSE218109.csv +1 -0
  31. p3/preprocess/Esophageal_Cancer/gene_data/GSE75241.csv +3 -0
  32. p3/preprocess/Esophageal_Cancer/gene_data/GSE77790.csv +1 -0
  33. p3/preprocess/Esophageal_Cancer/gene_data/TCGA.csv +3 -0
  34. p3/preprocess/Essential_Thrombocythemia/GSE103237.csv +0 -0
  35. p3/preprocess/Essential_Thrombocythemia/GSE12295.csv +0 -0
  36. p3/preprocess/Essential_Thrombocythemia/GSE159514.csv +3 -0
  37. p3/preprocess/Essential_Thrombocythemia/GSE174060.csv +0 -0
  38. p3/preprocess/Essential_Thrombocythemia/GSE55976.csv +0 -0
  39. p3/preprocess/Essential_Thrombocythemia/GSE57793.csv +3 -0
  40. p3/preprocess/Essential_Thrombocythemia/GSE61629.csv +0 -0
  41. p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE103176.csv +3 -0
  42. p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE103237.csv +3 -0
  43. p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE12295.csv +2 -0
  44. p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE159514.csv +2 -0
  45. p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE174060.csv +4 -0
  46. p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE55976.csv +2 -0
  47. p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE57793.csv +2 -0
  48. p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE61629.csv +2 -0
  49. p3/preprocess/Essential_Thrombocythemia/code/GSE103176.py +232 -0
  50. p3/preprocess/Essential_Thrombocythemia/code/GSE103237.py +172 -0
.gitattributes CHANGED
@@ -1664,3 +1664,29 @@ p3/preprocess/Endometriosis/GSE51981.csv filter=lfs diff=lfs merge=lfs -text
1664
  p3/preprocess/Breast_Cancer/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1665
  p3/preprocess/Epilepsy/GSE65106.csv filter=lfs diff=lfs merge=lfs -text
1666
  p3/preprocess/Endometriosis/gene_data/GSE51981.csv filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1664
  p3/preprocess/Breast_Cancer/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1665
  p3/preprocess/Epilepsy/GSE65106.csv filter=lfs diff=lfs merge=lfs -text
1666
  p3/preprocess/Endometriosis/gene_data/GSE51981.csv filter=lfs diff=lfs merge=lfs -text
1667
+ p3/preprocess/Epilepsy/gene_data/GSE143272.csv filter=lfs diff=lfs merge=lfs -text
1668
+ p3/preprocess/Epilepsy/gene_data/GSE29796.csv filter=lfs diff=lfs merge=lfs -text
1669
+ p3/preprocess/Epilepsy/gene_data/GSE123993.csv filter=lfs diff=lfs merge=lfs -text
1670
+ p3/preprocess/Epilepsy/gene_data/GSE74571.csv filter=lfs diff=lfs merge=lfs -text
1671
+ p3/preprocess/Endometriosis/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1672
+ p3/preprocess/Epilepsy/gene_data/GSE65106.csv filter=lfs diff=lfs merge=lfs -text
1673
+ p3/preprocess/Esophageal_Cancer/GSE75241.csv filter=lfs diff=lfs merge=lfs -text
1674
+ p3/preprocess/Esophageal_Cancer/GSE100843.csv filter=lfs diff=lfs merge=lfs -text
1675
+ p3/preprocess/Esophageal_Cancer/gene_data/GSE104958.csv filter=lfs diff=lfs merge=lfs -text
1676
+ p3/preprocess/Esophageal_Cancer/gene_data/GSE75241.csv filter=lfs diff=lfs merge=lfs -text
1677
+ p3/preprocess/Endometriosis/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1678
+ p3/preprocess/Esophageal_Cancer/gene_data/GSE107754.csv filter=lfs diff=lfs merge=lfs -text
1679
+ p3/preprocess/Depression/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1680
+ p3/preprocess/Esophageal_Cancer/gene_data/GSE131027.csv filter=lfs diff=lfs merge=lfs -text
1681
+ p3/preprocess/Esophageal_Cancer/gene_data/GSE100843.csv filter=lfs diff=lfs merge=lfs -text
1682
+ p3/preprocess/Essential_Thrombocythemia/GSE57793.csv filter=lfs diff=lfs merge=lfs -text
1683
+ p3/preprocess/Essential_Thrombocythemia/GSE159514.csv filter=lfs diff=lfs merge=lfs -text
1684
+ p3/preprocess/Essential_Thrombocythemia/gene_data/GSE103237.csv filter=lfs diff=lfs merge=lfs -text
1685
+ p3/preprocess/Esophageal_Cancer/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1686
+ p3/preprocess/Essential_Thrombocythemia/gene_data/GSE174060.csv filter=lfs diff=lfs merge=lfs -text
1687
+ p3/preprocess/Essential_Thrombocythemia/gene_data/GSE61629.csv filter=lfs diff=lfs merge=lfs -text
1688
+ p3/preprocess/Essential_Thrombocythemia/gene_data/GSE57793.csv filter=lfs diff=lfs merge=lfs -text
1689
+ p3/preprocess/Gastroesophageal_reflux_disease_(GERD)/GSE77563.csv filter=lfs diff=lfs merge=lfs -text
1690
+ p3/preprocess/Esophageal_Cancer/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1691
+ p3/preprocess/Essential_Thrombocythemia/gene_data/GSE159514.csv filter=lfs diff=lfs merge=lfs -text
1692
+ p3/preprocess/Gastroesophageal_reflux_disease_(GERD)/gene_data/GSE77563.csv filter=lfs diff=lfs merge=lfs -text
p3/preprocess/Depression/gene_data/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca538730424e09dc117dcbf2b9e361e18a559838fbd5166c65c39e001c215c63
3
+ size 203622702
p3/preprocess/Endometriosis/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d538e2fa52d08a897bcadf0285184ced6ecddc85d6df602208a912847e060e62
3
+ size 60336942
p3/preprocess/Endometriosis/gene_data/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:965772a8ddafe3b0baec55f80b0a37ac57d1cd394c3678a057598d5b214d2edd
3
+ size 60335341
p3/preprocess/Epilepsy/gene_data/GSE123993.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6111dad1e9f5abfbe6f2768c0cd1c1fd1396db43109b545e718dd54b7561f133
3
+ size 15123583
p3/preprocess/Epilepsy/gene_data/GSE143272.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:11b9d688b7c816f77cf4cb2f913fd2d0be6ab7c38198dfa9f4153f033b3e7172
3
+ size 15847932
p3/preprocess/Epilepsy/gene_data/GSE29796.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4edf231b1d6038cad00622845fdb6c06ada9b682c6e46af24a4183d565ff6de6
3
+ size 13410616
p3/preprocess/Epilepsy/gene_data/GSE65106.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ba36a56836f25c628cc7f6721d0b891f0a8f089e9041023fa41adfb38bdd2025
3
+ size 19281941
p3/preprocess/Epilepsy/gene_data/GSE74571.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e3535ea344d801f0a42c2294e42f2c4bbe0172e4fea404df54a5023c9f660e27
3
+ size 13432589
p3/preprocess/Esophageal_Cancer/GSE100843.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b9ae145a287823aa97d5f48d34d16a26f80bf7eb489589fc5ef77762366253c0
3
+ size 28263365
p3/preprocess/Esophageal_Cancer/GSE75241.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d70e298eaa7828d17ecd5e325101e457c0b1cf249b7153159f1a38ee94c5b101
3
+ size 18208964
p3/preprocess/Esophageal_Cancer/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2e2f33cc80d4aeb14bac98c498ad2d717e0b6ff3d595627015351df73746975e
3
+ size 58742434
p3/preprocess/Esophageal_Cancer/clinical_data/GSE75241.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM1946756,GSM1946757,GSM1946758,GSM1946759,GSM1946760,GSM1946761,GSM1946762,GSM1946763,GSM1946764,GSM1946765,GSM1946766,GSM1946767,GSM1946768,GSM1946769,GSM1946770,GSM1946771,GSM1946772,GSM1946773,GSM1946774,GSM1946775,GSM1946776,GSM1946777,GSM1946778,GSM1946779,GSM1946780,GSM1946781,GSM1946782,GSM1946783,GSM1946784,GSM1946785
2
+ Esophageal_Cancer,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0
p3/preprocess/Esophageal_Cancer/clinical_data/GSE77790.csv ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ,Esophageal_Cancer
2
+ !Sample_geo_accession,0
3
+ GSM2059404,0
4
+ GSM2059405,0
5
+ GSM2059406,0
6
+ GSM2059407,0
7
+ GSM2059408,0
8
+ GSM2059409,0
9
+ GSM2059410,0
10
+ GSM2059411,0
11
+ GSM2059412,0
12
+ GSM2059413,0
13
+ GSM2059414,0
14
+ GSM2059415,0
15
+ GSM2059416,0
16
+ GSM2059417,0
17
+ GSM2059418,0
18
+ GSM2059419,0
19
+ GSM2059420,0
20
+ GSM2059421,0
21
+ GSM2059422,0
22
+ GSM2059423,0
23
+ GSM2059424,0
24
+ GSM2059425,0
25
+ GSM2059426,0
26
+ GSM2059427,0
27
+ GSM2059428,0
28
+ GSM2059429,0
29
+ GSM2059430,1
30
+ GSM2059431,1
31
+ GSM2059432,0
32
+ GSM2059433,0
33
+ GSM2059434,0
34
+ GSM2059435,0
p3/preprocess/Esophageal_Cancer/code/GSE100843.py ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Esophageal_Cancer"
6
+ cohort = "GSE100843"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Esophageal_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Esophageal_Cancer/GSE100843"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Esophageal_Cancer/GSE100843.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Esophageal_Cancer/gene_data/GSE100843.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Esophageal_Cancer/clinical_data/GSE100843.csv"
16
+ json_path = "./output/preprocess/3/Esophageal_Cancer/cohort_info.json"
17
+
18
+ # Get relevant file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data from the matrix file
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get dictionary of unique values per row in clinical data
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Background Information:")
29
+ print("-" * 50)
30
+ print(background_info)
31
+ print("\n")
32
+
33
+ # Print clinical data unique values
34
+ print("Sample Characteristics:")
35
+ print("-" * 50)
36
+ for row, values in unique_values_dict.items():
37
+ print(f"{row}:")
38
+ print(f" {values}")
39
+ print()
40
+ # 1. Gene Expression Data Availability
41
+ # From background info, this is a microarray gene expression dataset
42
+ is_gene_available = True
43
+
44
+ # 2. Variable Availability and Data Type Conversion
45
+ # Trait (Barrett's esophagus):
46
+ # Available in field 0 as tissue type, where IM indicates disease and NSQ indicates normal
47
+ trait_row = 0
48
+ def convert_trait(value: str) -> int:
49
+ if not value or ':' not in value:
50
+ return None
51
+ value = value.split(':')[1].strip().lower()
52
+ if "barrett" in value:
53
+ return 1 # Disease tissue
54
+ elif "normal" in value:
55
+ return 0 # Normal tissue
56
+ return None
57
+
58
+ # Age: Not available in characteristics
59
+ age_row = None
60
+ convert_age = None
61
+
62
+ # Gender: Not available in characteristics
63
+ gender_row = None
64
+ convert_gender = None
65
+
66
+ # 3. Save metadata
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=(trait_row is not None)
73
+ )
74
+
75
+ # 4. Extract clinical features
76
+ if trait_row is not None:
77
+ selected_clinical = 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
+
88
+ # Preview the selected features
89
+ print("Preview of selected clinical features:")
90
+ print(preview_df(selected_clinical))
91
+
92
+ # Save to CSV
93
+ selected_clinical.to_csv(out_clinical_data_file)
94
+ # Extract gene expression data
95
+ genetic_data = get_genetic_data(matrix_file_path)
96
+
97
+ # Print first 20 probe IDs
98
+ print("First 20 probe IDs:")
99
+ print(genetic_data.index[:20])
100
+ # The probe IDs are numeric identifiers from an Illumina array, not standard gene symbols
101
+ # They need to be mapped to proper human gene symbols
102
+ requires_gene_mapping = True
103
+ # Extract gene annotation from SOFT file
104
+ gene_annotation = get_gene_annotation(soft_file_path)
105
+
106
+ # Preview column names and first few values
107
+ preview_dict = preview_df(gene_annotation)
108
+ print("Column names and preview values:")
109
+ for col, values in preview_dict.items():
110
+ print(f"\n{col}:")
111
+ print(values)
112
+ # Extract mapping between probe IDs and gene symbols
113
+ mapping_data = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='gene_assignment')
114
+
115
+ # Apply gene mapping to convert probe-level data to gene-level data
116
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
117
+
118
+ # Save the gene expression data
119
+ gene_data.to_csv(out_gene_data_file)
120
+ # Read the gene data that was saved in previous step
121
+ gene_data = pd.read_csv(out_gene_data_file, index_col=0)
122
+
123
+ # 1. Normalize gene symbols and save normalized gene data
124
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
125
+ normalized_gene_data.to_csv(out_gene_data_file)
126
+
127
+ # Read the processed clinical and gene data files
128
+ clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
129
+ gene_data = pd.read_csv(out_gene_data_file, index_col=0)
130
+
131
+ # Link clinical and genetic data
132
+ linked_data = geo_link_clinical_genetic_data(clinical_df, gene_data)
133
+
134
+ # Handle missing values systematically
135
+ linked_data = handle_missing_values(linked_data, trait)
136
+
137
+ # Detect bias in trait and demographic features, remove biased demographic features
138
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
139
+
140
+ # Validate data quality and save cohort info
141
+ note = ("This dataset studies gene expression profiles in esophageal squamous cell carcinoma, "
142
+ "comparing tumor samples with matched nonmalignant mucosa. The sample size is moderate with paired samples.")
143
+ is_usable = validate_and_save_cohort_info(
144
+ is_final=True,
145
+ cohort=cohort,
146
+ info_path=json_path,
147
+ is_gene_available=True,
148
+ is_trait_available=True,
149
+ is_biased=is_biased,
150
+ df=linked_data,
151
+ note=note
152
+ )
153
+
154
+ # Save linked data if usable
155
+ if is_usable:
156
+ linked_data.to_csv(out_data_file)
157
+ else:
158
+ print(f"Dataset {cohort} did not pass quality validation and will not be saved.")
p3/preprocess/Esophageal_Cancer/code/GSE104958.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Esophageal_Cancer"
6
+ cohort = "GSE104958"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Esophageal_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Esophageal_Cancer/GSE104958"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Esophageal_Cancer/GSE104958.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Esophageal_Cancer/gene_data/GSE104958.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Esophageal_Cancer/clinical_data/GSE104958.csv"
16
+ json_path = "./output/preprocess/3/Esophageal_Cancer/cohort_info.json"
17
+
18
+ # Get relevant file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data from the matrix file
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get dictionary of unique values per row in clinical data
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Background Information:")
29
+ print("-" * 50)
30
+ print(background_info)
31
+ print("\n")
32
+
33
+ # Print clinical data unique values
34
+ print("Sample Characteristics:")
35
+ print("-" * 50)
36
+ for row, values in unique_values_dict.items():
37
+ print(f"{row}:")
38
+ print(f" {values}")
39
+ print()
40
+ # 1. Gene Expression Data Availability
41
+ # Based on the background info mentioning "DNA microarray data", this dataset contains gene expression data
42
+ is_gene_available = True
43
+
44
+ # 2. Variable Availability and Data Type Conversion
45
+ # 2.1 Data Availability
46
+ # Trait (pCR status) is not directly available in sample characteristics,
47
+ # but needs to be inferred from RNA IDs in a later step
48
+ trait_row = None # Not available in sample characteristics
49
+ age_row = None # Age data not available
50
+ gender_row = None # Gender data not available
51
+
52
+ # 2.2 Data Type Conversion Functions
53
+ def convert_trait(value):
54
+ # Get sample ID from string
55
+ if not isinstance(value, str):
56
+ return None
57
+ try:
58
+ # Extract RNA sample number from identifiers
59
+ rna_id = int(''.join(filter(str.isdigit, value)))
60
+ # Check if RNA ID is in pCR group based on background info
61
+ pcr_samples = [1, 4, 7, 10, 12, 17, 24, 29, 35, 43]
62
+ return 1 if rna_id in pcr_samples else 0
63
+ except:
64
+ return None
65
+
66
+ # Age and gender conversion functions not needed since data unavailable
67
+ convert_age = None
68
+ convert_gender = None
69
+
70
+ # 3. Save initial metadata
71
+ is_trait_available = trait_row is not None
72
+ 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 skipped since trait_row is None
81
+ # Extract gene expression data
82
+ genetic_data = get_genetic_data(matrix_file_path)
83
+
84
+ # Print first 20 probe IDs
85
+ print("First 20 probe IDs:")
86
+ print(genetic_data.index[:20])
87
+ # These identifiers appear to be probe IDs from a microarray/RNA-seq platform
88
+ # They are not standard human gene symbols (which would look like BRCA1, TP53, etc)
89
+ # The format A_19_P* suggests these are likely Agilent array probe IDs that need mapping
90
+ requires_gene_mapping = True
91
+ # Extract gene annotation from SOFT file
92
+ gene_annotation = get_gene_annotation(soft_file_path)
93
+
94
+ # Preview column names and first few values
95
+ preview_dict = preview_df(gene_annotation)
96
+ print("Column names and preview values:")
97
+ for col, values in preview_dict.items():
98
+ print(f"\n{col}:")
99
+ print(values)
100
+ # Extract probe ID and gene symbol mapping from annotation
101
+ mapping_data = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL')
102
+
103
+ # Apply gene mapping to convert probe-level measurements to gene expression
104
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
105
+
106
+ # Print dimensions of original and mapped data
107
+ print(f"Original probe data dimensions: {genetic_data.shape}")
108
+ print(f"Mapped gene data dimensions: {gene_data.shape}")
109
+ # 1. Normalize gene symbols and save normalized gene data
110
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
111
+ normalized_gene_data.to_csv(out_gene_data_file)
112
+
113
+ # Create clinical data using sample IDs and convert_trait function
114
+ sample_ids = normalized_gene_data.columns
115
+ clinical_data = pd.DataFrame(index=['Esophageal_Cancer'])
116
+ clinical_data[sample_ids] = [convert_trait(id) for id in sample_ids]
117
+ clinical_data.to_csv(out_clinical_data_file)
118
+
119
+ # Link clinical and genetic data
120
+ linked_data = geo_link_clinical_genetic_data(clinical_data, normalized_gene_data)
121
+
122
+ # Handle missing values systematically
123
+ linked_data = handle_missing_values(linked_data, 'Esophageal_Cancer')
124
+
125
+ # Detect bias in trait and demographic features
126
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, 'Esophageal_Cancer')
127
+
128
+ # Validate data quality and save cohort info
129
+ note = ("This dataset studies gene expression related to pathological complete response (pCR) "
130
+ "after neoadjuvant chemotherapy in esophageal cancer. The trait information was derived "
131
+ "from RNA sample IDs mentioned in the background information.")
132
+ is_usable = validate_and_save_cohort_info(
133
+ is_final=True,
134
+ cohort=cohort,
135
+ info_path=json_path,
136
+ is_gene_available=True,
137
+ is_trait_available=True,
138
+ is_biased=is_biased,
139
+ df=linked_data,
140
+ note=note
141
+ )
142
+
143
+ # Save linked data if usable
144
+ if is_usable:
145
+ linked_data.to_csv(out_data_file)
146
+ else:
147
+ print(f"Dataset {cohort} did not pass quality validation and will not be saved.")
p3/preprocess/Esophageal_Cancer/code/GSE107754.py ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Esophageal_Cancer"
6
+ cohort = "GSE107754"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Esophageal_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Esophageal_Cancer/GSE107754"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Esophageal_Cancer/GSE107754.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Esophageal_Cancer/gene_data/GSE107754.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Esophageal_Cancer/clinical_data/GSE107754.csv"
16
+ json_path = "./output/preprocess/3/Esophageal_Cancer/cohort_info.json"
17
+
18
+ # Get relevant file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data from the matrix file
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get dictionary of unique values per row in clinical data
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Background Information:")
29
+ print("-" * 50)
30
+ print(background_info)
31
+ print("\n")
32
+
33
+ # Print clinical data unique values
34
+ print("Sample Characteristics:")
35
+ print("-" * 50)
36
+ for row, values in unique_values_dict.items():
37
+ print(f"{row}:")
38
+ print(f" {values}")
39
+ print()
40
+ # 1. Gene Expression Data Availability
41
+ # The background info mentions "whole human genome gene expression microarrays"
42
+ is_gene_available = True
43
+
44
+ # 2.1 Data Availability
45
+ # Trait (cancer) info is in key 2 under "tissue: ..."
46
+ trait_row = 2
47
+ # Age is not available in the sample characteristics
48
+ age_row = None
49
+ # Gender is in key 0
50
+ gender_row = 0
51
+
52
+ # 2.2 Data Type Conversion Functions
53
+ def convert_trait(value: str) -> int:
54
+ """Convert tissue type to binary indicating if it's esophageal cancer"""
55
+ if not value or ':' not in value:
56
+ return None
57
+ tissue = value.split(':')[1].strip().lower()
58
+ # Return 1 for esophageal cancer, 0 for other cancers
59
+ return 1 if 'esophagus cancer' in tissue else 0
60
+
61
+ def convert_age(value: str) -> float:
62
+ """Convert age string to float"""
63
+ # No age data available
64
+ return None
65
+
66
+ def convert_gender(value: str) -> int:
67
+ """Convert gender to binary (0=female, 1=male)"""
68
+ if not value or ':' not in value:
69
+ return None
70
+ gender = value.split(':')[1].strip().lower()
71
+ if gender == 'female':
72
+ return 0
73
+ elif gender == 'male':
74
+ return 1
75
+ return None
76
+
77
+ # 3. Save initial validation info
78
+ _ = validate_and_save_cohort_info(
79
+ is_final=False,
80
+ cohort=cohort,
81
+ info_path=json_path,
82
+ is_gene_available=is_gene_available,
83
+ is_trait_available=trait_row is not None
84
+ )
85
+
86
+ # 4. Extract clinical features
87
+ if trait_row is not None:
88
+ clinical_features = geo_select_clinical_features(
89
+ clinical_df=clinical_data,
90
+ trait=trait,
91
+ trait_row=trait_row,
92
+ convert_trait=convert_trait,
93
+ age_row=age_row,
94
+ convert_age=convert_age,
95
+ gender_row=gender_row,
96
+ convert_gender=convert_gender
97
+ )
98
+
99
+ # Preview the extracted features
100
+ preview = preview_df(clinical_features)
101
+ print("Preview of clinical features:")
102
+ print(preview)
103
+
104
+ # Save to CSV
105
+ clinical_features.to_csv(out_clinical_data_file)
106
+ # Extract gene expression data
107
+ genetic_data = get_genetic_data(matrix_file_path)
108
+
109
+ # Print first 20 probe IDs
110
+ print("First 20 probe IDs:")
111
+ print(genetic_data.index[:20])
112
+ # These identifiers are Agilent probe IDs, not HGNC gene symbols
113
+ # They follow the typical Agilent format "A_23_P######"
114
+ # Therefore mapping to gene symbols is required
115
+ requires_gene_mapping = True
116
+ # Extract gene annotation from SOFT file
117
+ gene_annotation = get_gene_annotation(soft_file_path)
118
+
119
+ # Preview column names and first few values
120
+ preview_dict = preview_df(gene_annotation)
121
+ print("Column names and preview values:")
122
+ for col, values in preview_dict.items():
123
+ print(f"\n{col}:")
124
+ print(values)
125
+ # 1. The 'ID' column in gene_annotation matches the probe IDs in genetic_data
126
+ # The 'GENE_SYMBOL' column contains the corresponding gene symbols
127
+ probe_col = 'ID'
128
+ symbol_col = 'GENE_SYMBOL'
129
+
130
+ # 2. Get gene mapping dataframe
131
+ gene_mapping = get_gene_mapping(gene_annotation, probe_col, symbol_col)
132
+
133
+ # 3. Apply gene mapping to convert probe-level data to gene expression data
134
+ gene_data = apply_gene_mapping(genetic_data, gene_mapping)
135
+ # 1. Normalize gene symbols and save normalized gene data
136
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
137
+ normalized_gene_data.to_csv(out_gene_data_file)
138
+
139
+ # 2. Link clinical and genetic data
140
+ clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
141
+ linked_data = geo_link_clinical_genetic_data(clinical_df, normalized_gene_data)
142
+
143
+ # 3. Handle missing values systematically
144
+ linked_data = handle_missing_values(linked_data, trait)
145
+
146
+ # 4. Detect bias in trait and demographic features, remove biased demographic features
147
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
148
+
149
+ # 5. Validate data quality and save cohort info
150
+ note = ("This dataset studies gene expression profiles in esophageal squamous cell carcinoma, "
151
+ "comparing tumor samples with matched nonmalignant mucosa. The sample size is moderate with paired samples.")
152
+ is_usable = validate_and_save_cohort_info(
153
+ is_final=True,
154
+ cohort=cohort,
155
+ info_path=json_path,
156
+ is_gene_available=True,
157
+ is_trait_available=True,
158
+ is_biased=is_biased,
159
+ df=linked_data,
160
+ note=note
161
+ )
162
+
163
+ # 6. Save linked data if usable
164
+ if is_usable:
165
+ linked_data.to_csv(out_data_file)
166
+ else:
167
+ print(f"Dataset {cohort} did not pass quality validation and will not be saved.")
p3/preprocess/Esophageal_Cancer/code/GSE131027.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Esophageal_Cancer"
6
+ cohort = "GSE131027"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Esophageal_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Esophageal_Cancer/GSE131027"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Esophageal_Cancer/GSE131027.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Esophageal_Cancer/gene_data/GSE131027.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Esophageal_Cancer/clinical_data/GSE131027.csv"
16
+ json_path = "./output/preprocess/3/Esophageal_Cancer/cohort_info.json"
17
+
18
+ # Get relevant file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data from the matrix file
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get dictionary of unique values per row in clinical data
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Background Information:")
29
+ print("-" * 50)
30
+ print(background_info)
31
+ print("\n")
32
+
33
+ # Print clinical data unique values
34
+ print("Sample Characteristics:")
35
+ print("-" * 50)
36
+ for row, values in unique_values_dict.items():
37
+ print(f"{row}:")
38
+ print(f" {values}")
39
+ print()
40
+ # 1. Gene Expression Data Availability
41
+ is_gene_available = True # Based on background info showing expression features analysis
42
+
43
+ # 2. Variable Availability and Type Conversion
44
+ # 2.1 Data Availability
45
+ trait_row = 1 # Cancer type is recorded in row 1
46
+ age_row = None # Age data not available
47
+ gender_row = None # Gender data not available
48
+
49
+ # 2.2 Data Type Conversion Functions
50
+ def convert_trait(value: str) -> int:
51
+ """Convert cancer type to binary for esophageal cancer"""
52
+ if pd.isna(value) or ':' not in value:
53
+ return None
54
+ cancer_type = value.split(': ')[1].lower()
55
+ # Match variations of esophageal cancer spelling
56
+ if 'oesophageal' in cancer_type or 'esophageal' in cancer_type:
57
+ return 1
58
+ return 0
59
+
60
+ def convert_age(value: str) -> float:
61
+ return None # Not used since age data unavailable
62
+
63
+ def convert_gender(value: str) -> int:
64
+ return None # Not used since gender data unavailable
65
+
66
+ # 3. Save Metadata
67
+ is_trait_available = trait_row is not None
68
+ validate_and_save_cohort_info(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
+ # 4. Clinical Feature Extraction
75
+ if trait_row is not None:
76
+ clinical_features = geo_select_clinical_features(
77
+ clinical_df=clinical_data,
78
+ trait=trait,
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 processed clinical features
88
+ print("Preview of clinical features:")
89
+ print(preview_df(clinical_features))
90
+
91
+ # Save to CSV
92
+ clinical_features.to_csv(out_clinical_data_file)
93
+ # Extract gene expression data
94
+ genetic_data = get_genetic_data(matrix_file_path)
95
+
96
+ # Print first 20 probe IDs
97
+ print("First 20 probe IDs:")
98
+ print(genetic_data.index[:20])
99
+ # Based on the probe IDs shown (e.g., '1007_s_at', '1053_at'), these are Affymetrix probe IDs
100
+ # and not human gene symbols. They need to be mapped to standard gene symbols for analysis.
101
+ requires_gene_mapping = True
102
+ # Extract gene annotation from SOFT file
103
+ gene_annotation = get_gene_annotation(soft_file_path)
104
+
105
+ # Preview column names and first few values
106
+ preview_dict = preview_df(gene_annotation)
107
+ print("Column names and preview values:")
108
+ for col, values in preview_dict.items():
109
+ print(f"\n{col}:")
110
+ print(values)
111
+ # The gene identifiers are in the 'ID' column of gene annotation data, which matches
112
+ # the probe IDs in gene expression data. Gene symbols are in the 'Gene Symbol' column.
113
+ gene_mapping = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')
114
+
115
+ # Apply the gene mapping to convert probe-level data to gene expression data
116
+ gene_data = apply_gene_mapping(genetic_data, gene_mapping)
117
+
118
+ # Preview the first few rows and columns of the gene data
119
+ print("\nPreview of gene expression data:")
120
+ print(preview_df(gene_data))
121
+ # 1. Normalize gene symbols and save normalized gene data
122
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
123
+ normalized_gene_data.to_csv(out_gene_data_file)
124
+
125
+ # 2. Link clinical and genetic data
126
+ linked_data = geo_link_clinical_genetic_data(clinical_data, normalized_gene_data)
127
+
128
+ # 3. Handle missing values systematically
129
+ linked_data = handle_missing_values(linked_data, trait)
130
+
131
+ # 4. Detect bias in trait and demographic features, remove biased demographic features
132
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
133
+
134
+ # 5. Validate data quality and save cohort info
135
+ note = ("This dataset studies gene expression profiles in esophageal squamous cell carcinoma, "
136
+ "comparing tumor samples with matched nonmalignant mucosa. The sample size is moderate with paired samples.")
137
+ is_usable = validate_and_save_cohort_info(
138
+ is_final=True,
139
+ cohort=cohort,
140
+ info_path=json_path,
141
+ is_gene_available=True,
142
+ is_trait_available=True,
143
+ is_biased=is_biased,
144
+ df=linked_data,
145
+ note=note
146
+ )
147
+
148
+ # 6. Save linked data if usable
149
+ if is_usable:
150
+ linked_data.to_csv(out_data_file)
151
+ else:
152
+ print(f"Dataset {cohort} did not pass quality validation and will not be saved.")
p3/preprocess/Esophageal_Cancer/code/GSE156915.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Esophageal_Cancer"
6
+ cohort = "GSE156915"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Esophageal_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Esophageal_Cancer/GSE156915"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Esophageal_Cancer/GSE156915.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Esophageal_Cancer/gene_data/GSE156915.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Esophageal_Cancer/clinical_data/GSE156915.csv"
16
+ json_path = "./output/preprocess/3/Esophageal_Cancer/cohort_info.json"
17
+
18
+ # Get relevant file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data from the matrix file
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get dictionary of unique values per row in clinical data
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Background Information:")
29
+ print("-" * 50)
30
+ print(background_info)
31
+ print("\n")
32
+
33
+ # Print clinical data unique values
34
+ print("Sample Characteristics:")
35
+ print("-" * 50)
36
+ for row, values in unique_values_dict.items():
37
+ print(f"{row}:")
38
+ print(f" {values}")
39
+ print()
40
+ # 1. Gene Expression Data Availability
41
+ # From the background info, we can see this is a gene expression study investigating
42
+ # DNA damage immune response in colorectal cancer
43
+ is_gene_available = True
44
+
45
+ # 2.1 Data Availability
46
+ # Looking at the sample characteristics:
47
+ # - Row 0 shows DDIR status which indicates DNA damage response status
48
+ trait_row = 0
49
+ # Age and gender info not available in sample characteristics
50
+ age_row = None
51
+ gender_row = None
52
+
53
+ # 2.2 Data Type Conversion Functions
54
+ def convert_trait(x):
55
+ if pd.isna(x):
56
+ return None
57
+ # Extract value after colon and strip whitespace
58
+ val = x.split(':')[1].strip()
59
+ # DDIR NEG = control = 0, DDIR POS = case = 1
60
+ if 'NEG' in val:
61
+ return 0
62
+ elif 'POS' in val:
63
+ return 1
64
+ return None
65
+
66
+ def convert_age(x):
67
+ # Not available
68
+ return None
69
+
70
+ def convert_gender(x):
71
+ # Not available
72
+ return None
73
+
74
+ # 3. Save Initial Metadata
75
+ is_trait_available = trait_row is not None
76
+ _ = validate_and_save_cohort_info(is_final=False,
77
+ cohort=cohort,
78
+ info_path=json_path,
79
+ is_gene_available=is_gene_available,
80
+ is_trait_available=is_trait_available)
81
+
82
+ # 4. Extract Clinical Features
83
+ if trait_row is not None:
84
+ clinical_df = geo_select_clinical_features(clinical_data,
85
+ trait=trait,
86
+ trait_row=trait_row,
87
+ convert_trait=convert_trait,
88
+ age_row=age_row,
89
+ convert_age=convert_age,
90
+ gender_row=gender_row,
91
+ convert_gender=convert_gender)
92
+
93
+ # Preview the extracted features
94
+ preview = preview_df(clinical_df)
95
+ print("Preview of clinical features:")
96
+ print(preview)
97
+
98
+ # Save to CSV
99
+ clinical_df.to_csv(out_clinical_data_file)
100
+ # Extract gene expression data
101
+ genetic_data = get_genetic_data(matrix_file_path)
102
+
103
+ # Print first 20 probe IDs
104
+ print("First 20 probe IDs:")
105
+ print(genetic_data.index[:20])
106
+ # These appear to be human gene symbols, with some RNA genes and pseudogenes
107
+ # The identifiers match official HGNC gene symbols and nomenclature patterns
108
+ requires_gene_mapping = False
109
+ # 1. Normalize gene symbols and save normalized gene data
110
+ normalized_gene_data = normalize_gene_symbols_in_index(genetic_data)
111
+ normalized_gene_data.to_csv(out_gene_data_file)
112
+
113
+ # Read the processed clinical and gene data files
114
+ clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
115
+ gene_data = pd.read_csv(out_gene_data_file, index_col=0)
116
+
117
+ # Link clinical and genetic data
118
+ linked_data = geo_link_clinical_genetic_data(clinical_df, gene_data)
119
+
120
+ # Handle missing values systematically
121
+ linked_data = handle_missing_values(linked_data, trait)
122
+
123
+ # Detect bias in trait and demographic features, remove biased demographic features
124
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
125
+
126
+ # Validate data quality and save cohort info
127
+ note = ("This dataset studies gene expression profiles in esophageal squamous cell carcinoma, "
128
+ "comparing tumor samples with matched nonmalignant mucosa. The sample size is moderate with paired samples.")
129
+ is_usable = validate_and_save_cohort_info(
130
+ is_final=True,
131
+ cohort=cohort,
132
+ info_path=json_path,
133
+ is_gene_available=True,
134
+ is_trait_available=True,
135
+ is_biased=is_biased,
136
+ df=linked_data,
137
+ note=note
138
+ )
139
+
140
+ # Save linked data if usable
141
+ if is_usable:
142
+ linked_data.to_csv(out_data_file)
143
+ else:
144
+ print(f"Dataset {cohort} did not pass quality validation and will not be saved.")
p3/preprocess/Esophageal_Cancer/code/GSE218109.py ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Esophageal_Cancer"
6
+ cohort = "GSE218109"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Esophageal_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Esophageal_Cancer/GSE218109"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Esophageal_Cancer/GSE218109.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Esophageal_Cancer/gene_data/GSE218109.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Esophageal_Cancer/clinical_data/GSE218109.csv"
16
+ json_path = "./output/preprocess/3/Esophageal_Cancer/cohort_info.json"
17
+
18
+ # Get relevant file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data from the matrix file
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get dictionary of unique values per row in clinical data
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Background Information:")
29
+ print("-" * 50)
30
+ print(background_info)
31
+ print("\n")
32
+
33
+ # Print clinical data unique values
34
+ print("Sample Characteristics:")
35
+ print("-" * 50)
36
+ for row, values in unique_values_dict.items():
37
+ print(f"{row}:")
38
+ print(f" {values}")
39
+ print()
40
+ # 1. Gene Expression Data
41
+ is_gene_available = True # Based on Series_title and Series_summary, this contains transcriptional profiling data
42
+
43
+ # 2.1 Data Availability
44
+ trait_row = 5 # p53 status indicates cancer condition
45
+ age_row = 1 # Age data available
46
+ gender_row = 0 # Sex data available
47
+
48
+ # 2.2 Data Type Conversion Functions
49
+ def convert_trait(value):
50
+ if pd.isna(value):
51
+ return None
52
+ value = value.split(': ')[-1].lower()
53
+ if 'ns+' in value or 'nuclear-stabilized' in value:
54
+ return 1
55
+ elif 'ns-' in value or 'unstable' in value:
56
+ return 0
57
+ return None
58
+
59
+ def convert_age(value):
60
+ if pd.isna(value):
61
+ return None
62
+ try:
63
+ return float(value.split(': ')[1])
64
+ except:
65
+ return None
66
+
67
+ def convert_gender(value):
68
+ if pd.isna(value):
69
+ return None
70
+ value = value.split(': ')[1].upper()
71
+ if value == 'F':
72
+ return 0
73
+ elif value == 'M':
74
+ return 1
75
+ return None
76
+
77
+ # 3. Save Initial Metadata
78
+ validate_and_save_cohort_info(
79
+ is_final=False,
80
+ cohort=cohort,
81
+ info_path=json_path,
82
+ is_gene_available=is_gene_available,
83
+ is_trait_available=(trait_row is not None)
84
+ )
85
+
86
+ # 4. Extract Clinical Features
87
+ selected_clinical = geo_select_clinical_features(
88
+ clinical_df=clinical_data,
89
+ trait=trait,
90
+ trait_row=trait_row,
91
+ convert_trait=convert_trait,
92
+ age_row=age_row,
93
+ convert_age=convert_age,
94
+ gender_row=gender_row,
95
+ convert_gender=convert_gender
96
+ )
97
+
98
+ # Preview the extracted features
99
+ print(preview_df(selected_clinical))
100
+
101
+ # Save clinical data
102
+ selected_clinical.to_csv(out_clinical_data_file)
103
+ # Extract gene expression data
104
+ genetic_data = get_genetic_data(matrix_file_path)
105
+
106
+ # Print first 20 probe IDs
107
+ print("First 20 probe IDs:")
108
+ print(genetic_data.index[:20])
109
+ # These probes appear to be numerical identifiers rather than standard human gene symbols
110
+ # Human gene symbols typically follow a specific format (e.g., BRCA1, TP53, IL6)
111
+ # Therefore gene mapping will be required
112
+ requires_gene_mapping = True
113
+ # Since the SOFT file doesn't contain usable annotation data, load platform annotation from external source
114
+ annotation_file = "./metadata/GPL4133.tsv"
115
+
116
+ # Load and preview the platform annotation
117
+ gene_annotation = pd.read_csv(annotation_file, sep='\t', comment='#')
118
+
119
+ # Show column names and preview the data
120
+ print("Platform Annotation Preview:")
121
+ print("-" * 50)
122
+ print(f"Number of rows: {len(gene_annotation)}")
123
+ print(f"\nColumns:")
124
+ for col in gene_annotation.columns:
125
+ print(col)
126
+ print("\nFirst few rows:")
127
+ print(preview_df(gene_annotation))
128
+ # Extract gene annotation from SOFT file
129
+ gene_annotation = get_gene_annotation(soft_file_path)
130
+
131
+ # Preview the data
132
+ print("Gene Annotation Preview:")
133
+ print("-" * 50)
134
+ print(f"Number of rows: {len(gene_annotation)}")
135
+ print(f"\nColumns:")
136
+ for col in gene_annotation.columns:
137
+ print(col)
138
+ print("\nFirst few rows:")
139
+ print(preview_df(gene_annotation))
140
+ # 1. The 'ID' column in gene annotation matches the gene expression data indices
141
+ # The 'GENE_SYMBOL' column contains the gene symbols we want to map to
142
+ mapping_df = get_gene_mapping(gene_annotation, 'ID', 'GENE_SYMBOL')
143
+
144
+ # 2. Apply gene mapping to convert probe-level data to gene-level data
145
+ gene_data = apply_gene_mapping(genetic_data, mapping_df)
146
+
147
+ # Preview results
148
+ print("Gene Expression Data Preview:")
149
+ print("-" * 50)
150
+ print(f"Number of genes: {len(gene_data)}")
151
+ print("\nFirst few rows:")
152
+ print(preview_df(gene_data))
153
+ # 1. Normalize gene symbols and save
154
+ normalized_gene_data = normalize_gene_symbols_in_index(genetic_data)
155
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
156
+ normalized_gene_data.to_csv(out_gene_data_file)
157
+
158
+ # 2. Link clinical and genetic data
159
+ clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
160
+ linked_data = geo_link_clinical_genetic_data(clinical_df, normalized_gene_data)
161
+
162
+ # 3. Handle missing values systematically
163
+ linked_data = handle_missing_values(linked_data, trait)
164
+
165
+ # 4. Detect bias in trait and demographic features
166
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
167
+
168
+ # 5. Validate data quality and save cohort info
169
+ note = ("This dataset studies gene expression profiles in esophageal squamous cell carcinoma tumors, "
170
+ "comparing nuclear-stabilized p53 (NS+) versus unstable p53 (NS-) protein tumor samples.")
171
+ is_usable = validate_and_save_cohort_info(
172
+ is_final=True,
173
+ cohort=cohort,
174
+ info_path=json_path,
175
+ is_gene_available=True,
176
+ is_trait_available=True,
177
+ is_biased=is_biased,
178
+ df=linked_data,
179
+ note=note
180
+ )
181
+
182
+ # 6. Save linked data if usable
183
+ if is_usable:
184
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
185
+ linked_data.to_csv(out_data_file)
186
+ else:
187
+ print(f"Dataset {cohort} did not pass quality validation and will not be saved.")
p3/preprocess/Esophageal_Cancer/code/GSE55857.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Esophageal_Cancer"
6
+ cohort = "GSE55857"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Esophageal_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Esophageal_Cancer/GSE55857"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Esophageal_Cancer/GSE55857.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Esophageal_Cancer/gene_data/GSE55857.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Esophageal_Cancer/clinical_data/GSE55857.csv"
16
+ json_path = "./output/preprocess/3/Esophageal_Cancer/cohort_info.json"
17
+
18
+ # Get relevant file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data from the matrix file
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get dictionary of unique values per row in clinical data
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Background Information:")
29
+ print("-" * 50)
30
+ print(background_info)
31
+ print("\n")
32
+
33
+ # Print clinical data unique values
34
+ print("Sample Characteristics:")
35
+ print("-" * 50)
36
+ for row, values in unique_values_dict.items():
37
+ print(f"{row}:")
38
+ print(f" {values}")
39
+ print()
40
+ # 1. Gene Expression Data Availability
41
+ # This is a microRNA dataset (SuperSeries) studying small non-coding RNAs
42
+ # MicroRNA data is not suitable for our gene expression analysis
43
+ is_gene_available = False
44
+
45
+ # 2. Clinical Data Variables Analysis
46
+ # 2.1 Data Availability
47
+ # Trait (cancer status) is available in row 1 as "tissue" field
48
+ # Age and gender are not recorded
49
+ trait_row = 1
50
+ age_row = None
51
+ gender_row = None
52
+
53
+ # 2.2 Data Type Conversion Functions
54
+ def convert_trait(value):
55
+ """Convert tissue type to binary cancer status"""
56
+ if not isinstance(value, str):
57
+ return None
58
+ value = value.split(": ")[-1].lower().strip()
59
+ if "tumor" in value:
60
+ return 1
61
+ elif "normal" in value:
62
+ return 0
63
+ return None
64
+
65
+ def convert_age(value):
66
+ """Convert age value - not used"""
67
+ return None
68
+
69
+ def convert_gender(value):
70
+ """Convert gender value - not used"""
71
+ return None
72
+
73
+ # 3. Save Metadata
74
+ # trait_row is not None, so trait data is available
75
+ is_trait_available = trait_row is not None
76
+ validate_and_save_cohort_info(is_final=False,
77
+ cohort=cohort,
78
+ info_path=json_path,
79
+ is_gene_available=is_gene_available,
80
+ is_trait_available=is_trait_available)
81
+
82
+ # 4. Extract Clinical Features
83
+ # Since trait_row is not None, we extract clinical features
84
+ clinical_features = geo_select_clinical_features(clinical_data,
85
+ trait=trait,
86
+ trait_row=trait_row,
87
+ convert_trait=convert_trait,
88
+ age_row=age_row,
89
+ convert_age=convert_age,
90
+ gender_row=gender_row,
91
+ convert_gender=convert_gender)
92
+
93
+ # Preview the extracted features
94
+ preview_results = preview_df(clinical_features)
95
+ print("Preview of clinical features:")
96
+ print(preview_results)
97
+
98
+ # Save clinical features
99
+ clinical_features.to_csv(out_clinical_data_file)
p3/preprocess/Esophageal_Cancer/code/GSE66258.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Esophageal_Cancer"
6
+ cohort = "GSE66258"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Esophageal_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Esophageal_Cancer/GSE66258"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Esophageal_Cancer/GSE66258.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Esophageal_Cancer/gene_data/GSE66258.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Esophageal_Cancer/clinical_data/GSE66258.csv"
16
+ json_path = "./output/preprocess/3/Esophageal_Cancer/cohort_info.json"
17
+
18
+ # Get relevant file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data from the matrix file
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get dictionary of unique values per row in clinical data
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Background Information:")
29
+ print("-" * 50)
30
+ print(background_info)
31
+ print("\n")
32
+
33
+ # Print clinical data unique values
34
+ print("Sample Characteristics:")
35
+ print("-" * 50)
36
+ for row, values in unique_values_dict.items():
37
+ print(f"{row}:")
38
+ print(f" {values}")
39
+ print()
40
+ # 1. Gene Expression Data Availability
41
+ # Based on the series description, this is a microRNA dataset, not suitable for gene expression analysis
42
+ is_gene_available = False
43
+
44
+ # 2.1 Data Availability
45
+ # From sample characteristics:
46
+ # - trait: Row 0 shows all samples are ESCC tumor tissue
47
+ # - age: Not available
48
+ # - gender: Not available
49
+ trait_row = 0
50
+ age_row = None
51
+ gender_row = None
52
+
53
+ # 2.2 Data Type Conversion Functions
54
+ def convert_trait(value: str) -> int:
55
+ """Convert ESCC tumor status to binary"""
56
+ if 'esophageal squamous cell carcinoma' in value.lower():
57
+ return 1
58
+ return None
59
+
60
+ def convert_age(value: str) -> float:
61
+ """Convert age to float"""
62
+ return None # Not used since age data not available
63
+
64
+ def convert_gender(value: str) -> int:
65
+ """Convert gender to binary"""
66
+ return None # Not used since gender data not available
67
+
68
+ # 3. Save metadata
69
+ 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=trait_row is not None
75
+ )
76
+
77
+ # 4. Extract clinical features since trait_row is not None
78
+ selected_clinical = geo_select_clinical_features(
79
+ clinical_df=clinical_data,
80
+ trait=trait,
81
+ trait_row=trait_row,
82
+ convert_trait=convert_trait
83
+ )
84
+
85
+ # Preview and save
86
+ print("Clinical data preview:")
87
+ print(preview_df(selected_clinical))
88
+
89
+ # Save clinical data
90
+ selected_clinical.to_csv(out_clinical_data_file)
p3/preprocess/Esophageal_Cancer/code/GSE75241.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Esophageal_Cancer"
6
+ cohort = "GSE75241"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Esophageal_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Esophageal_Cancer/GSE75241"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Esophageal_Cancer/GSE75241.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Esophageal_Cancer/gene_data/GSE75241.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Esophageal_Cancer/clinical_data/GSE75241.csv"
16
+ json_path = "./output/preprocess/3/Esophageal_Cancer/cohort_info.json"
17
+
18
+ # Get relevant file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data from the matrix file
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get dictionary of unique values per row in clinical data
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Background Information:")
29
+ print("-" * 50)
30
+ print(background_info)
31
+ print("\n")
32
+
33
+ # Print clinical data unique values
34
+ print("Sample Characteristics:")
35
+ print("-" * 50)
36
+ for row, values in unique_values_dict.items():
37
+ print(f"{row}:")
38
+ print(f" {values}")
39
+ print()
40
+ # 1. Gene Expression Data Availability
41
+ # From title and summary, this is a gene expression profile dataset
42
+ is_gene_available = True
43
+
44
+ # 2.1 Data Availability
45
+ # trait (cancer status) is in row 1 (tissue type)
46
+ trait_row = 1
47
+
48
+ # age and gender not available in characteristics
49
+ age_row = None
50
+ gender_row = None
51
+
52
+ # 2.2 Data Type Conversion Functions
53
+ def convert_trait(value):
54
+ if pd.isna(value):
55
+ return None
56
+ # Extract value after colon and strip whitespace
57
+ value = value.split(':')[1].strip()
58
+ # Convert to binary: nonmalignant (0) vs tumor (1)
59
+ if 'nonmalignant' in value.lower():
60
+ return 0
61
+ elif 'tumor' in value.lower():
62
+ return 1
63
+ return None
64
+
65
+ def convert_age(value):
66
+ return None # Not used since age data not available
67
+
68
+ def convert_gender(value):
69
+ return None # Not used since gender data not available
70
+
71
+ # 3. Save Metadata
72
+ 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=(trait_row is not None)
78
+ )
79
+
80
+ # 4. Clinical Feature Extraction
81
+ # Since trait_row is not None, we extract features
82
+ selected_clinical = geo_select_clinical_features(
83
+ clinical_df=clinical_data,
84
+ trait=trait,
85
+ trait_row=trait_row,
86
+ convert_trait=convert_trait,
87
+ age_row=age_row,
88
+ convert_age=convert_age,
89
+ gender_row=gender_row,
90
+ convert_gender=convert_gender
91
+ )
92
+
93
+ # Preview the extracted features
94
+ preview_result = preview_df(selected_clinical)
95
+
96
+ # Save clinical data
97
+ selected_clinical.to_csv(out_clinical_data_file)
98
+ # Extract gene expression data
99
+ genetic_data = get_genetic_data(matrix_file_path)
100
+
101
+ # Print first 20 probe IDs
102
+ print("First 20 probe IDs:")
103
+ print(genetic_data.index[:20])
104
+ # These probes appear to be numerical IDs from Illumina platform
105
+ # rather than standardized gene symbols like "BRCA1", "TP53" etc.
106
+ # Therefore mapping to gene symbols will be required
107
+ requires_gene_mapping = True
108
+ # Extract gene annotation from SOFT file
109
+ gene_annotation = get_gene_annotation(soft_file_path)
110
+
111
+ # Preview column names and first few values
112
+ preview_dict = preview_df(gene_annotation)
113
+ print("Column names and preview values:")
114
+ for col, values in preview_dict.items():
115
+ print(f"\n{col}:")
116
+ print(values)
117
+ # 'ID' in gene_annotation matches the probe IDs in genetic_data
118
+ # 'gene_assignment' contains gene symbol information
119
+ mapping_data = get_gene_mapping(gene_annotation, 'ID', 'gene_assignment')
120
+
121
+ # Apply gene mapping to get gene expression data
122
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
123
+
124
+ # Save gene data
125
+ gene_data.to_csv(out_gene_data_file)
126
+
127
+ # Preview the gene data
128
+ preview_result = preview_df(gene_data)
129
+ # Read the processed clinical and gene data files
130
+ clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
131
+ gene_data = pd.read_csv(out_gene_data_file, index_col=0) # Already normalized in step 6
132
+
133
+ # Link clinical and genetic data
134
+ linked_data = geo_link_clinical_genetic_data(clinical_df, gene_data)
135
+
136
+ # Handle missing values systematically
137
+ linked_data = handle_missing_values(linked_data, trait)
138
+
139
+ # Detect bias in trait and demographic features, remove biased demographic features
140
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
141
+
142
+ # Validate data quality and save cohort info
143
+ note = ("This dataset studies gene expression profiles in esophageal squamous cell carcinoma, "
144
+ "comparing tumor samples with matched nonmalignant mucosa. The sample size is moderate with paired samples.")
145
+ is_usable = validate_and_save_cohort_info(
146
+ is_final=True,
147
+ cohort=cohort,
148
+ info_path=json_path,
149
+ is_gene_available=True,
150
+ is_trait_available=True,
151
+ is_biased=is_biased,
152
+ df=linked_data,
153
+ note=note
154
+ )
155
+
156
+ # Save linked data if usable
157
+ if is_usable:
158
+ linked_data.to_csv(out_data_file)
159
+ else:
160
+ print(f"Dataset {cohort} did not pass quality validation and will not be saved.")
p3/preprocess/Esophageal_Cancer/code/GSE77790.py ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Esophageal_Cancer"
6
+ cohort = "GSE77790"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Esophageal_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Esophageal_Cancer/GSE77790"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Esophageal_Cancer/GSE77790.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Esophageal_Cancer/gene_data/GSE77790.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Esophageal_Cancer/clinical_data/GSE77790.csv"
16
+ json_path = "./output/preprocess/3/Esophageal_Cancer/cohort_info.json"
17
+
18
+ # Get relevant file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data from the matrix file
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get dictionary of unique values per row in clinical data
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Background Information:")
29
+ print("-" * 50)
30
+ print(background_info)
31
+ print("\n")
32
+
33
+ # Print clinical data unique values
34
+ print("Sample Characteristics:")
35
+ print("-" * 50)
36
+ for row, values in unique_values_dict.items():
37
+ print(f"{row}:")
38
+ print(f" {values}")
39
+ print()
40
+ # Get gene expression data from matrix file
41
+ genetic_data = get_genetic_data(matrix_file_path)
42
+
43
+ # Create trait column from cell line information
44
+ cell_lines = clinical_data.iloc[0]
45
+ clinical_df = pd.DataFrame(index=cell_lines.index)
46
+ clinical_df[trait] = cell_lines.str.contains('TE8|TE9').astype(int)
47
+
48
+ # Normalize gene symbols and save to file
49
+ normalized_gene_data = normalize_gene_symbols_in_index(genetic_data)
50
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
51
+ normalized_gene_data.to_csv(out_gene_data_file)
52
+
53
+ # Save clinical data to file
54
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
55
+ clinical_df.to_csv(out_clinical_data_file)
56
+
57
+ # Link clinical and genetic data
58
+ linked_data = geo_link_clinical_genetic_data(clinical_df, normalized_gene_data)
59
+
60
+ # Handle missing values systematically
61
+ linked_data = handle_missing_values(linked_data, trait)
62
+
63
+ # Detect bias in trait and demographic features, remove biased demographic features
64
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
65
+
66
+ # Validate data quality and save cohort info
67
+ note = ("This dataset studies gene expression changes in cancer cell lines after miRNA/siRNA treatments. "
68
+ "Data quality evaluation indicates the trait distribution is biased.")
69
+ is_usable = validate_and_save_cohort_info(
70
+ is_final=True,
71
+ cohort=cohort,
72
+ info_path=json_path,
73
+ is_gene_available=True,
74
+ is_trait_available=True,
75
+ is_biased=is_biased,
76
+ df=linked_data,
77
+ note=note
78
+ )
79
+
80
+ # Save linked data if usable
81
+ if is_usable:
82
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
83
+ linked_data.to_csv(out_data_file)
84
+ else:
85
+ print(f"Dataset {cohort} did not pass quality validation and will not be saved.")
86
+ # Set initial availability flags
87
+ is_gene_available = False # Cannot determine without data
88
+
89
+ # No data available yet
90
+ trait_row = None
91
+ age_row = None
92
+ gender_row = None
93
+
94
+ def convert_trait(x):
95
+ return None
96
+
97
+ def convert_age(x):
98
+ return None
99
+
100
+ def convert_gender(x):
101
+ return None
102
+
103
+ # Save initial metadata
104
+ validate_and_save_cohort_info(
105
+ is_final=False,
106
+ cohort=cohort,
107
+ info_path=json_path,
108
+ is_gene_available=is_gene_available,
109
+ is_trait_available=False # Since trait_row is None
110
+ )
111
+ # Check gene expression data availability (GPL570 platform indicates gene expression data)
112
+ is_gene_available = True
113
+
114
+ # Data availability from sample characteristics
115
+ trait_row = 2 # "source name: esophageal tumor or paired normal"
116
+ age_row = 9 # "age (years): [numeric values]"
117
+ gender_row = 8 # "sex: male/female"
118
+
119
+ def convert_trait(val: str) -> Optional[int]:
120
+ if val is None:
121
+ return None
122
+ val = val.split(":")[-1].strip().lower()
123
+ if "tumor" in val:
124
+ return 1
125
+ elif "normal" in val:
126
+ return 0
127
+ return None
128
+
129
+ def convert_age(val: str) -> Optional[float]:
130
+ if val is None:
131
+ return None
132
+ val = val.split(":")[-1].strip()
133
+ try:
134
+ return float(val)
135
+ except:
136
+ return None
137
+
138
+ def convert_gender(val: str) -> Optional[int]:
139
+ if val is None:
140
+ return None
141
+ val = val.split(":")[-1].strip().lower()
142
+ if "female" in val:
143
+ return 0
144
+ elif "male" in val:
145
+ return 1
146
+ return None
147
+
148
+ # Save metadata for initial filtering
149
+ _ = validate_and_save_cohort_info(is_final=False,
150
+ cohort=cohort,
151
+ info_path=json_path,
152
+ is_gene_available=is_gene_available,
153
+ is_trait_available=(trait_row is not None))
154
+ # Extract gene expression data
155
+ genetic_data = get_genetic_data(matrix_file_path)
156
+ genetic_data.index = genetic_data.index.astype(str) # Convert probe IDs to strings
157
+
158
+ # Print first 20 probe IDs
159
+ print("First 20 probe IDs:")
160
+ print(genetic_data.index[:20])
161
+ # The indices appear to be just sequential numbers rather than any meaningful gene identifiers
162
+ # This indicates the gene identifiers need to be mapped to proper gene symbols
163
+ requires_gene_mapping = True
164
+ # Extract gene annotation from SOFT file
165
+ gene_annotation = get_gene_annotation(soft_file_path)
166
+
167
+ # Preview column names and first few values
168
+ preview_dict = preview_df(gene_annotation)
169
+ print("Column names and preview values:")
170
+ for col, values in preview_dict.items():
171
+ print(f"\n{col}:")
172
+ print(values)
173
+ # Extract probe-gene mapping columns
174
+ mapping_data = get_gene_mapping(gene_annotation, 'ID', 'GENE_SYMBOL')
175
+
176
+ # Apply gene mapping to convert probe data to gene expression data
177
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
178
+ # Define clinical data parameters based on sample characteristics
179
+ trait_row = 1 # cell type row
180
+ def convert_trait(x):
181
+ if not isinstance(x, str):
182
+ return None
183
+ x = x.lower()
184
+ return 1 if 'esophageal cancer' in x else 0
185
+
186
+ # Extract clinical features
187
+ clinical_df = geo_select_clinical_features(
188
+ clinical_data,
189
+ trait=trait,
190
+ trait_row=trait_row,
191
+ convert_trait=convert_trait
192
+ )
193
+
194
+ # Normalize gene symbols
195
+ gene_data = normalize_gene_symbols_in_index(gene_data)
196
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
197
+ gene_data.to_csv(out_gene_data_file)
198
+
199
+ # Link clinical and genetic data
200
+ linked_data = geo_link_clinical_genetic_data(clinical_df, gene_data)
201
+
202
+ # Handle missing values systematically
203
+ linked_data = handle_missing_values(linked_data, trait)
204
+
205
+ # Detect bias in trait and demographic features, remove biased demographic features
206
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
207
+
208
+ # Validate data quality and save cohort info
209
+ note = ("This dataset studies gene expression in esophageal cancer cell lines. "
210
+ "Data quality evaluation indicates potential trait distribution bias.")
211
+ is_usable = validate_and_save_cohort_info(
212
+ is_final=True,
213
+ cohort=cohort,
214
+ info_path=json_path,
215
+ is_gene_available=True,
216
+ is_trait_available=True,
217
+ is_biased=is_biased,
218
+ df=linked_data,
219
+ note=note
220
+ )
221
+
222
+ # Save linked data if usable
223
+ if is_usable:
224
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
225
+ linked_data.to_csv(out_data_file)
226
+ else:
227
+ print(f"Dataset {cohort} did not pass quality validation and will not be saved.")
p3/preprocess/Esophageal_Cancer/code/TCGA.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Esophageal_Cancer"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/3/Esophageal_Cancer/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/3/Esophageal_Cancer/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/3/Esophageal_Cancer/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/3/Esophageal_Cancer/cohort_info.json"
15
+
16
+ # Select the ESCA (Esophageal Cancer) cohort directory
17
+ cohort_dir = os.path.join(tcga_root_dir, 'TCGA_Esophageal_Cancer_(ESCA)')
18
+
19
+ # Get paths for clinical and genetic data files
20
+ clinical_file, genetic_file = tcga_get_relevant_filepaths(cohort_dir)
21
+
22
+ # Load the data files
23
+ clinical_df = pd.read_csv(clinical_file, index_col=0, sep='\t')
24
+ genetic_df = pd.read_csv(genetic_file, index_col=0, sep='\t')
25
+
26
+ # Print clinical data columns for review
27
+ print("Clinical data columns:")
28
+ print(clinical_df.columns.tolist())
29
+ # 1. Identify candidate columns for age and gender
30
+ candidate_age_cols = ['age_at_initial_pathologic_diagnosis', 'age_began_smoking_in_years', 'days_to_birth']
31
+ candidate_gender_cols = ['gender']
32
+
33
+ # 2. Preview the data
34
+ # First check available directories
35
+ print("Available directories in TCGA root:")
36
+ print(os.listdir(tcga_root_dir))
37
+
38
+ # Get clinical data path using actual directory structure
39
+ cohort_dir = os.path.join(tcga_root_dir, "TCGA-ESCA")
40
+ clinical_file_path, _ = tcga_get_relevant_filepaths(cohort_dir)
41
+
42
+ # Read clinical data
43
+ clinical_df = pd.read_csv(clinical_file_path, index_col=0)
44
+
45
+ # Extract candidate columns
46
+ age_data = clinical_df[candidate_age_cols]
47
+ gender_data = clinical_df[candidate_gender_cols]
48
+
49
+ # Preview data as dictionaries
50
+ print("\nAge columns preview:")
51
+ print(preview_df(age_data))
52
+ print("\nGender columns preview:")
53
+ print(preview_df(gender_data))
54
+ # Select the ESCA (Esophageal Cancer) cohort directory
55
+ cohort_dir = os.path.join(tcga_root_dir, 'TCGA_Esophageal_Cancer_(ESCA)')
56
+
57
+ # Get paths for clinical and genetic data files
58
+ clinical_file, genetic_file = tcga_get_relevant_filepaths(cohort_dir)
59
+
60
+ # Load the data files
61
+ clinical_df = pd.read_csv(clinical_file, index_col=0, sep='\t')
62
+ genetic_df = pd.read_csv(genetic_file, index_col=0, sep='\t')
63
+
64
+ # Print clinical data columns for review
65
+ print("Clinical data columns:")
66
+ print(clinical_df.columns.tolist())
67
+ # Check values in candidate columns
68
+ age_col = "age_at_initial_pathologic_diagnosis"
69
+
70
+ # Gender column is straightforward
71
+ gender_col = "gender"
72
+
73
+ # Print chosen columns
74
+ print(f"Selected age column: {age_col}")
75
+ print(f"Selected gender column: {gender_col}")
76
+ # Carry over the selected demographic columns
77
+ age_col = "age_at_initial_pathologic_diagnosis"
78
+ gender_col = "gender"
79
+
80
+ # 1. Extract and standardize clinical features
81
+ clinical_df = tcga_select_clinical_features(clinical_df, trait, age_col, gender_col)
82
+
83
+ # 2. Normalize gene expression data
84
+ normalized_genetic_df = normalize_gene_symbols_in_index(genetic_df)
85
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
86
+ normalized_genetic_df.to_csv(out_gene_data_file)
87
+
88
+ # 3. Link clinical and genetic data
89
+ linked_data = pd.merge(normalized_genetic_df.T, clinical_df, left_index=True, right_index=True)
90
+
91
+ # Add trait labels based on sample IDs
92
+ linked_data[trait] = linked_data.index.map(tcga_convert_trait)
93
+
94
+ # 4. Handle missing values
95
+ linked_data = handle_missing_values(linked_data, trait)
96
+
97
+ # 5. Check for bias in features
98
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
99
+
100
+ # 6. Validate and save cohort info
101
+ is_usable = validate_and_save_cohort_info(
102
+ is_final=True,
103
+ cohort="TCGA_Esophageal_Cancer_(ESCA)",
104
+ info_path=json_path,
105
+ is_gene_available=len(normalized_genetic_df.columns) > 0,
106
+ is_trait_available=trait in linked_data.columns,
107
+ is_biased=is_biased,
108
+ df=linked_data,
109
+ note="Data from TCGA Esophageal Cancer cohort"
110
+ )
111
+
112
+ # 7. Save linked data if usable
113
+ if is_usable:
114
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
115
+ linked_data.to_csv(out_data_file)
p3/preprocess/Esophageal_Cancer/gene_data/GSE100843.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d9abb76c462b0a0290fb8bd1e665e3345055fcabe727f8ddb92919532d6b26c
3
+ size 28273352
p3/preprocess/Esophageal_Cancer/gene_data/GSE104958.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f56a51be1a5c9d45191e0295166f9ecde7c87bb40d6bfaf0a93ca8f8c181233
3
+ size 11772704
p3/preprocess/Esophageal_Cancer/gene_data/GSE107754.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a82da64a5edcbde2a3ccf1c07d005767e02ceeaad822b4ed6217419063405079
3
+ size 19822703
p3/preprocess/Esophageal_Cancer/gene_data/GSE131027.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a8582008fe6fc5b90879aea7d12ca4ea58cc0bbe03209acb333425d229be6e33
3
+ size 24379939
p3/preprocess/Esophageal_Cancer/gene_data/GSE218109.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ ID,GSM6734720,GSM6734721,GSM6734722,GSM6734723,GSM6734724,GSM6734725,GSM6734726,GSM6734727,GSM6734728,GSM6734729,GSM6734730,GSM6734731,GSM6734732,GSM6734733,GSM6734734,GSM6734735,GSM6734736,GSM6734737,GSM6734738,GSM6734739,GSM6734740,GSM6734741,GSM6734742,GSM6734743,GSM6734744,GSM6734745,GSM6734746,GSM6734747,GSM6734748,GSM6734749,GSM6734750,GSM6734751,GSM6734752,GSM6734753,GSM6734754,GSM6734755
p3/preprocess/Esophageal_Cancer/gene_data/GSE75241.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:671cc5a3e739a93eb07952d9d1c14095451645ae1a20145b7aa73ec9bd47e225
3
+ size 18737528
p3/preprocess/Esophageal_Cancer/gene_data/GSE77790.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ ID,GSM2059404,GSM2059405,GSM2059406,GSM2059407,GSM2059408,GSM2059409,GSM2059410,GSM2059411,GSM2059412,GSM2059413,GSM2059414,GSM2059415,GSM2059416,GSM2059417,GSM2059418,GSM2059419,GSM2059420,GSM2059421,GSM2059422,GSM2059423,GSM2059424,GSM2059425,GSM2059426,GSM2059427,GSM2059428,GSM2059429,GSM2059430,GSM2059431,GSM2059432,GSM2059433,GSM2059434,GSM2059435
p3/preprocess/Esophageal_Cancer/gene_data/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be8b1dd125bb45c3b527f42bfa3ddd3ac8a86d1f3a92868da89995845df4ef72
3
+ size 58741039
p3/preprocess/Essential_Thrombocythemia/GSE103237.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Essential_Thrombocythemia/GSE12295.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Essential_Thrombocythemia/GSE159514.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb319d1f2830f21ca6c9dadb7d1a99374a14894b518a863ed0aed19e1dd4a504
3
+ size 21786888
p3/preprocess/Essential_Thrombocythemia/GSE174060.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Essential_Thrombocythemia/GSE55976.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Essential_Thrombocythemia/GSE57793.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:788c0950aca6203d9bab29622515671322fe26e660d824dc4c12830fde911eee
3
+ size 17564694
p3/preprocess/Essential_Thrombocythemia/GSE61629.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE103176.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ,GSM2758744,GSM2758745,GSM2758746,GSM2758747,GSM2758748,GSM2758749,GSM2758750,GSM2758751,GSM2758752,GSM2758753,GSM2758754,GSM2758755,GSM2758756,GSM2758757,GSM2758758,GSM2758759,GSM2758760,GSM2758761,GSM2758762,GSM2758763,GSM2758764,GSM2758765,GSM2758766,GSM2758767,GSM2758768,GSM2758769,GSM2758770,GSM2758771,GSM2758772,GSM2758773,GSM2758774,GSM2758775,GSM2758776,GSM2758777,GSM2758778,GSM2758779,GSM2758780,GSM2758781,GSM2758782,GSM2758783,GSM2758784,GSM2758785,GSM2758786,GSM2758787,GSM2758788,GSM2758789,GSM2758790,GSM2758791,GSM2758792,GSM2758793,GSM2758794,GSM2758795,GSM2758796,GSM2758797,GSM2758798,GSM2758799,GSM2758800,GSM2758801,GSM2758802,GSM2758803,GSM2758804,GSM2758805,GSM2758806,GSM2758807,GSM2758808
2
+ Essential_Thrombocythemia,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,,,,,,,,,,,,,,,,,,,,,,,,,,,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
3
+ Gender,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.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,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,,,,,,,,,,,,,,,
p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE103237.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ,GSM2758679,GSM2758680,GSM2758681,GSM2758682,GSM2758683,GSM2758684,GSM2758685,GSM2758686,GSM2758687,GSM2758688,GSM2758689,GSM2758690,GSM2758691,GSM2758692,GSM2758693,GSM2758694,GSM2758695,GSM2758696,GSM2758697,GSM2758698,GSM2758699,GSM2758700,GSM2758701,GSM2758702,GSM2758703,GSM2758704,GSM2758705,GSM2758706,GSM2758707,GSM2758708,GSM2758709,GSM2758710,GSM2758711,GSM2758712,GSM2758713,GSM2758714,GSM2758715,GSM2758716,GSM2758717,GSM2758718,GSM2758719,GSM2758720,GSM2758721,GSM2758722,GSM2758723,GSM2758724,GSM2758725,GSM2758726,GSM2758727,GSM2758728,GSM2758729,GSM2758730,GSM2758731,GSM2758732,GSM2758733,GSM2758734,GSM2758735,GSM2758736,GSM2758737,GSM2758738,GSM2758739,GSM2758740,GSM2758741,GSM2758742,GSM2758743
2
+ Essential_Thrombocythemia,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,,,,,,,,,,,,,,,,,,,,,,,,,,,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
3
+ Gender,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.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,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,,,,,,,,,,,,,,,
p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE12295.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM309072,GSM309073,GSM309074,GSM309075,GSM309076,GSM309077,GSM309078,GSM309079,GSM309080,GSM309081,GSM309082,GSM309083,GSM309084,GSM309085,GSM309086,GSM309087,GSM309088,GSM309089,GSM309090,GSM309091,GSM309092,GSM309093,GSM309094,GSM309095,GSM309096,GSM309097,GSM309098,GSM309099,GSM309100,GSM309101,GSM309102,GSM309103,GSM309104,GSM309105,GSM309106,GSM309107,GSM309108,GSM309109,GSM309110,GSM309111,GSM309112,GSM309113,GSM309114,GSM309115,GSM309116,GSM309117,GSM309118,GSM309119,GSM309120,GSM309121,GSM309122,GSM309123,GSM309124,GSM309125,GSM309126,GSM309127,GSM309128,GSM309129,GSM309130,GSM309131,GSM309132,GSM309133,GSM309134,GSM309135,GSM309136,GSM309137,GSM309138,GSM309139,GSM309140,GSM309141,GSM309142,GSM309143,GSM309144,GSM309145,GSM309146,GSM309147,GSM309148,GSM309149,GSM309150,GSM309151,GSM309152,GSM309153,GSM309154,GSM309155,GSM309156,GSM309157,GSM309158,GSM309159,GSM309160,GSM309161,GSM309162,GSM309163,GSM309164,GSM309165,GSM309166
2
+ Essential_Thrombocythemia,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,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.0,0.0,0.0,0.0,,,,,,,1.0,1.0,,,,,,,,,,,,,,,,1.0
p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE159514.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM4831515,GSM4831516,GSM4831517,GSM4831518,GSM4831519,GSM4831520,GSM4831521,GSM4831522,GSM4831523,GSM4831524,GSM4831525,GSM4831526,GSM4831527,GSM4831528,GSM4831529,GSM4831530,GSM4831531,GSM4831532,GSM4831533,GSM4831534,GSM4831535,GSM4831536,GSM4831537,GSM4831538,GSM4831539,GSM4831540,GSM4831541,GSM4831542,GSM4831543,GSM4831544,GSM4831545,GSM4831546,GSM4831547,GSM4831548,GSM4831549,GSM4831550,GSM4831551,GSM4831552,GSM4831553,GSM4831554,GSM4831555,GSM4831556,GSM4831557,GSM4831558,GSM4831559,GSM4831560,GSM4831561,GSM4831562,GSM4831563,GSM4831564,GSM4831565,GSM4831566,GSM4831567,GSM4831568,GSM4831569,GSM4831570,GSM4831571,GSM4831572,GSM4831573,GSM4831574,GSM4831575,GSM4831576,GSM4831577,GSM4831578,GSM4831579,GSM4831580,GSM4831581,GSM4831582,GSM4831583,GSM4831584,GSM4831585,GSM4831586,GSM4831587,GSM4831588,GSM4831589,GSM4831590,GSM4831591,GSM4831592,GSM4831593,GSM4831594,GSM4831595,GSM4831596,GSM4831597,GSM4831598,GSM4831599,GSM4831600,GSM4831601,GSM4831602,GSM4831603,GSM4831604,GSM4831605,GSM4831606,GSM4831607,GSM4831608,GSM4831609,GSM4831610,GSM4831611,GSM4831612,GSM4831613,GSM4831614,GSM4831615,GSM4831616,GSM4831617,GSM4831618,GSM4831619,GSM4831620,GSM4831621,GSM4831622,GSM4831623,GSM4831624,GSM4831625,GSM4831626,GSM4831627,GSM4831628
2
+ Essential_Thrombocythemia,0.0,1.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,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.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,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.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,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
p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE174060.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ ,GSM5285411,GSM5285412,GSM5285413,GSM5285414,GSM5285415,GSM5285416,GSM5285417,GSM5285418,GSM5285419,GSM5285420,GSM5285421,GSM5285422,GSM5285423,GSM5285424,GSM5285425,GSM5285426,GSM5285427,GSM5285428,GSM5285429,GSM5285430,GSM5285431,GSM5285432,GSM5285433,GSM5285434,GSM5285435,GSM5285436,GSM5285437,GSM5285438,GSM5285439,GSM5285440,GSM5285441,GSM5285442,GSM5285443,GSM5285444,GSM5285445,GSM5285446
2
+ Essential_Thrombocythemia,1.0,1.0,1.0,1.0,1.0,1.0,,,,,,,,,,,,,,,,,,,,,,,,,0.0,0.0,0.0,0.0,0.0,0.0
3
+ Age,41.0,53.0,52.0,47.0,19.0,33.0,58.0,76.0,68.0,65.0,61.0,45.0,68.0,42.0,36.0,42.0,69.0,45.0,74.0,75.0,62.0,58.0,76.0,72.0,61.0,76.0,71.0,43.0,56.0,68.0,29.0,27.0,28.0,28.0,32.0,27.0
4
+ Gender,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.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,1.0,1.0,0.0,0.0
p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE55976.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM1349677,GSM1349678,GSM1349679,GSM1349680,GSM1349681,GSM1349682,GSM1349683,GSM1349684,GSM1349685,GSM1349686,GSM1349687,GSM1349688,GSM1349689,GSM1349690,GSM1349691,GSM1349692,GSM1349693,GSM1349694,GSM1349695,GSM1349696,GSM1349697,GSM1349698,GSM1349699,GSM1349700,GSM1349701,GSM1349702,GSM1349703,GSM1349704,GSM1349705,GSM1349706,GSM1349707,GSM1349708,GSM1349709,GSM1349710,GSM1349711,GSM1349712,GSM1349713,GSM1349714,GSM1349715
2
+ Essential_Thrombocythemia,0.0,0.0,0.0,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,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
p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE57793.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM1388566,GSM1388567,GSM1388568,GSM1388569,GSM1388570,GSM1388571,GSM1388572,GSM1388573,GSM1388574,GSM1388575,GSM1388576,GSM1388577,GSM1388578,GSM1388579,GSM1388580,GSM1388581,GSM1388582,GSM1388583,GSM1388584,GSM1388585,GSM1388586,GSM1388587,GSM1388588,GSM1388589,GSM1388590,GSM1388591,GSM1388592,GSM1388593,GSM1388594,GSM1388595,GSM1388596,GSM1388597,GSM1388598,GSM1388599,GSM1388600,GSM1388601,GSM1388602,GSM1388603,GSM1388604,GSM1388605,GSM1388606,GSM1388607,GSM1388608,GSM1388609,GSM1388610,GSM1388611,GSM1388612,GSM1388613,GSM1388614,GSM1388615,GSM1388616,GSM1388617,GSM1388618,GSM1388619,GSM1388620,GSM1388621,GSM1388622,GSM1388623,GSM1388624,GSM1388625,GSM1388626,GSM1388627,GSM1388628,GSM1388629,GSM1388630,GSM1388631
2
+ Essential_Thrombocythemia,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,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.0,0.0,0.0,0.0,0.0,0.0
p3/preprocess/Essential_Thrombocythemia/clinical_data/GSE61629.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM1388566,GSM1388567,GSM1388568,GSM1388569,GSM1388570,GSM1388571,GSM1388577,GSM1388579,GSM1388582,GSM1388584,GSM1388585,GSM1388587,GSM1388590,GSM1388591,GSM1388592,GSM1388593,GSM1388594,GSM1388595,GSM1388596,GSM1388598,GSM1388599,GSM1388600,GSM1388601,GSM1388603,GSM1388604,GSM1388605,GSM1388606,GSM1388607,GSM1388608,GSM1388614,GSM1388616,GSM1388623,GSM1388624,GSM1509517,GSM1509518,GSM1509519,GSM1509520,GSM1509521,GSM1509522,GSM1509523,GSM1509524,GSM1509525,GSM1509526,GSM1509527,GSM1509528,GSM1509529,GSM1509530,GSM1509531,GSM1509532,GSM1509533,GSM1509534,GSM1509535,GSM1509536,GSM1509537
2
+ Essential_Thrombocythemia,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,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
p3/preprocess/Essential_Thrombocythemia/code/GSE103176.py ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Essential_Thrombocythemia"
6
+ cohort = "GSE103176"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Essential_Thrombocythemia"
10
+ in_cohort_dir = "../DATA/GEO/Essential_Thrombocythemia/GSE103176"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Essential_Thrombocythemia/GSE103176.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Essential_Thrombocythemia/gene_data/GSE103176.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Essential_Thrombocythemia/clinical_data/GSE103176.csv"
16
+ json_path = "./output/preprocess/3/Essential_Thrombocythemia/cohort_info.json"
17
+
18
+ # Get relevant file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data from the matrix file
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get dictionary of unique values per row in clinical data
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Background Information:")
29
+ print("-" * 50)
30
+ print(background_info)
31
+ print("\n")
32
+
33
+ # Print clinical data unique values
34
+ print("Sample Characteristics:")
35
+ print("-" * 50)
36
+ for row, values in unique_values_dict.items():
37
+ print(f"{row}:")
38
+ print(f" {values}")
39
+ print()
40
+ # 1. Gene Expression Data Availability
41
+ # Series title mentions "Gene... expression profiles", so gene data is available
42
+ is_gene_available = True
43
+
44
+ # 2. Variable Availability and Data Row Identification
45
+ # 2.1 Data Type Selection and Data Row Identification
46
+ # Trait (ET vs Control) can be found in row 3 under 'disease'
47
+ trait_row = 3
48
+
49
+ # Age is not provided in the characteristics
50
+ age_row = None
51
+
52
+ # Gender is in row 1 under 'Sex'
53
+ gender_row = 1
54
+
55
+ # 2.2 Data Type Conversion Functions
56
+ def convert_trait(value: str) -> int:
57
+ """Convert disease status to binary (0: control, 1: ET)"""
58
+ if pd.isna(value):
59
+ return None
60
+ value = value.split(': ')[-1].strip().lower()
61
+ if 'et' in value:
62
+ return 1
63
+ elif 'healthy control' in value:
64
+ return 0
65
+ return None
66
+
67
+ def convert_age(value: str) -> float:
68
+ """Convert age to float - not used since age not available"""
69
+ return None
70
+
71
+ def convert_gender(value: str) -> int:
72
+ """Convert gender to binary (0: female, 1: male)"""
73
+ if pd.isna(value):
74
+ return None
75
+ value = value.split(': ')[-1].strip().lower()
76
+ if value == 'f':
77
+ return 0
78
+ elif value == 'm':
79
+ return 1
80
+ return None
81
+
82
+ # 3. Save Metadata
83
+ is_trait_available = trait_row is not None
84
+ validate_and_save_cohort_info(
85
+ is_final=False,
86
+ cohort=cohort,
87
+ info_path=json_path,
88
+ is_gene_available=is_gene_available,
89
+ is_trait_available=is_trait_available
90
+ )
91
+
92
+ # 4. Extract Clinical Features
93
+ if trait_row is not None:
94
+ selected_clinical = geo_select_clinical_features(
95
+ clinical_df=clinical_data,
96
+ trait=trait,
97
+ trait_row=trait_row,
98
+ convert_trait=convert_trait,
99
+ age_row=age_row,
100
+ convert_age=convert_age,
101
+ gender_row=gender_row,
102
+ convert_gender=convert_gender
103
+ )
104
+
105
+ # Preview the extracted features
106
+ preview_result = preview_df(selected_clinical)
107
+ print("Preview of extracted clinical features:")
108
+ print(preview_result)
109
+
110
+ # Save to CSV
111
+ selected_clinical.to_csv(out_clinical_data_file)
112
+ # Extract gene expression data
113
+ genetic_data = get_genetic_data(matrix_file_path)
114
+
115
+ # Print first 20 probe IDs
116
+ print("First 20 probe IDs:")
117
+ print(genetic_data.index[:20])
118
+ # The identifiers appear to be probe IDs from a microarray platform, not standard gene symbols
119
+ # They need to be mapped to human gene symbols for analysis
120
+ requires_gene_mapping = True
121
+ # Extract gene annotation from SOFT file
122
+ gene_annotation = get_gene_annotation(soft_file_path)
123
+
124
+ # Preview column names and first few values
125
+ preview_dict = preview_df(gene_annotation)
126
+ print("Column names and preview values:")
127
+ for col, values in preview_dict.items():
128
+ print(f"\n{col}:")
129
+ print(values)
130
+ # Get unique probe IDs from gene expression data to understand the format
131
+ probe_examples = genetic_data.index[:5].tolist()
132
+
133
+ # Extract the complete platform annotation table
134
+ gene_annotation = get_gene_annotation(soft_file_path, prefixes=['!platform_table_begin', '!platform_table_end'])
135
+
136
+ # Extract columns for mapping and rename them
137
+ mapping_data = get_gene_mapping(gene_annotation, prob_col='ID_REF', gene_col='Gene Symbol')
138
+
139
+ # Apply mapping to convert probe-level data to gene-level data
140
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
141
+
142
+ # Preview the result
143
+ print("\nExample probe IDs from expression data:")
144
+ print(probe_examples)
145
+
146
+ print("\nFirst 5 rows of mapping data:")
147
+ print(mapping_data.head())
148
+
149
+ print("\nFirst 5 rows and 3 columns of mapped gene expression data:")
150
+ print(gene_data.iloc[:5, :3])
151
+ # Get unique probe IDs from gene expression data to understand the format
152
+ probe_examples = genetic_data.index[:5].tolist()
153
+
154
+ # Extract the complete platform annotation table
155
+ gene_annotation = get_gene_annotation(soft_file_path)
156
+ print("\nRaw annotation data columns:")
157
+ print(gene_annotation.columns.tolist())
158
+
159
+ # Based on column names in the raw data, we can see that probe IDs are in the 'ID' column
160
+ # and gene symbols are in the 'Gene Symbol' column
161
+ mapping_data = pd.DataFrame({
162
+ 'ID': gene_annotation['ID'],
163
+ 'Gene': gene_annotation['Gene Symbol']
164
+ })
165
+
166
+ # Fix any NaN values that might cause mapping issues
167
+ mapping_data = mapping_data.dropna()
168
+
169
+ # Apply mapping to convert probe-level data to gene-level data
170
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
171
+
172
+ # Save gene expression data
173
+ gene_data.to_csv(out_gene_data_file)
174
+
175
+ # Preview results
176
+ print("\nExample probe IDs from expression data:")
177
+ print(probe_examples)
178
+
179
+ print("\nFirst 5 rows of mapping data:")
180
+ print(mapping_data.head())
181
+
182
+ print("\nFirst 5 rows and 3 columns of mapped gene expression data:")
183
+ print(gene_data.iloc[:5, :3])
184
+ # Check if genetic data is empty
185
+ if genetic_data.empty:
186
+ print("Gene expression data is empty - cannot proceed with linking and analysis")
187
+ # Record failure in cohort info
188
+ is_usable = validate_and_save_cohort_info(
189
+ is_final=True,
190
+ cohort=cohort,
191
+ info_path=json_path,
192
+ is_gene_available=False,
193
+ is_trait_available=True,
194
+ is_biased=None,
195
+ df=None,
196
+ note="Gene mapping failed - unable to match probe IDs between expression and annotation data"
197
+ )
198
+ else:
199
+ # 1. Normalize gene symbols and save normalized gene data
200
+ normalized_gene_data = normalize_gene_symbols_in_index(genetic_data)
201
+ normalized_gene_data.to_csv(out_gene_data_file)
202
+
203
+ # Read the processed clinical data file
204
+ clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
205
+
206
+ # Link clinical and genetic data using the normalized gene data
207
+ linked_data = geo_link_clinical_genetic_data(clinical_df, normalized_gene_data)
208
+
209
+ # Handle missing values systematically
210
+ linked_data = handle_missing_values(linked_data, trait)
211
+
212
+ # Detect bias in trait and demographic features, remove biased demographic features
213
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
214
+
215
+ # Validate data quality and save cohort info
216
+ note = "Expression data comparing patients with Essential Thrombocythemia to controls with other myeloproliferative disorders (PMF, PV). No age or gender data available."
217
+ is_usable = validate_and_save_cohort_info(
218
+ is_final=True,
219
+ cohort=cohort,
220
+ info_path=json_path,
221
+ is_gene_available=True,
222
+ is_trait_available=True,
223
+ is_biased=is_biased,
224
+ df=linked_data,
225
+ note=note
226
+ )
227
+
228
+ # Save linked data if usable
229
+ if is_usable:
230
+ linked_data.to_csv(out_data_file)
231
+ else:
232
+ print(f"Dataset {cohort} did not pass quality validation and will not be saved.")
p3/preprocess/Essential_Thrombocythemia/code/GSE103237.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Essential_Thrombocythemia"
6
+ cohort = "GSE103237"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Essential_Thrombocythemia"
10
+ in_cohort_dir = "../DATA/GEO/Essential_Thrombocythemia/GSE103237"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Essential_Thrombocythemia/GSE103237.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Essential_Thrombocythemia/gene_data/GSE103237.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Essential_Thrombocythemia/clinical_data/GSE103237.csv"
16
+ json_path = "./output/preprocess/3/Essential_Thrombocythemia/cohort_info.json"
17
+
18
+ # Get relevant file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data from the matrix file
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get dictionary of unique values per row in clinical data
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Background Information:")
29
+ print("-" * 50)
30
+ print(background_info)
31
+ print("\n")
32
+
33
+ # Print clinical data unique values
34
+ print("Sample Characteristics:")
35
+ print("-" * 50)
36
+ for row, values in unique_values_dict.items():
37
+ print(f"{row}:")
38
+ print(f" {values}")
39
+ print()
40
+ # 1. Gene Expression Data Availability
41
+ # Yes, this dataset contains gene expression data, as indicated in the background info
42
+ # "Gene expression profile (GEP) and miRNA expression profile (miEP) were performed..."
43
+ is_gene_available = True
44
+
45
+ # 2. Variable Availability and Data Type Conversion
46
+ # 2.1 Data Availability
47
+ # Trait (Essential Thrombocythemia) can be inferred from disease field (row 3)
48
+ trait_row = 3
49
+
50
+ # Gender is available in row 1
51
+ gender_row = 1
52
+
53
+ # No age information available
54
+ age_row = None
55
+
56
+ # 2.2 Data Type Conversion Functions
57
+ def convert_trait(value: str) -> int:
58
+ """Convert disease status to binary (0: control, 1: ET)"""
59
+ if not value or 'disease: ' not in value:
60
+ return None
61
+ value = value.split('disease: ')[1].strip().lower()
62
+ if value == 'et':
63
+ return 1
64
+ elif value == 'healthy control':
65
+ return 0
66
+ return None
67
+
68
+ def convert_gender(value: str) -> int:
69
+ """Convert gender to binary (0: female, 1: male)"""
70
+ if not value or 'Sex: ' not in value:
71
+ return None
72
+ value = value.split('Sex: ')[1].strip().lower()
73
+ if value == 'f':
74
+ return 0
75
+ elif value == 'm':
76
+ return 1
77
+ return None
78
+
79
+ def convert_age(value: str) -> float:
80
+ """Placeholder function since age is not available"""
81
+ return None
82
+
83
+ # 3. Save Metadata
84
+ # Initial filtering based on gene and trait availability
85
+ validate_and_save_cohort_info(
86
+ is_final=False,
87
+ cohort=cohort,
88
+ info_path=json_path,
89
+ is_gene_available=is_gene_available,
90
+ is_trait_available=trait_row is not None
91
+ )
92
+
93
+ # 4. Clinical Feature Extraction
94
+ if trait_row is not None:
95
+ # Extract clinical features
96
+ clinical_df = geo_select_clinical_features(
97
+ clinical_df=clinical_data,
98
+ trait=trait,
99
+ trait_row=trait_row,
100
+ convert_trait=convert_trait,
101
+ gender_row=gender_row,
102
+ convert_gender=convert_gender
103
+ )
104
+
105
+ # Preview the extracted features
106
+ print("Preview of extracted clinical features:")
107
+ print(preview_df(clinical_df))
108
+
109
+ # Save clinical data
110
+ clinical_df.to_csv(out_clinical_data_file)
111
+ # Extract gene expression data
112
+ genetic_data = get_genetic_data(matrix_file_path)
113
+
114
+ # Print first 20 probe IDs
115
+ print("First 20 probe IDs:")
116
+ print(genetic_data.index[:20])
117
+ # These identifiers look like Affymetrix probe IDs (e.g. 11715100_at format)
118
+ # Rather than standard human gene symbols (e.g. BRCA1)
119
+ # They will need to be mapped to gene symbols
120
+ requires_gene_mapping = True
121
+ # Extract gene annotation from SOFT file
122
+ gene_annotation = get_gene_annotation(soft_file_path)
123
+
124
+ # Preview column names and first few values
125
+ preview_dict = preview_df(gene_annotation)
126
+ print("Column names and preview values:")
127
+ for col, values in preview_dict.items():
128
+ print(f"\n{col}:")
129
+ print(values)
130
+ # Extract probe ID and gene symbol mapping from annotation data
131
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')
132
+
133
+ # Apply gene mapping to convert probe level data to gene level data
134
+ gene_data = apply_gene_mapping(genetic_data, mapping_df)
135
+
136
+ # Preview the results
137
+ print("First 5 genes and their expression values:")
138
+ print(preview_df(gene_data.head()))
139
+ # 1. Normalize gene symbols and save normalized gene data
140
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
141
+ normalized_gene_data.to_csv(out_gene_data_file)
142
+
143
+ # Read the processed clinical data file
144
+ clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
145
+
146
+ # Link clinical and genetic data using the normalized gene data
147
+ linked_data = geo_link_clinical_genetic_data(clinical_df, normalized_gene_data)
148
+
149
+ # Handle missing values systematically
150
+ linked_data = handle_missing_values(linked_data, trait)
151
+
152
+ # Detect bias in trait and demographic features, remove biased demographic features
153
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
154
+
155
+ # Validate data quality and save cohort info
156
+ note = "Expression data comparing patients with Essential Thrombocythemia to controls with other myeloproliferative disorders (PMF, PV). No age or gender data available."
157
+ is_usable = validate_and_save_cohort_info(
158
+ is_final=True,
159
+ cohort=cohort,
160
+ info_path=json_path,
161
+ is_gene_available=True,
162
+ is_trait_available=True,
163
+ is_biased=is_biased,
164
+ df=linked_data,
165
+ note=note
166
+ )
167
+
168
+ # Save linked data if usable
169
+ if is_usable:
170
+ linked_data.to_csv(out_data_file)
171
+ else:
172
+ print(f"Dataset {cohort} did not pass quality validation and will not be saved.")