Liu-Hy commited on
Commit
4170dd3
·
verified ·
1 Parent(s): 3b8d6f7

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 +18 -0
  2. p1/preprocess/Prostate_Cancer/TCGA.csv +3 -0
  3. p1/preprocess/Prostate_Cancer/gene_data/TCGA.csv +3 -0
  4. p1/preprocess/Sarcoma/gene_data/TCGA.csv +3 -0
  5. p1/preprocess/Sjögrens_Syndrome/gene_data/GSE66795.csv +3 -0
  6. p1/preprocess/Stroke/GSE58294.csv +3 -0
  7. p1/preprocess/Stroke/gene_data/GSE161533.csv +3 -0
  8. p1/preprocess/Stroke/gene_data/GSE47727.csv +3 -0
  9. p1/preprocess/Stroke/gene_data/GSE48424.csv +3 -0
  10. p1/preprocess/Stroke/gene_data/GSE58294.csv +3 -0
  11. p1/preprocess/Stroke/gene_data/GSE68526.csv +3 -0
  12. p1/preprocess/Substance_Use_Disorder/GSE159676.csv +0 -0
  13. p1/preprocess/Substance_Use_Disorder/code/GSE161999.py +186 -0
  14. p1/preprocess/Substance_Use_Disorder/code/GSE273630.py +75 -0
  15. p1/preprocess/Substance_Use_Disorder/code/GSE94399.py +120 -0
  16. p1/preprocess/Substance_Use_Disorder/code/TCGA.py +71 -0
  17. p1/preprocess/Substance_Use_Disorder/gene_data/GSE116833.csv +0 -0
  18. p1/preprocess/Substance_Use_Disorder/gene_data/GSE125681.csv +0 -0
  19. p1/preprocess/Substance_Use_Disorder/gene_data/GSE138297.csv +3 -0
  20. p1/preprocess/Substance_Use_Disorder/gene_data/GSE159676.csv +0 -0
  21. p1/preprocess/Substance_Use_Disorder/gene_data/GSE161986.csv +0 -0
  22. p1/preprocess/Substance_Use_Disorder/gene_data/GSE161999.csv +0 -0
  23. p1/preprocess/Substance_Use_Disorder/gene_data/GSE94399.csv +0 -0
  24. p1/preprocess/Telomere_Length/code/GSE16058.py +151 -0
  25. p1/preprocess/Telomere_Length/code/GSE52237.py +181 -0
  26. p1/preprocess/Telomere_Length/code/GSE80435.py +171 -0
  27. p1/preprocess/Telomere_Length/code/TCGA.py +74 -0
  28. p1/preprocess/Telomere_Length/cohort_info.json +1 -0
  29. p1/preprocess/Testicular_Cancer/code/GSE42647.py +60 -0
  30. p1/preprocess/Testicular_Cancer/code/GSE62523.py +73 -0
  31. p1/preprocess/Testicular_Cancer/code/TCGA.py +171 -0
  32. p1/preprocess/Testicular_Cancer/cohort_info.json +1 -0
  33. p1/preprocess/Thymoma/GSE42977.csv +3 -0
  34. p1/preprocess/Thymoma/clinical_data/GSE131027.csv +2 -0
  35. p1/preprocess/Thymoma/clinical_data/GSE42977.csv +2 -0
  36. p1/preprocess/Thymoma/code/GSE131027.py +171 -0
  37. p1/preprocess/Thymoma/code/GSE29695.py +156 -0
  38. p1/preprocess/Thymoma/code/GSE42977.py +170 -0
  39. p1/preprocess/Thymoma/code/TCGA.py +133 -0
  40. p1/preprocess/Thymoma/cohort_info.json +1 -0
  41. p1/preprocess/Thymoma/gene_data/GSE131027.csv +3 -0
  42. p1/preprocess/Thymoma/gene_data/GSE42977.csv +3 -0
  43. p1/preprocess/Thyroid_Cancer/GSE104005.csv +0 -0
  44. p1/preprocess/Thyroid_Cancer/GSE151179.csv +3 -0
  45. p1/preprocess/Thyroid_Cancer/GSE58689.csv +0 -0
  46. p1/preprocess/Thyroid_Cancer/GSE80022.csv +3 -0
  47. p1/preprocess/Thyroid_Cancer/GSE82208.csv +3 -0
  48. p1/preprocess/Thyroid_Cancer/clinical_data/GSE104005.csv +4 -0
  49. p1/preprocess/Thyroid_Cancer/clinical_data/GSE104006.csv +4 -0
  50. p1/preprocess/Thyroid_Cancer/clinical_data/GSE107754.csv +3 -0
.gitattributes CHANGED
@@ -861,3 +861,21 @@ p1/preprocess/Sjögrens_Syndrome/gene_data/GSE51092.csv filter=lfs diff=lfs merg
861
  p1/preprocess/Stomach_Cancer/gene_data/GSE98708.csv filter=lfs diff=lfs merge=lfs -text
862
  p1/preprocess/Stomach_Cancer/gene_data/GSE183136.csv filter=lfs diff=lfs merge=lfs -text
863
  p1/preprocess/Stomach_Cancer/gene_data/GSE130823.csv filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
861
  p1/preprocess/Stomach_Cancer/gene_data/GSE98708.csv filter=lfs diff=lfs merge=lfs -text
862
  p1/preprocess/Stomach_Cancer/gene_data/GSE183136.csv filter=lfs diff=lfs merge=lfs -text
863
  p1/preprocess/Stomach_Cancer/gene_data/GSE130823.csv filter=lfs diff=lfs merge=lfs -text
