|
|
|
from tools.preprocess import * |
|
|
|
|
|
trait = "Cardiovascular_Disease" |
|
cohort = "GSE228783" |
|
|
|
|
|
in_trait_dir = "../DATA/GEO/Cardiovascular_Disease" |
|
in_cohort_dir = "../DATA/GEO/Cardiovascular_Disease/GSE228783" |
|
|
|
|
|
out_data_file = "./output/preprocess/3/Cardiovascular_Disease/GSE228783.csv" |
|
out_gene_data_file = "./output/preprocess/3/Cardiovascular_Disease/gene_data/GSE228783.csv" |
|
out_clinical_data_file = "./output/preprocess/3/Cardiovascular_Disease/clinical_data/GSE228783.csv" |
|
json_path = "./output/preprocess/3/Cardiovascular_Disease/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): |
|
return None |
|
|
|
def convert_age(x): |
|
return None |
|
|
|
def convert_gender(x): |
|
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=False |
|
) |
|
|
|
|
|
|
|
genetic_df = get_genetic_data(matrix_file) |
|
|
|
|
|
print("DataFrame shape:", genetic_df.shape) |
|
print("\nFirst few rows and columns:") |
|
print(genetic_df.head().iloc[:, :5]) |
|
|
|
|
|
print("\nRaw file preview:") |
|
with gzip.open(matrix_file, 'rt') as f: |
|
for i, line in enumerate(f): |
|
if i > 30 and i < 35: |
|
print(line.strip()) |
|
|
|
|
|
|
|
|
|
requires_gene_mapping = True |
|
|
|
gene_metadata = get_gene_annotation(soft_file) |
|
|
|
|
|
print("Column names and preview of gene annotation data:") |
|
print(preview_df(gene_metadata)) |
|
|
|
mapping_df = get_gene_mapping(gene_metadata, prob_col='ID', gene_col='Gene Symbol') |
|
|
|
|
|
gene_data = apply_gene_mapping(genetic_df, mapping_df) |
|
|
|
|
|
print("Gene expression data shape after mapping:", gene_data.shape) |
|
print("\nFirst few rows of gene expression data:") |
|
print(gene_data.head().iloc[:, :5]) |
|
|
|
genetic_df = normalize_gene_symbols_in_index(gene_data) |
|
os.makedirs(os.path.dirname(out_gene_data_file), exist_ok=True) |
|
genetic_df.to_csv(out_gene_data_file) |
|
|
|
|
|
placeholder_df = pd.DataFrame(index=genetic_df.columns, columns=['trait']) |
|
|
|
|
|
note = "Dataset contains gene expression data from liver tissue samples but lacks required trait information for cardiovascular disease analysis." |
|
is_usable = validate_and_save_cohort_info( |
|
is_final=True, |
|
cohort=cohort, |
|
info_path=json_path, |
|
is_gene_available=True, |
|
is_trait_available=False, |
|
is_biased=True, |
|
df=placeholder_df, |
|
note=note |
|
) |