Liu-Hy commited on
Commit
d5514d2
·
verified ·
1 Parent(s): f2fc1fc

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 +3 -0
  2. p3/preprocess/Kidney_Papillary_Cell_Carcinoma/GSE19949.csv +3 -0
  3. p3/preprocess/Lower_Grade_Glioma/GSE107850.csv +3 -0
  4. p3/preprocess/Lupus_(Systemic_Lupus_Erythematosus)/GSE112943.csv +3 -0
  5. p3/preprocess/Retinoblastoma/code/GSE58780.py +160 -0
  6. p3/preprocess/Retinoblastoma/code/GSE59983.py +155 -0
  7. p3/preprocess/Retinoblastoma/code/GSE63529.py +132 -0
  8. p3/preprocess/Retinoblastoma/code/GSE68950.py +117 -0
  9. p3/preprocess/Retinoblastoma/code/TCGA.py +96 -0
  10. p3/preprocess/Retinoblastoma/gene_data/GSE110811.csv +1 -0
  11. p3/preprocess/Retinoblastoma/gene_data/GSE208143.csv +0 -0
  12. p3/preprocess/Retinoblastoma/gene_data/GSE26805.csv +0 -0
  13. p3/preprocess/Retinoblastoma/gene_data/GSE29683.csv +1 -0
  14. p3/preprocess/Retinoblastoma/gene_data/GSE58780.csv +0 -0
  15. p3/preprocess/Retinoblastoma/gene_data/GSE63529.csv +0 -0
  16. p3/preprocess/Rheumatoid_Arthritis/GSE121894.csv +0 -0
  17. p3/preprocess/Rheumatoid_Arthritis/GSE143153.csv +0 -0
  18. p3/preprocess/Rheumatoid_Arthritis/GSE186963.csv +0 -0
  19. p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE121894.csv +2 -0
  20. p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE143153.csv +4 -0
  21. p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE176440.csv +2 -0
  22. p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE186963.csv +2 -0
  23. p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE224330.csv +4 -0
  24. p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE224842.csv +2 -0
  25. p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE236924.csv +2 -0
  26. p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE42842.csv +3 -0
  27. p3/preprocess/Rheumatoid_Arthritis/code/GSE121894.py +168 -0
  28. p3/preprocess/Rheumatoid_Arthritis/code/GSE140161.py +168 -0
  29. p3/preprocess/Rheumatoid_Arthritis/code/GSE143153.py +185 -0
  30. p3/preprocess/Rheumatoid_Arthritis/code/GSE176440.py +169 -0
  31. p3/preprocess/Rheumatoid_Arthritis/code/GSE186963.py +175 -0
  32. p3/preprocess/Rheumatoid_Arthritis/code/GSE224330.py +472 -0
  33. p3/preprocess/Rheumatoid_Arthritis/code/GSE224842.py +172 -0
  34. p3/preprocess/Rheumatoid_Arthritis/code/GSE236924.py +161 -0
  35. p3/preprocess/Rheumatoid_Arthritis/code/GSE42842.py +155 -0
  36. p3/preprocess/Rheumatoid_Arthritis/code/GSE97475.py +120 -0
  37. p3/preprocess/Rheumatoid_Arthritis/code/TCGA.py +34 -0
  38. p3/preprocess/Rheumatoid_Arthritis/cohort_info.json +1 -0
  39. p3/preprocess/Rheumatoid_Arthritis/gene_data/GSE121894.csv +0 -0
  40. p3/preprocess/Rheumatoid_Arthritis/gene_data/GSE143153.csv +0 -0
  41. p3/preprocess/Rheumatoid_Arthritis/gene_data/GSE186963.csv +0 -0
  42. p3/preprocess/Rheumatoid_Arthritis/gene_data/GSE224330.csv +1 -0
  43. p3/preprocess/Rheumatoid_Arthritis/gene_data/GSE224842.csv +0 -0
  44. p3/preprocess/Sarcoma/GSE159848.csv +0 -0
  45. p3/preprocess/Sarcoma/clinical_data/GSE118336.csv +2 -0
  46. p3/preprocess/Sarcoma/clinical_data/GSE133228.csv +4 -0
  47. p3/preprocess/Sarcoma/clinical_data/GSE142162.csv +4 -0
  48. p3/preprocess/Sarcoma/clinical_data/GSE159847.csv +4 -0
  49. p3/preprocess/Sarcoma/clinical_data/GSE159848.csv +4 -0
  50. p3/preprocess/Sarcoma/clinical_data/GSE162785.csv +2 -0
.gitattributes CHANGED
@@ -1882,3 +1882,6 @@ p3/preprocess/lower_grade_glioma_and_glioblastoma/gene_data/GSE35158.csv filter=
1882
  p3/preprocess/lower_grade_glioma_and_glioblastoma/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1883
  p3/preprocess/Hypertrophic_Cardiomyopathy/GSE36961.csv filter=lfs diff=lfs merge=lfs -text
1884
  p3/preprocess/Kidney_Clear_Cell_Carcinoma/GSE119958.csv filter=lfs diff=lfs merge=lfs -text
 
 
 
 
1882
  p3/preprocess/lower_grade_glioma_and_glioblastoma/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
1883
  p3/preprocess/Hypertrophic_Cardiomyopathy/GSE36961.csv filter=lfs diff=lfs merge=lfs -text
1884
  p3/preprocess/Kidney_Clear_Cell_Carcinoma/GSE119958.csv filter=lfs diff=lfs merge=lfs -text
