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 +30 -0
- p1/preprocess/Atrial_Fibrillation/GSE115574.csv +3 -0
- p1/preprocess/Atrial_Fibrillation/GSE235307.csv +3 -0
- p1/preprocess/Atrial_Fibrillation/gene_data/GSE115574.csv +3 -0
- p1/preprocess/Atrial_Fibrillation/gene_data/GSE235307.csv +3 -0
- p1/preprocess/Atrial_Fibrillation/gene_data/GSE41177.csv +0 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE111175.csv +3 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE42133.csv +3 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE65106.csv +3 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE87847.csv +3 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE89594.csv +3 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE42133.py +187 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE111175.csv +3 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE123302.csv +1 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE285666.csv +3 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE42133.csv +3 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE57802.csv +3 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE65106.csv +3 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE87847.csv +3 -0
- p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE89594.csv +3 -0
- p1/preprocess/Autoinflammatory_Disorders/GSE80060.csv +3 -0
- p1/preprocess/Autoinflammatory_Disorders/clinical_data/GSE43553.csv +2 -0
- p1/preprocess/Autoinflammatory_Disorders/clinical_data/GSE80060.csv +2 -0
- p1/preprocess/Autoinflammatory_Disorders/code/GSE43553.py +151 -0
- p1/preprocess/Autoinflammatory_Disorders/code/GSE80060.py +158 -0
- p1/preprocess/Autoinflammatory_Disorders/code/TCGA.py +51 -0
- p1/preprocess/Autoinflammatory_Disorders/cohort_info.json +1 -0
- p1/preprocess/Autoinflammatory_Disorders/gene_data/GSE43553.csv +3 -0
- p1/preprocess/Autoinflammatory_Disorders/gene_data/GSE80060.csv +3 -0
- p1/preprocess/Bile_Duct_Cancer/GSE131027.csv +3 -0
- p1/preprocess/Bile_Duct_Cancer/TCGA.csv +3 -0
- p1/preprocess/Bile_Duct_Cancer/clinical_data/GSE107754.csv +3 -0
- p1/preprocess/Bile_Duct_Cancer/clinical_data/GSE131027.csv +2 -0
- p1/preprocess/Bile_Duct_Cancer/clinical_data/TCGA.csv +46 -0
- p1/preprocess/Bile_Duct_Cancer/code/GSE107754.py +169 -0
- p1/preprocess/Bile_Duct_Cancer/code/GSE131027.py +162 -0
- p1/preprocess/Bile_Duct_Cancer/code/TCGA.py +119 -0
- p1/preprocess/Bile_Duct_Cancer/cohort_info.json +1 -0
- p1/preprocess/Bile_Duct_Cancer/gene_data/GSE107754.csv +3 -0
- p1/preprocess/Bile_Duct_Cancer/gene_data/GSE131027.csv +3 -0
- p1/preprocess/Bile_Duct_Cancer/gene_data/TCGA.csv +3 -0
- p1/preprocess/Bipolar_disorder/GSE120340.csv +0 -0
- p1/preprocess/Bipolar_disorder/GSE120342.csv +0 -0
- p1/preprocess/Bipolar_disorder/GSE46416.csv +0 -0
- p1/preprocess/Bipolar_disorder/GSE46449.csv +3 -0
- p1/preprocess/Bipolar_disorder/GSE92538.csv +3 -0
- p1/preprocess/Bipolar_disorder/clinical_data/GSE120340.csv +2 -0
- p1/preprocess/Bipolar_disorder/clinical_data/GSE120342.csv +2 -0
- p1/preprocess/Bipolar_disorder/clinical_data/GSE46416.csv +2 -0
- p1/preprocess/Bipolar_disorder/clinical_data/GSE46449.csv +3 -0
.gitattributes
CHANGED
@@ -952,3 +952,33 @@ p1/preprocess/Alzheimers_Disease/gene_data/GSE122063.csv filter=lfs diff=lfs mer
|
|
952 |
p1/preprocess/Alzheimers_Disease/gene_data/GSE132903.csv filter=lfs diff=lfs merge=lfs -text
|
953 |
p1/preprocess/Alzheimers_Disease/GSE132903.csv filter=lfs diff=lfs merge=lfs -text
|
954 |
p1/preprocess/Von_Willebrand_Disease/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
952 |
p1/preprocess/Alzheimers_Disease/gene_data/GSE132903.csv filter=lfs diff=lfs merge=lfs -text
|
953 |
p1/preprocess/Alzheimers_Disease/GSE132903.csv filter=lfs diff=lfs merge=lfs -text
|
954 |
p1/preprocess/Von_Willebrand_Disease/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
|
955 |
+
p1/preprocess/Atrial_Fibrillation/GSE115574.csv filter=lfs diff=lfs merge=lfs -text
|
956 |
+
p1/preprocess/Atrial_Fibrillation/gene_data/GSE115574.csv filter=lfs diff=lfs merge=lfs -text
|
957 |
+
p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE87847.csv filter=lfs diff=lfs merge=lfs -text
|
958 |
+
p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE65106.csv filter=lfs diff=lfs merge=lfs -text
|
959 |
+
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE285666.csv filter=lfs diff=lfs merge=lfs -text
|
960 |
+
p1/preprocess/Atrial_Fibrillation/GSE235307.csv filter=lfs diff=lfs merge=lfs -text
|
961 |
+
p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE89594.csv filter=lfs diff=lfs merge=lfs -text
|
962 |
+
p1/preprocess/Von_Willebrand_Disease/TCGA.csv filter=lfs diff=lfs merge=lfs -text
|
963 |
+
p1/preprocess/Atrial_Fibrillation/gene_data/GSE235307.csv filter=lfs diff=lfs merge=lfs -text
|
964 |
+
p1/preprocess/Autoinflammatory_Disorders/gene_data/GSE43553.csv filter=lfs diff=lfs merge=lfs -text
|
965 |
+
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE87847.csv filter=lfs diff=lfs merge=lfs -text
|
966 |
+
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE65106.csv filter=lfs diff=lfs merge=lfs -text
|
967 |
+
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE57802.csv filter=lfs diff=lfs merge=lfs -text
|
968 |
+
p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE111175.csv filter=lfs diff=lfs merge=lfs -text
|
969 |
+
p1/preprocess/Bile_Duct_Cancer/TCGA.csv filter=lfs diff=lfs merge=lfs -text
|
970 |
+
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE89594.csv filter=lfs diff=lfs merge=lfs -text
|
971 |
+
p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE42133.csv filter=lfs diff=lfs merge=lfs -text
|
972 |
+
p1/preprocess/Bile_Duct_Cancer/GSE131027.csv filter=lfs diff=lfs merge=lfs -text
|
973 |
+
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE111175.csv filter=lfs diff=lfs merge=lfs -text
|
974 |
+
p1/preprocess/Bile_Duct_Cancer/gene_data/GSE107754.csv filter=lfs diff=lfs merge=lfs -text
|
975 |
+
p1/preprocess/Bile_Duct_Cancer/gene_data/TCGA.csv filter=lfs diff=lfs merge=lfs -text
|
976 |
+
p1/preprocess/Bile_Duct_Cancer/gene_data/GSE131027.csv filter=lfs diff=lfs merge=lfs -text
|
977 |
+
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE42133.csv filter=lfs diff=lfs merge=lfs -text
|
978 |
+
p1/preprocess/Autoinflammatory_Disorders/GSE80060.csv filter=lfs diff=lfs merge=lfs -text
|
979 |
+
p1/preprocess/Bipolar_disorder/GSE46449.csv filter=lfs diff=lfs merge=lfs -text
|
980 |
+
p1/preprocess/Bipolar_disorder/gene_data/GSE62191.csv filter=lfs diff=lfs merge=lfs -text
|
981 |
+
p1/preprocess/Autoinflammatory_Disorders/gene_data/GSE80060.csv filter=lfs diff=lfs merge=lfs -text
|
982 |
+
p1/preprocess/Bipolar_disorder/gene_data/GSE45484.csv filter=lfs diff=lfs merge=lfs -text
|
983 |
+
p1/preprocess/Bipolar_disorder/GSE92538.csv filter=lfs diff=lfs merge=lfs -text
|
984 |
+
p1/preprocess/Bipolar_disorder/gene_data/GSE46449.csv filter=lfs diff=lfs merge=lfs -text
|
p1/preprocess/Atrial_Fibrillation/GSE115574.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3daad640890cf0559e32fcc84a3fdb4e324a6b9efbbe24d355b043bc9baf340a
|
3 |
+
size 15534640
|
p1/preprocess/Atrial_Fibrillation/GSE235307.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ad0f7bf3d07aff5ac673d3e1721eaa5233fa6f9fbf4912b231aedc6f1593c391
|
3 |
+
size 30127846
|
p1/preprocess/Atrial_Fibrillation/gene_data/GSE115574.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:456a00d22351d374c6e573fb5f8cd9aee06d8e578a5597254ec39e90ed25195d
|
3 |
+
size 15534388
|
p1/preprocess/Atrial_Fibrillation/gene_data/GSE235307.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9d40bfec5aee125dd279e5a4a5b658d3b8c0ce73e2f05846a13e621756e1927e
|
3 |
+
size 30126272
|
p1/preprocess/Atrial_Fibrillation/gene_data/GSE41177.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE111175.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b252d02a516acff5b0c923fb1de59bb71f180797456340473a8b986e2b11f2ec
|
3 |
+
size 36331282
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE42133.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0a08501bec3a2536e27659ce4e83df4d328c7e8649d8b1ae961d7329f9fe16e2
|
3 |
+
size 37924345
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE65106.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:39fd1cdbb61bc441fe1a0b41b3060ef3bf221b7392842634e6164cb9a0aab0f9
|
3 |
+
size 19282521
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE87847.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b313364d732229373da3f5569dfebca20ab5c6a325190a9d69751b1a118948f8
|
3 |
+
size 16974075
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/GSE89594.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2f1b79a3b2737c066109d8f618ade6f457e6d5ec6145fc7f1605a0b5d029e6ef
|
3 |
+
size 23812563
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/code/GSE42133.py
ADDED
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Autism_spectrum_disorder_(ASD)"
|
6 |
+
cohort = "GSE42133"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Autism_spectrum_disorder_(ASD)/GSE42133"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Autism_spectrum_disorder_(ASD)/GSE42133.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Autism_spectrum_disorder_(ASD)/gene_data/GSE42133.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Autism_spectrum_disorder_(ASD)/clinical_data/GSE42133.csv"
|
16 |
+
json_path = "./output/preprocess/1/Autism_spectrum_disorder_(ASD)/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Gene Expression Data Availability
|
37 |
+
is_gene_available = True # Based on the background info describing leukocyte gene expression
|
38 |
+
|
39 |
+
# 2. Variable Availability
|
40 |
+
# From the sample characteristics dictionary:
|
41 |
+
# 0 -> ['dx (diagnosis): ASD', 'dx (diagnosis): Control']
|
42 |
+
# 1 -> ['gender: male']
|
43 |
+
# 2 -> ['cell type: leukocyte']
|
44 |
+
|
45 |
+
# Trait information is in key=0 with two unique values (ASD vs Control), so it's available.
|
46 |
+
trait_row = 0
|
47 |
+
|
48 |
+
# There is no mention of an age variable, so it's unavailable.
|
49 |
+
age_row = None
|
50 |
+
|
51 |
+
# Gender has only one unique value "male", so it is a constant feature and thus considered not available.
|
52 |
+
gender_row = None
|
53 |
+
|
54 |
+
# 2.2 Data Type Conversion Functions
|
55 |
+
def convert_trait(value: str):
|
56 |
+
"""
|
57 |
+
Convert the trait (diagnosis) to binary.
|
58 |
+
ASD -> 1
|
59 |
+
Control -> 0
|
60 |
+
Else -> None
|
61 |
+
"""
|
62 |
+
# Extract substring after the colon
|
63 |
+
parts = value.split(':', 1)
|
64 |
+
val = parts[-1].strip().lower()
|
65 |
+
if val == 'asd':
|
66 |
+
return 1
|
67 |
+
elif val == 'control':
|
68 |
+
return 0
|
69 |
+
else:
|
70 |
+
return None
|
71 |
+
|
72 |
+
def convert_age(value: str):
|
73 |
+
"""
|
74 |
+
Age data is not available, so return None.
|
75 |
+
"""
|
76 |
+
return None
|
77 |
+
|
78 |
+
def convert_gender(value: str):
|
79 |
+
"""
|
80 |
+
Convert gender to binary.
|
81 |
+
female -> 0
|
82 |
+
male -> 1
|
83 |
+
Else -> None
|
84 |
+
(Not used here because gender is unavailable.)
|
85 |
+
"""
|
86 |
+
parts = value.split(':', 1)
|
87 |
+
val = parts[-1].strip().lower()
|
88 |
+
if val == 'female':
|
89 |
+
return 0
|
90 |
+
elif val == 'male':
|
91 |
+
return 1
|
92 |
+
else:
|
93 |
+
return None
|
94 |
+
|
95 |
+
# 3. Initial Filtering and Save Metadata
|
96 |
+
is_trait_available = (trait_row is not None)
|
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. Clinical Feature Extraction if trait is available
|
106 |
+
if is_trait_available:
|
107 |
+
selected_clinical_df = geo_select_clinical_features(
|
108 |
+
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 |
+
|
118 |
+
# Observe the extracted clinical DataFrame
|
119 |
+
preview_result = preview_df(selected_clinical_df, n=5)
|
120 |
+
print("Preview of selected clinical features:", preview_result)
|
121 |
+
|
122 |
+
# Save the clinical features
|
123 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
124 |
+
# STEP3
|
125 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
126 |
+
gene_data = get_genetic_data(matrix_file)
|
127 |
+
|
128 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
129 |
+
print(gene_data.index[:20])
|
130 |
+
# These "ILMN_xxxxxxx" are Illumina probe IDs, not standard human gene symbols.
|
131 |
+
# Hence, they require mapping to gene symbols.
|
132 |
+
|
133 |
+
requires_gene_mapping = True
|
134 |
+
# STEP5
|
135 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
136 |
+
gene_annotation = get_gene_annotation(soft_file)
|
137 |
+
|
138 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
139 |
+
print("Gene annotation preview:")
|
140 |
+
print(preview_df(gene_annotation))
|
141 |
+
# STEP: Gene Identifier Mapping
|
142 |
+
|
143 |
+
# 1. Identify the relevant columns in the annotation dataframe:
|
144 |
+
# - The gene expression dataset has identifiers like "ILMN_xxxxxx" in its index, which matches the "ID" column.
|
145 |
+
# - The gene symbol information appears to be in the "Symbol" column.
|
146 |
+
|
147 |
+
# 2. Extract the mapping between "ID" and "Symbol" from 'gene_annotation'.
|
148 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col="ID", gene_col="Symbol")
|
149 |
+
|
150 |
+
# 3. Apply the mapping to convert probe-level data to gene-level data.
|
151 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
152 |
+
|
153 |
+
# (Optional) A quick check to see the dimension and a preview of the newly mapped gene_data.
|
154 |
+
print("Gene data shape after mapping:", gene_data.shape)
|
155 |
+
print("Gene data head after mapping:")
|
156 |
+
print(gene_data.head())
|
157 |
+
# STEP7
|
158 |
+
|
159 |
+
# 1. Normalize the obtained gene data using the NCBI Gene synonym database
|
160 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
161 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
162 |
+
|
163 |
+
# 2. Link the clinical and genetic data
|
164 |
+
# Replace the undefined 'clinical_features' with the 'selected_clinical_df' from previous steps
|
165 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
166 |
+
|
167 |
+
# 3. Handle missing values systematically
|
168 |
+
linked_data_processed = handle_missing_values(linked_data, trait_col=trait)
|
169 |
+
|
170 |
+
# 4. Check for biased trait and remove any biased demographic features
|
171 |
+
trait_biased, linked_data_final = judge_and_remove_biased_features(linked_data_processed, trait)
|
172 |
+
|
173 |
+
# 5. Final quality validation and metadata saving
|
174 |
+
is_usable = validate_and_save_cohort_info(
|
175 |
+
is_final=True,
|
176 |
+
cohort=cohort,
|
177 |
+
info_path=json_path,
|
178 |
+
is_gene_available=True,
|
179 |
+
is_trait_available=True,
|
180 |
+
is_biased=trait_biased,
|
181 |
+
df=linked_data_final,
|
182 |
+
note="Dataset processed with GEO pipeline. Checked for missing values and bias."
|
183 |
+
)
|
184 |
+
|
185 |
+
# 6. If dataset is usable, save the final linked data
|
186 |
+
if is_usable:
|
187 |
+
linked_data_final.to_csv(out_data_file)
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE111175.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6d4fd747838f3aea1a8b881de3a4d7798477ea2093688ee30f40ff841c95bcb5
|
3 |
+
size 36329712
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE123302.csv
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ID,GSM3499537,GSM3499538,GSM3499539,GSM3499540,GSM3499541,GSM3499542,GSM3499543,GSM3499544,GSM3499545,GSM3499546,GSM3499547,GSM3499548,GSM3499549,GSM3499550,GSM3499551,GSM3499552,GSM3499553,GSM3499554,GSM3499555,GSM3499556,GSM3499557,GSM3499558,GSM3499559,GSM3499560,GSM3499561,GSM3499562,GSM3499563,GSM3499564,GSM3499565,GSM3499566,GSM3499567,GSM3499568,GSM3499569,GSM3499570,GSM3499571,GSM3499572,GSM3499573,GSM3499574,GSM3499575,GSM3499576,GSM3499577,GSM3499578,GSM3499579,GSM3499580,GSM3499581,GSM3499582,GSM3499583,GSM3499584,GSM3499585,GSM3499586,GSM3499587,GSM3499588,GSM3499589,GSM3499590,GSM3499591,GSM3499592,GSM3499593,GSM3499594,GSM3499595,GSM3499596,GSM3499597,GSM3499598,GSM3499599,GSM3499600,GSM3499601,GSM3499602,GSM3499603,GSM3499604,GSM3499605,GSM3499606,GSM3499607,GSM3499608,GSM3499609,GSM3499610,GSM3499611,GSM3499612,GSM3499613,GSM3499614,GSM3499615,GSM3499616,GSM3499617,GSM3499618,GSM3499619,GSM3499620,GSM3499621,GSM3499622,GSM3499623,GSM3499624,GSM3499625,GSM3499626,GSM3499627,GSM3499628,GSM3499629,GSM3499630,GSM3499631,GSM3499632,GSM3499633,GSM3499634,GSM3499635,GSM3499636,GSM3499637,GSM3499638,GSM3499639,GSM3499640,GSM3499641,GSM3499642,GSM3499643,GSM3499644,GSM3499645,GSM3499646,GSM3499647,GSM3499648,GSM3499649,GSM3499650,GSM3499651,GSM3499652,GSM3499653,GSM3499654,GSM3499655,GSM3499656,GSM3499657,GSM3499658,GSM3499659,GSM3499660,GSM3499661,GSM3499662,GSM3499663,GSM3499664,GSM3499665,GSM3499666,GSM3499667,GSM3499668,GSM3499669,GSM3499670,GSM3499671,GSM3499672,GSM3499673,GSM3499674,GSM3499675,GSM3499676,GSM3499677,GSM3499678,GSM3499679,GSM3499680,GSM3499681,GSM3499682,GSM3499683,GSM3499684,GSM3499685,GSM3499686,GSM3499687,GSM3499688,GSM3499689,GSM3499690,GSM3499691,GSM3499692,GSM3499693,GSM3499694,GSM3499695,GSM3499696,GSM3499697,GSM3499698,GSM3499699,GSM3499700,GSM3499701,GSM3499702,GSM3499703,GSM3499704,GSM3499705,GSM3499706,GSM3499707,GSM3499708,GSM3499709,GSM3499710,GSM3499711,GSM3499712,GSM3499713,GSM3499714,GSM3499715,GSM3499716,GSM3499717,GSM3499718,GSM3499719,GSM3499720,GSM3499721,GSM3499722,GSM3499723,GSM3499724,GSM3499725,GSM3499726,GSM3499727,GSM3499728,GSM3499729,GSM3499730,GSM3499731,GSM3499732,GSM3499733,GSM3499734,GSM3499735,GSM3499736,GSM3499737,GSM3499738,GSM3499739,GSM3499740,GSM3499741,GSM3499742,GSM3499743,GSM3499744,GSM3499745,GSM3499746,GSM3499747,GSM3499748,GSM3499749,GSM3499750,GSM3499751,GSM3499752,GSM3499753,GSM3499754,GSM3499755,GSM3499756,GSM3499757,GSM3499758,GSM3499759,GSM3499760
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE285666.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e1fec8c851bc39edce7b7408d61853a2a6d2a6e46991b19a804616d9896b9a17
|
3 |
+
size 12878916
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE42133.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:da49f29f71be670f8ac15b81887e3365e01d9175d7722033154f03884683d90d
|
3 |
+
size 37923730
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE57802.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:67464965939f3be0671ede96503c02e46f652f5fcdd1a69a40a1ddc90851cd36
|
3 |
+
size 16352073
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE65106.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ba36a56836f25c628cc7f6721d0b891f0a8f089e9041023fa41adfb38bdd2025
|
3 |
+
size 19281941
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE87847.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7a6faf5ecfc7862999021b37b56766fd4e3dd69c77702d1bfb9a9e2dee51d4fb
|
3 |
+
size 16973297
|
p1/preprocess/Autism_spectrum_disorder_(ASD)/gene_data/GSE89594.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d76a3967959d50c84ec6d36a0c8c56926580b854240c2e6d194762f3630a0a5c
|
3 |
+
size 23811303
|
p1/preprocess/Autoinflammatory_Disorders/GSE80060.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8d4d57d05931fc6f3b2f70aeabb30ec868a7316087a64d4188a5d9452d97fc40
|
3 |
+
size 45737271
|
p1/preprocess/Autoinflammatory_Disorders/clinical_data/GSE43553.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
GSM1065191,GSM1065192,GSM1065193,GSM1065194,GSM1065195,GSM1065196,GSM1065197,GSM1065198,GSM1065199,GSM1065200,GSM1065201,GSM1065202,GSM1065203,GSM1065204,GSM1065205,GSM1065206,GSM1065207,GSM1065208,GSM1065209,GSM1065210,GSM1065211,GSM1065212,GSM1065213,GSM1065214,GSM1065215,GSM1065216,GSM1065217,GSM1065218,GSM1065219,GSM1065220,GSM1065221,GSM1065222,GSM1065223,GSM1065224,GSM1065225,GSM1065226,GSM1065227,GSM1065228,GSM1065229,GSM1065230,GSM1065231,GSM1065232,GSM1065233,GSM1065234,GSM1065235,GSM1065236,GSM1065237,GSM1065238,GSM1065239,GSM1065240,GSM1065241,GSM1065242,GSM1065243,GSM1065244,GSM1065245,GSM1065246,GSM1065247,GSM1065248,GSM1065249,GSM1065250,GSM1065251,GSM1065252,GSM1065253,GSM1065254,GSM1065255,GSM1065256,GSM1065257,GSM1065258,GSM1065259,GSM1065260,GSM1065261,GSM1065262,GSM1065263,GSM1065264,GSM1065265,GSM1065266,GSM1065267,GSM1065268,GSM1065269,GSM1065270,GSM1065271,GSM1065272,GSM1065273,GSM1065274,GSM1065275,GSM1065276,GSM1065277,GSM1065278,GSM1065279,GSM1065280,GSM1065281,GSM1065282,GSM1065283,GSM1065284,GSM1065285,GSM1065286,GSM1065287,GSM1065288,GSM1065289,GSM1065290
|
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,1.0,1.0,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/Autoinflammatory_Disorders/clinical_data/GSE80060.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
GSM2111993,GSM2111994,GSM2111995,GSM2111996,GSM2111997,GSM2111998,GSM2111999,GSM2112000,GSM2112001,GSM2112002,GSM2112003,GSM2112004,GSM2112005,GSM2112006,GSM2112007,GSM2112008,GSM2112009,GSM2112010,GSM2112011,GSM2112012,GSM2112013,GSM2112014,GSM2112015,GSM2112016,GSM2112017,GSM2112018,GSM2112019,GSM2112020,GSM2112021,GSM2112022,GSM2112023,GSM2112024,GSM2112025,GSM2112026,GSM2112027,GSM2112028,GSM2112029,GSM2112030,GSM2112031,GSM2112032,GSM2112033,GSM2112034,GSM2112035,GSM2112036,GSM2112037,GSM2112038,GSM2112039,GSM2112040,GSM2112041,GSM2112042,GSM2112043,GSM2112044,GSM2112045,GSM2112046,GSM2112047,GSM2112048,GSM2112049,GSM2112050,GSM2112051,GSM2112052,GSM2112053,GSM2112054,GSM2112055,GSM2112056,GSM2112057,GSM2112058,GSM2112059,GSM2112060,GSM2112061,GSM2112062,GSM2112063,GSM2112064,GSM2112065,GSM2112066,GSM2112067,GSM2112068,GSM2112069,GSM2112070,GSM2112071,GSM2112072,GSM2112073,GSM2112074,GSM2112075,GSM2112076,GSM2112077,GSM2112078,GSM2112079,GSM2112080,GSM2112081,GSM2112082,GSM2112083,GSM2112084,GSM2112085,GSM2112086,GSM2112087,GSM2112088,GSM2112089,GSM2112090,GSM2112091,GSM2112092,GSM2112093,GSM2112094,GSM2112095,GSM2112096,GSM2112097,GSM2112098,GSM2112099,GSM2112100,GSM2112101,GSM2112102,GSM2112103,GSM2112104,GSM2112105,GSM2112106,GSM2112107,GSM2112108,GSM2112109,GSM2112110,GSM2112111,GSM2112112,GSM2112113,GSM2112114,GSM2112115,GSM2112116,GSM2112117,GSM2112118,GSM2112119,GSM2112120,GSM2112121,GSM2112122,GSM2112123,GSM2112124,GSM2112125,GSM2112126,GSM2112127,GSM2112128,GSM2112129,GSM2112130,GSM2112131,GSM2112132,GSM2112133,GSM2112134,GSM2112135,GSM2112136,GSM2112137,GSM2112138,GSM2112139,GSM2112140,GSM2112141,GSM2112142,GSM2112143,GSM2112144,GSM2112145,GSM2112146,GSM2112147,GSM2112148,GSM2112149,GSM2112150,GSM2112151,GSM2112152,GSM2112153,GSM2112154,GSM2112155,GSM2112156,GSM2112157,GSM2112158,GSM2112159,GSM2112160,GSM2112161,GSM2112162,GSM2112163,GSM2112164,GSM2112165,GSM2112166,GSM2112167,GSM2112168,GSM2112169,GSM2112170,GSM2112171,GSM2112172,GSM2112173,GSM2112174,GSM2112175,GSM2112176,GSM2112177,GSM2112178,GSM2112179,GSM2112180,GSM2112181,GSM2112182,GSM2112183,GSM2112184,GSM2112185,GSM2112186,GSM2112187,GSM2112188,GSM2112189,GSM2112190,GSM2112191,GSM2112192,GSM2112193,GSM2112194,GSM2112195,GSM2112196,GSM2112197,GSM2112198
|
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,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0
|
p1/preprocess/Autoinflammatory_Disorders/code/GSE43553.py
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Autoinflammatory_Disorders"
|
6 |
+
cohort = "GSE43553"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Autoinflammatory_Disorders"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Autoinflammatory_Disorders/GSE43553"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Autoinflammatory_Disorders/GSE43553.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Autoinflammatory_Disorders/gene_data/GSE43553.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Autoinflammatory_Disorders/clinical_data/GSE43553.csv"
|
16 |
+
json_path = "./output/preprocess/1/Autoinflammatory_Disorders/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
import pandas as pd
|
37 |
+
import numpy as np
|
38 |
+
|
39 |
+
# 1. Gene Expression Data Availability
|
40 |
+
is_gene_available = True # Based on microarray-based gene expression profiling in the background info
|
41 |
+
|
42 |
+
# 2. Variable Availability and Data Type Conversion
|
43 |
+
# Examining the sample characteristics dictionary, we see "disease state: CAPS" and
|
44 |
+
# "disease state: other autoinflammatory disease" in key=3, which vary across samples
|
45 |
+
# (not a constant feature). Hence, we'll use key=3 for our trait.
|
46 |
+
trait_row = 3
|
47 |
+
age_row = None # No age information found
|
48 |
+
gender_row = None # No gender information found
|
49 |
+
|
50 |
+
# Define the conversion functions
|
51 |
+
def convert_trait(value: str) -> int:
|
52 |
+
if not isinstance(value, str) or pd.isna(value):
|
53 |
+
return None
|
54 |
+
parts = value.split(':', 1)
|
55 |
+
if len(parts) < 2:
|
56 |
+
return None
|
57 |
+
val = parts[1].strip().lower()
|
58 |
+
if 'caps' in val or 'other autoinflammatory disease' in val:
|
59 |
+
return 1
|
60 |
+
# Otherwise, assume 0 (e.g., healthy or not the target condition)
|
61 |
+
return 0
|
62 |
+
|
63 |
+
convert_age = None
|
64 |
+
convert_gender = None
|
65 |
+
|
66 |
+
# 3. Save Metadata (initial filtering)
|
67 |
+
is_trait_available = (trait_row is not None)
|
68 |
+
validate_and_save_cohort_info(
|
69 |
+
is_final=False,
|
70 |
+
cohort=cohort,
|
71 |
+
info_path=json_path,
|
72 |
+
is_gene_available=is_gene_available,
|
73 |
+
is_trait_available=is_trait_available
|
74 |
+
)
|
75 |
+
|
76 |
+
# 4. Clinical Feature Extraction
|
77 |
+
# Proceed only if trait_row is not None.
|
78 |
+
if is_trait_available:
|
79 |
+
selected_clinical_df = geo_select_clinical_features(
|
80 |
+
clinical_data,
|
81 |
+
trait=trait,
|
82 |
+
trait_row=trait_row,
|
83 |
+
convert_trait=convert_trait,
|
84 |
+
age_row=age_row,
|
85 |
+
convert_age=convert_age,
|
86 |
+
gender_row=gender_row,
|
87 |
+
convert_gender=convert_gender
|
88 |
+
)
|
89 |
+
# Preview the resulting DataFrame
|
90 |
+
print(preview_df(selected_clinical_df, n=5))
|
91 |
+
# Save to CSV
|
92 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
93 |
+
# STEP3
|
94 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
95 |
+
gene_data = get_genetic_data(matrix_file)
|
96 |
+
|
97 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
98 |
+
print(gene_data.index[:20])
|
99 |
+
print("requires_gene_mapping = True")
|
100 |
+
# STEP5
|
101 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
102 |
+
gene_annotation = get_gene_annotation(soft_file)
|
103 |
+
|
104 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
105 |
+
print("Gene annotation preview:")
|
106 |
+
print(preview_df(gene_annotation))
|
107 |
+
# STEP: Gene Identifier Mapping
|
108 |
+
# 1. Identify the columns in the gene annotation that match the probe IDs in the gene expression data ("ID")
|
109 |
+
# and the column that stores the gene symbols ("Gene Symbol").
|
110 |
+
prob_col = 'ID'
|
111 |
+
gene_col = 'Gene Symbol'
|
112 |
+
|
113 |
+
# 2. Extract a gene mapping dataframe with the probe column and the gene symbol column.
|
114 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col=prob_col, gene_col=gene_col)
|
115 |
+
|
116 |
+
# 3. Convert probe-level measurements to gene expression data by applying the gene mapping.
|
117 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
118 |
+
|
119 |
+
# (Optional) Preview a few rows of the mapped gene expression data
|
120 |
+
print("Preview of gene_data after mapping:")
|
121 |
+
print(gene_data.head(5))
|
122 |
+
# STEP7
|
123 |
+
|
124 |
+
# 1. Normalize the obtained gene data using the NCBI Gene synonym database
|
125 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
126 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
127 |
+
|
128 |
+
# 2. Link the clinical and genetic data
|
129 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
130 |
+
|
131 |
+
# 3. Handle missing values systematically using the actual trait name
|
132 |
+
linked_data_processed = handle_missing_values(linked_data, trait_col=trait)
|
133 |
+
|
134 |
+
# 4. Check for biased trait and remove any biased demographic features
|
135 |
+
trait_biased, linked_data_final = judge_and_remove_biased_features(linked_data_processed, trait)
|
136 |
+
|
137 |
+
# 5. Final quality validation and metadata saving
|
138 |
+
is_usable = validate_and_save_cohort_info(
|
139 |
+
is_final=True,
|
140 |
+
cohort=cohort,
|
141 |
+
info_path=json_path,
|
142 |
+
is_gene_available=True,
|
143 |
+
is_trait_available=True,
|
144 |
+
is_biased=trait_biased,
|
145 |
+
df=linked_data_final,
|
146 |
+
note="Dataset processed with GEO pipeline. Checked for missing values and bias."
|
147 |
+
)
|
148 |
+
|
149 |
+
# 6. If dataset is usable, save the final linked data
|
150 |
+
if is_usable:
|
151 |
+
linked_data_final.to_csv(out_data_file)
|
p1/preprocess/Autoinflammatory_Disorders/code/GSE80060.py
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Autoinflammatory_Disorders"
|
6 |
+
cohort = "GSE80060"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Autoinflammatory_Disorders"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Autoinflammatory_Disorders/GSE80060"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Autoinflammatory_Disorders/GSE80060.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Autoinflammatory_Disorders/gene_data/GSE80060.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Autoinflammatory_Disorders/clinical_data/GSE80060.csv"
|
16 |
+
json_path = "./output/preprocess/1/Autoinflammatory_Disorders/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# Step 1: Determine whether this dataset likely contains gene expression data
|
37 |
+
is_gene_available = True # Based on the title "Gene expression data of whole blood..."
|
38 |
+
|
39 |
+
# Step 2.1: Identify data availability for trait, age, and gender
|
40 |
+
trait_row = 1 # "disease status: SJIA" vs "disease status: Healthy"
|
41 |
+
age_row = None # No age info found
|
42 |
+
gender_row = None # No gender info found
|
43 |
+
|
44 |
+
# Step 2.2: Define data type conversions
|
45 |
+
def convert_trait(value: str):
|
46 |
+
# Extract the substring after the colon
|
47 |
+
parts = value.split(':')
|
48 |
+
if len(parts) < 2:
|
49 |
+
return None
|
50 |
+
val = parts[1].strip().lower()
|
51 |
+
# Map SJIA -> 1, Healthy -> 0
|
52 |
+
if val == 'sjia':
|
53 |
+
return 1
|
54 |
+
elif val == 'healthy':
|
55 |
+
return 0
|
56 |
+
else:
|
57 |
+
return None
|
58 |
+
|
59 |
+
def convert_age(value: str):
|
60 |
+
# No age data; return None
|
61 |
+
return None
|
62 |
+
|
63 |
+
def convert_gender(value: str):
|
64 |
+
# No gender data; return None
|
65 |
+
return None
|
66 |
+
|
67 |
+
# Step 3: Conduct initial filtering and save metadata
|
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 |
+
# Step 4: Clinical feature extraction if trait_row is not None
|
78 |
+
if trait_row is not None:
|
79 |
+
selected_clinical_df = geo_select_clinical_features(
|
80 |
+
clinical_data,
|
81 |
+
trait='Disease Status',
|
82 |
+
trait_row=trait_row,
|
83 |
+
convert_trait=convert_trait,
|
84 |
+
age_row=age_row,
|
85 |
+
convert_age=convert_age,
|
86 |
+
gender_row=gender_row,
|
87 |
+
convert_gender=convert_gender
|
88 |
+
)
|
89 |
+
# Preview the selected clinical data
|
90 |
+
preview = preview_df(selected_clinical_df)
|
91 |
+
print("Selected Clinical Data Preview:", preview)
|
92 |
+
|
93 |
+
# Save extracted clinical features
|
94 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
95 |
+
# STEP3
|
96 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
97 |
+
gene_data = get_genetic_data(matrix_file)
|
98 |
+
|
99 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
100 |
+
print(gene_data.index[:20])
|
101 |
+
# These identifiers appear to be Affymetrix probe IDs rather than standard human gene symbols.
|
102 |
+
# Therefore, they require mapping to gene symbols.
|
103 |
+
|
104 |
+
print("requires_gene_mapping = True")
|
105 |
+
# STEP5
|
106 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
107 |
+
gene_annotation = get_gene_annotation(soft_file)
|
108 |
+
|
109 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
110 |
+
print("Gene annotation preview:")
|
111 |
+
print(preview_df(gene_annotation))
|
112 |
+
# STEP: Gene Identifier Mapping
|
113 |
+
|
114 |
+
# 1. Identify the columns in gene_annotation that correspond to the probe IDs and the gene symbols.
|
115 |
+
# From the preview, the "ID" column matches the probe identifiers in the gene_data index,
|
116 |
+
# and the "Gene Symbol" column contains the gene symbols.
|
117 |
+
probe_col = "ID"
|
118 |
+
gene_symbol_col = "Gene Symbol"
|
119 |
+
|
120 |
+
# 2. Get a gene mapping dataframe from the annotation.
|
121 |
+
mapping_df = get_gene_mapping(gene_annotation, probe_col, gene_symbol_col)
|
122 |
+
|
123 |
+
# 3. Convert probe-level data to gene-level data using the mapping, dividing probe expression among multiple genes.
|
124 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
125 |
+
|
126 |
+
# For verification, print a small preview of the resulting gene expression dataframe.
|
127 |
+
print("Preview of Gene Expression Data (first few genes):")
|
128 |
+
print(preview_df(gene_data, n=5))
|
129 |
+
# STEP7
|
130 |
+
|
131 |
+
# 1. Normalize the obtained gene data using the NCBI Gene synonym database
|
132 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
133 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
134 |
+
|
135 |
+
# 2. Link the clinical and genetic data
|
136 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
137 |
+
|
138 |
+
# 3. Handle missing values systematically (note the trait column name matches the clinical data's "Disease Status")
|
139 |
+
linked_data_processed = handle_missing_values(linked_data, trait_col="Disease Status")
|
140 |
+
|
141 |
+
# 4. Check for biased trait and remove any biased demographic features
|
142 |
+
trait_biased, linked_data_final = judge_and_remove_biased_features(linked_data_processed, "Disease Status")
|
143 |
+
|
144 |
+
# 5. Final quality validation and metadata saving
|
145 |
+
is_usable = validate_and_save_cohort_info(
|
146 |
+
is_final=True,
|
147 |
+
cohort=cohort,
|
148 |
+
info_path=json_path,
|
149 |
+
is_gene_available=True,
|
150 |
+
is_trait_available=True,
|
151 |
+
is_biased=trait_biased,
|
152 |
+
df=linked_data_final,
|
153 |
+
note="Dataset processed with GEO pipeline. Checked for missing values and bias."
|
154 |
+
)
|
155 |
+
|
156 |
+
# 6. If dataset is usable, save the final linked data
|
157 |
+
if is_usable:
|
158 |
+
linked_data_final.to_csv(out_data_file)
|
p1/preprocess/Autoinflammatory_Disorders/code/TCGA.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Autoinflammatory_Disorders"
|
6 |
+
|
7 |
+
# Input paths
|
8 |
+
tcga_root_dir = "../DATA/TCGA"
|
9 |
+
|
10 |
+
# Output paths
|
11 |
+
out_data_file = "./output/preprocess/1/Autoinflammatory_Disorders/TCGA.csv"
|
12 |
+
out_gene_data_file = "./output/preprocess/1/Autoinflammatory_Disorders/gene_data/TCGA.csv"
|
13 |
+
out_clinical_data_file = "./output/preprocess/1/Autoinflammatory_Disorders/clinical_data/TCGA.csv"
|
14 |
+
json_path = "./output/preprocess/1/Autoinflammatory_Disorders/cohort_info.json"
|
15 |
+
|
16 |
+
import os
|
17 |
+
import pandas as pd
|
18 |
+
|
19 |
+
# Step 1: Check directories in tcga_root_dir for anything relevant to "Autoinflammatory_Disorders"
|
20 |
+
search_terms = ["autoinflammatory", "inflam"]
|
21 |
+
dir_list = os.listdir(tcga_root_dir)
|
22 |
+
matching_dir = None
|
23 |
+
|
24 |
+
for d in dir_list:
|
25 |
+
d_lower = d.lower()
|
26 |
+
if any(term in d_lower for term in search_terms):
|
27 |
+
# Found a match, select this directory
|
28 |
+
matching_dir = d
|
29 |
+
break
|
30 |
+
|
31 |
+
if matching_dir is None:
|
32 |
+
# No matching directory found. Mark trait as skipped.
|
33 |
+
validate_and_save_cohort_info(
|
34 |
+
is_final=False,
|
35 |
+
cohort="TCGA",
|
36 |
+
info_path=json_path,
|
37 |
+
is_gene_available=False,
|
38 |
+
is_trait_available=False
|
39 |
+
)
|
40 |
+
else:
|
41 |
+
# 2. Identify the clinicalMatrix and PANCAN files
|
42 |
+
cohort_dir = os.path.join(tcga_root_dir, matching_dir)
|
43 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
44 |
+
|
45 |
+
# 3. Load both data files
|
46 |
+
clinical_df = pd.read_csv(clinical_file_path, index_col=0, sep='\t')
|
47 |
+
genetic_df = pd.read_csv(genetic_file_path, index_col=0, sep='\t')
|
48 |
+
|
49 |
+
# 4. Print the column names of the clinical data
|
50 |
+
print("Clinical Data Columns:")
|
51 |
+
print(clinical_df.columns.tolist())
|
p1/preprocess/Autoinflammatory_Disorders/cohort_info.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"GSE80060": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 206, "note": "Dataset processed with GEO pipeline. Checked for missing values and bias."}, "GSE43553": {"is_usable": false, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": true, "has_age": false, "has_gender": false, "sample_size": 66, "note": "Dataset processed with GEO pipeline. Checked for missing values and bias."}, "TCGA": {"is_usable": false, "is_gene_available": false, "is_trait_available": false, "is_available": false, "is_biased": null, "has_age": null, "has_gender": null, "sample_size": null, "note": null}}
|
p1/preprocess/Autoinflammatory_Disorders/gene_data/GSE43553.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2864f40de710ee8b203131c58b5f99674e4f96b78bd94f88620825ec5665bb6e
|
3 |
+
size 12702839
|
p1/preprocess/Autoinflammatory_Disorders/gene_data/GSE80060.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9df5145ab13c51ae5d9a8a8d0506870eae1854951a44c7867bb8915b5e661c9a
|
3 |
+
size 45736436
|
p1/preprocess/Bile_Duct_Cancer/GSE131027.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:736f3631855fdd8eae6daa1dfffa37d999c36cbfd1aac2fbd0fd6f178733399d
|
3 |
+
size 24380320
|
p1/preprocess/Bile_Duct_Cancer/TCGA.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e2103d04521950d3b88b9565b1ce1ee6344980e6bb6d02f0109d29900e7faa53
|
3 |
+
size 13656271
|
p1/preprocess/Bile_Duct_Cancer/clinical_data/GSE107754.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
GSM2878070,GSM2878071,GSM2878072,GSM2878073,GSM2878074,GSM2878075,GSM2878076,GSM2878077,GSM2878078,GSM2878079,GSM2878080,GSM2878081,GSM2878082,GSM2891194,GSM2891195,GSM2891196,GSM2891197,GSM2891198,GSM2891199,GSM2891200,GSM2891201,GSM2891202,GSM2891203,GSM2891204,GSM2891205,GSM2891206,GSM2891207,GSM2891208,GSM2891209,GSM2891210,GSM2891211,GSM2891212,GSM2891213,GSM2891214,GSM2891215,GSM2891216,GSM2891217,GSM2891218,GSM2891219,GSM2891220,GSM2891221,GSM2891222,GSM2891223,GSM2891224,GSM2891225,GSM2891226,GSM2891227,GSM2891228,GSM2891229,GSM2891230,GSM2891231,GSM2891232,GSM2891233,GSM2891234,GSM2891235,GSM2891236,GSM2891237,GSM2891238,GSM2891239,GSM2891240,GSM2891241,GSM2891242,GSM2891243,GSM2891244,GSM2891245,GSM2891246,GSM2891247,GSM2891248,GSM2891249,GSM2891250,GSM2891251,GSM2891252,GSM2891253,GSM2891254,GSM2891255,GSM2891256,GSM2891257,GSM2891258,GSM2891259,GSM2891260,GSM2891261,GSM2891262,GSM2891263,GSM2891264
|
2 |
+
0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0
|
3 |
+
1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,1.0
|
p1/preprocess/Bile_Duct_Cancer/clinical_data/GSE131027.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
GSM3759992,GSM3759993,GSM3759994,GSM3759995,GSM3759996,GSM3759997,GSM3759998,GSM3759999,GSM3760000,GSM3760001,GSM3760002,GSM3760003,GSM3760004,GSM3760005,GSM3760006,GSM3760007,GSM3760008,GSM3760009,GSM3760010,GSM3760011,GSM3760012,GSM3760013,GSM3760014,GSM3760015,GSM3760016,GSM3760017,GSM3760018,GSM3760019,GSM3760020,GSM3760021,GSM3760022,GSM3760023,GSM3760024,GSM3760025,GSM3760026,GSM3760027,GSM3760028,GSM3760029,GSM3760030,GSM3760031,GSM3760032,GSM3760033,GSM3760034,GSM3760035,GSM3760036,GSM3760037,GSM3760038,GSM3760039,GSM3760040,GSM3760041,GSM3760042,GSM3760043,GSM3760044,GSM3760045,GSM3760046,GSM3760047,GSM3760048,GSM3760049,GSM3760050,GSM3760051,GSM3760052,GSM3760053,GSM3760054,GSM3760055,GSM3760056,GSM3760057,GSM3760058,GSM3760059,GSM3760060,GSM3760061,GSM3760062,GSM3760063,GSM3760064,GSM3760065,GSM3760066,GSM3760067,GSM3760068,GSM3760069,GSM3760070,GSM3760071,GSM3760072,GSM3760073,GSM3760074,GSM3760075,GSM3760076,GSM3760077,GSM3760078,GSM3760079,GSM3760080,GSM3760081,GSM3760082,GSM3760083
|
2 |
+
0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0
|
p1/preprocess/Bile_Duct_Cancer/clinical_data/TCGA.csv
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
,Bile_Duct_Cancer,Age,Gender
|
2 |
+
TCGA-3X-AAV9-01,1,72,1
|
3 |
+
TCGA-3X-AAVA-01,1,50,0
|
4 |
+
TCGA-3X-AAVB-01,1,70,0
|
5 |
+
TCGA-3X-AAVC-01,1,72,0
|
6 |
+
TCGA-3X-AAVE-01,1,60,1
|
7 |
+
TCGA-4G-AAZO-01,1,71,0
|
8 |
+
TCGA-4G-AAZT-01,1,62,1
|
9 |
+
TCGA-W5-AA2G-01,1,62,0
|
10 |
+
TCGA-W5-AA2H-01,1,70,0
|
11 |
+
TCGA-W5-AA2I-01,1,66,1
|
12 |
+
TCGA-W5-AA2I-11,0,66,1
|
13 |
+
TCGA-W5-AA2O-01,1,57,1
|
14 |
+
TCGA-W5-AA2Q-01,1,68,1
|
15 |
+
TCGA-W5-AA2Q-11,0,68,1
|
16 |
+
TCGA-W5-AA2R-01,1,77,0
|
17 |
+
TCGA-W5-AA2R-11,0,77,0
|
18 |
+
TCGA-W5-AA2T-01,1,64,0
|
19 |
+
TCGA-W5-AA2U-01,1,78,0
|
20 |
+
TCGA-W5-AA2U-11,0,78,0
|
21 |
+
TCGA-W5-AA2W-01,1,31,0
|
22 |
+
TCGA-W5-AA2X-01,1,67,1
|
23 |
+
TCGA-W5-AA2X-11,0,67,1
|
24 |
+
TCGA-W5-AA2Z-01,1,29,0
|
25 |
+
TCGA-W5-AA30-01,1,82,1
|
26 |
+
TCGA-W5-AA30-11,0,82,1
|
27 |
+
TCGA-W5-AA31-01,1,71,1
|
28 |
+
TCGA-W5-AA31-11,0,71,1
|
29 |
+
TCGA-W5-AA33-01,1,60,1
|
30 |
+
TCGA-W5-AA34-01,1,75,0
|
31 |
+
TCGA-W5-AA34-11,0,75,0
|
32 |
+
TCGA-W5-AA36-01,1,51,0
|
33 |
+
TCGA-W5-AA38-01,1,55,0
|
34 |
+
TCGA-W5-AA39-01,1,81,1
|
35 |
+
TCGA-W6-AA0S-01,1,46,0
|
36 |
+
TCGA-WD-A7RX-01,1,71,0
|
37 |
+
TCGA-YR-A95A-01,1,52,1
|
38 |
+
TCGA-ZD-A8I3-01,1,73,0
|
39 |
+
TCGA-ZH-A8Y1-01,1,74,0
|
40 |
+
TCGA-ZH-A8Y2-01,1,59,0
|
41 |
+
TCGA-ZH-A8Y4-01,1,58,1
|
42 |
+
TCGA-ZH-A8Y5-01,1,69,1
|
43 |
+
TCGA-ZH-A8Y6-01,1,41,0
|
44 |
+
TCGA-ZH-A8Y8-01,1,73,1
|
45 |
+
TCGA-ZU-A8S4-01,1,52,1
|
46 |
+
TCGA-ZU-A8S4-11,0,52,1
|
p1/preprocess/Bile_Duct_Cancer/code/GSE107754.py
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Bile_Duct_Cancer"
|
6 |
+
cohort = "GSE107754"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Bile_Duct_Cancer"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Bile_Duct_Cancer/GSE107754"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Bile_Duct_Cancer/GSE107754.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Bile_Duct_Cancer/gene_data/GSE107754.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Bile_Duct_Cancer/clinical_data/GSE107754.csv"
|
16 |
+
json_path = "./output/preprocess/1/Bile_Duct_Cancer/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
import pandas as pd
|
37 |
+
|
38 |
+
# 1) Determine gene expression data availability
|
39 |
+
is_gene_available = True # The summary indicates "Whole human genome gene expression microarrays"
|
40 |
+
|
41 |
+
# 2) Variable Availability and Data Type Conversion
|
42 |
+
# After reviewing the sample characteristics:
|
43 |
+
# - trait_row (for Bile_Duct_Cancer) is 2, because "tissue: Bile duct cancer" appears among various tissues.
|
44 |
+
# - age_row is None, no age information found.
|
45 |
+
# - gender_row is 0, as "gender: Male" and "gender: Female" appear there.
|
46 |
+
|
47 |
+
trait_row = 2
|
48 |
+
age_row = None
|
49 |
+
gender_row = 0
|
50 |
+
|
51 |
+
# Conversion functions
|
52 |
+
def convert_trait(x: str):
|
53 |
+
parts = x.split(':', 1)
|
54 |
+
if len(parts) < 2:
|
55 |
+
return None
|
56 |
+
val = parts[1].strip().lower()
|
57 |
+
# Binary conversion: 1 if it's Bile duct cancer, 0 otherwise
|
58 |
+
return 1 if val == 'bile duct cancer' else 0
|
59 |
+
|
60 |
+
def convert_age(x: str):
|
61 |
+
# Age data not available, return None
|
62 |
+
return None
|
63 |
+
|
64 |
+
def convert_gender(x: str):
|
65 |
+
parts = x.split(':', 1)
|
66 |
+
if len(parts) < 2:
|
67 |
+
return None
|
68 |
+
val = parts[1].strip().lower()
|
69 |
+
if val == 'male':
|
70 |
+
return 1
|
71 |
+
elif val == 'female':
|
72 |
+
return 0
|
73 |
+
return None
|
74 |
+
|
75 |
+
# 3) Save Metadata (initial filtering)
|
76 |
+
# trait data is available (trait_row is not None) => is_trait_available = True
|
77 |
+
is_trait_available = (trait_row is not None)
|
78 |
+
|
79 |
+
is_usable = validate_and_save_cohort_info(
|
80 |
+
is_final=False,
|
81 |
+
cohort=cohort,
|
82 |
+
info_path=json_path,
|
83 |
+
is_gene_available=is_gene_available,
|
84 |
+
is_trait_available=is_trait_available
|
85 |
+
)
|
86 |
+
|
87 |
+
# 4) Clinical Feature Extraction (only do this step if trait_row is not None)
|
88 |
+
if trait_row is not None:
|
89 |
+
# Suppose the clinical_data dataframe is already loaded in the environment
|
90 |
+
clinical_features_df = geo_select_clinical_features(
|
91 |
+
clinical_df=clinical_data,
|
92 |
+
trait=trait,
|
93 |
+
trait_row=trait_row,
|
94 |
+
convert_trait=convert_trait,
|
95 |
+
age_row=age_row,
|
96 |
+
convert_age=convert_age,
|
97 |
+
gender_row=gender_row,
|
98 |
+
convert_gender=convert_gender
|
99 |
+
)
|
100 |
+
|
101 |
+
# Preview the extracted clinical features
|
102 |
+
preview_result = preview_df(clinical_features_df, n=5)
|
103 |
+
print("Clinical Features Preview:", preview_result)
|
104 |
+
|
105 |
+
# Save clinical data
|
106 |
+
clinical_features_df.to_csv(out_clinical_data_file, index=False)
|
107 |
+
# STEP3
|
108 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
109 |
+
gene_data = get_genetic_data(matrix_file)
|
110 |
+
|
111 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
112 |
+
print(gene_data.index[:20])
|
113 |
+
# Based on review, these identifiers (e.g., A_23_P100001) appear to be microarray probe set IDs,
|
114 |
+
# not standard human gene symbols, hence gene mapping is required.
|
115 |
+
print("\nrequires_gene_mapping = True")
|
116 |
+
# STEP5
|
117 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
118 |
+
gene_annotation = get_gene_annotation(soft_file)
|
119 |
+
|
120 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
121 |
+
print("Gene annotation preview:")
|
122 |
+
print(preview_df(gene_annotation))
|
123 |
+
# STEP: Gene Identifier Mapping
|
124 |
+
|
125 |
+
# 1) Identify the columns in the annotation dataframe that match the IDs in the gene expression data
|
126 |
+
# and which store the human gene symbols. In this case, "ID" matches "A_23_P..." probe IDs,
|
127 |
+
# and "GENE_SYMBOL" stores the actual gene symbols.
|
128 |
+
|
129 |
+
# 2) Extract the mapping between these columns into a separate dataframe
|
130 |
+
mapping_df = get_gene_mapping(gene_annotation, prob_col='ID', gene_col='GENE_SYMBOL')
|
131 |
+
|
132 |
+
# 3) Convert probe-level measurements to gene-level measurements
|
133 |
+
gene_data = apply_gene_mapping(gene_data, mapping_df)
|
134 |
+
|
135 |
+
# (Optional demonstration) Print shape or a small snippet to verify
|
136 |
+
print("Mapped gene_data shape:", gene_data.shape)
|
137 |
+
print("First few gene symbols in the mapped gene_data index:")
|
138 |
+
print(gene_data.index[:10].tolist())
|
139 |
+
# STEP7
|
140 |
+
|
141 |
+
# 1. Normalize the obtained gene data using the NCBI Gene synonym database
|
142 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
143 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
144 |
+
|
145 |
+
# 2. Link the clinical and genetic data
|
146 |
+
# Use the correct variable name from previous steps: "clinical_features_df"
|
147 |
+
linked_data = geo_link_clinical_genetic_data(clinical_features_df, normalized_gene_data)
|
148 |
+
|
149 |
+
# 3. Handle missing values systematically using the actual trait name
|
150 |
+
linked_data_processed = handle_missing_values(linked_data, trait_col=trait)
|
151 |
+
|
152 |
+
# 4. Check for biased trait and remove any biased demographic features
|
153 |
+
trait_biased, linked_data_final = judge_and_remove_biased_features(linked_data_processed, trait)
|
154 |
+
|
155 |
+
# 5. Final quality validation and metadata saving
|
156 |
+
is_usable = validate_and_save_cohort_info(
|
157 |
+
is_final=True,
|
158 |
+
cohort=cohort,
|
159 |
+
info_path=json_path,
|
160 |
+
is_gene_available=True,
|
161 |
+
is_trait_available=True,
|
162 |
+
is_biased=trait_biased,
|
163 |
+
df=linked_data_final,
|
164 |
+
note="Dataset processed with GEO pipeline. Checked for missing values and bias."
|
165 |
+
)
|
166 |
+
|
167 |
+
# 6. If dataset is usable, save the final linked data
|
168 |
+
if is_usable:
|
169 |
+
linked_data_final.to_csv(out_data_file)
|
p1/preprocess/Bile_Duct_Cancer/code/GSE131027.py
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Bile_Duct_Cancer"
|
6 |
+
cohort = "GSE131027"
|
7 |
+
|
8 |
+
# Input paths
|
9 |
+
in_trait_dir = "../DATA/GEO/Bile_Duct_Cancer"
|
10 |
+
in_cohort_dir = "../DATA/GEO/Bile_Duct_Cancer/GSE131027"
|
11 |
+
|
12 |
+
# Output paths
|
13 |
+
out_data_file = "./output/preprocess/1/Bile_Duct_Cancer/GSE131027.csv"
|
14 |
+
out_gene_data_file = "./output/preprocess/1/Bile_Duct_Cancer/gene_data/GSE131027.csv"
|
15 |
+
out_clinical_data_file = "./output/preprocess/1/Bile_Duct_Cancer/clinical_data/GSE131027.csv"
|
16 |
+
json_path = "./output/preprocess/1/Bile_Duct_Cancer/cohort_info.json"
|
17 |
+
|
18 |
+
# STEP1
|
19 |
+
from tools.preprocess import *
|
20 |
+
# 1. Identify the paths to the SOFT file and the matrix file
|
21 |
+
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir)
|
22 |
+
|
23 |
+
# 2. Read the matrix file to obtain background information and sample characteristics data
|
24 |
+
background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design']
|
25 |
+
clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1']
|
26 |
+
background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes)
|
27 |
+
|
28 |
+
# 3. Obtain the sample characteristics dictionary from the clinical dataframe
|
29 |
+
sample_characteristics_dict = get_unique_values_by_row(clinical_data)
|
30 |
+
|
31 |
+
# 4. Explicitly print out all the background information and the sample characteristics dictionary
|
32 |
+
print("Background Information:")
|
33 |
+
print(background_info)
|
34 |
+
print("Sample Characteristics Dictionary:")
|
35 |
+
print(sample_characteristics_dict)
|
36 |
+
# 1. Gene Expression Data Availability
|
37 |
+
is_gene_available = True # Based on the series description mentioning "expression features", we assume gene expression.
|
38 |
+
|
39 |
+
# 2. Variable Availability and Data Type Conversion
|
40 |
+
|
41 |
+
# From the sample characteristics, "Bile duct cancer" appears under key=1 alongside other cancers.
|
42 |
+
# Hence, trait data is available and not constant. So:
|
43 |
+
trait_row = 1
|
44 |
+
|
45 |
+
# Age data is not present in the dictionary.
|
46 |
+
age_row = None
|
47 |
+
|
48 |
+
# Gender data is also absent in the dictionary.
|
49 |
+
gender_row = None
|
50 |
+
|
51 |
+
# Define conversion functions
|
52 |
+
def convert_trait(value: str):
|
53 |
+
# Split by colon and take the rightmost part
|
54 |
+
val = value.split(':')[-1].strip().lower()
|
55 |
+
# Convert "bile duct cancer" to 1, everything else to 0, unknown to None
|
56 |
+
if val == "bile duct cancer":
|
57 |
+
return 1
|
58 |
+
elif val:
|
59 |
+
return 0
|
60 |
+
return None
|
61 |
+
|
62 |
+
def convert_age(value: str):
|
63 |
+
# No data available, just return None
|
64 |
+
return None
|
65 |
+
|
66 |
+
def convert_gender(value: str):
|
67 |
+
# No data available, just return None
|
68 |
+
return None
|
69 |
+
|
70 |
+
# 3. Save Metadata (initial filtering)
|
71 |
+
is_trait_available = (trait_row is not None)
|
72 |
+
is_usable = 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 (only if trait_row is not None)
|
81 |
+
if trait_row is not None:
|
82 |
+
selected_clinical_df = geo_select_clinical_features(
|
83 |
+
clinical_df=clinical_data,
|
84 |
+
trait=trait,
|
85 |
+
trait_row=trait_row,
|
86 |
+
convert_trait=convert_trait,
|
87 |
+
age_row=age_row,
|
88 |
+
convert_age=convert_age,
|
89 |
+
gender_row=gender_row,
|
90 |
+
convert_gender=convert_gender
|
91 |
+
)
|
92 |
+
# Preview the extracted features (just for inspection, not stored)
|
93 |
+
print(preview_df(selected_clinical_df, n=5, max_items=200))
|
94 |
+
# Save clinical data
|
95 |
+
selected_clinical_df.to_csv(out_clinical_data_file, index=False)
|
96 |
+
# STEP3
|
97 |
+
# 1. Use the get_genetic_data function from the library to get the gene_data from the matrix_file previously defined.
|
98 |
+
gene_data = get_genetic_data(matrix_file)
|
99 |
+
|
100 |
+
# 2. Print the first 20 row IDs (gene or probe identifiers) for future observation.
|
101 |
+
print(gene_data.index[:20])
|
102 |
+
print("requires_gene_mapping = True")
|
103 |
+
# STEP5
|
104 |
+
# 1. Use the 'get_gene_annotation' function from the library to get gene annotation data from the SOFT file.
|
105 |
+
gene_annotation = get_gene_annotation(soft_file)
|
106 |
+
|
107 |
+
# 2. Use the 'preview_df' function from the library to preview the data and print out the results.
|
108 |
+
print("Gene annotation preview:")
|
109 |
+
print(preview_df(gene_annotation))
|
110 |
+
# STEP6 - Gene Identifier Mapping
|
111 |
+
|
112 |
+
# 1. Identify columns in 'gene_annotation' which correspond to the probe ID and the gene symbol.
|
113 |
+
# From the preview, the 'ID' column matches our gene_data index (e.g., '1007_s_at'),
|
114 |
+
# and the 'Gene Symbol' column stores the gene symbols.
|
115 |
+
|
116 |
+
# 2. Get the gene mapping dataframe
|
117 |
+
gene_mapping_df = get_gene_mapping(
|
118 |
+
annotation=gene_annotation,
|
119 |
+
prob_col="ID",
|
120 |
+
gene_col="Gene Symbol"
|
121 |
+
)
|
122 |
+
|
123 |
+
# 3. Convert probe-level measurements to gene expression data
|
124 |
+
gene_data = apply_gene_mapping(
|
125 |
+
expression_df=gene_data,
|
126 |
+
mapping_df=gene_mapping_df
|
127 |
+
)
|
128 |
+
|
129 |
+
# Optional: Print shape or index to verify
|
130 |
+
print("Gene expression data after mapping:")
|
131 |
+
print("Shape:", gene_data.shape)
|
132 |
+
print("First 5 genes:\n", gene_data.index[:5])
|
133 |
+
# STEP7
|
134 |
+
|
135 |
+
# 1. Normalize the obtained gene data using the NCBI Gene synonym database
|
136 |
+
normalized_gene_data = normalize_gene_symbols_in_index(gene_data)
|
137 |
+
normalized_gene_data.to_csv(out_gene_data_file)
|
138 |
+
|
139 |
+
# 2. Link the clinical and genetic data
|
140 |
+
linked_data = geo_link_clinical_genetic_data(selected_clinical_df, normalized_gene_data)
|
141 |
+
|
142 |
+
# 3. Handle missing values systematically using the actual trait name
|
143 |
+
linked_data_processed = handle_missing_values(linked_data, trait_col=trait)
|
144 |
+
|
145 |
+
# 4. Check for biased trait and remove any biased demographic features
|
146 |
+
trait_biased, linked_data_final = judge_and_remove_biased_features(linked_data_processed, trait)
|
147 |
+
|
148 |
+
# 5. Final quality validation and metadata saving
|
149 |
+
is_usable = validate_and_save_cohort_info(
|
150 |
+
is_final=True,
|
151 |
+
cohort=cohort,
|
152 |
+
info_path=json_path,
|
153 |
+
is_gene_available=True,
|
154 |
+
is_trait_available=True,
|
155 |
+
is_biased=trait_biased,
|
156 |
+
df=linked_data_final,
|
157 |
+
note="Dataset processed with GEO pipeline. Checked for missing values and bias."
|
158 |
+
)
|
159 |
+
|
160 |
+
# 6. If dataset is usable, save the final linked data
|
161 |
+
if is_usable:
|
162 |
+
linked_data_final.to_csv(out_data_file)
|
p1/preprocess/Bile_Duct_Cancer/code/TCGA.py
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path Configuration
|
2 |
+
from tools.preprocess import *
|
3 |
+
|
4 |
+
# Processing context
|
5 |
+
trait = "Bile_Duct_Cancer"
|
6 |
+
|
7 |
+
# Input paths
|
8 |
+
tcga_root_dir = "../DATA/TCGA"
|
9 |
+
|
10 |
+
# Output paths
|
11 |
+
out_data_file = "./output/preprocess/1/Bile_Duct_Cancer/TCGA.csv"
|
12 |
+
out_gene_data_file = "./output/preprocess/1/Bile_Duct_Cancer/gene_data/TCGA.csv"
|
13 |
+
out_clinical_data_file = "./output/preprocess/1/Bile_Duct_Cancer/clinical_data/TCGA.csv"
|
14 |
+
json_path = "./output/preprocess/1/Bile_Duct_Cancer/cohort_info.json"
|
15 |
+
|
16 |
+
import os
|
17 |
+
import pandas as pd
|
18 |
+
|
19 |
+
# Step 1: Check directories in tcga_root_dir for anything relevant to "Bile_Duct_Cancer"
|
20 |
+
search_terms = ["bile_duct", "bileduct", "chol"]
|
21 |
+
dir_list = os.listdir(tcga_root_dir)
|
22 |
+
matching_dir = None
|
23 |
+
|
24 |
+
for d in dir_list:
|
25 |
+
d_lower = d.lower()
|
26 |
+
if any(term in d_lower for term in search_terms):
|
27 |
+
# Found a match, select this directory
|
28 |
+
matching_dir = d
|
29 |
+
break
|
30 |
+
|
31 |
+
if matching_dir is None:
|
32 |
+
# No matching directory found. Mark the dataset as skipped.
|
33 |
+
validate_and_save_cohort_info(
|
34 |
+
is_final=False,
|
35 |
+
cohort="TCGA",
|
36 |
+
info_path=json_path,
|
37 |
+
is_gene_available=False,
|
38 |
+
is_trait_available=False
|
39 |
+
)
|
40 |
+
else:
|
41 |
+
# 2. Identify the clinicalMatrix and PANCAN files
|
42 |
+
cohort_dir = os.path.join(tcga_root_dir, matching_dir)
|
43 |
+
clinical_file_path, genetic_file_path = tcga_get_relevant_filepaths(cohort_dir)
|
44 |
+
|
45 |
+
# 3. Load both data files
|
46 |
+
clinical_df = pd.read_csv(clinical_file_path, index_col=0, sep='\t')
|
47 |
+
genetic_df = pd.read_csv(genetic_file_path, index_col=0, sep='\t')
|
48 |
+
|
49 |
+
# 4. Print the column names of the clinical data
|
50 |
+
print("Clinical Data Columns:")
|
51 |
+
print(clinical_df.columns.tolist())
|
52 |
+
# Identify candidate demographic columns
|
53 |
+
candidate_age_cols = ["age_at_initial_pathologic_diagnosis", "days_to_birth"]
|
54 |
+
candidate_gender_cols = ["gender"]
|
55 |
+
|
56 |
+
# Extract the columns and preview them
|
57 |
+
age_cols_in_data = [col for col in candidate_age_cols if col in clinical_df.columns]
|
58 |
+
gender_cols_in_data = [col for col in candidate_gender_cols if col in clinical_df.columns]
|
59 |
+
|
60 |
+
if age_cols_in_data:
|
61 |
+
age_preview_df = clinical_df[age_cols_in_data]
|
62 |
+
print("Age Data Preview:", preview_df(age_preview_df, n=5))
|
63 |
+
else:
|
64 |
+
print("Age Data Preview:", {})
|
65 |
+
|
66 |
+
if gender_cols_in_data:
|
67 |
+
gender_preview_df = clinical_df[gender_cols_in_data]
|
68 |
+
print("Gender Data Preview:", preview_df(gender_preview_df, n=5))
|
69 |
+
else:
|
70 |
+
print("Gender Data Preview:", {})
|
71 |
+
# Based on inspection of the supplied previews, we select "age_at_initial_pathologic_diagnosis" for age
|
72 |
+
# (as it directly represents age in years) and "gender" for gender.
|
73 |
+
|
74 |
+
age_col = "age_at_initial_pathologic_diagnosis"
|
75 |
+
gender_col = "gender"
|
76 |
+
|
77 |
+
print("Chosen Age Column:", age_col)
|
78 |
+
print("Chosen Gender Column:", gender_col)
|
79 |
+
# 1) Extract and standardize clinical features (trait, age, gender) from the TCGA data
|
80 |
+
selected_clinical_df = tcga_select_clinical_features(
|
81 |
+
clinical_df=clinical_df,
|
82 |
+
trait=trait,
|
83 |
+
age_col=age_col,
|
84 |
+
gender_col=gender_col
|
85 |
+
)
|
86 |
+
|
87 |
+
# 2) Normalize gene symbols in the gene expression data
|
88 |
+
genetic_df_normalized = normalize_gene_symbols_in_index(genetic_df)
|
89 |
+
genetic_df_normalized.to_csv(out_gene_data_file)
|
90 |
+
|
91 |
+
# 3) Link clinical and genetic data on sample IDs
|
92 |
+
gene_expr_t = genetic_df_normalized.T
|
93 |
+
linked_data = selected_clinical_df.join(gene_expr_t, how='inner')
|
94 |
+
|
95 |
+
# 4) Handle missing values in the linked data
|
96 |
+
linked_data = handle_missing_values(linked_data, trait)
|
97 |
+
|
98 |
+
# 5) Determine whether the trait and some demographic features are severely biased
|
99 |
+
trait_biased, linked_data = judge_and_remove_biased_features(linked_data, trait)
|
100 |
+
|
101 |
+
# 6) Validate and save cohort information
|
102 |
+
is_usable = validate_and_save_cohort_info(
|
103 |
+
is_final=True,
|
104 |
+
cohort="TCGA",
|
105 |
+
info_path=json_path,
|
106 |
+
is_gene_available=True,
|
107 |
+
is_trait_available=True,
|
108 |
+
is_biased=trait_biased,
|
109 |
+
df=linked_data,
|
110 |
+
note="Prostate Cancer data from TCGA."
|
111 |
+
)
|
112 |
+
|
113 |
+
# 7) If usable, save the final linked data, including clinical and genetic features
|
114 |
+
if is_usable:
|
115 |
+
linked_data.to_csv(out_data_file)
|
116 |
+
# Save clinical subset if present
|
117 |
+
clinical_cols = [col for col in [trait, "Age", "Gender"] if col in linked_data.columns]
|
118 |
+
if clinical_cols:
|
119 |
+
linked_data[clinical_cols].to_csv(out_clinical_data_file)
|
p1/preprocess/Bile_Duct_Cancer/cohort_info.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"GSE131027": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": false, "has_gender": false, "sample_size": 92, "note": "Dataset processed with GEO pipeline. Checked for missing values and bias."}, "GSE107754": {"is_usable": false, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": true, "has_age": false, "has_gender": true, "sample_size": 84, "note": "Dataset processed with GEO pipeline. Checked for missing values and bias."}, "TCGA": {"is_usable": true, "is_gene_available": true, "is_trait_available": true, "is_available": true, "is_biased": false, "has_age": true, "has_gender": true, "sample_size": 45, "note": "Prostate Cancer data from TCGA."}}
|
p1/preprocess/Bile_Duct_Cancer/gene_data/GSE107754.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a82da64a5edcbde2a3ccf1c07d005767e02ceeaad822b4ed6217419063405079
|
3 |
+
size 19822703
|
p1/preprocess/Bile_Duct_Cancer/gene_data/GSE131027.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a8582008fe6fc5b90879aea7d12ca4ea58cc0bbe03209acb333425d229be6e33
|
3 |
+
size 24379939
|
p1/preprocess/Bile_Duct_Cancer/gene_data/TCGA.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:487ad5b2b7321770f48f777197bb2b173d2d7bdc3c910702b5bbc9b90cd9dc77
|
3 |
+
size 13655934
|
p1/preprocess/Bipolar_disorder/GSE120340.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Bipolar_disorder/GSE120342.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Bipolar_disorder/GSE46416.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
p1/preprocess/Bipolar_disorder/GSE46449.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dd9c37f1491e231f5be738c4447ac560f961bc72284a9d5d73f3596e3b13b07f
|
3 |
+
size 23289308
|
p1/preprocess/Bipolar_disorder/GSE92538.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b672a0b2d6064f5dfcc1a63d081c449ddb4e827649580c6072269951c5173e5c
|
3 |
+
size 32891082
|
p1/preprocess/Bipolar_disorder/clinical_data/GSE120340.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
GSM3398477,GSM3398478,GSM3398479,GSM3398480,GSM3398481,GSM3398482,GSM3398483,GSM3398484,GSM3398485,GSM3398486,GSM3398487,GSM3398488,GSM3398489,GSM3398490,GSM3398491,GSM3398492,GSM3398493,GSM3398494,GSM3398495,GSM3398496,GSM3398497,GSM3398498,GSM3398499,GSM3398500,GSM3398501,GSM3398502,GSM3398503,GSM3398504,GSM3398505,GSM3398506
|
2 |
+
0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
|
p1/preprocess/Bipolar_disorder/clinical_data/GSE120342.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
GSM3398507,GSM3398508,GSM3398509,GSM3398510,GSM3398511,GSM3398512,GSM3398513,GSM3398514,GSM3398515,GSM3398516,GSM3398517
|
2 |
+
0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0
|
p1/preprocess/Bipolar_disorder/clinical_data/GSE46416.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
GSM1129903,GSM1129904,GSM1129905,GSM1129906,GSM1129907,GSM1129908,GSM1129909,GSM1129910,GSM1129911,GSM1129912,GSM1129913,GSM1129914,GSM1129915,GSM1129916,GSM1129917,GSM1129918,GSM1129919,GSM1129920,GSM1129921,GSM1129922,GSM1129923,GSM1129924,GSM1129925,GSM1129926,GSM1129927,GSM1129928,GSM1129929,GSM1129930,GSM1129931,GSM1129932,GSM1129933,GSM1129934
|
2 |
+
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0
|
p1/preprocess/Bipolar_disorder/clinical_data/GSE46449.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
GSM1130402,GSM1130403,GSM1130404,GSM1130405,GSM1130406,GSM1130407,GSM1130408,GSM1130409,GSM1130410,GSM1130411,GSM1130412,GSM1130413,GSM1130414,GSM1130415,GSM1130416,GSM1130417,GSM1130418,GSM1130419,GSM1130420,GSM1130421,GSM1130422,GSM1130423,GSM1130424,GSM1130425,GSM1130426,GSM1130427,GSM1130428,GSM1130429,GSM1130430,GSM1130431,GSM1130432,GSM1130433,GSM1130434,GSM1130435,GSM1130436,GSM1130437,GSM1130438,GSM1130439,GSM1130440,GSM1130441,GSM1130442,GSM1130443,GSM1130444,GSM1130445,GSM1130446,GSM1130447,GSM1130448,GSM1130449,GSM1130450,GSM1130451,GSM1130452,GSM1130453,GSM1130454,GSM1130455,GSM1130456,GSM1130457,GSM1130458,GSM1130459,GSM1130460,GSM1130461,GSM1130462,GSM1130463,GSM1130464,GSM1130465,GSM1130466,GSM1130467,GSM1130468,GSM1130469,GSM1130470,GSM1130471,GSM1130472,GSM1130473,GSM1130474,GSM1130475,GSM1130476,GSM1130477,GSM1130478,GSM1130479,GSM1130480,GSM1130481,GSM1130482,GSM1130483,GSM1130484,GSM1130485,GSM1130486,GSM1130487,GSM1130488,GSM1130489
|
2 |
+
1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0
|
3 |
+
63.0,63.0,43.0,43.0,40.0,40.0,28.0,35.0,35.0,40.0,40.0,41.0,41.0,27.0,27.0,33.0,33.0,31.0,31.0,26.0,26.0,27.0,27.0,29.0,42.0,42.0,28.0,28.0,27.0,27.0,37.0,37.0,25.0,25.0,36.0,36.0,30.0,36.0,36.0,62.0,42.0,52.0,24.0,21.0,26.0,26.0,63.0,50.0,49.0,49.0,49.0,58.0,58.0,41.0,41.0,33.0,33.0,48.0,48.0,23.0,26.0,26.0,31.0,31.0,63.0,63.0,38.0,38.0,24.0,24.0,24.0,70.0,70.0,25.0,29.0,37.0,37.0,24.0,24.0,31.0,35.0,23.0,23.0,28.0,28.0,23.0,23.0,50.0
|