11
11
12
12
import sys
13
13
import os
14
+
14
15
#sys.path.insert(0, os.path.join(".."))
15
16
16
17
@@ -168,10 +169,10 @@ def labels_for_grap(conf, full_loci,csvdir):
168
169
169
170
nodes_plan_b = list (set (nodes_plan_b ))
170
171
all_combo_list = list (dict .fromkeys (nodes_plan_a + nodes_plan_b + top_nodes_plan_b ))
171
- with open (csvdir + '/ nodes_for_plan_a.txt' , 'w' ) as f :
172
+ with open (csvdir + 'nodes_for_plan_a.txt' , 'w' ) as f :
172
173
for item in nodes_plan_a :
173
174
f .write ("%s\n " % item )
174
- with open (csvdir + '/ nodes_for_plan_b.txt' , 'w' ) as f :
175
+ with open (csvdir + 'nodes_for_plan_b.txt' , 'w' ) as f :
175
176
for item in (nodes_plan_b + top_nodes_plan_b ):
176
177
f .write ("%s\n " % item )
177
178
#pickle.dump(nodes_plan_a, open(csvdir + '/nodes_for_plan_a.pkl', "wb"))
@@ -197,8 +198,8 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
197
198
# Configure
198
199
##############################################################################
199
200
# set output directory and create it if it doesn't exist
200
- csvdir = "output/csv"
201
- pathlib . Path ( csvdir ). mkdir ( parents = True , exist_ok = True )
201
+ # csvdir = "output/csv"
202
+
202
203
203
204
204
205
# Input file
@@ -218,6 +219,11 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
218
219
with open (configuration_file ) as f :
219
220
conf = json .load (f )
220
221
222
+ csvdir = conf .get ("graph_files_path" )
223
+ pathlib .Path (csvdir ).mkdir (parents = True , exist_ok = True )
224
+ if csvdir [- 1 ] != '/' :
225
+ csvdir += '/'
226
+
221
227
pops = conf .get ("populations" )
222
228
if em_pop :
223
229
pops = em_pop
@@ -227,16 +233,19 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
227
233
if freq_file == "default" :
228
234
freq_file = os .path .dirname (os .path .realpath (__file__ )) + '/output/hpf.csv'
229
235
dict_count_of_pop = {}
230
- #if em:
231
- for pop in pops :
232
- dict_count_of_pop [pop ] = freq_trim
233
- """else:
234
- project_dir = "../../"
235
- pop_ratio_dir = project_dir + conf.get("pops_count_file", 'imputation/graph_generation/output/pop_ratio.txt')
236
+
237
+ pop_ratio_dir = conf .get ("pops_count_file" , os .path .dirname (os .path .realpath (__file__ )) + '/imputation/graph_generation/output/pop_ratio.txt' )
238
+ path = pathlib .Path (pop_ratio_dir )
239
+
240
+
241
+ if em or not path .is_file ():
242
+ for pop in pops :
243
+ dict_count_of_pop [pop ] = freq_trim
244
+ else :
236
245
with open (pop_ratio_dir ) as f_count :
237
246
for line in f_count :
238
247
pop , count_pop , ratio = line .strip ().split (',' )
239
- dict_count_of_pop[pop] = freq_trim / float(count_pop)"""
248
+ dict_count_of_pop [pop ] = freq_trim / float (count_pop )
240
249
241
250
242
251
# Display the configurations we are using
@@ -360,7 +369,7 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
360
369
# #### Build Nodes file
361
370
362
371
header = ['haplotypeId:ID(HAPLOTYPE)' , 'name' , 'loci:LABEL' , 'frequency:DOUBLE[]' ]
363
- node_file = csvdir + '/nodes.csv'
372
+ node_file = csvdir + conf . get ( "node_csv_file" )
364
373
with open (node_file , mode = 'w' ) as csvfile :
365
374
csv_writer = csv .writer (csvfile )
366
375
csv_writer .writerow (header )
@@ -373,7 +382,7 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
373
382
# #### Build Edges File
374
383
375
384
edgeheader = [':START_ID(HAPLOTYPE)' , ':END_ID(HAPLOTYPE)' , 'CP:DOUBLE[]' , ':TYPE' ]
376
- edge_file = csvdir + '/edges.csv'
385
+ edge_file = csvdir + conf . get ( "edges_csv_file" )
377
386
with open (edge_file , mode = 'w' ) as csvfile :
378
387
csv_writer = csv .writer (csvfile )
379
388
csv_writer .writerow (edgeheader )
@@ -396,7 +405,7 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
396
405
# #### Generate Top Links file
397
406
398
407
topheader = [':START_ID(HAPLOTYPE)' , ':END_ID(HAPLOTYPE)' , ':TYPE' ]
399
- top_links_file = csvdir + '/top_links.csv'
408
+ top_links_file = csvdir + conf . get ( "top_links_csv_file" )
400
409
with open (top_links_file , mode = 'w' ) as csvfile :
401
410
csv_writer = csv .writer (csvfile )
402
411
csv_writer .writerow (topheader )
@@ -412,7 +421,7 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
412
421
# #### Generate Info Node file
413
422
414
423
infonode_header = ['INFO_NODE_ID:ID(INFO_NODE)' , 'populations:STRING[]' , 'INFO_NODE:LABEL' ]
415
- top_links_file = csvdir + '/info_node.csv'
424
+ top_links_file = csvdir + conf . get ( "info_node_csv_file" )
416
425
with open (top_links_file , mode = 'w' ) as csvfile :
417
426
csv_writer = csv .writer (csvfile )
418
427
csv_writer .writerow (infonode_header )
0 commit comments