1885
+ p3/preprocess/Kidney_Papillary_Cell_Carcinoma/GSE19949.csv filter=lfs diff=lfs merge=lfs -text
1886
+ p3/preprocess/Lower_Grade_Glioma/GSE107850.csv filter=lfs diff=lfs merge=lfs -text
1887
+ p3/preprocess/Lupus_(Systemic_Lupus_Erythematosus)/GSE112943.csv filter=lfs diff=lfs merge=lfs -text
p3/preprocess/Kidney_Papillary_Cell_Carcinoma/GSE19949.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:633c345f5e6e42cf13d32490fa18bf65e3e46c642ff5e202b46d4ea9c9cbf398
3
+ size 32430679
p3/preprocess/Lower_Grade_Glioma/GSE107850.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6e59635445960e7b620f444d95bfe9c178a939ade0a22fffdeb698b505cba1f2
3
+ size 47675256
p3/preprocess/Lupus_(Systemic_Lupus_Erythematosus)/GSE112943.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d4e43b7dfe5fa8de7c7ccc232ddd1da433b93feb1359dfc6cabbd5c56f276e8
3
+ size 12112382
p3/preprocess/Retinoblastoma/code/GSE58780.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Retinoblastoma"
6
+ cohort = "GSE58780"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Retinoblastoma"
10
+ in_cohort_dir = "../DATA/GEO/Retinoblastoma/GSE58780"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Retinoblastoma/GSE58780.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Retinoblastoma/gene_data/GSE58780.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Retinoblastoma/clinical_data/GSE58780.csv"
16
+ json_path = "./output/preprocess/3/Retinoblastoma/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+ print("Background Information:")
24
+ print(background_info)
25
+ print("\nSample Characteristics:")
26
+
27
+ # Get dictionary of unique values per row
28
+ unique_values_dict = get_unique_values_by_row(clinical_data)
29
+ for row, values in unique_values_dict.items():
30
+ print(f"\n{row}:")
31
+ print(values)
32
+ # 1. Gene Expression Data Analysis
33
+ # Based on background info mentioning Affymetrix array and gene expression data
34
+ is_gene_available = True
35
+
36
+ # 2.1 Data Availability
37
+ # Trait can be determined from tissue field (row 2)
38
+ trait_row = 2
39
+ # Age and gender not available in sample characteristics
40
+ age_row = None
41
+ gender_row = None
42
+
43
+ # 2.2 Data Type Conversion Functions
44
+ def convert_trait(value: str) -> int:
45
+ """Convert tissue type to binary (0 for control, 1 for retinoblastoma)"""
46
+ if not value or ':' not in value:
47
+ return None
48
+ tissue = value.split(':')[1].strip().lower()
49
+ if 'retinoblastoma' in tissue:
50
+ return 1
51
+ elif 'fetal retina' in tissue:
52
+ return 0
53
+ return None
54
+
55
+ def convert_age(value: str) -> float:
56
+ return None
57
+
58
+ def convert_gender(value: str) -> int:
59
+ return None
60
+
61
+ # 3. Save Initial Metadata
62
+ # Trait data is available since trait_row is not None
63
+ is_trait_available = trait_row is not None
64
+ validate_and_save_cohort_info(is_final=False,
65
+ cohort=cohort,
66
+ info_path=json_path,
67
+ is_gene_available=is_gene_available,
68
+ is_trait_available=is_trait_available)
69
+
70
+ # 4. Clinical Feature Extraction
71
+ clinical_features = geo_select_clinical_features(clinical_df=clinical_data,
72
+ trait=trait,
73
+ trait_row=trait_row,
74
+ convert_trait=convert_trait)
75
+
76
+ # Preview and save clinical features
77
+ print("Clinical features preview:")
78
+ print(preview_df(clinical_features))
79
+
80
+ # Save clinical data
81
+ os.makedirs(os.path.dirname(out_clinical_data_file), exist_ok=True)
82
+ clinical_features.to_csv(out_clinical_data_file)
83
+ # Get gene expression data from matrix file
84
+ genetic_data = get_genetic_data(matrix_file_path)
85
+
86
+ # Examine data structure
87
+ print("Data structure and head:")
88
+ print(genetic_data.head())
89
+
90
+ print("\nShape:", genetic_data.shape)
91
+
92
+ print("\nFirst 20 row IDs (gene/probe identifiers):")
93
+ print(list(genetic_data.index)[:20])
94
+
95
+ # Get a few column names to verify sample IDs
96
+ print("\nFirst 5 column names:")
97
+ print(list(genetic_data.columns)[:5])
98
+ # Checking the format of gene identifiers, it appears they are probe identifiers with "_at" suffix
99
+ # This indicates these are probe IDs from an Affymetrix microarray rather than standard gene symbols
100
+ # We will need to map these probe IDs to human gene symbols
101
+ requires_gene_mapping = True
102
+ # Extract gene annotation data
103
+ gene_annotation = get_gene_annotation(soft_file_path)
104
+
105
+ # Display column names and preview data
106
+ print("Column names:")
107
+ print(gene_annotation.columns)
108
+
109
+ print("\nPreview of gene annotation data:")
110
+ print(preview_df(gene_annotation))
111
+ # 1. In gene expression data we see IDs like "100009676_at", which matches the "ID" column in annotation
112
+ # Description field contains gene names that we can extract symbols from
113
+
114
+ # 2. Extract mapping between probe IDs and gene symbols
115
+ mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Description')
116
+
117
+ # 3. Apply gene mapping to convert probe data to gene expression data
118
+ gene_data = apply_gene_mapping(genetic_data, mapping_df)
119
+
120
+ # Preview converted gene data
121
+ print("Gene expression data shape after mapping:", gene_data.shape)
122
+ print("\nPreview of gene expression data:")
123
+ print(gene_data.head())
124
+
125
+ # Save gene data
126
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
127
+ gene_data.to_csv(out_gene_data_file)
128
+ # Reload clinical data that was processed earlier
129
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
130
+
131
+ # 1. Normalize gene symbols
132
+ gene_data = normalize_gene_symbols_in_index(gene_data)
133
+ gene_data.to_csv(out_gene_data_file)
134
+
135
+ # 2. Link clinical and genetic data
136
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, gene_data)
137
+
138
+ # 3. Handle missing values systematically
139
+ linked_data = handle_missing_values(linked_data, trait)
140
+
141
+ # 4. Check for bias in trait and demographic features
142
+ trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
143
+
144
+ # 5. Final validation and information saving
145
+ note = "Dataset contains gene expression data from primary human retinoblastoma samples profiled with Affymetrix microarray."
146
+ is_usable = validate_and_save_cohort_info(
147
+ is_final=True,
148
+ cohort=cohort,
149
+ info_path=json_path,
150
+ is_gene_available=True,
151
+ is_trait_available=True,
152
+ is_biased=trait_biased,
153
+ df=linked_data,
154
+ note=note
155
+ )
156
+
157
+ # 6. Save linked data only if usable
158
+ if is_usable:
159
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
160
+ linked_data.to_csv(out_data_file)
p3/preprocess/Retinoblastoma/code/GSE59983.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Retinoblastoma"
6
+ cohort = "GSE59983"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Retinoblastoma"
10
+ in_cohort_dir = "../DATA/GEO/Retinoblastoma/GSE59983"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Retinoblastoma/GSE59983.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Retinoblastoma/gene_data/GSE59983.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Retinoblastoma/clinical_data/GSE59983.csv"
16
+ json_path = "./output/preprocess/3/Retinoblastoma/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+ print("Background Information:")
24
+ print(background_info)
25
+ print("\nSample Characteristics:")
26
+
27
+ # Get dictionary of unique values per row
28
+ unique_values_dict = get_unique_values_by_row(clinical_data)
29
+ for row, values in unique_values_dict.items():
30
+ print(f"\n{row}:")
31
+ print(values)
32
+ # 1. Gene Expression Data Availability
33
+ # Yes, this dataset contains gene expression data (Affymetrix microarray)
34
+ is_gene_available = True
35
+
36
+ # 2.1 Data Availability
37
+ trait_row = 0 # "tissue: primary Rb tissue" indicates these are retinoblastoma samples
38
+ age_row = None # Age not available in sample characteristics
39
+ gender_row = None # Gender not available in sample characteristics
40
+
41
+ # 2.2 Data Type Conversion Functions
42
+ def convert_trait(value: str) -> int:
43
+ """Convert trait value to binary: 1 for retinoblastoma tissue, 0 for normal"""
44
+ if not value or ':' not in value:
45
+ return None
46
+ value = value.split(':')[1].strip().lower()
47
+ if 'primary rb tissue' in value:
48
+ return 1
49
+ return 0
50
+
51
+ def convert_age(value: str) -> Optional[float]:
52
+ """Convert age value to continuous number"""
53
+ return None # Not used since age data unavailable
54
+
55
+ def convert_gender(value: str) -> Optional[int]:
56
+ """Convert gender to binary: 0 for female, 1 for male"""
57
+ return None # Not used since gender data unavailable
58
+
59
+ # 3. Save Metadata
60
+ is_trait_available = trait_row is not None
61
+ validate_and_save_cohort_info(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
+ # 4. Clinical Feature Extraction
68
+ if trait_row is not None:
69
+ clinical_features = geo_select_clinical_features(
70
+ clinical_df=clinical_data,
71
+ trait=trait,
72
+ trait_row=trait_row,
73
+ convert_trait=convert_trait,
74
+ age_row=age_row,
75
+ convert_age=convert_age,
76
+ gender_row=gender_row,
77
+ convert_gender=convert_gender
78
+ )
79
+
80
+ # Preview the extracted features
81
+ print("Preview of clinical features:")
82
+ print(preview_df(clinical_features))
83
+
84
+ # Save to CSV
85
+ clinical_features.to_csv(out_clinical_data_file)
86
+ # Get gene expression data from matrix file
87
+ genetic_data = get_genetic_data(matrix_file_path)
88
+
89
+ # Examine data structure
90
+ print("Data structure and head:")
91
+ print(genetic_data.head())
92
+
93
+ print("\nShape:", genetic_data.shape)
94
+
95
+ print("\nFirst 20 row IDs (gene/probe identifiers):")
96
+ print(list(genetic_data.index)[:20])
97
+
98
+ # Get a few column names to verify sample IDs
99
+ print("\nFirst 5 column names:")
100
+ print(list(genetic_data.columns)[:5])
101
+ # Looking at the gene identifiers like '1007_PM_s_at', '1053_PM_at', these are Affymetrix probe IDs
102
+ # NOT human gene symbols, so they need to be mapped
103
+ requires_gene_mapping = True
104
+ # Extract gene annotation data
105
+ gene_annotation = get_gene_annotation(soft_file_path)
106
+
107
+ # Display column names and preview data
108
+ print("Column names:")
109
+ print(gene_annotation.columns)
110
+
111
+ print("\nPreview of gene annotation data:")
112
+ print(preview_df(gene_annotation))
113
+ # Create gene mapping dataframe with 'ID' and 'Gene Symbol' columns
114
+ mapping_df = get_gene_mapping(gene_annotation, 'ID', 'Gene Symbol')
115
+
116
+ # Apply gene mapping to get gene expression data
117
+ gene_data = apply_gene_mapping(genetic_data, mapping_df)
118
+
119
+ # Peek at the mapped gene data
120
+ print("Data structure after gene mapping:")
121
+ print(gene_data.head())
122
+ print("\nShape:", gene_data.shape)
123
+ # Reload clinical data that was processed earlier
124
+ selected_clinical_df = pd.read_csv(out_clinical_data_file, index_col=0)
125
+
126
+ # 1. Normalize gene symbols
127
+ gene_data = normalize_gene_symbols_in_index(gene_data)
128
+ gene_data.to_csv(out_gene_data_file)
129
+
130
+ # 2. Link clinical and genetic data
131
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, gene_data)
132
+
133
+ # 3. Handle missing values systematically
134
+ linked_data = handle_missing_values(linked_data, trait)
135
+
136
+ # 4. Check for bias in trait and demographic features
137
+ trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
138
+
139
+ # 5. Final validation and information saving
140
+ note = "Dataset contains gene expression data from primary human retinoblastoma samples profiled with Affymetrix microarray."
141
+ is_usable = validate_and_save_cohort_info(
142
+ is_final=True,
143
+ cohort=cohort,
144
+ info_path=json_path,
145
+ is_gene_available=True,
146
+ is_trait_available=True,
147
+ is_biased=trait_biased,
148
+ df=linked_data,
149
+ note=note
150
+ )
151
+
152
+ # 6. Save linked data only if usable
153
+ if is_usable:
154
+ os.makedirs(os.path.dirname(out_data_file), exist_ok=True)
155
+ linked_data.to_csv(out_data_file)
p3/preprocess/Retinoblastoma/code/GSE63529.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Retinoblastoma"
6
+ cohort = "GSE63529"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Retinoblastoma"
10
+ in_cohort_dir = "../DATA/GEO/Retinoblastoma/GSE63529"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Retinoblastoma/GSE63529.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Retinoblastoma/gene_data/GSE63529.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Retinoblastoma/clinical_data/GSE63529.csv"
16
+ json_path = "./output/preprocess/3/Retinoblastoma/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+ print("Background Information:")
24
+ print(background_info)
25
+ print("\nSample Characteristics:")
26
+
27
+ # Get dictionary of unique values per row
28
+ unique_values_dict = get_unique_values_by_row(clinical_data)
29
+ for row, values in unique_values_dict.items():
30
+ print(f"\n{row}:")
31
+ print(values)
32
+ # 1. Gene Expression Data Availability
33
+ is_gene_available = True # The Series_summary and design indicate a gene expression study
34
+
35
+ # 2.1 Data Availability
36
+ # This dataset studies ovarian cancer drug resistance, not retinoblastoma
37
+ trait_row = None # No appropriate retinoblastoma trait data
38
+ age_row = None # Age information is not provided
39
+ gender_row = None # Gender information is not provided
40
+
41
+ # 2.2 Data Type Conversion Functions
42
+ def convert_trait(x):
43
+ # Not needed since trait data is unavailable
44
+ return None
45
+
46
+ def convert_age(x):
47
+ # Not needed since age data is unavailable
48
+ return None
49
+
50
+ def convert_gender(x):
51
+ # Not needed since gender data is unavailable
52
+ return None
53
+
54
+ # 3. Save Metadata
55
+ is_trait_available = trait_row is not None
56
+ validate_and_save_cohort_info(
57
+ is_final=False,
58
+ cohort=cohort,
59
+ info_path=json_path,
60
+ is_gene_available=is_gene_available,
61
+ is_trait_available=is_trait_available
62
+ )
63
+
64
+ # 4. Clinical Feature Extraction
65
+ # Skip since trait_row is None
66
+ # Get gene expression data from matrix file
67
+ genetic_data = get_genetic_data(matrix_file_path)
68
+
69
+ # Examine data structure
70
+ print("Data structure and head:")
71
+ print(genetic_data.head())
72
+
73
+ print("\nShape:", genetic_data.shape)
74
+
75
+ print("\nFirst 20 row IDs (gene/probe identifiers):")
76
+ print(list(genetic_data.index)[:20])
77
+
78
+ # Get a few column names to verify sample IDs
79
+ print("\nFirst 5 column names:")
80
+ print(list(genetic_data.columns)[:5])
81
+ # The identifiers starting with "ILMN_" are Illumina probe IDs used in microarrays.
82
+ # They need to be mapped to human gene symbols for consistent analysis.
83
+ requires_gene_mapping = True
84
+ # Extract gene annotation data
85
+ gene_annotation = get_gene_annotation(soft_file_path)
86
+
87
+ # Display column names and preview data
88
+ print("Column names:")
89
+ print(gene_annotation.columns)
90
+
91
+ print("\nPreview of gene annotation data:")
92
+ print(preview_df(gene_annotation))
93
+ # 1. Column names identified:
94
+ # 'ID' in gene annotation corresponds to the probe IDs (ILMN_*) in gene expression data
95
+ # 'Symbol' contains the gene symbols to map to
96
+
97
+ # 2. Get gene mapping dataframe with probe ID and gene symbol columns
98
+ mapping_data = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Symbol')
99
+
100
+ # 3. Convert probe-level measurements to gene expression data
101
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
102
+
103
+ # Print info about the conversion
104
+ print("Original probe data shape:", genetic_data.shape)
105
+ print("Gene mapping data shape:", mapping_data.shape)
106
+ print("Final gene expression data shape:", gene_data.shape)
107
+
108
+ print("\nPreview of gene expression data:")
109
+ print(preview_df(gene_data))
110
+ # 1. Normalize gene symbols and save
111
+ gene_data = normalize_gene_symbols_in_index(gene_data)
112
+ os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True)
113
+ gene_data.to_csv(out_gene_data_file)
114
+
115
+ # 2-4. Skip clinical data linking and bias checking since trait data is unavailable
116
+ linked_data = gene_data # Use gene data as linked data since no clinical data available
117
+ trait_biased = True # No retinoblastoma data makes it maximally biased for this trait
118
+
119
+ # 5. Final validation - mark as unusable due to lack of retinoblastoma trait data
120
+ note = "Dataset contains gene expression data from ovarian cancer drug resistance study, not retinoblastoma."
121
+ is_usable = validate_and_save_cohort_info(
122
+ is_final=True,
123
+ cohort=cohort,
124
+ info_path=json_path,
125
+ is_gene_available=True,
126
+ is_trait_available=False,
127
+ is_biased=trait_biased,
128
+ df=linked_data,
129
+ note=note
130
+ )
131
+
132
+ # 6. Skip saving linked data since dataset is unusable
p3/preprocess/Retinoblastoma/code/GSE68950.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Retinoblastoma"
6
+ cohort = "GSE68950"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Retinoblastoma"
10
+ in_cohort_dir = "../DATA/GEO/Retinoblastoma/GSE68950"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Retinoblastoma/GSE68950.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Retinoblastoma/gene_data/GSE68950.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Retinoblastoma/clinical_data/GSE68950.csv"
16
+ json_path = "./output/preprocess/3/Retinoblastoma/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Get background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
23
+ print("Background Information:")
24
+ print(background_info)
25
+ print("\nSample Characteristics:")
26
+
27
+ # Get dictionary of unique values per row
28
+ unique_values_dict = get_unique_values_by_row(clinical_data)
29
+ for row, values in unique_values_dict.items():
30
+ print(f"\n{row}:")
31
+ print(values)
32
+ # Check gene expression data availability (yes, this is Affymetrix gene expression data)
33
+ is_gene_available = True
34
+
35
+ # After reviewing disease states, there are no retinoblastoma cases
36
+ trait_row = None # No retinoblastoma cases in the dataset
37
+ age_row = None # No age information available
38
+ gender_row = None # No gender information available
39
+
40
+ # Define conversion functions
41
+ def convert_trait(value: str) -> int:
42
+ """Convert disease state to binary: 1 for Retinoblastoma, 0 for others"""
43
+ if not value or ':' not in value:
44
+ return None
45
+ disease = value.split(':', 1)[1].strip().lower()
46
+ if 'retinoblastoma' in disease:
47
+ return 1
48
+ return 0
49
+
50
+ def convert_age(value: str) -> float:
51
+ """Placeholder function since age data is not available"""
52
+ return None
53
+
54
+ def convert_gender(value: str) -> int:
55
+ """Placeholder function since gender data is not available"""
56
+ return None
57
+
58
+ # Save metadata
59
+ validate_and_save_cohort_info(is_final=False,
60
+ cohort=cohort,
61
+ info_path=json_path,
62
+ is_gene_available=is_gene_available,
63
+ is_trait_available=trait_row is not None)
64
+
65
+ # Skip clinical feature extraction since trait data is not available
66
+ # Get gene expression data from matrix file
67
+ genetic_data = get_genetic_data(matrix_file_path)
68
+
69
+ # Examine data structure
70
+ print("Data structure and head:")
71
+ print(genetic_data.head())
72
+
73
+ print("\nShape:", genetic_data.shape)
74
+
75
+ print("\nFirst 20 row IDs (gene/probe identifiers):")
76
+ print(list(genetic_data.index)[:20])
77
+
78
+ # Get a few column names to verify sample IDs
79
+ print("\nFirst 5 column names:")
80
+ print(list(genetic_data.columns)[:5])
81
+ requires_gene_mapping = True
82
+ # Extract gene annotation data
83
+ gene_annotation = get_gene_annotation(soft_file_path)
84
+
85
+ # Display column names and preview data
86
+ print("Column names:")
87
+ print(gene_annotation.columns)
88
+
89
+ print("\nPreview of gene annotation data:")
90
+ print(preview_df(gene_annotation))
91
+ # Get gene mapping information from annotation data
92
+ # The ID column in gene_annotation matches the probe IDs in genetic_data
93
+ # The Gene Symbol column contains corresponding gene symbols
94
+ mapping_data = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')
95
+
96
+ # Apply the mapping to convert probe data to gene expression data
97
+ gene_data = apply_gene_mapping(genetic_data, mapping_data)
98
+
99
+ # Save gene data
100
+ gene_data.to_csv(out_gene_data_file)
101
+ import pandas as pd
102
+
103
+ # Create empty DataFrame for validation
104
+ empty_df = pd.DataFrame()
105
+
106
+ # Final validation and information saving
107
+ note = "Dataset lacks retinoblastoma trait information, cannot be used for analysis."
108
+ is_usable = validate_and_save_cohort_info(
109
+ is_final=True,
110
+ cohort=cohort,
111
+ info_path=json_path,
112
+ is_gene_available=True,
113
+ is_trait_available=False,
114
+ is_biased=True,
115
+ df=empty_df,
116
+ note=note
117
+ )
p3/preprocess/Retinoblastoma/code/TCGA.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Retinoblastoma"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/3/Retinoblastoma/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/3/Retinoblastoma/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/3/Retinoblastoma/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/3/Retinoblastoma/cohort_info.json"
15
+
16
+ # 1. Look for directories related to retinoblastoma (eye/ocular cancer)
17
+ available_cohorts = os.listdir(tcga_root_dir)
18
+ relevant_dirs = [d for d in available_cohorts if any(term in d.lower() for term in ['eye', 'ocular', 'retina', 'retinoblastoma'])]
19
+
20
+ # If no exact match found, use ocular melanoma as closest available eye cancer data
21
+ if len(relevant_dirs) == 0:
22
+ # Record unavailability and exit
23
+ validate_and_save_cohort_info(
24
+ is_final=False,
25
+ cohort="TCGA",
26
+ info_path=json_path,
27
+ is_gene_available=False,
28
+ is_trait_available=False
29
+ )
30
+ # Since we need to skip this trait, return empty dataframes to avoid errors in subsequent code
31
+ clinical_df = pd.DataFrame()
32
+ genetic_df = pd.DataFrame()
33
+ else:
34
+ # Select the most relevant directory (first match)
35
+ selected_dir = relevant_dirs[0]
36
+ cohort_dir = os.path.join(tcga_root_dir, selected_dir)
37
+
38
+ # 2. Get file paths for clinical and genetic data
39
+ clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
40
+
41
+ # 3. Load the data files
42
+ clinical_df = pd.read_csv(clinical_file_path, index_col=0, sep='\t')
43
+ genetic_df = pd.read_csv(genetic_file_path, index_col=0, sep='\t')
44
+
45
+ # 4. Print clinical data columns
46
+ print("Clinical data columns:")
47
+ print(clinical_df.columns.tolist())
48
+
49
+ # Record data availability
50
+ is_gene_available = len(genetic_df.columns) > 0
51
+ is_trait_available = len(clinical_df.columns) > 0
52
+
53
+ validate_and_save_cohort_info(
54
+ is_final=False,
55
+ cohort="TCGA",
56
+ info_path=json_path,
57
+ is_gene_available=is_gene_available,
58
+ is_trait_available=is_trait_available
59
+ )
60
+ # Identify candidate demographic columns
61
+ candidate_age_cols = ['age_at_initial_pathologic_diagnosis', 'days_to_birth']
62
+ candidate_gender_cols = ['gender']
63
+
64
+ # Get list of TCGA cohort directories
65
+ cohorts = os.listdir(tcga_root_dir)
66
+
67
+ # Find any clinical files containing Retinoblastoma data
68
+ clinical_df = None
69
+ for cohort in cohorts:
70
+ cohort_dir = os.path.join(tcga_root_dir, cohort)
71
+ if os.path.isdir(cohort_dir):
72
+ try:
73
+ clinical_file_path, _ = tcga_get_relevant_filepaths(cohort_dir)
74
+ temp_df = pd.read_csv(clinical_file_path, index_col=0)
75
+ if any('retinoblastoma' in str(col).lower() for col in temp_df.columns):
76
+ clinical_df = temp_df
77
+ break
78
+ except:
79
+ continue
80
+
81
+ if clinical_df is not None:
82
+ # Preview age columns
83
+ age_preview = {}
84
+ for col in candidate_age_cols:
85
+ if col in clinical_df.columns:
86
+ age_preview[col] = clinical_df[col].head().tolist()
87
+ print("Age columns preview:", age_preview)
88
+
89
+ # Preview gender columns
90
+ gender_preview = {}
91
+ for col in candidate_gender_cols:
92
+ if col in clinical_df.columns:
93
+ gender_preview[col] = clinical_df[col].head().tolist()
94
+ print("Gender columns preview:", gender_preview)
95
+ else:
96
+ print("No clinical data found containing Retinoblastoma information")
p3/preprocess/Retinoblastoma/gene_data/GSE110811.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ Gene,GSM3017123,GSM3017124,GSM3017125,GSM3017126,GSM3017127,GSM3017128,GSM3017129,GSM3017130,GSM3017131,GSM3017132,GSM3017133,GSM3017134,GSM3017135,GSM3017136,GSM3017137,GSM3017138,GSM3017139,GSM3017140,GSM3017141,GSM3017142,GSM3017143,GSM3017144,GSM3017145,GSM3017146,GSM3017147,GSM3017148,GSM3017149,GSM3017150,GSM3017151,GSM3017152,GSM3017153,GSM3017154,GSM3017155,GSM3017156
p3/preprocess/Retinoblastoma/gene_data/GSE208143.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Retinoblastoma/gene_data/GSE26805.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Retinoblastoma/gene_data/GSE29683.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ ID,GSM736228,GSM736229,GSM736230,GSM736231,GSM736232,GSM736233,GSM736234,GSM736235,GSM736236,GSM736237,GSM736238,GSM736239,GSM736240,GSM736241,GSM736242,GSM736243,GSM736244,GSM736245,GSM736246,GSM736247,GSM736248,GSM736249,GSM736250,GSM736251,GSM736252,GSM736253,GSM736254,GSM736255,GSM736256,GSM736257,GSM736258,GSM736259,GSM736260,GSM736261,GSM736262,GSM736263,GSM736264,GSM736265,GSM736266,GSM736267,GSM736268,GSM736269,GSM736270,GSM736271,GSM736272,GSM736273,GSM736274,GSM736275,GSM736276,GSM736277,GSM736278,GSM736279,GSM736280,GSM736281,GSM736282,GSM736283,GSM736284,GSM736285,GSM736286,GSM736287,GSM736288,GSM736289
p3/preprocess/Retinoblastoma/gene_data/GSE58780.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Retinoblastoma/gene_data/GSE63529.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Rheumatoid_Arthritis/GSE121894.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Rheumatoid_Arthritis/GSE143153.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Rheumatoid_Arthritis/GSE186963.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE121894.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM3449621,GSM3449622,GSM3449623,GSM3449624,GSM3449625,GSM3449626,GSM3449627,GSM3449628,GSM3449629,GSM3449630,GSM3449631,GSM3449632,GSM3449633,GSM3449634,GSM3449635,GSM3449636,GSM3449637,GSM3449638,GSM3449639,GSM3449640,GSM3449641,GSM3449642,GSM3449643,GSM3449644,GSM3449645,GSM3449646,GSM3449647,GSM3449648,GSM3449649,GSM3449650,GSM3449651,GSM3449652,GSM3449653,GSM3449654,GSM3449655,GSM3449656,GSM3449657,GSM3449658,GSM3449659,GSM3449660,GSM3449661,GSM3449662,GSM3449663,GSM3449664,GSM3449665,GSM3449666,GSM3449667,GSM3449668,GSM3449669,GSM3449670,GSM3449671,GSM3449672,GSM3449673,GSM3449674,GSM3449675,GSM3449676,GSM3449677,GSM3449678
2
+ Rheumatoid_Arthritis,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE143153.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ ,GSM4251021,GSM4251022,GSM4251023,GSM4251024,GSM4251025,GSM4251026,GSM4251027,GSM4251028,GSM4251029,GSM4251030,GSM4251031,GSM4251032,GSM4251033,GSM4251034,GSM4251035,GSM4251036,GSM4251037,GSM4251038,GSM4251039,GSM4251040,GSM4251041,GSM4251042,GSM4251043,GSM4251044,GSM4251045,GSM4251046,GSM4251047,GSM4251048,GSM4251049,GSM4251050,GSM4251051,GSM4251052
2
+ Rheumatoid_Arthritis,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
3
+ Age,56.0,51.0,37.0,40.0,41.0,50.0,38.0,50.0,58.0,55.0,35.0,43.0,62.0,46.0,58.0,40.0,66.0,35.0,58.0,60.0,63.0,56.0,19.0,64.0,71.0,30.0,31.0,45.0,38.0,43.0,37.0,41.0
4
+ Gender,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,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,1.0,0.0
p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE176440.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM5365607,GSM5365608,GSM5365609,GSM5365610,GSM5365611,GSM5365612,GSM5365613,GSM5365614,GSM5365615,GSM5365616,GSM5365617,GSM5365618,GSM5365619,GSM5365620,GSM5365621,GSM5365622,GSM5365623,GSM5365624,GSM5365625,GSM5365626,GSM5365627,GSM5365628,GSM5365629,GSM5365630,GSM5365631,GSM5365632,GSM5365633,GSM5365634,GSM5365635,GSM5365636,GSM5365637,GSM5365638,GSM5365639,GSM5365640,GSM5365641,GSM5365642,GSM5365643,GSM5365644,GSM5365645,GSM5365646,GSM5365647,GSM5365648,GSM5365649,GSM5365650,GSM5365651,GSM5365652,GSM5365653,GSM5365654,GSM5365655,GSM5365656,GSM5365657,GSM5365658,GSM5365659,GSM5365660,GSM5365661,GSM5365662
2
+ Rheumatoid_Arthritis,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE186963.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM5664373,GSM5664374,GSM5664375,GSM5664376,GSM5664377,GSM5664378,GSM5664379,GSM5664380,GSM5664381,GSM5664382,GSM5664383,GSM5664384,GSM5664385,GSM5664386,GSM5664387,GSM5664388,GSM5664389,GSM5664390,GSM5664391,GSM5664392,GSM5664393,GSM5664394,GSM5664395,GSM5664396,GSM5664397,GSM5664398,GSM5664399,GSM5664400,GSM5664401,GSM5664402,GSM5664403,GSM5664404,GSM5664405,GSM5664406,GSM5664407,GSM5664408,GSM5664409,GSM5664410,GSM5664411,GSM5664412,GSM5664413,GSM5664414,GSM5664415,GSM5664416,GSM5664417,GSM5664418,GSM5664419,GSM5664420,GSM5664421,GSM5664422,GSM5664423,GSM5664424,GSM5664425,GSM5664426,GSM5664427,GSM5664428,GSM5664429,GSM5664430,GSM5664431,GSM5664432,GSM5664433,GSM5664434,GSM5664435,GSM5664436,GSM5664437,GSM5664438,GSM5664439,GSM5664440,GSM5664441,GSM5664442,GSM5664443,GSM5664444
2
+ Rheumatoid_Arthritis,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0
p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE224330.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ ,GSM7019507,GSM7019508,GSM7019509,GSM7019510,GSM7019511,GSM7019512,GSM7019513,GSM7019514,GSM7019515,GSM7019516,GSM7019517,GSM7019518,GSM7019519,GSM7019520,GSM7019521,GSM7019522,GSM7019523,GSM7019524,GSM7019525,GSM7019526,GSM7019527,GSM7019528,GSM7019529,GSM7019530,GSM7019531,GSM7019532,GSM7019533,GSM7019534,GSM7019535,GSM7019536,GSM7019537
2
+ Rheumatoid_Arthritis,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
3
+ Age,63.0,64.0,63.0,48.0,70.0,62.0,58.0,57.0,60.0,57.0,52.0,51.0,53.0,56.0,62.0,54.0,61.0,54.0,55.0,65.0,84.0,70.0,76.0,62.0,73.0,71.0,59.0,62.0,47.0,76.0,54.0
4
+ Gender,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0
p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE224842.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM7034090,GSM7034091,GSM7034092,GSM7034093,GSM7034094,GSM7034095,GSM7034096,GSM7034097,GSM7034098,GSM7034099,GSM7034100,GSM7034101,GSM7034102,GSM7034103,GSM7034104,GSM7034105,GSM7034106,GSM7034107,GSM7034108,GSM7034109,GSM7034110,GSM7034111,GSM7034112,GSM7034113,GSM7034114,GSM7034115,GSM7034116,GSM7034117,GSM7034118,GSM7034119
2
+ Rheumatoid_Arthritis,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE236924.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM7585682,GSM7585683,GSM7585684,GSM7585685,GSM7585686,GSM7585687,GSM7585688,GSM7585689,GSM7585690,GSM7585691,GSM7585692,GSM7585693,GSM7585694,GSM7585695,GSM7585696,GSM7585697,GSM7585698,GSM7585699,GSM7585700,GSM7585701,GSM7585702,GSM7585703,GSM7585704,GSM7585705,GSM7585706,GSM7585707,GSM7585708,GSM7585709,GSM7585710,GSM7585711,GSM7585712,GSM7585713,GSM7585714,GSM7585715,GSM7585716,GSM7585717,GSM7585718,GSM7585719,GSM7585720,GSM7585721,GSM7585722,GSM7585723,GSM7585724,GSM7585725,GSM7585726,GSM7585727,GSM7585728,GSM7585729,GSM7585730,GSM7585731,GSM7585732,GSM7585733,GSM7585734,GSM7585735,GSM7585736,GSM7585737,GSM7585738,GSM7585739,GSM7585740,GSM7585741,GSM7585742,GSM7585743,GSM7585744,GSM7585745,GSM7585746,GSM7585747,GSM7585748,GSM7585749,GSM7585750,GSM7585751,GSM7585752,GSM7585753,GSM7585754,GSM7585755,GSM7585756,GSM7585757,GSM7585758,GSM7585759,GSM7585760,GSM7585761,GSM7585762,GSM7585763,GSM7585764,GSM7585765,GSM7585766,GSM7585767,GSM7585768,GSM7585769,GSM7585770,GSM7585771,GSM7585772,GSM7585773,GSM7585774,GSM7585775,GSM7585776,GSM7585777,GSM7585778,GSM7585779,GSM7585780,GSM7585781,GSM7585782,GSM7585783,GSM7585784,GSM7585785,GSM7585786,GSM7585787,GSM7585788,GSM7585789,GSM7585790,GSM7585791,GSM7585792,GSM7585793,GSM7585794,GSM7585795,GSM7585796,GSM7585797,GSM7585798,GSM7585799,GSM7585800,GSM7585801,GSM7585802,GSM7585803,GSM7585804,GSM7585805,GSM7585806,GSM7585807,GSM7585808,GSM7585809,GSM7585810,GSM7585811,GSM7585812,GSM7585813
2
+ Rheumatoid_Arthritis,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.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,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,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
p3/preprocess/Rheumatoid_Arthritis/clinical_data/GSE42842.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ,GSM1051243,GSM1051244,GSM1051245,GSM1051246,GSM1051247,GSM1051248,GSM1051249,GSM1051250,GSM1051251,GSM1051252,GSM1051253,GSM1051254,GSM1051255,GSM1051256,GSM1051257,GSM1051258,GSM1051259,GSM1051260,GSM1051261,GSM1051262,GSM1051263,GSM1051264,GSM1051265,GSM1051266,GSM1051267,GSM1051268,GSM1051269,GSM1051270,GSM1051271,GSM1051272,GSM1051273
2
+ Rheumatoid_Arthritis,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
3
+ Gender,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0
p3/preprocess/Rheumatoid_Arthritis/code/GSE121894.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Rheumatoid_Arthritis"
6
+ cohort = "GSE121894"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Rheumatoid_Arthritis"
10
+ in_cohort_dir = "../DATA/GEO/Rheumatoid_Arthritis/GSE121894"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/GSE121894.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/gene_data/GSE121894.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/clinical_data/GSE121894.csv"
16
+ json_path = "./output/preprocess/3/Rheumatoid_Arthritis/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file)
23
+
24
+ # Get unique values per clinical feature
25
+ sample_characteristics = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Dataset Background Information:")
29
+ print(f"{background_info}\n")
30
+
31
+ # Print sample characteristics
32
+ print("Sample Characteristics:")
33
+ for feature, values in sample_characteristics.items():
34
+ print(f"Feature: {feature}")
35
+ print(f"Values: {values}\n")
36
+ # 1. Gene Expression Data Availability
37
+ is_gene_available = True # From series title and design, this is gene expression microarray data
38
+
39
+ # 2. Variable Availability and Data Type Conversion
40
+ trait_row = 0 # Subject status row contains RA/control info
41
+ age_row = None # Age not available
42
+ gender_row = None # Gender not available
43
+
44
+ # Convert trait: binary (0=control, 1=RA)
45
+ def convert_trait(value):
46
+ if not isinstance(value, str):
47
+ return None
48
+ value = value.lower().split(':')[-1].strip()
49
+ if 'rheumatoid arthritis' in value:
50
+ return 1
51
+ elif 'healthy control' in value:
52
+ return 0
53
+ return None
54
+
55
+ # Skip convert_age and convert_gender since data not available
56
+
57
+ # 3. Save metadata
58
+ validate_and_save_cohort_info(is_final=False,
59
+ cohort=cohort,
60
+ info_path=json_path,
61
+ is_gene_available=is_gene_available,
62
+ is_trait_available=trait_row is not None)
63
+
64
+ # 4. Clinical feature extraction
65
+ clinical_df = geo_select_clinical_features(clinical_df=clinical_data,
66
+ trait=trait,
67
+ trait_row=trait_row,
68
+ convert_trait=convert_trait)
69
+
70
+ # Preview and save clinical data
71
+ print("Clinical data preview:")
72
+ print(preview_df(clinical_df))
73
+ clinical_df.to_csv(out_clinical_data_file)
74
+ # Get file paths
75
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
76
+
77
+ # Extract gene expression data from matrix file
78
+ gene_data = get_genetic_data(matrix_file)
79
+
80
+ # Print first 20 row IDs and shape of data to help debug
81
+ print("Shape of gene expression data:", gene_data.shape)
82
+ print("\nFirst few rows of data:")
83
+ print(gene_data.head())
84
+ print("\nFirst 20 gene/probe identifiers:")
85
+ print(gene_data.index[:20])
86
+
87
+ # Inspect a snippet of raw file to verify identifier format
88
+ import gzip
89
+ with gzip.open(matrix_file, 'rt', encoding='utf-8') as f:
90
+ lines = []
91
+ for i, line in enumerate(f):
92
+ if "!series_matrix_table_begin" in line:
93
+ # Get the next 5 lines after the marker
94
+ for _ in range(5):
95
+ lines.append(next(f).strip())
96
+ break
97
+ print("\nFirst few lines after matrix marker in raw file:")
98
+ for line in lines:
99
+ print(line)
100
+ # Looking at the gene identifiers, they are ending with '_at' which indicates
101
+ # they are Affymetrix probe IDs, not standard human gene symbols.
102
+ # These need to be mapped to gene symbols for consistent downstream analysis.
103
+ requires_gene_mapping = True
104
+ # Extract gene annotation data
105
+ gene_metadata = get_gene_annotation(soft_file)
106
+
107
+ # Preview the annotation data
108
+ print("Column names:", gene_metadata.columns.tolist())
109
+ print("\nFirst few rows preview:")
110
+ print(preview_df(gene_metadata))
111
+ # 1. Extract gene annotation data with enhanced preview to find gene symbol column
112
+ gene_metadata = get_gene_annotation(soft_file)
113
+ print("\nFirst lines of raw SOFT file to locate gene symbol column:")
114
+ with gzip.open(soft_file, 'rt', encoding='utf-8') as f:
115
+ for i, line in enumerate(f):
116
+ if not any(line.startswith(p) for p in ['^', '!', '#']):
117
+ print(line.strip())
118
+ print("-"*80)
119
+ if i > 5:
120
+ break
121
+
122
+ # Print all columns in gene_metadata
123
+ print("\nAll columns in gene metadata:")
124
+ print(gene_metadata.columns.tolist())
125
+ print("\nFull preview of first row:")
126
+ print(gene_metadata.iloc[0].to_dict())
127
+
128
+ # Get gene symbol info from SOFT file using regex pattern
129
+ gene_metadata['Gene_Symbol'] = gene_metadata['Description'].apply(lambda x: extract_human_gene_symbols(x)[0] if extract_human_gene_symbols(x) else None)
130
+
131
+ # 2. Get gene mapping dataframe with probe ID and gene symbol columns
132
+ mapping_data = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='Gene_Symbol')
133
+
134
+ # 3. Apply gene mapping to convert probe-level data to gene-level data
135
+ gene_data = apply_gene_mapping(gene_data, mapping_data)
136
+
137
+ # Print the shape and preview of the mapped gene data
138
+ print("\nShape of gene data after mapping:", gene_data.shape)
139
+ print("\nPreview of gene data after mapping:")
140
+ print(preview_df(gene_data))
141
+ # 1. Normalize gene symbols
142
+ gene_data = normalize_gene_symbols_in_index(gene_data)
143
+ gene_data.to_csv(out_gene_data_file)
144
+
145
+ # 2. Link clinical and genetic data
146
+ linked_data = geo_link_clinical_genetic_data(clinical_df, gene_data)
147
+
148
+ # 3. Handle missing values
149
+ linked_data = handle_missing_values(linked_data, trait)
150
+
151
+ # 4. Check for bias
152
+ trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
153
+
154
+ # 5. Validate and save cohort info
155
+ is_usable = validate_and_save_cohort_info(
156
+ is_final=True,
157
+ cohort=cohort,
158
+ info_path=json_path,
159
+ is_gene_available=True,
160
+ is_trait_available=True,
161
+ is_biased=trait_biased,
162
+ df=linked_data,
163
+ note="Study examining transcriptome profiles in rheumatoid arthritis."
164
+ )
165
+
166
+ # 6. Save if usable
167
+ if is_usable:
168
+ linked_data.to_csv(out_data_file)
p3/preprocess/Rheumatoid_Arthritis/code/GSE140161.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Rheumatoid_Arthritis"
6
+ cohort = "GSE140161"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Rheumatoid_Arthritis"
10
+ in_cohort_dir = "../DATA/GEO/Rheumatoid_Arthritis/GSE140161"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/GSE140161.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/gene_data/GSE140161.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/clinical_data/GSE140161.csv"
16
+ json_path = "./output/preprocess/3/Rheumatoid_Arthritis/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file)
23
+
24
+ # Get unique values per clinical feature
25
+ sample_characteristics = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Dataset Background Information:")
29
+ print(f"{background_info}\n")
30
+
31
+ # Print sample characteristics
32
+ print("Sample Characteristics:")
33
+ for feature, values in sample_characteristics.items():
34
+ print(f"Feature: {feature}")
35
+ print(f"Values: {values}\n")
36
+ # 1. Gene Expression Availability
37
+ # Yes - Series_overall_design indicates Affymetrix chip was used for whole blood transcriptome
38
+ is_gene_available = True
39
+
40
+ # 2.1 Data Availability
41
+ # Disease state is constant "Sjögren's syndrome", not usable
42
+ trait_row = None
43
+
44
+ # Gender is available in row 1
45
+ gender_row = 1
46
+
47
+ # Age is not available
48
+ age_row = None
49
+
50
+ # 2.2 Data Type Conversion
51
+ def convert_trait(x):
52
+ # Not used since trait_row is None
53
+ return None
54
+
55
+ def convert_gender(x):
56
+ if not isinstance(x, str):
57
+ return None
58
+ value = x.split(': ')[1].lower() if ': ' in x else x.lower()
59
+ if value == 'female':
60
+ return 0
61
+ elif value == 'male':
62
+ return 1
63
+ return None
64
+
65
+ def convert_age(x):
66
+ # Not used since age_row is None
67
+ return None
68
+
69
+ # 3. Save Metadata
70
+ is_trait_available = trait_row is not None
71
+ validate_and_save_cohort_info(
72
+ is_final=False,
73
+ cohort=cohort,
74
+ info_path=json_path,
75
+ is_gene_available=is_gene_available,
76
+ is_trait_available=is_trait_available
77
+ )
78
+
79
+ # 4. Clinical Feature Extraction skipped since trait_row is None
80
+ # Get file paths
81
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
82
+
83
+ # Extract gene expression data from matrix file
84
+ gene_data = get_genetic_data(matrix_file)
85
+
86
+ # Print first 20 row IDs and shape of data to help debug
87
+ print("Shape of gene expression data:", gene_data.shape)
88
+ print("\nFirst few rows of data:")
89
+ print(gene_data.head())
90
+ print("\nFirst 20 gene/probe identifiers:")
91
+ print(gene_data.index[:20])
92
+
93
+ # Inspect a snippet of raw file to verify identifier format
94
+ import gzip
95
+ with gzip.open(matrix_file, 'rt', encoding='utf-8') as f:
96
+ lines = []
97
+ for i, line in enumerate(f):
98
+ if "!series_matrix_table_begin" in line:
99
+ # Get the next 5 lines after the marker
100
+ for _ in range(5):
101
+ lines.append(next(f).strip())
102
+ break
103
+ print("\nFirst few lines after matrix marker in raw file:")
104
+ for line in lines:
105
+ print(line)
106
+ requires_gene_mapping = True
107
+ # Extract gene annotation data
108
+ gene_metadata = get_gene_annotation(soft_file)
109
+
110
+ # Preview the annotation data
111
+ print("Column names:", gene_metadata.columns.tolist())
112
+ print("\nFirst few rows preview:")
113
+ print(preview_df(gene_metadata))
114
+ # Extract gene IDs and gene symbols from annotation data
115
+ def get_gene_name(text):
116
+ """Extract gene symbol from RefSeq annotation text"""
117
+ if not isinstance(text, str):
118
+ return None
119
+ # Look for gene symbols after RefSeq
120
+ match = re.search(r'RefSeq // Homo sapiens .+?\(([A-Z0-9]+)\)', text)
121
+ if match:
122
+ return match.group(1)
123
+ # Also try looking for gene symbols after HGNC Symbol tag
124
+ match = re.search(r'\[Source:HGNC Symbol;Acc:HGNC:\d+\] // ([A-Z0-9]+)', text)
125
+ if match:
126
+ return match.group(1)
127
+ return None
128
+
129
+ # Create mapping dataframe
130
+ mapping_data = pd.DataFrame({
131
+ 'ID': gene_metadata['ID'],
132
+ 'Gene': gene_metadata['SPOT_ID.1'].apply(get_gene_name)
133
+ })
134
+
135
+ # Map probes to genes and combine expression values
136
+ gene_data = apply_gene_mapping(gene_data, mapping_data)
137
+
138
+ # Preview result
139
+ print("Shape of mapped gene expression data:", gene_data.shape)
140
+ print("\nFirst few rows of mapped data:")
141
+ print(gene_data.head())
142
+ # Save normalized gene data for future use
143
+ gene_data = normalize_gene_symbols_in_index(gene_data)
144
+ gene_data.to_csv(out_gene_data_file)
145
+
146
+ # Create minimal clinical features with constant trait
147
+ clinical_features = pd.DataFrame({'Sjogrens': 1}, index=gene_data.columns)
148
+
149
+ # Link data and check bias
150
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
151
+ linked_data = handle_missing_values(linked_data, 'Sjogrens')
152
+ trait_biased, linked_data = judge_and_remove_biased_features(linked_data, 'Sjogrens')
153
+
154
+ # Validate and save info
155
+ is_usable = validate_and_save_cohort_info(
156
+ is_final=True,
157
+ cohort=cohort,
158
+ info_path=json_path,
159
+ is_gene_available=True,
160
+ is_trait_available=True,
161
+ is_biased=trait_biased,
162
+ df=linked_data,
163
+ note="Dataset contains gene expression data but all samples are Sjögren's syndrome cases."
164
+ )
165
+
166
+ # Save if usable (won't be in this case due to constant trait)
167
+ if is_usable:
168
+ linked_data.to_csv(out_data_file)
p3/preprocess/Rheumatoid_Arthritis/code/GSE143153.py ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Rheumatoid_Arthritis"
6
+ cohort = "GSE143153"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Rheumatoid_Arthritis"
10
+ in_cohort_dir = "../DATA/GEO/Rheumatoid_Arthritis/GSE143153"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/GSE143153.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/gene_data/GSE143153.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/clinical_data/GSE143153.csv"
16
+ json_path = "./output/preprocess/3/Rheumatoid_Arthritis/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file)
23
+
24
+ # Get unique values per clinical feature
25
+ sample_characteristics = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Dataset Background Information:")
29
+ print(f"{background_info}\n")
30
+
31
+ # Print sample characteristics
32
+ print("Sample Characteristics:")
33
+ for feature, values in sample_characteristics.items():
34
+ print(f"Feature: {feature}")
35
+ print(f"Values: {values}\n")
36
+ # 1. Gene Expression Data Availability
37
+ # Yes - this is a microarray study of gene expression in CD4+ T cells
38
+ is_gene_available = True
39
+
40
+ # 2.1 Data Availability
41
+ # Trait (Primary SS vs non-SS) is in row 1
42
+ trait_row = 1
43
+ # Age is in row 2
44
+ age_row = 2
45
+ # Gender is in row 3
46
+ gender_row = 3
47
+
48
+ # 2.2 Data Type Conversion Functions
49
+ def convert_trait(value: str) -> int:
50
+ """Convert Primary SS vs non-SS to binary"""
51
+ if not value:
52
+ return None
53
+ value = value.split(': ')[1].strip()
54
+ if value == 'Primary SS':
55
+ return 1
56
+ elif value == 'non-SS':
57
+ return 0
58
+ return None
59
+
60
+ def convert_age(value: str) -> float:
61
+ """Convert age to float"""
62
+ if not value:
63
+ return None
64
+ try:
65
+ return float(value.split(': ')[1])
66
+ except:
67
+ return None
68
+
69
+ def convert_gender(value: str) -> int:
70
+ """Convert gender to binary (F=0, M=1)"""
71
+ if not value:
72
+ return None
73
+ value = value.split(': ')[1].strip()
74
+ if value == 'F':
75
+ return 0
76
+ elif value == 'M':
77
+ return 1
78
+ return None
79
+
80
+ # 3. Save Metadata
81
+ is_trait_available = trait_row is not None
82
+ validate_and_save_cohort_info(is_final=False,
83
+ cohort=cohort,
84
+ info_path=json_path,
85
+ is_gene_available=is_gene_available,
86
+ is_trait_available=is_trait_available)
87
+
88
+ # 4. Clinical Feature Extraction
89
+ if trait_row is not None:
90
+ clinical_features = geo_select_clinical_features(
91
+ clinical_df=clinical_data,
92
+ trait=trait,
93
+ trait_row=trait_row,
94
+ convert_trait=convert_trait,
95
+ age_row=age_row,
96
+ convert_age=convert_age,
97
+ gender_row=gender_row,
98
+ convert_gender=convert_gender
99
+ )
100
+
101
+ # Preview the extracted features
102
+ preview = preview_df(clinical_features)
103
+ print("Preview of clinical features:")
104
+ print(preview)
105
+
106
+ # Save clinical features
107
+ clinical_features.to_csv(out_clinical_data_file)
108
+ # Get file paths
109
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
110
+
111
+ # Extract gene expression data from matrix file
112
+ gene_data = get_genetic_data(matrix_file)
113
+
114
+ # Print first 20 row IDs and shape of data to help debug
115
+ print("Shape of gene expression data:", gene_data.shape)
116
+ print("\nFirst few rows of data:")
117
+ print(gene_data.head())
118
+ print("\nFirst 20 gene/probe identifiers:")
119
+ print(gene_data.index[:20])
120
+
121
+ # Inspect a snippet of raw file to verify identifier format
122
+ import gzip
123
+ with gzip.open(matrix_file, 'rt', encoding='utf-8') as f:
124
+ lines = []
125
+ for i, line in enumerate(f):
126
+ if "!series_matrix_table_begin" in line:
127
+ # Get the next 5 lines after the marker
128
+ for _ in range(5):
129
+ lines.append(next(f).strip())
130
+ break
131
+ print("\nFirst few lines after matrix marker in raw file:")
132
+ for line in lines:
133
+ print(line)
134
+ # Reviewing identifiers from data
135
+ # The gene identifiers appear to be numerical probe IDs instead of official gene symbols
136
+ # IDs like '1', '2', '3' indicate they are probe identifiers that need to be mapped
137
+ requires_gene_mapping = True
138
+ # Extract gene annotation data
139
+ gene_metadata = get_gene_annotation(soft_file)
140
+
141
+ # Preview the annotation data
142
+ print("Column names:", gene_metadata.columns.tolist())
143
+ print("\nFirst few rows preview:")
144
+ print(preview_df(gene_metadata))
145
+ # Extract the gene mapping from annotation data
146
+ # 'ID' matches the identifiers in expression data, 'GeneName' contains gene symbols
147
+ mapping_df = get_gene_mapping(gene_metadata, 'ID', 'GeneName')
148
+
149
+ # Apply the gene mapping to convert probe-level data to gene expression data
150
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
151
+
152
+ # Preview the mapped gene expression data
153
+ print("Shape of gene expression data after mapping:", gene_data.shape)
154
+ print("\nFirst few rows of mapped data:")
155
+ print(gene_data.head())
156
+ print("\nFirst 20 gene symbols:")
157
+ print(gene_data.index[:20])
158
+ # 1. Normalize gene symbols
159
+ gene_data = normalize_gene_symbols_in_index(gene_data)
160
+ gene_data.to_csv(out_gene_data_file)
161
+
162
+ # 2. Link clinical and genetic data
163
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
164
+
165
+ # 3. Handle missing values
166
+ linked_data = handle_missing_values(linked_data, trait)
167
+
168
+ # 4. Check for bias
169
+ trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
170
+
171
+ # 5. Validate and save cohort info
172
+ is_usable = validate_and_save_cohort_info(
173
+ is_final=True,
174
+ cohort=cohort,
175
+ info_path=json_path,
176
+ is_gene_available=True,
177
+ is_trait_available=True,
178
+ is_biased=trait_biased,
179
+ df=linked_data,
180
+ note="Study examining transcriptome profiles in rheumatoid arthritis."
181
+ )
182
+
183
+ # 6. Save if usable
184
+ if is_usable:
185
+ linked_data.to_csv(out_data_file)
p3/preprocess/Rheumatoid_Arthritis/code/GSE176440.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Rheumatoid_Arthritis"
6
+ cohort = "GSE176440"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Rheumatoid_Arthritis"
10
+ in_cohort_dir = "../DATA/GEO/Rheumatoid_Arthritis/GSE176440"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/GSE176440.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/gene_data/GSE176440.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/clinical_data/GSE176440.csv"
16
+ json_path = "./output/preprocess/3/Rheumatoid_Arthritis/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file)
23
+
24
+ # Get unique values per clinical feature
25
+ sample_characteristics = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Dataset Background Information:")
29
+ print(f"{background_info}\n")
30
+
31
+ # Print sample characteristics
32
+ print("Sample Characteristics:")
33
+ for feature, values in sample_characteristics.items():
34
+ print(f"Feature: {feature}")
35
+ print(f"Values: {values}\n")
36
+ # Check gene data availability - Yes, this is a microarray gene expression dataset
37
+ is_gene_available = True
38
+
39
+ # Check trait data availability - Feature 2 indicates treatment status, can be used for disease activity
40
+ trait_row = 2
41
+
42
+ # Age data is not available
43
+ age_row = None
44
+
45
+ # Gender data is not available
46
+ gender_row = None
47
+
48
+ # Convert treatment status to binary (before=1 active disease, after=0 controlled)
49
+ def convert_trait(value):
50
+ if not isinstance(value, str):
51
+ return None
52
+ value = value.split(": ")[-1].lower()
53
+ if "before" in value:
54
+ return 1
55
+ elif "after" in value:
56
+ return 0
57
+ return None
58
+
59
+ # Age conversion not needed
60
+ convert_age = None
61
+
62
+ # Gender conversion not needed
63
+ convert_gender = None
64
+
65
+ # Validate and save cohort info
66
+ validate_and_save_cohort_info(
67
+ is_final=False,
68
+ cohort=cohort,
69
+ info_path=json_path,
70
+ is_gene_available=is_gene_available,
71
+ is_trait_available=trait_row is not None
72
+ )
73
+
74
+ # Extract clinical features since trait data is available
75
+ clinical_features = geo_select_clinical_features(
76
+ clinical_df=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
+
86
+ # Preview the processed clinical data
87
+ print("Preview of clinical features:")
88
+ print(preview_df(clinical_features))
89
+
90
+ # Save clinical features
91
+ clinical_features.to_csv(out_clinical_data_file)
92
+ # Get file paths
93
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
94
+
95
+ # Extract gene expression data from matrix file
96
+ gene_data = get_genetic_data(matrix_file)
97
+
98
+ # Print first 20 row IDs and shape of data to help debug
99
+ print("Shape of gene expression data:", gene_data.shape)
100
+ print("\nFirst few rows of data:")
101
+ print(gene_data.head())
102
+ print("\nFirst 20 gene/probe identifiers:")
103
+ print(gene_data.index[:20])
104
+
105
+ # Inspect a snippet of raw file to verify identifier format
106
+ import gzip
107
+ with gzip.open(matrix_file, 'rt', encoding='utf-8') as f:
108
+ lines = []
109
+ for i, line in enumerate(f):
110
+ if "!series_matrix_table_begin" in line:
111
+ # Get the next 5 lines after the marker
112
+ for _ in range(5):
113
+ lines.append(next(f).strip())
114
+ break
115
+ print("\nFirst few lines after matrix marker in raw file:")
116
+ for line in lines:
117
+ print(line)
118
+ # Based on the probe IDs (e.g., A_23_P100001), these are Agilent microarray probe IDs, not gene symbols
119
+ # Therefore we need to map them to standard gene symbols
120
+ requires_gene_mapping = True
121
+ # Extract gene annotation data
122
+ gene_metadata = get_gene_annotation(soft_file)
123
+
124
+ # Preview the annotation data
125
+ print("Column names:", gene_metadata.columns.tolist())
126
+ print("\nFirst few rows preview:")
127
+ print(preview_df(gene_metadata))
128
+ # Get gene mapping from annotation data
129
+ # ID column contains the same probe IDs as in gene expression data
130
+ # GENE_SYMBOL column contains the target gene symbols
131
+ mapping_data = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='GENE_SYMBOL')
132
+
133
+ # Apply gene mapping to convert probe data to gene expression data
134
+ gene_data = apply_gene_mapping(gene_data, mapping_data)
135
+
136
+ # Preview the gene-level expression data
137
+ print("Shape of gene expression data after mapping:", gene_data.shape)
138
+ print("\nFirst few rows of gene-level data:")
139
+ print(gene_data.head())
140
+ print("\nFirst 20 gene symbols:")
141
+ print(gene_data.index[:20])
142
+ # 1. Normalize gene symbols
143
+ gene_data = normalize_gene_symbols_in_index(gene_data)
144
+ gene_data.to_csv(out_gene_data_file)
145
+
146
+ # 2. Link clinical and genetic data
147
+ linked_data = geo_link_clinical_genetic_data(clinical_features, gene_data)
148
+
149
+ # 3. Handle missing values
150
+ linked_data = handle_missing_values(linked_data, trait)
151
+
152
+ # 4. Check for bias
153
+ trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
154
+
155
+ # 5. Validate and save cohort info
156
+ is_usable = validate_and_save_cohort_info(
157
+ is_final=True,
158
+ cohort=cohort,
159
+ info_path=json_path,
160
+ is_gene_available=True,
161
+ is_trait_available=True,
162
+ is_biased=trait_biased,
163
+ df=linked_data,
164
+ note="Study examining transcriptome profiles in rheumatoid arthritis."
165
+ )
166
+
167
+ # 6. Save if usable
168
+ if is_usable:
169
+ linked_data.to_csv(out_data_file)
p3/preprocess/Rheumatoid_Arthritis/code/GSE186963.py ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Rheumatoid_Arthritis"
6
+ cohort = "GSE186963"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Rheumatoid_Arthritis"
10
+ in_cohort_dir = "../DATA/GEO/Rheumatoid_Arthritis/GSE186963"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/GSE186963.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/gene_data/GSE186963.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/clinical_data/GSE186963.csv"
16
+ json_path = "./output/preprocess/3/Rheumatoid_Arthritis/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file)
23
+
24
+ # Get unique values per clinical feature
25
+ sample_characteristics = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Dataset Background Information:")
29
+ print(f"{background_info}\n")
30
+
31
+ # Print sample characteristics
32
+ print("Sample Characteristics:")
33
+ for feature, values in sample_characteristics.items():
34
+ print(f"Feature: {feature}")
35
+ print(f"Values: {values}\n")
36
+ # 1. Gene expression availability
37
+ # Dataset contains whole blood gene expression data according to title and summary
38
+ is_gene_available = True
39
+
40
+ # 2. Variable availability and conversion functions
41
+ # Trait (patient response status) is available at index 3
42
+ trait_row = 3
43
+
44
+ def convert_trait(value):
45
+ # Extract value after colon and strip whitespace
46
+ if ':' in value:
47
+ value = value.split(':')[1].strip()
48
+ if value == 'Responder':
49
+ return 0 # Negative case (control)
50
+ elif value == 'Non-responder':
51
+ return 1 # Positive case
52
+ return None
53
+
54
+ # Age and gender data are not available in sample characteristics
55
+ age_row = None
56
+ gender_row = None
57
+
58
+ def convert_age(value):
59
+ return None
60
+
61
+ def convert_gender(value):
62
+ return None
63
+
64
+ # 3. Save metadata
65
+ 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=trait_row is not None
71
+ )
72
+
73
+ # 4. Extract clinical features since trait data is available
74
+ clinical_df = geo_select_clinical_features(
75
+ clinical_df=clinical_data,
76
+ trait=trait,
77
+ trait_row=trait_row,
78
+ convert_trait=convert_trait,
79
+ age_row=age_row,
80
+ convert_age=convert_age,
81
+ gender_row=gender_row,
82
+ convert_gender=convert_gender
83
+ )
84
+
85
+ # Preview and save clinical data
86
+ print("Clinical data preview:")
87
+ print(preview_df(clinical_df))
88
+
89
+ clinical_df.to_csv(out_clinical_data_file)
90
+ # Get file paths
91
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
92
+
93
+ # Extract gene expression data from matrix file
94
+ gene_data = get_genetic_data(matrix_file)
95
+
96
+ # Print first 20 row IDs and shape of data to help debug
97
+ print("Shape of gene expression data:", gene_data.shape)
98
+ print("\nFirst few rows of data:")
99
+ print(gene_data.head())
100
+ print("\nFirst 20 gene/probe identifiers:")
101
+ print(gene_data.index[:20])
102
+
103
+ # Inspect a snippet of raw file to verify identifier format
104
+ import gzip
105
+ with gzip.open(matrix_file, 'rt', encoding='utf-8') as f:
106
+ lines = []
107
+ for i, line in enumerate(f):
108
+ if "!series_matrix_table_begin" in line:
109
+ # Get the next 5 lines after the marker
110
+ for _ in range(5):
111
+ lines.append(next(f).strip())
112
+ break
113
+ print("\nFirst few lines after matrix marker in raw file:")
114
+ for line in lines:
115
+ print(line)
116
+ requires_gene_mapping = True
117
+ # Extract gene annotation data
118
+ gene_metadata = get_gene_annotation(soft_file)
119
+
120
+ # Preview the annotation data
121
+ print("Column names:", gene_metadata.columns.tolist())
122
+ print("\nFirst few rows preview:")
123
+ print(preview_df(gene_metadata))
124
+ # Extract gene mapping data from annotation metadata
125
+ def extract_first_gene_symbol(desc):
126
+ matches = re.findall(r'\[Source:HGNC Symbol;Acc:HGNC:\d+\]', str(desc))
127
+ if matches:
128
+ text_before = desc.split(matches[0])[0]
129
+ gene = text_before.strip().split()[-1]
130
+ return gene
131
+ return None
132
+
133
+ # Create mapping dataframe with ID and extracted gene symbols
134
+ mapping_df = pd.DataFrame({
135
+ 'ID': gene_metadata['ID'],
136
+ 'Gene': gene_metadata['SPOT_ID.1'].apply(extract_first_gene_symbol)
137
+ })
138
+
139
+ # Apply gene mapping to convert probe-level data to gene-level data
140
+ gene_data = apply_gene_mapping(gene_data, mapping_df)
141
+
142
+ # Preview results
143
+ print("Shape of gene expression data after mapping:", gene_data.shape)
144
+ print("\nFirst few rows of mapped gene data:")
145
+ print(gene_data.head())
146
+ print("\nFirst 20 gene symbols:")
147
+ print(gene_data.index[:20].tolist())
148
+ # 1. Normalize gene symbols
149
+ gene_data = normalize_gene_symbols_in_index(gene_data)
150
+ gene_data.to_csv(out_gene_data_file)
151
+
152
+ # 2. Link clinical and genetic data
153
+ linked_data = geo_link_clinical_genetic_data(clinical_df, gene_data)
154
+
155
+ # 3. Handle missing values
156
+ linked_data = handle_missing_values(linked_data, trait)
157
+
158
+ # 4. Check for bias
159
+ trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
160
+
161
+ # 5. Validate and save cohort info
162
+ is_usable = validate_and_save_cohort_info(
163
+ is_final=True,
164
+ cohort=cohort,
165
+ info_path=json_path,
166
+ is_gene_available=True,
167
+ is_trait_available=True,
168
+ is_biased=trait_biased,
169
+ df=linked_data,
170
+ note="Study examining transcriptome profiles in rheumatoid arthritis."
171
+ )
172
+
173
+ # 6. Save if usable
174
+ if is_usable:
175
+ linked_data.to_csv(out_data_file)
p3/preprocess/Rheumatoid_Arthritis/code/GSE224330.py ADDED
@@ -0,0 +1,472 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Rheumatoid_Arthritis"
6
+ cohort = "GSE224330"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Rheumatoid_Arthritis"
10
+ in_cohort_dir = "../DATA/GEO/Rheumatoid_Arthritis/GSE224330"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/GSE224330.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/gene_data/GSE224330.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/clinical_data/GSE224330.csv"
16
+ json_path = "./output/preprocess/3/Rheumatoid_Arthritis/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file)
23
+
24
+ # Get unique values per clinical feature
25
+ sample_characteristics = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Dataset Background Information:")
29
+ print(f"{background_info}\n")
30
+
31
+ # Print sample characteristics
32
+ print("Sample Characteristics:")
33
+ for feature, values in sample_characteristics.items():
34
+ print(f"Feature: {feature}")
35
+ print(f"Values: {values}\n")
36
+ # 1. Gene Expression Data Availability
37
+ # Based on background info mentioning "gene expression profiling", "transcriptomic profile", "whole-genome transcriptomics"
38
+ is_gene_available = True
39
+
40
+ # 2.1 Variable Availability
41
+ trait_row = 0 # Can infer RA status from tissue source
42
+ age_row = 1 # Age data available in feature 1
43
+ gender_row = 2 # Gender data available in feature 2
44
+
45
+ # 2.2 Data Type Conversion Functions
46
+ def convert_trait(x):
47
+ if pd.isna(x):
48
+ return None
49
+ # First 10 samples (GSM7019507-GSM7019516) are from healthy controls based on background info
50
+ # Rest are RA patients on different treatments
51
+ sample_id = x.name
52
+ sample_num = int(sample_id.replace('GSM',''))
53
+ if 7019507 <= sample_num <= 7019516:
54
+ return 0 # Healthy control
55
+ else:
56
+ return 1 # RA patient
57
+
58
+ def convert_age(x):
59
+ if pd.isna(x):
60
+ return None
61
+ # Extract numeric value before 'y'
62
+ try:
63
+ age = int(x.split(':')[1].strip().replace('y',''))
64
+ return age
65
+ except:
66
+ return None
67
+
68
+ def convert_gender(x):
69
+ if pd.isna(x):
70
+ return None
71
+ value = x.split(':')[1].strip().lower()
72
+ if 'female' in value:
73
+ return 0
74
+ elif 'male' in value:
75
+ return 1
76
+ return None
77
+
78
+ # 3. Save Metadata
79
+ is_trait_available = trait_row is not None
80
+ _ = validate_and_save_cohort_info(
81
+ is_final=False,
82
+ cohort=cohort,
83
+ info_path=json_path,
84
+ is_gene_available=is_gene_available,
85
+ is_trait_available=is_trait_available
86
+ )
87
+
88
+ # 4. Clinical Feature Extraction
89
+ selected_clinical_df = geo_select_clinical_features(
90
+ clinical_df=clinical_data,
91
+ trait=trait,
92
+ trait_row=trait_row,
93
+ convert_trait=convert_trait,
94
+ age_row=age_row,
95
+ convert_age=convert_age,
96
+ gender_row=gender_row,
97
+ convert_gender=convert_gender
98
+ )
99
+
100
+ # Preview the extracted features
101
+ preview = preview_df(selected_clinical_df)
102
+ print("Preview of extracted clinical features:")
103
+ print(preview)
104
+
105
+ # Save to CSV
106
+ selected_clinical_df.to_csv(out_clinical_data_file)
107
+ # The previous step output was not provided. Without it, we cannot properly:
108
+ # 1. Determine gene expression data availability
109
+ # 2. Identify row numbers for clinical features
110
+ # 3. Design appropriate conversion logic based on actual data values
111
+
112
+ # Therefore, this step cannot be completed until we receive:
113
+ # - Background information about the dataset
114
+ # - Sample characteristics dictionary showing available clinical data
115
+
116
+ raise ValueError("Previous step output with dataset information is required to analyze data availability and implement conversion logic")
117
+ # Get file paths
118
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
119
+
120
+ # Extract gene expression data from matrix file
121
+ gene_data = get_genetic_data(matrix_file)
122
+
123
+ # Print first 20 row IDs and shape of data to help debug
124
+ print("Shape of gene expression data:", gene_data.shape)
125
+ print("\nFirst few rows of data:")
126
+ print(gene_data.head())
127
+ print("\nFirst 20 gene/probe identifiers:")
128
+ print(gene_data.index[:20])
129
+
130
+ # Inspect a snippet of raw file to verify identifier format
131
+ import gzip
132
+ with gzip.open(matrix_file, 'rt', encoding='utf-8') as f:
133
+ lines = []
134
+ for i, line in enumerate(f):
135
+ if "!series_matrix_table_begin" in line:
136
+ # Get the next 5 lines after the marker
137
+ for _ in range(5):
138
+ lines.append(next(f).strip())
139
+ break
140
+ print("\nFirst few lines after matrix marker in raw file:")
141
+ for line in lines:
142
+ print(line)
143
+ # The identifiers starting with "A_19_P" appear to be Agilent microarray probe IDs
144
+ # These are not standard human gene symbols and need to be mapped to gene symbols
145
+ requires_gene_mapping = True
146
+ # Extract gene annotation data
147
+ gene_metadata = get_gene_annotation(soft_file)
148
+
149
+ # Preview the annotation data
150
+ print("Column names:", gene_metadata.columns.tolist())
151
+ print("\nFirst few rows preview:")
152
+ print(preview_df(gene_metadata))
153
+ # 1. Extract gene annotation data
154
+ gene_metadata = get_gene_annotation(soft_file)
155
+
156
+ # 2. Extract gene mapping from annotation data
157
+ mapping_data = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='GENE_SYMBOL')
158
+
159
+ # 3. Apply mapping to convert probe-level data to gene-level data
160
+ gene_expression_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_data)
161
+
162
+ # Save processed gene data
163
+ gene_expression_data.to_csv(out_gene_data_file)
164
+ # Get file paths
165
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
166
+
167
+ # Extract gene expression data from matrix file
168
+ gene_data = get_genetic_data(matrix_file)
169
+
170
+ # Print first 20 row IDs and shape of data to help debug
171
+ print("Shape of gene expression data:", gene_data.shape)
172
+ print("\nFirst few rows of data:")
173
+ print(gene_data.head())
174
+ print("\nFirst 20 gene/probe identifiers:")
175
+ print(gene_data.index[:20])
176
+
177
+ # Inspect a snippet of raw file to verify identifier format
178
+ import gzip
179
+ with gzip.open(matrix_file, 'rt', encoding='utf-8') as f:
180
+ lines = []
181
+ for i, line in enumerate(f):
182
+ if "!series_matrix_table_begin" in line:
183
+ # Get the next 5 lines after the marker
184
+ for _ in range(5):
185
+ lines.append(next(f).strip())
186
+ break
187
+ print("\nFirst few lines after matrix marker in raw file:")
188
+ for line in lines:
189
+ print(line)
190
+ # 1. Extract gene annotation data and observe identifiers
191
+ # From previous outputs, we can see:
192
+ # - Gene expression data uses identifiers like 'A_19_P00315452'
193
+ # - Gene annotation data has matching IDs in the 'ID' column and gene symbols in 'GENE_SYMBOL'
194
+ gene_metadata = get_gene_annotation(soft_file)
195
+
196
+ # 2. Extract gene mapping from annotation data
197
+ mapping_data = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='GENE_SYMBOL')
198
+
199
+ # 3. Apply mapping to convert probe-level data to gene-level data
200
+ gene_expression_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_data)
201
+
202
+ # Save processed gene data
203
+ gene_expression_data.to_csv(out_gene_data_file)
204
+
205
+ # Print shape before and after mapping to verify the transformation
206
+ print("Shape before mapping (probes):", gene_data.shape)
207
+ print("Shape after mapping (genes):", gene_expression_data.shape)
208
+ print("\nFirst few gene symbols and their expression values:")
209
+ print(gene_expression_data.head())
210
+ # First get clinical features
211
+ selected_clinical_df = geo_select_clinical_features(
212
+ clinical_df=clinical_data,
213
+ trait=trait,
214
+ trait_row=0, # From trait identification in previous step
215
+ convert_trait=lambda x: 1 if not pd.isna(x) else None, # Initially mark all as patients
216
+ age_row=1, # From age identification in previous step
217
+ convert_age=convert_age,
218
+ gender_row=2, # From gender identification in previous step
219
+ convert_gender=convert_gender
220
+ )
221
+
222
+ # Set first 10 samples as controls based on background info
223
+ sample_cols = selected_clinical_df.columns[:10] # First 10 samples
224
+ selected_clinical_df.loc[trait, sample_cols] = 0
225
+
226
+ # 1. Normalize gene symbols
227
+ gene_expression_data = normalize_gene_symbols_in_index(gene_expression_data)
228
+ gene_expression_data.to_csv(out_gene_data_file)
229
+
230
+ # 2. Link clinical and genetic data
231
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, gene_expression_data)
232
+
233
+ # 3. Handle missing values
234
+ linked_data = handle_missing_values(linked_data, trait)
235
+
236
+ # 4. Check for bias
237
+ trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
238
+
239
+ # 5. Validate and save cohort info
240
+ is_usable = validate_and_save_cohort_info(
241
+ is_final=True,
242
+ cohort=cohort,
243
+ info_path=json_path,
244
+ is_gene_available=True,
245
+ is_trait_available=True,
246
+ is_biased=trait_biased,
247
+ df=linked_data,
248
+ note="Study examining transcriptome profiles in rheumatoid arthritis."
249
+ )
250
+
251
+ # 6. Save if usable
252
+ if is_usable:
253
+ linked_data.to_csv(out_data_file)
254
+ # Get file paths
255
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
256
+
257
+ # Extract gene expression data from matrix file
258
+ gene_data = get_genetic_data(matrix_file)
259
+
260
+ # Print first 20 row IDs and shape of data to help debug
261
+ print("Shape of gene expression data:", gene_data.shape)
262
+ print("\nFirst few rows of data:")
263
+ print(gene_data.head())
264
+ print("\nFirst 20 gene/probe identifiers:")
265
+ print(gene_data.index[:20])
266
+
267
+ # Inspect a snippet of raw file to verify identifier format
268
+ import gzip
269
+ with gzip.open(matrix_file, 'rt', encoding='utf-8') as f:
270
+ lines = []
271
+ for i, line in enumerate(f):
272
+ if "!series_matrix_table_begin" in line:
273
+ # Get the next 5 lines after the marker
274
+ for _ in range(5):
275
+ lines.append(next(f).strip())
276
+ break
277
+ print("\nFirst few lines after matrix marker in raw file:")
278
+ for line in lines:
279
+ print(line)
280
+ # 1. Extract gene annotation data and observe identifiers
281
+ # From previous outputs, we can see:
282
+ # - Gene expression data uses identifiers like 'A_19_P00315452'
283
+ # - Gene annotation data has matching IDs in the 'ID' column and gene symbols in 'GENE_SYMBOL'
284
+ gene_metadata = get_gene_annotation(soft_file)
285
+
286
+ # 2. Extract gene mapping from annotation data
287
+ mapping_data = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='GENE_SYMBOL')
288
+
289
+ # 3. Apply mapping to convert probe-level data to gene-level data
290
+ gene_expression_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_data)
291
+
292
+ # Save processed gene data
293
+ gene_expression_data.to_csv(out_gene_data_file)
294
+
295
+ # Print shape before and after mapping to verify the transformation
296
+ print("Shape before mapping (probes):", gene_data.shape)
297
+ print("Shape after mapping (genes):", gene_expression_data.shape)
298
+ print("\nFirst few gene symbols and their expression values:")
299
+ print(gene_expression_data.head())
300
+ # First extract clinical features with proper conversion functions
301
+ def convert_trait(x):
302
+ if pd.isna(x):
303
+ return None
304
+ # All samples with tissue:monocytes are trait positive (RA patients) except first 10 which are controls
305
+ return 1
306
+
307
+ def convert_age(x):
308
+ if pd.isna(x):
309
+ return None
310
+ # Extract numeric value after 'age:'
311
+ match = re.search(r'age:\s*(\d+)y', str(x))
312
+ if match:
313
+ return int(match.group(1))
314
+ return None
315
+
316
+ def convert_gender(x):
317
+ if pd.isna(x):
318
+ return None
319
+ # Convert after 'gender:'
320
+ if 'female' in str(x).lower():
321
+ return 0
322
+ elif 'male' in str(x).lower():
323
+ return 1
324
+ return None
325
+
326
+ # Extract clinical features
327
+ selected_clinical_df = geo_select_clinical_features(
328
+ clinical_df=clinical_data,
329
+ trait=trait,
330
+ trait_row=0, # Using tissue row
331
+ convert_trait=convert_trait,
332
+ age_row=1, # Age information is in row 1
333
+ convert_age=convert_age,
334
+ gender_row=2, # Gender information is in row 2
335
+ convert_gender=convert_gender
336
+ )
337
+
338
+ # Set first 10 samples as controls based on background info
339
+ sample_cols = selected_clinical_df.columns[:10] # First 10 samples
340
+ selected_clinical_df.loc[trait, sample_cols] = 0
341
+
342
+ # 1. Normalize gene symbols from previous gene mapping result
343
+ gene_data = normalize_gene_symbols_in_index(gene_data)
344
+ gene_data.to_csv(out_gene_data_file)
345
+
346
+ # 2. Link clinical and genetic data
347
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, gene_data)
348
+
349
+ # 3. Handle missing values
350
+ linked_data = handle_missing_values(linked_data, trait)
351
+
352
+ # 4. Check for bias
353
+ trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
354
+
355
+ # 5. Validate and save cohort info
356
+ is_usable = validate_and_save_cohort_info(
357
+ is_final=True,
358
+ cohort=cohort,
359
+ info_path=json_path,
360
+ is_gene_available=True,
361
+ is_trait_available=True,
362
+ is_biased=trait_biased,
363
+ df=linked_data,
364
+ note="Study examining transcriptome profiles in rheumatoid arthritis, with 10 controls and 21 RA patients."
365
+ )
366
+
367
+ # 6. Save if usable
368
+ if is_usable:
369
+ linked_data.to_csv(out_data_file)
370
+ # Get file paths
371
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
372
+
373
+ # Extract background info and clinical data
374
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file)
375
+
376
+ # Get unique values per clinical feature
377
+ sample_characteristics = get_unique_values_by_row(clinical_data)
378
+
379
+ # Print background info
380
+ print("Dataset Background Information:")
381
+ print(f"{background_info}\n")
382
+
383
+ # Print sample characteristics
384
+ print("Sample Characteristics:")
385
+ for feature, values in sample_characteristics.items():
386
+ print(f"Feature: {feature}")
387
+ print(f"Values: {values}\n")
388
+ # 1. Gene Expression Data Availability
389
+ # The series title and summary indicate gene expression data of monocytes
390
+ is_gene_available = True
391
+
392
+ # 2.1 Data Availability
393
+ # For trait: While we know there are healthy controls and RA patients from the series design,
394
+ # the treatment information is not shown in the available sample characteristics preview
395
+ # So we cannot reliably extract trait information
396
+ trait_row = None
397
+
398
+ # Age is in Feature 1
399
+ age_row = 1
400
+
401
+ # Gender is in Feature 2
402
+ gender_row = 2
403
+
404
+ # 2.2 Data Type Conversion Functions
405
+ def convert_trait(x):
406
+ # Not needed since trait_row is None
407
+ return None
408
+
409
+ def convert_age(x):
410
+ if pd.isna(x):
411
+ return None
412
+ # Extract number before 'y'
413
+ try:
414
+ age = int(x.split(': ')[1].replace('y',''))
415
+ return age
416
+ except:
417
+ return None
418
+
419
+ def convert_gender(x):
420
+ if pd.isna(x):
421
+ return None
422
+ val = x.split(': ')[1].lower()
423
+ if 'female' in val:
424
+ return 0
425
+ elif 'male' in val:
426
+ return 1
427
+ return None
428
+
429
+ # 3. Save Metadata
430
+ is_trait_available = trait_row is not None
431
+ validate_and_save_cohort_info(
432
+ is_final=False,
433
+ cohort=cohort,
434
+ info_path=json_path,
435
+ is_gene_available=is_gene_available,
436
+ is_trait_available=is_trait_available
437
+ )
438
+
439
+ # 4. Clinical Feature Extraction
440
+ # Skip since trait_row is None
441
+ # Request to see sample characteristics data first
442
+ print("Please provide previous output containing:")
443
+ print("1. The sample characteristics dictionary")
444
+ print("2. Background information about the dataset")
445
+ print("3. Any other relevant metadata")
446
+ # Set availability flag for gene expression data based on series type
447
+ is_gene_available = False # Only miRNA data based on previous output shown
448
+
449
+ # Define row indices and conversion functions for clinical features
450
+ trait_row = None # No disease status/RA information found in sample characteristics
451
+ age_row = None # Age information not provided
452
+ gender_row = None # Gender information not provided
453
+
454
+ def convert_trait(x: str) -> int:
455
+ return None # Not used since trait_row is None
456
+
457
+ def convert_age(x: str) -> float:
458
+ return None # Not used since age_row is None
459
+
460
+ def convert_gender(x: str) -> int:
461
+ return None # Not used since gender_row is None
462
+
463
+ # Save initial filtering results
464
+ validate_and_save_cohort_info(
465
+ is_final=False,
466
+ cohort=cohort,
467
+ info_path=json_path,
468
+ is_gene_available=is_gene_available,
469
+ is_trait_available=(trait_row is not None)
470
+ )
471
+
472
+ # Skip clinical feature extraction since trait_row is None
p3/preprocess/Rheumatoid_Arthritis/code/GSE224842.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Rheumatoid_Arthritis"
6
+ cohort = "GSE224842"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Rheumatoid_Arthritis"
10
+ in_cohort_dir = "../DATA/GEO/Rheumatoid_Arthritis/GSE224842"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/GSE224842.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/gene_data/GSE224842.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/clinical_data/GSE224842.csv"
16
+ json_path = "./output/preprocess/3/Rheumatoid_Arthritis/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file)
23
+
24
+ # Get unique values per clinical feature
25
+ sample_characteristics = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Dataset Background Information:")
29
+ print(f"{background_info}\n")
30
+
31
+ # Print sample characteristics
32
+ print("Sample Characteristics:")
33
+ for feature, values in sample_characteristics.items():
34
+ print(f"Feature: {feature}")
35
+ print(f"Values: {values}\n")
36
+ # 1. Gene Expression Data Availability
37
+ # Based on background info, this is DNA microarray data of PBMCs, so gene expression data is available
38
+ is_gene_available = True
39
+
40
+ # 2.1 Data Availability
41
+ # The only feature indicates all samples are RA patients
42
+ trait_row = 0 # From Feature 0: "disease state: rheumatoid arthritis"
43
+ age_row = None # Age data not available
44
+ gender_row = None # Gender data not available
45
+
46
+ # 2.2 Data Type Conversion Functions
47
+ def convert_trait(value):
48
+ """Convert trait values to binary"""
49
+ if pd.isna(value):
50
+ return None
51
+ # Extract value after colon if present
52
+ if ':' in str(value):
53
+ value = value.split(':')[1].strip()
54
+ # Convert to binary where 1 = has disease
55
+ if 'rheumatoid arthritis' in value.lower():
56
+ return 1
57
+ return 0
58
+
59
+ def convert_age(value):
60
+ """Convert age values - not used since age not available"""
61
+ return None
62
+
63
+ def convert_gender(value):
64
+ """Convert gender values - not used since gender not available"""
65
+ return None
66
+
67
+ # 3. Save metadata for initial filtering
68
+ # trait_row is not None, so trait data is available
69
+ is_trait_available = True if trait_row is not None else False
70
+
71
+ validate_and_save_cohort_info(
72
+ is_final=False,
73
+ cohort=cohort,
74
+ info_path=json_path,
75
+ is_gene_available=is_gene_available,
76
+ is_trait_available=is_trait_available
77
+ )
78
+
79
+ # 4. Extract clinical features since trait_row is not None
80
+ selected_clinical_df = geo_select_clinical_features(
81
+ clinical_df=clinical_data,
82
+ trait=trait,
83
+ trait_row=trait_row,
84
+ convert_trait=convert_trait,
85
+ age_row=age_row,
86
+ convert_age=convert_age,
87
+ gender_row=gender_row,
88
+ convert_gender=convert_gender
89
+ )
90
+
91
+ # Preview the processed clinical data
92
+ print("Preview of processed clinical data:")
93
+ print(preview_df(selected_clinical_df))
94
+
95
+ # Save to CSV
96
+ selected_clinical_df.to_csv(out_clinical_data_file)
97
+ # Get file paths
98
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
99
+
100
+ # Extract gene expression data from matrix file
101
+ gene_data = get_genetic_data(matrix_file)
102
+
103
+ # Print first 20 row IDs and shape of data to help debug
104
+ print("Shape of gene expression data:", gene_data.shape)
105
+ print("\nFirst few rows of data:")
106
+ print(gene_data.head())
107
+ print("\nFirst 20 gene/probe identifiers:")
108
+ print(gene_data.index[:20])
109
+
110
+ # Inspect a snippet of raw file to verify identifier format
111
+ import gzip
112
+ with gzip.open(matrix_file, 'rt', encoding='utf-8') as f:
113
+ lines = []
114
+ for i, line in enumerate(f):
115
+ if "!series_matrix_table_begin" in line:
116
+ # Get the next 5 lines after the marker
117
+ for _ in range(5):
118
+ lines.append(next(f).strip())
119
+ break
120
+ print("\nFirst few lines after matrix marker in raw file:")
121
+ for line in lines:
122
+ print(line)
123
+ # The probe IDs starting with "A_23_P" indicate this is an Agilent microarray dataset
124
+ # These are probe IDs and need to be mapped to human gene symbols
125
+ requires_gene_mapping = True
126
+ # Extract gene annotation data
127
+ gene_metadata = get_gene_annotation(soft_file)
128
+
129
+ # Preview the annotation data
130
+ print("Column names:", gene_metadata.columns.tolist())
131
+ print("\nFirst few rows preview:")
132
+ print(preview_df(gene_metadata))
133
+ # Extract ID and GENE_SYMBOL columns from gene annotation for mapping
134
+ mapping_data = get_gene_mapping(gene_metadata, 'ID', 'GENE_SYMBOL')
135
+
136
+ # Apply gene mapping to convert probe measurements to gene expression values
137
+ gene_data = apply_gene_mapping(gene_data, mapping_data)
138
+
139
+ # Preview the processed gene data
140
+ print("\nShape of gene expression data after mapping:", gene_data.shape)
141
+ print("\nFirst few rows of mapped gene data:")
142
+ print(gene_data.head())
143
+ print("\nFirst 20 gene symbols:")
144
+ print(gene_data.index[:20])
145
+ # 1. Normalize gene symbols
146
+ gene_data = normalize_gene_symbols_in_index(gene_data)
147
+ gene_data.to_csv(out_gene_data_file)
148
+
149
+ # 2. Link clinical and genetic data
150
+ linked_data = geo_link_clinical_genetic_data(selected_clinical_df, gene_data)
151
+
152
+ # 3. Handle missing values
153
+ linked_data = handle_missing_values(linked_data, trait)
154
+
155
+ # 4. Check for bias
156
+ trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
157
+
158
+ # 5. Validate and save cohort info
159
+ is_usable = validate_and_save_cohort_info(
160
+ is_final=True,
161
+ cohort=cohort,
162
+ info_path=json_path,
163
+ is_gene_available=True,
164
+ is_trait_available=True,
165
+ is_biased=trait_biased,
166
+ df=linked_data,
167
+ note="Study examining transcriptome profiles in rheumatoid arthritis."
168
+ )
169
+
170
+ # 6. Save if usable
171
+ if is_usable:
172
+ linked_data.to_csv(out_data_file)
p3/preprocess/Rheumatoid_Arthritis/code/GSE236924.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Rheumatoid_Arthritis"
6
+ cohort = "GSE236924"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Rheumatoid_Arthritis"
10
+ in_cohort_dir = "../DATA/GEO/Rheumatoid_Arthritis/GSE236924"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/GSE236924.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/gene_data/GSE236924.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/clinical_data/GSE236924.csv"
16
+ json_path = "./output/preprocess/3/Rheumatoid_Arthritis/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file)
23
+
24
+ # Get unique values per clinical feature
25
+ sample_characteristics = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Dataset Background Information:")
29
+ print(f"{background_info}\n")
30
+
31
+ # Print sample characteristics
32
+ print("Sample Characteristics:")
33
+ for feature, values in sample_characteristics.items():
34
+ print(f"Feature: {feature}")
35
+ print(f"Values: {values}\n")
36
+ # 1. Gene Expression Data
37
+ # From background, this is a gene array study of joint tissue comparing RA, OA and control
38
+ # So gene expression data should be available
39
+ is_gene_available = True
40
+
41
+ # 2.1 Data Availability
42
+ # Disease status (trait) is in row 0
43
+ trait_row = 0
44
+
45
+ # No age data available
46
+ age_row = None
47
+
48
+ # No gender data available
49
+ gender_row = None
50
+
51
+ # 2.2 Data Type Conversion Functions
52
+ def convert_trait(value):
53
+ """Convert trait values to binary (RA=1, non-RA=0)"""
54
+ if not isinstance(value, str):
55
+ return None
56
+ val = value.split(': ')[-1].strip().upper()
57
+ if val == 'RA':
58
+ return 1
59
+ elif val in ['OA', 'CONTROL']:
60
+ return 0
61
+ return None
62
+
63
+ def convert_age(value):
64
+ """Not used since age data not available"""
65
+ return None
66
+
67
+ def convert_gender(value):
68
+ """Not used since gender data not available"""
69
+ return None
70
+
71
+ # 3. Save initial metadata
72
+ validate_and_save_cohort_info(is_final=False,
73
+ cohort=cohort,
74
+ info_path=json_path,
75
+ is_gene_available=is_gene_available,
76
+ is_trait_available=trait_row is not None)
77
+
78
+ # 4. Extract clinical features since trait data is available
79
+ clinical_df = geo_select_clinical_features(clinical_data,
80
+ trait=trait,
81
+ trait_row=trait_row,
82
+ convert_trait=convert_trait)
83
+
84
+ # Preview the extracted features
85
+ print(preview_df(clinical_df))
86
+
87
+ # Save clinical data
88
+ clinical_df.to_csv(out_clinical_data_file)
89
+ # Get file paths
90
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
91
+
92
+ # Extract gene expression data from matrix file
93
+ gene_data = get_genetic_data(matrix_file)
94
+
95
+ # Print first 20 row IDs and shape of data to help debug
96
+ print("Shape of gene expression data:", gene_data.shape)
97
+ print("\nFirst few rows of data:")
98
+ print(gene_data.head())
99
+ print("\nFirst 20 gene/probe identifiers:")
100
+ print(gene_data.index[:20])
101
+
102
+ # Inspect a snippet of raw file to verify identifier format
103
+ import gzip
104
+ with gzip.open(matrix_file, 'rt', encoding='utf-8') as f:
105
+ lines = []
106
+ for i, line in enumerate(f):
107
+ if "!series_matrix_table_begin" in line:
108
+ # Get the next 5 lines after the marker
109
+ for _ in range(5):
110
+ lines.append(next(f).strip())
111
+ break
112
+ print("\nFirst few lines after matrix marker in raw file:")
113
+ for line in lines:
114
+ print(line)
115
+ # Gene identifiers in this GEO dataset appear to be Affymetrix probe IDs rather than gene symbols
116
+ # This is indicated by the format like "1007_s_at", "1053_at" etc.
117
+ requires_gene_mapping = True
118
+ # Extract gene annotation data
119
+ gene_metadata = get_gene_annotation(soft_file)
120
+
121
+ # Preview the annotation data
122
+ print("Column names:", gene_metadata.columns.tolist())
123
+ print("\nFirst few rows preview:")
124
+ print(preview_df(gene_metadata))
125
+ # 1. Gene identifiers are in 'ID' column, gene symbols in 'Gene Symbol' column
126
+ # Extract mapping info
127
+ mapping_data = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='Gene Symbol')
128
+
129
+ # 2. Apply the mapping to convert probe-level measurements to gene-level expression
130
+ gene_data = apply_gene_mapping(gene_data, mapping_data)
131
+
132
+ # 3. Save the gene expression data
133
+ gene_data.to_csv(out_gene_data_file)
134
+ # 1. Normalize gene symbols
135
+ gene_data = normalize_gene_symbols_in_index(gene_data)
136
+ gene_data.to_csv(out_gene_data_file)
137
+
138
+ # 2. Link clinical and genetic data
139
+ linked_data = geo_link_clinical_genetic_data(clinical_df, gene_data)
140
+
141
+ # 3. Handle missing values
142
+ linked_data = handle_missing_values(linked_data, trait)
143
+
144
+ # 4. Check for bias
145
+ trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
146
+
147
+ # 5. Validate and save cohort info
148
+ is_usable = validate_and_save_cohort_info(
149
+ is_final=True,
150
+ cohort=cohort,
151
+ info_path=json_path,
152
+ is_gene_available=True,
153
+ is_trait_available=True,
154
+ is_biased=trait_biased,
155
+ df=linked_data,
156
+ note="Study examining transcriptome profiles in rheumatoid arthritis."
157
+ )
158
+
159
+ # 6. Save if usable
160
+ if is_usable:
161
+ linked_data.to_csv(out_data_file)
p3/preprocess/Rheumatoid_Arthritis/code/GSE42842.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Rheumatoid_Arthritis"
6
+ cohort = "GSE42842"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Rheumatoid_Arthritis"
10
+ in_cohort_dir = "../DATA/GEO/Rheumatoid_Arthritis/GSE42842"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/GSE42842.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/gene_data/GSE42842.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/clinical_data/GSE42842.csv"
16
+ json_path = "./output/preprocess/3/Rheumatoid_Arthritis/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file)
23
+
24
+ # Get unique values per clinical feature
25
+ sample_characteristics = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Dataset Background Information:")
29
+ print(f"{background_info}\n")
30
+
31
+ # Print sample characteristics
32
+ print("Sample Characteristics:")
33
+ for feature, values in sample_characteristics.items():
34
+ print(f"Feature: {feature}")
35
+ print(f"Values: {values}\n")
36
+ # 1. Gene Expression Data Availability
37
+ # Since Series_overall_design mentions two color experiments, this is a gene expression microarray dataset
38
+ is_gene_available = True
39
+
40
+ # 2.1 Data Availability
41
+ # Feature 2 shows disease state, which indicates RA vs non-RA
42
+ trait_row = 2
43
+ # Age is not available in sample characteristics
44
+ age_row = None
45
+ # Gender is available in Feature 0
46
+ gender_row = 0
47
+
48
+ # 2.2 Data Type Conversion Functions
49
+ def convert_trait(x):
50
+ """Convert disease state to binary"""
51
+ if not isinstance(x, str):
52
+ return None
53
+ value = x.split(': ')[1].lower() if ': ' in x else x.lower()
54
+ if 'rheumatoid arthritis' in value:
55
+ return 1
56
+ return None
57
+
58
+ def convert_gender(x):
59
+ """Convert gender to binary (0=female, 1=male)"""
60
+ if not isinstance(x, str):
61
+ return None
62
+ value = x.split(': ')[1].lower() if ': ' in x else x.lower()
63
+ if value == 'f':
64
+ return 0
65
+ elif value == 'm':
66
+ return 1
67
+ return None
68
+
69
+ convert_age = None
70
+
71
+ # 3. Save initial metadata
72
+ validate_and_save_cohort_info(
73
+ is_final=False,
74
+ cohort=cohort,
75
+ info_path=json_path,
76
+ is_gene_available=is_gene_available,
77
+ is_trait_available=trait_row is not None
78
+ )
79
+
80
+ # 4. Extract clinical features
81
+ if trait_row is not None:
82
+ selected_clinical = geo_select_clinical_features(
83
+ clinical_df=clinical_data,
84
+ trait=trait,
85
+ trait_row=trait_row,
86
+ convert_trait=convert_trait,
87
+ age_row=age_row,
88
+ convert_age=convert_age,
89
+ gender_row=gender_row,
90
+ convert_gender=convert_gender
91
+ )
92
+
93
+ # Preview the data
94
+ print("Preview of selected clinical features:")
95
+ print(preview_df(selected_clinical))
96
+
97
+ # Save to CSV
98
+ selected_clinical.to_csv(out_clinical_data_file)
99
+ # Get file paths
100
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
101
+
102
+ # Extract gene expression data from matrix file
103
+ gene_data = get_genetic_data(matrix_file)
104
+
105
+ # Print first 20 row IDs and shape of data to help debug
106
+ print("Shape of gene expression data:", gene_data.shape)
107
+ print("\nFirst few rows of data:")
108
+ print(gene_data.head())
109
+ print("\nFirst 20 gene/probe identifiers:")
110
+ print(gene_data.index[:20])
111
+
112
+ # Inspect a snippet of raw file to verify identifier format
113
+ import gzip
114
+ with gzip.open(matrix_file, 'rt', encoding='utf-8') as f:
115
+ lines = []
116
+ for i, line in enumerate(f):
117
+ if "!series_matrix_table_begin" in line:
118
+ # Get the next 5 lines after the marker
119
+ for _ in range(5):
120
+ lines.append(next(f).strip())
121
+ break
122
+ print("\nFirst few lines after matrix marker in raw file:")
123
+ for line in lines:
124
+ print(line)
125
+ # The gene identifiers are just numerical indices (1,2,3...)
126
+ # They are not human gene symbols and need to be mapped
127
+ requires_gene_mapping = True
128
+ # Extract gene annotation data
129
+ gene_annotation = get_gene_annotation(soft_file)
130
+
131
+ # Preview annotation data
132
+ print("Gene annotation preview:")
133
+ print(preview_df(gene_annotation))
134
+
135
+ # Check if gene annotation data is usable by looking at gene-related columns
136
+ gene_cols = ['GENE', 'GENE_SYMBOL', 'GENE_NAME', 'REFSEQ', 'GB_ACC', 'UNIGENE_ID', 'ENSEMBL_ID']
137
+ has_gene_info = any(gene_annotation[col].notna().any() for col in gene_cols)
138
+
139
+ if not has_gene_info:
140
+ # Save metadata indicating this dataset is not usable
141
+ validate_and_save_cohort_info(
142
+ is_final=False,
143
+ cohort=cohort,
144
+ info_path=json_path,
145
+ is_gene_available=False, # Set to False since gene annotations are missing
146
+ is_trait_available=True,
147
+ note="Dataset lacks proper gene annotations - all gene identifier fields are empty"
148
+ )
149
+
150
+ print("\nWARNING: This dataset lacks proper gene annotations.")
151
+ print("All gene identifier fields (GENE, GENE_SYMBOL, REFSEQ, etc.) are empty.")
152
+ print("Stopping processing as gene mapping cannot be performed without annotations.")
153
+
154
+ # Exit further processing as dataset is not suitable
155
+ raise ValueError("Dataset lacks proper gene annotations")
p3/preprocess/Rheumatoid_Arthritis/code/GSE97475.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Rheumatoid_Arthritis"
6
+ cohort = "GSE97475"
7
+
8
+ # Input paths
9
+ in_trait_dir = "../DATA/GEO/Rheumatoid_Arthritis"
10
+ in_cohort_dir = "../DATA/GEO/Rheumatoid_Arthritis/GSE97475"
11
+
12
+ # Output paths
13
+ out_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/GSE97475.csv"
14
+ out_gene_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/gene_data/GSE97475.csv"
15
+ out_clinical_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/clinical_data/GSE97475.csv"
16
+ json_path = "./output/preprocess/3/Rheumatoid_Arthritis/cohort_info.json"
17
+
18
+ # Get file paths
19
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
20
+
21
+ # Extract background info and clinical data
22
+ background_info, clinical_data = get_background_and_clinical_data(matrix_file)
23
+
24
+ # Get unique values per clinical feature
25
+ sample_characteristics = get_unique_values_by_row(clinical_data)
26
+
27
+ # Print background info
28
+ print("Dataset Background Information:")
29
+ print(f"{background_info}\n")
30
+
31
+ # Print sample characteristics
32
+ print("Sample Characteristics:")
33
+ for feature, values in sample_characteristics.items():
34
+ print(f"Feature: {feature}")
35
+ print(f"Values: {values}\n")
36
+ # 1. Gene Expression Data Availability
37
+ # Based on the series title and description, this is a gene expression study that includes PBMCs RNA data
38
+ is_gene_available = True
39
+
40
+ # 2.1 Data Availability
41
+ # Trait: Not available since this is healthy control data
42
+ trait_row = None
43
+
44
+ # Age: Available in demographics
45
+ age_row = 81
46
+
47
+ # Gender: Available in demographics
48
+ gender_row = 118
49
+
50
+ # 2.2 Data Type Conversion Functions
51
+ def convert_trait(x):
52
+ return None
53
+
54
+ def convert_age(x):
55
+ if pd.isna(x):
56
+ return None
57
+ value = x.split(': ')[1]
58
+ try:
59
+ return float(value)
60
+ except:
61
+ return None
62
+
63
+ def convert_gender(x):
64
+ if pd.isna(x):
65
+ return None
66
+ value = x.split(': ')[1].lower()
67
+ if 'female' in value:
68
+ return 0
69
+ elif 'male' in value:
70
+ return 1
71
+ return None
72
+
73
+ # 3. Save Metadata
74
+ is_trait_available = trait_row is not None
75
+ validate_and_save_cohort_info(is_final=False, cohort=cohort, info_path=json_path,
76
+ is_gene_available=is_gene_available,
77
+ is_trait_available=is_trait_available)
78
+ # Get file paths
79
+ soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
80
+
81
+ # Extract gene expression data from matrix file
82
+ gene_data = get_genetic_data(matrix_file)
83
+
84
+ # Print first 20 row IDs and shape of data to help debug
85
+ print("Shape of gene expression data:", gene_data.shape)
86
+ print("\nFirst few rows of data:")
87
+ print(gene_data.head())
88
+ print("\nFirst 20 gene/probe identifiers:")
89
+ print(gene_data.index[:20])
90
+
91
+ # Inspect a snippet of raw file to verify identifier format
92
+ import gzip
93
+ with gzip.open(matrix_file, 'rt', encoding='utf-8') as f:
94
+ lines = []
95
+ for i, line in enumerate(f):
96
+ if "!series_matrix_table_begin" in line:
97
+ # Get the next 5 lines after the marker
98
+ for _ in range(5):
99
+ lines.append(next(f).strip())
100
+ break
101
+ print("\nFirst few lines after matrix marker in raw file:")
102
+ for line in lines:
103
+ print(line)
104
+ requires_gene_mapping = False
105
+ # 1. Normalize gene symbols and save
106
+ gene_data = normalize_gene_symbols_in_index(gene_data)
107
+ gene_data.to_csv(out_gene_data_file)
108
+
109
+ # Since trait_row is None (no trait data available), skip clinical data processing
110
+ # and data linking. Instead, just validate and save the cohort info.
111
+ is_usable = validate_and_save_cohort_info(
112
+ is_final=True,
113
+ cohort=cohort,
114
+ info_path=json_path,
115
+ is_gene_available=True,
116
+ is_trait_available=False, # We know trait is not available
117
+ is_biased=None, # No trait to check for bias
118
+ df=None,
119
+ note="Dataset contains gene expression profiles from healthy hepatitis B vaccine recipients, but lacks disease trait for comparison."
120
+ )
p3/preprocess/Rheumatoid_Arthritis/code/TCGA.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Path Configuration
2
+ from tools.preprocess import *
3
+
4
+ # Processing context
5
+ trait = "Rheumatoid_Arthritis"
6
+
7
+ # Input paths
8
+ tcga_root_dir = "../DATA/TCGA"
9
+
10
+ # Output paths
11
+ out_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/TCGA.csv"
12
+ out_gene_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/gene_data/TCGA.csv"
13
+ out_clinical_data_file = "./output/preprocess/3/Rheumatoid_Arthritis/clinical_data/TCGA.csv"
14
+ json_path = "./output/preprocess/3/Rheumatoid_Arthritis/cohort_info.json"
15
+
16
+ # Review available cohorts for asthma relevance
17
+ tcga_dirs = os.listdir(tcga_root_dir)
18
+ # Filter out non-directory files
19
+ tcga_dirs = [d for d in tcga_dirs if os.path.isdir(os.path.join(tcga_root_dir, d))]
20
+
21
+ # For asthma trait, none of the TCGA cancer cohorts are directly relevant
22
+ print(f"No suitable TCGA cancer cohort was found for the trait: {trait}")
23
+
24
+ # Save cohort info to mark this trait as completed
25
+ _ = validate_and_save_cohort_info(
26
+ is_final=False,
27
+ cohort="TCGA",
28
+ info_path=json_path,
29
+ is_gene_available=False,
30
+ is_trait_available=False
31
+ )
32
+ # Exit preprocessing as no suitable data exists
33
+ clinical_df = None
34
+ genetic_df = None
p3/preprocess/Rheumatoid_Arthritis/cohort_info.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"GSE97475": {"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}, "GSE42842": {"is_usable": false, "is_gene_available": false, "is_trait_available": true, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}, "GSE236924": {"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": 132, "note": "Study examining transcriptome profiles in rheumatoid arthritis."}, "GSE224842": {"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": 30, "note": "Study examining transcriptome profiles in rheumatoid arthritis."}, "GSE224330": {"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}, "GSE186963": {"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": 72, "note": "Study examining transcriptome profiles in rheumatoid arthritis."}, "GSE176440": {"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": 56, "note": "Study examining transcriptome profiles in rheumatoid arthritis."}, "GSE143153": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": false, "sample_size": 32, "note": "Study examining transcriptome profiles in rheumatoid arthritis."}, "GSE140161": {"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}, "GSE121894": {"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": 58, "note": "Study examining transcriptome profiles in rheumatoid arthritis."}, "TCGA": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}}
p3/preprocess/Rheumatoid_Arthritis/gene_data/GSE121894.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Rheumatoid_Arthritis/gene_data/GSE143153.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Rheumatoid_Arthritis/gene_data/GSE186963.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Rheumatoid_Arthritis/gene_data/GSE224330.csv ADDED
@@ -0,0 +1 @@
 
 
1
+ ID,GSM7019507,GSM7019508,GSM7019509,GSM7019510,GSM7019511,GSM7019512,GSM7019513,GSM7019514,GSM7019515,GSM7019516,GSM7019517,GSM7019518,GSM7019519,GSM7019520,GSM7019521,GSM7019522,GSM7019523,GSM7019524,GSM7019525,GSM7019526,GSM7019527,GSM7019528,GSM7019529,GSM7019530,GSM7019531,GSM7019532,GSM7019533,GSM7019534,GSM7019535,GSM7019536,GSM7019537
p3/preprocess/Rheumatoid_Arthritis/gene_data/GSE224842.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Sarcoma/GSE159848.csv ADDED
The diff for this file is too large to render. See raw diff
 
