|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Cystic_Fibrosis" |
|
cohort = "GSE76347" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Cystic_Fibrosis" |
|
in_cohort_dir = "../DATA/GEO/Cystic_Fibrosis/GSE76347" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Cystic_Fibrosis/GSE76347.csv" |
|
out_gene_data_file = "./output/preprocess/3/Cystic_Fibrosis/gene_data/GSE76347.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Cystic_Fibrosis/clinical_data/GSE76347.csv" |
|
json_path = "./output/preprocess/3/Cystic_Fibrosis/cohort_info.json" |
|
|
|
|
|
soft_file, matrix_file = geo_get_relevant_filepaths(in_cohort_dir) |
|
|
|
|
|
background_info, clinical_data = get_background_and_clinical_data(matrix_file) |
|
|
|
|
|
unique_values_dict = get_unique_values_by_row(clinical_data) |
|
|
|
|
|
print("=== Dataset Background Information ===") |
|
print(background_info) |
|
print("\n=== Sample 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 pd.isna(x): |
|
return None |
|
val = str(x).split(":")[-1].strip().upper() |
|
if "CF" in val: |
|
return 1 |
|
return None |
|
|
|
def convert_age(x): |
|
|
|
return None |
|
|
|
def convert_gender(x): |
|
|
|
return None |
|
|
|
|
|
|
|
is_trait_available = False if trait_row is None else True |
|
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) |
|
|
|
|
|
|
|
genetic_df = get_genetic_data(matrix_file) |
|
|
|
|
|
print("DataFrame shape:", genetic_df.shape) |
|
print("\nFirst 20 row IDs:") |
|
print(genetic_df.index[:20]) |
|
|
|
print("\nPreview of first few rows and columns:") |
|
print(genetic_df.head().iloc[:, :5]) |
|
|
|
|
|
requires_gene_mapping = True |
|
|
|
gene_metadata = get_gene_annotation(soft_file) |
|
|
|
|
|
print("Column names:") |
|
print(gene_metadata.columns) |
|
print("\nPreview of gene annotation data:") |
|
print(preview_df(gene_metadata)) |
|
|
|
prob_col = 'ID' |
|
|
|
|
|
def extract_gene_symbol(text): |
|
if pd.isna(text) or text == '---': |
|
return None |
|
|
|
parts = text.split('//') |
|
if len(parts) >= 2: |
|
return parts[1].strip() |
|
return None |
|
|
|
|
|
mapping_df = gene_metadata[['ID']].copy() |
|
mapping_df['Gene'] = gene_metadata['gene_assignment'].apply(extract_gene_symbol) |
|
mapping_df = mapping_df.dropna() |
|
|
|
|
|
gene_data = apply_gene_mapping(genetic_df, mapping_df) |
|
|
|
|
|
print("Gene expression data shape after mapping:", gene_data.shape) |
|
print("\nFirst few gene symbols:") |
|
print(gene_data.index[:10]) |
|
print("\nPreview of expression values:") |
|
print(gene_data.head().iloc[:, :5]) |
|
|
|
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) |
|
|
|
|
|
empty_df = pd.DataFrame() |
|
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=empty_df, |
|
note="All subjects have CF (constant trait). Gene expression data saved but not suitable for trait association analysis." |
|
) |