Liu-Hy commited on
Commit
0a0878d
·
verified ·
1 Parent(s): ba45cf6

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/Hypertrophic_Cardiomyopathy/gene_data/GSE36961.csv +3 -0
  3. p3/preprocess/Hypothyroidism/TCGA.csv +3 -0
  4. p3/preprocess/Hypothyroidism/gene_data/GSE75678.csv +3 -0
  5. p3/preprocess/Hypothyroidism/gene_data/TCGA.csv +3 -0
  6. p3/preprocess/Insomnia/GSE208668.csv +0 -0
  7. p3/preprocess/Insomnia/code/GSE208668.py +151 -0
  8. p3/preprocess/Insomnia/code/TCGA.py +32 -0
  9. p3/preprocess/Insomnia/gene_data/GSE208668.csv +0 -0
  10. p3/preprocess/Intellectual_Disability/GSE100680.csv +0 -0
  11. p3/preprocess/Intellectual_Disability/GSE158385.csv +0 -0
  12. p3/preprocess/Intellectual_Disability/GSE192767.csv +3 -0
  13. p3/preprocess/Intellectual_Disability/GSE273850.csv +3 -0
  14. p3/preprocess/Intellectual_Disability/GSE285666.csv +0 -0
  15. p3/preprocess/Intellectual_Disability/GSE63870.csv +3 -0
  16. p3/preprocess/Intellectual_Disability/GSE98697.csv +3 -0
  17. p3/preprocess/Intellectual_Disability/clinical_data/GSE100680.csv +3 -0
  18. p3/preprocess/Intellectual_Disability/clinical_data/GSE158385.csv +2 -0
  19. p3/preprocess/Intellectual_Disability/clinical_data/GSE192767.csv +2 -0
  20. p3/preprocess/Intellectual_Disability/clinical_data/GSE200864.csv +2 -0
  21. p3/preprocess/Intellectual_Disability/clinical_data/GSE273850.csv +3 -0
  22. p3/preprocess/Intellectual_Disability/clinical_data/GSE285666.csv +2 -0
  23. p3/preprocess/Intellectual_Disability/clinical_data/GSE59630.csv +4 -0
  24. p3/preprocess/Intellectual_Disability/clinical_data/GSE63870.csv +3 -0
  25. p3/preprocess/Intellectual_Disability/clinical_data/GSE89594.csv +4 -0
  26. p3/preprocess/Intellectual_Disability/clinical_data/GSE98697.csv +2 -0
  27. p3/preprocess/Intellectual_Disability/code/GSE100680.py +183 -0
  28. p3/preprocess/Intellectual_Disability/code/GSE158385.py +200 -0
  29. p3/preprocess/Intellectual_Disability/code/GSE192767.py +172 -0
  30. p3/preprocess/Intellectual_Disability/code/GSE200864.py +130 -0
  31. p3/preprocess/Intellectual_Disability/code/GSE273850.py +177 -0
  32. p3/preprocess/Intellectual_Disability/code/GSE285666.py +178 -0
  33. p3/preprocess/Intellectual_Disability/code/GSE59630.py +196 -0
  34. p3/preprocess/Intellectual_Disability/code/GSE63870.py +185 -0
  35. p3/preprocess/Intellectual_Disability/code/GSE89594.py +192 -0
  36. p3/preprocess/Intellectual_Disability/code/GSE98697.py +178 -0
  37. p3/preprocess/Intellectual_Disability/code/TCGA.py +32 -0
  38. p3/preprocess/Intellectual_Disability/cohort_info.json +1 -0
  39. p3/preprocess/Intellectual_Disability/gene_data/GSE100680.csv +0 -0
  40. p3/preprocess/Intellectual_Disability/gene_data/GSE158385.csv +0 -0
  41. p3/preprocess/Intellectual_Disability/gene_data/GSE192767.csv +3 -0
  42. p3/preprocess/Intellectual_Disability/gene_data/GSE200864.csv +3 -0
  43. p3/preprocess/Intellectual_Disability/gene_data/GSE273850.csv +3 -0
  44. p3/preprocess/Intellectual_Disability/gene_data/GSE285666.csv +0 -0
  45. p3/preprocess/Intellectual_Disability/gene_data/GSE59630.csv +3 -0
  46. p3/preprocess/Intellectual_Disability/gene_data/GSE63870.csv +3 -0
  47. p3/preprocess/Intellectual_Disability/gene_data/GSE89594.csv +3 -0
  48. p3/preprocess/Intellectual_Disability/gene_data/GSE98697.csv +3 -0
  49. p3/preprocess/Irritable_bowel_syndrome_(IBS)/GSE25220.csv +0 -0
  50. p3/preprocess/Irritable_bowel_syndrome_(IBS)/GSE36701.csv +3 -0
.gitattributes CHANGED
@@ -1804,3 +1804,29 @@ p3/preprocess/Sjögrens_Syndrome/GSE66795.csv filter=lfs diff=lfs merge=lfs -tex
1804
  p3/preprocess/Sjögrens_Syndrome/gene_data/GSE93683.csv filter=lfs diff=lfs merge=lfs -text
1805
  p3/preprocess/Sjögrens_Syndrome/gene_data/GSE51092.csv filter=lfs diff=lfs merge=lfs -text
1806
  p3/preprocess/Sjögrens_Syndrome/gene_data/GSE66795.csv filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1804
  p3/preprocess/Sjögrens_Syndrome/gene_data/GSE93683.csv filter=lfs diff=lfs merge=lfs -text
1805
  p3/preprocess/Sjögrens_Syndrome/gene_data/GSE51092.csv filter=lfs diff=lfs merge=lfs -text
1806
  p3/preprocess/Sjögrens_Syndrome/gene_data/GSE66795.csv filter=lfs diff=lfs merge=lfs -text
