|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Hypothyroidism" |
|
cohort = "GSE32445" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Hypothyroidism" |
|
in_cohort_dir = "../DATA/GEO/Hypothyroidism/GSE32445" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Hypothyroidism/GSE32445.csv" |
|
out_gene_data_file = "./output/preprocess/3/Hypothyroidism/gene_data/GSE32445.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Hypothyroidism/clinical_data/GSE32445.csv" |
|
json_path = "./output/preprocess/3/Hypothyroidism/cohort_info.json" |
|
|
|
|
|
soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir) |
|
|
|
|
|
background_info, clinical_data = get_background_and_clinical_data(matrix_file_path) |
|
|
|
|
|
unique_values_dict = get_unique_values_by_row(clinical_data) |
|
|
|
|
|
print("Background Information:") |
|
print(background_info) |
|
print("\nSample Characteristics:") |
|
print(json.dumps(unique_values_dict, indent=2)) |
|
|
|
|
|
|
|
is_gene_available = True |
|
|
|
|
|
|
|
|
|
|
|
trait_row = None |
|
|
|
|
|
age_row = 2 |
|
|
|
|
|
gender_row = 1 |
|
|
|
|
|
|
|
def convert_trait(x): |
|
return None |
|
|
|
|
|
def convert_age(x): |
|
try: |
|
|
|
value = x.split(':')[1].strip() |
|
value = value.lower().replace('months', '').replace('years', '').strip() |
|
return float(value) |
|
except: |
|
return None |
|
|
|
|
|
def convert_gender(x): |
|
try: |
|
value = x.split(':')[1].strip().lower() |
|
if 'female' in value: |
|
return 0 |
|
elif 'male' in value: |
|
return 1 |
|
return None |
|
except: |
|
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_data = get_genetic_data(matrix_file_path) |
|
|
|
|
|
print("First 20 row IDs:") |
|
print(genetic_data.index[:20].tolist()) |
|
|
|
|
|
requires_gene_mapping = True |
|
|
|
gene_metadata = get_gene_annotation(soft_file_path) |
|
|
|
|
|
print("Column names:") |
|
print(gene_metadata.columns.tolist()) |
|
|
|
|
|
print("\nData shape:", gene_metadata.shape) |
|
|
|
|
|
print("\nNumber of non-NaN values in key columns:") |
|
for col in ['Gene Symbol', 'Gene Title']: |
|
print(f"{col}: {gene_metadata[col].notna().sum()}") |
|
|
|
|
|
print("\nPreview of rows with gene information:") |
|
gene_rows = gene_metadata[gene_metadata['Gene Symbol'].notna()].head() |
|
print(json.dumps(preview_df(gene_rows), indent=2)) |
|
|
|
|
|
mapping_data = gene_metadata.loc[:, ['ID', 'Gene Symbol']] |
|
mapping_data = mapping_data.dropna() |
|
|
|
mapping_data = mapping_data.rename(columns={'Gene Symbol': 'Gene'}) |
|
|
|
|
|
gene_data = apply_gene_mapping(genetic_data, mapping_data) |
|
|
|
|
|
print("\nNumber of genes after mapping:", len(gene_data)) |
|
print("\nFirst few gene symbols:", gene_data.index[:10].tolist()) |
|
|
|
empty_df = pd.DataFrame() |
|
|
|
|
|
note = "Dataset lacks trait information and gene mapping failed to produce any valid gene expression data." |
|
is_usable = validate_and_save_cohort_info( |
|
is_final=True, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=True, |
|
is_trait_available=False, |
|
is_biased=True, |
|
df=empty_df, |
|
note=note |
|
) |