all_random_ints = [] for iproc in range(args.n_procs): # have to generate these all at once, 'cause each of the subprocesses is going to reset its seed and god knows what happens to our seed at that point all_random_ints.append([random.randint(0, sys.maxint) for i in range(n_per_proc)]) for iproc in range(args.n_procs): proc = Process(target=make_events, args=(n_per_proc, iproc, all_random_ints[iproc])) proc.start() while len(active_children()) > 0: # print ' wait %s' % len(active_children()), sys.stdout.flush() time.sleep(1) utils.merge_csvs(args.outfname, [args.workdir + '/recombinator-' + str(iproc) + '/' + os.path.basename(args.outfname) for iproc in range(args.n_procs)], cleanup=(not args.no_clean)) if args.action == 'simulate' or args.action == 'generate-trees': if args.action == 'generate-trees': from treegenerator import TreeGenerator, Hist treegen = TreeGenerator(args, args.parameter_dir + '/mean-mute-freqs.csv') treegen.generate_trees(args.outfname) sys.exit(0) # if not args.no_clean: # os.rmdir(reco.workdir) from recombinator import Recombinator run_simulation(args) else: start = time.time() from partitiondriver import PartitionDriver random.seed(args.seed) args.queries = utils.get_arg_list(args.queries) args.reco_ids = utils.get_arg_list(args.reco_ids) args.n_max_per_region = utils.get_arg_list(args.n_max_per_region, intify=True) args.match_mismatch = utils.get_arg_list(args.match_mismatch, intify=True) args.annotation_clustering_thresholds = utils.get_arg_list(args.annotation_clustering_thresholds, floatify=True)
utils.merge_csvs(args.outfname, [args.workdir + '/recombinator-' + str(iproc) + '/' + os.path.basename(args.outfname) for iproc in range(args.n_procs)], cleanup=(not args.no_clean)) # ---------------------------------------------------------------------------------------- def make_events(args, n_events, iproc, random_ints): # NOTE all the different seeds! this sucks but is necessary reco = Recombinator(args, seed=args.seed+iproc, sublabel=str(iproc)) #, total_length_from_right=args.total_length_from_right) for ievt in range(n_events): # print ievt, # sys.stdout.flush() reco.combine(random_ints[ievt]) # ---------------------------------------------------------------------------------------- if args.action == 'simulate' or args.action == 'generate-trees': if args.action == 'generate-trees': from treegenerator import TreeGenerator, Hist treegen = TreeGenerator(args, args.parameter_dir + '/mean-mute-freqs.csv') treegen.generate_trees(self.args.outfname) sys.exit(0) # if not args.no_clean: # os.rmdir(reco.workdir) from recombinator import Recombinator run_simulation(args) else: from partitiondriver import PartitionDriver args.queries = utils.get_arg_list(args.queries, intify=False) args.reco_ids = utils.get_arg_list(args.reco_ids, intify=True) args.n_max_per_region = utils.get_arg_list(args.n_max_per_region) if len(args.n_max_per_region) != 3: raise Exception('ERROR n-max-per-region should be of the form \'x:y:z\', but I got' + str(args.n_max_per_region))