Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +7 -0
- p1/preprocess/Adrenocortical_Cancer/gene_data/GSE68950.csv +3 -0
- p1/preprocess/Alopecia/GSE66664.csv +3 -0
- p1/preprocess/Alopecia/gene_data/GSE148346.csv +3 -0
- p1/preprocess/Alopecia/gene_data/GSE18876.csv +3 -0
- p1/preprocess/Alopecia/gene_data/GSE66664.csv +3 -0
- p1/preprocess/Alzheimers_Disease/GSE122063.csv +3 -0
- p1/preprocess/Alzheimers_Disease/gene_data/GSE137202.csv +0 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/GSE118336.py +230 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/GSE26927.py +207 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/GSE52937.py +141 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/GSE61322.py +150 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/GSE68608.py +157 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/GSE95810.py +105 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/TCGA.py +57 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE118336.csv +1 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE139384.csv +1 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE212134.csv +1 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE26927.csv +1 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE52937.csv +1 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE61322.csv +1 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE68607.csv +1 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE68608.csv +1 -0
- p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE95810.csv +1 -0
- p1/preprocess/Angelman_Syndrome/code/GSE43900.py +169 -0
- p1/preprocess/Angelman_Syndrome/code/TCGA.py +57 -0
- p1/preprocess/Angelman_Syndrome/cohort_info.json +1 -0
- p1/preprocess/Angelman_Syndrome/gene_data/GSE43900.csv +1 -0
- p1/preprocess/Aniridia/clinical_data/GSE137996.csv +4 -0
- p1/preprocess/Aniridia/clinical_data/GSE137997.csv +4 -0
- p1/preprocess/Aniridia/code/GSE137996.py +170 -0
- p1/preprocess/Aniridia/code/GSE137997.py +167 -0
- p1/preprocess/Aniridia/code/GSE204791.py +183 -0
- p1/preprocess/Aniridia/code/TCGA.py +57 -0
- p1/preprocess/Aniridia/cohort_info.json +1 -0
- p1/preprocess/Aniridia/gene_data/GSE137996.csv +1 -0
- p1/preprocess/Aniridia/gene_data/GSE137997.csv +1 -0
- p1/preprocess/Aniridia/gene_data/GSE204791.csv +1 -0
- p1/preprocess/Ankylosing_Spondylitis/clinical_data/GSE25101.csv +2 -0
- p1/preprocess/Ankylosing_Spondylitis/clinical_data/GSE73754.csv +4 -0
- p1/preprocess/Ankylosing_Spondylitis/code/GSE25101.py +191 -0
- p1/preprocess/Ankylosing_Spondylitis/code/GSE73754.py +183 -0
- p1/preprocess/Ankylosing_Spondylitis/code/TCGA.py +57 -0
- p1/preprocess/Ankylosing_Spondylitis/cohort_info.json +1 -0
- p1/preprocess/Ankylosing_Spondylitis/gene_data/GSE25101.csv +1 -0
- p1/preprocess/Ankylosing_Spondylitis/gene_data/GSE73754.csv +1 -0
- p1/preprocess/Anorexia_Nervosa/clinical_data/GSE60190.csv +4 -0
- p1/preprocess/Anorexia_Nervosa/code/GSE60190.py +186 -0
- p1/preprocess/Anorexia_Nervosa/code/TCGA.py +57 -0
- p1/preprocess/Anorexia_Nervosa/cohort_info.json +1 -0
.gitattributes
CHANGED
@@ -940,3 +940,10 @@ p1/preprocess/Von_Hippel_Lindau/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs
|
|
940 |
p1/preprocess/Allergies/gene_data/GSE185658.csv filter=lfs diff=lfs merge=lfs -text
|
941 |
p1/preprocess/Thyroid_Cancer/TCGA.csv filter=lfs diff=lfs merge=lfs -text
|
942 |
p1/preprocess/Allergies/gene_data/GSE230164.csv filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
940 |
p1/preprocess/Allergies/gene_data/GSE185658.csv filter=lfs diff=lfs merge=lfs -text
|
941 |
p1/preprocess/Thyroid_Cancer/TCGA.csv filter=lfs diff=lfs merge=lfs -text
|
942 |
p1/preprocess/Allergies/gene_data/GSE230164.csv filter=lfs diff=lfs merge=lfs -text
|
943 |
+
p1/preprocess/Alopecia/gene_data/GSE148346.csv filter=lfs diff=lfs merge=lfs -text
|
944 |
+
p1/preprocess/Alopecia/gene_data/GSE18876.csv filter=lfs diff=lfs merge=lfs -text
|
945 |
+
p1/preprocess/Adrenocortical_Cancer/gene_data/GSE68950.csv filter=lfs diff=lfs merge=lfs -text
|
946 |
+
p1/preprocess/Thyroid_Cancer/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
|
947 |
+
p1/preprocess/Alopecia/GSE66664.csv filter=lfs diff=lfs merge=lfs -text
|
948 |
+
p1/preprocess/Alopecia/gene_data/GSE66664.csv filter=lfs diff=lfs merge=lfs -text
|
949 |
+
p1/preprocess/Alzheimers_Disease/GSE122063.csv filter=lfs diff=lfs merge=lfs -text
|
p1/preprocess/Adrenocortical_Cancer/gene_data/GSE68950.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:54bc2618961cab9be52e2e0e50a219b5df5559caeddf32ce819e42341796dec5
|
3 |
+
size 65411017
|
p1/preprocess/Alopecia/GSE66664.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:98f97b3a973a426ec32ccf4bf8745797511a861b23854255500849cc35e311f9
|
3 |
+
size 36070366
|
p1/preprocess/Alopecia/gene_data/GSE148346.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:830556682e0675dd524d2e1f986ec941a14de052b109af704c73ffd79667a6b4
|
3 |
+
size 20446260
|
p1/preprocess/Alopecia/gene_data/GSE18876.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1f138e02b190833ca491eb19bb4c1025ed390ad8e84765f26124c1c4c0a6ab1e
|
3 |
+
size 21422913
|
p1/preprocess/Alopecia/gene_data/GSE66664.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3c4dac871fce23933c4db6847907a61bd43ef30584b1c524a208cafb30b5f71e
|
3 |
+
size 36069801
|
p1/preprocess/Alzheimers_Disease/GSE122063.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:15c391c4a016201750999ff1cd0c79ca3ecd1578549d0d847bb6ce48a91835de
|
3 |
+
size 34271968
|
p1/preprocess/Alzheimers_Disease/gene_data/GSE137202.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/GSE118336.py
ADDED
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Amyotrophic_Lateral_Sclerosis"
|
6 |
+
cohort = "GSE118336"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Amyotrophic_Lateral_Sclerosis"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Amyotrophic_Lateral_Sclerosis/GSE118336"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/GSE118336.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/gene_data/GSE118336.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/clinical_data/GSE118336.csv"
|
16 |
+
json_path = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# Step 1: Determine if gene expression data is available
|
43 |
+
# Based on the series description (HTA2.0 array - a gene expression microarray), we assume it contains gene expression data.
|
44 |
+
is_gene_available = True
|
45 |
+
|
46 |
+
# Step 2: Identify availability of trait, age, and gender, and set row indices accordingly
|
47 |
+
# From the sample characteristics dictionary:
|
48 |
+
# {
|
49 |
+
# 0: ['cell type: iPSC-MN'],
|
50 |
+
# 1: ['genotype: FUSWT/WT', 'genotype: FUSWT/H517D', 'genotype: FUSH517D/H517D'],
|
51 |
+
# 2: ['time (differentiation from motor neuron precursor): 2 weeks', 'time (differentiation from motor neuron precursor): 4 weeks']
|
52 |
+
# }
|
53 |
+
# We interpret row=1 as the ALS status (presence/absence of mutation) => trait
|
54 |
+
trait_row = 1
|
55 |
+
|
56 |
+
# There's no clear row for age or gender
|
57 |
+
age_row = None
|
58 |
+
gender_row = None
|
59 |
+
|
60 |
+
# Step 2.2: Define conversion functions for trait, age, and gender
|
61 |
+
|
62 |
+
def convert_trait(value: str):
|
63 |
+
# Typically "genotype: something"
|
64 |
+
parts = value.split(':', 1)
|
65 |
+
if len(parts) < 2:
|
66 |
+
return None
|
67 |
+
val = parts[1].strip()
|
68 |
+
# Map genotype to binary: "FUSWT/WT" -> 0 (control), else -> 1 (ALS)
|
69 |
+
if val == "FUSWT/WT":
|
70 |
+
return 0
|
71 |
+
elif "H517D" in val:
|
72 |
+
return 1
|
73 |
+
else:
|
74 |
+
return None
|
75 |
+
|
76 |
+
def convert_age(value: str):
|
77 |
+
# Not applicable here, return None
|
78 |
+
return None
|
79 |
+
|
80 |
+
def convert_gender(value: str):
|
81 |
+
# Not applicable here, return None
|
82 |
+
return None
|
83 |
+
|
84 |
+
# Step 3: Initial filtering for dataset usability
|
85 |
+
is_trait_available = (trait_row is not None)
|
86 |
+
is_usable = validate_and_save_cohort_info(
|
87 |
+
is_final=False,
|
88 |
+
cohort=cohort,
|
89 |
+
info_path=json_path,
|
90 |
+
is_gene_available=is_gene_available,
|
91 |
+
is_trait_available=is_trait_available
|
92 |
+
)
|
93 |
+
|
94 |
+
# Step 4: Clinical Feature Extraction (only if trait data is available)
|
95 |
+
if trait_row is not None:
|
96 |
+
# Here we assume 'clinical_data' is already loaded as a pandas DataFrame
|
97 |
+
selected_clinical_df = geo_select_clinical_features(
|
98 |
+
clinical_data,
|
99 |
+
trait=trait,
|
100 |
+
trait_row=trait_row,
|
101 |
+
convert_trait=convert_trait,
|
102 |
+
age_row=age_row,
|
103 |
+
convert_age=convert_age,
|
104 |
+
gender_row=gender_row,
|
105 |
+
convert_gender=convert_gender
|
106 |
+
)
|
107 |
+
|
108 |
+
# Preview the extracted clinical data
|
109 |
+
preview = preview_df(selected_clinical_df, n=5)
|
110 |
+
print("Clinical Data Preview:", preview)
|
111 |
+
|
112 |
+
# Save clinical data to CSV
|
113 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
114 |
+
# STEP3
|
115 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
116 |
+
gene_data = get_genetic_data(matrix_file)
|
117 |
+
|
118 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
119 |
+
print(gene_data.index[:20])
|
120 |
+
# Based on biomedical knowledge, these "xxx_st" identifiers appear to be probe set IDs (likely from an Affymetrix array),
|
121 |
+
# not human gene symbols. Therefore, they require mapping to gene symbols.
|
122 |
+
|
123 |
+
# Conclusion:
|
124 |
+
requires_gene_mapping = True
|
125 |
+
# STEP5
|
126 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
127 |
+
gene_annotation = get_gene_annotation(soft_file)
|
128 |
+
|
129 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
130 |
+
print("Gene annotation preview:")
|
131 |
+
print(preview_df(gene_annotation))
|
132 |
+
# STEP 6: Gene Identifier Mapping (Revised)
|
133 |
+
|
134 |
+
# We will attempt to map the probe identifiers in gene_data (e.g. "2824546_st") to those in the
|
135 |
+
# gene_annotation DataFrame (e.g. "TC01000001.hg.1"). The original attempt concluded there
|
136 |
+
# was no match and skipped the mapping entirely. Here, we'll demonstrate a more thorough check:
|
137 |
+
# 1) Direct match
|
138 |
+
# 2) Partial match by stripping "_st"
|
139 |
+
# If no matches are found, we conclude that no mapping can be performed and retain the original data.
|
140 |
+
|
141 |
+
# Copy the annotation so we can manipulate it safely
|
142 |
+
annot_df = gene_annotation.copy()
|
143 |
+
|
144 |
+
# Identify columns to use for probe ID and gene assignment (gene symbol or similar).
|
145 |
+
probe_col = 'ID'
|
146 |
+
gene_col = 'gene_assignment'
|
147 |
+
|
148 |
+
# Create the mapping DataFrame
|
149 |
+
mapping_df = get_gene_mapping(
|
150 |
+
annotation=annot_df,
|
151 |
+
prob_col=probe_col,
|
152 |
+
gene_col=gene_col
|
153 |
+
)
|
154 |
+
|
155 |
+
# 1) Direct match between expression index and annotation ID:
|
156 |
+
expr_ids = set(gene_data.index)
|
157 |
+
annot_ids = set(mapping_df['ID'])
|
158 |
+
common_ids = expr_ids.intersection(annot_ids)
|
159 |
+
|
160 |
+
if len(common_ids) > 0:
|
161 |
+
# Some probes match directly; proceed with standard mapping
|
162 |
+
print("Direct matches found. Proceeding with gene symbol mapping using apply_gene_mapping...")
|
163 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
164 |
+
else:
|
165 |
+
# 2) Attempt partial match: removing '_st' from expression IDs before checking
|
166 |
+
print("No direct matches found. Attempting partial match by stripping '_st'...")
|
167 |
+
# Create a dictionary to map stripped IDs -> original IDs
|
168 |
+
stripped_to_orig = {}
|
169 |
+
for idx in gene_data.index:
|
170 |
+
stripped = idx.replace('_st', '').strip()
|
171 |
+
stripped_to_orig[stripped] = idx
|
172 |
+
|
173 |
+
# Re-check intersection
|
174 |
+
new_expr_ids = set(stripped_to_orig.keys())
|
175 |
+
common_stripped = new_expr_ids.intersection(annot_ids)
|
176 |
+
|
177 |
+
if len(common_stripped) > 0:
|
178 |
+
print("Partial matches found. Proceeding with gene symbol mapping...")
|
179 |
+
# Temporarily rename expression DataFrame index to the stripped version
|
180 |
+
gene_data_tmp = gene_data.copy()
|
181 |
+
gene_data_tmp.index = gene_data_tmp.index.map(lambda x: x.replace('_st', '').strip())
|
182 |
+
|
183 |
+
# Perform mapping with apply_gene_mapping
|
184 |
+
gene_data_mapped = apply_gene_mapping(gene_data_tmp, mapping_df)
|
185 |
+
|
186 |
+
# We revert the index to some user-friendly format (e.g., the gene symbols returned)
|
187 |
+
# but "apply_gene_mapping" already sets the new DataFrame's index to gene symbols.
|
188 |
+
gene_data = gene_data_mapped
|
189 |
+
else:
|
190 |
+
# 3) Confirm no mapping possible
|
191 |
+
print("No direct or partial matches found. No reliable way to map these probe IDs.")
|
192 |
+
print("Retaining the original gene_data DataFrame without mapping.")
|
193 |
+
|
194 |
+
# Display final shape and top rows
|
195 |
+
print("Final gene_data shape:", gene_data.shape)
|
196 |
+
print(gene_data.head(5))
|
197 |
+
# STEP 7: Data Normalization and Linking
|
198 |
+
|
199 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
200 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
201 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
202 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
203 |
+
|
204 |
+
# 2. Link the clinical and genetic data on sample IDs
|
205 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
206 |
+
|
207 |
+
# 3. Handle missing values, removing or imputing as instructed
|
208 |
+
linked_data = handle_missing_values(linked_data, trait)
|
209 |
+
|
210 |
+
# 4. Determine whether the trait (and potentially other features) is severely biased.
|
211 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
212 |
+
|
213 |
+
# 5. Conduct final quality validation and save metadata
|
214 |
+
is_usable = validate_and_save_cohort_info(
|
215 |
+
is_final=True,
|
216 |
+
cohort=cohort,
|
217 |
+
info_path=json_path,
|
218 |
+
is_gene_available=True,
|
219 |
+
is_trait_available=True, # We do have a trait column
|
220 |
+
is_biased=trait_biased,
|
221 |
+
df=linked_data,
|
222 |
+
note="Cohort data successfully processed with trait-based analysis."
|
223 |
+
)
|
224 |
+
|
225 |
+
# 6. If the dataset is usable, save the final linked data
|
226 |
+
if is_usable:
|
227 |
+
linked_data.to_csv(out_data_file, index=True)
|
228 |
+
print(f"Saved final linked data to {out_data_file}")
|
229 |
+
else:
|
230 |
+
print("The dataset is not usable for trait-based association. Skipping final output.")
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/GSE26927.py
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Amyotrophic_Lateral_Sclerosis"
|
6 |
+
cohort = "GSE26927"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Amyotrophic_Lateral_Sclerosis"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Amyotrophic_Lateral_Sclerosis/GSE26927"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/GSE26927.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/gene_data/GSE26927.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/clinical_data/GSE26927.csv"
|
16 |
+
json_path = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# 1. Gene Expression Data Availability
|
43 |
+
is_gene_available = True # Based on the series summary, this dataset uses Illumina whole genome array.
|
44 |
+
|
45 |
+
# 2. Variable Availability
|
46 |
+
# Checking the sample characteristics dictionary, we found:
|
47 |
+
# - trait_row = 0, because row 0 has "disease: ..." entries including "Amyotrophic lateral sclerosis".
|
48 |
+
# - age_row = 2, because row 2 has "age at death (in years): ..." entries.
|
49 |
+
# - gender_row = 1, because row 1 has "gender: M" or "gender: F".
|
50 |
+
trait_row = 0
|
51 |
+
age_row = 2
|
52 |
+
gender_row = 1
|
53 |
+
|
54 |
+
# 2.2 Data Type Conversions
|
55 |
+
def convert_trait(value: str) -> int:
|
56 |
+
"""
|
57 |
+
Convert disease field to binary indicating ALS (1) vs non-ALS (0).
|
58 |
+
Unknown values are converted to None.
|
59 |
+
Example input: "disease: Amyotrophic lateral sclerosis"
|
60 |
+
"""
|
61 |
+
parts = value.split(":")
|
62 |
+
if len(parts) < 2:
|
63 |
+
return None
|
64 |
+
disease_str = parts[1].strip().lower()
|
65 |
+
if "amyotrophic lateral sclerosis" in disease_str:
|
66 |
+
return 1
|
67 |
+
else:
|
68 |
+
return 0
|
69 |
+
|
70 |
+
def convert_age(value: str) -> Optional[float]:
|
71 |
+
"""
|
72 |
+
Convert age field to continuous (float).
|
73 |
+
Unknown values are converted to None.
|
74 |
+
Example input: "age at death (in years): 70"
|
75 |
+
"""
|
76 |
+
parts = value.split(":")
|
77 |
+
if len(parts) < 2:
|
78 |
+
return None
|
79 |
+
age_str = parts[1].strip()
|
80 |
+
try:
|
81 |
+
return float(age_str)
|
82 |
+
except ValueError:
|
83 |
+
return None
|
84 |
+
|
85 |
+
def convert_gender(value: str) -> Optional[int]:
|
86 |
+
"""
|
87 |
+
Convert gender field to binary: female -> 0, male -> 1.
|
88 |
+
Unknown values are converted to None.
|
89 |
+
Example input: "gender: M"
|
90 |
+
"""
|
91 |
+
parts = value.split(":")
|
92 |
+
if len(parts) < 2:
|
93 |
+
return None
|
94 |
+
gender_str = parts[1].strip().lower()
|
95 |
+
if gender_str == 'f':
|
96 |
+
return 0
|
97 |
+
elif gender_str == 'm':
|
98 |
+
return 1
|
99 |
+
else:
|
100 |
+
return None
|
101 |
+
|
102 |
+
# 3. Save Metadata (initial filtering)
|
103 |
+
is_trait_available = (trait_row is not None)
|
104 |
+
is_final = False # initial filtering
|
105 |
+
validate_and_save_cohort_info(
|
106 |
+
is_final=is_final,
|
107 |
+
cohort=cohort,
|
108 |
+
info_path=json_path,
|
109 |
+
is_gene_available=is_gene_available,
|
110 |
+
is_trait_available=is_trait_available
|
111 |
+
)
|
112 |
+
|
113 |
+
# 4. Clinical Feature Extraction (only if trait_row is not None)
|
114 |
+
if trait_row is not None:
|
115 |
+
# Assume 'clinical_data' is the DataFrame with sample characteristics loaded from a previous step.
|
116 |
+
selected_clinical_df = geo_select_clinical_features(
|
117 |
+
clinical_data,
|
118 |
+
trait=trait,
|
119 |
+
trait_row=trait_row,
|
120 |
+
convert_trait=convert_trait,
|
121 |
+
age_row=age_row,
|
122 |
+
convert_age=convert_age,
|
123 |
+
gender_row=gender_row,
|
124 |
+
convert_gender=convert_gender
|
125 |
+
)
|
126 |
+
# Preview and save
|
127 |
+
print("Preview of Selected Clinical Features:", preview_df(selected_clinical_df))
|
128 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
129 |
+
# STEP3
|
130 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
131 |
+
gene_data = get_genetic_data(matrix_file)
|
132 |
+
|
133 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
134 |
+
print(gene_data.index[:20])
|
135 |
+
# These identifiers, such as 'ILMN_10000', are Illumina microarray probe IDs rather than standard gene symbols.
|
136 |
+
# Hence, they require mapping to gene symbols.
|
137 |
+
print("requires_gene_mapping = True")
|
138 |
+
# STEP5
|
139 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
140 |
+
gene_annotation = get_gene_annotation(soft_file)
|
141 |
+
|
142 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
143 |
+
print("Gene annotation preview:")
|
144 |
+
print(preview_df(gene_annotation))
|
145 |
+
# STEP: Gene Identifier Mapping
|
146 |
+
|
147 |
+
# 1. Identify the corresponding columns for probe ID and gene symbol in 'gene_annotation'.
|
148 |
+
# From the previews, 'ID' matches the probe identifiers used in the gene expression data (e.g., 'ILMN_10000'),
|
149 |
+
# and 'SYMBOL' stores the gene symbols.
|
150 |
+
probe_col = 'ID'
|
151 |
+
symbol_col = 'SYMBOL'
|
152 |
+
|
153 |
+
# 2. Get a mapping dataframe from 'gene_annotation'.
|
154 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=probe_col, gene_col=symbol_col)
|
155 |
+
|
156 |
+
# 3. Convert probe-level measurements to gene-level expression data using 'apply_gene_mapping'.
|
157 |
+
# This handles the many-to-many relationships by dividing expression across genes and summing contributions per gene.
|
158 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
159 |
+
|
160 |
+
# For verification, let's output a small preview of the resulting gene_data: shape and first few gene indices.
|
161 |
+
print("Mapped gene_data shape:", gene_data.shape)
|
162 |
+
print("First 10 genes after mapping:", gene_data.index[:10].to_list())
|
163 |
+
# STEP 7: Data Normalization and Linking
|
164 |
+
|
165 |
+
import pandas as pd
|
166 |
+
|
167 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
168 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
169 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
170 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
171 |
+
|
172 |
+
# 2. Read the previously saved clinical data and correctly restore the row/column structure
|
173 |
+
# After step 2, the CSV has 3 rows (trait, Age, Gender) and columns = sample IDs (header=0).
|
174 |
+
# We can directly set the new index labels because we know row 0 = trait, row 1 = Age, row 2 = Gender.
|
175 |
+
selected_clinical_df = pd.read_csv(out_clinical_data_file, header=0)
|
176 |
+
if selected_clinical_df.shape[0] == 3:
|
177 |
+
selected_clinical_df.index = [trait, 'Age', 'Gender']
|
178 |
+
else:
|
179 |
+
print("Warning: The clinical data does not have 3 rows as expected. Check the saved CSV format.")
|
180 |
+
|
181 |
+
# 3. Link clinical and gene expression data on sample IDs
|
182 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
183 |
+
|
184 |
+
# 4. Handle missing values (drop samples missing trait, drop high-missing genes/samples, impute remaining)
|
185 |
+
linked_data = handle_missing_values(linked_data, trait_col=trait)
|
186 |
+
|
187 |
+
# 5. Check for biased features (trait, age, gender) and remove biased demographic features
|
188 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
189 |
+
|
190 |
+
# 6. Final quality validation and metadata saving
|
191 |
+
is_usable = validate_and_save_cohort_info(
|
192 |
+
is_final=True,
|
193 |
+
cohort=cohort,
|
194 |
+
info_path=json_path,
|
195 |
+
is_gene_available=True,
|
196 |
+
is_trait_available=True,
|
197 |
+
is_biased=trait_biased,
|
198 |
+
df=linked_data,
|
199 |
+
note="Final data pipeline completed."
|
200 |
+
)
|
201 |
+
|
202 |
+
# 7. Save final linked data if usable
|
203 |
+
if is_usable:
|
204 |
+
linked_data.to_csv(out_data_file)
|
205 |
+
print(f"Saved final linked data to {out_data_file}")
|
206 |
+
else:
|
207 |
+
print("Dataset is not usable for trait-based association. Skipping final output.")
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/GSE52937.py
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Amyotrophic_Lateral_Sclerosis"
|
6 |
+
cohort = "GSE52937"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Amyotrophic_Lateral_Sclerosis"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Amyotrophic_Lateral_Sclerosis/GSE52937"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/GSE52937.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/gene_data/GSE52937.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/clinical_data/GSE52937.csv"
|
16 |
+
json_path = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# 1. Gene Expression Data Availability
|
43 |
+
is_gene_available = True # Based on background ("transcriptional response", etc.), we assume gene expression data is present
|
44 |
+
|
45 |
+
# 2. Variable Availability and Data Type Conversion
|
46 |
+
|
47 |
+
# From the sample characteristics dictionary, no rows contain explicit or implicit ALS trait, age, or gender data.
|
48 |
+
trait_row = None
|
49 |
+
age_row = None
|
50 |
+
gender_row = None
|
51 |
+
|
52 |
+
# Define data conversion functions (they won't be used if the rows are None, but we define them as requested).
|
53 |
+
|
54 |
+
def convert_trait(value: str) -> int:
|
55 |
+
# Example logic for binary classification of the trait
|
56 |
+
# If the trait is unavailable, return None
|
57 |
+
return None
|
58 |
+
|
59 |
+
def convert_age(value: str) -> float:
|
60 |
+
# Example logic for continuous age value
|
61 |
+
return None
|
62 |
+
|
63 |
+
def convert_gender(value: str) -> int:
|
64 |
+
# Example logic for binary gender classification
|
65 |
+
return None
|
66 |
+
|
67 |
+
# 3. Save Metadata (Initial Filtering)
|
68 |
+
is_trait_available = (trait_row is not None)
|
69 |
+
is_usable = validate_and_save_cohort_info(
|
70 |
+
is_final=False,
|
71 |
+
cohort=cohort,
|
72 |
+
info_path=json_path,
|
73 |
+
is_gene_available=is_gene_available,
|
74 |
+
is_trait_available=is_trait_available
|
75 |
+
)
|
76 |
+
|
77 |
+
# 4. Clinical Feature Extraction
|
78 |
+
# We only do this if trait_row is not None. Here trait_row is None, so we skip this step.
|
79 |
+
# STEP3
|
80 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
81 |
+
gene_data = get_genetic_data(matrix_file)
|
82 |
+
|
83 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
84 |
+
print(gene_data.index[:20])
|
85 |
+
print("requires_gene_mapping = True")
|
86 |
+
# STEP5
|
87 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
88 |
+
gene_annotation = get_gene_annotation(soft_file)
|
89 |
+
|
90 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
91 |
+
print("Gene annotation preview:")
|
92 |
+
print(preview_df(gene_annotation))
|
93 |
+
# STEP: Gene Identifier Mapping
|
94 |
+
|
95 |
+
# 1 & 2. Identify the corresponding columns in the gene annotation dataframe for
|
96 |
+
# (a) the probe IDs, which match those in the gene expression data
|
97 |
+
# (b) the gene symbols
|
98 |
+
# We use "ID" for the probe identifier and "Symbol" for the gene symbol.
|
99 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="Symbol")
|
100 |
+
|
101 |
+
# 3. Convert probe-level data in gene_data to gene-level data using the mapping.
|
102 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
103 |
+
|
104 |
+
# For confirmation, let's print out the shape of the resulting gene_data
|
105 |
+
print("Mapped gene_data shape:", gene_data.shape)
|
106 |
+
# STEP 7: Data Normalization and Linking
|
107 |
+
|
108 |
+
# Since we concluded in previous steps that there is no trait data (trait_row = None),
|
109 |
+
# we cannot link clinical data or perform trait-based analyses. We'll still normalize
|
110 |
+
# the gene data and then perform a final validation indicating that the dataset does
|
111 |
+
# not have trait information.
|
112 |
+
|
113 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
114 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
115 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
116 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
117 |
+
|
118 |
+
# 2. No trait data is available, so we skip linking genetic and clinical data.
|
119 |
+
# We also skip handling missing trait values or checking trait bias.
|
120 |
+
|
121 |
+
# 3. Final Quality Validation
|
122 |
+
# Since there's no trait, is_trait_available=False, so the dataset won't be deemed usable for trait-based analysis.
|
123 |
+
# However, we still record the metadata. We must provide 'df' and 'is_biased' as the function requires.
|
124 |
+
is_usable = validate_and_save_cohort_info(
|
125 |
+
is_final=True,
|
126 |
+
cohort=cohort,
|
127 |
+
info_path=json_path,
|
128 |
+
is_gene_available=True,
|
129 |
+
is_trait_available=False,
|
130 |
+
is_biased=False, # Arbitrarily False because trait doesn't exist
|
131 |
+
df=normalized_gene_data, # We'll pass the gene data as the 'df'
|
132 |
+
note="No trait data available, so cohort is not usable for association study."
|
133 |
+
)
|
134 |
+
|
135 |
+
# 4. If the dataset were usable, we'd save the final linked data. In this case, it's not usable for trait-based association.
|
136 |
+
if is_usable:
|
137 |
+
# This branch will not execute because there's no trait
|
138 |
+
linked_data.to_csv(out_data_file)
|
139 |
+
print(f"Saved final linked data to {out_data_file}")
|
140 |
+
else:
|
141 |
+
print("Trait data not available. Skipping final output for association analysis.")
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/GSE61322.py
ADDED
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Amyotrophic_Lateral_Sclerosis"
|
6 |
+
cohort = "GSE61322"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Amyotrophic_Lateral_Sclerosis"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Amyotrophic_Lateral_Sclerosis/GSE61322"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/GSE61322.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/gene_data/GSE61322.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/clinical_data/GSE61322.csv"
|
16 |
+
json_path = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# 1. Gene Expression Data Availability
|
43 |
+
# From the background info ("microarray", "RNA-sequencing"), this dataset likely contains gene expression data.
|
44 |
+
is_gene_available = True
|
45 |
+
|
46 |
+
# 2. Variable Availability and Conversion
|
47 |
+
# Checking the sample characteristics dictionary:
|
48 |
+
# {0: ['diagnosis: carrier', 'diagnosis: affected'],
|
49 |
+
# 1: ['disease: AOA2'],
|
50 |
+
# 2: ['definite analysis: definite', 'definite analysis: presumed']}
|
51 |
+
# None of these keys mention "Amyotrophic_Lateral_Sclerosis" or an "ALS" variant.
|
52 |
+
# Also, no keys show age or gender data. Hence, all are considered unavailable.
|
53 |
+
trait_row = None
|
54 |
+
age_row = None
|
55 |
+
gender_row = None
|
56 |
+
|
57 |
+
def convert_trait(value: str) -> Optional[float]:
|
58 |
+
# Not used as trait_row is None, but we provide a stub.
|
59 |
+
# Typically would parse the string after ':', then map to 0./1. or None appropriately.
|
60 |
+
return None
|
61 |
+
|
62 |
+
def convert_age(value: str) -> Optional[float]:
|
63 |
+
# Not used as age_row is None, but we provide a stub.
|
64 |
+
return None
|
65 |
+
|
66 |
+
def convert_gender(value: str) -> Optional[int]:
|
67 |
+
# Not used as gender_row is None, but we provide a stub.
|
68 |
+
return None
|
69 |
+
|
70 |
+
# 3. Save Metadata with initial filtering
|
71 |
+
# If trait_row is None => is_trait_available = False
|
72 |
+
is_trait_available = (trait_row is not None)
|
73 |
+
|
74 |
+
is_usable = validate_and_save_cohort_info(
|
75 |
+
is_final=False,
|
76 |
+
cohort=cohort,
|
77 |
+
info_path=json_path,
|
78 |
+
is_gene_available=is_gene_available,
|
79 |
+
is_trait_available=is_trait_available
|
80 |
+
)
|
81 |
+
|
82 |
+
# 4. Clinical Feature Extraction
|
83 |
+
# Since trait_row is None, we skip this step (no clinical data for the trait).
|
84 |
+
# STEP3
|
85 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
86 |
+
gene_data = get_genetic_data(matrix_file)
|
87 |
+
|
88 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
89 |
+
print(gene_data.index[:20])
|
90 |
+
# Based on the above identifiers (e.g., ILMN_1343291, ILMN_1651209, etc.),
|
91 |
+
# they are Illumina probe IDs rather than standard human gene symbols.
|
92 |
+
# Therefore, they require mapping to gene symbols.
|
93 |
+
|
94 |
+
print("requires_gene_mapping = True")
|
95 |
+
# STEP5
|
96 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
97 |
+
gene_annotation = get_gene_annotation(soft_file)
|
98 |
+
|
99 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
100 |
+
print("Gene annotation preview:")
|
101 |
+
print(preview_df(gene_annotation))
|
102 |
+
# STEP: Gene Identifier Mapping
|
103 |
+
|
104 |
+
# 1. From the annotation preview and the gene expression row IDs, we see that
|
105 |
+
# the "ID" column in gene_annotation matches probe IDs like "ILMN_1343291",
|
106 |
+
# and the "Symbol" column stores the gene symbols.
|
107 |
+
prob_col = "ID"
|
108 |
+
gene_col = "Symbol"
|
109 |
+
|
110 |
+
# 2. Extract the mapping dataframe with these two columns
|
111 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col, gene_col)
|
112 |
+
|
113 |
+
# 3. Apply the mapping to convert probe-level data into gene-level expression
|
114 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
115 |
+
# STEP 7: Data Normalization and Linking
|
116 |
+
|
117 |
+
# Since we concluded in previous steps that there is no trait data (trait_row = None),
|
118 |
+
# we cannot link clinical data or perform trait-based analyses. We'll still normalize
|
119 |
+
# the gene data and then perform a final validation indicating that the dataset does
|
120 |
+
# not have trait information.
|
121 |
+
|
122 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
123 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
124 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
125 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
126 |
+
|
127 |
+
# 2. No trait data is available, so we skip linking genetic and clinical data.
|
128 |
+
# We also skip handling missing trait values or checking trait bias.
|
129 |
+
|
130 |
+
# 3. Final Quality Validation
|
131 |
+
# Since there's no trait, is_trait_available=False, so the dataset won't be deemed usable for trait-based analysis.
|
132 |
+
# However, we still record the metadata. We must provide 'df' and 'is_biased' as the function requires.
|
133 |
+
is_usable = validate_and_save_cohort_info(
|
134 |
+
is_final=True,
|
135 |
+
cohort=cohort,
|
136 |
+
info_path=json_path,
|
137 |
+
is_gene_available=True,
|
138 |
+
is_trait_available=False,
|
139 |
+
is_biased=False, # Arbitrarily False because trait doesn't exist
|
140 |
+
df=normalized_gene_data, # We'll pass the gene data as the 'df'
|
141 |
+
note="No trait data available, so cohort is not usable for association study."
|
142 |
+
)
|
143 |
+
|
144 |
+
# 4. If the dataset were usable, we'd save the final linked data. In this case, it's not usable for trait-based association.
|
145 |
+
if is_usable:
|
146 |
+
# This branch will not execute because there's no trait
|
147 |
+
linked_data.to_csv(out_data_file)
|
148 |
+
print(f"Saved final linked data to {out_data_file}")
|
149 |
+
else:
|
150 |
+
print("Trait data not available. Skipping final output for association analysis.")
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/GSE68608.py
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Amyotrophic_Lateral_Sclerosis"
|
6 |
+
cohort = "GSE68608"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Amyotrophic_Lateral_Sclerosis"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Amyotrophic_Lateral_Sclerosis/GSE68608"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/GSE68608.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/gene_data/GSE68608.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/clinical_data/GSE68608.csv"
|
16 |
+
json_path = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# 1) Gene Expression Data Availability
|
43 |
+
is_gene_available = True # Based on the background, it's likely gene expression data.
|
44 |
+
|
45 |
+
# 2) Variable Availability and Data Type Conversion
|
46 |
+
trait_row = 1 # Key 1 contains ALS vs Control information.
|
47 |
+
age_row = None # No age information found in the dictionary.
|
48 |
+
gender_row = None # No gender information found in the dictionary.
|
49 |
+
|
50 |
+
def convert_trait(value: str):
|
51 |
+
# Extract the part after the colon (if any) and convert to lowercase
|
52 |
+
if ':' in value:
|
53 |
+
_, val = value.split(':', 1)
|
54 |
+
val = val.strip().lower()
|
55 |
+
else:
|
56 |
+
val = value.strip().lower()
|
57 |
+
|
58 |
+
# Map to binary
|
59 |
+
if 'als' in val:
|
60 |
+
return 1
|
61 |
+
elif 'control' in val or 'healthy' in val:
|
62 |
+
return 0
|
63 |
+
else:
|
64 |
+
return None
|
65 |
+
|
66 |
+
def convert_age(value: str):
|
67 |
+
# No age data is available; return None
|
68 |
+
return None
|
69 |
+
|
70 |
+
def convert_gender(value: str):
|
71 |
+
# No gender data is available; return None
|
72 |
+
return None
|
73 |
+
|
74 |
+
# 3) Save Metadata (Initial filtering)
|
75 |
+
is_trait_available = (trait_row is not None)
|
76 |
+
is_usable = validate_and_save_cohort_info(
|
77 |
+
is_final=False,
|
78 |
+
cohort=cohort,
|
79 |
+
info_path=json_path,
|
80 |
+
is_gene_available=is_gene_available,
|
81 |
+
is_trait_available=is_trait_available
|
82 |
+
)
|
83 |
+
|
84 |
+
# 4) Clinical Feature Extraction (only if trait data is available)
|
85 |
+
if trait_row is not None:
|
86 |
+
selected_clinical_df = geo_select_clinical_features(
|
87 |
+
clinical_df=clinical_data,
|
88 |
+
trait=trait,
|
89 |
+
trait_row=trait_row,
|
90 |
+
convert_trait=convert_trait,
|
91 |
+
age_row=age_row,
|
92 |
+
convert_age=convert_age,
|
93 |
+
gender_row=gender_row,
|
94 |
+
convert_gender=convert_gender
|
95 |
+
)
|
96 |
+
print("Preview of selected clinical features:")
|
97 |
+
print(preview_df(selected_clinical_df))
|
98 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
99 |
+
# STEP3
|
100 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
101 |
+
gene_data = get_genetic_data(matrix_file)
|
102 |
+
|
103 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
104 |
+
print(gene_data.index[:20])
|
105 |
+
# Based on the provided identifiers (e.g., '1007_s_at', '1053_at'), they appear to be Affymetrix probe set IDs.
|
106 |
+
# These are not standard human gene symbols and thus require mapping to gene symbols.
|
107 |
+
print("They appear to be Affymetrix probe set IDs.")
|
108 |
+
print("requires_gene_mapping = True")
|
109 |
+
# STEP5
|
110 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
111 |
+
gene_annotation = get_gene_annotation(soft_file)
|
112 |
+
|
113 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
114 |
+
print("Gene annotation preview:")
|
115 |
+
print(preview_df(gene_annotation))
|
116 |
+
# STEP: Gene Identifier Mapping
|
117 |
+
|
118 |
+
# 1) The 'ID' column in 'gene_annotation' corresponds to the probe IDs in the gene expression data.
|
119 |
+
# The 'Gene Symbol' column contains the gene symbols.
|
120 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Gene Symbol')
|
121 |
+
|
122 |
+
# 2) Convert probe-level measurements to gene-level measurements by applying the many-to-many mapping.
|
123 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
124 |
+
# STEP 7: Data Normalization and Linking
|
125 |
+
|
126 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
127 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
128 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
129 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
130 |
+
|
131 |
+
# 2. Link the clinical and genetic data
|
132 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
133 |
+
|
134 |
+
# 3. Systematically handle missing values
|
135 |
+
linked_data = handle_missing_values(linked_data, trait)
|
136 |
+
|
137 |
+
# 4. Determine whether the trait (and demographic features) are severely biased
|
138 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
139 |
+
|
140 |
+
# 5. Conduct final quality validation and save metadata
|
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="Trait data is ALS vs. control; age and gender are not available."
|
150 |
+
)
|
151 |
+
|
152 |
+
# 6. If the dataset is usable, save the final linked data
|
153 |
+
if is_usable:
|
154 |
+
linked_data.to_csv(out_data_file)
|
155 |
+
print(f"Saved final linked data to {out_data_file}")
|
156 |
+
else:
|
157 |
+
print("Data not usable for association; skipping final output.")
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/GSE95810.py
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Amyotrophic_Lateral_Sclerosis"
|
6 |
+
cohort = "GSE95810"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Amyotrophic_Lateral_Sclerosis"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Amyotrophic_Lateral_Sclerosis/GSE95810"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/GSE95810.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/gene_data/GSE95810.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/clinical_data/GSE95810.csv"
|
16 |
+
json_path = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# 1) Determine if gene expression data is available
|
43 |
+
is_gene_available = True # Based on series title indicating "Gene expression..."
|
44 |
+
|
45 |
+
# 2) Identify the availability of trait, age, and gender data
|
46 |
+
trait_row = None # No ALS-specific indicator in the sample characteristics
|
47 |
+
age_row = None # No age data found
|
48 |
+
gender_row = None # No gender data found
|
49 |
+
|
50 |
+
# 2) Create conversion functions (though they won't be used since rows are None)
|
51 |
+
def convert_trait(value: str):
|
52 |
+
return None
|
53 |
+
|
54 |
+
def convert_age(value: str):
|
55 |
+
return None
|
56 |
+
|
57 |
+
def convert_gender(value: str):
|
58 |
+
return None
|
59 |
+
|
60 |
+
# 3) Initial metadata saving and validation
|
61 |
+
is_trait_available = (trait_row is not None)
|
62 |
+
validate_and_save_cohort_info(
|
63 |
+
is_final=False,
|
64 |
+
cohort=cohort,
|
65 |
+
info_path=json_path,
|
66 |
+
is_gene_available=is_gene_available,
|
67 |
+
is_trait_available=is_trait_available
|
68 |
+
)
|
69 |
+
|
70 |
+
# 4) Skip clinical feature extraction because 'trait_row' is None
|
71 |
+
# STEP3
|
72 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
73 |
+
gene_data = get_genetic_data(matrix_file)
|
74 |
+
|
75 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
76 |
+
print(gene_data.index[:20])
|
77 |
+
# Based on the provided gene identifiers (e.g., A1BG, A1CF, A2M, etc.), they appear to be standard human gene symbols.
|
78 |
+
# Consequently, a separate mapping step does not seem to be required.
|
79 |
+
|
80 |
+
print("requires_gene_mapping = False")
|
81 |
+
# STEP 5: Data Normalization and Linking
|
82 |
+
|
83 |
+
# Since trait data is not available based on the previous steps (trait_row=None),
|
84 |
+
# we cannot perform clinical-gene linking or meaningful trait-based analyses.
|
85 |
+
|
86 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
87 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
88 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
89 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
90 |
+
|
91 |
+
# 2-6. Since there's no trait data, we skip linking and final output for association.
|
92 |
+
# Perform final validation indicating the dataset is not usable for trait association.
|
93 |
+
is_trait_available = False
|
94 |
+
validate_and_save_cohort_info(
|
95 |
+
is_final=True,
|
96 |
+
cohort=cohort,
|
97 |
+
info_path=json_path,
|
98 |
+
is_gene_available=True,
|
99 |
+
is_trait_available=is_trait_available,
|
100 |
+
is_biased=False, # Provide a valid Boolean so it doesn't raise ValueError
|
101 |
+
df=pd.DataFrame(), # Empty since we can't link without trait
|
102 |
+
note="No trait data found; skipping linking and final output."
|
103 |
+
)
|
104 |
+
|
105 |
+
print("Trait data is unavailable; no further steps for linking or final output can be performed.")
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/code/TCGA.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Amyotrophic_Lateral_Sclerosis"
|
6 |
+
|
7 |
+
# Input paths
|
8 |
+
tcga_root_dir = "../DATA/TCGA"
|
9 |
+
|
10 |
+
# Output paths
|
11 |
+
out_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/TCGA.csv"
|
12 |
+
out_gene_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/gene_data/TCGA.csv"
|
13 |
+
out_clinical_data_file = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/clinical_data/TCGA.csv"
|
14 |
+
json_path = "./output/preprocess/1/Amyotrophic_Lateral_Sclerosis/cohort_info.json"
|
15 |
+
|
16 |
+
import os
|
17 |
+
import pandas as pd
|
18 |
+
|
19 |
+
# 1. Identify the relevant subdirectory for the trait "Obesity"
|
20 |
+
subdirectories = [
|
21 |
+
'CrawlData.ipynb', '.DS_Store', 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
|
22 |
+
'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)', 'TCGA_Thymoma_(THYM)',
|
23 |
+
'TCGA_Testicular_Cancer_(TGCT)', 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
|
24 |
+
'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)', 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)',
|
25 |
+
'TCGA_Pancreatic_Cancer_(PAAD)', 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
|
26 |
+
'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)', 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)',
|
27 |
+
'TCGA_Lung_Cancer_(LUNG)', 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
|
28 |
+
'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)', 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)',
|
29 |
+
'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)', 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
|
30 |
+
'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)', 'TCGA_Endometrioid_Cancer_(UCEC)',
|
31 |
+
'TCGA_Colon_and_Rectal_Cancer_(COADREAD)', 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
|
32 |
+
'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)', 'TCGA_Bile_Duct_Cancer_(CHOL)',
|
33 |
+
'TCGA_Adrenocortical_Cancer_(ACC)', 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
|
34 |
+
]
|
35 |
+
|
36 |
+
trait_keyword = trait
|
37 |
+
target_subdir = None
|
38 |
+
|
39 |
+
for sd in subdirectories:
|
40 |
+
if trait_keyword.lower() in sd.lower():
|
41 |
+
target_subdir = sd
|
42 |
+
break
|
43 |
+
|
44 |
+
if target_subdir is None:
|
45 |
+
# No suitable data found for this trait; mark as completed
|
46 |
+
print("No TCGA subdirectory found for the trait. Skipping.")
|
47 |
+
else:
|
48 |
+
# 2. Locate clinical and genetic data files
|
49 |
+
cohort_dir = os.path.join(tcga_root_dir, target_subdir)
|
50 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
51 |
+
|
52 |
+
# 3. Load the data
|
53 |
+
clinical_df = pd.read_csv(clinical_file_path, index_col=0, sep='\t')
|
54 |
+
genetic_df = pd.read_csv(genetic_file_path, index_col=0, sep='\t')
|
55 |
+
|
56 |
+
# 4. Print column names of clinical data
|
57 |
+
print(clinical_df.columns)
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE118336.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,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
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE139384.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,GSM4140293,GSM4140294,GSM4140295,GSM4140296,GSM4140297,GSM4140298,GSM4140299,GSM4140300,GSM4140301,GSM4140302,GSM4140303,GSM4140304,GSM4140305,GSM4140306,GSM4140307,GSM4140308,GSM4140309,GSM4140310,GSM4140311,GSM4140312,GSM4140313,GSM4140314,GSM4140315,GSM4140316,GSM4140317,GSM4140318,GSM4140319,GSM4140320,GSM4140321,GSM4140322,GSM4140323,GSM4140324,GSM4140325
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE212134.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,GSM6509811,GSM6509812,GSM6509813,GSM6509814,GSM6509815,GSM6509816,GSM6509817,GSM6509818,GSM6509819,GSM6509820,GSM6509821,GSM6509822,GSM6509823,GSM6509824,GSM6509825,GSM6509826,GSM6509827,GSM6509828,GSM6509829,GSM6509830,GSM6509831,GSM6509832,GSM6509833,GSM6509834,GSM6509835,GSM6509836,GSM6509837,GSM6509838,GSM6509839,GSM6509840,GSM6509841,GSM6509842,GSM6509843,GSM6509844,GSM6509845,GSM6509846,GSM6509847,GSM6509848,GSM6509849,GSM6509850,GSM6509851,GSM6509852
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE26927.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,GSM663008,GSM663009,GSM663010,GSM663011,GSM663012,GSM663013,GSM663014,GSM663015,GSM663016,GSM663017,GSM663018,GSM663019,GSM663020,GSM663021,GSM663022,GSM663023,GSM663024,GSM663025,GSM663026,GSM663027,GSM663028,GSM663029,GSM663030,GSM663031,GSM663032,GSM663033,GSM663034,GSM663035,GSM663036,GSM663037,GSM663038,GSM663039,GSM663040,GSM663041,GSM663042,GSM663043,GSM663044,GSM663045,GSM663046,GSM663047,GSM663048,GSM663049,GSM663050,GSM663051,GSM663052,GSM663053,GSM663054,GSM663055,GSM663056,GSM663057,GSM663058,GSM663059,GSM663060,GSM663061,GSM663062,GSM663063,GSM663064,GSM663065,GSM663066,GSM663067,GSM663068,GSM663069,GSM663070,GSM663071,GSM663072,GSM663073,GSM663074,GSM663075,GSM663076,GSM663077,GSM663078,GSM663079,GSM663080,GSM663081,GSM663082,GSM663083,GSM663084,GSM663085,GSM663086,GSM663087,GSM663088,GSM663089,GSM663090,GSM663091,GSM663092,GSM663093,GSM663094,GSM663095,GSM663096,GSM663097,GSM663098,GSM663099,GSM663100,GSM663101,GSM663102,GSM663103,GSM663104,GSM663105,GSM663106,GSM663107,GSM663108,GSM663109,GSM663110,GSM663111,GSM663112,GSM663113,GSM663114,GSM663115,GSM663116,GSM663117,GSM663118,GSM663119,GSM663120,GSM663121,GSM663122,GSM663123,GSM663124,GSM663125
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE52937.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,GSM1278303,GSM1278304,GSM1278305,GSM1278306,GSM1278307,GSM1278308,GSM1278309,GSM1278310,GSM1278311,GSM1278312,GSM1278313,GSM1278314,GSM1278315,GSM1278316,GSM1278317,GSM1278318,GSM1278319,GSM1278320,GSM1278321,GSM1278322,GSM1278323,GSM1278324,GSM1278325,GSM1278326,GSM1278327,GSM1278328,GSM1278329,GSM1627269,GSM1627270,GSM1627271,GSM1627272,GSM1627273,GSM1627274,GSM1627275,GSM1627276,GSM1627277,GSM1627278,GSM1627279,GSM1627280,GSM1627281,GSM1627282,GSM1627283,GSM1627284,GSM1627285,GSM1627286,GSM1627287,GSM1627288,GSM1627289,GSM1627290,GSM1627291,GSM1627292,GSM1627293,GSM1627294,GSM1627295
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE61322.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,GSM1502059,GSM1502060,GSM1502061,GSM1502062,GSM1502063,GSM1502064,GSM1502065,GSM1502066,GSM1502067,GSM1502068,GSM1502069,GSM1502070,GSM1502071,GSM1502072,GSM1502073,GSM1502074,GSM1502075,GSM1502076,GSM1502077,GSM1502078,GSM1502079,GSM1502080,GSM1502081,GSM1502082,GSM1502083,GSM1502084,GSM1502085,GSM1502086,GSM1502087,GSM1502088,GSM1502089,GSM1502090,GSM1502091
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE68607.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,GSM1677001,GSM1677002,GSM1677003,GSM1677004,GSM1677005,GSM1677006,GSM1677007,GSM1677008,GSM1677009,GSM1677010,GSM1677011,GSM1677012,GSM1677013,GSM1677014,GSM1677015,GSM1677016,GSM1677017,GSM1677018,GSM1677019,GSM1677020,GSM1677021,GSM1677022,GSM1677023,GSM1677024,GSM1677025,GSM1677026,GSM1677027,GSM1677028,GSM1677029,GSM1677030,GSM1677031,GSM1677032,GSM1677033,GSM1677034,GSM1677035,GSM1677036,GSM1677037,GSM1677038,GSM1677039,GSM1677040,GSM1677041,GSM1677042,GSM1677043,GSM1677044,GSM1677045,GSM1677046,GSM1677047,GSM1677048,GSM1677049,GSM1677050,GSM1677051,GSM1677052,GSM1677053,GSM1677054,GSM1677055,GSM1677056,GSM1677057,GSM1677058,GSM1677059,GSM1677060,GSM1677061,GSM1677062,GSM1677063,GSM1677064,GSM1677065,GSM1677066,GSM1677067,GSM1677068,GSM1677069
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE68608.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,GSM1676853,GSM1676854,GSM1676855,GSM1676856,GSM1676857,GSM1676858,GSM1676859,GSM1676860,GSM1676861,GSM1676862,GSM1676863
|
p1/preprocess/Amyotrophic_Lateral_Sclerosis/gene_data/GSE95810.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ID,GSM2526327,GSM2526328,GSM2526329,GSM2526330,GSM2526331,GSM2526332,GSM2526333,GSM2526334,GSM2526335,GSM2526336,GSM2526337,GSM2526338,GSM2526339,GSM2526340,GSM2526341,GSM2526342,GSM2526343,GSM2526344,GSM2526345,GSM2526346,GSM2526347,GSM2526348,GSM2526349,GSM2526350,GSM2526351,GSM2526352,GSM2526353,GSM2526354,GSM2526355,GSM2526356,GSM2526357,GSM2526358,GSM2526359,GSM2526360,GSM2526361,GSM2526362,GSM2526363,GSM2526364,GSM2526365,GSM2526366,GSM2526367,GSM2526368,GSM2526369,GSM2526370,GSM2526371,GSM2526372,GSM2526373,GSM2526374,GSM2526375,GSM2526376,GSM2526377,GSM2526378,GSM2526379,GSM2526380,GSM2526381,GSM2526382,GSM2526383,GSM2526384
|
p1/preprocess/Angelman_Syndrome/code/GSE43900.py
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Angelman_Syndrome"
|
6 |
+
cohort = "GSE43900"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Angelman_Syndrome"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Angelman_Syndrome/GSE43900"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Angelman_Syndrome/GSE43900.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Angelman_Syndrome/gene_data/GSE43900.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Angelman_Syndrome/clinical_data/GSE43900.csv"
|
16 |
+
json_path = "./output/preprocess/1/Angelman_Syndrome/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# 1. Determine if the dataset likely contains gene expression data
|
43 |
+
is_gene_available = True # From background info, it appears to focus on gene regulation, so we assume gene expression data
|
44 |
+
|
45 |
+
# 2. Variable Availability and Data Type Conversion
|
46 |
+
|
47 |
+
# According to the sample characteristics dictionary, we only have:
|
48 |
+
# 0: treatment information,
|
49 |
+
# 1: cell type, and
|
50 |
+
# 2: strain.
|
51 |
+
# None indicates that the dataset does not provide suitable human trait, age, or gender info.
|
52 |
+
trait_row = None
|
53 |
+
age_row = None
|
54 |
+
gender_row = None
|
55 |
+
|
56 |
+
# Define the conversion functions (though they won't be used if rows are None).
|
57 |
+
|
58 |
+
def convert_trait(x: str) -> int:
|
59 |
+
# No actual data available, placeholder implementation
|
60 |
+
return None
|
61 |
+
|
62 |
+
def convert_age(x: str) -> float:
|
63 |
+
# No actual data available, placeholder implementation
|
64 |
+
return None
|
65 |
+
|
66 |
+
def convert_gender(x: str) -> int:
|
67 |
+
# No actual data available, placeholder implementation
|
68 |
+
return None
|
69 |
+
|
70 |
+
# 3. Save Metadata (initial filtering)
|
71 |
+
is_trait_available = (trait_row is not None)
|
72 |
+
validate_and_save_cohort_info(
|
73 |
+
is_final=False,
|
74 |
+
cohort=cohort,
|
75 |
+
info_path=json_path,
|
76 |
+
is_gene_available=is_gene_available,
|
77 |
+
is_trait_available=is_trait_available
|
78 |
+
)
|
79 |
+
|
80 |
+
# 4. Clinical Feature Extraction (skip because trait_row is None)
|
81 |
+
# No action needed as trait_row is None
|
82 |
+
# STEP3
|
83 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
84 |
+
gene_data = get_genetic_data(matrix_file)
|
85 |
+
|
86 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
87 |
+
print(gene_data.index[:20])
|
88 |
+
# Based on observation, the identifiers are numeric probe IDs and do not appear to be standard human gene symbols.
|
89 |
+
# Therefore, gene mapping is required.
|
90 |
+
print("requires_gene_mapping = True")
|
91 |
+
# STEP5
|
92 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
93 |
+
gene_annotation = get_gene_annotation(soft_file)
|
94 |
+
|
95 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
96 |
+
print("Gene annotation preview:")
|
97 |
+
print(preview_df(gene_annotation))
|
98 |
+
# STEP: Gene Identifier Mapping
|
99 |
+
|
100 |
+
# 1. Decide the columns for gene identifier (probe) and gene symbol based on the preview.
|
101 |
+
probe_col = "ID"
|
102 |
+
gene_symbol_col = "Gene Symbol"
|
103 |
+
|
104 |
+
# 2. Get the mapping dataframe from the annotation.
|
105 |
+
mapping_df = get_gene_mapping(gene_annotation, probe_col, gene_symbol_col)
|
106 |
+
|
107 |
+
# 3. Convert probe-level measurements to gene-level expression data.
|
108 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
109 |
+
|
110 |
+
# Display the first few gene symbols to confirm the result.
|
111 |
+
print(gene_data.index[:20])
|
112 |
+
# STEP 7: Data Normalization and Linking
|
113 |
+
|
114 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
115 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
116 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
117 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
118 |
+
|
119 |
+
# 2. Check if the trait is available in this dataset
|
120 |
+
if trait_row is None:
|
121 |
+
# If the trait does not exist, we do not finalize; we do an initial validation
|
122 |
+
# so that the library won't require 'df' and 'is_biased'.
|
123 |
+
validate_and_save_cohort_info(
|
124 |
+
is_final=False,
|
125 |
+
cohort=cohort,
|
126 |
+
info_path=json_path,
|
127 |
+
is_gene_available=True, # Genetic data is present
|
128 |
+
is_trait_available=False # Trait data is not available
|
129 |
+
)
|
130 |
+
print("Trait data not available. Only gene expression data was processed. No final data to save.")
|
131 |
+
|
132 |
+
else:
|
133 |
+
# 3. Since trait is available, link the clinical and genetic data on sample IDs
|
134 |
+
selected_clinical_df = geo_select_clinical_features(
|
135 |
+
clinical_data,
|
136 |
+
trait,
|
137 |
+
trait_row,
|
138 |
+
convert_trait,
|
139 |
+
age_row,
|
140 |
+
convert_age,
|
141 |
+
gender_row,
|
142 |
+
convert_gender
|
143 |
+
)
|
144 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
145 |
+
|
146 |
+
# 4. Handle missing values as instructed
|
147 |
+
linked_data = handle_missing_values(linked_data, trait)
|
148 |
+
|
149 |
+
# 5. Determine whether the trait is severely biased
|
150 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
151 |
+
|
152 |
+
# 6. Conduct final quality validation and save metadata
|
153 |
+
is_usable = validate_and_save_cohort_info(
|
154 |
+
is_final=True,
|
155 |
+
cohort=cohort,
|
156 |
+
info_path=json_path,
|
157 |
+
is_gene_available=True,
|
158 |
+
is_trait_available=True,
|
159 |
+
is_biased=trait_biased,
|
160 |
+
df=linked_data,
|
161 |
+
note="Cohort data successfully processed with trait-based analysis."
|
162 |
+
)
|
163 |
+
|
164 |
+
# 7. If the dataset is usable, save the final linked data
|
165 |
+
if is_usable:
|
166 |
+
linked_data.to_csv(out_data_file, index=True)
|
167 |
+
print(f"Saved final linked data to {out_data_file}")
|
168 |
+
else:
|
169 |
+
print("The dataset is not usable for trait-based association. Skipping final output.")
|
p1/preprocess/Angelman_Syndrome/code/TCGA.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Angelman_Syndrome"
|
6 |
+
|
7 |
+
# Input paths
|
8 |
+
tcga_root_dir = "../DATA/TCGA"
|
9 |
+
|
10 |
+
# Output paths
|
11 |
+
out_data_file = "./output/preprocess/1/Angelman_Syndrome/TCGA.csv"
|
12 |
+
out_gene_data_file = "./output/preprocess/1/Angelman_Syndrome/gene_data/TCGA.csv"
|
13 |
+
out_clinical_data_file = "./output/preprocess/1/Angelman_Syndrome/clinical_data/TCGA.csv"
|
14 |
+
json_path = "./output/preprocess/1/Angelman_Syndrome/cohort_info.json"
|
15 |
+
|
16 |
+
import os
|
17 |
+
import pandas as pd
|
18 |
+
|
19 |
+
# 1. Identify the relevant subdirectory for the trait "Obesity"
|
20 |
+
subdirectories = [
|
21 |
+
'CrawlData.ipynb', '.DS_Store', 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
|
22 |
+
'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)', 'TCGA_Thymoma_(THYM)',
|
23 |
+
'TCGA_Testicular_Cancer_(TGCT)', 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
|
24 |
+
'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)', 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)',
|
25 |
+
'TCGA_Pancreatic_Cancer_(PAAD)', 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
|
26 |
+
'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)', 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)',
|
27 |
+
'TCGA_Lung_Cancer_(LUNG)', 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
|
28 |
+
'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)', 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)',
|
29 |
+
'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)', 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
|
30 |
+
'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)', 'TCGA_Endometrioid_Cancer_(UCEC)',
|
31 |
+
'TCGA_Colon_and_Rectal_Cancer_(COADREAD)', 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
|
32 |
+
'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)', 'TCGA_Bile_Duct_Cancer_(CHOL)',
|
33 |
+
'TCGA_Adrenocortical_Cancer_(ACC)', 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
|
34 |
+
]
|
35 |
+
|
36 |
+
trait_keyword = trait
|
37 |
+
target_subdir = None
|
38 |
+
|
39 |
+
for sd in subdirectories:
|
40 |
+
if trait_keyword.lower() in sd.lower():
|
41 |
+
target_subdir = sd
|
42 |
+
break
|
43 |
+
|
44 |
+
if target_subdir is None:
|
45 |
+
# No suitable data found for this trait; mark as completed
|
46 |
+
print("No TCGA subdirectory found for the trait. Skipping.")
|
47 |
+
else:
|
48 |
+
# 2. Locate clinical and genetic data files
|
49 |
+
cohort_dir = os.path.join(tcga_root_dir, target_subdir)
|
50 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
51 |
+
|
52 |
+
# 3. Load the data
|
53 |
+
clinical_df = pd.read_csv(clinical_file_path, index_col=0, sep='\t')
|
54 |
+
genetic_df = pd.read_csv(genetic_file_path, index_col=0, sep='\t')
|
55 |
+
|
56 |
+
# 4. Print column names of clinical data
|
57 |
+
print(clinical_df.columns)
|
p1/preprocess/Angelman_Syndrome/cohort_info.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"GSE43900": {"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}}
|
p1/preprocess/Angelman_Syndrome/gene_data/GSE43900.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,GSM1179395,GSM1179396,GSM1179397,GSM1179398,GSM1179399,GSM1179400,GSM1179401,GSM1179402,GSM1179409,GSM1179410,GSM1179411,GSM1179412,GSM1179413,GSM1179414,GSM1179415,GSM1179416,GSM1179417,GSM1179418,GSM1179419,GSM1179420,GSM1179421,GSM1179422,GSM1179423,GSM1179424,GSM1179425,GSM1179426,GSM1179427,GSM1179428,GSM1179429,GSM1179430,GSM1179431,GSM1179432,GSM1179433,GSM1179434
|
p1/preprocess/Aniridia/clinical_data/GSE137996.csv
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GSM4096389,GSM4096390,GSM4096391,GSM4096392,GSM4096393,GSM4096394,GSM4096395,GSM4096396,GSM4096397,GSM4096398,GSM4096399,GSM4096400,GSM4096401,GSM4096402,GSM4096403,GSM4096404,GSM4096405,GSM4096406,GSM4096407,GSM4096408,GSM4096409,GSM4096410,GSM4096411,GSM4096412,GSM4096413,GSM4096414,GSM4096415,GSM4096416,GSM4096417,GSM4096418,GSM4096419,GSM4096420,GSM4096421,GSM4096422,GSM4096423,GSM4096424,GSM4096425,GSM4096426,GSM4096427,GSM4096428
|
2 |
+
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,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
|
3 |
+
20.0,20.0,28.0,20.0,38.0,57.0,26.0,18.0,36.0,42.0,18.0,42.0,36.0,28.0,55.0,54.0,34.0,51.0,46.0,52.0,53.0,54.0,40.0,55.0,57.0,28.0,39.0,59.0,20.0,32.0,37.0,34.0,28.0,28.0,29.0,19.0,25.0,25.0,34.0,22.0
|
4 |
+
0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0
|
p1/preprocess/Aniridia/clinical_data/GSE137997.csv
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GSM4096349,GSM4096350,GSM4096351,GSM4096352,GSM4096353,GSM4096354,GSM4096355,GSM4096356,GSM4096357,GSM4096358,GSM4096359,GSM4096360,GSM4096361,GSM4096362,GSM4096363,GSM4096364,GSM4096365,GSM4096366,GSM4096367,GSM4096368,GSM4096369,GSM4096370,GSM4096371,GSM4096372,GSM4096373,GSM4096374,GSM4096375,GSM4096376,GSM4096377,GSM4096378,GSM4096379,GSM4096380,GSM4096381,GSM4096382,GSM4096383,GSM4096384,GSM4096385,GSM4096386,GSM4096387,GSM4096388
|
2 |
+
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,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
|
3 |
+
20.0,20.0,28.0,20.0,38.0,57.0,26.0,18.0,36.0,42.0,18.0,42.0,36.0,28.0,55.0,54.0,34.0,51.0,46.0,52.0,53.0,54.0,40.0,55.0,57.0,28.0,39.0,59.0,20.0,32.0,37.0,34.0,28.0,28.0,29.0,19.0,25.0,25.0,34.0,22.0
|
4 |
+
0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0
|
p1/preprocess/Aniridia/code/GSE137996.py
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Aniridia"
|
6 |
+
cohort = "GSE137996"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Aniridia"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Aniridia/GSE137996"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Aniridia/GSE137996.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Aniridia/gene_data/GSE137996.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Aniridia/clinical_data/GSE137996.csv"
|
16 |
+
json_path = "./output/preprocess/1/Aniridia/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# Step 1: Determine if gene expression data is available
|
43 |
+
# Based on the background info (mRNA expression and microRNA data), we consider this dataset to have gene expression data.
|
44 |
+
is_gene_available = True
|
45 |
+
|
46 |
+
# Step 2: Identify availability for trait, age, and gender, and define conversion functions.
|
47 |
+
|
48 |
+
# From the sample characteristics:
|
49 |
+
# row 0 => age
|
50 |
+
# row 1 => gender
|
51 |
+
# row 2 => disease (AAK / healthy control)
|
52 |
+
#
|
53 |
+
# We treat 'disease' as the trait variable, 'age' as continuous, and 'gender' as binary.
|
54 |
+
|
55 |
+
trait_row = 2
|
56 |
+
age_row = 0
|
57 |
+
gender_row = 1
|
58 |
+
|
59 |
+
def convert_trait(x: str) -> int:
|
60 |
+
# Extract the raw value after the colon
|
61 |
+
val = x.split(':')[-1].strip().lower()
|
62 |
+
# Convert to binary: 1 for aniridia (AAK), 0 for control, None otherwise
|
63 |
+
if val == 'aak':
|
64 |
+
return 1
|
65 |
+
elif val == 'healthy control':
|
66 |
+
return 0
|
67 |
+
return None
|
68 |
+
|
69 |
+
def convert_age(x: str) -> float:
|
70 |
+
# Extract the raw value after the colon
|
71 |
+
val = x.split(':')[-1].strip()
|
72 |
+
# Convert to float if possible
|
73 |
+
try:
|
74 |
+
return float(val)
|
75 |
+
except ValueError:
|
76 |
+
return None
|
77 |
+
|
78 |
+
def convert_gender(x: str) -> int:
|
79 |
+
# Extract the raw value after the colon
|
80 |
+
val = x.split(':')[-1].strip().lower()
|
81 |
+
# Convert F/M/W to binary: female => 0, male => 1
|
82 |
+
if val in ['f', 'w']:
|
83 |
+
return 0
|
84 |
+
elif val == 'm':
|
85 |
+
return 1
|
86 |
+
return None
|
87 |
+
|
88 |
+
# Step 3: Initial filtering and saving metadata
|
89 |
+
is_trait_available = (trait_row is not None)
|
90 |
+
|
91 |
+
validate_and_save_cohort_info(
|
92 |
+
is_final=False,
|
93 |
+
cohort=cohort,
|
94 |
+
info_path=json_path,
|
95 |
+
is_gene_available=is_gene_available,
|
96 |
+
is_trait_available=is_trait_available
|
97 |
+
)
|
98 |
+
|
99 |
+
# Step 4: Clinical feature extraction (only if trait_row is not None)
|
100 |
+
if trait_row is not None:
|
101 |
+
selected_clinical_df = geo_select_clinical_features(
|
102 |
+
clinical_data,
|
103 |
+
trait=trait, # "Aniridia"
|
104 |
+
trait_row=trait_row,
|
105 |
+
convert_trait=convert_trait,
|
106 |
+
age_row=age_row,
|
107 |
+
convert_age=convert_age,
|
108 |
+
gender_row=gender_row,
|
109 |
+
convert_gender=convert_gender
|
110 |
+
)
|
111 |
+
|
112 |
+
# Preview extracted clinical features
|
113 |
+
previewed_data = preview_df(selected_clinical_df)
|
114 |
+
print("Preview of selected clinical data:", previewed_data)
|
115 |
+
|
116 |
+
# Save clinical features to CSV
|
117 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
118 |
+
# STEP3
|
119 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
120 |
+
gene_data = get_genetic_data(matrix_file)
|
121 |
+
|
122 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
123 |
+
print(gene_data.index[:20])
|
124 |
+
# After reviewing the identifiers such as "A_19_P00315452", they appear to be array probe IDs and not standard gene symbols.
|
125 |
+
# Therefore, gene symbol mapping is required.
|
126 |
+
print("requires_gene_mapping = True")
|
127 |
+
# STEP5
|
128 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
129 |
+
gene_annotation = get_gene_annotation(soft_file)
|
130 |
+
|
131 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
132 |
+
print("Gene annotation preview:")
|
133 |
+
print(preview_df(gene_annotation))
|
134 |
+
# Gene Identifier Mapping
|
135 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="GENE_SYMBOL")
|
136 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
137 |
+
# STEP 7: Data Normalization and Linking
|
138 |
+
|
139 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
140 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
141 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
142 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
143 |
+
|
144 |
+
# 2. Link the clinical and genetic data on sample IDs
|
145 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
146 |
+
|
147 |
+
# 3. Handle missing values, removing or imputing as instructed
|
148 |
+
linked_data = handle_missing_values(linked_data, trait)
|
149 |
+
|
150 |
+
# 4. Determine whether the trait (and potentially other features) is severely biased.
|
151 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
152 |
+
|
153 |
+
# 5. Conduct final quality validation and save metadata
|
154 |
+
is_usable = validate_and_save_cohort_info(
|
155 |
+
is_final=True,
|
156 |
+
cohort=cohort,
|
157 |
+
info_path=json_path,
|
158 |
+
is_gene_available=True,
|
159 |
+
is_trait_available=True, # We do have a trait column
|
160 |
+
is_biased=trait_biased,
|
161 |
+
df=linked_data,
|
162 |
+
note="Cohort data successfully processed with trait-based analysis."
|
163 |
+
)
|
164 |
+
|
165 |
+
# 6. If the dataset is usable, save the final linked data
|
166 |
+
if is_usable:
|
167 |
+
linked_data.to_csv(out_data_file, index=True)
|
168 |
+
print(f"Saved final linked data to {out_data_file}")
|
169 |
+
else:
|
170 |
+
print("The dataset is not usable for trait-based association. Skipping final output.")
|
p1/preprocess/Aniridia/code/GSE137997.py
ADDED
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Aniridia"
|
6 |
+
cohort = "GSE137997"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Aniridia"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Aniridia/GSE137997"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Aniridia/GSE137997.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Aniridia/gene_data/GSE137997.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Aniridia/clinical_data/GSE137997.csv"
|
16 |
+
json_path = "./output/preprocess/1/Aniridia/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# 1. Determine if gene expression data is available
|
43 |
+
is_gene_available = True # The title mentions "mRNA" alongside miRNA, so we consider gene expression data present.
|
44 |
+
|
45 |
+
# 2. Identify rows for trait, age, and gender, and define their conversion functions
|
46 |
+
|
47 |
+
# Based on the sample characteristics dictionary:
|
48 |
+
# 0 -> age data
|
49 |
+
# 1 -> gender data
|
50 |
+
# 2 -> "disease: AAK" or "disease: healthy control"
|
51 |
+
# This suggests:
|
52 |
+
trait_row = 2
|
53 |
+
age_row = 0
|
54 |
+
gender_row = 1
|
55 |
+
|
56 |
+
def convert_trait(value: str) -> int:
|
57 |
+
"""
|
58 |
+
Convert 'disease: AAK' or 'disease: healthy control' to binary (1 for aniridia, 0 for control).
|
59 |
+
Unknown or unexpected values become None.
|
60 |
+
"""
|
61 |
+
try:
|
62 |
+
val = value.split(':', 1)[1].strip().lower()
|
63 |
+
if 'aak' in val:
|
64 |
+
return 1
|
65 |
+
elif 'healthy' in val:
|
66 |
+
return 0
|
67 |
+
else:
|
68 |
+
return None
|
69 |
+
except:
|
70 |
+
return None
|
71 |
+
|
72 |
+
def convert_age(value: str) -> float:
|
73 |
+
"""
|
74 |
+
Convert 'age: 20' etc. to a float (continuous). Unknown values become None.
|
75 |
+
"""
|
76 |
+
try:
|
77 |
+
val = value.split(':', 1)[1].strip()
|
78 |
+
return float(val)
|
79 |
+
except:
|
80 |
+
return None
|
81 |
+
|
82 |
+
def convert_gender(value: str) -> int:
|
83 |
+
"""
|
84 |
+
Convert 'gender: F', 'gender: M', 'gender: W' to binary (female=0, male=1).
|
85 |
+
'W' presumed female. Unknown or unexpected become None.
|
86 |
+
"""
|
87 |
+
try:
|
88 |
+
val = value.split(':', 1)[1].strip().lower()
|
89 |
+
if val in ['f', 'w', 'female', 'woman', 'women']:
|
90 |
+
return 0
|
91 |
+
elif val in ['m', 'male']:
|
92 |
+
return 1
|
93 |
+
else:
|
94 |
+
return None
|
95 |
+
except:
|
96 |
+
return None
|
97 |
+
|
98 |
+
# 3. Conduct initial filtering and save metadata
|
99 |
+
is_trait_available = (trait_row is not None)
|
100 |
+
validate_and_save_cohort_info(
|
101 |
+
is_final=False,
|
102 |
+
cohort=cohort,
|
103 |
+
info_path=json_path,
|
104 |
+
is_gene_available=is_gene_available,
|
105 |
+
is_trait_available=is_trait_available
|
106 |
+
)
|
107 |
+
|
108 |
+
# 4. Clinical feature extraction if trait data is available
|
109 |
+
if trait_row is not None:
|
110 |
+
selected_clinical_df = geo_select_clinical_features(
|
111 |
+
clinical_df=clinical_data,
|
112 |
+
trait=trait,
|
113 |
+
trait_row=trait_row,
|
114 |
+
convert_trait=convert_trait,
|
115 |
+
age_row=age_row,
|
116 |
+
convert_age=convert_age,
|
117 |
+
gender_row=gender_row,
|
118 |
+
convert_gender=convert_gender
|
119 |
+
)
|
120 |
+
# Preview
|
121 |
+
preview_result = preview_df(selected_clinical_df)
|
122 |
+
print("Preview of selected clinical features:", preview_result)
|
123 |
+
# Save clinical data
|
124 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
125 |
+
# STEP3
|
126 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
127 |
+
gene_data = get_genetic_data(matrix_file)
|
128 |
+
|
129 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
130 |
+
print(gene_data.index[:20])
|
131 |
+
# These are microRNA identifiers (e.g. hsa-miR-1-3p) rather than standard human gene symbols;
|
132 |
+
# they do not require further mapping to gene symbols.
|
133 |
+
print("requires_gene_mapping = False")
|
134 |
+
# STEP 7: Data Normalization and Linking
|
135 |
+
|
136 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
137 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
138 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
139 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
140 |
+
|
141 |
+
# 2. Link the clinical and genetic data on sample IDs
|
142 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
143 |
+
|
144 |
+
# 3. Handle missing values, removing or imputing as instructed
|
145 |
+
linked_data = handle_missing_values(linked_data, trait)
|
146 |
+
|
147 |
+
# 4. Determine whether the trait (and potentially other features) is severely biased.
|
148 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
149 |
+
|
150 |
+
# 5. Conduct final quality validation and save metadata
|
151 |
+
is_usable = validate_and_save_cohort_info(
|
152 |
+
is_final=True,
|
153 |
+
cohort=cohort,
|
154 |
+
info_path=json_path,
|
155 |
+
is_gene_available=True,
|
156 |
+
is_trait_available=True, # We do have a trait column
|
157 |
+
is_biased=trait_biased,
|
158 |
+
df=linked_data,
|
159 |
+
note="Cohort data successfully processed with trait-based analysis."
|
160 |
+
)
|
161 |
+
|
162 |
+
# 6. If the dataset is usable, save the final linked data
|
163 |
+
if is_usable:
|
164 |
+
linked_data.to_csv(out_data_file, index=True)
|
165 |
+
print(f"Saved final linked data to {out_data_file}")
|
166 |
+
else:
|
167 |
+
print("The dataset is not usable for trait-based association. Skipping final output.")
|
p1/preprocess/Aniridia/code/GSE204791.py
ADDED
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Aniridia"
|
6 |
+
cohort = "GSE204791"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Aniridia"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Aniridia/GSE204791"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Aniridia/GSE204791.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Aniridia/gene_data/GSE204791.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Aniridia/clinical_data/GSE204791.csv"
|
16 |
+
json_path = "./output/preprocess/1/Aniridia/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# 1. Gene Expression Data Availability
|
43 |
+
is_gene_available = True # The series includes mRNA expression, so we consider it gene expression data.
|
44 |
+
|
45 |
+
# 2. Variable Availability and Data Type Conversion
|
46 |
+
# 2.1 Determine row indices for 'trait', 'age', 'gender'
|
47 |
+
# Based on the sample characteristics dictionary:
|
48 |
+
# - 0: ['age: 59', 'age: 28', ... ]
|
49 |
+
# - 1: ['gender: F', 'gender: M']
|
50 |
+
# - 2: ['disease: KC', 'disease: healthy control']
|
51 |
+
# - 3: [ ... staging info ... ]
|
52 |
+
# We are looking for "Aniridia" but our dictionary lists "KC" or "healthy control" for disease.
|
53 |
+
# Hence, we do not have data for "Aniridia." So trait_row = None.
|
54 |
+
|
55 |
+
trait_row = None # No data on "Aniridia" found
|
56 |
+
age_row = 0 # Multiple ages are present
|
57 |
+
gender_row = 1 # "F" and "M" are present
|
58 |
+
|
59 |
+
# 2.2 Write conversion functions
|
60 |
+
def convert_trait(val: str):
|
61 |
+
"""
|
62 |
+
Attempt to parse 'Aniridia' or 'control' from the string after the colon.
|
63 |
+
Since 'Aniridia' is not actually in our sample data, return None.
|
64 |
+
"""
|
65 |
+
return None
|
66 |
+
|
67 |
+
def convert_age(val: str):
|
68 |
+
"""
|
69 |
+
Parse the value after the colon and convert to float.
|
70 |
+
Non-numeric or invalid data is converted to None.
|
71 |
+
"""
|
72 |
+
parts = val.split(':')
|
73 |
+
if len(parts) < 2:
|
74 |
+
return None
|
75 |
+
raw_value = parts[1].strip()
|
76 |
+
try:
|
77 |
+
return float(raw_value)
|
78 |
+
except ValueError:
|
79 |
+
return None
|
80 |
+
|
81 |
+
def convert_gender(val: str):
|
82 |
+
"""
|
83 |
+
Parse the value after the colon and convert:
|
84 |
+
F -> 0
|
85 |
+
M -> 1
|
86 |
+
Otherwise -> None
|
87 |
+
"""
|
88 |
+
parts = val.split(':')
|
89 |
+
if len(parts) < 2:
|
90 |
+
return None
|
91 |
+
raw_value = parts[1].strip().upper()
|
92 |
+
if raw_value == 'F':
|
93 |
+
return 0
|
94 |
+
elif raw_value == 'M':
|
95 |
+
return 1
|
96 |
+
else:
|
97 |
+
return None
|
98 |
+
|
99 |
+
# 3. Save Metadata
|
100 |
+
# Trait data availability is determined by whether trait_row is None.
|
101 |
+
is_trait_available = (trait_row is not None)
|
102 |
+
|
103 |
+
# Perform initial filtering (is_final=False).
|
104 |
+
# This will record metadata if data fails initial filtering.
|
105 |
+
is_usable = validate_and_save_cohort_info(
|
106 |
+
is_final=False,
|
107 |
+
cohort=cohort,
|
108 |
+
info_path=json_path,
|
109 |
+
is_gene_available=is_gene_available,
|
110 |
+
is_trait_available=is_trait_available
|
111 |
+
)
|
112 |
+
|
113 |
+
# 4. Clinical Feature Extraction
|
114 |
+
# Since trait_row is None, clinical data extraction is skipped.
|
115 |
+
# STEP3
|
116 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
117 |
+
gene_data = get_genetic_data(matrix_file)
|
118 |
+
|
119 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
120 |
+
print(gene_data.index[:20])
|
121 |
+
# These identifiers appear to be microarray probe IDs or custom probe identifiers rather than standard human gene symbols.
|
122 |
+
# Therefore, they need to be mapped to gene symbols.
|
123 |
+
|
124 |
+
requires_gene_mapping = True
|
125 |
+
# STEP5
|
126 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
127 |
+
gene_annotation = get_gene_annotation(soft_file)
|
128 |
+
|
129 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
130 |
+
print("Gene annotation preview:")
|
131 |
+
print(preview_df(gene_annotation))
|
132 |
+
# Gene Identifier Mapping
|
133 |
+
|
134 |
+
# 1. Identify which columns correspond to the expression data's probe ID and to the gene symbols.
|
135 |
+
# From the annotation preview, "ID" appears to match the probe identifiers (e.g., "A_19_P..."),
|
136 |
+
# and "GENE_SYMBOL" appears to be the gene symbol column.
|
137 |
+
|
138 |
+
probe_id_col = "ID"
|
139 |
+
gene_symbol_col = "GENE_SYMBOL"
|
140 |
+
|
141 |
+
# 2. Extract the mapping information between probe IDs and gene symbols.
|
142 |
+
gene_mapping_df = get_gene_mapping(gene_annotation, probe_id_col, gene_symbol_col)
|
143 |
+
|
144 |
+
# 3. Apply the mapping to convert probe-level data into gene-level data.
|
145 |
+
gene_data = apply_gene_mapping(gene_data, gene_mapping_df)
|
146 |
+
# STEP 7: Data Normalization and Linking
|
147 |
+
|
148 |
+
import pandas as pd
|
149 |
+
|
150 |
+
# Since in previous steps we determined trait_row = None (no available trait data),
|
151 |
+
# we cannot link clinical data or perform trait-based filtering. Hence, we skip steps
|
152 |
+
# that depend on clinical or trait information.
|
153 |
+
|
154 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
155 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
156 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
157 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
158 |
+
|
159 |
+
# 2. No trait data found; skip clinical linking, missing-value handling, and bias assessment.
|
160 |
+
print("No trait data found. Skipping clinical linking, missing-value handling, and bias assessment.")
|
161 |
+
|
162 |
+
# 3. Conduct final quality validation and save metadata.
|
163 |
+
# Since there's no trait data, we must pass some dummy DataFrame and a boolean for is_biased
|
164 |
+
# to avoid the ValueError in final mode.
|
165 |
+
dummy_df = pd.DataFrame()
|
166 |
+
is_biased_dummy = False # Arbitrary placeholder since we can't assess bias
|
167 |
+
is_usable = validate_and_save_cohort_info(
|
168 |
+
is_final=True,
|
169 |
+
cohort=cohort,
|
170 |
+
info_path=json_path,
|
171 |
+
is_gene_available=True,
|
172 |
+
is_trait_available=False,
|
173 |
+
is_biased=is_biased_dummy,
|
174 |
+
df=dummy_df,
|
175 |
+
note="Trait data not found; dataset cannot be used for trait-based analysis."
|
176 |
+
)
|
177 |
+
|
178 |
+
# 4. Because we don't have usable trait data, skip saving the linked data
|
179 |
+
if is_usable:
|
180 |
+
# This case should not occur since there's no trait data
|
181 |
+
pass
|
182 |
+
else:
|
183 |
+
print("The dataset is not usable for trait-based association. Skipping final output.")
|
p1/preprocess/Aniridia/code/TCGA.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Aniridia"
|
6 |
+
|
7 |
+
# Input paths
|
8 |
+
tcga_root_dir = "../DATA/TCGA"
|
9 |
+
|
10 |
+
# Output paths
|
11 |
+
out_data_file = "./output/preprocess/1/Aniridia/TCGA.csv"
|
12 |
+
out_gene_data_file = "./output/preprocess/1/Aniridia/gene_data/TCGA.csv"
|
13 |
+
out_clinical_data_file = "./output/preprocess/1/Aniridia/clinical_data/TCGA.csv"
|
14 |
+
json_path = "./output/preprocess/1/Aniridia/cohort_info.json"
|
15 |
+
|
16 |
+
import os
|
17 |
+
import pandas as pd
|
18 |
+
|
19 |
+
# 1. Identify the relevant subdirectory for the trait "Obesity"
|
20 |
+
subdirectories = [
|
21 |
+
'CrawlData.ipynb', '.DS_Store', 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
|
22 |
+
'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)', 'TCGA_Thymoma_(THYM)',
|
23 |
+
'TCGA_Testicular_Cancer_(TGCT)', 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
|
24 |
+
'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)', 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)',
|
25 |
+
'TCGA_Pancreatic_Cancer_(PAAD)', 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
|
26 |
+
'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)', 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)',
|
27 |
+
'TCGA_Lung_Cancer_(LUNG)', 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
|
28 |
+
'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)', 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)',
|
29 |
+
'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)', 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
|
30 |
+
'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)', 'TCGA_Endometrioid_Cancer_(UCEC)',
|
31 |
+
'TCGA_Colon_and_Rectal_Cancer_(COADREAD)', 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
|
32 |
+
'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)', 'TCGA_Bile_Duct_Cancer_(CHOL)',
|
33 |
+
'TCGA_Adrenocortical_Cancer_(ACC)', 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
|
34 |
+
]
|
35 |
+
|
36 |
+
trait_keyword = trait
|
37 |
+
target_subdir = None
|
38 |
+
|
39 |
+
for sd in subdirectories:
|
40 |
+
if trait_keyword.lower() in sd.lower():
|
41 |
+
target_subdir = sd
|
42 |
+
break
|
43 |
+
|
44 |
+
if target_subdir is None:
|
45 |
+
# No suitable data found for this trait; mark as completed
|
46 |
+
print("No TCGA subdirectory found for the trait. Skipping.")
|
47 |
+
else:
|
48 |
+
# 2. Locate clinical and genetic data files
|
49 |
+
cohort_dir = os.path.join(tcga_root_dir, target_subdir)
|
50 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
51 |
+
|
52 |
+
# 3. Load the data
|
53 |
+
clinical_df = pd.read_csv(clinical_file_path, index_col=0, sep='\t')
|
54 |
+
genetic_df = pd.read_csv(genetic_file_path, index_col=0, sep='\t')
|
55 |
+
|
56 |
+
# 4. Print column names of clinical data
|
57 |
+
print(clinical_df.columns)
|
p1/preprocess/Aniridia/cohort_info.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"GSE204791": {"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": "Trait data not found; dataset cannot be used for trait-based analysis."}, "GSE137997": {"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": "Cohort data successfully processed with trait-based analysis."}, "GSE137996": {"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": "Cohort data successfully processed with trait-based analysis."}}
|
p1/preprocess/Aniridia/gene_data/GSE137996.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,GSM4096389,GSM4096390,GSM4096391,GSM4096392,GSM4096393,GSM4096394,GSM4096395,GSM4096396,GSM4096397,GSM4096398,GSM4096399,GSM4096400,GSM4096401,GSM4096402,GSM4096403,GSM4096404,GSM4096405,GSM4096406,GSM4096407,GSM4096408,GSM4096409,GSM4096410,GSM4096411,GSM4096412,GSM4096413,GSM4096414,GSM4096415,GSM4096416,GSM4096417,GSM4096418,GSM4096419,GSM4096420,GSM4096421,GSM4096422,GSM4096423,GSM4096424,GSM4096425,GSM4096426,GSM4096427,GSM4096428
|
p1/preprocess/Aniridia/gene_data/GSE137997.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ID,GSM4096349,GSM4096350,GSM4096351,GSM4096352,GSM4096353,GSM4096354,GSM4096355,GSM4096356,GSM4096357,GSM4096358,GSM4096359,GSM4096360,GSM4096361,GSM4096362,GSM4096363,GSM4096364,GSM4096365,GSM4096366,GSM4096367,GSM4096368,GSM4096369,GSM4096370,GSM4096371,GSM4096372,GSM4096373,GSM4096374,GSM4096375,GSM4096376,GSM4096377,GSM4096378,GSM4096379,GSM4096380,GSM4096381,GSM4096382,GSM4096383,GSM4096384,GSM4096385,GSM4096386,GSM4096387,GSM4096388
|
p1/preprocess/Aniridia/gene_data/GSE204791.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,GSM6193900,GSM6193903,GSM6193906,GSM6193908,GSM6193911,GSM6193913,GSM6193916,GSM6193918,GSM6193920,GSM6193923,GSM6193925,GSM6193928,GSM6193930,GSM6193933,GSM6193935,GSM6193938,GSM6193940,GSM6193943,GSM6193945,GSM6193948,GSM6193950,GSM6193953,GSM6193955,GSM6193957,GSM6193960,GSM6193962,GSM6193965,GSM6193967,GSM6193970,GSM6193972,GSM6193975
|
p1/preprocess/Ankylosing_Spondylitis/clinical_data/GSE25101.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
GSM616668,GSM616669,GSM616670,GSM616671,GSM616672,GSM616673,GSM616674,GSM616675,GSM616676,GSM616677,GSM616678,GSM616679,GSM616680,GSM616681,GSM616682,GSM616683,GSM616684,GSM616685,GSM616686,GSM616687,GSM616688,GSM616689,GSM616690,GSM616691,GSM616692,GSM616693,GSM616694,GSM616695,GSM616696,GSM616697,GSM616698,GSM616699
|
2 |
+
1.0,1.0,1.0,1.0,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
|
p1/preprocess/Ankylosing_Spondylitis/clinical_data/GSE73754.csv
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GSM1902130,GSM1902131,GSM1902132,GSM1902133,GSM1902134,GSM1902135,GSM1902136,GSM1902137,GSM1902138,GSM1902139,GSM1902140,GSM1902141,GSM1902142,GSM1902143,GSM1902144,GSM1902145,GSM1902146,GSM1902147,GSM1902148,GSM1902149,GSM1902150,GSM1902151,GSM1902152,GSM1902153,GSM1902154,GSM1902155,GSM1902156,GSM1902157,GSM1902158,GSM1902159,GSM1902160,GSM1902161,GSM1902162,GSM1902163,GSM1902164,GSM1902165,GSM1902166,GSM1902167,GSM1902168,GSM1902169,GSM1902170,GSM1902171,GSM1902172,GSM1902173,GSM1902174,GSM1902175,GSM1902176,GSM1902177,GSM1902178,GSM1902179,GSM1902180,GSM1902181,GSM1902182,GSM1902183,GSM1902184,GSM1902185,GSM1902186,GSM1902187,GSM1902188,GSM1902189,GSM1902190,GSM1902191,GSM1902192,GSM1902193,GSM1902194,GSM1902195,GSM1902196,GSM1902197,GSM1902198,GSM1902199,GSM1902200,GSM1902201
|
2 |
+
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,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
|
3 |
+
53.0,26.0,29.0,50.0,35.0,48.0,18.0,39.0,49.0,43.0,43.0,18.0,59.0,51.0,18.0,45.0,52.0,77.0,34.0,31.0,51.0,23.0,52.0,46.0,40.0,55.0,54.0,41.0,38.0,45.0,52.0,43.0,41.0,21.0,47.0,60.0,46.0,27.0,37.0,28.0,37.0,48.0,41.0,53.0,39.0,18.0,50.0,22.0,48.0,57.0,23.0,56.0,28.0,26.0,65.0,41.0,32.0,56.0,47.0,71.0,24.0,24.0,27.0,37.0,42.0,63.0,61.0,20.0,31.0,25.0,29.0,65.0
|
4 |
+
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
|
p1/preprocess/Ankylosing_Spondylitis/code/GSE25101.py
ADDED
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Ankylosing_Spondylitis"
|
6 |
+
cohort = "GSE25101"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Ankylosing_Spondylitis"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Ankylosing_Spondylitis/GSE25101"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Ankylosing_Spondylitis/GSE25101.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Ankylosing_Spondylitis/gene_data/GSE25101.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Ankylosing_Spondylitis/clinical_data/GSE25101.csv"
|
16 |
+
json_path = "./output/preprocess/1/Ankylosing_Spondylitis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# 1) Gene Expression Data Availability
|
43 |
+
# Based on the series description, this dataset uses "Illumina HT-12 Whole-Genome Expression BeadChips".
|
44 |
+
# Hence, we conclude that it likely contains gene expression data.
|
45 |
+
is_gene_available = True
|
46 |
+
|
47 |
+
# 2) Variable Availability and Data Type Conversion
|
48 |
+
|
49 |
+
# Inspecting the sample characteristics dictionary:
|
50 |
+
# {0: ['tissue: Whole blood'],
|
51 |
+
# 1: ['cell type: PBMC'],
|
52 |
+
# 2: ['disease status: Ankylosing spondylitis patient', 'disease status: Normal control']}
|
53 |
+
|
54 |
+
# -- Trait --
|
55 |
+
# The data for "Ankylosing_Spondylitis" can be inferred from key=2 (it has at least 2 unique values).
|
56 |
+
trait_row = 2
|
57 |
+
|
58 |
+
# -- Age --
|
59 |
+
# No age information is found. So:
|
60 |
+
age_row = None
|
61 |
+
|
62 |
+
# -- Gender --
|
63 |
+
# No gender information is found. So:
|
64 |
+
gender_row = None
|
65 |
+
|
66 |
+
# Data type choices:
|
67 |
+
# Since the "trait" variable has two categories (patient vs control), we treat it as binary.
|
68 |
+
# For "age" and "gender", no data is available, so we won't convert.
|
69 |
+
|
70 |
+
def convert_trait(value: str):
|
71 |
+
"""
|
72 |
+
Convert disease status to binary:
|
73 |
+
'Ankylosing spondylitis patient' -> 1
|
74 |
+
'Normal control' -> 0
|
75 |
+
Unknown -> None
|
76 |
+
"""
|
77 |
+
# Split by ':', then take the part after the colon if present
|
78 |
+
parts = value.split(':', 1)
|
79 |
+
val = parts[1].strip().lower() if len(parts) > 1 else parts[0].strip().lower()
|
80 |
+
|
81 |
+
if 'ankylosing spondylitis patient' in val:
|
82 |
+
return 1
|
83 |
+
elif 'normal control' in val:
|
84 |
+
return 0
|
85 |
+
else:
|
86 |
+
return None
|
87 |
+
|
88 |
+
def convert_age(value: str):
|
89 |
+
# Age not available in this dataset, so all become None
|
90 |
+
return None
|
91 |
+
|
92 |
+
def convert_gender(value: str):
|
93 |
+
# Gender not available in this dataset, so all become None
|
94 |
+
return None
|
95 |
+
|
96 |
+
# 3) Save Metadata with initial filtering
|
97 |
+
# Trait data is available if trait_row is not None
|
98 |
+
is_trait_available = (trait_row is not None)
|
99 |
+
|
100 |
+
is_usable = validate_and_save_cohort_info(
|
101 |
+
is_final=False,
|
102 |
+
cohort=cohort,
|
103 |
+
info_path=json_path,
|
104 |
+
is_gene_available=is_gene_available,
|
105 |
+
is_trait_available=is_trait_available
|
106 |
+
)
|
107 |
+
|
108 |
+
# 4) Clinical Feature Extraction (only if trait_row is not None)
|
109 |
+
if trait_row is not None:
|
110 |
+
selected_clinical = geo_select_clinical_features(
|
111 |
+
clinical_df=clinical_data, # assume 'clinical_data' was loaded in a previous step
|
112 |
+
trait=trait,
|
113 |
+
trait_row=trait_row,
|
114 |
+
convert_trait=convert_trait,
|
115 |
+
age_row=age_row,
|
116 |
+
convert_age=convert_age,
|
117 |
+
gender_row=gender_row,
|
118 |
+
convert_gender=convert_gender
|
119 |
+
)
|
120 |
+
# Preview the extracted clinical features
|
121 |
+
print("Preview of selected clinical features:")
|
122 |
+
print(preview_df(selected_clinical, n=5))
|
123 |
+
|
124 |
+
# Save the clinical data
|
125 |
+
selected_clinical.to_csv(out_clinical_data_file, index=False)
|
126 |
+
# STEP3
|
127 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
128 |
+
gene_data = get_genetic_data(matrix_file)
|
129 |
+
|
130 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
131 |
+
print(gene_data.index[:20])
|
132 |
+
# These ILMN_* identifiers are Illumina probe IDs, not standard human gene symbols.
|
133 |
+
# Therefore, they require mapping to gene symbols.
|
134 |
+
|
135 |
+
print("requires_gene_mapping = True")
|
136 |
+
# STEP5
|
137 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
138 |
+
gene_annotation = get_gene_annotation(soft_file)
|
139 |
+
|
140 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
141 |
+
print("Gene annotation preview:")
|
142 |
+
print(preview_df(gene_annotation))
|
143 |
+
# STEP: Gene Identifier Mapping
|
144 |
+
|
145 |
+
# 1) Identify the columns in gene_annotation that match gene_data's "ID" and the gene symbol
|
146 |
+
# From inspection, "ID" corresponds to the Illumina probe IDs in gene_data, and "Symbol" contains the gene symbols.
|
147 |
+
|
148 |
+
# 2) Create the gene mapping dataframe using probe IDs and gene symbols
|
149 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='Symbol')
|
150 |
+
|
151 |
+
# 3) Convert probe-level to gene-level data using the mapping
|
152 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=mapping_df)
|
153 |
+
|
154 |
+
# Print out some information about the mapped gene data
|
155 |
+
print("Gene expression data after mapping:")
|
156 |
+
print("Shape of gene_data:", gene_data.shape)
|
157 |
+
print("First 20 mapped gene symbols:", list(gene_data.index[:20]))
|
158 |
+
# STEP 7: Data Normalization and Linking
|
159 |
+
|
160 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
161 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
162 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
163 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
164 |
+
|
165 |
+
# 2. Link the clinical and genetic data on sample IDs
|
166 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical, normalized_gene_data)
|
167 |
+
|
168 |
+
# 3. Handle missing values, removing or imputing as instructed
|
169 |
+
linked_data = handle_missing_values(linked_data, trait)
|
170 |
+
|
171 |
+
# 4. Determine whether the trait (and potentially other features) is severely biased.
|
172 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
173 |
+
|
174 |
+
# 5. Conduct final quality validation and save metadata
|
175 |
+
is_usable = validate_and_save_cohort_info(
|
176 |
+
is_final=True,
|
177 |
+
cohort=cohort,
|
178 |
+
info_path=json_path,
|
179 |
+
is_gene_available=True,
|
180 |
+
is_trait_available=True, # We do have a trait column
|
181 |
+
is_biased=trait_biased,
|
182 |
+
df=linked_data,
|
183 |
+
note="Cohort data successfully processed with trait-based analysis."
|
184 |
+
)
|
185 |
+
|
186 |
+
# 6. If the dataset is usable, save the final linked data
|
187 |
+
if is_usable:
|
188 |
+
linked_data.to_csv(out_data_file, index=True)
|
189 |
+
print(f"Saved final linked data to {out_data_file}")
|
190 |
+
else:
|
191 |
+
print("The dataset is not usable for trait-based association. Skipping final output.")
|
p1/preprocess/Ankylosing_Spondylitis/code/GSE73754.py
ADDED
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Ankylosing_Spondylitis"
|
6 |
+
cohort = "GSE73754"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Ankylosing_Spondylitis"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Ankylosing_Spondylitis/GSE73754"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Ankylosing_Spondylitis/GSE73754.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Ankylosing_Spondylitis/gene_data/GSE73754.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Ankylosing_Spondylitis/clinical_data/GSE73754.csv"
|
16 |
+
json_path = "./output/preprocess/1/Ankylosing_Spondylitis/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# Step 1. Determine gene expression data availability
|
43 |
+
is_gene_available = True # Based on the background (differential gene expression analysis), we consider this dataset to have gene data
|
44 |
+
|
45 |
+
# Step 2. Identify data availability for trait, age, and gender
|
46 |
+
# According to the sample characteristics dictionary:
|
47 |
+
# 0 -> 'Sex: Male', 'Sex: Female'
|
48 |
+
# 1 -> 'age (yr): 53', ...
|
49 |
+
# 3 -> 'disease: Ankylosing Spondylitis', 'disease: healthy control'
|
50 |
+
trait_row = 3
|
51 |
+
age_row = 1
|
52 |
+
gender_row = 0
|
53 |
+
|
54 |
+
# Step 2.2 Define conversion functions
|
55 |
+
def convert_trait(x: str):
|
56 |
+
# e.g., "disease: Ankylosing Spondylitis" -> 1, "disease: healthy control" -> 0
|
57 |
+
# parse out the value after the colon
|
58 |
+
try:
|
59 |
+
val = x.split(":", 1)[1].strip().lower()
|
60 |
+
except IndexError:
|
61 |
+
return None
|
62 |
+
if "ankylosing spondylitis" in val:
|
63 |
+
return 1
|
64 |
+
elif "healthy control" in val:
|
65 |
+
return 0
|
66 |
+
else:
|
67 |
+
return None
|
68 |
+
|
69 |
+
def convert_age(x: str):
|
70 |
+
# e.g., "age (yr): 53" -> 53
|
71 |
+
try:
|
72 |
+
val = x.split(":", 1)[1].strip()
|
73 |
+
return float(val)
|
74 |
+
except:
|
75 |
+
return None
|
76 |
+
|
77 |
+
def convert_gender(x: str):
|
78 |
+
# e.g., "Sex: Male" -> 1, "Sex: Female" -> 0
|
79 |
+
try:
|
80 |
+
val = x.split(":", 1)[1].strip().lower()
|
81 |
+
except IndexError:
|
82 |
+
return None
|
83 |
+
if "male" in val:
|
84 |
+
return 1
|
85 |
+
elif "female" in val:
|
86 |
+
return 0
|
87 |
+
else:
|
88 |
+
return None
|
89 |
+
|
90 |
+
# Step 3. Initial filtering and save metadata
|
91 |
+
is_trait_available = (trait_row is not None)
|
92 |
+
validate_and_save_cohort_info(
|
93 |
+
is_final=False,
|
94 |
+
cohort=cohort,
|
95 |
+
info_path=json_path,
|
96 |
+
is_gene_available=is_gene_available,
|
97 |
+
is_trait_available=is_trait_available
|
98 |
+
)
|
99 |
+
|
100 |
+
# Step 4. Clinical feature extraction (only if trait_row is not None)
|
101 |
+
if trait_row is not None:
|
102 |
+
# 'clinical_data' is assumed to be the DataFrame previously obtained for sample characteristics
|
103 |
+
selected_clinical_df = geo_select_clinical_features(
|
104 |
+
clinical_df=clinical_data,
|
105 |
+
trait=trait,
|
106 |
+
trait_row=trait_row,
|
107 |
+
convert_trait=convert_trait,
|
108 |
+
age_row=age_row,
|
109 |
+
convert_age=convert_age,
|
110 |
+
gender_row=gender_row,
|
111 |
+
convert_gender=convert_gender
|
112 |
+
)
|
113 |
+
|
114 |
+
# Preview the result
|
115 |
+
print("Preview of clinical features:")
|
116 |
+
print(preview_df(selected_clinical_df, n=5))
|
117 |
+
|
118 |
+
# Save to CSV
|
119 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
120 |
+
# STEP3
|
121 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
122 |
+
gene_data = get_genetic_data(matrix_file)
|
123 |
+
|
124 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
125 |
+
print(gene_data.index[:20])
|
126 |
+
# The observed gene identifiers (ILMN_####) are Illumina microarray probe IDs.
|
127 |
+
# They are not standard human gene symbols and require mapping to official gene symbols.
|
128 |
+
print("requires_gene_mapping = True")
|
129 |
+
# STEP5
|
130 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
131 |
+
gene_annotation = get_gene_annotation(soft_file)
|
132 |
+
|
133 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
134 |
+
print("Gene annotation preview:")
|
135 |
+
print(preview_df(gene_annotation))
|
136 |
+
# STEP: Gene Identifier Mapping
|
137 |
+
|
138 |
+
# 1. Identify the annotation columns for mapping
|
139 |
+
# - The gene expression data uses 'ILMN_####' as identifiers, which match the 'ID' column in the annotation.
|
140 |
+
# - The gene symbols are in the 'Symbol' column.
|
141 |
+
|
142 |
+
# 2. Extract the gene mapping dataframe using the library function
|
143 |
+
gene_mapping_df = get_gene_mapping(annotation=gene_annotation, prob_col='ID', gene_col='Symbol')
|
144 |
+
|
145 |
+
# 3. Convert probe-level measurements to gene expression data
|
146 |
+
gene_data = apply_gene_mapping(expression_df=gene_data, mapping_df=gene_mapping_df)
|
147 |
+
|
148 |
+
# Print shape of the new gene_data to confirm processing
|
149 |
+
print("Gene data shape after mapping:", gene_data.shape)
|
150 |
+
# STEP 7: Data Normalization and Linking
|
151 |
+
|
152 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
153 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
154 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
155 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
156 |
+
|
157 |
+
# 2. Link the clinical and genetic data on sample IDs
|
158 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
159 |
+
|
160 |
+
# 3. Handle missing values, removing or imputing as instructed
|
161 |
+
linked_data = handle_missing_values(linked_data, trait)
|
162 |
+
|
163 |
+
# 4. Determine whether the trait (and potentially other features) is severely biased.
|
164 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
165 |
+
|
166 |
+
# 5. Conduct final quality validation and save metadata
|
167 |
+
is_usable = validate_and_save_cohort_info(
|
168 |
+
is_final=True,
|
169 |
+
cohort=cohort,
|
170 |
+
info_path=json_path,
|
171 |
+
is_gene_available=True,
|
172 |
+
is_trait_available=True, # We do have a trait column
|
173 |
+
is_biased=trait_biased,
|
174 |
+
df=linked_data,
|
175 |
+
note="Cohort data successfully processed with trait-based analysis."
|
176 |
+
)
|
177 |
+
|
178 |
+
# 6. If the dataset is usable, save the final linked data
|
179 |
+
if is_usable:
|
180 |
+
linked_data.to_csv(out_data_file, index=True)
|
181 |
+
print(f"Saved final linked data to {out_data_file}")
|
182 |
+
else:
|
183 |
+
print("The dataset is not usable for trait-based association. Skipping final output.")
|
p1/preprocess/Ankylosing_Spondylitis/code/TCGA.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Ankylosing_Spondylitis"
|
6 |
+
|
7 |
+
# Input paths
|
8 |
+
tcga_root_dir = "../DATA/TCGA"
|
9 |
+
|
10 |
+
# Output paths
|
11 |
+
out_data_file = "./output/preprocess/1/Ankylosing_Spondylitis/TCGA.csv"
|
12 |
+
out_gene_data_file = "./output/preprocess/1/Ankylosing_Spondylitis/gene_data/TCGA.csv"
|
13 |
+
out_clinical_data_file = "./output/preprocess/1/Ankylosing_Spondylitis/clinical_data/TCGA.csv"
|
14 |
+
json_path = "./output/preprocess/1/Ankylosing_Spondylitis/cohort_info.json"
|
15 |
+
|
16 |
+
import os
|
17 |
+
import pandas as pd
|
18 |
+
|
19 |
+
# 1. Identify the relevant subdirectory for the trait "Obesity"
|
20 |
+
subdirectories = [
|
21 |
+
'CrawlData.ipynb', '.DS_Store', 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
|
22 |
+
'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)', 'TCGA_Thymoma_(THYM)',
|
23 |
+
'TCGA_Testicular_Cancer_(TGCT)', 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
|
24 |
+
'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)', 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)',
|
25 |
+
'TCGA_Pancreatic_Cancer_(PAAD)', 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
|
26 |
+
'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)', 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)',
|
27 |
+
'TCGA_Lung_Cancer_(LUNG)', 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
|
28 |
+
'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)', 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)',
|
29 |
+
'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)', 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
|
30 |
+
'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)', 'TCGA_Endometrioid_Cancer_(UCEC)',
|
31 |
+
'TCGA_Colon_and_Rectal_Cancer_(COADREAD)', 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
|
32 |
+
'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)', 'TCGA_Bile_Duct_Cancer_(CHOL)',
|
33 |
+
'TCGA_Adrenocortical_Cancer_(ACC)', 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
|
34 |
+
]
|
35 |
+
|
36 |
+
trait_keyword = trait
|
37 |
+
target_subdir = None
|
38 |
+
|
39 |
+
for sd in subdirectories:
|
40 |
+
if trait_keyword.lower() in sd.lower():
|
41 |
+
target_subdir = sd
|
42 |
+
break
|
43 |
+
|
44 |
+
if target_subdir is None:
|
45 |
+
# No suitable data found for this trait; mark as completed
|
46 |
+
print("No TCGA subdirectory found for the trait. Skipping.")
|
47 |
+
else:
|
48 |
+
# 2. Locate clinical and genetic data files
|
49 |
+
cohort_dir = os.path.join(tcga_root_dir, target_subdir)
|
50 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
51 |
+
|
52 |
+
# 3. Load the data
|
53 |
+
clinical_df = pd.read_csv(clinical_file_path, index_col=0, sep='\t')
|
54 |
+
genetic_df = pd.read_csv(genetic_file_path, index_col=0, sep='\t')
|
55 |
+
|
56 |
+
# 4. Print column names of clinical data
|
57 |
+
print(clinical_df.columns)
|
p1/preprocess/Ankylosing_Spondylitis/cohort_info.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"GSE73754": {"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": "Cohort data successfully processed with trait-based analysis."}, "GSE25101": {"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": "Cohort data successfully processed with trait-based analysis."}}
|
p1/preprocess/Ankylosing_Spondylitis/gene_data/GSE25101.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,GSM616668,GSM616669,GSM616670,GSM616671,GSM616672,GSM616673,GSM616674,GSM616675,GSM616676,GSM616677,GSM616678,GSM616679,GSM616680,GSM616681,GSM616682,GSM616683,GSM616684,GSM616685,GSM616686,GSM616687,GSM616688,GSM616689,GSM616690,GSM616691,GSM616692,GSM616693,GSM616694,GSM616695,GSM616696,GSM616697,GSM616698,GSM616699
|
p1/preprocess/Ankylosing_Spondylitis/gene_data/GSE73754.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Gene,GSM1902130,GSM1902131,GSM1902132,GSM1902133,GSM1902134,GSM1902135,GSM1902136,GSM1902137,GSM1902138,GSM1902139,GSM1902140,GSM1902141,GSM1902142,GSM1902143,GSM1902144,GSM1902145,GSM1902146,GSM1902147,GSM1902148,GSM1902149,GSM1902150,GSM1902151,GSM1902152,GSM1902153,GSM1902154,GSM1902155,GSM1902156,GSM1902157,GSM1902158,GSM1902159,GSM1902160,GSM1902161,GSM1902162,GSM1902163,GSM1902164,GSM1902165,GSM1902166,GSM1902167,GSM1902168,GSM1902169,GSM1902170,GSM1902171,GSM1902172,GSM1902173,GSM1902174,GSM1902175,GSM1902176,GSM1902177,GSM1902178,GSM1902179,GSM1902180,GSM1902181,GSM1902182,GSM1902183,GSM1902184,GSM1902185,GSM1902186,GSM1902187,GSM1902188,GSM1902189,GSM1902190,GSM1902191,GSM1902192,GSM1902193,GSM1902194,GSM1902195,GSM1902196,GSM1902197,GSM1902198,GSM1902199,GSM1902200,GSM1902201
|
p1/preprocess/Anorexia_Nervosa/clinical_data/GSE60190.csv
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
,GSM1467273,GSM1467274,GSM1467275,GSM1467276,GSM1467277,GSM1467278,GSM1467279,GSM1467280,GSM1467281,GSM1467282,GSM1467283,GSM1467284,GSM1467285,GSM1467286,GSM1467287,GSM1467288,GSM1467289,GSM1467290,GSM1467291,GSM1467292,GSM1467293,GSM1467294,GSM1467295,GSM1467296,GSM1467297,GSM1467298,GSM1467299,GSM1467300,GSM1467301,GSM1467302,GSM1467303,GSM1467304,GSM1467305,GSM1467306,GSM1467307,GSM1467308,GSM1467309,GSM1467310,GSM1467311,GSM1467312,GSM1467313,GSM1467314,GSM1467315,GSM1467316,GSM1467317,GSM1467318,GSM1467319,GSM1467320,GSM1467321,GSM1467322,GSM1467323,GSM1467324,GSM1467325,GSM1467326,GSM1467327,GSM1467328,GSM1467329,GSM1467330,GSM1467331,GSM1467332,GSM1467333,GSM1467334,GSM1467335,GSM1467336,GSM1467337,GSM1467338,GSM1467339,GSM1467340,GSM1467341,GSM1467342,GSM1467343,GSM1467344,GSM1467345,GSM1467346,GSM1467347,GSM1467348,GSM1467349,GSM1467350,GSM1467351,GSM1467352,GSM1467353,GSM1467354,GSM1467355,GSM1467356,GSM1467357,GSM1467358,GSM1467359,GSM1467360,GSM1467361,GSM1467362,GSM1467363,GSM1467364,GSM1467365,GSM1467366,GSM1467367,GSM1467368,GSM1467369,GSM1467370,GSM1467371,GSM1467372,GSM1467373,GSM1467374,GSM1467375,GSM1467376,GSM1467377,GSM1467378,GSM1467379,GSM1467380,GSM1467381,GSM1467382,GSM1467383,GSM1467384,GSM1467385,GSM1467386,GSM1467387,GSM1467388,GSM1467389,GSM1467390,GSM1467391,GSM1467392,GSM1467393,GSM1467394,GSM1467395,GSM1467396,GSM1467397,GSM1467398,GSM1467399,GSM1467400,GSM1467401,GSM1467402,GSM1467403,GSM1467404,GSM1467405
|
2 |
+
Anorexia_Nervosa,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,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
|
3 |
+
Age,50.421917,27.49863,30.627397,61.167123,32.69589,39.213698,58.605479,49.2,41.041095,51.750684,50.89863,26.745205,29.104109,39.301369,48.978082,57.884931,28.364383,24.041095,19.268493,27.230136,46.605479,23.443835,51.038356,39.663013,46.109589,77.989041,46.967123,63.241095,62.306849,83.641095,42.838356,51.386301,66.715068,51.939726,34.339726,50.109589,18.758904,16.649315,16.353424,42.065753,16.726027,34.465753,34.254794,47.484931,43.756164,49.210958,57.482191,46.561643,49.561643,28.589041,38.410958,30.032876,56.09041,46.915068,49.021917,71.109589,17.235616,16.583561,16.934246,16.8,18.117808,18.660273,16.69589,75.572602,59.260273,55.545205,41.778082,57.454794,45.284931,56.304109,39.654794,55.945205,38.232876,58.109589,40.021917,50.504109,36.550684,45.117808,83.545205,18.786301,48.567123,38.331506,48.101369,18.39452,60.843835,61.372602,52.038356,59.254794,41.567123,50.358904,31.558904,45.701369,44.731506,34.39726,31.613698,54.846575,84.057534,66.79452,53.323287,30.043835,55.435616,45.676712,54.334246,63.558904,45.224657,23.69589,67.865753,16.753424,18.424657,17.09041,16.183561,33.260273,54.424657,45.378082,52.523287,35.273972,22.630136,20.863013,26.531506,24.627397,53.978082,34.961643,18.731506,30.726027,63.471232,54.808219,57.512328,57.610958,44.958904,35.684931,63.0,38.780821,45.978082
|
4 |
+
Gender,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.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,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,0.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,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0
|
p1/preprocess/Anorexia_Nervosa/code/GSE60190.py
ADDED
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Anorexia_Nervosa"
|
6 |
+
cohort = "GSE60190"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Anorexia_Nervosa"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Anorexia_Nervosa/GSE60190"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Anorexia_Nervosa/GSE60190.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Anorexia_Nervosa/gene_data/GSE60190.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Anorexia_Nervosa/clinical_data/GSE60190.csv"
|
16 |
+
json_path = "./output/preprocess/1/Anorexia_Nervosa/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP 1
|
19 |
+
|
20 |
+
from tools.preprocess import *
|
21 |
+
|
22 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
23 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
24 |
+
|
25 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
26 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
27 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
28 |
+
background_info, clinical_data = get_background_and_clinical_data(
|
29 |
+
matrix_file,
|
30 |
+
background_prefixes,
|
31 |
+
clinical_prefixes
|
32 |
+
)
|
33 |
+
|
34 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
35 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
36 |
+
|
37 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
38 |
+
print("Background Information:")
|
39 |
+
print(background_info)
|
40 |
+
print("\nSample Characteristics Dictionary:")
|
41 |
+
print(sample_characteristics_dict)
|
42 |
+
# 1. Determine if gene expression data is available
|
43 |
+
# Based on the background info (Illumina HumanHT-12 v3 microarray measurements),
|
44 |
+
# we conclude that gene expression data is available.
|
45 |
+
is_gene_available = True
|
46 |
+
|
47 |
+
# 2. Identify rows and define conversion functions for trait, age, and gender.
|
48 |
+
|
49 |
+
# After examining the sample characteristics dictionary, we select:
|
50 |
+
# - trait information in row 3 ("dx: ED", "dx: OCD", "dx: Control", etc.)
|
51 |
+
# We'll map "dx: ED" -> 1 (our trait of interest, albeit grouped as ED)
|
52 |
+
# and everything else -> 0.
|
53 |
+
trait_row = 3
|
54 |
+
|
55 |
+
# - age information in row 5 (e.g., "age: 50.421917")
|
56 |
+
age_row = 5
|
57 |
+
|
58 |
+
# - gender information in row 7 (e.g., "Sex: F" or "Sex: M")
|
59 |
+
gender_row = 7
|
60 |
+
|
61 |
+
def convert_trait(x: str) -> Optional[int]:
|
62 |
+
parts = x.split(":", 1)
|
63 |
+
if len(parts) < 2:
|
64 |
+
return None
|
65 |
+
val = parts[1].strip()
|
66 |
+
# Convert "ED" to 1, others (including OCD, Control, etc.) to 0
|
67 |
+
return 1 if val == "ED" else 0
|
68 |
+
|
69 |
+
def convert_age(x: str) -> Optional[float]:
|
70 |
+
parts = x.split(":", 1)
|
71 |
+
if len(parts) < 2:
|
72 |
+
return None
|
73 |
+
val = parts[1].strip()
|
74 |
+
try:
|
75 |
+
return float(val)
|
76 |
+
except ValueError:
|
77 |
+
return None
|
78 |
+
|
79 |
+
def convert_gender(x: str) -> Optional[int]:
|
80 |
+
parts = x.split(":", 1)
|
81 |
+
if len(parts) < 2:
|
82 |
+
return None
|
83 |
+
val = parts[1].strip()
|
84 |
+
# Map "F" -> 0, "M" -> 1
|
85 |
+
if val == "F":
|
86 |
+
return 0
|
87 |
+
elif val == "M":
|
88 |
+
return 1
|
89 |
+
return None
|
90 |
+
|
91 |
+
# 2.1 Check if trait data is available
|
92 |
+
# We consider trait data available if trait_row is not None
|
93 |
+
is_trait_available = (trait_row is not None)
|
94 |
+
|
95 |
+
# 3. Perform initial filtering and save metadata
|
96 |
+
# (is_final=False for initial filtering)
|
97 |
+
is_usable = validate_and_save_cohort_info(
|
98 |
+
is_final=False,
|
99 |
+
cohort=cohort,
|
100 |
+
info_path=json_path,
|
101 |
+
is_gene_available=is_gene_available,
|
102 |
+
is_trait_available=is_trait_available
|
103 |
+
)
|
104 |
+
|
105 |
+
# 4. If trait_row is not None, extract clinical features, preview, and save
|
106 |
+
if trait_row is not None:
|
107 |
+
clinical_data_selected = geo_select_clinical_features(
|
108 |
+
clinical_df=clinical_data,
|
109 |
+
trait=trait,
|
110 |
+
trait_row=trait_row,
|
111 |
+
convert_trait=convert_trait,
|
112 |
+
age_row=age_row,
|
113 |
+
convert_age=convert_age,
|
114 |
+
gender_row=gender_row,
|
115 |
+
convert_gender=convert_gender
|
116 |
+
)
|
117 |
+
# Preview the selected clinical data
|
118 |
+
preview = preview_df(clinical_data_selected)
|
119 |
+
print("Preview of selected clinical features:", preview)
|
120 |
+
|
121 |
+
# Save the clinical features to CSV
|
122 |
+
clinical_data_selected.to_csv(out_clinical_data_file)
|
123 |
+
# STEP3
|
124 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
125 |
+
gene_data = get_genetic_data(matrix_file)
|
126 |
+
|
127 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
128 |
+
print(gene_data.index[:20])
|
129 |
+
print("These are Illumina probe identifiers (e.g., ILMN_xxxx), which are not human gene symbols and thus require mapping.")
|
130 |
+
print("requires_gene_mapping = True")
|
131 |
+
# STEP5
|
132 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
133 |
+
gene_annotation = get_gene_annotation(soft_file)
|
134 |
+
|
135 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
136 |
+
print("Gene annotation preview:")
|
137 |
+
print(preview_df(gene_annotation))
|
138 |
+
# STEP6 - Gene Identifier Mapping
|
139 |
+
|
140 |
+
# 1. Identify the columns for probe IDs and gene symbols in the gene_annotation DataFrame.
|
141 |
+
# From observing the data preview, "ID" holds Illumina probe identifiers matching our gene_data index,
|
142 |
+
# and "Symbol" holds the gene symbol information.
|
143 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="Symbol")
|
144 |
+
|
145 |
+
# 2. Apply this mapping to the probe-level expression data to get gene-level expression data.
|
146 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
147 |
+
|
148 |
+
# Now, 'gene_data' contains gene expression values indexed by gene symbols.
|
149 |
+
# STEP 7: Data Normalization and Linking
|
150 |
+
|
151 |
+
# 1. Normalize gene symbols in the obtained gene expression data
|
152 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
153 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
154 |
+
print(f"Saved normalized gene data to {out_gene_data_file}")
|
155 |
+
|
156 |
+
# Make sure we have the clinical data in scope.
|
157 |
+
# In previous steps, we stored it as 'clinical_data_selected', so define 'selected_clinical' for consistency here.
|
158 |
+
selected_clinical = clinical_data_selected
|
159 |
+
|
160 |
+
# 2. Link the clinical and genetic data on sample IDs
|
161 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical, normalized_gene_data)
|
162 |
+
|
163 |
+
# 3. Handle missing values, removing or imputing as instructed
|
164 |
+
linked_data = handle_missing_values(linked_data, trait)
|
165 |
+
|
166 |
+
# 4. Determine whether the trait (and potentially other features) is severely biased.
|
167 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
168 |
+
|
169 |
+
# 5. Conduct final quality validation and save metadata
|
170 |
+
is_usable = validate_and_save_cohort_info(
|
171 |
+
is_final=True,
|
172 |
+
cohort=cohort,
|
173 |
+
info_path=json_path,
|
174 |
+
is_gene_available=True,
|
175 |
+
is_trait_available=True, # We do have a trait column
|
176 |
+
is_biased=trait_biased,
|
177 |
+
df=linked_data,
|
178 |
+
note="Cohort data successfully processed with trait-based analysis."
|
179 |
+
)
|
180 |
+
|
181 |
+
# 6. If the dataset is usable, save the final linked data
|
182 |
+
if is_usable:
|
183 |
+
linked_data.to_csv(out_data_file, index=True)
|
184 |
+
print(f"Saved final linked data to {out_data_file}")
|
185 |
+
else:
|
186 |
+
print("The dataset is not usable for trait-based association. Skipping final output.")
|
p1/preprocess/Anorexia_Nervosa/code/TCGA.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Anorexia_Nervosa"
|
6 |
+
|
7 |
+
# Input paths
|
8 |
+
tcga_root_dir = "../DATA/TCGA"
|
9 |
+
|
10 |
+
# Output paths
|
11 |
+
out_data_file = "./output/preprocess/1/Anorexia_Nervosa/TCGA.csv"
|
12 |
+
out_gene_data_file = "./output/preprocess/1/Anorexia_Nervosa/gene_data/TCGA.csv"
|
13 |
+
out_clinical_data_file = "./output/preprocess/1/Anorexia_Nervosa/clinical_data/TCGA.csv"
|
14 |
+
json_path = "./output/preprocess/1/Anorexia_Nervosa/cohort_info.json"
|
15 |
+
|
16 |
+
import os
|
17 |
+
import pandas as pd
|
18 |
+
|
19 |
+
# 1. Identify the relevant subdirectory for the trait "Obesity"
|
20 |
+
subdirectories = [
|
21 |
+
'CrawlData.ipynb', '.DS_Store', 'TCGA_lower_grade_glioma_and_glioblastoma_(GBMLGG)',
|
22 |
+
'TCGA_Uterine_Carcinosarcoma_(UCS)', 'TCGA_Thyroid_Cancer_(THCA)', 'TCGA_Thymoma_(THYM)',
|
23 |
+
'TCGA_Testicular_Cancer_(TGCT)', 'TCGA_Stomach_Cancer_(STAD)', 'TCGA_Sarcoma_(SARC)',
|
24 |
+
'TCGA_Rectal_Cancer_(READ)', 'TCGA_Prostate_Cancer_(PRAD)', 'TCGA_Pheochromocytoma_Paraganglioma_(PCPG)',
|
25 |
+
'TCGA_Pancreatic_Cancer_(PAAD)', 'TCGA_Ovarian_Cancer_(OV)', 'TCGA_Ocular_melanomas_(UVM)',
|
26 |
+
'TCGA_Mesothelioma_(MESO)', 'TCGA_Melanoma_(SKCM)', 'TCGA_Lung_Squamous_Cell_Carcinoma_(LUSC)',
|
27 |
+
'TCGA_Lung_Cancer_(LUNG)', 'TCGA_Lung_Adenocarcinoma_(LUAD)', 'TCGA_Lower_Grade_Glioma_(LGG)',
|
28 |
+
'TCGA_Liver_Cancer_(LIHC)', 'TCGA_Large_Bcell_Lymphoma_(DLBC)', 'TCGA_Kidney_Papillary_Cell_Carcinoma_(KIRP)',
|
29 |
+
'TCGA_Kidney_Clear_Cell_Carcinoma_(KIRC)', 'TCGA_Kidney_Chromophobe_(KICH)', 'TCGA_Head_and_Neck_Cancer_(HNSC)',
|
30 |
+
'TCGA_Glioblastoma_(GBM)', 'TCGA_Esophageal_Cancer_(ESCA)', 'TCGA_Endometrioid_Cancer_(UCEC)',
|
31 |
+
'TCGA_Colon_and_Rectal_Cancer_(COADREAD)', 'TCGA_Colon_Cancer_(COAD)', 'TCGA_Cervical_Cancer_(CESC)',
|
32 |
+
'TCGA_Breast_Cancer_(BRCA)', 'TCGA_Bladder_Cancer_(BLCA)', 'TCGA_Bile_Duct_Cancer_(CHOL)',
|
33 |
+
'TCGA_Adrenocortical_Cancer_(ACC)', 'TCGA_Acute_Myeloid_Leukemia_(LAML)'
|
34 |
+
]
|
35 |
+
|
36 |
+
trait_keyword = trait
|
37 |
+
target_subdir = None
|
38 |
+
|
39 |
+
for sd in subdirectories:
|
40 |
+
if trait_keyword.lower() in sd.lower():
|
41 |
+
target_subdir = sd
|
42 |
+
break
|
43 |
+
|
44 |
+
if target_subdir is None:
|
45 |
+
# No suitable data found for this trait; mark as completed
|
46 |
+
print("No TCGA subdirectory found for the trait. Skipping.")
|
47 |
+
else:
|
48 |
+
# 2. Locate clinical and genetic data files
|
49 |
+
cohort_dir = os.path.join(tcga_root_dir, target_subdir)
|
50 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
51 |
+
|
52 |
+
# 3. Load the data
|
53 |
+
clinical_df = pd.read_csv(clinical_file_path, index_col=0, sep='\t')
|
54 |
+
genetic_df = pd.read_csv(genetic_file_path, index_col=0, sep='\t')
|
55 |
+
|
56 |
+
# 4. Print column names of clinical data
|
57 |
+
print(clinical_df.columns)
|
p1/preprocess/Anorexia_Nervosa/cohort_info.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"GSE60190": {"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": "Cohort data successfully processed with trait-based analysis."}}
|