File size: 4,667 Bytes
6f366b0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# Path Configuration
from tools.preprocess import *
# Processing context
trait = "Testicular_Cancer"
cohort = "GSE42647"
# Input paths
in_trait_dir = "../DATA/GEO/Testicular_Cancer"
in_cohort_dir = "../DATA/GEO/Testicular_Cancer/GSE42647"
# Output paths
out_data_file = "./output/preprocess/3/Testicular_Cancer/GSE42647.csv"
out_gene_data_file = "./output/preprocess/3/Testicular_Cancer/gene_data/GSE42647.csv"
out_clinical_data_file = "./output/preprocess/3/Testicular_Cancer/clinical_data/GSE42647.csv"
json_path = "./output/preprocess/3/Testicular_Cancer/cohort_info.json"
# Get file paths
soft_file_path, matrix_file_path = geo_get_relevant_filepaths(in_cohort_dir)
# Get background info and clinical data
background_info, clinical_data = get_background_and_clinical_data(matrix_file_path)
# Print shape and first few rows to verify data
print("Background Information:")
print(background_info)
print("\nClinical Data Shape:", clinical_data.shape)
print("\nFirst few rows of Clinical Data:")
print(clinical_data.head())
print("\nSample Characteristics:")
# Get dictionary of unique values per row
unique_values_dict = get_unique_values_by_row(clinical_data)
for row, values in unique_values_dict.items():
print(f"\n{row}:")
print(values)
# 1. Gene Expression Data Availability
# Yes, this dataset likely contains gene expression data since it's about pluripotent testicular cancer cells
is_gene_available = True
# 2.1 Data Availability
# From sample characteristics:
# Row 0 shows all samples are from NT2/D1-R1 cell line
# Row 1 shows all samples are human embryonal carcinoma
# Since these are all testicular cancer cell lines, trait value is 1 for all
trait_row = 1 # Use row 1 to identify testicular cancer samples
# Age and gender not available since this is cell line data
age_row = None
gender_row = None
# 2.2 Data Type Conversion Functions
def convert_trait(x):
"""Convert to binary: 1 for testicular cancer"""
value = x.split(": ")[1].lower()
if 'ebryonal carcinoma' in value:
return 1
return None
def convert_age(x):
"""Not used since age data unavailable"""
return None
def convert_gender(x):
"""Not used since gender data unavailable"""
return None
# 3. Save initial metadata
is_trait_available = trait_row is not None
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)
# 4. Extract clinical features since trait_row is not None
clinical_features = 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 the extracted features
preview = preview_df(clinical_features)
print("Preview of clinical features:")
print(preview)
# Save clinical data
clinical_features.to_csv(out_clinical_data_file)
# Since the previous assessment shows this is methylation data (not gene expression)
# and the reviewer indicated we need to return to Step 2, we should not proceed with
# gene data extraction. Simply print an explanatory message.
print("ERROR: This dataset (GSE42647) contains methylation data rather than gene expression data.")
print("Gene data extraction stopped as methylation data is not suitable for this analysis.")
print("Please revise Step 2 to correctly set is_gene_available = False")
# 1. Gene Expression Data Availability
is_gene_available = False # Methylation data is not suitable
# 2. Variable Availability and Data Type Conversion
# Since gene data is not suitable, we can skip further preprocessing
trait_row = None # Not proceeding with clinical data extraction
age_row = None
gender_row = None
# Dummy conversion functions (won't be used but defined for completeness)
def convert_trait(x): return None
def convert_age(x): return None
def convert_gender(x): return None
# 3. Save metadata
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)
)
# 4. Clinical Feature Extraction
# Skip this step since trait_row is None |