def pll_task(alignment_file, partition_string, guidetree=None, threads=1, seed=PLL_RANDOM_SEED, frequencies=None, write_to_file=None): guidetree = True if guidetree is None else guidetree instance = pll(alignment_file, partition_string, guidetree, threads, seed) if frequencies is not None and len(frequencies) == instance.get_number_of_partitions(): for i in range(len(frequencies)): instance.set_frequencies(frequencies[i], i, False) instance.optimise_tree_search(True) result = pll_to_dict(instance) if write_to_file is not None: # attempt to write to file specified by write_to_file try: parameters = Parameters() parameters.construct_from_dict(result) with fileIO.fwriter(write_to_file, gz=True) as fl: parameters.write(fl) except: pass # fail silently return result
def pll_task(alignment_file, partition_string, guidetree=None, threads=1, seed=PLL_RANDOM_SEED, frequencies=None, write_to_file=None): guidetree = True if guidetree is None else guidetree instance = pll(alignment_file, partition_string, guidetree, threads, seed) if frequencies is not None and len( frequencies) == instance.get_number_of_partitions(): for i in range(len(frequencies)): instance.set_frequencies(frequencies[i], i, False) instance.optimise_tree_search(True) result = pll_to_dict(instance) if write_to_file is not None: # attempt to write to file specified by write_to_file try: parameters = Parameters() parameters.construct_from_dict(result) with fileIO.fwriter(write_to_file, gz=True) as fl: parameters.write(fl) except: pass # fail silently return result
return None try: ac, ag, at, cg, ct, gt = (float(x) for x in re.search(r'GTR rates\(ac ag at cg ct gt\) ([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)', s).groups()) except AttributeError: warnings.warn('Couldn\'t parse substitution rates from {}'.format(filename)) return None return { 'loglk': loglk, 'alpha': alpha, 'freqs': np.array([a, c, g, t]), 'rates': np.array([ [0 , ac, ag, at], [ac, 0 , cg, ct], [ag, cg, 0 , gt], [at, ct, gt, 0 ] ]) } if __name__ == '__main__': import argparse parser = argparse.ArgumentParser() parser.add_argument('-f', '--filename', type=str) parser.add_argument('-o', '--output', type=str) args = parser.parse_args() import json result = run_raxml_fast(args.filename) with fileIO.fwriter(args.output) as fl: json.dump(result, fl)
def write_concats(collection, ps, path, index, logger, method, fastest): concat_dir = get_dirs(path, index)['concdir'] if not os.path.exists(concat_dir): os.mkdir(concat_dir) # First concat is all records, no clustering outf = os.path.join(concat_dir, '1cl0.phy') outr = os.path.join(concat_dir, '1cl0.json') if not os.path.exists(outf): conc = collection.concatenate(range(len(collection))) al = conc.alignment al.write_alignment(outf, 'phylip', True) AlignIO.convert(outf, 'phylip-relaxed', '{}_'.format(outf), 'phylip-relaxed') os.system('mv {} {}'.format('{}_'.format(outf), outf)) if not os.path.exists(outr): al = treeCl.alignment.Alignment(outf, 'phylip', True) if al.is_dna(): if method == 'raxml': logger.info('Calculating fast raxml tree for dna alignment 1cl0.phy') result = run_raxml_fast(outf, fastest) else: logger.info('Calculating FastTree tree for dna alignment 1cl0.phy') result = run_fasttree(outf, True) else: if method == 'raxml': logger.info('Calculating fast raxml tree for protein alignment 1cl0.phy') result = run_raxml_fast(outf, 'PROTGAMMALG', fastest) else: logger.info('Calculating FastTree tree for protein alignment 1cl0.phy') result = run_fasttree(outf, False) with fileIO.fwriter(outr) as fl: json.dump(result, fl) # Now do rest of concats for ngrp, p in enumerate(ps, start=2): for i, grp in enumerate(p.get_membership()): outf = os.path.join(concat_dir, '{}cl{}.phy'.format(ngrp, i)) outr = os.path.join(concat_dir, '{}cl{}.json'.format(ngrp, i)) if not os.path.exists(outf): conc = collection.concatenate(grp) al = conc.alignment al.write_alignment(outf, 'phylip', True) AlignIO.convert(outf, 'phylip-relaxed', '{}_'.format(outf), 'phylip-relaxed') os.system('mv {} {}'.format('{}_'.format(outf), outf)) if not os.path.exists(outr): al = treeCl.alignment.Alignment(outf, 'phylip', True) if al.is_dna(): if method == 'raxml': logger.info('Calculating fast raxml tree for dna alignment {}cl{}.phy'.format(ngrp, i)) result = run_raxml_fast(outf, fastest) else: logger.info('Calculating FastTree tree for dna alignment {}cl{}.phy'.format(ngrp, i)) result = run_fasttree(outf, True) else: if method == 'raxml': logger.info('Calculating fast raxml tree for protein alignment {}cl{}.phy'.format(ngrp, i)) result = run_raxml_fast(outf, 'PROTGAMMALG', fastest) else: logger.info('Calculating FastTree tree for protein alignment {}cl{}.phy'.format(ngrp, i)) result = run_fasttree(outf, False) with fileIO.fwriter(outr) as fl: json.dump(result, fl)