p3/preprocess/Sarcoma/clinical_data/GSE118336.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM3325490,GSM3325491,GSM3325492,GSM3325493,GSM3325494,GSM3325495,GSM3325496,GSM3325497,GSM3325498,GSM3325499,GSM3325500,GSM3325501,GSM3325502,GSM3325503,GSM3325504,GSM3325505,GSM3325506,GSM3325507,GSM3325508,GSM3325509,GSM3325510,GSM3325511,GSM3325512,GSM3325513,GSM3325514,GSM3325515,GSM3325516,GSM3325517,GSM3325518,GSM3325519,GSM3325520,GSM3325521,GSM3325522,GSM3325523,GSM3325524,GSM3325525,GSM3325526,GSM3325527,GSM3325528,GSM3325529,GSM3325530,GSM3325531,GSM3325532,GSM3325533,GSM3325534,GSM3325535,GSM3325536,GSM3325537,GSM3325538,GSM3325539,GSM3325540,GSM3325541,GSM3325542,GSM3325543,GSM3325544,GSM3325545,GSM3325546,GSM3325547,GSM3325548,GSM3325549
2
+ Sarcoma,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
p3/preprocess/Sarcoma/clinical_data/GSE133228.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ ,GSM4221667,GSM4221668,GSM4221669,GSM4221671,GSM4221673,GSM4221674,GSM4221675,GSM4221677,GSM4221678,GSM4221679,GSM4221680,GSM4221682,GSM4221683,GSM4221684,GSM4221685,GSM4221686,GSM4221687,GSM4221688,GSM4221689,GSM4221690,GSM4221691,GSM4221692,GSM4221693,GSM4221694,GSM4221695,GSM4221696,GSM4221697,GSM4221698,GSM4221699,GSM4221700,GSM4221701,GSM4221702,GSM4221703,GSM4221704,GSM4221705,GSM4221706,GSM4221707,GSM5252261,GSM5252262,GSM5252263,GSM5252264,GSM5252265,GSM5252266,GSM5252267,GSM5252268,GSM5252269,GSM5252270,GSM5252271,GSM5252272,GSM5252273,GSM5252274,GSM5252275,GSM5252276,GSM5252277,GSM5252278,GSM5252279,GSM5252280,GSM5252281,GSM5252282,GSM5252283,GSM5252284,GSM5252285,GSM5252286,GSM5252287,GSM5252288,GSM5252289,GSM5252290,GSM5252291,GSM5252292,GSM5252293,GSM5252294,GSM5252295,GSM5252296,GSM5252297,GSM5252298,GSM5252299,GSM5252300,GSM5252301,GSM5252302
2
+ Sarcoma,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
3
+ Age,3.0,11.0,4.0,11.0,25.0,13.0,4.0,15.0,11.0,11.0,19.0,8.0,13.0,20.0,19.0,15.0,24.0,11.0,16.0,11.0,14.0,13.0,5.0,13.0,37.0,15.0,26.0,10.0,35.0,23.0,17.0,11.0,12.0,9.0,0.0,10.0,5.0,9.0,11.0,4.0,11.0,8.0,5.0,25.0,36.0,10.0,14.0,27.0,1.0,15.0,18.0,8.0,13.0,29.0,19.0,13.0,8.0,6.0,23.0,19.0,15.0,17.0,12.0,5.0,12.0,14.0,13.0,28.0,14.0,31.0,6.0,1.0,3.0,4.0,7.0,5.0,16.0,31.0,26.0
4
+ Gender,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0
p3/preprocess/Sarcoma/clinical_data/GSE142162.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ ,GSM4221667,GSM4221668,GSM4221669,GSM4221671,GSM4221673,GSM4221674,GSM4221675,GSM4221677,GSM4221678,GSM4221679,GSM4221680,GSM4221682,GSM4221683,GSM4221684,GSM4221685,GSM4221686,GSM4221687,GSM4221688,GSM4221689,GSM4221690,GSM4221691,GSM4221692,GSM4221693,GSM4221694,GSM4221695,GSM4221696,GSM4221697,GSM4221698,GSM4221699,GSM4221700,GSM4221701,GSM4221702,GSM4221703,GSM4221704,GSM4221705,GSM4221706,GSM4221707,GSM5252261,GSM5252262,GSM5252263,GSM5252264,GSM5252265,GSM5252266,GSM5252267,GSM5252268,GSM5252269,GSM5252270,GSM5252271,GSM5252272,GSM5252273,GSM5252274,GSM5252275,GSM5252276,GSM5252277,GSM5252278,GSM5252279,GSM5252280,GSM5252281,GSM5252282,GSM5252283,GSM5252284,GSM5252285,GSM5252286,GSM5252287,GSM5252288,GSM5252289,GSM5252290,GSM5252291,GSM5252292,GSM5252293,GSM5252294,GSM5252295,GSM5252296,GSM5252297,GSM5252298,GSM5252299,GSM5252300,GSM5252301,GSM5252302
2
+ Sarcoma,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
3
+ Age,3.0,11.0,4.0,11.0,25.0,13.0,4.0,15.0,11.0,11.0,19.0,8.0,13.0,20.0,19.0,15.0,24.0,11.0,16.0,11.0,14.0,13.0,5.0,13.0,37.0,15.0,26.0,10.0,35.0,23.0,17.0,11.0,12.0,9.0,0.0,10.0,5.0,9.0,11.0,4.0,11.0,8.0,5.0,25.0,36.0,10.0,14.0,27.0,1.0,15.0,18.0,8.0,13.0,29.0,19.0,13.0,8.0,6.0,23.0,19.0,15.0,17.0,12.0,5.0,12.0,14.0,13.0,28.0,14.0,31.0,6.0,1.0,3.0,4.0,7.0,5.0,16.0,31.0,26.0
4
+ Gender,1.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0
p3/preprocess/Sarcoma/clinical_data/GSE159847.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ ,GSM4848266,GSM4848267,GSM4848268,GSM4848269,GSM4848270,GSM4848271,GSM4848272,GSM4848273,GSM4848274,GSM4848275,GSM4848276,GSM4848277,GSM4848278,GSM4848279,GSM4848280,GSM4848281,GSM4848282,GSM4848283,GSM4848284,GSM4848285,GSM4848286,GSM4848287,GSM4848288,GSM4848289,GSM4848290,GSM4848291,GSM4848292,GSM4848293,GSM4848294,GSM4848295,GSM4848296,GSM4848297,GSM4848298,GSM4848299,GSM4848300,GSM4848301,GSM4848302,GSM4848303,GSM4848304,GSM4848305,GSM4848306,GSM4848307,GSM4848308,GSM4848309,GSM4848310,GSM4848311,GSM4848312,GSM4848313,GSM4848314,GSM4848315,GSM4848316,GSM4848317,GSM4848318,GSM4848319,GSM4848320,GSM4848321,GSM4848322,GSM4848323,GSM4848324,GSM4848325,GSM4848326,GSM4848327,GSM4848328,GSM4848329,GSM4848330,GSM4848331,GSM4848332,GSM4848333,GSM4848334,GSM4848335,GSM4848336,GSM4848337,GSM4848338,GSM4848339,GSM4848340,GSM4848341,GSM4848342,GSM4848343,GSM4848344,GSM4848345,GSM4848346,GSM4848347,GSM4848348,GSM4848349,GSM4848350,GSM4848351,GSM4848352
2
+ Sarcoma,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0
3
+ Age,73.0,45.0,62.0,60.0,80.0,57.0,59.0,68.0,69.0,51.0,63.0,57.0,35.0,77.0,53.0,66.0,58.0,74.0,60.0,37.0,61.0,86.0,55.0,54.0,82.0,55.0,55.0,84.0,54.0,25.0,77.0,50.0,76.0,69.0,79.0,62.0,74.0,54.0,32.0,56.0,71.0,63.0,63.0,61.0,88.0,75.0,51.0,64.0,55.0,72.0,50.0,39.0,73.0,46.0,58.0,41.0,92.0,71.0,36.0,33.0,57.0,16.0,41.0,62.0,28.0,16.0,75.0,83.0,65.0,59.0,47.0,54.0,69.0,71.0,74.0,64.0,68.0,78.0,77.0,64.0,76.0,65.0,67.0,75.0,83.0,81.0,82.0
4
+ Gender,1.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0
p3/preprocess/Sarcoma/clinical_data/GSE159848.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ ,GSM4848353,GSM4848354,GSM4848355,GSM4848356,GSM4848357,GSM4848358,GSM4848359,GSM4848360,GSM4848361,GSM4848362,GSM4848363,GSM4848364,GSM4848365,GSM4848366,GSM4848367,GSM4848368,GSM4848369,GSM4848370,GSM4848371,GSM4848372,GSM4848373,GSM4848374,GSM4848375,GSM4848376,GSM4848377,GSM4848378,GSM4848379,GSM4848380,GSM4848381,GSM4848382,GSM4848383,GSM4848384,GSM4848385,GSM4848386,GSM4848387,GSM4848388,GSM4848389,GSM4848390,GSM4848391,GSM4848392,GSM4848393,GSM4848394,GSM4848395,GSM4848396,GSM4848397,GSM4848398,GSM4848399,GSM4848400,GSM4848401,GSM4848402
2
+ Sarcoma,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,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0
3
+ Age,44.0,67.0,54.0,82.0,47.0,32.0,57.0,47.0,60.0,51.0,45.0,38.0,16.0,52.0,60.0,46.0,58.0,20.0,39.0,43.0,31.0,71.0,49.0,45.0,28.0,29.0,75.0,74.0,44.0,40.0,54.0,59.0,44.0,42.0,39.0,43.0,35.0,33.0,39.0,36.0,35.0,42.0,44.0,41.0,56.0,83.0,40.0,40.0,45.0,47.0
4
+ Gender,1.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0
p3/preprocess/Sarcoma/clinical_data/GSE162785.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ,GSM4959871,GSM4959872,GSM4959873,GSM4959874,GSM4959875,GSM4959876,GSM4959877,GSM4959878,GSM4959879,GSM4959880,GSM4959881,GSM4959882,GSM4959883,GSM4959884,GSM4959885,GSM4959886,GSM4959887,GSM4959888,GSM4959889,GSM4959890,GSM4959891,GSM4959892,GSM4959893,GSM4959894,GSM4959895,GSM4959896,GSM4959897,GSM4959898,GSM4959899,GSM4959900,GSM4959901,GSM4959902,GSM4959903,GSM4959904,GSM4959905,GSM4959906,GSM4959907,GSM4959908,GSM4959909,GSM4959910,GSM4959911,GSM4959912
2
+ Sarcoma,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0