parser.add_argument('--ancestral', action='store_true', default=False, help='calculate ancestral sequences') parser.add_argument('--timetree', action='store_true', default=False, help='infer time stamped phylogeny') parser.add_argument('--confidence', action='store_true', default=False, help='estimate confidence intervals for node timing') parser.add_argument('--Tc', type=float, default=0.0, help='coalescence time scale measured in substitution rate units') parser.add_argument('--keeproot', action='store_true', default=False, help="don't reroot the tree") args = parser.parse_args() path = args.path date_fmt = '%Y-%m-%d' T = build_fasttree(ref_alignment(path), tree_newick(path)) #T = tree_newick(path) meta = read_sequence_meta_data(path) fields = ['branchlength', 'clade'] if args.timetree: tt = timetree(tree=T, aln=ref_alignment(path), confidence=args.confidence, seq_meta=meta, reroot=None if args.keeproot else 'best',Tc=args.Tc) T = tt.tree fields.extend(['mutations', 'mutation_length', 'num_date', 'clock_length']) if args.confidence: fields.append('num_date_confidence') elif args.ancestral: tt = ancestral_sequence_inference(tree=T, aln=ref_alignment(path)) T = tt.tree fields.extend(['mutations', 'mutation_length'])
start = time.time() write_out_variable_fasta(compress_seq, path, args.drm) end = time.time() print "Writing out variable sites took {}".format(str(end - start)) if args.iqmodel and not args.iqtree: print "Cannot specify model unless using IQTree. Model specification ignored." if args.vcf: treebuild_align = var_site_alignment(path) else: treebuild_align = ref_alignment(path) start = time.time() if args.raxml: T = build_raxml(treebuild_align, tree_newick(path), path, args.nthreads) elif args.iqtree: T = build_iqtree(treebuild_align, tree_newick(path), args.iqmodel, args.nthreads) else: #use fasttree - if add more options, put another check here T = build_fasttree(treebuild_align, tree_newick(path)) end = time.time() print "Building original tree took {}".format(str(end - start)) meta = read_sequence_meta_data(path) fields = ['branchlength', 'clade'] #Anything but a list of sequences to root by, shouldn't go as a "list". if len(args.roottype) == 1: args.roottype = args.roottype[0]
if __name__ == '__main__': parser = generic_argparse("Export precomputed data as auspice jsons") parser.add_argument( '--prefix', required=True, help= "prefix for json files that are passed on to auspice (e.g., zika.fasta)" ) parser.add_argument( '--reference', required=True, help="reference sequence needed for entropy feature export") args = parser.parse_args() path = args.path T = Phylo.read(tree_newick(path), 'newick') seq_meta = read_sequence_meta_data(path) tree_meta = read_tree_meta_data(path) attach_tree_meta_data(T, tree_meta) tree_layout(T) fields_to_export = tree_meta.values()[0].keys() + [ "tvalue", "yvalue", "xvalue", "attr", "muts", "aa_muts" ] tjson = tree_to_json(T.root, extra_attr=fields_to_export) write_json(tjson, tree_json(path, args.prefix)) export_sequence_json(T, path, args.prefix) export_diversity(path, args.prefix, args.reference)
return tt, alphabet if __name__ == '__main__': parser = generic_argparse("Infer ancestral states for a discrete character") parser.add_argument('--field', default='region', help='meta data field to perform discrete reconstruction on') parser.add_argument('--confidence',action="store_true", help='record the distribution of subleading mugration states') parser.add_argument('--vcf', action='store_true', default=False, help="sequence is in VCF format") args = parser.parse_args() path = args.path T = tree_newick(path) import time start = time.time() seq_meta = read_sequence_meta_data(path) tree_meta = read_tree_meta_data(path) end = time.time() print "Reading in meta files took {}".format(str(end-start)) start = time.time() tt, alphabet = mugration_inference(tree=T, seq_meta=seq_meta, field=args.field, confidence=args.confidence) end = time.time() print "Mugration took {}".format(str(end-start))