|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Celiac_Disease" |
|
cohort = "GSE106260" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Celiac_Disease" |
|
in_cohort_dir = "../DATA/GEO/Celiac_Disease/GSE106260" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Celiac_Disease/GSE106260.csv" |
|
out_gene_data_file = "./output/preprocess/3/Celiac_Disease/gene_data/GSE106260.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Celiac_Disease/clinical_data/GSE106260.csv" |
|
json_path = "./output/preprocess/3/Celiac_Disease/cohort_info.json" |
|
|
|
|
|
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) |
|
|
|
|
|
background_info, clinical_data = get_background_and_clinical_data(soft_file) |
|
|
|
|
|
unique_values = {} |
|
for _, row in clinical_data.iterrows(): |
|
for cell in row: |
|
if isinstance(cell, str) and ': ' in cell: |
|
feature_type = cell.split(': ')[0] |
|
feature_value = cell.split(': ')[1] |
|
if feature_type not in unique_values: |
|
unique_values[feature_type] = set() |
|
unique_values[feature_type].add(feature_value) |
|
|
|
|
|
unique_values = {k: list(v) for k, v in unique_values.items()} |
|
|
|
|
|
print("=== Dataset Background Information ===") |
|
print(background_info) |
|
print("\n=== Sample Characteristics ===") |
|
print(json.dumps(unique_values, indent=2)) |
|
|
|
|
|
|
|
is_gene_available = True |
|
|
|
|
|
|
|
|
|
|
|
trait_row = None |
|
age_row = None |
|
gender_row = None |
|
|
|
|
|
def convert_trait(x): |
|
"""Convert trait value to binary""" |
|
if not isinstance(x, str): |
|
return None |
|
val = x.split(':')[-1].strip().lower() |
|
if 'celiac' in val or 'cd' in val: |
|
return 1 |
|
elif 'control' in val or 'healthy' in val: |
|
return 0 |
|
return None |
|
|
|
def convert_age(x): |
|
"""Convert age value to float""" |
|
if not isinstance(x, str): |
|
return None |
|
val = x.split(':')[-1].strip() |
|
try: |
|
return float(val) |
|
except: |
|
return None |
|
|
|
def convert_gender(x): |
|
"""Convert gender to binary""" |
|
if not isinstance(x, str): |
|
return None |
|
val = x.split(':')[-1].strip().lower() |
|
if 'f' in val or 'female' in val: |
|
return 0 |
|
elif 'm' in val or 'male' in val: |
|
return 1 |
|
return None |
|
|
|
|
|
|
|
validate_and_save_cohort_info(is_final=False, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=is_gene_available, |
|
is_trait_available=False) |
|
|
|
|
|
|
|
genetic_df = get_genetic_data(matrix_file) |
|
|
|
|
|
print("DataFrame shape:", genetic_df.shape) |
|
print("\nFirst 20 row IDs:") |
|
print(genetic_df.index[:20]) |
|
|
|
print("\nPreview of first few rows and columns:") |
|
print(genetic_df.head().iloc[:, :5]) |
|
|
|
|
|
requires_gene_mapping = True |
|
|
|
gene_metadata = get_gene_annotation(soft_file) |
|
|
|
|
|
print("Column names:") |
|
print(gene_metadata.columns) |
|
print("\nPreview of gene annotation data:") |
|
print(preview_df(gene_metadata)) |
|
|
|
prob_col = 'ID' |
|
gene_col = 'Symbol' |
|
|
|
|
|
mapping_data = get_gene_mapping(gene_metadata, prob_col, gene_col) |
|
|
|
|
|
gene_data = apply_gene_mapping(genetic_df, mapping_data) |
|
|
|
|
|
print("Gene expression data shape:", gene_data.shape) |
|
print("\nPreview of gene expression data:") |
|
print(gene_data.head().iloc[:, :5]) |
|
|
|
gene_data = normalize_gene_symbols_in_index(gene_data) |
|
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) |
|
gene_data.to_csv(out_gene_data_file) |
|
|
|
|
|
validate_and_save_cohort_info( |
|
is_final=False, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=is_gene_available, |
|
is_trait_available=False |
|
) |