|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Substance_Use_Disorder" |
|
cohort = "GSE148375" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Substance_Use_Disorder" |
|
in_cohort_dir = "../DATA/GEO/Substance_Use_Disorder/GSE148375" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Substance_Use_Disorder/GSE148375.csv" |
|
out_gene_data_file = "./output/preprocess/3/Substance_Use_Disorder/gene_data/GSE148375.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Substance_Use_Disorder/clinical_data/GSE148375.csv" |
|
json_path = "./output/preprocess/3/Substance_Use_Disorder/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) |
|
print("Background Information:") |
|
print(background_info) |
|
print("\nSample Characteristics:") |
|
|
|
|
|
unique_values_dict = get_unique_values_by_row(clinical_data) |
|
for row, values in unique_values_dict.items(): |
|
print(f"\n{row}:") |
|
print(values) |
|
|
|
|
|
is_gene_available = True |
|
|
|
|
|
|
|
trait_row = 6 |
|
|
|
age_row = 1 |
|
|
|
gender_row = 2 |
|
|
|
|
|
def convert_trait(x): |
|
if pd.isna(x) or ':' not in x: |
|
return None |
|
val = x.split(':')[1].strip().lower() |
|
|
|
if 'smoker' in val: |
|
if val == 'smoker': |
|
return 1 |
|
else: |
|
return 0 |
|
return None |
|
|
|
def convert_age(x): |
|
if pd.isna(x) or ':' not in x: |
|
return None |
|
try: |
|
return float(x.split(':')[1].strip()) |
|
except: |
|
return None |
|
|
|
def convert_gender(x): |
|
if pd.isna(x) or ':' not in x: |
|
return None |
|
val = x.split(':')[1].strip().lower() |
|
if val == 'female': |
|
return 0 |
|
elif val == 'male': |
|
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=(trait_row is not None) |
|
) |
|
|
|
|
|
if trait_row is not None: |
|
selected_clinical_df = geo_select_clinical_features( |
|
clinical_df=clinical_data, |
|
trait=trait, |
|
trait_row=trait_row, |
|
convert_trait=convert_trait, |
|
age_row=age_row, |
|
convert_age=convert_age, |
|
gender_row=gender_row, |
|
convert_gender=convert_gender |
|
) |
|
|
|
print("Preview of extracted clinical features:") |
|
print(preview_df(selected_clinical_df)) |
|
|
|
|
|
selected_clinical_df.to_csv(out_clinical_data_file) |
|
|
|
row_count = 0 |
|
with gzip.open(matrix_file_path, 'rt') as f: |
|
for line in f: |
|
if '!series_matrix_table_begin' in line: |
|
break |
|
row_count += 1 |
|
|
|
genetic_data = pd.read_csv(matrix_file_path, compression='gzip', skiprows=row_count+1, sep='\t', |
|
index_col=0, comment='!') |
|
|
|
|
|
genetic_data = genetic_data[~genetic_data.index.str.contains('!series_matrix_table_end', na=False)] |
|
|
|
|
|
print("Data structure and head:") |
|
print(genetic_data.head()) |
|
|
|
print("\nShape:", genetic_data.shape) |
|
|
|
print("\nFirst 20 row IDs (gene/probe identifiers):") |
|
print(list(genetic_data.index)[:20]) |
|
|
|
print("\nFirst 5 column names:") |
|
print(list(genetic_data.columns)[:5]) |
|
|
|
is_gene_available = False |
|
|
|
|
|
validate_and_save_cohort_info( |
|
is_final=False, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=is_gene_available, |
|
is_trait_available=(trait_row is not None) |
|
) |