|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Depression" |
|
cohort = "GSE273630" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Depression" |
|
in_cohort_dir = "../DATA/GEO/Depression/GSE273630" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Depression/GSE273630.csv" |
|
out_gene_data_file = "./output/preprocess/3/Depression/gene_data/GSE273630.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Depression/clinical_data/GSE273630.csv" |
|
json_path = "./output/preprocess/3/Depression/cohort_info.json" |
|
|
|
|
|
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) |
|
|
|
|
|
background_info, clinical_data = get_background_and_clinical_data(matrix_file) |
|
|
|
|
|
unique_values_dict = get_unique_values_by_row(clinical_data) |
|
|
|
|
|
print("=== Dataset Background Information ===") |
|
print(background_info) |
|
print("\n=== Sample Characteristics ===") |
|
print(json.dumps(unique_values_dict, indent=2)) |
|
|
|
is_gene_available = True |
|
|
|
|
|
trait_row = None |
|
age_row = None |
|
gender_row = None |
|
|
|
|
|
def convert_trait(x): |
|
if x is None or pd.isna(x): |
|
return None |
|
val = str(x).split(':')[-1].strip().lower() |
|
|
|
if 'yes' in val or 'true' in val or 'positive' in val: |
|
return 1 |
|
elif 'no' in val or 'false' in val or 'negative' in val: |
|
return 0 |
|
return None |
|
|
|
def convert_age(x): |
|
if x is None or pd.isna(x): |
|
return None |
|
val = str(x).split(':')[-1].strip() |
|
try: |
|
return float(val) |
|
except: |
|
return None |
|
|
|
def convert_gender(x): |
|
if x is None or pd.isna(x): |
|
return None |
|
val = str(x).split(':')[-1].strip().lower() |
|
if 'female' in val or 'f' in val: |
|
return 0 |
|
elif 'male' in val or 'm' in val: |
|
return 1 |
|
return None |
|
|
|
|
|
is_trait_available = trait_row is not None |
|
validate_and_save_cohort_info( |
|
is_final=False, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=is_gene_available, |
|
is_trait_available=is_trait_available |
|
) |
|
|
|
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 = False |
|
|
|
genetic_df = normalize_gene_symbols_in_index(genetic_df) |
|
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) |
|
genetic_df.to_csv(out_gene_data_file) |
|
|
|
|
|
minimal_df = pd.DataFrame(index=genetic_df.columns) |
|
|
|
|
|
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=minimal_df, |
|
note="Dataset focuses on HIV and Methamphetamine use, depression data not available" |
|
) |