1807
+ p3/preprocess/Hypothyroidism/gene_data/GSE75678.csv filter=lfs diff=lfs merge=lfs -text
1808
+ p3/preprocess/Hypertrophic_Cardiomyopathy/gene_data/GSE36961.csv filter=lfs diff=lfs merge=lfs -text
1809
+ p3/preprocess/Lower_Grade_Glioma/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1810
+ p3/preprocess/Intellectual_Disability/GSE192767.csv filter=lfs diff=lfs merge=lfs -text
1811
+ p3/preprocess/Intellectual_Disability/GSE273850.csv filter=lfs diff=lfs merge=lfs -text
1812
+ p3/preprocess/Intellectual_Disability/GSE63870.csv filter=lfs diff=lfs merge=lfs -text
1813
+ p3/preprocess/Intellectual_Disability/GSE98697.csv filter=lfs diff=lfs merge=lfs -text
1814
+ p3/preprocess/Sjögrens_Syndrome/gene_data/GSE140161.csv filter=lfs diff=lfs merge=lfs -text
1815
+ p3/preprocess/Intellectual_Disability/gene_data/GSE200864.csv filter=lfs diff=lfs merge=lfs -text
1816
+ p3/preprocess/Intellectual_Disability/gene_data/GSE192767.csv filter=lfs diff=lfs merge=lfs -text
1817
+ p3/preprocess/Intellectual_Disability/gene_data/GSE273850.csv filter=lfs diff=lfs merge=lfs -text
1818
+ p3/preprocess/Intellectual_Disability/gene_data/GSE63870.csv filter=lfs diff=lfs merge=lfs -text
1819
+ p3/preprocess/Intellectual_Disability/gene_data/GSE59630.csv filter=lfs diff=lfs merge=lfs -text
1820
+ p3/preprocess/Intellectual_Disability/gene_data/GSE89594.csv filter=lfs diff=lfs merge=lfs -text
1821
+ p3/preprocess/Intellectual_Disability/gene_data/GSE98697.csv filter=lfs diff=lfs merge=lfs -text
1822
+ p3/preprocess/Irritable_bowel_syndrome_(IBS)/GSE63379.csv filter=lfs diff=lfs merge=lfs -text
1823
+ p3/preprocess/Irritable_bowel_syndrome_(IBS)/GSE66824.csv filter=lfs diff=lfs merge=lfs -text
1824
+ p3/preprocess/Hypothyroidism/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1825
+ p3/preprocess/Irritable_bowel_syndrome_(IBS)/gene_data/GSE138297.csv filter=lfs diff=lfs merge=lfs -text
1826
+ p3/preprocess/Irritable_bowel_syndrome_(IBS)/GSE36701.csv filter=lfs diff=lfs merge=lfs -text
1827
+ p3/preprocess/Irritable_bowel_syndrome_(IBS)/gene_data/GSE66824.csv filter=lfs diff=lfs merge=lfs -text
1828
+ p3/preprocess/Irritable_bowel_syndrome_(IBS)/gene_data/GSE63379.csv filter=lfs diff=lfs merge=lfs -text
1829
+ p3/preprocess/Irritable_bowel_syndrome_(IBS)/gene_data/GSE20881.csv filter=lfs diff=lfs merge=lfs -text
1830
+ p3/preprocess/Hypothyroidism/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1831
+ p3/preprocess/Irritable_bowel_syndrome_(IBS)/gene_data/GSE36701.csv filter=lfs diff=lfs merge=lfs -text
1832
+ p3/preprocess/Kidney_Chromophobe/GSE26574.csv filter=lfs diff=lfs merge=lfs -text
p3/preprocess/Hypertrophic_Cardiomyopathy/gene_data/GSE36961.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0fd3cb153e8a94a03d27a8048601cf21af7c6b47d562397e7c7c0d3e9e2ed1bf
3
+ size 32368017
p3/preprocess/Hypothyroidism/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:291fbb9e789469e928d5eb54d36e860f286cc4d64ffd237caf5b24912716f189
3
+ size 172250060
p3/preprocess/Hypothyroidism/gene_data/GSE75678.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:48a79b5b9e72d2a7d7d689fda0b25afad08f2639268aca6975fc01f897092144
3
+ size 12484984
p3/preprocess/Hypothyroidism/gene_data/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:116506c96e07673dc76e9ed5290370c62b4b440443ef1e3d87b96279aa4b80e6
3
+ size 172246036
p3/preprocess/Insomnia/GSE208668.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Insomnia/code/GSE208668.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Insomnia"
6
+ cohort = "GSE208668"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Insomnia"
10
+ in_cohort_dir = "../DATA/GEO/Insomnia/GSE208668"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Insomnia/GSE208668.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Insomnia/gene_data/GSE208668.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Insomnia/clinical_data/GSE208668.csv"
16
+ json_path = "./output/preprocess/3/Insomnia/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get unique values for each clinical feature
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background information
28
+ print("Background Information:")
29
+ print(background_info)
30
+ print("\nSample Characteristics:")
31
+ print(json.dumps(unique_values_dict, indent=2))
32
+ # 1. Gene Expression Data Availability
33
+ # From background info, it's genome-wide transcriptional profiling of PBMCs
34
+ # Though raw data was lost, it's still gene expression data
35
+ is_gene_available = True
36
+
37
+ # 2. Variable Availability and Data Type Conversion
38
+ # 2.1 Data Availability
39
+ trait_row = 0 # 'insomnia' is in row 0
40
+ age_row = 1 # 'age' is in row 1
41
+ gender_row = 2 # 'gender' is in row 2
42
+
43
+ # 2.2 Data Type Conversion Functions
44
+ def convert_trait(value: str) -> Optional[int]:
45
+ if not isinstance(value, str):
46
+ return None
47
+ value = value.lower().split(": ")[-1].strip()
48
+ if value == "yes":
49
+ return 1
50
+ elif value == "no":
51
+ return 0
52
+ return None
53
+
54
+ def convert_age(value: str) -> Optional[float]:
55
+ if not isinstance(value, str):
56
+ return None
57
+ try:
58
+ age = float(value.split(": ")[-1].strip())
59
+ return age
60
+ except:
61
+ return None
62
+
63
+ def convert_gender(value: str) -> Optional[int]:
64
+ if not isinstance(value, str):
65
+ return None
66
+ value = value.lower().split(": ")[-1].strip()
67
+ if value == "female":
68
+ return 0
69
+ elif value == "male":
70
+ return 1
71
+ return None
72
+
73
+ # 3. Save Metadata - Initial Filtering
74
+ is_trait_available = trait_row is not None
75
+ initial_validation = validate_and_save_cohort_info(
76
+ 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
+
83
+ # 4. Clinical Feature Extraction
84
+ if trait_row is not None:
85
+ selected_clinical = geo_select_clinical_features(
86
+ clinical_df=clinical_data,
87
+ trait=trait,
88
+ trait_row=trait_row,
89
+ convert_trait=convert_trait,
90
+ age_row=age_row,
91
+ convert_age=convert_age,
92
+ gender_row=gender_row,
93
+ convert_gender=convert_gender
94
+ )
95
+
96
+ # Preview the processed data
97
+ preview = preview_df(selected_clinical)
98
+ print("Preview of processed clinical data:")
99
+ print(preview)
100
+
101
+ # Save to CSV
102
+ selected_clinical.to_csv(out_clinical_data_file)
103
+ # Extract gene expression data from the matrix file
104
+ genetic_data = get_genetic_data(matrix_file_path)
105
+
106
+ # Print first 20 row IDs
107
+ print("First 20 row IDs:")
108
+ print(genetic_data.index[:20].tolist())
109
+ requires_gene_mapping = False # The gene identifiers are already in human gene symbol format. No mapping needed.
110
+ # 1. Normalize gene symbols
111
+ genetic_data = normalize_gene_symbols_in_index(genetic_data)
112
+ genetic_data.to_csv(out_gene_data_file)
113
+
114
+ # Get clinical features
115
+ clinical_features = geo_select_clinical_features(
116
+ clinical_data,
117
+ trait=trait,
118
+ trait_row=trait_row,
119
+ convert_trait=convert_trait,
120
+ age_row=age_row,
121
+ convert_age=convert_age,
122
+ gender_row=gender_row,
123
+ convert_gender=convert_gender
124
+ )
125
+
126
+ # 2. Link clinical and genetic data
127
+ linked_data = geo_link_clinical_genetic_data(clinical_features, genetic_data)
128
+
129
+ # 3. Handle missing values
130
+ linked_data = handle_missing_values(linked_data, trait)
131
+
132
+ # 4. Judge whether features are biased and remove biased demographic features
133
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
134
+
135
+ # 5. Final validation and save metadata
136
+ note = "Dataset contains genome-wide transcriptional profiling of PBMCs from older adults with and without insomnia disorder."
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 the linked data only if it's usable
149
+ if is_usable:
150
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
151
+ linked_data.to_csv(out_data_file)
p3/preprocess/Insomnia/code/TCGA.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Insomnia"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/3/Insomnia/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/3/Insomnia/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/3/Insomnia/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/3/Insomnia/cohort_info.json"
15
+
16
+ # Get subdirectories from TCGA root directory
17
+ tcga_subdirs = os.listdir(tcga_root_dir)
18
+ tcga_subdirs = [d for d in tcga_subdirs if not d.startswith('.')]
19
+
20
+ # Review available subdirectories for insomnia-related cohorts
21
+ # No suitable cohort found - all are cancer specific and not related to sleep disorders
22
+ print(f"No suitable TCGA cohort found for {trait}.")
23
+ print("Available cohorts are cancer-specific and do not contain relevant data for sleep disorders.")
24
+
25
+ # Record that this trait should be skipped due to lack of suitable data
26
+ is_gene_available = False
27
+ is_trait_available = False
28
+ validate_and_save_cohort_info(is_final=False,
29
+ cohort="TCGA",
30
+ info_path=json_path,
31
+ is_gene_available=is_gene_available,
32
+ is_trait_available=is_trait_available)
p3/preprocess/Insomnia/gene_data/GSE208668.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Intellectual_Disability/GSE100680.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Intellectual_Disability/GSE158385.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Intellectual_Disability/GSE192767.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:27d467e20cf766ce8f6257633e65caaf483f7ee3f6a90b3895af4a785f79af28
3
+ size 16853124
p3/preprocess/Intellectual_Disability/GSE273850.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c13ff0173cefc0e63ad81efd50273361f721536fd0da7147edc98d46a85c61c
3
+ size 16872976
p3/preprocess/Intellectual_Disability/GSE285666.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Intellectual_Disability/GSE63870.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a154e787dab3ce41e3ff011cf49f4b0d86466ed4ea403b238aa9cc12b744ea73
3
+ size 11793811
p3/preprocess/Intellectual_Disability/GSE98697.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:40fd1fe5ba10a18d7101e58e547ac3f6d2903d59a9a4e38341d41cf0931d19ef
3
+ size 10665312
p3/preprocess/Intellectual_Disability/clinical_data/GSE100680.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ,GSM2691139,GSM2691140,GSM2691141,GSM2691142,GSM2691143,GSM2691144,GSM2691145,GSM2691146,GSM2691147,GSM2691148,GSM2691149,GSM2691150,GSM2691151,GSM2691152,GSM2691153,GSM2691154,GSM2691155,GSM2691156,GSM2691157,GSM2691158,GSM2691159,GSM2691160,GSM2691161,GSM2691162,GSM2691163,GSM2691164,GSM2691165,GSM2691166,GSM2691167,GSM2691168,GSM2691169,GSM2691170,GSM2691171,GSM2691172
2
+ Intellectual_Disability,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0
3
+ Age,45.0,45.0,45.0,45.0,45.0,65.0,65.0,65.0,65.0,65.0,65.0,45.0,45.0,45.0,45.0,45.0,65.0,65.0,65.0,65.0,65.0,65.0,45.0,45.0,45.0,45.0,45.0,45.0,65.0,65.0,65.0,65.0,65.0,65.0
p3/preprocess/Intellectual_Disability/clinical_data/GSE158385.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM4798573,GSM4798574,GSM4798575,GSM4798576,GSM4798577,GSM4798578,GSM4798579,GSM4798580,GSM4798581,GSM4798582,GSM4798583,GSM4798584,GSM4798585,GSM4798586,GSM4798587,GSM4798588,GSM4798589,GSM4798590,GSM4798591,GSM4798592,GSM4798593,GSM4798594,GSM4798595,GSM4798596,GSM4798597,GSM4798598,GSM4798599,GSM4798600
2
+ Intellectual_Disability,0.0,0.0,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,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
p3/preprocess/Intellectual_Disability/clinical_data/GSE192767.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM5765052,GSM5765053,GSM5765054,GSM5765055,GSM5765056,GSM5765057,GSM5765058,GSM5765059,GSM5765060,GSM5765061,GSM5765062,GSM5765063,GSM5765064,GSM5765065,GSM5765066,GSM5765067,GSM5765068,GSM5765069,GSM5765070,GSM5765071,GSM5765072,GSM5765073,GSM5765074,GSM5765075,GSM5765076,GSM5765077,GSM5765078,GSM5765079,GSM5765080,GSM5765081,GSM5765082,GSM5765083,GSM5765084,GSM5765085,GSM5765086,GSM5765087,GSM5765088,GSM5765089,GSM5765090,GSM5765091,GSM5765092,GSM5765093,GSM5765094,GSM5765095,GSM5765096,GSM5765097,GSM5765098,GSM5765099
2
+ Intellectual_Disability,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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/Intellectual_Disability/clinical_data/GSE200864.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM6045608,GSM6045609,GSM6045610,GSM6045611,GSM6045612,GSM6045613,GSM6045614,GSM6045615,GSM6045616,GSM6045617,GSM6045618,GSM6045619,GSM6045620,GSM6045621,GSM6045622,GSM6045623,GSM6045624,GSM6045625,GSM6045626,GSM6045627,GSM6045628,GSM6045629,GSM6045630,GSM6045631,GSM6045632,GSM6045633,GSM6045634,GSM6045635,GSM6045636,GSM6045637,GSM6045638,GSM6045639,GSM6045640,GSM6045641,GSM6045642,GSM6045643,GSM6045644,GSM6045645,GSM6045646,GSM6045647,GSM6045648,GSM6045649,GSM6045650,GSM6045651,GSM6045652,GSM6045653,GSM6045654,GSM6045655,GSM6045656,GSM6045657,GSM6045658,GSM6045659,GSM6045660,GSM6045661,GSM6045662,GSM6045663,GSM6045664,GSM6045665,GSM6045666,GSM6045667,GSM6045668,GSM6045669,GSM6045670,GSM6045671
2
+ Intellectual_Disability,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
p3/preprocess/Intellectual_Disability/clinical_data/GSE273850.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ,GSM8438101,GSM8438102,GSM8438103,GSM8438104,GSM8438105,GSM8438106,GSM8438107,GSM8438108,GSM8438109,GSM8438110,GSM8438111,GSM8438112,GSM8438113,GSM8438114,GSM8438115,GSM8438116,GSM8438117,GSM8438118,GSM8438119,GSM8438120,GSM8438121,GSM8438122,GSM8438123,GSM8438124,GSM8438125,GSM8438126,GSM8438127,GSM8438128,GSM8438129,GSM8438130,GSM8438131,GSM8438132,GSM8438133,GSM8438134,GSM8438135,GSM8438136,GSM8438137,GSM8438138,GSM8438139,GSM8438140,GSM8438141,GSM8438142,GSM8438143,GSM8438144,GSM8438145,GSM8438146,GSM8438147,GSM8438148,GSM8438149,GSM8438150,GSM8438151
2
+ Intellectual_Disability,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.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
3
+ Gender,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0
p3/preprocess/Intellectual_Disability/clinical_data/GSE285666.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM8706502,GSM8706503,GSM8706504,GSM8706505,GSM8706506,GSM8706507,GSM8706508,GSM8706509,GSM8706510,GSM8706511,GSM8706512,GSM8706513,GSM8706514,GSM8706515,GSM8706516,GSM8706517,GSM8706518,GSM8706519,GSM8706520,GSM8706521,GSM8706522,GSM8706523,GSM8706524,GSM8706525,GSM8706526,GSM8706527,GSM8706528,GSM8706529,GSM8706530,GSM8706531,GSM8706532,GSM8706533,GSM8706534,GSM8706535,GSM8706536,GSM8706537,GSM8706538,GSM8706539,GSM8706540,GSM8706541,GSM8706542,GSM8706543,GSM8706544,GSM8706545,GSM8706546,GSM8706547,GSM8706548,GSM8706549,GSM8706550,GSM8706551,GSM8706552,GSM8706553
2
+ Intellectual_Disability,0.0,0.0,0.0,0.0,0.0,0.0,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,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
p3/preprocess/Intellectual_Disability/clinical_data/GSE59630.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ ,GSM1440797,GSM1440798,GSM1440799,GSM1440800,GSM1440801,GSM1440802,GSM1440803,GSM1440804,GSM1440805,GSM1440806,GSM1440807,GSM1440808,GSM1440809,GSM1440810,GSM1440811,GSM1440812,GSM1440813,GSM1440814,GSM1440815,GSM1440816,GSM1440817,GSM1440818,GSM1440819,GSM1440820,GSM1440821,GSM1440822,GSM1440823,GSM1440824,GSM1440825,GSM1440826,GSM1440827,GSM1440828,GSM1440829,GSM1440830,GSM1440831,GSM1440832,GSM1440833,GSM1440834,GSM1440835,GSM1440836,GSM1440837,GSM1440838,GSM1440839,GSM1440840,GSM1440841,GSM1440842,GSM1440843,GSM1440844,GSM1440845,GSM1440846,GSM1440847,GSM1440848,GSM1440849,GSM1440850,GSM1440851,GSM1440852,GSM1440853,GSM1440854,GSM1440855,GSM1440856,GSM1440857,GSM1440858,GSM1440859,GSM1440860,GSM1440861,GSM1440862,GSM1440863,GSM1440864,GSM1440865,GSM1440866,GSM1440867,GSM1440868,GSM1440869,GSM1440870,GSM1440871,GSM1440872,GSM1440873,GSM1440874,GSM1440875,GSM1440876,GSM1440877,GSM1440878,GSM1440879,GSM1440880,GSM1440881,GSM1440882,GSM1440883,GSM1440884,GSM1440885,GSM1440886,GSM1440887,GSM1440888,GSM1440889,GSM1440890,GSM1440891,GSM1440892,GSM1440893,GSM1440894,GSM1440895,GSM1440896,GSM1440897,GSM1440898,GSM1440899,GSM1440900,GSM1440901,GSM1440902,GSM1440903,GSM1440904,GSM1440905,GSM1440906,GSM1440907,GSM1440908,GSM1440909,GSM1440910,GSM1440911,GSM1440912
2
+ Intellectual_Disability,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,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
3
+ Age,0.3269230769230769,0.36538461538461536,0.36538461538461536,0.4230769230769231,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.8333333333333334,0.8333333333333334,0.8333333333333334,0.8333333333333334,0.8333333333333334,0.8333333333333334,0.8333333333333334,0.8333333333333334,0.8333333333333334,0.8333333333333334,1.0,1.0,2.0,2.0,3.0,3.0,3.0,3.0,3.0,3.0,8.0,8.0,8.0,15.0,15.0,15.0,15.0,18.0,18.0,18.0,22.0,22.0,22.0,30.0,30.0,30.0,30.0,30.0,30.0,30.0,42.0,42.0,42.0,42.0,0.3076923076923077,0.36538461538461536,0.36538461538461536,0.4230769230769231,0.08333333333333333,0.08333333333333333,0.08333333333333333,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.75,0.75,0.75,0.75,0.75,0.75,0.75,0.75,0.75,0.75,1.1666666666666667,1.1666666666666667,3.0,3.0,3.0,3.0,3.0,3.0,2.0,2.0,10.0,10.0,10.0,13.0,13.0,13.0,13.0,19.0,19.0,19.0,22.0,22.0,22.0,39.0,39.0,39.0,39.0,39.0,39.0,39.0,40.0,40.0,40.0,40.0
4
+ Gender,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.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,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,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.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,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,1.0,1.0,1.0,1.0
p3/preprocess/Intellectual_Disability/clinical_data/GSE63870.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ,GSM1558696,GSM1558697,GSM1558698,GSM1558699,GSM1558700,GSM1558701,GSM1558702,GSM1558703,GSM1558704,GSM1558705,GSM1558706,GSM1558707,GSM1558708,GSM1558709,GSM1558710,GSM1558711,GSM1558712,GSM1558713,GSM1558714,GSM1558715,GSM1558716,GSM1558717,GSM1558718,GSM1558719,GSM1558720,GSM1558721,GSM1558722,GSM1558723,GSM1558724,GSM1558725,GSM1558726,GSM1558727,GSM1558728,GSM1558729,GSM1558730,GSM1558731,GSM1558732,GSM1558733,GSM1558734,GSM1558735,GSM1558736,GSM1558737,GSM1558738,GSM1558739,GSM1558740,GSM1558741,GSM1558742,GSM1558743
2
+ Intellectual_Disability,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,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
3
+ Age,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
p3/preprocess/Intellectual_Disability/clinical_data/GSE89594.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ ,GSM2384988,GSM2384989,GSM2384990,GSM2384991,GSM2384992,GSM2384993,GSM2384994,GSM2384995,GSM2384996,GSM2384997,GSM2384998,GSM2384999,GSM2385000,GSM2385001,GSM2385002,GSM2385003,GSM2385004,GSM2385005,GSM2385006,GSM2385007,GSM2385008,GSM2385009,GSM2385010,GSM2385011,GSM2385012,GSM2385013,GSM2385014,GSM2385015,GSM2385016,GSM2385017,GSM2385018,GSM2385019,GSM2385020,GSM2385021,GSM2385022,GSM2385023,GSM2385024,GSM2385025,GSM2385026,GSM2385027,GSM2385028,GSM2385029,GSM2385030,GSM2385031,GSM2385032,GSM2385033,GSM2385034,GSM2385035,GSM2385036,GSM2385037,GSM2385038,GSM2385039,GSM2385040,GSM2385041,GSM2385042,GSM2385043,GSM2385044,GSM2385045,GSM2385046,GSM2385047,GSM2385048,GSM2385049,GSM2385050,GSM2385051,GSM2385052,GSM2385053,GSM2385054,GSM2385055,GSM2385056,GSM2385057,GSM2385058,GSM2385059,GSM2385060,GSM2385061,GSM2385062,GSM2385063,GSM2385064,GSM2385065,GSM2385066,GSM2385067,GSM2385068,GSM2385069,GSM2385070,GSM2385071,GSM2385072,GSM2385073,GSM2385074,GSM2385075,GSM2385076,GSM2385077,GSM2385078,GSM2385079,GSM2385080,GSM2385081
2
+ Intellectual_Disability,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
3
+ Age,22.0,23.0,24.0,24.0,33.0,22.0,24.0,21.0,24.0,20.0,28.0,21.0,21.0,22.0,25.0,23.0,20.0,21.0,20.0,32.0,36.0,24.0,21.0,30.0,28.0,22.0,24.0,21.0,22.0,20.0,27.0,22.0,23.0,20.0,31.0,27.0,32.0,20.0,36.0,22.0,28.0,25.0,35.0,22.0,22.0,10.0,16.0,10.0,33.0,21.0,11.0,10.0,35.0,12.0,38.0,24.0,34.0,32.0,21.0,29.0,20.0,19.0,24.0,13.0,23.0,15.0,43.0,10.0,13.0,16.0,27.0,24.0,11.0,24.0,32.0,24.0,27.0,16.0,14.0,11.0,24.0,28.0,17.0,15.0,34.0,39.0,12.0,15.0,21.0,29.0,23.0,26.0,19.0,21.0
4
+ Gender,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0
p3/preprocess/Intellectual_Disability/clinical_data/GSE98697.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM2610219,GSM2610220,GSM2610221,GSM2610222,GSM2610223,GSM2610224,GSM2610225,GSM2610226,GSM2610227,GSM2610228,GSM2610229,GSM2610230,GSM2610231,GSM2610232,GSM2610233,GSM2610234,GSM2610235,GSM2610236,GSM2610237,GSM2610238,GSM2610239,GSM2610240,GSM2610241,GSM2610242,GSM2610243,GSM2610244,GSM2610245,GSM2610246,GSM2610247,GSM2610248,GSM2610249,GSM2610250,GSM2610251,GSM2610252,GSM2610253,GSM2610254,GSM2610255,GSM2610256,GSM2610257,GSM2610258,GSM2610259,GSM2610260,GSM2610261,GSM2610262,GSM2610263,GSM2610264,GSM2610265,GSM2610266
2
+ Intellectual_Disability,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
p3/preprocess/Intellectual_Disability/code/GSE100680.py ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Intellectual_Disability"
6
+ cohort = "GSE100680"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Intellectual_Disability"
10
+ in_cohort_dir = "../DATA/GEO/Intellectual_Disability/GSE100680"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Intellectual_Disability/GSE100680.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Intellectual_Disability/gene_data/GSE100680.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Intellectual_Disability/clinical_data/GSE100680.csv"
16
+ json_path = "./output/preprocess/3/Intellectual_Disability/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get unique values for each clinical feature
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background information
28
+ print("Background Information:")
29
+ print(background_info)
30
+ print("\nSample Characteristics:")
31
+ print(json.dumps(unique_values_dict, indent=2))
32
+ # 1. Gene Expression Data Availability
33
+ # Yes, this dataset appears to contain gene expression data based on the background information
34
+ # which mentions measuring APP expression levels and genome-wide effects
35
+ is_gene_available = True
36
+
37
+ # 2. Variable Availability and Data Type Conversion
38
+
39
+ # 2.1 Data Availability
40
+ # Trait (DS vs Control) can be inferred from field 3 (description)
41
+ trait_row = 3
42
+ # Age is in field 2
43
+ age_row = 2
44
+ # Gender is not available
45
+ gender_row = None
46
+
47
+ # 2.2 Data Type Conversion Functions
48
+ def convert_trait(value):
49
+ """Convert description to binary indicating if sample is DS (1) or control (0)"""
50
+ if not isinstance(value, str):
51
+ return None
52
+ value = value.split(': ')[-1]
53
+ if 'DS Clone' in value:
54
+ return 1
55
+ elif 'Euploid Clone' in value:
56
+ return 0
57
+ return None
58
+
59
+ def convert_age(value):
60
+ """Convert age string to numeric days"""
61
+ if not isinstance(value, str):
62
+ return None
63
+ value = value.split(': ')[-1]
64
+ if 'Day' in value:
65
+ try:
66
+ return float(value.replace('Day ', ''))
67
+ except:
68
+ return None
69
+ return None
70
+
71
+ def convert_gender(value):
72
+ """Not used since gender data is not available"""
73
+ return None
74
+
75
+ # 3. Save Initial Metadata
76
+ is_trait_available = trait_row is not None
77
+ validate_and_save_cohort_info(
78
+ is_final=False,
79
+ cohort=cohort,
80
+ info_path=json_path,
81
+ is_gene_available=is_gene_available,
82
+ is_trait_available=is_trait_available
83
+ )
84
+
85
+ # 4. Extract Clinical Features
86
+ clinical_features = geo_select_clinical_features(
87
+ clinical_df=clinical_data,
88
+ trait=trait,
89
+ trait_row=trait_row,
90
+ convert_trait=convert_trait,
91
+ age_row=age_row,
92
+ convert_age=convert_age,
93
+ gender_row=gender_row,
94
+ convert_gender=convert_gender
95
+ )
96
+
97
+ # Preview the extracted features
98
+ preview_df(clinical_features)
99
+
100
+ # Save clinical features
101
+ clinical_features.to_csv(out_clinical_data_file)
102
+ # Extract gene expression data from the matrix file
103
+ genetic_data = get_genetic_data(matrix_file_path)
104
+
105
+ # Print first 20 row IDs
106
+ print("First 20 row IDs:")
107
+ print(genetic_data.index[:20].tolist())
108
+ # These identifiers are ILMN (Illumina) probe IDs, not gene symbols
109
+ # The ILMN_ prefix indicates they are from an Illumina microarray platform
110
+ # They need to be mapped to official gene symbols
111
+ requires_gene_mapping = True
112
+ # Extract gene annotation data from SOFT file
113
+ gene_metadata = get_gene_annotation(soft_file_path)
114
+
115
+ # Drop rows where Symbol is null or contains phage/virus/bacteria
116
+ gene_metadata = gene_metadata[gene_metadata['Symbol'].notna()]
117
+ gene_metadata = gene_metadata[~gene_metadata['Symbol'].str.contains('phage|virus|bacteria',
118
+ case=False, na=False)]
119
+
120
+ # Display information about the annotation data
121
+ print("Column names:")
122
+ print(gene_metadata.columns.tolist())
123
+
124
+ # Look at general data statistics
125
+ print("\nData shape:", gene_metadata.shape)
126
+
127
+ # Preview the first few rows
128
+ print("\nPreview of the annotation data:")
129
+ print(json.dumps(preview_df(gene_metadata), indent=2))
130
+ # Get gene mapping data from annotation
131
+ # 'ID' column matches the ILMN probe IDs in expression data
132
+ # 'Symbol' column contains the gene symbols
133
+ mapping_data = get_gene_mapping(gene_metadata, 'ID', 'Symbol')
134
+
135
+ # Apply gene mapping to convert probe-level data to gene-level data
136
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
137
+ # 1. Normalize gene symbols
138
+ gene_data = normalize_gene_symbols_in_index(gene_data)
139
+ gene_data.to_csv(out_gene_data_file)
140
+
141
+ # Get clinical features
142
+ clinical_features = geo_select_clinical_features(
143
+ clinical_data,
144
+ trait=trait,
145
+ trait_row=trait_row,
146
+ convert_trait=convert_trait,
147
+ age_row=age_row,
148
+ convert_age=convert_age,
149
+ gender_row=gender_row,
150
+ convert_gender=convert_gender
151
+ )
152
+
153
+ # 2. Link clinical and genetic data
154
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
155
+
156
+ # 3. Handle missing values
157
+ linked_data = handle_missing_values(linked_data, trait)
158
+
159
+ # Early exit if trait values are all NaN
160
+ if linked_data[trait].isna().all():
161
+ is_biased = True
162
+ linked_data = None
163
+ else:
164
+ # 4. Judge whether features are biased and remove biased demographic features
165
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
166
+
167
+ # 5. Final validation and save metadata
168
+ note = "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."
169
+ is_usable = validate_and_save_cohort_info(
170
+ is_final=True,
171
+ cohort=cohort,
172
+ info_path=json_path,
173
+ is_gene_available=True,
174
+ is_trait_available=True,
175
+ is_biased=is_biased,
176
+ df=linked_data,
177
+ note=note
178
+ )
179
+
180
+ # 6. Save the linked data only if it's usable
181
+ if is_usable:
182
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
183
+ linked_data.to_csv(out_data_file)
p3/preprocess/Intellectual_Disability/code/GSE158385.py ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Intellectual_Disability"
6
+ cohort = "GSE158385"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Intellectual_Disability"
10
+ in_cohort_dir = "../DATA/GEO/Intellectual_Disability/GSE158385"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Intellectual_Disability/GSE158385.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Intellectual_Disability/gene_data/GSE158385.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Intellectual_Disability/clinical_data/GSE158385.csv"
16
+ json_path = "./output/preprocess/3/Intellectual_Disability/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get unique values for each clinical feature
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background information
28
+ print("Background Information:")
29
+ print(background_info)
30
+ print("\nSample Characteristics:")
31
+ print(json.dumps(unique_values_dict, indent=2))
32
+ # 1. Gene Expression Data Availability
33
+ is_gene_available = True # Yes, this appears to be gene expression data based on the background which studies effects in human amniocytes
34
+
35
+ # 2. Variable Availability and Data Type Conversion
36
+
37
+ # 2.1 Key identification
38
+ trait_row = 2 # Karyotype indicates T21 (Trisomy 21) status which represents Intellectual Disability
39
+ age_row = None # No age data available
40
+ gender_row = None # Although gender info is embedded in karyotype, we can't reliably extract it since some patients could have multiple records
41
+
42
+ # 2.2 Data Type Conversion Functions
43
+ def convert_trait(value):
44
+ if pd.isna(value):
45
+ return None
46
+ value = value.split(': ')[-1].strip()
47
+ if '47' in value and 'T21' in value: # Trisomy 21 cases
48
+ return 1
49
+ elif '46' in value and '2N' in value: # Normal karyotype
50
+ return 0
51
+ return None
52
+
53
+ convert_age = None # No age data
54
+ convert_gender = None # No reliable gender data
55
+
56
+ # 3. Save Metadata
57
+ is_trait_available = trait_row is not None
58
+ validate_and_save_cohort_info(is_final=False,
59
+ cohort=cohort,
60
+ info_path=json_path,
61
+ is_gene_available=is_gene_available,
62
+ is_trait_available=is_trait_available)
63
+
64
+ # 4. Clinical Feature Extraction
65
+ if trait_row is not None:
66
+ clinical_features = geo_select_clinical_features(clinical_data,
67
+ trait=trait,
68
+ trait_row=trait_row,
69
+ convert_trait=convert_trait)
70
+ print("Preview of clinical features:")
71
+ print(preview_df(clinical_features))
72
+
73
+ clinical_features.to_csv(out_clinical_data_file)
74
+ # Extract gene expression data from the matrix file
75
+ genetic_data = get_genetic_data(matrix_file_path)
76
+
77
+ # Print first 20 row IDs
78
+ print("First 20 row IDs:")
79
+ print(genetic_data.index[:20].tolist())
80
+ # The identifiers in the gene expression data appear to be Affymetrix transcript cluster IDs (TC.....hg.1)
81
+ # These are probe set IDs that need to be mapped to human gene symbols for analysis
82
+ requires_gene_mapping = True
83
+ # Identify all platform sections in the SOFT file
84
+ with gzip.open(soft_file_path, 'rt') as f:
85
+ platform_sections = []
86
+ current_platform = None
87
+ for line in f:
88
+ if line.startswith('^PLATFORM'):
89
+ if current_platform:
90
+ platform_sections.append(current_platform)
91
+ current_platform = {'id': line.strip()}
92
+ elif current_platform is not None and line.startswith('!Platform_title'):
93
+ current_platform['title'] = line.strip()
94
+ if 'human' in line.lower() or 'homo sapiens' in line.lower():
95
+ current_platform['is_human'] = True
96
+ elif not line.startswith('^'): # End of platform section
97
+ if current_platform:
98
+ platform_sections.append(current_platform)
99
+ current_platform = None
100
+ if current_platform: # Handle last platform if exists
101
+ platform_sections.append(current_platform)
102
+
103
+ print("Found Platform Sections:")
104
+ for platform in platform_sections:
105
+ print(platform)
106
+
107
+ # Look for human gene annotations
108
+ with gzip.open(soft_file_path, 'rt') as f:
109
+ human_data = []
110
+ is_human_section = False
111
+ for line in f:
112
+ if line.startswith('^PLATFORM'):
113
+ is_human_section = False
114
+ platform_id = line.strip()
115
+ elif line.startswith('!Platform_title') and ('human' in line.lower() or 'homo sapiens' in line.lower()):
116
+ is_human_section = True
117
+ print(f"\nFound human platform section: {platform_id}")
118
+ print(f"Platform title: {line.strip()}")
119
+ elif is_human_section and not line.startswith(('!', '#', '^')):
120
+ human_data.append(line)
121
+
122
+ if human_data:
123
+ # Convert human annotation data to dataframe
124
+ human_annotation_df = pd.read_csv(io.StringIO(''.join(human_data)), sep='\t')
125
+
126
+ print("\nColumn names:")
127
+ print(human_annotation_df.columns.tolist())
128
+
129
+ print("\nData shape:", human_annotation_df.shape)
130
+
131
+ print("\nPreview of the annotation data:")
132
+ print(json.dumps(preview_df(human_annotation_df), indent=2))
133
+ else:
134
+ print("\nNo human gene annotation data found in the SOFT file.")
135
+ # Extract probe and gene mapping from annotation data
136
+ prob_col = 'ID' # The gene expression data uses TC.....hg.1 identifiers, which match the ID column
137
+ gene_col = 'gene_assignment' # This column contains gene symbol information
138
+
139
+ # Get initial mapping between probes and genes
140
+ mapping_df = get_gene_mapping(human_annotation_df, prob_col, gene_col)
141
+
142
+ # Convert probe-level expression data to gene expression data
143
+ gene_data = apply_gene_mapping(genetic_data, mapping_df)
144
+
145
+ # Normalize gene symbols to ensure consistency
146
+ gene_data = normalize_gene_symbols_in_index(gene_data)
147
+
148
+ # Preview the result
149
+ print("\nGene expression data shape:", gene_data.shape)
150
+ print("\nFirst few gene symbols:", gene_data.index[:5].tolist())
151
+
152
+ # Save gene expression data
153
+ gene_data.to_csv(out_gene_data_file)
154
+ # 1. Normalize gene symbols
155
+ gene_data = normalize_gene_symbols_in_index(gene_data)
156
+ gene_data.to_csv(out_gene_data_file)
157
+
158
+ # Get clinical features
159
+ clinical_features = geo_select_clinical_features(
160
+ clinical_data,
161
+ trait=trait,
162
+ trait_row=trait_row,
163
+ convert_trait=convert_trait,
164
+ age_row=age_row,
165
+ convert_age=convert_age,
166
+ gender_row=gender_row,
167
+ convert_gender=convert_gender
168
+ )
169
+
170
+ # 2. Link clinical and genetic data
171
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
172
+
173
+ # 3. Handle missing values
174
+ linked_data = handle_missing_values(linked_data, trait)
175
+
176
+ # Early exit if trait values are all NaN
177
+ if linked_data[trait].isna().all():
178
+ is_biased = True
179
+ linked_data = None
180
+ else:
181
+ # 4. Judge whether features are biased and remove biased demographic features
182
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
183
+
184
+ # 5. Final validation and save metadata
185
+ note = "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."
186
+ is_usable = validate_and_save_cohort_info(
187
+ is_final=True,
188
+ cohort=cohort,
189
+ info_path=json_path,
190
+ is_gene_available=True,
191
+ is_trait_available=True,
192
+ is_biased=is_biased,
193
+ df=linked_data,
194
+ note=note
195
+ )
196
+
197
+ # 6. Save the linked data only if it's usable
198
+ if is_usable:
199
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
200
+ linked_data.to_csv(out_data_file)
p3/preprocess/Intellectual_Disability/code/GSE192767.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Intellectual_Disability"
6
+ cohort = "GSE192767"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Intellectual_Disability"
10
+ in_cohort_dir = "../DATA/GEO/Intellectual_Disability/GSE192767"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Intellectual_Disability/GSE192767.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Intellectual_Disability/gene_data/GSE192767.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Intellectual_Disability/clinical_data/GSE192767.csv"
16
+ json_path = "./output/preprocess/3/Intellectual_Disability/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get unique values for each clinical feature
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background information
28
+ print("Background Information:")
29
+ print(background_info)
30
+ print("\nSample Characteristics:")
31
+ print(json.dumps(unique_values_dict, indent=2))
32
+ # 1. Gene Expression Data Availability
33
+ # Yes - this dataset uses Affymetrix microarrays for gene expression profiling
34
+ is_gene_available = True
35
+
36
+ # 2.1 Data Availability
37
+
38
+ # Trait (ID) data is available in row 0 (phenotype field)
39
+ trait_row = 0
40
+
41
+ # Age data not available
42
+ age_row = None
43
+
44
+ # Gender data not available
45
+ gender_row = None
46
+
47
+ # 2.2 Data Type Conversion Functions
48
+
49
+ def convert_trait(value: str) -> int:
50
+ """Convert ATR-X syndrome phenotype to binary values"""
51
+ if not isinstance(value, str):
52
+ return None
53
+ value = value.lower().split("phenotype:")[-1].strip()
54
+ if "atr-x syndrome" in value:
55
+ return 1
56
+ elif "unaffected" in value:
57
+ return 0
58
+ return None
59
+
60
+ def convert_age(value: str) -> float:
61
+ """Convert age to float - not used since age not available"""
62
+ return None
63
+
64
+ def convert_gender(value: str) -> int:
65
+ """Convert gender to binary - not used since gender not available"""
66
+ return None
67
+
68
+ # 3. Save metadata with initial filtering
69
+ validate_and_save_cohort_info(is_final=False,
70
+ cohort=cohort,
71
+ info_path=json_path,
72
+ is_gene_available=is_gene_available,
73
+ is_trait_available=(trait_row is not None))
74
+
75
+ # 4. Extract clinical features
76
+ if trait_row is not None:
77
+ clinical_features = 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 extracted features
89
+ print("Preview of clinical features:")
90
+ print(preview_df(clinical_features))
91
+
92
+ # Save to CSV
93
+ clinical_features.to_csv(out_clinical_data_file)
94
+ # Extract gene expression data from the matrix file
95
+ genetic_data = get_genetic_data(matrix_file_path)
96
+
97
+ # Print first 20 row IDs
98
+ print("First 20 row IDs:")
99
+ print(genetic_data.index[:20].tolist())
100
+ # These are Affymetrix probe IDs from HuGene arrays that need to be mapped to gene symbols
101
+ requires_gene_mapping = True
102
+ # Extract gene annotation data from SOFT file
103
+ gene_metadata = get_gene_annotation(soft_file_path)
104
+
105
+ # Display information about the annotation data
106
+ print("Column names:")
107
+ print(gene_metadata.columns.tolist())
108
+
109
+ # Look at general data statistics
110
+ print("\nData shape:", gene_metadata.shape)
111
+
112
+ # Preview the first few rows
113
+ print("\nPreview of the annotation data:")
114
+ print(json.dumps(preview_df(gene_metadata), indent=2))
115
+ # 1. Identify the columns for mapping
116
+ # 'ID' in gene_metadata matches the probe IDs in genetic_data
117
+ # 'Gene Symbol' contains the gene symbols we want to map to
118
+ mapping_df = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='Gene Symbol')
119
+
120
+ # 2. Apply gene mapping
121
+ gene_data = apply_gene_mapping(genetic_data, mapping_df)
122
+
123
+ # Preview the first few rows of the mapped data
124
+ print("\nPreview of mapped gene expression data:")
125
+ print(preview_df(gene_data))
126
+ # 1. Normalize gene symbols
127
+ gene_data = normalize_gene_symbols_in_index(gene_data)
128
+ gene_data.to_csv(out_gene_data_file)
129
+
130
+ # Get clinical features
131
+ clinical_features = geo_select_clinical_features(
132
+ clinical_data,
133
+ trait=trait,
134
+ trait_row=trait_row,
135
+ convert_trait=convert_trait,
136
+ age_row=age_row,
137
+ convert_age=convert_age,
138
+ gender_row=gender_row,
139
+ convert_gender=convert_gender
140
+ )
141
+
142
+ # 2. Link clinical and genetic data
143
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
144
+
145
+ # 3. Handle missing values
146
+ linked_data = handle_missing_values(linked_data, trait)
147
+
148
+ # Early exit if trait values are all NaN
149
+ if linked_data[trait].isna().all():
150
+ is_biased = True
151
+ linked_data = None
152
+ else:
153
+ # 4. Judge whether features are biased and remove biased demographic features
154
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
155
+
156
+ # 5. Final validation and save metadata
157
+ note = "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."
158
+ is_usable = validate_and_save_cohort_info(
159
+ is_final=True,
160
+ cohort=cohort,
161
+ info_path=json_path,
162
+ is_gene_available=True,
163
+ is_trait_available=True,
164
+ is_biased=is_biased,
165
+ df=linked_data,
166
+ note=note
167
+ )
168
+
169
+ # 6. Save the linked data only if it's usable
170
+ if is_usable:
171
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
172
+ linked_data.to_csv(out_data_file)
p3/preprocess/Intellectual_Disability/code/GSE200864.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Intellectual_Disability"
6
+ cohort = "GSE200864"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Intellectual_Disability"
10
+ in_cohort_dir = "../DATA/GEO/Intellectual_Disability/GSE200864"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Intellectual_Disability/GSE200864.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Intellectual_Disability/gene_data/GSE200864.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Intellectual_Disability/clinical_data/GSE200864.csv"
16
+ json_path = "./output/preprocess/3/Intellectual_Disability/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get unique values for each clinical feature
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background information
28
+ print("Background Information:")
29
+ print(background_info)
30
+ print("\nSample Characteristics:")
31
+ print(json.dumps(unique_values_dict, indent=2))
32
+ # 1. Gene Expression Data Availability
33
+ # Based on Series_title and Series_overall_design mentioning Affymetrix platform and gene expression
34
+ is_gene_available = True
35
+
36
+ # 2. Variable Availability and Data Type Conversion
37
+
38
+ # 2.1 Data Availability
39
+ # Trait: Down Syndrome mentioned in title and summary, everyone has Down Syndrome based on background info
40
+ trait_row = None # Everyone has intellectual disability (Down Syndrome), so constant feature
41
+
42
+ # Age and gender: Not available in characteristics
43
+ age_row = None
44
+ gender_row = None
45
+
46
+ # 2.2 Data Type Conversion Functions
47
+ def convert_trait(x):
48
+ return 1 # Would return 1 for all samples since all have Down Syndrome
49
+
50
+ def convert_age(x):
51
+ return None # Not used since age data not available
52
+
53
+ def convert_gender(x):
54
+ return None # Not used since gender data not available
55
+
56
+ # 3. Save Metadata
57
+ is_trait_available = True # Although trait_row is None, we know everyone has intellectual disability
58
+ validate_and_save_cohort_info(is_final=False,
59
+ cohort=cohort,
60
+ info_path=json_path,
61
+ is_gene_available=is_gene_available,
62
+ is_trait_available=is_trait_available)
63
+
64
+ # 4. Clinical Feature Extraction
65
+ # Skip since trait_row is None (constant feature)
66
+ # Extract gene expression data from the matrix file
67
+ genetic_data = get_genetic_data(matrix_file_path)
68
+
69
+ # Print first 20 row IDs
70
+ print("First 20 row IDs:")
71
+ print(genetic_data.index[:20].tolist())
72
+ # These indices appear to be probe set IDs from Affymetrix microarray platform
73
+ # They are not standard human gene symbols and will need to be mapped
74
+ requires_gene_mapping = True
75
+ # Extract gene annotation data from SOFT file
76
+ gene_metadata = get_gene_annotation(soft_file_path)
77
+
78
+ # Display information about the annotation data
79
+ print("Column names:")
80
+ print(gene_metadata.columns.tolist())
81
+
82
+ # Look at general data statistics
83
+ print("\nData shape:", gene_metadata.shape)
84
+
85
+ # Preview the first few rows
86
+ print("\nPreview of the annotation data:")
87
+ print(json.dumps(preview_df(gene_metadata), indent=2))
88
+ # Create gene mapping from probe IDs to gene symbols
89
+ mapping_data = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='Gene Symbol')
90
+
91
+ # Apply gene mapping to convert probe-level data to gene-level data
92
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
93
+ # 1. Normalize gene symbols
94
+ gene_data = normalize_gene_symbols_in_index(gene_data)
95
+ gene_data.to_csv(out_gene_data_file)
96
+
97
+ # Since trait is constant (all Down Syndrome), create a clinical features dataframe of all 1's
98
+ clinical_features = pd.DataFrame(1, index=gene_data.columns, columns=['trait'])
99
+
100
+ # 2. Link clinical and genetic data
101
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
102
+
103
+ # 3. Handle missing values
104
+ linked_data = handle_missing_values(linked_data, 'trait')
105
+
106
+ # Early exit if trait values are all NaN
107
+ if linked_data['trait'].isna().all():
108
+ is_biased = True
109
+ linked_data = None
110
+ else:
111
+ # 4. Judge whether features are biased and remove biased demographic features
112
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, 'trait')
113
+
114
+ # 5. Final validation and save metadata
115
+ note = "Dataset contains gene expression data from pediatric patients with Down Syndrome. Since all samples have Down Syndrome, the trait is constant (all 1's)."
116
+ is_usable = validate_and_save_cohort_info(
117
+ is_final=True,
118
+ cohort=cohort,
119
+ info_path=json_path,
120
+ is_gene_available=True,
121
+ is_trait_available=True,
122
+ is_biased=is_biased,
123
+ df=linked_data,
124
+ note=note
125
+ )
126
+
127
+ # 6. Save the linked data only if it's usable
128
+ if is_usable:
129
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
130
+ linked_data.to_csv(out_data_file)
p3/preprocess/Intellectual_Disability/code/GSE273850.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Intellectual_Disability"
6
+ cohort = "GSE273850"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Intellectual_Disability"
10
+ in_cohort_dir = "../DATA/GEO/Intellectual_Disability/GSE273850"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Intellectual_Disability/GSE273850.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Intellectual_Disability/gene_data/GSE273850.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Intellectual_Disability/clinical_data/GSE273850.csv"
16
+ json_path = "./output/preprocess/3/Intellectual_Disability/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get unique values for each clinical feature
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background information
28
+ print("Background Information:")
29
+ print(background_info)
30
+ print("\nSample Characteristics:")
31
+ print(json.dumps(unique_values_dict, indent=2))
32
+ # 1. Gene Expression Data Availability
33
+ # Affymetrix array data indicates gene expression data is available
34
+ is_gene_available = True
35
+
36
+ # 2. Variable and Data Type Analysis
37
+
38
+ # 2.1 Row identifiers
39
+ trait_row = 0 # Genotype info in row 0 indicates T21 vs control
40
+ gender_row = 1 # Sex info in row 1
41
+ age_row = None # Age not available
42
+
43
+ # 2.2 Conversion functions
44
+ def convert_trait(value: str) -> int:
45
+ """Convert T21 status to binary: 1 for T21, 0 for control"""
46
+ if not value or ':' not in value:
47
+ return None
48
+ value = value.split(':')[1].strip().lower()
49
+ if 't21' in value:
50
+ return 1
51
+ elif 'euploid' in value:
52
+ return 0
53
+ return None
54
+
55
+ def convert_gender(value: str) -> int:
56
+ """Convert gender to binary: 0 for female, 1 for male"""
57
+ if not value or ':' not in value:
58
+ return None
59
+ value = value.split(':')[1].strip().lower()
60
+ if 'female' in value:
61
+ return 0
62
+ elif 'male' in value:
63
+ return 1
64
+ return None
65
+
66
+ def convert_age(value: str) -> float:
67
+ """Placeholder function since age is not available"""
68
+ return None
69
+
70
+ # 3. Save metadata
71
+ _ = validate_and_save_cohort_info(is_final=False,
72
+ cohort=cohort,
73
+ info_path=json_path,
74
+ is_gene_available=is_gene_available,
75
+ is_trait_available=trait_row is not None)
76
+
77
+ # 4. Clinical feature extraction
78
+ if trait_row is not None:
79
+ clinical_features = geo_select_clinical_features(
80
+ clinical_df=clinical_data,
81
+ trait=trait,
82
+ trait_row=trait_row,
83
+ convert_trait=convert_trait,
84
+ gender_row=gender_row,
85
+ convert_gender=convert_gender
86
+ )
87
+
88
+ # Preview the extracted features
89
+ preview = preview_df(clinical_features)
90
+ print("Clinical features preview:", preview)
91
+
92
+ # Save to CSV
93
+ clinical_features.to_csv(out_clinical_data_file)
94
+ # Extract gene expression data from the matrix file
95
+ genetic_data = get_genetic_data(matrix_file_path)
96
+
97
+ # Print first 20 row IDs
98
+ print("First 20 row IDs:")
99
+ print(genetic_data.index[:20].tolist())
100
+ # The transcript IDs are in the format "TCxxxxxxxx.hg.1" which are not standard human gene symbols
101
+ # They appear to be transcript cluster identifiers that need mapping to gene symbols
102
+ requires_gene_mapping = True
103
+ # Extract gene annotation data from SOFT file
104
+ gene_metadata = get_gene_annotation(soft_file_path)
105
+
106
+ # Display information about the annotation data
107
+ print("Column names:")
108
+ print(gene_metadata.columns.tolist())
109
+
110
+ # Look at general data statistics
111
+ print("\nData shape:", gene_metadata.shape)
112
+
113
+ # Preview the first few rows
114
+ print("\nPreview of the annotation data:")
115
+ print(json.dumps(preview_df(gene_metadata), indent=2))
116
+ # 1. Identify columns for gene mapping
117
+ # Based on observation:
118
+ # - 'ID' column in gene annotation contains probe IDs like 'TC0100006437.hg.1'
119
+ # - Gene symbols are contained in 'SPOT_ID.1' column within RefSeq/ENSEMBL descriptions
120
+
121
+ # 2. Create gene mapping dataframe from the annotation data
122
+ mapping_df = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='SPOT_ID.1')
123
+
124
+ # 3. Apply gene mapping to convert probe-level data to gene expression data
125
+ gene_data = apply_gene_mapping(genetic_data, mapping_df)
126
+
127
+ # Preview the gene data
128
+ print("\nShape of gene expression data:", gene_data.shape)
129
+ print("\nFirst few rows of gene expression data:")
130
+ print(preview_df(gene_data))
131
+ # 1. Normalize gene symbols
132
+ gene_data = normalize_gene_symbols_in_index(gene_data)
133
+ gene_data.to_csv(out_gene_data_file)
134
+
135
+ # Get clinical features
136
+ clinical_features = geo_select_clinical_features(
137
+ clinical_data,
138
+ trait=trait,
139
+ trait_row=trait_row,
140
+ convert_trait=convert_trait,
141
+ age_row=age_row,
142
+ convert_age=convert_age,
143
+ gender_row=gender_row,
144
+ convert_gender=convert_gender
145
+ )
146
+
147
+ # 2. Link clinical and genetic data
148
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
149
+
150
+ # 3. Handle missing values
151
+ linked_data = handle_missing_values(linked_data, trait)
152
+
153
+ # Early exit if trait values are all NaN
154
+ if linked_data[trait].isna().all():
155
+ is_biased = True
156
+ linked_data = None
157
+ else:
158
+ # 4. Judge whether features are biased and remove biased demographic features
159
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
160
+
161
+ # 5. Final validation and save metadata
162
+ note = "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."
163
+ is_usable = validate_and_save_cohort_info(
164
+ is_final=True,
165
+ cohort=cohort,
166
+ info_path=json_path,
167
+ is_gene_available=True,
168
+ is_trait_available=True,
169
+ is_biased=is_biased,
170
+ df=linked_data,
171
+ note=note
172
+ )
173
+
174
+ # 6. Save the linked data only if it's usable
175
+ if is_usable:
176
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
177
+ linked_data.to_csv(out_data_file)
p3/preprocess/Intellectual_Disability/code/GSE285666.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Intellectual_Disability"
6
+ cohort = "GSE285666"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Intellectual_Disability"
10
+ in_cohort_dir = "../DATA/GEO/Intellectual_Disability/GSE285666"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Intellectual_Disability/GSE285666.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Intellectual_Disability/gene_data/GSE285666.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Intellectual_Disability/clinical_data/GSE285666.csv"
16
+ json_path = "./output/preprocess/3/Intellectual_Disability/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get unique values for each clinical feature
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background information
28
+ print("Background Information:")
29
+ print(background_info)
30
+ print("\nSample Characteristics:")
31
+ print(json.dumps(unique_values_dict, indent=2))
32
+ # 1. Gene expression availability - Yes, it uses Affymetrix exon arrays
33
+ is_gene_available = True
34
+
35
+ # 2.1 Get row numbers for clinical features
36
+ trait_row = 0 # disease state row
37
+ age_row = None # age not available
38
+ gender_row = None # gender not available
39
+
40
+ # 2.2 Define conversion functions
41
+ def convert_trait(value: str) -> int:
42
+ """Convert disease state to binary: 1 for Williams syndrome, 0 for control"""
43
+ if pd.isna(value) or value is None:
44
+ return None
45
+ if ':' in value:
46
+ value = value.split(':')[1].strip().lower()
47
+ if 'williams syndrome' in value:
48
+ return 1
49
+ elif 'unaffected' in value or 'control' in value:
50
+ return 0
51
+ return None
52
+
53
+ def convert_age(value: str) -> float:
54
+ """Placeholder function since age is not available"""
55
+ return None
56
+
57
+ def convert_gender(value: str) -> int:
58
+ """Placeholder function since gender is not available"""
59
+ return None
60
+
61
+ # 3. Save metadata about dataset usability
62
+ is_trait_available = trait_row is not None
63
+ validate_and_save_cohort_info(is_final=False, cohort=cohort, info_path=json_path,
64
+ is_gene_available=is_gene_available,
65
+ is_trait_available=is_trait_available)
66
+
67
+ # 4. Extract clinical features since trait data is available
68
+ clinical_features = geo_select_clinical_features(clinical_df=clinical_data,
69
+ trait=trait,
70
+ trait_row=trait_row,
71
+ convert_trait=convert_trait)
72
+
73
+ # Preview results
74
+ preview_result = preview_df(clinical_features)
75
+ print("Preview of extracted clinical features:")
76
+ print(preview_result)
77
+
78
+ # Save clinical data
79
+ clinical_features.to_csv(out_clinical_data_file)
80
+ # Extract gene expression data from the matrix file
81
+ genetic_data = get_genetic_data(matrix_file_path)
82
+
83
+ # Print first 20 row IDs
84
+ print("First 20 row IDs:")
85
+ print(genetic_data.index[:20].tolist())
86
+ # These appear to be probe IDs from a microarray platform, not standard human gene symbols
87
+ # Examining the numeric format and length pattern confirms they need mapping
88
+ requires_gene_mapping = True
89
+ # Extract gene annotation data from SOFT file
90
+ gene_metadata = get_gene_annotation(soft_file_path)
91
+
92
+ # Display information about the annotation data
93
+ print("Column names:")
94
+ print(gene_metadata.columns.tolist())
95
+
96
+ # Look at general data statistics
97
+ print("\nData shape:", gene_metadata.shape)
98
+
99
+ # Display non-NaN value counts for key gene identifier columns
100
+ print("\nNumber of non-NaN values in key columns:")
101
+ for col in ['ID', 'gene_assignment']:
102
+ print(f"{col}: {gene_metadata[col].notna().sum()}")
103
+
104
+ # Preview rows with actual gene information
105
+ print("\nPreview of rows with gene information:")
106
+ gene_rows = gene_metadata[gene_metadata['gene_assignment'].notna()].head()
107
+ print(json.dumps(preview_df(gene_rows), indent=2))
108
+ # Get gene mapping dataframe
109
+ mapping_data = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='gene_assignment')
110
+ mapping_data = mapping_data[mapping_data['Gene'] != '---']
111
+
112
+ # Extract gene symbols from gene_assignment strings
113
+ def extract_gene_symbol(text):
114
+ if pd.isna(text):
115
+ return None
116
+ parts = text.split('//')
117
+ if len(parts) >= 2:
118
+ return parts[1].strip()
119
+ return None
120
+
121
+ mapping_data['Gene'] = mapping_data['Gene'].apply(extract_gene_symbol)
122
+ mapping_data = mapping_data.dropna()
123
+
124
+ # Apply gene mapping to convert probe data to gene data
125
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
126
+
127
+ # Print info about the converted data
128
+ print("Shape of probe-level data:", genetic_data.shape)
129
+ print("Shape of gene-level data:", gene_data.shape)
130
+ print("\nFirst few genes:")
131
+ print(gene_data.index[:10].tolist())
132
+ # 1. Normalize gene symbols
133
+ gene_data = normalize_gene_symbols_in_index(gene_data)
134
+ gene_data.to_csv(out_gene_data_file)
135
+
136
+ # Get clinical features
137
+ clinical_features = geo_select_clinical_features(
138
+ clinical_data,
139
+ trait=trait,
140
+ trait_row=trait_row,
141
+ convert_trait=convert_trait,
142
+ age_row=age_row,
143
+ convert_age=convert_age,
144
+ gender_row=gender_row,
145
+ convert_gender=convert_gender
146
+ )
147
+
148
+ # 2. Link clinical and genetic data
149
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
150
+
151
+ # 3. Handle missing values
152
+ linked_data = handle_missing_values(linked_data, trait)
153
+
154
+ # Early exit if trait values are all NaN
155
+ if linked_data[trait].isna().all():
156
+ is_biased = True
157
+ linked_data = None
158
+ else:
159
+ # 4. Judge whether features are biased and remove biased demographic features
160
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
161
+
162
+ # 5. Final validation and save metadata
163
+ note = "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."
164
+ is_usable = validate_and_save_cohort_info(
165
+ is_final=True,
166
+ cohort=cohort,
167
+ info_path=json_path,
168
+ is_gene_available=True,
169
+ is_trait_available=True,
170
+ is_biased=is_biased,
171
+ df=linked_data,
172
+ note=note
173
+ )
174
+
175
+ # 6. Save the linked data only if it's usable
176
+ if is_usable:
177
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
178
+ linked_data.to_csv(out_data_file)
p3/preprocess/Intellectual_Disability/code/GSE59630.py ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Intellectual_Disability"
6
+ cohort = "GSE59630"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Intellectual_Disability"
10
+ in_cohort_dir = "../DATA/GEO/Intellectual_Disability/GSE59630"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Intellectual_Disability/GSE59630.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Intellectual_Disability/gene_data/GSE59630.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Intellectual_Disability/clinical_data/GSE59630.csv"
16
+ json_path = "./output/preprocess/3/Intellectual_Disability/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get unique values for each clinical feature
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background information
28
+ print("Background Information:")
29
+ print(background_info)
30
+ print("\nSample Characteristics:")
31
+ print(json.dumps(unique_values_dict, indent=2))
32
+ # 1. Gene Expression Data Availability
33
+ # From the background info, we can see this is a gene expression study analyzing transcriptome, so:
34
+ is_gene_available = True
35
+
36
+ # 2. Variable Availability and Data Type Conversion
37
+ # 2.1 Data Availability
38
+ # From sample characteristics, we can find:
39
+ trait_row = 2 # 'disease status' indicates DS vs Control
40
+ age_row = 4 # Age data available
41
+ gender_row = 3 # Sex data available
42
+
43
+ # 2.2 Data Type Conversion Functions
44
+ def convert_trait(x):
45
+ """Convert disease status to binary (0: Control, 1: DS)"""
46
+ if x is None:
47
+ return None
48
+ value = x.split(': ')[-1].strip()
49
+ if value == 'CTL':
50
+ return 0
51
+ elif value == 'DS':
52
+ return 1
53
+ return None
54
+
55
+ def convert_age(x):
56
+ """Convert age to continuous numeric value in years"""
57
+ if x is None:
58
+ return None
59
+ value = x.split(': ')[-1].strip().lower()
60
+
61
+ # Extract number and unit
62
+ try:
63
+ num = float(''.join(filter(str.isdigit, value)))
64
+ if 'wg' in value: # weeks of gestation
65
+ return num/52 # convert to years
66
+ elif 'mo' in value: # months
67
+ return num/12 # convert to years
68
+ elif 'yr' in value: # years
69
+ return num
70
+ return None
71
+ except:
72
+ return None
73
+
74
+ def convert_gender(x):
75
+ """Convert gender to binary (0: Female, 1: Male)"""
76
+ if x is None:
77
+ return None
78
+ value = x.split(': ')[-1].strip()
79
+ if value == 'F':
80
+ return 0
81
+ elif value == 'M':
82
+ return 1
83
+ return None
84
+
85
+ # 3. Save Metadata
86
+ validate_and_save_cohort_info(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
+ # 4. Clinical Feature Extraction
93
+ if trait_row is not None:
94
+ clinical_features = geo_select_clinical_features(clinical_data,
95
+ trait=trait,
96
+ trait_row=trait_row,
97
+ convert_trait=convert_trait,
98
+ age_row=age_row,
99
+ convert_age=convert_age,
100
+ gender_row=gender_row,
101
+ convert_gender=convert_gender)
102
+
103
+ # Preview the extracted features
104
+ preview = preview_df(clinical_features)
105
+ print("Preview of clinical features:", preview)
106
+
107
+ # Save to CSV
108
+ clinical_features.to_csv(out_clinical_data_file)
109
+ # Extract gene expression data from the matrix file
110
+ genetic_data = get_genetic_data(matrix_file_path)
111
+
112
+ # Print first 20 row IDs
113
+ print("First 20 row IDs:")
114
+ print(genetic_data.index[:20].tolist())
115
+ # These appear to be probe IDs from a microarray platform rather than gene symbols
116
+ # They are numeric IDs which need to be mapped to human gene symbols
117
+ requires_gene_mapping = True
118
+ # Extract gene annotation data from SOFT file
119
+ gene_metadata = get_gene_annotation(soft_file_path)
120
+
121
+ # Display information about the annotation data
122
+ print("Column names:")
123
+ print(gene_metadata.columns.tolist())
124
+
125
+ # Look at general data statistics
126
+ print("\nData shape:", gene_metadata.shape)
127
+
128
+ # Display non-NaN value counts for key gene identifier columns
129
+ print("\nNumber of non-NaN values in key columns:")
130
+ for col in ['ID', 'gene_assignment']:
131
+ print(f"{col}: {gene_metadata[col].notna().sum()}")
132
+
133
+ # Preview rows with actual gene information
134
+ print("\nPreview of rows with gene information:")
135
+ gene_rows = gene_metadata[gene_metadata['gene_assignment'].notna()].head()
136
+ print(json.dumps(preview_df(gene_rows), indent=2))
137
+ # From the previous output, we can see:
138
+ # - Gene identifiers are in the 'ID' column
139
+ # - Gene symbols are in 'gene_assignment' column and need to be extracted
140
+ mapping_data = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='gene_assignment')
141
+
142
+ # Apply the mapping to convert probe-level data to gene-level data
143
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
144
+
145
+ # Print information about the mapping result
146
+ print("\nOriginal probes:", len(genetic_data))
147
+ print("Mapped genes:", len(gene_data))
148
+ print("\nPreview of first few genes and their expression values:")
149
+ print(json.dumps(preview_df(gene_data), indent=2))
150
+ # 1. Normalize gene symbols
151
+ gene_data = normalize_gene_symbols_in_index(gene_data)
152
+ gene_data.to_csv(out_gene_data_file)
153
+
154
+ # Get clinical features
155
+ clinical_features = geo_select_clinical_features(
156
+ clinical_data,
157
+ trait=trait,
158
+ trait_row=trait_row,
159
+ convert_trait=convert_trait,
160
+ age_row=age_row,
161
+ convert_age=convert_age,
162
+ gender_row=gender_row,
163
+ convert_gender=convert_gender
164
+ )
165
+
166
+ # 2. Link clinical and genetic data
167
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
168
+
169
+ # 3. Handle missing values
170
+ linked_data = handle_missing_values(linked_data, trait)
171
+
172
+ # Early exit if trait values are all NaN
173
+ if linked_data[trait].isna().all():
174
+ is_biased = True
175
+ linked_data = None
176
+ else:
177
+ # 4. Judge whether features are biased and remove biased demographic features
178
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
179
+
180
+ # 5. Final validation and save metadata
181
+ note = "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."
182
+ is_usable = validate_and_save_cohort_info(
183
+ is_final=True,
184
+ cohort=cohort,
185
+ info_path=json_path,
186
+ is_gene_available=True,
187
+ is_trait_available=True,
188
+ is_biased=is_biased,
189
+ df=linked_data,
190
+ note=note
191
+ )
192
+
193
+ # 6. Save the linked data only if it's usable
194
+ if is_usable:
195
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
196
+ linked_data.to_csv(out_data_file)
p3/preprocess/Intellectual_Disability/code/GSE63870.py ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Intellectual_Disability"
6
+ cohort = "GSE63870"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Intellectual_Disability"
10
+ in_cohort_dir = "../DATA/GEO/Intellectual_Disability/GSE63870"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Intellectual_Disability/GSE63870.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Intellectual_Disability/gene_data/GSE63870.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Intellectual_Disability/clinical_data/GSE63870.csv"
16
+ json_path = "./output/preprocess/3/Intellectual_Disability/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get unique values for each clinical feature
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background information
28
+ print("Background Information:")
29
+ print(background_info)
30
+ print("\nSample Characteristics:")
31
+ print(json.dumps(unique_values_dict, indent=2))
32
+ # 1. Gene Expression Data Availability
33
+ # Yes - it's analyzing whole genome expression in white blood cells
34
+ is_gene_available = True
35
+
36
+ # 2. Variable Availability and Data Type Conversion
37
+ # 2.1 Data Availability
38
+ trait_row = 1 # Found in "condition" field
39
+ age_row = 0 # Found in "age" field
40
+ gender_row = None # Gender data not available
41
+
42
+ # 2.2 Data Type Conversion Functions
43
+ def convert_trait(value: str) -> int:
44
+ """Convert cognitive disability status to binary"""
45
+ if not value or ':' not in value:
46
+ return None
47
+ value = value.split(':')[1].strip().lower()
48
+ # 1 for having severe cognitive disability/dementia, 0 for without
49
+ if 'without' in value:
50
+ return 0
51
+ elif 'severe cognitive disability' in value or 'early dementia' in value:
52
+ return 1
53
+ return None
54
+
55
+ def convert_age(value: str) -> int:
56
+ """Convert age group to binary"""
57
+ if not value or ':' not in value:
58
+ return None
59
+ value = value.split(':')[1].strip().lower()
60
+ # Convert to binary: 0 for young, 1 for old
61
+ if value == 'young':
62
+ return 0
63
+ elif value == 'old':
64
+ return 1
65
+ return None
66
+
67
+ def convert_gender(value: str) -> int:
68
+ """Placeholder function - not used since gender data unavailable"""
69
+ return None
70
+
71
+ # 3. Save Metadata
72
+ is_trait_available = trait_row is not None
73
+ validate_and_save_cohort_info(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
+ # 4. Clinical Feature Extraction
80
+ if trait_row is not None:
81
+ clinical_features = geo_select_clinical_features(
82
+ clinical_df=clinical_data,
83
+ trait=trait,
84
+ trait_row=trait_row,
85
+ convert_trait=convert_trait,
86
+ age_row=age_row,
87
+ convert_age=convert_age,
88
+ gender_row=gender_row,
89
+ convert_gender=convert_gender
90
+ )
91
+
92
+ # Preview the extracted features
93
+ preview = preview_df(clinical_features)
94
+ print("Preview of extracted clinical features:")
95
+ print(preview)
96
+
97
+ # Save to CSV
98
+ clinical_features.to_csv(out_clinical_data_file)
99
+ # Extract gene expression data from the matrix file
100
+ genetic_data = get_genetic_data(matrix_file_path)
101
+
102
+ # Print first 20 row IDs
103
+ print("First 20 row IDs:")
104
+ print(genetic_data.index[:20].tolist())
105
+ # These identifiers are not standard human gene symbols. They appear to be Agilent microarray probe IDs.
106
+ # Probe IDs like 'A_19_P00315452' need to be mapped to gene symbols for analysis.
107
+
108
+ requires_gene_mapping = True
109
+ # Extract gene annotation data from SOFT file
110
+ gene_metadata = get_gene_annotation(soft_file_path)
111
+
112
+ # Display information about the annotation data
113
+ print("Column names:")
114
+ print(gene_metadata.columns.tolist())
115
+
116
+ # Look at general data statistics
117
+ print("\nData shape:", gene_metadata.shape)
118
+
119
+ # Display non-NaN value counts for key gene identifier columns
120
+ print("\nNumber of non-NaN values in key columns:")
121
+ for col in ['ID', 'GENE_SYMBOL']:
122
+ print(f"{col}: {gene_metadata[col].notna().sum()}")
123
+
124
+ # Preview rows with actual gene information
125
+ print("\nPreview of rows with gene information:")
126
+ gene_rows = gene_metadata[gene_metadata['GENE_SYMBOL'].notna()].head()
127
+ print(json.dumps(preview_df(gene_rows), indent=2))
128
+ # 1. Identify mapping columns
129
+ # 'ID' in gene metadata matches the identifiers in genetic_data
130
+ # 'GENE_SYMBOL' contains the target gene symbols
131
+ gene_id_col = 'ID'
132
+ gene_symbol_col = 'GENE_SYMBOL'
133
+
134
+ # 2. Get mapping dataframe
135
+ gene_mapping = get_gene_mapping(gene_metadata, gene_id_col, gene_symbol_col)
136
+
137
+ # 3. Apply gene mapping to convert probe-level data to gene expression data
138
+ gene_data = apply_gene_mapping(genetic_data, gene_mapping)
139
+ # 1. Normalize gene symbols
140
+ gene_data = normalize_gene_symbols_in_index(gene_data)
141
+ gene_data.to_csv(out_gene_data_file)
142
+
143
+ # Get clinical features
144
+ clinical_features = geo_select_clinical_features(
145
+ clinical_data,
146
+ trait=trait,
147
+ trait_row=trait_row,
148
+ convert_trait=convert_trait,
149
+ age_row=age_row,
150
+ convert_age=convert_age,
151
+ gender_row=gender_row,
152
+ convert_gender=convert_gender
153
+ )
154
+
155
+ # 2. Link clinical and genetic data
156
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
157
+
158
+ # 3. Handle missing values
159
+ linked_data = handle_missing_values(linked_data, trait)
160
+
161
+ # Early exit if trait values are all NaN
162
+ if linked_data[trait].isna().all():
163
+ is_biased = True
164
+ linked_data = None
165
+ else:
166
+ # 4. Judge whether features are biased and remove biased demographic features
167
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
168
+
169
+ # 5. Final validation and save metadata
170
+ note = "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."
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 the linked data only if it's 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)
p3/preprocess/Intellectual_Disability/code/GSE89594.py ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Intellectual_Disability"
6
+ cohort = "GSE89594"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Intellectual_Disability"
10
+ in_cohort_dir = "../DATA/GEO/Intellectual_Disability/GSE89594"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Intellectual_Disability/GSE89594.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Intellectual_Disability/gene_data/GSE89594.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Intellectual_Disability/clinical_data/GSE89594.csv"
16
+ json_path = "./output/preprocess/3/Intellectual_Disability/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get unique values for each clinical feature
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background information
28
+ print("Background Information:")
29
+ print(background_info)
30
+ print("\nSample Characteristics:")
31
+ print(json.dumps(unique_values_dict, indent=2))
32
+ # 1. Gene Expression Data Availability
33
+ # Based on background info, this is a gene expression study using peripheral blood
34
+ is_gene_available = True
35
+
36
+ # 2.1 Data Availability
37
+ trait_row = 0 # "diagnosis" in row 0 contains trait info
38
+ age_row = 2 # "age" in row 2
39
+ gender_row = 3 # "gender" in row 3
40
+
41
+ # 2.2 Data Type Conversion Functions
42
+ def convert_trait(x):
43
+ """Convert trait status to binary"""
44
+ if not isinstance(x, str):
45
+ return None
46
+ value = x.split(': ')[-1].lower()
47
+ # Williams Syndrome is intellectual disability
48
+ if 'williams syndrome' in value or 'ws' in value:
49
+ return 1
50
+ elif 'control' in value:
51
+ return 0
52
+ # ASD samples counted as None since not relevant
53
+ return None
54
+
55
+ def convert_age(x):
56
+ """Convert age to continuous values"""
57
+ if not isinstance(x, str):
58
+ return None
59
+ value = x.split(': ')[-1].lower()
60
+ try:
61
+ # Extract numeric value before 'y'
62
+ return float(value.replace('y',''))
63
+ except:
64
+ return None
65
+
66
+ def convert_gender(x):
67
+ """Convert gender to binary (0=female, 1=male)"""
68
+ if not isinstance(x, str):
69
+ return None
70
+ value = x.split(': ')[-1].lower()
71
+ if 'female' in value:
72
+ return 0
73
+ elif 'male' in value:
74
+ return 1
75
+ return None
76
+
77
+ # 3. Save Metadata
78
+ is_trait_available = trait_row is not None
79
+ validate_and_save_cohort_info(is_final=False,
80
+ cohort=cohort,
81
+ info_path=json_path,
82
+ is_gene_available=is_gene_available,
83
+ is_trait_available=is_trait_available)
84
+
85
+ # 4. Clinical Feature Extraction
86
+ if trait_row is not None:
87
+ clinical_features = 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 processed clinical data
99
+ preview = preview_df(clinical_features)
100
+ print("Preview of processed clinical data:")
101
+ print(preview)
102
+
103
+ # Save clinical features
104
+ clinical_features.to_csv(out_clinical_data_file)
105
+ # Extract gene expression data from the matrix file
106
+ genetic_data = get_genetic_data(matrix_file_path)
107
+
108
+ # Print first 20 row IDs
109
+ print("First 20 row IDs:")
110
+ print(genetic_data.index[:20].tolist())
111
+ # Based on the provided sample row IDs which are just sequential numbers,
112
+ # we need to map these identifiers to proper gene symbols
113
+ requires_gene_mapping = True
114
+ # Extract gene annotation data from SOFT file
115
+ gene_metadata = get_gene_annotation(soft_file_path)
116
+
117
+ # Display information about the annotation data
118
+ print("Column names:")
119
+ print(gene_metadata.columns.tolist())
120
+
121
+ # Look at general data statistics
122
+ print("\nData shape:", gene_metadata.shape)
123
+
124
+ # Display non-NaN value counts for key gene identifier columns
125
+ print("\nNumber of non-NaN values in key columns:")
126
+ for col in ['ID', 'GENE_SYMBOL']:
127
+ print(f"{col}: {gene_metadata[col].notna().sum()}")
128
+
129
+ # Preview rows with actual gene information
130
+ print("\nPreview of rows with gene information:")
131
+ gene_rows = gene_metadata[gene_metadata['GENE_SYMBOL'].notna()].head()
132
+ print(json.dumps(preview_df(gene_rows), indent=2))
133
+ # 1. Identify mapping columns
134
+ # ID in expression data corresponds to ID in annotation
135
+ # GENE_SYMBOL contains gene symbols for mapping
136
+ mapping_df = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='GENE_SYMBOL')
137
+
138
+ # 2. Apply mapping and aggregate to get gene expression data
139
+ gene_data = apply_gene_mapping(genetic_data, mapping_df)
140
+
141
+ # Preview the processed data
142
+ print("\nPreview of mapped gene expression data:")
143
+ print(f"Shape: {gene_data.shape}")
144
+ print("\nFirst few gene symbols:")
145
+ print(gene_data.index[:10].tolist())
146
+ # 1. Normalize gene symbols
147
+ gene_data = normalize_gene_symbols_in_index(gene_data)
148
+ gene_data.to_csv(out_gene_data_file)
149
+
150
+ # Get clinical features
151
+ clinical_features = geo_select_clinical_features(
152
+ clinical_data,
153
+ trait=trait,
154
+ trait_row=trait_row,
155
+ convert_trait=convert_trait,
156
+ age_row=age_row,
157
+ convert_age=convert_age,
158
+ gender_row=gender_row,
159
+ convert_gender=convert_gender
160
+ )
161
+
162
+ # 2. Link clinical and genetic data
163
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
164
+
165
+ # 3. Handle missing values
166
+ linked_data = handle_missing_values(linked_data, trait)
167
+
168
+ # Early exit if trait values are all NaN
169
+ if linked_data[trait].isna().all():
170
+ is_biased = True
171
+ linked_data = None
172
+ else:
173
+ # 4. Judge whether features are biased and remove biased demographic features
174
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
175
+
176
+ # 5. Final validation and save metadata
177
+ note = "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."
178
+ is_usable = validate_and_save_cohort_info(
179
+ is_final=True,
180
+ cohort=cohort,
181
+ info_path=json_path,
182
+ is_gene_available=True,
183
+ is_trait_available=True,
184
+ is_biased=is_biased,
185
+ df=linked_data,
186
+ note=note
187
+ )
188
+
189
+ # 6. Save the linked data only if it's usable
190
+ if is_usable:
191
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
192
+ linked_data.to_csv(out_data_file)
p3/preprocess/Intellectual_Disability/code/GSE98697.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Intellectual_Disability"
6
+ cohort = "GSE98697"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Intellectual_Disability"
10
+ in_cohort_dir = "../DATA/GEO/Intellectual_Disability/GSE98697"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Intellectual_Disability/GSE98697.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Intellectual_Disability/gene_data/GSE98697.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Intellectual_Disability/clinical_data/GSE98697.csv"
16
+ json_path = "./output/preprocess/3/Intellectual_Disability/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+
24
+ # Get unique values for each clinical feature
25
+ unique_values_dict = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background information
28
+ print("Background Information:")
29
+ print(background_info)
30
+ print("\nSample Characteristics:")
31
+ print(json.dumps(unique_values_dict, indent=2))
32
+ # 1. Gene Expression Data Availability
33
+ # Yes - the dataset contains both coding and non-coding gene expression data according to title and design
34
+ is_gene_available = True
35
+
36
+ # 2.1 Data Row Numbers
37
+ # Trait: Not directly given but subtype shows Down syndrome cases, can infer from aml subtype
38
+ trait_row = 2
39
+ # Age not available
40
+ age_row = None
41
+ # Gender not available
42
+ gender_row = None
43
+
44
+ # 2.2 Type Conversion Functions
45
+ def convert_trait(x):
46
+ # Extract value after colon
47
+ if ':' in x:
48
+ x = x.split(':', 1)[1].strip()
49
+ # Convert to binary - 1 for Down syndrome AMKL, 0 for other types
50
+ if 'Down-syndrome' in x:
51
+ return 1
52
+ elif 'aml' in x.lower(): # Other AML types
53
+ return 0
54
+ return None
55
+
56
+ def convert_age(x):
57
+ return None # Not used as age is not available
58
+
59
+ def convert_gender(x):
60
+ return None # Not used as gender is not available
61
+
62
+ # 3. Save metadata
63
+ is_trait_available = trait_row is not None
64
+ validate_and_save_cohort_info(is_final=False,
65
+ cohort=cohort,
66
+ info_path=json_path,
67
+ is_gene_available=is_gene_available,
68
+ is_trait_available=is_trait_available)
69
+
70
+ # 4. Clinical Feature Extraction
71
+ if trait_row is not None:
72
+ clinical_features = geo_select_clinical_features(
73
+ clinical_df=clinical_data,
74
+ trait=trait,
75
+ trait_row=trait_row,
76
+ convert_trait=convert_trait,
77
+ age_row=age_row,
78
+ convert_age=convert_age,
79
+ gender_row=gender_row,
80
+ convert_gender=convert_gender
81
+ )
82
+
83
+ # Preview the extracted features
84
+ preview_df(clinical_features)
85
+
86
+ # Save to CSV
87
+ clinical_features.to_csv(out_clinical_data_file)
88
+ # Extract gene expression data from the matrix file
89
+ genetic_data = get_genetic_data(matrix_file_path)
90
+
91
+ # Print first 20 row IDs
92
+ print("First 20 row IDs:")
93
+ print(genetic_data.index[:20].tolist())
94
+ # Observe that the identifiers are just '1', '2', '3' etc
95
+ # These are numeric indices and not standard gene symbols
96
+ # Therefore we need to map these IDs to proper gene symbols
97
+
98
+ requires_gene_mapping = True
99
+ # Extract gene annotation data from SOFT file
100
+ gene_metadata = get_gene_annotation(soft_file_path)
101
+
102
+ # Display information about the annotation data
103
+ print("Column names:")
104
+ print(gene_metadata.columns.tolist())
105
+
106
+ # Look at general data statistics
107
+ print("\nData shape:", gene_metadata.shape)
108
+
109
+ # Display non-NaN value counts for key gene identifier columns
110
+ print("\nNumber of non-NaN values in key columns:")
111
+ for col in ['ID', 'FINAL_SYMBOL']:
112
+ print(f"{col}: {gene_metadata[col].notna().sum()}")
113
+
114
+ # Preview rows with actual gene information
115
+ print("\nPreview of rows with gene information:")
116
+ gene_rows = gene_metadata[gene_metadata['FINAL_SYMBOL'].notna()].head()
117
+ print(json.dumps(preview_df(gene_rows), indent=2))
118
+ # Extract the gene mapping data
119
+ # From observing the data, we need to map numeric 'ID' to 'FINAL_SYMBOL'
120
+ mapping_data = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='FINAL_SYMBOL')
121
+
122
+ # Apply the gene mapping to convert probe-level data to gene-level data
123
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
124
+
125
+ # Display the shape of the gene expression data before and after mapping
126
+ print(f"Shape before mapping (probes × samples): {genetic_data.shape}")
127
+ print(f"Shape after mapping (genes × samples): {gene_data.shape}")
128
+
129
+ # Preview the first few gene symbols
130
+ print("\nFirst few gene symbols:")
131
+ print(gene_data.index[:5].tolist())
132
+ # 1. Normalize gene symbols
133
+ gene_data = normalize_gene_symbols_in_index(gene_data)
134
+ gene_data.to_csv(out_gene_data_file)
135
+
136
+ # Get clinical features
137
+ clinical_features = geo_select_clinical_features(
138
+ clinical_data,
139
+ trait=trait,
140
+ trait_row=trait_row,
141
+ convert_trait=convert_trait,
142
+ age_row=age_row,
143
+ convert_age=convert_age,
144
+ gender_row=gender_row,
145
+ convert_gender=convert_gender
146
+ )
147
+
148
+ # 2. Link clinical and genetic data
149
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
150
+
151
+ # 3. Handle missing values
152
+ linked_data = handle_missing_values(linked_data, trait)
153
+
154
+ # Early exit if trait values are all NaN
155
+ if linked_data[trait].isna().all():
156
+ is_biased = True
157
+ linked_data = None
158
+ else:
159
+ # 4. Judge whether features are biased and remove biased demographic features
160
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
161
+
162
+ # 5. Final validation and save metadata
163
+ note = "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."
164
+ is_usable = validate_and_save_cohort_info(
165
+ is_final=True,
166
+ cohort=cohort,
167
+ info_path=json_path,
168
+ is_gene_available=True,
169
+ is_trait_available=True,
170
+ is_biased=is_biased,
171
+ df=linked_data,
172
+ note=note
173
+ )
174
+
175
+ # 6. Save the linked data only if it's usable
176
+ if is_usable:
177
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
178
+ linked_data.to_csv(out_data_file)
p3/preprocess/Intellectual_Disability/code/TCGA.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Intellectual_Disability"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/3/Intellectual_Disability/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/3/Intellectual_Disability/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/3/Intellectual_Disability/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/3/Intellectual_Disability/cohort_info.json"
15
+
16
+ # Get subdirectories from TCGA root directory
17
+ tcga_subdirs = os.listdir(tcga_root_dir)
18
+ tcga_subdirs = [d for d in tcga_subdirs if not d.startswith('.')]
19
+
20
+ # Review available subdirectories for insomnia-related cohorts
21
+ # No suitable cohort found - all are cancer specific and not related to sleep disorders
22
+ print(f"No suitable TCGA cohort found for {trait}.")
23
+ print("Available cohorts are cancer-specific and do not contain relevant data for sleep disorders.")
24
+
25
+ # Record that this trait should be skipped due to lack of suitable data
26
+ is_gene_available = False
27
+ is_trait_available = False
28
+ validate_and_save_cohort_info(is_final=False,
29
+ cohort="TCGA",
30
+ info_path=json_path,
31
+ is_gene_available=is_gene_available,
32
+ is_trait_available=is_trait_available)
p3/preprocess/Intellectual_Disability/cohort_info.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"GSE98697": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 44, "note": "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."}, "GSE89594": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": true, "sample_size": 62, "note": "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."}, "GSE63870": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": false, "sample_size": 48, "note": "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."}, "GSE59630": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": true, "sample_size": 116, "note": "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."}, "GSE285666": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 52, "note": "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."}, "GSE273850": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": true, "sample_size": 51, "note": "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."}, "GSE192767": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 48, "note": "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."}, "GSE158385": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 28, "note": "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."}, "GSE100680": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": false, "sample_size": 34, "note": "Dataset contains gene expression data from pediatric AML samples, focusing on Down syndrome cases versus other AML types."}, "TCGA": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}}
p3/preprocess/Intellectual_Disability/gene_data/GSE100680.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Intellectual_Disability/gene_data/GSE158385.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Intellectual_Disability/gene_data/GSE192767.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f81a5749729311519b56acbd48a1ff320ad1bcc158b18f46a484d867dc45b7e
3
+ size 16852912
p3/preprocess/Intellectual_Disability/gene_data/GSE200864.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:98b899f1f9bbba8de34efc6142b77e7facb4b8fac8c25126fdc99516cdfe593c
3
+ size 16949662
p3/preprocess/Intellectual_Disability/gene_data/GSE273850.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a6782ba54e7165f7c17565afcc10c64d586752326fffa570e39aeb4be5e9d163
3
+ size 16872541
p3/preprocess/Intellectual_Disability/gene_data/GSE285666.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Intellectual_Disability/gene_data/GSE59630.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c2e112c676d59b786988135d17f4ad5a89de54991163968994365fd00c87a4e
3
+ size 25114594
p3/preprocess/Intellectual_Disability/gene_data/GSE63870.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ede1fa47eabf944de57302830e946c84aaee78154c61f3e0191f8a3f63b19926
3
+ size 11793403
p3/preprocess/Intellectual_Disability/gene_data/GSE89594.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d76a3967959d50c84ec6d36a0c8c56926580b854240c2e6d194762f3630a0a5c
3
+ size 23811303
p3/preprocess/Intellectual_Disability/gene_data/GSE98697.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c05e0333e3e6413919d57569b93c3ecb5a45faa5370b7dc1f77bae61cc90d440
3
+ size 11613947
p3/preprocess/Irritable_bowel_syndrome_(IBS)/GSE25220.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Irritable_bowel_syndrome_(IBS)/GSE36701.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b0488b09f51372285cb0234becdbdcace49ef93b7551f825588f5aacf6f16389
3
+ size 47723829