1111
1212import sys
1313import os
14+
1415#sys.path.insert(0, os.path.join(".."))
1516
1617
@@ -168,10 +169,10 @@ def labels_for_grap(conf, full_loci,csvdir):
168169
169170 nodes_plan_b = list (set (nodes_plan_b ))
170171 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 :
172173 for item in nodes_plan_a :
173174 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 :
175176 for item in (nodes_plan_b + top_nodes_plan_b ):
176177 f .write ("%s\n " % item )
177178 #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
197198 # Configure
198199 ##############################################################################
199200 # 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+
202203
203204
204205 # Input file
@@ -218,6 +219,11 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
218219 with open (configuration_file ) as f :
219220 conf = json .load (f )
220221
222+ csvdir = conf .get ("graph_files_path" )
223+ pathlib .Path (csvdir ).mkdir (parents = True , exist_ok = True )
224+ if csvdir [- 1 ] != '/' :
225+ csvdir += '/'
226+
221227 pops = conf .get ("populations" )
222228 if em_pop :
223229 pops = em_pop
@@ -227,16 +233,19 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
227233 if freq_file == "default" :
228234 freq_file = os .path .dirname (os .path .realpath (__file__ )) + '/output/hpf.csv'
229235 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 :
236245 with open (pop_ratio_dir ) as f_count :
237246 for line in f_count :
238247 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 )
240249
241250
242251 # Display the configurations we are using
@@ -360,7 +369,7 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
360369 # #### Build Nodes file
361370
362371 header = ['haplotypeId:ID(HAPLOTYPE)' , 'name' , 'loci:LABEL' , 'frequency:DOUBLE[]' ]
363- node_file = csvdir + '/nodes.csv'
372+ node_file = csvdir + conf . get ( "node_csv_file" )
364373 with open (node_file , mode = 'w' ) as csvfile :
365374 csv_writer = csv .writer (csvfile )
366375 csv_writer .writerow (header )
@@ -373,7 +382,7 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
373382 # #### Build Edges File
374383
375384 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" )
377386 with open (edge_file , mode = 'w' ) as csvfile :
378387 csv_writer = csv .writer (csvfile )
379388 csv_writer .writerow (edgeheader )
@@ -396,7 +405,7 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
396405 # #### Generate Top Links file
397406
398407 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" )
400409 with open (top_links_file , mode = 'w' ) as csvfile :
401410 csv_writer = csv .writer (csvfile )
402411 csv_writer .writerow (topheader )
@@ -412,7 +421,7 @@ def generate_graph(config_file = "../../conf/minimal-configuration.json", em_pop
412421 # #### Generate Info Node file
413422
414423 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" )
416425 with open (top_links_file , mode = 'w' ) as csvfile :
417426 csv_writer = csv .writer (csvfile )
418427 csv_writer .writerow (infonode_header )
0 commit comments