|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Height" |
|
cohort = "GSE97475" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Height" |
|
in_cohort_dir = "../DATA/GEO/Height/GSE97475" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Height/GSE97475.csv" |
|
out_gene_data_file = "./output/preprocess/3/Height/gene_data/GSE97475.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Height/clinical_data/GSE97475.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 = 5 |
|
|
|
|
|
age_row = 81 |
|
|
|
|
|
gender_row = 118 |
|
|
|
def convert_trait(x): |
|
|
|
if pd.isna(x) or ':' not in x: |
|
return None |
|
height = x.split(': ')[1] |
|
try: |
|
|
|
return float(height) |
|
except: |
|
if height == 'NA': |
|
return None |
|
return None |
|
|
|
def convert_age(x): |
|
if pd.isna(x) or ':' not in x: |
|
return None |
|
age = x.split(': ')[1] |
|
try: |
|
|
|
return float(age) |
|
except: |
|
if age == 'NA': |
|
return None |
|
return None |
|
|
|
def convert_gender(x): |
|
if pd.isna(x) or ':' not in x: |
|
return None |
|
gender = x.split(': ')[1] |
|
|
|
if gender.lower() == 'female': |
|
return 0 |
|
elif gender.lower() == '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: |
|
clinical_features_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(clinical_features_df)) |
|
|
|
|
|
clinical_features_df.to_csv(out_clinical_data_file) |
|
|
|
genetic_data = get_genetic_data(matrix_file_path) |
|
|
|
|
|
print("First few rows of the genetic data:") |
|
print(genetic_data.head()) |
|
print("\nShape of genetic data:", genetic_data.shape) |
|
print("\nColumn names:", genetic_data.columns.tolist()) |
|
|
|
|
|
requires_gene_mapping = False |
|
|
|
gene_data = get_genetic_data(matrix_file_path) |
|
is_gene_available = len(gene_data.columns) > 1 |
|
|
|
|
|
clinical_data = pd.read_csv(out_clinical_data_file, index_col=0) |
|
|
|
is_trait_available = not clinical_data.loc[trait].isna().all() |
|
|
|
|
|
gene_data = normalize_gene_symbols_in_index(gene_data) |
|
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) |
|
gene_data.to_csv(out_gene_data_file) |
|
|
|
|
|
linked_data = pd.DataFrame() |
|
is_biased = True |
|
if is_trait_available: |
|
linked_data = geo_link_clinical_genetic_data(clinical_data, gene_data) |
|
linked_data = handle_missing_values(linked_data, trait) |
|
is_biased, linked_data = judge_and_remove_biased_features(linked_data, trait) |
|
|
|
|
|
note = "This dataset contains valid gene expression data and demographic information (age and gender), but all height measurements are missing." |
|
is_usable = validate_and_save_cohort_info( |
|
is_final=True, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=is_gene_available, |
|
is_trait_available=is_trait_available, |
|
is_biased=is_biased, |
|
df=linked_data, |
|
note=note |
|
) |
|
|
|
|
|
if is_usable: |
|
os.makedirs(os.path.dirname(out_data_file), exist_ok=True) |
|
linked_data.to_csv(out_data_file) |