-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
173 lines (68 loc) · 3.11 KB
/
Copy pathmain.py
File metadata and controls
173 lines (68 loc) · 3.11 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import os
import pandas as pd
from GeoDataset import GeoDataset
from SRRDownload import SRRDownload
from SRRConvert import SRRConvert
from utils import log_message
def main(geo_accessions_file, base_dir="output", summary_csv="metadata_summary.csv"):
"""
Main function to process GEO accessions, download SRRs, and convert them to FASTQ.
"""
log_message("Starting GEO dataset processing pipeline.")
# Read GEO accessions from file
with open(geo_accessions_file, "r") as f:
geo_accessions = [line.strip() for line in f if line.strip()]
# Initialize GeoDataset
geo_dataset = GeoDataset(geo_accessions)
geo_results = geo_dataset.process_all(base_dir, summary_csv)
# Initialize SRRDownload
srr_downloader = SRRDownload()
for result in geo_results:
accession = result["accession"]
geo_dir = result["geo_directory"]
gds_id = result["gds_id"]
if not gds_id:
log_message(f"Skipping {accession} due to missing GDS ID.", level="WARNING")
continue
srr_csv_path = os.path.join(geo_dir, "SRR.csv")
runinfo_path = os.path.join(geo_dir, f"{gds_id}_SRA_RunInfo.csv")
if not os.path.exists(srr_csv_path) or not os.path.exists(runinfo_path):
log_message(f"Skipping {accession}, missing required files.", level="WARNING")
continue
# Read SRR IDs and library layout
try:
srr_df = pd.read_csv(srr_csv_path)
srr_ids = srr_df["Run"].tolist()
runinfo_df = pd.read_csv(runinfo_path)
layout_map = {row["Run"]: row.get("LibraryLayout", "SINGLE") for _, row in runinfo_df.iterrows() if "Run" in row}
except Exception as e:
log_message(f"Error reading metadata for {accession}: {e}", level="ERROR")
continue
# Download SRRs
srr_downloader.download_srrs(srr_ids, geo_dir)
# Convert SRRs to FASTQ
srr_converter = SRRConvert()
for result in geo_results:
accession = result["accession"]
geo_dir = result["geo_directory"]
gds_id = result["gds_id"]
if not gds_id:
continue
runinfo_path = os.path.join(geo_dir, f"{gds_id}_SRA_RunInfo.csv")
if not os.path.exists(runinfo_path):
continue
try:
runinfo_df = pd.read_csv(runinfo_path)
layout_map = {row["Run"]: row.get("LibraryLayout", "SINGLE") for _, row in runinfo_df.iterrows() if "Run" in row}
except Exception as e:
log_message(f"Error reading runinfo for {accession}: {e}", level="ERROR")
continue
srr_converter.convert_srr_to_fastq(srr_ids, geo_dir, layout_map)
log_message("Finished GEO dataset processing pipeline.")
if __name__ == "__main__":
import sys
if len(sys.argv) != 2:
print("Usage: python main.py <geo_accessions_file>")
sys.exit(1)
geo_accessions_file = sys.argv[1]
main(geo_accessions_file)