def bootstrap_worker(params): """Worker function to compute boostrap replicates of datasets and indiv. loci""" bootstrap_trees = [] rep, fullpth, oneliners = params pth, exe = os.path.split(fullpth) # first, resample w/ replacement/bootstrap across loci multilocus_bstrap = get_bootstraps(oneliners) # Resample w/ replacement/boostrap bases within loci bootstraps = get_bootstrap_replicates(multilocus_bstrap) for oneliner in bootstraps: args_dict, locus = split_oneliner(oneliner, default_model=True) phylip = oneliner_to_phylip(locus) phyml = Phyml(phylip, pth=pth, exe=exe) # run phyml. if no model, defaults to GTR # TOOD: Why do we need LnL? args_dict['lnL'], tree = phyml.run(args_dict['model']) #bootstrap_trees.append("tree '%s' = [&U] %s" % (make_tree_name(args_dict), tree)) bootstrap_trees.append('''%s\t"%s"''' % (rep, tree)) sys.stdout.write("[Info] {0} {1} bootstrap completed\n".format( strftime("%a, %d %b %Y %H:%M:%S", localtime()), args_dict['chrm'] ) ) sys.stdout.flush() return bootstrap_trees
def get_bootstrap_replicates(multilocus_bstrap): """Boostrap the bases of all alignments in a resampled population of alignments""" for locus in multilocus_bstrap: # split keys from alignments args_dict, locus = split_oneliner(locus) # convert alignments to arrays taxa, numpy_alignment = oneliner_to_array(locus.rstrip(';')) # transpose so we bootstrap by columns bases_by_col = np.column_stack(numpy_alignment) # bootstrap by columns shuffled = get_bootstraps(bases_by_col) # transpose back to rows of sequences shuffled = np.column_stack(shuffled) # convert back to oneliner oneliner = array_to_oneliner(taxa, shuffled) oneliner = "%s:%s" % (make_tree_name(args_dict), oneliner) yield oneliner
def bootstrap_worker(params): """Worker function to compute boostrap replicates of datasets and indiv. loci""" bootstrap_trees = [] rep, fullpth, oneliners = params pth, exe = os.path.split(fullpth) # first, resample w/ replacement/bootstrap across loci multilocus_bstrap = get_bootstraps(oneliners) # Resample w/ replacement/boostrap bases within loci bootstraps = get_bootstrap_replicates(multilocus_bstrap) for oneliner in bootstraps: args_dict, locus = split_oneliner(oneliner, default_model=True) phylip = oneliner_to_phylip(locus) phyml = Phyml(phylip, pth=pth, exe=exe) # run phyml. if no model, defaults to GTR # TOOD: Why do we need LnL? args_dict['lnL'], tree = phyml.run(args_dict['model']) #bootstrap_trees.append("tree '%s' = [&U] %s" % (make_tree_name(args_dict), tree)) bootstrap_trees.append('''%s\t"%s"''' % (rep, tree)) sys.stdout.write("[Info] {0} bootstrap completed\n".format( strftime("%a, %d %b %Y %H:%M:%S", localtime()))) sys.stdout.flush() return bootstrap_trees