File size: 2,773 Bytes
e6817b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Path Configuration
from tools.preprocess import *

# Processing context
trait = "Height"
cohort = "GSE102130"

# Input paths
in_trait_dir = "../DATA/GEO/Height"
in_cohort_dir = "../DATA/GEO/Height/GSE102130"

# Output paths
out_data_file = "./output/preprocess/3/Height/GSE102130.csv"
out_gene_data_file = "./output/preprocess/3/Height/gene_data/GSE102130.csv"
out_clinical_data_file = "./output/preprocess/3/Height/clinical_data/GSE102130.csv"
json_path = "./output/preprocess/3/Height/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)

# Get unique values for each clinical feature 
unique_values_dict = get_unique_values_by_row(clinical_data)

# Print background information
print("Background Information:")
print(background_info)
print("\nSample Characteristics:")
print(json.dumps(unique_values_dict, indent=2))
# 1. Gene Expression Data Availability 
is_gene_available = True  # Contains scRNA-seq data according to series title and summary

# 2. Variable Availability and Data Type Conversion
# 2.1 Data Keys
# None of Height, age or gender information is available in the sample characteristics
trait_row = None 
age_row = None  
gender_row = None

# 2.2 Data Type Conversion Functions
def convert_trait(x):
    if ':' in str(x):
        val = str(x).split(':')[1].strip()
        try:
            return float(val)
        except:
            return None
    return None

def convert_age(x):
    if ':' in str(x):
        val = str(x).split(':')[1].strip()
        try:
            return float(val)
        except:
            return None
    return None

def convert_gender(x):
    if ':' in str(x):
        val = str(x).split(':')[1].strip().lower()
        if 'female' in val or 'f' in val:
            return 0
        elif 'male' in val or 'm' in val:
            return 1
    return None

# 3. Save 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. Clinical Feature Extraction is skipped since trait_row is None
# Extract gene expression data from the matrix file
try:
    # First check if we can read the file and print contents
    print("First few lines of the matrix file:")
    with gzip.open(matrix_file_path, 'rt', encoding='latin-1') as file:
        for i, line in enumerate(file):
            if i < 10:
                print(line.strip())
            if i > 10:
                break
                
except Exception as e:
    print(f"Error reading matrix file: {e}")