|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Cystic_Fibrosis" |
|
cohort = "GSE60690" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Cystic_Fibrosis" |
|
in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE60690" |
|
|
|
|
|
out_data_file = "./output/preprocess/1/Cystic_Fibrosis/GSE60690.csv" |
|
out_gene_data_file = "./output/preprocess/1/Cystic_Fibrosis/gene_data/GSE60690.csv" |
|
out_clinical_data_file = "./output/preprocess/1/Cystic_Fibrosis/clinical_data/GSE60690.csv" |
|
json_path = "./output/preprocess/1/Cystic_Fibrosis/cohort_info.json" |
|
|
|
|
|
from tools.preprocess import * |
|
|
|
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) |
|
|
|
|
|
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) |
|
|
|
|
|
print("Background Information:") |
|
print(background_info) |
|
print("Sample Characteristics Dictionary:") |
|
print(sample_characteristics_dict) |
|
|
|
|
|
|
|
is_gene_available = True |
|
|
|
|
|
|
|
|
|
|
|
trait_row = None |
|
|
|
|
|
age_row = 2 |
|
|
|
|
|
gender_row = 0 |
|
|
|
|
|
import re |
|
|
|
def convert_trait(value: str) -> int: |
|
""" |
|
Although trait_row is None (trait not available), |
|
define a function for completeness. |
|
Returns None if called, as there's no variation here. |
|
""" |
|
return None |
|
|
|
def convert_age(value: str) -> float: |
|
""" |
|
Convert 'age of enrollment: 38.2' -> 38.2 (float). |
|
If 'NA', return None. |
|
""" |
|
|
|
parts = value.split(':') |
|
if len(parts) < 2: |
|
return None |
|
age_str = parts[1].strip() |
|
if age_str.upper() == 'NA': |
|
return None |
|
try: |
|
return float(age_str) |
|
except ValueError: |
|
return None |
|
|
|
def convert_gender(value: str) -> int: |
|
""" |
|
Convert 'Sex: Male' -> 1 |
|
'Sex: Female' -> 0 |
|
Otherwise return None. |
|
""" |
|
parts = value.split(':') |
|
if len(parts) < 2: |
|
return None |
|
gender_str = parts[1].strip().lower() |
|
if gender_str == 'male': |
|
return 1 |
|
elif gender_str == 'female': |
|
return 0 |
|
return None |
|
|
|
|
|
|
|
is_trait_available = trait_row is not None |
|
|
|
usable_status = 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 |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
gene_data = get_genetic_data(matrix_file) |
|
|
|
|
|
print(gene_data.index[:20]) |
|
print("requires_gene_mapping = True") |
|
|
|
|
|
gene_annotation = get_gene_annotation(soft_file) |
|
|
|
|
|
print("Gene annotation preview:") |
|
print(preview_df(gene_annotation)) |
|
|
|
|
|
|
|
|
|
|
|
probe_col = "ID" |
|
gene_symbol_col = "gene_assignment" |
|
|
|
|
|
mapping_df = get_gene_mapping(gene_annotation, probe_col, gene_symbol_col) |
|
|
|
|
|
gene_data = apply_gene_mapping(gene_data, mapping_df) |
|
|
|
|
|
|
|
normalized_gene_data = normalize_gene_symbols_in_index(gene_data) |
|
normalized_gene_data.to_csv(out_gene_data_file) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
is_biased = True |
|
|
|
_ = validate_and_save_cohort_info( |
|
is_final=True, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=True, |
|
is_trait_available=False, |
|
is_biased=is_biased, |
|
df=pd.DataFrame(), |
|
note="All samples are CF patients; no variation in the trait." |
|
) |
|
|
|
|
|
|