|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Huntingtons_Disease" |
|
cohort = "GSE71220" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Huntingtons_Disease" |
|
in_cohort_dir = "../DATA/GEO/Huntingtons_Disease/GSE71220" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Huntingtons_Disease/GSE71220.csv" |
|
out_gene_data_file = "./output/preprocess/3/Huntingtons_Disease/gene_data/GSE71220.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Huntingtons_Disease/clinical_data/GSE71220.csv" |
|
json_path = "./output/preprocess/3/Huntingtons_Disease/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(soft_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 = 1 |
|
age_row = 2 |
|
gender_row = 3 |
|
|
|
def convert_trait(value: str) -> int: |
|
"""Convert disease status to binary.""" |
|
if ':' in value: |
|
value = value.split(':')[1].strip() |
|
if value == 'COPD': |
|
return 1 |
|
elif value == 'Control': |
|
return 0 |
|
return None |
|
|
|
def convert_age(value: str) -> float: |
|
"""Convert age to float.""" |
|
if ':' in value: |
|
value = value.split(':')[1].strip() |
|
try: |
|
return float(value) |
|
except: |
|
return None |
|
|
|
def convert_gender(value: str) -> int: |
|
"""Convert gender to binary.""" |
|
if ':' in value: |
|
value = value.split(':')[1].strip() |
|
if value.upper() == 'F': |
|
return 0 |
|
elif value.upper() == 'M': |
|
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=True) |
|
|
|
|
|
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) |
|
|
|
|
|
preview = preview_df(selected_clinical_df) |
|
|
|
|
|
selected_clinical_df.to_csv(out_clinical_data_file) |
|
|
|
genetic_data = get_genetic_data(matrix_file_path) |
|
|
|
|
|
print("First 20 row IDs:") |
|
print(genetic_data.index[:20].tolist()) |
|
|
|
|
|
|
|
requires_gene_mapping = True |
|
|
|
gene_metadata = get_gene_annotation(soft_file_path) |
|
|
|
|
|
print("Column names:") |
|
print(gene_metadata.columns.tolist()) |
|
print("\nPreview of first few rows:") |
|
print(json.dumps(preview_df(gene_metadata), indent=2)) |
|
|
|
|
|
|
|
mapping_data = get_gene_mapping(gene_metadata, 'ID', 'gene_assignment') |
|
|
|
|
|
def extract_gene_symbols(text: str) -> List[str]: |
|
if pd.isna(text) or text == '---': |
|
return [] |
|
|
|
genes = [] |
|
segments = text.split('//') |
|
for i in range(1, len(segments)-1, 3): |
|
symbol = segments[i].strip() |
|
if symbol not in ['---', 'ENSEMBL', 'RefSeq', 'GenBank']: |
|
genes.append(symbol) |
|
return list(set(genes)) |
|
|
|
|
|
mapping_data['Gene'] = mapping_data['gene_assignment'].apply(extract_gene_symbols) |
|
|
|
|
|
gene_data = apply_gene_mapping(genetic_data, mapping_data) |
|
|
|
|
|
gene_data = normalize_gene_symbols_in_index(gene_data) |
|
|
|
|
|
print("Preview of gene expression data:") |
|
print("Number of genes:", len(gene_data.index)) |
|
print("First 5 gene symbols:", gene_data.index[:5].tolist()) |