|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Height" |
|
cohort = "GSE102130" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Height" |
|
in_cohort_dir = "../DATA/GEO/Height/GSE102130" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Height/GSE102130.csv" |
|
out_gene_data_file = "./output/preprocess/3/Height/gene_data/GSE102130.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Height/clinical_data/GSE102130.csv" |
|
json_path = "./output/preprocess/3/Height/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 = None |
|
gender_row = None |
|
|
|
|
|
def convert_trait(x): |
|
if ':' in str(x): |
|
val = str(x).split(':')[1].strip() |
|
try: |
|
return float(val) |
|
except: |
|
return None |
|
return None |
|
|
|
def convert_age(x): |
|
if ':' in str(x): |
|
val = str(x).split(':')[1].strip() |
|
try: |
|
return float(val) |
|
except: |
|
return None |
|
return None |
|
|
|
def convert_gender(x): |
|
if ':' in str(x): |
|
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 |
|
) |
|
|
|
|
|
|
|
try: |
|
|
|
print("First few lines of the matrix file:") |
|
with gzip.open(matrix_file_path, 'rt', encoding='latin-1') as file: |
|
for i, line in enumerate(file): |
|
if i < 10: |
|
print(line.strip()) |
|
if i > 10: |
|
break |
|
|
|
except Exception as e: |
|
print(f"Error reading matrix file: {e}") |