def main():
    args = get_args()
    # read in phylip files
    alns = {}
    for f in glob.glob(os.path.join(args.input, '*.phy*')):
        alns[os.path.splitext(os.path.basename(f))[0]] = open(f, 'rU').read()
    # replicate our options for passing to map()
    opts = [args.phyml for i in range(len(alns))]
    # compute genetrees
    if args.run == 'genetrees' or args.run == 'both':
        sys.stdout.write("Running genetrees...\n\n")
        params = zip(alns.items(), opts)
        genetrees = mmap(genetree_worker, params)
        # write genetrees to output file
        outf = open(os.path.join(args.output, 'genetrees.tre'), 'w')
        for tree in genetrees:
            outf.write("%s\n" % (tree[2]))
        outf.close()
    # compute bootreps on genetrees from above
    if args.run == 'both':
        sys.stdout.write("Running boostraps of genetrees...\n")
        # get models for each locus based on genetrees in-memory
        models = dict([[tree[0], tree[1]] for tree in genetrees])
        boostrap_all_loci(args, models, alns)
    # compute bootreps on genetrees from a file
    if args.run == 'bootstraps':
        sys.stdout.write("Running boostraps...\n")
        # get models for each locus based on genetrees in genetree file
        models = get_models_from_genetrees(args.genetrees)
        boostrap_all_loci(args, models, alns)
def main():
    args = get_args()
    # read in phylip files
    alns = {}
    for f in glob.glob(os.path.join(args.input, '*.phy*')):
        alns[os.path.splitext(os.path.basename(f))[0]] = open(f, 'rU').read()
    # replicate our options for passing to map()
    opts = [args.phyml for i in range(len(alns))]
    # compute genetrees
    if args.run == 'genetrees' or args.run == 'both':
        sys.stdout.write("Running genetrees...\n\n")
        params = zip(alns.items(), opts)
        genetrees = mmap(genetree_worker, params)
        # write genetrees to output file
        outf = open(os.path.join(args.output, 'genetrees.tre'), 'w')
        for tree in genetrees:
            outf.write("%s\n" % (tree[2]))
        outf.close()
    # compute bootreps on genetrees from above
    if args.run == 'both':
        sys.stdout.write("Running bootstraps of genetrees...\n")
        # get models for each locus based on genetrees in-memory
        models = dict([[tree[0], tree[1]] for tree in genetrees])
        boostrap_all_loci(args, models, alns)
    # compute bootreps on genetrees from a file
    if args.run == 'bootstraps':
        sys.stdout.write("Running boostraps...\n")
        # get models for each locus based on genetrees in genetree file
        models = get_models_from_genetrees(args.genetrees)
        boostrap_all_loci(args, models, alns)
def boostrap_all_loci(args, models, alns):
    """Compute trees from bootstrap replicates of a dataset"""
    oneliners = [phylip_to_oneliner(phylip, locus, models[locus]) for locus, phylip in alns.iteritems()]
    # for every rep in boostraps, map loci onto worker that will
    # bootstrap, run phyml, and return bootstrap trees
    params = generate_bootreps(args.bootreps, args.phyml, oneliners)
    bootreps = mmap(bootstrap_worker, params)
    # write
    outname = "%s-bootreps.tree" % (args.bootreps)
    outf = open(os.path.join(args.output, outname), "w")
    for bootrep in bootreps:
        for tree in bootrep:
            outf.write("%s\n" % (tree))
def boostrap_all_loci(args, models, alns):
    """Compute trees from bootstrap replicates of a dataset"""
    oneliners = [phylip_to_oneliner(phylip, locus, models[locus]) \
                for locus, phylip in alns.iteritems()]
    # for every rep in boostraps, map loci onto worker that will
    # bootstrap, run phyml, and return bootstrap trees
    params = generate_bootreps(args.bootreps, args.phyml, oneliners)
    bootreps = mmap(bootstrap_worker, params)
    # write
    outname = "%s-bootreps.tree" % (args.bootreps)
    outf = open(os.path.join(args.output, outname), 'w')
    for bootrep in bootreps:
        for tree in bootrep:
            outf.write("%s\n" % (tree))
Beispiel #5
0
def main():
    args = get_args()
    # iterate over files reading contents into a list that we'll pass to sate
    loci = get_fasta_dict(args)
    opts = [[args.sate, args.cfg] for i in range(len(loci))]
    params = zip(loci.items(), opts)
    sys.stdout.write('Aligning')
    # pass to map or Pool.map or mpimap
    alignments = mmap(worker, params)
    for data in alignments:
        name, aln = data
        out_file = os.path.join(args.output, name) + '.aln'
        out = open(out_file, 'w')
        out.write(aln)
        out.close()
Beispiel #6
0
def main():
    args = get_args()
    # iterate over files reading contents into a list that we'll pass to sate
    loci = get_fasta_dict(args)
    opts = [[args.sate, args.cfg] for i in range(len(loci))]
    params = zip(loci.items(), opts)
    sys.stdout.write("Aligning")
    # pass to map or Pool.map or mpimap
    alignments = mmap(worker, params)
    for data in alignments:
        name, aln = data
        out_file = os.path.join(args.output, name) + ".aln"
        out = open(out_file, "w")
        out.write(aln)
        out.close()