864
+ p1/preprocess/Stroke/GSE58294.csv filter=lfs diff=lfs merge=lfs -text
865
+ p1/preprocess/Sjögrens_Syndrome/gene_data/GSE66795.csv filter=lfs diff=lfs merge=lfs -text
866
+ p1/preprocess/Stroke/gene_data/GSE48424.csv filter=lfs diff=lfs merge=lfs -text
867
+ p1/preprocess/Stroke/gene_data/GSE68526.csv filter=lfs diff=lfs merge=lfs -text
868
+ p1/preprocess/Sarcoma/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
869
+ p1/preprocess/Stroke/gene_data/GSE161533.csv filter=lfs diff=lfs merge=lfs -text
870
+ p1/preprocess/Stroke/gene_data/GSE47727.csv filter=lfs diff=lfs merge=lfs -text
871
+ p1/preprocess/Stroke/gene_data/GSE58294.csv filter=lfs diff=lfs merge=lfs -text
872
+ p1/preprocess/Substance_Use_Disorder/gene_data/GSE138297.csv filter=lfs diff=lfs merge=lfs -text
873
+ p1/preprocess/Thyroid_Cancer/GSE151179.csv filter=lfs diff=lfs merge=lfs -text
874
+ p1/preprocess/Thymoma/GSE42977.csv filter=lfs diff=lfs merge=lfs -text
875
+ p1/preprocess/Prostate_Cancer/TCGA.csv filter=lfs diff=lfs merge=lfs -text
876
+ p1/preprocess/Thyroid_Cancer/GSE82208.csv filter=lfs diff=lfs merge=lfs -text
877
+ p1/preprocess/Thymoma/gene_data/GSE42977.csv filter=lfs diff=lfs merge=lfs -text
878
+ p1/preprocess/Thymoma/gene_data/GSE131027.csv filter=lfs diff=lfs merge=lfs -text
879
+ p1/preprocess/Prostate_Cancer/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
880
+ p1/preprocess/Thyroid_Cancer/GSE80022.csv filter=lfs diff=lfs merge=lfs -text
881
+ p1/preprocess/Thyroid_Cancer/gene_data/GSE138198.csv filter=lfs diff=lfs merge=lfs -text
p1/preprocess/Prostate_Cancer/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3bbf3437810231a05a8a33244fdb0b456a205419e47f9ac0fd0a9f41b075ea96
3
+ size 165480790
p1/preprocess/Prostate_Cancer/gene_data/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:890ecd87b1a72d6f024ca89aca716617571a5bd650d1394b9310f986ab9eb496
3
+ size 165478026
p1/preprocess/Sarcoma/gene_data/TCGA.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:affd5e63814cb48cd311be374db9e5944092f4cd6f4c56833a078f5444d320b7
3
+ size 79542665
p1/preprocess/Sjögrens_Syndrome/gene_data/GSE66795.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:36ec421c3df8e66a99cd36c18a80075dcb9de3b67ea6f9704ac561a05b16e6d7
3
+ size 41209920
p1/preprocess/Stroke/GSE58294.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aac70556b9b82709796331682b3477de899258a31c4d35c3ff19363f33e1be0e
3
+ size 20321203
p1/preprocess/Stroke/gene_data/GSE161533.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5d208865a1e0a2d86a225d5d57d2b021d6aeadb41c64abca895fd41bc8a56d1d
3
+ size 16557136
p1/preprocess/Stroke/gene_data/GSE47727.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3911e4ca8b0d9286bd33dfe6347f7ca16dd00f295d016d279eaaebc43067913c
3
+ size 28462595
p1/preprocess/Stroke/gene_data/GSE48424.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:00dd792e0a6531655e940c53da609aacb9b587f391354cbec5d5bf0e24df81c2
3
+ size 11568964
p1/preprocess/Stroke/gene_data/GSE58294.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:69f36e4f9618774bbd303b0f2be4cd8f6dd651cc162cd324e238f00773ef4e5a
3
+ size 20320832
p1/preprocess/Stroke/gene_data/GSE68526.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9162df01fa3b48faf0f29544794c10bfa1ff1b98c717e0d6a35f31690d3ee1cf
3
+ size 22185928
p1/preprocess/Substance_Use_Disorder/GSE159676.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Substance_Use_Disorder/code/GSE161999.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Substance_Use_Disorder"
6
+ cohort = "GSE161999"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Substance_Use_Disorder"
10
+ in_cohort_dir = "../DATA/GEO/Substance_Use_Disorder/GSE161999"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Substance_Use_Disorder/GSE161999.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Substance_Use_Disorder/gene_data/GSE161999.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Substance_Use_Disorder/clinical_data/GSE161999.csv"
16
+ json_path = "./output/preprocess/1/Substance_Use_Disorder/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # Step 1: Determine whether gene expression data is available
37
+ is_gene_available = True # Based on the dataset description indicating RNA-based (likely gene expression) data
38
+
39
+ # Step 2: Identify data availability and define conversion functions
40
+ # 2.1. Identify row indices
41
+ trait_row = 1 # diagnosis: Alcohol/Control (binary)
42
+ age_row = 2 # age: numeric, multiple unique values
43
+ gender_row = None # Only 'Sex: Male' found; single unique value => not available
44
+
45
+ # 2.2. Define data type conversion functions
46
+ def convert_trait(value: str):
47
+ """
48
+ Convert the trait diagnosis information to a binary variable:
49
+ 'Alcohol' -> 1
50
+ 'Control' -> 0
51
+ Otherwise -> None
52
+ """
53
+ # Extract the part after the colon
54
+ parts = value.split(':')
55
+ raw_val = parts[-1].strip().lower() if len(parts) > 1 else None
56
+ if raw_val == 'alcohol':
57
+ return 1
58
+ elif raw_val == 'control':
59
+ return 0
60
+ return None
61
+
62
+ def convert_age(value: str):
63
+ """
64
+ Convert the age to a float. If parsing fails, return None.
65
+ """
66
+ parts = value.split(':')
67
+ raw_val = parts[-1].strip() if len(parts) > 1 else None
68
+ try:
69
+ return float(raw_val)
70
+ except:
71
+ return None
72
+
73
+ def convert_gender(value: str):
74
+ """
75
+ Convert gender to binary:
76
+ 'Female' -> 0
77
+ 'Male' -> 1
78
+ Otherwise -> None
79
+ (Not used here because gender_row is None.)
80
+ """
81
+ parts = value.split(':')
82
+ raw_val = parts[-1].strip().lower() if len(parts) > 1 else None
83
+ if raw_val == 'male':
84
+ return 1
85
+ elif raw_val == 'female':
86
+ return 0
87
+ return None
88
+
89
+ # Step 3: Conduct initial filtering and save metadata
90
+ is_trait_available = (trait_row is not None)
91
+ validate_and_save_cohort_info(
92
+ is_final=False,
93
+ cohort=cohort,
94
+ info_path=json_path,
95
+ is_gene_available=is_gene_available,
96
+ is_trait_available=is_trait_available
97
+ )
98
+
99
+ # Step 4: If trait data is available, extract clinical features
100
+ if trait_row is not None:
101
+ extracted_clinical_df = geo_select_clinical_features(
102
+ clinical_df=clinical_data,
103
+ trait=trait,
104
+ trait_row=trait_row,
105
+ convert_trait=convert_trait,
106
+ age_row=age_row,
107
+ convert_age=convert_age,
108
+ gender_row=gender_row,
109
+ convert_gender=convert_gender
110
+ )
111
+
112
+ # Preview
113
+ clinical_preview = preview_df(extracted_clinical_df)
114
+ print(clinical_preview)
115
+
116
+ # Save extracted clinical data to CSV
117
+ extracted_clinical_df.to_csv(out_clinical_data_file, index=False)
118
+ # STEP3
119
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
120
+ gene_data = get_genetic_data(matrix_file)
121
+
122
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
123
+ print(gene_data.index[:20])
124
+ # These IDs (e.g., "1007_s_at", "1053_at") are Affymetrix probe set identifiers, not standard human gene symbols.
125
+ # Therefore, gene mapping to symbols is required.
126
+
127
+ print("requires_gene_mapping = True")
128
+ # STEP5
129
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
130
+ gene_annotation = get_gene_annotation(soft_file)
131
+
132
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
133
+ print("Gene annotation preview:")
134
+ print(preview_df(gene_annotation))
135
+ # STEP: Gene Identifier Mapping
136
+
137
+ # 1. Identify the columns in the gene_annotation dataframe that correspond to the probe identifiers ("ID")
138
+ # and the gene symbols ("Gene Symbol").
139
+
140
+ # 2. Create a mapping dataframe using the get_gene_mapping function.
141
+ mapping_df = get_gene_mapping(
142
+ annotation=gene_annotation,
143
+ prob_col="ID",
144
+ gene_col="Gene Symbol"
145
+ )
146
+
147
+ # 3. Apply the mapping to convert probe-level data into gene-level expression.
148
+ gene_data = apply_gene_mapping(
149
+ expression_df=gene_data,
150
+ mapping_df=mapping_df
151
+ )
152
+
153
+ # (Optional) Print some basic information about the resulting gene_data for verification.
154
+ print("Shape of the mapped gene_data:", gene_data.shape)
155
+ print("Preview of the mapped gene_data:")
156
+ print(preview_df(gene_data, n=5))
157
+ # STEP7
158
+
159
+ # 1. Normalize the obtained gene data and save
160
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
161
+ normalized_gene_data.to_csv(out_gene_data_file)
162
+
163
+ # 2. Link clinical and gene expression data on sample IDs
164
+ linked_data = geo_link_clinical_genetic_data(extracted_clinical_df, normalized_gene_data)
165
+
166
+ # 3. Handle missing values systematically using the trait column name in the 'trait' variable
167
+ linked_data = handle_missing_values(linked_data, trait)
168
+
169
+ # 4. Check for biased features (trait, age, gender) using the same trait column name
170
+ is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
171
+
172
+ # 5. Final quality validation and record metadata
173
+ is_usable = validate_and_save_cohort_info(
174
+ is_final=True,
175
+ cohort=cohort,
176
+ info_path=json_path,
177
+ is_gene_available=True,
178
+ is_trait_available=True,
179
+ is_biased=is_trait_biased,
180
+ df=linked_data,
181
+ note=f"Preprocessed with trait column named '{trait}'."
182
+ )
183
+
184
+ # 6. If usable, save linked data
185
+ if is_usable:
186
+ linked_data.to_csv(out_data_file, index=True)
p1/preprocess/Substance_Use_Disorder/code/GSE273630.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Substance_Use_Disorder"
6
+ cohort = "GSE273630"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Substance_Use_Disorder"
10
+ in_cohort_dir = "../DATA/GEO/Substance_Use_Disorder/GSE273630"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Substance_Use_Disorder/GSE273630.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Substance_Use_Disorder/gene_data/GSE273630.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Substance_Use_Disorder/clinical_data/GSE273630.csv"
16
+ json_path = "./output/preprocess/1/Substance_Use_Disorder/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # Step 1: Determine if gene expression data is available
37
+ # Based on the background information, we have NanoString custom transcriptome data, so set True
38
+ is_gene_available = True
39
+
40
+ # Step 2: Variable Availability and Data Type Conversion
41
+ # From the sample characteristics dictionary:
42
+ # {0: ['tissue: Peripheral blood cells']}
43
+ # There is no row providing trait, age, or gender information (all participants are the same)
44
+ # Hence, they are not available.
45
+ trait_row = None
46
+ age_row = None
47
+ gender_row = None
48
+
49
+ # Define conversion functions
50
+ def convert_trait(raw_value: str):
51
+ # For demonstration, we parse after colon. But here, trait data is not available.
52
+ # Return None for any input in this scenario.
53
+ return None
54
+
55
+ def convert_age(raw_value: str):
56
+ # Age data is constant (35-44) for all participants, effectively not a variable.
57
+ # Return None for any input in this scenario.
58
+ return None
59
+
60
+ def convert_gender(raw_value: str):
61
+ # All participants are male, so there is no variation.
62
+ # Return None for any input in this scenario.
63
+ return None
64
+
65
+ # Step 3: Save Metadata (initial filtering)
66
+ is_trait_available = (trait_row is not None)
67
+ is_usable = validate_and_save_cohort_info(
68
+ is_final=False,
69
+ cohort=cohort,
70
+ info_path=json_path,
71
+ is_gene_available=is_gene_available,
72
+ is_trait_available=is_trait_available
73
+ )
74
+
75
+ # Step 4: Since trait_row is None, skip clinical feature extraction
p1/preprocess/Substance_Use_Disorder/code/GSE94399.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Substance_Use_Disorder"
6
+ cohort = "GSE94399"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Substance_Use_Disorder"
10
+ in_cohort_dir = "../DATA/GEO/Substance_Use_Disorder/GSE94399"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Substance_Use_Disorder/GSE94399.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Substance_Use_Disorder/gene_data/GSE94399.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Substance_Use_Disorder/clinical_data/GSE94399.csv"
16
+ json_path = "./output/preprocess/1/Substance_Use_Disorder/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Gene Expression Data Availability
37
+ is_gene_available = True # Based on the background stating "Gene expression profiling..."
38
+
39
+ # 2. Variable Availability and Data Type Conversion
40
+
41
+ # Since the clinical dictionary only has "cohort" and "outcome" entries,
42
+ # and everyone seems to share the same overarching trait (alcoholic hepatitis),
43
+ # there is no varying trait data here. Similarly, no age or gender info is present.
44
+ trait_row = None
45
+ age_row = None
46
+ gender_row = None
47
+
48
+ # Define the conversion functions.
49
+ # They won't be used since trait_row, age_row, and gender_row are None,
50
+ # but we still define them to match the required function names.
51
+ def convert_trait(value: str) -> Optional[Union[int, float]]:
52
+ return None
53
+
54
+ def convert_age(value: str) -> Optional[Union[int, float]]:
55
+ return None
56
+
57
+ def convert_gender(value: str) -> Optional[int]:
58
+ return None
59
+
60
+ # 3. Save Metadata (Initial Filtering)
61
+ # trait data availability is determined by whether trait_row is None
62
+ is_trait_available = (trait_row is not None)
63
+ is_usable = validate_and_save_cohort_info(
64
+ is_final=False,
65
+ cohort=cohort,
66
+ info_path=json_path,
67
+ is_gene_available=is_gene_available,
68
+ is_trait_available=is_trait_available
69
+ )
70
+
71
+ # 4. Clinical Feature Extraction
72
+ # Since trait_row is None, we do not extract clinical features.
73
+ # STEP3
74
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
75
+ gene_data = get_genetic_data(matrix_file)
76
+
77
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
78
+ print(gene_data.index[:20])
79
+ # These probe identifiers (e.g., "11715100_at") appear to be Affymetrix probe set IDs, not standard human gene symbols.
80
+ # Hence, they require mapping to gene symbols.
81
+
82
+ print("requires_gene_mapping = True")
83
+ # STEP5
84
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
85
+ gene_annotation = get_gene_annotation(soft_file)
86
+
87
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
88
+ print("Gene annotation preview:")
89
+ print(preview_df(gene_annotation))
90
+ # STEP: Gene Identifier Mapping
91
+
92
+ # 1. Identify the columns for gene ID and gene symbol in 'gene_annotation'.
93
+ # From the preview, probe IDs match 'ID' and gene symbols match 'Gene Symbol'.
94
+
95
+ # 2. Get the gene mapping dataframe using the identified columns.
96
+ mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="Gene Symbol")
97
+
98
+ # 3. Convert probe-level measurements to gene expression data.
99
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
100
+ # STEP7
101
+
102
+ # According to the instructions, if the trait is not actually available (trait_row is None),
103
+ # we should not proceed with further trait-dependent steps such as linking and bias checks.
104
+ # Instead, we finalize the dataset as not usable.
105
+
106
+ # Therefore, we skip all trait-dependent steps and directly perform final validation with
107
+ # is_trait_available=False, marking this dataset as not usable.
108
+
109
+ is_usable = validate_and_save_cohort_info(
110
+ is_final=True,
111
+ cohort=cohort,
112
+ info_path=json_path,
113
+ is_gene_available=True, # We did confirm gene data are available
114
+ is_trait_available=False, # Trait is not available
115
+ is_biased=None,
116
+ df=None,
117
+ note="Trait unavailable => dataset not usable."
118
+ )
119
+
120
+ # No further steps are done because trait is unavailable.
p1/preprocess/Substance_Use_Disorder/code/TCGA.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Substance_Use_Disorder"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/1/Substance_Use_Disorder/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/1/Substance_Use_Disorder/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/1/Substance_Use_Disorder/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/1/Substance_Use_Disorder/cohort_info.json"
15
+
16
+ import os
17
+
18
+ # List subdirectories (already provided in the environment)
19
+ subdirectories = [
20
+ 'TCGA-LGG', 'CrawlData.ipynb', '.DS_Store',
21
+ 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
22
+ 'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)',
23
+ 'TCGA_Thymoma_(THYM)', 'TCGA_Testicular_Cancer_(TGCT)',
24
+ 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
25
+ 'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)',
26
+ 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)', 'TCGA_Pancreatic_Cancer_(PAAD)',
27
+ 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
28
+ 'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)',
29
+ 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)', 'TCGA_Lung_Cancer_(LUNG)',
30
+ 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
31
+ 'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)',
32
+ 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)', 'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)',
33
+ 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
34
+ 'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)',
35
+ 'TCGA_Endometrioid_Cancer_(UCEC)', 'TCGA_Colon_and_Rectal_Cancer_(COADREAD)',
36
+ 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
37
+ 'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)',
38
+ 'TCGA_Bile_Duct_Cancer_(CHOL)', 'TCGA_Adrenocortical_Cancer_(ACC)',
39
+ 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
40
+ ]
41
+
42
+ trait_lower = trait.lower()
43
+ relevant_folder = None
44
+
45
+ # Look for any subdirectory name containing terms relevant to our trait name
46
+ for folder in subdirectories:
47
+ folder_lower = folder.lower()
48
+ # Simple direct matching approach
49
+ if "substance" in folder_lower or "use" in folder_lower or "disorder" in folder_lower:
50
+ relevant_folder = folder
51
+ break
52
+
53
+ # If we don't find a matching folder, skip this trait
54
+ if not relevant_folder:
55
+ _ = validate_and_save_cohort_info(
56
+ is_final=False,
57
+ cohort="TCGA",
58
+ info_path=json_path,
59
+ is_gene_available=False,
60
+ is_trait_available=False
61
+ )
62
+ print(f"No suitable directory found for trait {trait}. Skipping this trait.")
63
+ else:
64
+ # If we did find a relevant directory (unlikely for this trait), load the files.
65
+ folder_path = os.path.join(tcga_root_dir, relevant_folder)
66
+ clinical_file, genetic_file = tcga_get_relevant_filepaths(folder_path)
67
+
68
+ clinical_data = pd.read_csv(clinical_file, index_col=0, sep='\t')
69
+ genetic_data = pd.read_csv(genetic_file, index_col=0, sep='\t')
70
+
71
+ print("Clinical data columns:", clinical_data.columns.tolist())
p1/preprocess/Substance_Use_Disorder/gene_data/GSE116833.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Substance_Use_Disorder/gene_data/GSE125681.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Substance_Use_Disorder/gene_data/GSE138297.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de9565415a246beb680e5ba05e15de50eccfec4d24f558d0cba022302313ca04
3
+ size 15408302
p1/preprocess/Substance_Use_Disorder/gene_data/GSE159676.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Substance_Use_Disorder/gene_data/GSE161986.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Substance_Use_Disorder/gene_data/GSE161999.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Substance_Use_Disorder/gene_data/GSE94399.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Telomere_Length/code/GSE16058.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Telomere_Length"
6
+ cohort = "GSE16058"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Telomere_Length"
10
+ in_cohort_dir = "../DATA/GEO/Telomere_Length/GSE16058"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Telomere_Length/GSE16058.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Telomere_Length/gene_data/GSE16058.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Telomere_Length/clinical_data/GSE16058.csv"
16
+ json_path = "./output/preprocess/1/Telomere_Length/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1) Gene Expression Data Availability
37
+ is_gene_available = True # The series summary explicitly mentions "Gene transcript", indicating gene expression data.
38
+
39
+ # 2) Variable Availability and Data Type Conversion
40
+ # From inspecting the sample characteristics, there is no clear key containing telomere length, age, or gender.
41
+ trait_row = None
42
+ age_row = None
43
+ gender_row = None
44
+
45
+ def convert_trait(value: str):
46
+ # This dataset does not explicitly provide telomere length measurements,
47
+ # so we'll return None.
48
+ return None
49
+
50
+ def convert_age(value: str):
51
+ # No age information is available, return None.
52
+ return None
53
+
54
+ def convert_gender(value: str):
55
+ # No gender information is available, return None.
56
+ return None
57
+
58
+ # 3) Save Metadata (Initial filtering)
59
+ is_trait_available = (trait_row is not None)
60
+ validate_and_save_cohort_info(
61
+ is_final=False,
62
+ cohort=cohort,
63
+ info_path=json_path,
64
+ is_gene_available=is_gene_available,
65
+ is_trait_available=is_trait_available
66
+ )
67
+
68
+ # 4) Clinical Feature Extraction
69
+ # Skipped, because trait_row is None.
70
+ # STEP3
71
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
72
+ gene_data = get_genetic_data(matrix_file)
73
+
74
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
75
+ print(gene_data.index[:20])
76
+ print("requires_gene_mapping = True")
77
+ # STEP5
78
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
79
+ gene_annotation = get_gene_annotation(soft_file)
80
+
81
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
82
+ print("Gene annotation preview:")
83
+ print(preview_df(gene_annotation))
84
+ # STEP6: Gene Identifier Mapping
85
+
86
+ # 1) Identify the appropriate columns in the gene annotation DataFrame that correspond to the probe identifiers
87
+ # and the gene symbols, respectively.
88
+ # From the preview, "ID" matches the gene expression data index, and "Gene Symbol" provides the gene symbols.
89
+
90
+ # 2) Construct the mapping dataframe between the gene ID and the gene symbol.
91
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')
92
+
93
+ # 3) Convert probe-level measurements to gene-level expression by applying the gene mapping.
94
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
95
+ # STEP7
96
+
97
+ import pandas as pd
98
+
99
+ # Check if clinical data (and thus the trait) was actually extracted in a previous step
100
+ # by testing whether "selected_clinical_df" exists.
101
+ try:
102
+ selected_clinical_df
103
+ trait_data_available = True
104
+ except NameError:
105
+ trait_data_available = False
106
+
107
+ if not trait_data_available:
108
+ # Since there's no clinical DataFrame, we finalize the dataset as unusable for trait analysis
109
+ # (missing trait), and skip further processing.
110
+ empty_df = pd.DataFrame()
111
+ # Mark trait as biased (or simply unusable) to ensure the final validation flags it as not usable
112
+ is_trait_biased = True
113
+ validate_and_save_cohort_info(
114
+ is_final=True,
115
+ cohort=cohort,
116
+ info_path=json_path,
117
+ is_gene_available=True, # We do have gene data, but no trait data
118
+ is_trait_available=False,
119
+ is_biased=is_trait_biased,
120
+ df=empty_df,
121
+ note="No trait data found; dataset is not usable for trait-based analysis."
122
+ )
123
+ else:
124
+ # 1. Normalize the obtained gene data and save
125
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
126
+ normalized_gene_data.to_csv(out_gene_data_file)
127
+
128
+ # 2. Link clinical and gene expression data on sample IDs
129
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
130
+
131
+ # 3. Handle missing values systematically using the trait column name in the 'trait' variable
132
+ linked_data = handle_missing_values(linked_data, trait)
133
+
134
+ # 4. Check for biased features (trait, age, gender) using the same trait column name
135
+ is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
136
+
137
+ # 5. Final quality validation and record metadata
138
+ is_usable = validate_and_save_cohort_info(
139
+ is_final=True,
140
+ cohort=cohort,
141
+ info_path=json_path,
142
+ is_gene_available=True,
143
+ is_trait_available=True,
144
+ is_biased=is_trait_biased,
145
+ df=linked_data,
146
+ note=f"Preprocessed with trait column named '{trait}'."
147
+ )
148
+
149
+ # 6. If usable, save linked data
150
+ if is_usable:
151
+ linked_data.to_csv(out_data_file, index=True)
p1/preprocess/Telomere_Length/code/GSE52237.py ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Telomere_Length"
6
+ cohort = "GSE52237"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Telomere_Length"
10
+ in_cohort_dir = "../DATA/GEO/Telomere_Length/GSE52237"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Telomere_Length/GSE52237.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Telomere_Length/gene_data/GSE52237.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Telomere_Length/clinical_data/GSE52237.csv"
16
+ json_path = "./output/preprocess/1/Telomere_Length/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Determine if gene expression data is available
37
+ is_gene_available = True # From the series description mentioning gene expression analysis
38
+
39
+ # 2. Determine data availability for trait, age, and gender
40
+ # Based on the sample characteristics dictionary, none of these variables appear.
41
+ trait_row = None
42
+ age_row = None
43
+ gender_row = None
44
+
45
+ # 2.2 Define data type conversion functions (though we have no actual data rows)
46
+ def convert_trait(value: str):
47
+ # Telomere length is continuous if present, but here it's unavailable.
48
+ # We'll define a generic continuous conversion.
49
+ parts = value.split(":")
50
+ if len(parts) < 2:
51
+ return None
52
+ val_str = parts[1].strip()
53
+ try:
54
+ return float(val_str)
55
+ except ValueError:
56
+ return None
57
+
58
+ def convert_age(value: str):
59
+ # Age is continuous if present, but here it's unavailable.
60
+ # We'll define a generic continuous conversion.
61
+ parts = value.split(":")
62
+ if len(parts) < 2:
63
+ return None
64
+ val_str = parts[1].strip()
65
+ try:
66
+ return float(val_str)
67
+ except ValueError:
68
+ return None
69
+
70
+ def convert_gender(value: str):
71
+ # Convert female to 0 and male to 1 if present, but here it's unavailable.
72
+ # We'll define a generic binary conversion.
73
+ parts = value.split(":")
74
+ if len(parts) < 2:
75
+ return None
76
+ val_str = parts[1].strip().lower()
77
+ if val_str in ['female', 'f']:
78
+ return 0
79
+ elif val_str in ['male', 'm']:
80
+ return 1
81
+ return None
82
+
83
+ # 3. Conduct initial filtering and save metadata
84
+ is_trait_available = (trait_row is not None)
85
+ is_usable = validate_and_save_cohort_info(
86
+ is_final=False,
87
+ cohort=cohort,
88
+ info_path=json_path,
89
+ is_gene_available=is_gene_available,
90
+ is_trait_available=is_trait_available
91
+ )
92
+
93
+ # 4. Since trait_row is None, we skip clinical feature extraction.
94
+ # STEP3
95
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
96
+ gene_data = get_genetic_data(matrix_file)
97
+
98
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
99
+ print(gene_data.index[:20])
100
+ # These gene identifiers appear to be Affymetrix probe set IDs (e.g. "1007_s_at"), not human gene symbols.
101
+ # Therefore, gene mapping is required.
102
+ requires_gene_mapping = True
103
+ # STEP5
104
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
105
+ gene_annotation = get_gene_annotation(soft_file)
106
+
107
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
108
+ print("Gene annotation preview:")
109
+ print(preview_df(gene_annotation))
110
+ # STEP: Gene Identifier Mapping
111
+
112
+ # 1. Identify the matching columns in the gene annotation dataframe
113
+ identifier_col = "ID" # The probe identifier column
114
+ symbol_col = "Gene Symbol" # The gene symbol column
115
+
116
+ # 2. Get the gene mapping dataframe
117
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=identifier_col, gene_col=symbol_col)
118
+
119
+ # 3. Convert probe-level measurements to gene-level expression data
120
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
121
+
122
+ # (Optional) Print information for verification
123
+ print("Gene-level data shape:", gene_data.shape)
124
+ print("First 10 gene symbols in the mapped data:", list(gene_data.index[:10]))
125
+ # STEP7
126
+
127
+ import pandas as pd
128
+
129
+ # Check if clinical data (and thus the trait) was actually extracted in a previous step
130
+ # by testing whether "selected_clinical_df" exists.
131
+ try:
132
+ selected_clinical_df
133
+ trait_data_available = True
134
+ except NameError:
135
+ trait_data_available = False
136
+
137
+ if not trait_data_available:
138
+ # Since there's no clinical DataFrame, we finalize the dataset as unusable for trait analysis
139
+ # (missing trait), and skip further processing.
140
+ empty_df = pd.DataFrame()
141
+ # Mark trait as biased (or simply unusable) to ensure the final validation flags it as not usable
142
+ is_trait_biased = True
143
+ validate_and_save_cohort_info(
144
+ is_final=True,
145
+ cohort=cohort,
146
+ info_path=json_path,
147
+ is_gene_available=True, # We do have gene data, but no trait data
148
+ is_trait_available=False,
149
+ is_biased=is_trait_biased,
150
+ df=empty_df,
151
+ note="No trait data found; dataset is not usable for trait-based analysis."
152
+ )
153
+ else:
154
+ # 1. Normalize the obtained gene data and save
155
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
156
+ normalized_gene_data.to_csv(out_gene_data_file)
157
+
158
+ # 2. Link clinical and gene expression data on sample IDs
159
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
160
+
161
+ # 3. Handle missing values systematically using the trait column name in the 'trait' variable
162
+ linked_data = handle_missing_values(linked_data, trait)
163
+
164
+ # 4. Check for biased features (trait, age, gender) using the same trait column name
165
+ is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
166
+
167
+ # 5. Final quality validation and record metadata
168
+ is_usable = validate_and_save_cohort_info(
169
+ is_final=True,
170
+ cohort=cohort,
171
+ info_path=json_path,
172
+ is_gene_available=True,
173
+ is_trait_available=True,
174
+ is_biased=is_trait_biased,
175
+ df=linked_data,
176
+ note=f"Preprocessed with trait column named '{trait}'."
177
+ )
178
+
179
+ # 6. If usable, save linked data
180
+ if is_usable:
181
+ linked_data.to_csv(out_data_file, index=True)
p1/preprocess/Telomere_Length/code/GSE80435.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Telomere_Length"
6
+ cohort = "GSE80435"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Telomere_Length"
10
+ in_cohort_dir = "../DATA/GEO/Telomere_Length/GSE80435"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Telomere_Length/GSE80435.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Telomere_Length/gene_data/GSE80435.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Telomere_Length/clinical_data/GSE80435.csv"
16
+ json_path = "./output/preprocess/1/Telomere_Length/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Gene Expression Data Availability
37
+ is_gene_available = True # From background info: "Expression arrays were used..."
38
+
39
+ # 2. Variable Availability and Data Type Conversion
40
+
41
+ # Based on the sample characteristics dictionary:
42
+ # {0: ['region: Lymph nodes- Inguinal', 'region: Lymph nodes- Axilla', 'region: Lymph nodes- Groin']}
43
+ # None of these rows provide data for 'Telomere_Length', 'age', or 'gender'.
44
+ trait_row = None
45
+ age_row = None
46
+ gender_row = None
47
+
48
+ # Define conversion functions (though they won't be used here since all rows are None)
49
+ def convert_trait(value: str):
50
+ try:
51
+ # Hypothetical splitting on colon
52
+ part = value.split(":")[-1].strip()
53
+ return float(part) if part else None
54
+ except:
55
+ return None
56
+
57
+ def convert_age(value: str):
58
+ try:
59
+ part = value.split(":")[-1].strip()
60
+ return float(part) if part else None
61
+ except:
62
+ return None
63
+
64
+ def convert_gender(value: str):
65
+ # Convert female->0, male->1. Otherwise None.
66
+ part = value.split(":")[-1].strip().lower()
67
+ if 'female' in part:
68
+ return 0
69
+ elif 'male' in part:
70
+ return 1
71
+ return None
72
+
73
+ # 3. Save Metadata (initial filtering)
74
+ is_trait_available = (trait_row is not None)
75
+ 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
+ # We skip this step because trait_row is None
85
+ # STEP3
86
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
87
+ gene_data = get_genetic_data(matrix_file)
88
+
89
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
90
+ print(gene_data.index[:20])
91
+ requires_gene_mapping = True
92
+ # STEP5
93
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
94
+ gene_annotation = get_gene_annotation(soft_file)
95
+
96
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
97
+ print("Gene annotation preview:")
98
+ print(preview_df(gene_annotation))
99
+ # STEP: Gene Identifier Mapping
100
+
101
+ # 1. Decide which columns in the gene annotation match our probe IDs and gene symbols.
102
+ # From our preview, the "ID" column matches probe identifiers (e.g., ILMN_1825594),
103
+ # and the "Symbol" column contains gene symbols (though some may be special locus IDs).
104
+
105
+ # 2. Get a dataframe mapping probe IDs to gene symbols.
106
+ mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="Symbol")
107
+
108
+ # 3. Convert probe-level measurements to gene-level by applying the mapping.
109
+ # Each probe that maps to multiple genes is split, then summed for each gene.
110
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
111
+
112
+ # Optional: to quickly inspect the new gene_data
113
+ print("Mapped gene_data shape:", gene_data.shape)
114
+ print("Mapped gene_data index (sample):", gene_data.index[:10])
115
+ # STEP7
116
+
117
+ import pandas as pd
118
+
119
+ # Check if clinical data (and thus the trait) was actually extracted in a previous step
120
+ # by testing whether "selected_clinical_df" exists.
121
+ try:
122
+ selected_clinical_df
123
+ trait_data_available = True
124
+ except NameError:
125
+ trait_data_available = False
126
+
127
+ if not trait_data_available:
128
+ # Since there's no clinical DataFrame, we finalize the dataset as unusable for trait analysis
129
+ # (missing trait), and skip further processing.
130
+ empty_df = pd.DataFrame()
131
+ # Mark trait as biased (or simply unusable) to ensure the final validation flags it as not usable
132
+ is_trait_biased = True
133
+ validate_and_save_cohort_info(
134
+ is_final=True,
135
+ cohort=cohort,
136
+ info_path=json_path,
137
+ is_gene_available=True, # We do have gene data, but no trait data
138
+ is_trait_available=False,
139
+ is_biased=is_trait_biased,
140
+ df=empty_df,
141
+ note="No trait data found; dataset is not usable for trait-based analysis."
142
+ )
143
+ else:
144
+ # 1. Normalize the obtained gene data and save
145
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
146
+ normalized_gene_data.to_csv(out_gene_data_file)
147
+
148
+ # 2. Link clinical and gene expression data on sample IDs
149
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
150
+
151
+ # 3. Handle missing values systematically using the trait column name in the 'trait' variable
152
+ linked_data = handle_missing_values(linked_data, trait)
153
+
154
+ # 4. Check for biased features (trait, age, gender) using the same trait column name
155
+ is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
156
+
157
+ # 5. Final quality validation and record metadata
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_trait_biased,
165
+ df=linked_data,
166
+ note=f"Preprocessed with trait column named '{trait}'."
167
+ )
168
+
169
+ # 6. If usable, save linked data
170
+ if is_usable:
171
+ linked_data.to_csv(out_data_file, index=True)
p1/preprocess/Telomere_Length/code/TCGA.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Telomere_Length"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/1/Telomere_Length/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/1/Telomere_Length/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/1/Telomere_Length/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/1/Telomere_Length/cohort_info.json"
15
+
16
+ # Step 1: Initial Data Loading
17
+
18
+ import os
19
+ import pandas as pd
20
+
21
+ # List subdirectories (as already given in the environment)
22
+ subdirectories = [
23
+ 'TCGA-LGG', 'CrawlData.ipynb', '.DS_Store',
24
+ 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
25
+ 'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)',
26
+ 'TCGA_Thymoma_(THYM)', 'TCGA_Testicular_Cancer_(TGCT)',
27
+ 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
28
+ 'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)',
29
+ 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)', 'TCGA_Pancreatic_Cancer_(PAAD)',
30
+ 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
31
+ 'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)',
32
+ 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)', 'TCGA_Lung_Cancer_(LUNG)',
33
+ 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
34
+ 'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)',
35
+ 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)', 'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)',
36
+ 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
37
+ 'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)',
38
+ 'TCGA_Endometrioid_Cancer_(UCEC)', 'TCGA_Colon_and_Rectal_Cancer_(COADREAD)',
39
+ 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
40
+ 'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)',
41
+ 'TCGA_Bile_Duct_Cancer_(CHOL)', 'TCGA_Adrenocortical_Cancer_(ACC)',
42
+ 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
43
+ ]
44
+
45
+ # Define synonyms or keywords relevant to "Telomere_Length"
46
+ telomere_synonyms = ["telomere"]
47
+
48
+ relevant_folder = None
49
+
50
+ for folder in subdirectories:
51
+ folder_lower = folder.lower()
52
+ if any(syn in folder_lower for syn in telomere_synonyms):
53
+ relevant_folder = folder
54
+ break
55
+
56
+ if not relevant_folder:
57
+ # No suitable directory found, mark as skipped
58
+ _ = validate_and_save_cohort_info(
59
+ is_final=False,
60
+ cohort="TCGA",
61
+ info_path=json_path,
62
+ is_gene_available=False,
63
+ is_trait_available=False
64
+ )
65
+ print(f"No suitable directory found for trait {trait}. Skipping this trait.")
66
+ else:
67
+ # If a relevant directory is found, load the files
68
+ folder_path = os.path.join(tcga_root_dir, relevant_folder)
69
+ clinical_file, genetic_file = tcga_get_relevant_filepaths(folder_path)
70
+
71
+ clinical_data = pd.read_csv(clinical_file, index_col=0, sep='\t')
72
+ genetic_data = pd.read_csv(genetic_file, index_col=0, sep='\t')
73
+
74
+ print("Clinical data columns:", clinical_data.columns.tolist())
p1/preprocess/Telomere_Length/cohort_info.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"GSE80435": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "No trait data found; dataset is not usable for trait-based analysis."}, "GSE52237": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "No trait data found; dataset is not usable for trait-based analysis."}, "GSE16058": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "No trait data found; dataset is not usable for trait-based analysis."}, "TCGA": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}}
p1/preprocess/Testicular_Cancer/code/GSE42647.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Testicular_Cancer"
6
+ cohort = "GSE42647"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Testicular_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Testicular_Cancer/GSE42647"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Testicular_Cancer/GSE42647.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Testicular_Cancer/gene_data/GSE42647.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Testicular_Cancer/clinical_data/GSE42647.csv"
16
+ json_path = "./output/preprocess/1/Testicular_Cancer/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1) Gene Expression Data Availability
37
+ # From the background information and sample characteristics, this dataset appears
38
+ # to be about a cell line treated with a demethylating agent, without clear evidence
39
+ # of standard gene expression profiling.
40
+ is_gene_available = False
41
+
42
+ # 2) Variable Availability and Data Type Conversion
43
+ # The dictionary only shows cell line and cell type info with no meaningful
44
+ # (variable) differences for trait, age, or gender. Therefore, none are available.
45
+ trait_row = None
46
+ age_row = None
47
+ gender_row = None
48
+
49
+ # 3) Save Metadata (initial filtering)
50
+ is_trait_available = (trait_row is not None)
51
+ is_usable = validate_and_save_cohort_info(
52
+ is_final=False,
53
+ cohort=cohort,
54
+ info_path=json_path,
55
+ is_gene_available=is_gene_available,
56
+ is_trait_available=is_trait_available
57
+ )
58
+
59
+ # 4) Clinical Feature Extraction
60
+ # Since trait_row is None, we skip this step.
p1/preprocess/Testicular_Cancer/code/GSE62523.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Testicular_Cancer"
6
+ cohort = "GSE62523"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Testicular_Cancer"
10
+ in_cohort_dir = "../DATA/GEO/Testicular_Cancer/GSE62523"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Testicular_Cancer/GSE62523.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Testicular_Cancer/gene_data/GSE62523.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Testicular_Cancer/clinical_data/GSE62523.csv"
16
+ json_path = "./output/preprocess/1/Testicular_Cancer/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Gene Expression Data Availability
37
+ is_gene_available = True # From the background info, this dataset is a gene expression dataset.
38
+
39
+ # 2. Variable Availability and Data Type Conversion
40
+ # The sample characteristics dictionary is:
41
+ # {0: ['cell line: HMEC-1'], 1: ['cell type: human microvascular endothelial cell line']}
42
+ #
43
+ # None of these correspond to our trait ("Testicular_Cancer"), age, or gender in a usable way.
44
+ # Therefore, all three are considered unavailable.
45
+
46
+ trait_row = None
47
+ age_row = None
48
+ gender_row = None
49
+
50
+ # Define conversion functions. Although no data is available, we still define them per requirement.
51
+ def convert_trait(value: str) -> int:
52
+ return None
53
+
54
+ def convert_age(value: str) -> float:
55
+ return None
56
+
57
+ def convert_gender(value: str) -> int:
58
+ return None
59
+
60
+ # 3. Save Metadata - initial filtering based on availability of gene data and trait data
61
+ is_trait_available = (trait_row is not None)
62
+
63
+ is_usable = validate_and_save_cohort_info(
64
+ is_final=False,
65
+ cohort=cohort,
66
+ info_path=json_path,
67
+ is_gene_available=is_gene_available,
68
+ is_trait_available=is_trait_available
69
+ )
70
+ print("Initial filtering result:", is_usable)
71
+
72
+ # 4. Clinical Feature Extraction
73
+ # trait_row is None, so we skip extraction of clinical features.
p1/preprocess/Testicular_Cancer/code/TCGA.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Testicular_Cancer"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/1/Testicular_Cancer/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/1/Testicular_Cancer/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/1/Testicular_Cancer/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/1/Testicular_Cancer/cohort_info.json"
15
+
16
+ # Step 1: Initial Data Loading
17
+
18
+ import os
19
+ import pandas as pd
20
+
21
+ # List subdirectories (as already given in the environment)
22
+ subdirectories = [
23
+ 'TCGA-LGG', 'CrawlData.ipynb', '.DS_Store',
24
+ 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
25
+ 'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)',
26
+ 'TCGA_Thymoma_(THYM)', 'TCGA_Testicular_Cancer_(TGCT)',
27
+ 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
28
+ 'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)',
29
+ 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)', 'TCGA_Pancreatic_Cancer_(PAAD)',
30
+ 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
31
+ 'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)',
32
+ 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)', 'TCGA_Lung_Cancer_(LUNG)',
33
+ 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
34
+ 'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)',
35
+ 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)', 'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)',
36
+ 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
37
+ 'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)',
38
+ 'TCGA_Endometrioid_Cancer_(UCEC)', 'TCGA_Colon_and_Rectal_Cancer_(COADREAD)',
39
+ 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
40
+ 'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)',
41
+ 'TCGA_Bile_Duct_Cancer_(CHOL)', 'TCGA_Adrenocortical_Cancer_(ACC)',
42
+ 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
43
+ ]
44
+
45
+ # We want to find a folder relevant to "Testicular_Cancer"
46
+ testicular_synonyms = ["testicular", "tgct"]
47
+
48
+ relevant_folder = None
49
+
50
+ for folder in subdirectories:
51
+ folder_lower = folder.lower()
52
+ if any(syn in folder_lower for syn in testicular_synonyms):
53
+ relevant_folder = folder
54
+ break
55
+
56
+ if not relevant_folder:
57
+ # No suitable directory found, mark as skipped
58
+ _ = validate_and_save_cohort_info(
59
+ is_final=False,
60
+ cohort="TCGA",
61
+ info_path=json_path,
62
+ is_gene_available=False,
63
+ is_trait_available=False
64
+ )
65
+ print(f"No suitable directory found for trait {trait}. Skipping this trait.")
66
+ else:
67
+ # If a relevant directory is found, load the files
68
+ folder_path = os.path.join(tcga_root_dir, relevant_folder)
69
+ clinical_file, genetic_file = tcga_get_relevant_filepaths(folder_path)
70
+
71
+ clinical_data = pd.read_csv(clinical_file, index_col=0, sep='\t')
72
+ genetic_data = pd.read_csv(genetic_file, index_col=0, sep='\t')
73
+
74
+ print("Clinical data columns:", clinical_data.columns.tolist())
75
+ candidate_age_cols = ["age_at_initial_pathologic_diagnosis", "undescended_testis_corrected_age", "days_to_birth"]
76
+ candidate_gender_cols = ["gender"]
77
+
78
+ # Extract candidate columns
79
+ age_data = clinical_data[candidate_age_cols] if candidate_age_cols else pd.DataFrame()
80
+ gender_data = clinical_data[candidate_gender_cols] if candidate_gender_cols else pd.DataFrame()
81
+
82
+ # Preview the extracted columns
83
+ age_preview = preview_df(age_data, n=5) if not age_data.empty else {}
84
+ gender_preview = preview_df(gender_data, n=5) if not gender_data.empty else {}
85
+
86
+ age_preview, gender_preview
87
+ import re
88
+
89
+ # Example dictionaries from a previous step (replace with actual dictionaries)
90
+ age_candidates = {
91
+ "age_at_diagnosis": ["45", "48", "nan", None, "52"],
92
+ "patient_age": ["42", "forty", "37", "45", None]
93
+ }
94
+ gender_candidates = {
95
+ "gender": ["male", "female", "male", "female", "male"],
96
+ "sex_info": ["MALE", None, "n/a", "FEMALE", "FEMALE"]
97
+ }
98
+
99
+ def column_has_sufficient_valid_age(values, threshold=0.7):
100
+ valid_count = 0
101
+ for val in values:
102
+ if val is None:
103
+ continue
104
+ match = re.search(r'\d+', str(val))
105
+ if match:
106
+ valid_count += 1
107
+ return (valid_count / len(values)) >= threshold if values else False
108
+
109
+ def column_has_sufficient_valid_gender(values, threshold=0.7):
110
+ valid_count = 0
111
+ for val in values:
112
+ if val is None:
113
+ continue
114
+ val_lower = str(val).lower()
115
+ if val_lower in ["male", "female"]:
116
+ valid_count += 1
117
+ return (valid_count / len(values)) >= threshold if values else False
118
+
119
+ age_col = None
120
+ gender_col = None
121
+
122
+ # Find the first suitable age column
123
+ for col_name, vals in age_candidates.items():
124
+ if column_has_sufficient_valid_age(vals):
125
+ age_col = col_name
126
+ break
127
+
128
+ # Find the first suitable gender column
129
+ for col_name, vals in gender_candidates.items():
130
+ if column_has_sufficient_valid_gender(vals):
131
+ gender_col = col_name
132
+ break
133
+
134
+ print("Chosen age_col:", age_col)
135
+ print("Chosen gender_col:", gender_col)
136
+ # 1. Extract and standardize the clinical features
137
+ selected_clinical_df = tcga_select_clinical_features(
138
+ clinical_data,
139
+ trait,
140
+ age_col=age_col,
141
+ gender_col=gender_col
142
+ )
143
+
144
+ # 2. Normalize gene symbols in the genetic data and save the result
145
+ normalized_gene_data = normalize_gene_symbols_in_index(genetic_data)
146
+ normalized_gene_data.to_csv(out_gene_data_file)
147
+
148
+ # 3. Link clinical and genetic data on sample IDs
149
+ linked_data = selected_clinical_df.join(normalized_gene_data.T, how='inner')
150
+
151
+ # 4. Handle missing values
152
+ linked_data = handle_missing_values(linked_data, trait)
153
+
154
+ # 5. Determine whether the trait (and other features) are severely biased; remove biased age or gender if needed
155
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
156
+
157
+ # 6. Final validation and save metadata
158
+ is_usable = validate_and_save_cohort_info(
159
+ is_final=True,
160
+ cohort="TCGA",
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="Standard STAD pipeline complete."
167
+ )
168
+
169
+ # 7. If usable, save the fully linked and processed data
170
+ if is_usable:
171
+ linked_data.to_csv(out_data_file)
p1/preprocess/Testicular_Cancer/cohort_info.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"GSE62523": {"is_usable": false, "is_gene_available": true, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}, "GSE42647": {"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}, "TCGA": {"is_usable": false, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": true, "has_age": false, "has_gender": false, "sample_size": 156, "note": "Standard STAD pipeline complete."}}
p1/preprocess/Thymoma/GSE42977.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:292745155401b16941bd7e6f2ccc1082deeac09b3dd619d38e01ed63455b4b7a
3
+ size 24576654
p1/preprocess/Thymoma/clinical_data/GSE131027.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ GSM3759992,GSM3759993,GSM3759994,GSM3759995,GSM3759996,GSM3759997,GSM3759998,GSM3759999,GSM3760000,GSM3760001,GSM3760002,GSM3760003,GSM3760004,GSM3760005,GSM3760006,GSM3760007,GSM3760008,GSM3760009,GSM3760010,GSM3760011,GSM3760012,GSM3760013,GSM3760014,GSM3760015,GSM3760016,GSM3760017,GSM3760018,GSM3760019,GSM3760020,GSM3760021,GSM3760022,GSM3760023,GSM3760024,GSM3760025,GSM3760026,GSM3760027,GSM3760028,GSM3760029,GSM3760030,GSM3760031,GSM3760032,GSM3760033,GSM3760034,GSM3760035,GSM3760036,GSM3760037,GSM3760038,GSM3760039,GSM3760040,GSM3760041,GSM3760042,GSM3760043,GSM3760044,GSM3760045,GSM3760046,GSM3760047,GSM3760048,GSM3760049,GSM3760050,GSM3760051,GSM3760052,GSM3760053,GSM3760054,GSM3760055,GSM3760056,GSM3760057,GSM3760058,GSM3760059,GSM3760060,GSM3760061,GSM3760062,GSM3760063,GSM3760064,GSM3760065,GSM3760066,GSM3760067,GSM3760068,GSM3760069,GSM3760070,GSM3760071,GSM3760072,GSM3760073,GSM3760074,GSM3760075,GSM3760076,GSM3760077,GSM3760078,GSM3760079,GSM3760080,GSM3760081,GSM3760082,GSM3760083
2
+ 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
p1/preprocess/Thymoma/clinical_data/GSE42977.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ GSM1054230,GSM1054231,GSM1054232,GSM1054233,GSM1054234,GSM1054235,GSM1054236,GSM1054237,GSM1054238,GSM1054239,GSM1054240,GSM1054241,GSM1054242,GSM1054243,GSM1054244,GSM1054245,GSM1054246,GSM1054247,GSM1054248,GSM1054249,GSM1054250,GSM1054251,GSM1054252,GSM1054253,GSM1054254,GSM1054255,GSM1054256,GSM1054257,GSM1054258,GSM1054259,GSM1054260,GSM1054261,GSM1054262,GSM1054263,GSM1054264,GSM1054265,GSM1054266,GSM1054267,GSM1054268,GSM1054269,GSM1054270,GSM1054271,GSM1054272,GSM1054273,GSM1054274,GSM1054275,GSM1054276,GSM1054277,GSM1054278,GSM1054279,GSM1054280,GSM1054281,GSM1054282,GSM1054283,GSM1054284,GSM1054285,GSM1054286,GSM1054287,GSM1054288,GSM1054289,GSM1054290,GSM1054291,GSM1054292,GSM1054293,GSM1054294,GSM1054295,GSM1054296,GSM1054297,GSM1054298,GSM1054299,GSM1054300,GSM1054301,GSM1054302,GSM1054303,GSM1054304,GSM1054305,GSM1054306,GSM1054307,GSM1054308,GSM1054309,GSM1054310,GSM1054311,GSM1054312,GSM1054313,GSM1054314,GSM1054315,GSM1054316,GSM1054317,GSM1054318,GSM1054319,GSM1054320,GSM1054321,GSM1054322,GSM1054323,GSM1054324,GSM1054325,GSM1054326,GSM1054327,GSM1054328,GSM1054329,GSM1054330,GSM1054331,GSM1054332,GSM1054333,GSM1054334,GSM1054335,GSM1054336,GSM1054337,GSM1054338,GSM1054339,GSM1054340,GSM1054341,GSM1054342,GSM1054343,GSM1054344,GSM1054345,GSM1054346
2
+ 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
p1/preprocess/Thymoma/code/GSE131027.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Thymoma"
6
+ cohort = "GSE131027"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Thymoma"
10
+ in_cohort_dir = "../DATA/GEO/Thymoma/GSE131027"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Thymoma/GSE131027.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Thymoma/gene_data/GSE131027.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Thymoma/clinical_data/GSE131027.csv"
16
+ json_path = "./output/preprocess/1/Thymoma/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Decide whether gene expression data is available
37
+ is_gene_available = True # Based on the series description focusing on "expression features"
38
+
39
+ # 2. Check the availability of trait, age, and gender
40
+ # From the sample characteristics, we see key=1 contains "cancer: Thymoma" among other types.
41
+ # Hence trait data is available at row=1. There's no mention of age or gender keys.
42
+ trait_row = 1
43
+ age_row = None
44
+ gender_row = None
45
+
46
+ # 2.2 Define data type conversion functions
47
+ def convert_trait(value: str):
48
+ parts = value.split(':', 1)
49
+ if len(parts) < 2:
50
+ return None
51
+ label = parts[1].strip().lower()
52
+ # Convert "Thymoma" to 1, everything else to 0
53
+ return 1 if "thymoma" in label else 0
54
+
55
+ def convert_age(value: str):
56
+ # No age data available, return None
57
+ return None
58
+
59
+ def convert_gender(value: str):
60
+ # No gender data available, return None
61
+ return None
62
+
63
+ # 3. Conduct initial filtering and save metadata
64
+ is_trait_available = (trait_row is not None)
65
+ pass_filter = validate_and_save_cohort_info(
66
+ is_final=False,
67
+ cohort=cohort,
68
+ info_path=json_path,
69
+ is_gene_available=is_gene_available,
70
+ is_trait_available=is_trait_available
71
+ )
72
+
73
+ # 4. Extract clinical features only if trait data is available and we have not filtered out
74
+ if (not pass_filter) and is_trait_available:
75
+ selected_clinical_df = geo_select_clinical_features(
76
+ clinical_data,
77
+ trait=trait,
78
+ trait_row=trait_row,
79
+ convert_trait=convert_trait,
80
+ age_row=age_row,
81
+ convert_age=convert_age,
82
+ gender_row=gender_row,
83
+ convert_gender=convert_gender
84
+ )
85
+ preview = preview_df(selected_clinical_df, n=5)
86
+ print(preview)
87
+ selected_clinical_df.to_csv(out_clinical_data_file, index=False)
88
+ # STEP3
89
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
90
+ gene_data = get_genetic_data(matrix_file)
91
+
92
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
93
+ print(gene_data.index[:20])
94
+ # These identifiers (e.g., "1007_s_at", "1053_at", etc.) are Affymetrix probe set IDs, not human gene symbols.
95
+ # Therefore, they require mapping to official gene symbols.
96
+
97
+ requires_gene_mapping = True
98
+ # STEP5
99
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
100
+ gene_annotation = get_gene_annotation(soft_file)
101
+
102
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
103
+ print("Gene annotation preview:")
104
+ print(preview_df(gene_annotation))
105
+ # STEP6: Gene Identifier Mapping
106
+
107
+ # 1. The gene annotation DataFrame has the Affymetrix probe identifiers in column 'ID', which matches the index of gene_data.
108
+ # The corresponding human gene symbols are in the column 'Gene Symbol'.
109
+
110
+ # 2. Extract the two columns to get a mapping between probe IDs and gene symbols
111
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')
112
+
113
+ # 3. Convert probe-level expression data to gene-level expression data using the many-to-many mapping approach
114
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
115
+ # STEP7
116
+
117
+ import pandas as pd
118
+
119
+ # Check if clinical data (and thus the trait) was actually extracted in a previous step
120
+ # by testing whether "selected_clinical_df" exists.
121
+ try:
122
+ selected_clinical_df
123
+ trait_data_available = True
124
+ except NameError:
125
+ trait_data_available = False
126
+
127
+ if not trait_data_available:
128
+ # Since there's no clinical DataFrame, we finalize the dataset as unusable for trait analysis
129
+ # (missing trait), and skip further processing.
130
+ empty_df = pd.DataFrame()
131
+ # Mark trait as biased (or simply unusable) to ensure the final validation flags it as not usable
132
+ is_trait_biased = True
133
+ validate_and_save_cohort_info(
134
+ is_final=True,
135
+ cohort=cohort,
136
+ info_path=json_path,
137
+ is_gene_available=True, # We do have gene data, but no trait data
138
+ is_trait_available=False,
139
+ is_biased=is_trait_biased,
140
+ df=empty_df,
141
+ note="No trait data found; dataset is not usable for trait-based analysis."
142
+ )
143
+ else:
144
+ # 1. Normalize the obtained gene data and save
145
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
146
+ normalized_gene_data.to_csv(out_gene_data_file)
147
+
148
+ # 2. Link clinical and gene expression data on sample IDs
149
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
150
+
151
+ # 3. Handle missing values systematically using the trait column name in the 'trait' variable
152
+ linked_data = handle_missing_values(linked_data, trait)
153
+
154
+ # 4. Check for biased features (trait, age, gender) using the same trait column name
155
+ is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
156
+
157
+ # 5. Final quality validation and record metadata
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_trait_biased,
165
+ df=linked_data,
166
+ note=f"Preprocessed with trait column named '{trait}'."
167
+ )
168
+
169
+ # 6. If usable, save linked data
170
+ if is_usable:
171
+ linked_data.to_csv(out_data_file, index=True)
p1/preprocess/Thymoma/code/GSE29695.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Thymoma"
6
+ cohort = "GSE29695"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Thymoma"
10
+ in_cohort_dir = "../DATA/GEO/Thymoma/GSE29695"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Thymoma/GSE29695.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Thymoma/gene_data/GSE29695.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Thymoma/clinical_data/GSE29695.csv"
16
+ json_path = "./output/preprocess/1/Thymoma/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1) Gene Expression Data Availability
37
+ is_gene_available = True # from background info (whole genome gene expression analysis mentioned)
38
+
39
+ # 2) Variable Availability and Data Type Conversion
40
+ # Looking at the sample characteristics dictionary, we do not see any row that contains valid/variable
41
+ # trait data specific to "Thymoma" (all samples are thymoma-related; no variation is apparent),
42
+ # nor do we see 'age' or 'gender' information. Hence all are set to None.
43
+ trait_row = None
44
+ age_row = None
45
+ gender_row = None
46
+
47
+ # Define conversion functions (they won't be used here because all rows are None).
48
+ def convert_trait(x: str):
49
+ # No valid trait data available; return None.
50
+ return None
51
+
52
+ def convert_age(x: str):
53
+ # No valid age data available; return None.
54
+ return None
55
+
56
+ def convert_gender(x: str):
57
+ # No valid gender data available; return None.
58
+ return None
59
+
60
+ # 3) Save Metadata for Initial Filtering
61
+ is_trait_available = (trait_row is not None) # This will be False
62
+ validate_and_save_cohort_info(
63
+ is_final=False,
64
+ cohort=cohort,
65
+ info_path=json_path,
66
+ is_gene_available=is_gene_available,
67
+ is_trait_available=is_trait_available
68
+ )
69
+
70
+ # 4) Clinical Feature Extraction
71
+ # Since trait_row is None (trait not available), we skip clinical data extraction.
72
+ # STEP3
73
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
74
+ gene_data = get_genetic_data(matrix_file)
75
+
76
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
77
+ print(gene_data.index[:20])
78
+ # Based on the gene identifiers (ILMN_...), these are likely Illumina probe IDs instead of standard gene symbols.
79
+ # Thus, they will need to be mapped to gene symbols.
80
+
81
+ print("requires_gene_mapping = True")
82
+ # STEP5
83
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
84
+ gene_annotation = get_gene_annotation(soft_file)
85
+
86
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
87
+ print("Gene annotation preview:")
88
+ print(preview_df(gene_annotation))
89
+ # STEP: Gene Identifier Mapping
90
+
91
+ # 1. Identify the columns in gene_annotation that match the gene expression identifiers and the gene symbols
92
+ probe_id_col = "ID" # This corresponds to the ILMN_... ids, matching the row IDs in gene_data
93
+ gene_symbol_col = "Symbol" # This column holds the gene symbols
94
+
95
+ # 2. Extract the gene mapping dataframe using the library function
96
+ mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_id_col, gene_col=gene_symbol_col)
97
+
98
+ # 3. Convert probe-level data to gene-level data
99
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
100
+ # STEP7
101
+
102
+ import pandas as pd
103
+
104
+ # Check if clinical data (and thus the trait) was actually extracted in a previous step
105
+ # by testing whether "selected_clinical_df" exists.
106
+ try:
107
+ selected_clinical_df
108
+ trait_data_available = True
109
+ except NameError:
110
+ trait_data_available = False
111
+
112
+ if not trait_data_available:
113
+ # Since there's no clinical DataFrame, we finalize the dataset as unusable for trait analysis
114
+ # (missing trait), and skip further processing.
115
+ empty_df = pd.DataFrame()
116
+ # Mark trait as biased (or simply unusable) to ensure the final validation flags it as not usable
117
+ is_trait_biased = True
118
+ validate_and_save_cohort_info(
119
+ is_final=True,
120
+ cohort=cohort,
121
+ info_path=json_path,
122
+ is_gene_available=True, # We do have gene data, but no trait data
123
+ is_trait_available=False,
124
+ is_biased=is_trait_biased,
125
+ df=empty_df,
126
+ note="No trait data found; dataset is not usable for trait-based analysis."
127
+ )
128
+ else:
129
+ # 1. Normalize the obtained gene data and save
130
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
131
+ normalized_gene_data.to_csv(out_gene_data_file)
132
+
133
+ # 2. Link clinical and gene expression data on sample IDs
134
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
135
+
136
+ # 3. Handle missing values systematically using the trait column name in the 'trait' variable
137
+ linked_data = handle_missing_values(linked_data, trait)
138
+
139
+ # 4. Check for biased features (trait, age, gender) using the same trait column name
140
+ is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
141
+
142
+ # 5. Final quality validation and record metadata
143
+ is_usable = validate_and_save_cohort_info(
144
+ is_final=True,
145
+ cohort=cohort,
146
+ info_path=json_path,
147
+ is_gene_available=True,
148
+ is_trait_available=True,
149
+ is_biased=is_trait_biased,
150
+ df=linked_data,
151
+ note=f"Preprocessed with trait column named '{trait}'."
152
+ )
153
+
154
+ # 6. If usable, save linked data
155
+ if is_usable:
156
+ linked_data.to_csv(out_data_file, index=True)
p1/preprocess/Thymoma/code/GSE42977.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Thymoma"
6
+ cohort = "GSE42977"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Thymoma"
10
+ in_cohort_dir = "../DATA/GEO/Thymoma/GSE42977"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/1/Thymoma/GSE42977.csv"
14
+ out_gene_data_file = "./output/preprocess/1/Thymoma/gene_data/GSE42977.csv"
15
+ out_clinical_data_file = "./output/preprocess/1/Thymoma/clinical_data/GSE42977.csv"
16
+ json_path = "./output/preprocess/1/Thymoma/cohort_info.json"
17
+
18
+ # STEP1
19
+ from tools.preprocess import *
20
+ # 1. Identify the paths to the SOFT file and the matrix file
21
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
22
+
23
+ # 2. Read the matrix file to obtain background information and sample characteristics data
24
+ background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
25
+ clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
26
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
27
+
28
+ # 3. Obtain the sample characteristics dictionary from the clinical dataframe
29
+ sample_characteristics_dict = get_unique_values_by_row(clinical_data)
30
+
31
+ # 4. Explicitly print out all the background information and the sample characteristics dictionary
32
+ print("Background Information:")
33
+ print(background_info)
34
+ print("Sample Characteristics Dictionary:")
35
+ print(sample_characteristics_dict)
36
+ # 1. Gene Expression Data Availability
37
+ is_gene_available = True # Based on the "microarray analysis" mention
38
+
39
+ # 2. Variable Availability and Data Type Conversion
40
+ # From the sample characteristics, only one key (0) is present,
41
+ # which includes "tissue: Thymoma" among many other tissue types.
42
+ # Thus, "trait" data is available in row 0, but age and gender data
43
+ # are not provided.
44
+
45
+ trait_row = 0
46
+
47
+ def convert_trait(value: str) -> int:
48
+ # Extract the substring after the colon and convert to lowercase
49
+ val = value.split(':')[-1].strip().lower()
50
+ # Binary conversion: 1 if it's Thymoma (including "metastatic thymoma"), else 0
51
+ return 1 if "thymoma" in val else 0
52
+
53
+ age_row = None
54
+ convert_age = None # No age data found, so no conversion function needed
55
+
56
+ gender_row = None
57
+ convert_gender = None # No gender data found, so no conversion function needed
58
+
59
+ # 3. Initial Filtering and Saving Metadata
60
+ is_trait_available = (trait_row is not None)
61
+ is_usable = validate_and_save_cohort_info(
62
+ is_final=False,
63
+ cohort=cohort,
64
+ info_path=json_path,
65
+ is_gene_available=is_gene_available,
66
+ is_trait_available=is_trait_available
67
+ )
68
+
69
+ # 4. Clinical Feature Extraction (only if trait data is available)
70
+ if is_trait_available:
71
+ selected_clinical_df = geo_select_clinical_features(
72
+ clinical_df=clinical_data,
73
+ trait=trait,
74
+ trait_row=trait_row,
75
+ convert_trait=convert_trait,
76
+ age_row=age_row,
77
+ convert_age=convert_age,
78
+ gender_row=gender_row,
79
+ convert_gender=convert_gender
80
+ )
81
+ # Preview and save the clinical data
82
+ print(preview_df(selected_clinical_df, n=5))
83
+ selected_clinical_df.to_csv(out_clinical_data_file, index=False)
84
+ # STEP3
85
+ # 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
86
+ gene_data = get_genetic_data(matrix_file)
87
+
88
+ # 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
89
+ print(gene_data.index[:20])
90
+ # The gene identifiers shown (e.g., "ILMN_10000", "ILMN_100000") are Illumina probe IDs,
91
+ # not standard human gene symbols. They need to be mapped to gene symbols.
92
+
93
+ requires_gene_mapping = True
94
+ # STEP5
95
+ # 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
96
+ gene_annotation = get_gene_annotation(soft_file)
97
+
98
+ # 2. Use the 'preview_df' function from the library to preview the data and print out the results.
99
+ print("Gene annotation preview:")
100
+ print(preview_df(gene_annotation))
101
+ # STEP: Gene Identifier Mapping
102
+
103
+ # 1 & 2. Identify the columns in gene_annotation that correspond to the probe IDs and gene symbols.
104
+ # From the preview, 'ID' matches the ILMN_ identifiers (same as gene_data index),
105
+ # and 'Symbol' stores the gene symbols.
106
+ mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="Symbol")
107
+
108
+ # 3. Map the probe-level data to gene-level data by distributing probe expression values to mapped genes
109
+ gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
110
+
111
+ # Optionally, inspect the resulting gene_data
112
+ print("Gene data shape after mapping:", gene_data.shape)
113
+ print("First 5 gene symbols after mapping:", gene_data.index[:5].tolist())
114
+ # STEP7
115
+
116
+ import pandas as pd
117
+
118
+ # Check if clinical data (and thus the trait) was actually extracted in a previous step
119
+ # by testing whether "selected_clinical_df" exists.
120
+ try:
121
+ selected_clinical_df
122
+ trait_data_available = True
123
+ except NameError:
124
+ trait_data_available = False
125
+
126
+ if not trait_data_available:
127
+ # Since there's no clinical DataFrame, we finalize the dataset as unusable for trait analysis
128
+ # (missing trait), and skip further processing.
129
+ empty_df = pd.DataFrame()
130
+ # Mark trait as biased (or simply unusable) to ensure the final validation flags it as not usable
131
+ is_trait_biased = True
132
+ validate_and_save_cohort_info(
133
+ is_final=True,
134
+ cohort=cohort,
135
+ info_path=json_path,
136
+ is_gene_available=True, # We do have gene data, but no trait data
137
+ is_trait_available=False,
138
+ is_biased=is_trait_biased,
139
+ df=empty_df,
140
+ note="No trait data found; dataset is not usable for trait-based analysis."
141
+ )
142
+ else:
143
+ # 1. Normalize the obtained gene data and save
144
+ normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
145
+ normalized_gene_data.to_csv(out_gene_data_file)
146
+
147
+ # 2. Link clinical and gene expression data on sample IDs
148
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
149
+
150
+ # 3. Handle missing values systematically using the trait column name in the 'trait' variable
151
+ linked_data = handle_missing_values(linked_data, trait)
152
+
153
+ # 4. Check for biased features (trait, age, gender) using the same trait column name
154
+ is_trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
155
+
156
+ # 5. Final quality validation and record metadata
157
+ is_usable = validate_and_save_cohort_info(
158
+ is_final=True,
159
+ cohort=cohort,
160
+ info_path=json_path,
161
+ is_gene_available=True,
162
+ is_trait_available=True,
163
+ is_biased=is_trait_biased,
164
+ df=linked_data,
165
+ note=f"Preprocessed with trait column named '{trait}'."
166
+ )
167
+
168
+ # 6. If usable, save linked data
169
+ if is_usable:
170
+ linked_data.to_csv(out_data_file, index=True)
p1/preprocess/Thymoma/code/TCGA.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Thymoma"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/1/Thymoma/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/1/Thymoma/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/1/Thymoma/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/1/Thymoma/cohort_info.json"
15
+
16
+ # Step 1: Initial Data Loading
17
+
18
+ import os
19
+ import pandas as pd
20
+
21
+ # List subdirectories (as already given in the environment)
22
+ subdirectories = [
23
+ 'TCGA-LGG', 'CrawlData.ipynb', '.DS_Store',
24
+ 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
25
+ 'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)',
26
+ 'TCGA_Thymoma_(THYM)', 'TCGA_Testicular_Cancer_(TGCT)',
27
+ 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
28
+ 'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)',
29
+ 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)', 'TCGA_Pancreatic_Cancer_(PAAD)',
30
+ 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
31
+ 'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)',
32
+ 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)', 'TCGA_Lung_Cancer_(LUNG)',
33
+ 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
34
+ 'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)',
35
+ 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)', 'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)',
36
+ 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
37
+ 'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)',
38
+ 'TCGA_Endometrioid_Cancer_(UCEC)', 'TCGA_Colon_and_Rectal_Cancer_(COADREAD)',
39
+ 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
40
+ 'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)',
41
+ 'TCGA_Bile_Duct_Cancer_(CHOL)', 'TCGA_Adrenocortical_Cancer_(ACC)',
42
+ 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
43
+ ]
44
+
45
+ # We want to find a folder relevant to "Thymoma"
46
+ trait_synonyms = ["thymoma", "thym"]
47
+
48
+ relevant_folder = None
49
+
50
+ for folder in subdirectories:
51
+ folder_lower = folder.lower()
52
+ if any(syn in folder_lower for syn in trait_synonyms):
53
+ relevant_folder = folder
54
+ break
55
+
56
+ if not relevant_folder:
57
+ # No suitable directory found, mark as skipped
58
+ _ = validate_and_save_cohort_info(
59
+ is_final=False,
60
+ cohort="TCGA",
61
+ info_path=json_path,
62
+ is_gene_available=False,
63
+ is_trait_available=False
64
+ )
65
+ print(f"No suitable directory found for trait {trait}. Skipping this trait.")
66
+ else:
67
+ # If a relevant directory is found, load the files
68
+ folder_path = os.path.join(tcga_root_dir, relevant_folder)
69
+ clinical_file, genetic_file = tcga_get_relevant_filepaths(folder_path)
70
+
71
+ clinical_data = pd.read_csv(clinical_file, index_col=0, sep='\t')
72
+ genetic_data = pd.read_csv(genetic_file, index_col=0, sep='\t')
73
+
74
+ print("Clinical data columns:", clinical_data.columns.tolist())
75
+ candidate_age_cols = ["age_at_initial_pathologic_diagnosis", "days_to_birth"]
76
+ candidate_gender_cols = ["gender"]
77
+
78
+ print(f"candidate_age_cols = {candidate_age_cols}")
79
+ print(f"candidate_gender_cols = {candidate_gender_cols}")
80
+
81
+ if candidate_age_cols:
82
+ preview_age = preview_df(clinical_data[candidate_age_cols], n=5)
83
+ print("Age Columns Preview (first 5 rows):")
84
+ print(preview_age)
85
+
86
+ if candidate_gender_cols:
87
+ preview_gender = preview_df(clinical_data[candidate_gender_cols], n=5)
88
+ print("Gender Columns Preview (first 5 rows):")
89
+ print(preview_gender)
90
+ # Based on the previews, 'age_at_initial_pathologic_diagnosis' directly provides ages in years,
91
+ # and 'gender' seems to consistently provide gender information.
92
+
93
+ age_col = "age_at_initial_pathologic_diagnosis"
94
+ gender_col = "gender"
95
+
96
+ print("Chosen age column:", age_col)
97
+ print("Chosen gender column:", gender_col)
98
+ # 1. Extract and standardize the clinical features
99
+ selected_clinical_df = tcga_select_clinical_features(
100
+ clinical_data,
101
+ trait,
102
+ age_col=age_col,
103
+ gender_col=gender_col
104
+ )
105
+
106
+ # 2. Normalize gene symbols in the genetic data and save the result
107
+ normalized_gene_data = normalize_gene_symbols_in_index(genetic_data)
108
+ normalized_gene_data.to_csv(out_gene_data_file)
109
+
110
+ # 3. Link clinical and genetic data on sample IDs
111
+ linked_data = selected_clinical_df.join(normalized_gene_data.T, how='inner')
112
+
113
+ # 4. Handle missing values
114
+ linked_data = handle_missing_values(linked_data, trait)
115
+
116
+ # 5. Determine whether the trait (and other features) are severely biased; remove biased age or gender if needed
117
+ is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
118
+
119
+ # 6. Final validation and save metadata
120
+ is_usable = validate_and_save_cohort_info(
121
+ is_final=True,
122
+ cohort="TCGA",
123
+ info_path=json_path,
124
+ is_gene_available=True,
125
+ is_trait_available=True,
126
+ is_biased=is_biased,
127
+ df=linked_data,
128
+ note="Standard STAD pipeline complete."
129
+ )
130
+
131
+ # 7. If usable, save the fully linked and processed data
132
+ if is_usable:
133
+ linked_data.to_csv(out_data_file)
p1/preprocess/Thymoma/cohort_info.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"GSE42977": {"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": 117, "note": "Preprocessed with trait column named 'Thymoma'."}, "GSE29695": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": "No trait data found; dataset is not usable for trait-based analysis."}, "GSE131027": {"is_usable": false, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": true, "has_age": false, "has_gender": false, "sample_size": 92, "note": "Preprocessed with trait column named 'Thymoma'."}, "TCGA": {"is_usable": false, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": true, "has_age": true, "has_gender": true, "sample_size": 122, "note": "Standard STAD pipeline complete."}}
p1/preprocess/Thymoma/gene_data/GSE131027.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a8582008fe6fc5b90879aea7d12ca4ea58cc0bbe03209acb333425d229be6e33
3
+ size 24379939
p1/preprocess/Thymoma/gene_data/GSE42977.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee4aba8ed3943a5e7f98022325bcf90252f7fb056f558e0e99dd7f361acd56f8
3
+ size 24576182
p1/preprocess/Thyroid_Cancer/GSE104005.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Thyroid_Cancer/GSE151179.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d8a00b1cdaa951ccf347dc554e3e8b1ea163868f9950d06ffc59a67bbad5128
3
+ size 18389228
p1/preprocess/Thyroid_Cancer/GSE58689.csv ADDED
The diff for this file is too large to render. See raw diff
 
p1/preprocess/Thyroid_Cancer/GSE80022.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b9a4a1510359a0679f76dd7798a706daeecc1fbfa0481d594dfd91d016f9dd7e
3
+ size 14562176
p1/preprocess/Thyroid_Cancer/GSE82208.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0b37d20eadfbf260e3ad50b28e2cbd9ccacc6a3a80cb45ffd0898aeb6b52b834
3
+ size 13702981
p1/preprocess/Thyroid_Cancer/clinical_data/GSE104005.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ GSM2787612,GSM2787613,GSM2787614,GSM2787615,GSM2787616,GSM2787617,GSM2787618,GSM2787619,GSM2787620,GSM2787621,GSM2787622,GSM2787623,GSM2787624,GSM2787625,GSM2787626,GSM2787627,GSM2787628,GSM2787629,GSM2787630,GSM2787631,GSM2787632,GSM2787633,GSM2787634,GSM2787635,GSM2787636,GSM2787637,GSM2787638,GSM2787639,GSM2787640,GSM2787641,GSM2787642,GSM2787643,GSM2787644,GSM2787645
2
+ 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0
3
+ 74.0,74.0,67.0,72.0,74.0,38.0,50.0,41.0,51.0,73.0,52.0,48.0,59.0,58.0,39.0,37.0,33.0,36.0,70.0,26.0,46.0,57.0,44.0,44.0,35.0,42.0,61.0,38.0,35.0,35.0,38.0,49.0,52.0,51.0
4
+ 1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0
p1/preprocess/Thyroid_Cancer/clinical_data/GSE104006.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ GSM2787513,GSM2787514,GSM2787515,GSM2787516,GSM2787517,GSM2787518,GSM2787519,GSM2787520,GSM2787521,GSM2787522,GSM2787523,GSM2787524,GSM2787525,GSM2787526,GSM2787527,GSM2787528,GSM2787529,GSM2787530,GSM2787531,GSM2787532,GSM2787533,GSM2787534,GSM2787535,GSM2787536,GSM2787537,GSM2787538,GSM2787539,GSM2787540,GSM2787541,GSM2787542,GSM2787543,GSM2787544,GSM2787545,GSM2787546
2
+ 1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0
3
+ 74.0,74.0,72.0,74.0,38.0,50.0,41.0,51.0,73.0,52.0,48.0,59.0,58.0,39.0,37.0,33.0,36.0,70.0,26.0,46.0,57.0,44.0,35.0,42.0,47.0,61.0,38.0,35.0,35.0,38.0,49.0,56.0,52.0,51.0
4
+ 1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0
p1/preprocess/Thyroid_Cancer/clinical_data/GSE107754.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ GSM2878070,GSM2878071,GSM2878072,GSM2878073,GSM2878074,GSM2878075,GSM2878076,GSM2878077,GSM2878078,GSM2878079,GSM2878080,GSM2878081,GSM2878082,GSM2891194,GSM2891195,GSM2891196,GSM2891197,GSM2891198,GSM2891199,GSM2891200,GSM2891201,GSM2891202,GSM2891203,GSM2891204,GSM2891205,GSM2891206,GSM2891207,GSM2891208,GSM2891209,GSM2891210,GSM2891211,GSM2891212,GSM2891213,GSM2891214,GSM2891215,GSM2891216,GSM2891217,GSM2891218,GSM2891219,GSM2891220,GSM2891221,GSM2891222,GSM2891223,GSM2891224,GSM2891225,GSM2891226,GSM2891227,GSM2891228,GSM2891229,GSM2891230,GSM2891231,GSM2891232,GSM2891233,GSM2891234,GSM2891235,GSM2891236,GSM2891237,GSM2891238,GSM2891239,GSM2891240,GSM2891241,GSM2891242,GSM2891243,GSM2891244,GSM2891245,GSM2891246,GSM2891247,GSM2891248,GSM2891249,GSM2891250,GSM2891251,GSM2891252,GSM2891253,GSM2891254,GSM2891255,GSM2891256,GSM2891257,GSM2891258,GSM2891259,GSM2891260,GSM2891261,GSM2891262,GSM2891263,GSM2891264
2
+ 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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
3
+ 1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0