| |
| from tools.preprocess import * |
|
|
| |
| trait = "Allergies" |
| cohort = "GSE184382" |
|
|
| |
| in_trait_dir = "../DATA/GEO/Allergies" |
| in_cohort_dir = "../DATA/GEO/Allergies/GSE184382" |
|
|
| |
| out_data_file = "./output/z1/preprocess/Allergies/GSE184382.csv" |
| out_gene_data_file = "./output/z1/preprocess/Allergies/gene_data/GSE184382.csv" |
| out_clinical_data_file = "./output/z1/preprocess/Allergies/clinical_data/GSE184382.csv" |
| json_path = "./output/z1/preprocess/Allergies/cohort_info.json" |
|
|
|
|
| |
| import os |
| from tools.preprocess import * |
|
|
| |
| def find_geo_files_recursive(root_dir: str): |
| matrix_candidates = [] |
| soft_candidates = [] |
| for dirpath, _, filenames in os.walk(root_dir): |
| for fname in filenames: |
| lf = fname.lower() |
| full_path = os.path.join(dirpath, fname) |
| |
| if ('series_matrix' in lf or 'matrix' in lf) and lf.endswith('.gz'): |
| matrix_candidates.append(full_path) |
| |
| if 'soft' in lf and (lf.endswith('.gz') or lf.endswith('.soft') or lf.endswith('.txt')): |
| soft_candidates.append(full_path) |
| matrix_candidates.sort() |
| soft_candidates.sort() |
| return matrix_candidates[0] if matrix_candidates else None, soft_candidates[0] if soft_candidates else None |
|
|
| soft_file = None |
| matrix_file = None |
|
|
| |
| try: |
| soft_guess, matrix_guess = geo_get_relevant_filepaths(in_cohort_dir) |
| |
| soft_file = soft_guess |
| matrix_file = matrix_guess |
| except Exception: |
| pass |
|
|
| |
| if matrix_file is None or not os.path.exists(matrix_file): |
| rec_matrix, rec_soft = find_geo_files_recursive(in_cohort_dir) |
| matrix_file = matrix_file if (matrix_file and os.path.exists(matrix_file)) else rec_matrix |
| soft_file = soft_file if (soft_file and os.path.exists(soft_file)) else rec_soft |
|
|
| |
| if matrix_file is None or not os.path.exists(matrix_file): |
| print(f"WARNING: No series matrix file found under {in_cohort_dir}. Skipping data extraction for Step 1.") |
| |
| validate_and_save_cohort_info( |
| is_final=False, |
| cohort=cohort, |
| info_path=json_path, |
| is_gene_available=False, |
| is_trait_available=False |
| ) |
| |
| background_info = "" |
| sample_characteristics_dict = {} |
| print("Background Information:") |
| print(background_info) |
| print("Sample Characteristics Dictionary:") |
| print(sample_characteristics_dict) |
| else: |
| |
| print(f"Matrix file selected: {matrix_file}") |
| if soft_file is not None: |
| print(f"SOFT file selected: {soft_file}") |
| else: |
| print("WARNING: No SOFT file found. Proceeding with matrix file only for Step 1.") |
|
|
| |
| background_prefixes = ['!Series_title', '!Series_summary', '!Series_overall_design'] |
| clinical_prefixes = ['!Sample_geo_accession', '!Sample_characteristics_ch1'] |
| background_info, clinical_data = get_background_and_clinical_data(matrix_file, background_prefixes, clinical_prefixes) |
|
|
| |
| sample_characteristics_dict = get_unique_values_by_row(clinical_data, max_len=20) |
|
|
| |
| print("Background Information:") |
| print(background_info) |
| print("Sample Characteristics Dictionary:") |
| print(sample_characteristics_dict) |