sp_node.add_child(n) sp_node.add_child(connector) sp_node.add_feature("collapse_subspecies", "1") if args.show_tree: t.show() print "\n\n ===== Newick files saved as 'your_taxa_query.*' ===== " t.write(format=9, outfile="your_ncbi_query.nw") t.write(format=8, outfile="your_ncbi_query.named.nw") t.write(format=9, features=[ "taxid", "name", "rank", "bgcolor", "sci_name", "collapse_subspecies" ], outfile="your_ncbi_query.extended.nw") for i in t.iter_leaves(): i.name = i.taxid t.write(format=9, outfile="your_ncbi_query.taxids.nw") if all_taxids and reftree: translator = get_taxid_translator(all_taxids) for n in reftree.iter_leaves(): n.add_features(taxid=n.name) n.add_features(cool_name=translator.get(int(n.name), n.name)) lineage = get_sp_lineage(n.taxid) named_lineage = '|'.join(translate_to_names(lineage)) n.add_features(ncbi_track=named_lineage) print reftree.write(features=["taxid", "cool_name", "ncbi_track"])
#seqB MAEIPDATIQQFMALTNVSHNIAVQY--EFGDLNEALNSYYAYQTDDQKDRREEAH # # The associated alignment can be changed at any time t.link_to_alignment(alignment=iphylip_txt, alg_format="iphylip") # Let's check that sequences have changed print "These are the nodes and its re-linked sequences:" for leaf in t.iter_leaves(): print leaf.name, leaf.sequence #seqD MAEAPDETIQQFMALTNVSHNIAVQYLSEFGDLNEAL--------------REEAHQ----------FMALTNVSH #seqC MAEIPDATIQ---ALTNVSHNIAVQYLSEFGDLNEALNSYYASQTDDQPDRREEAHQFMALTNVSH---------- #seqA MAEIPDETIQQFMALT---HNIAVQYLSEFGDLNEALNSYYASQTDDIKDRREEAHQFMALTNVSHQFMALTNVSH #seqB MAEIPDATIQQFMALTNVSHNIAVQY--EFGDLNEALNSYYAYQTDDQKDRREEAHQFMALTNVSH---------- # # The sequence attribute is considered as node feature, so you can # even include sequences in your extended newick format! print t.write(features=["sequence"], format=9) # # # (((seqA[&&NHX:sequence=MAEIPDETIQQFMALT---HNIAVQYLSEFGDLNEALNSYYASQTDDIKDRREEAHQF # MALTNVSHQFMALTNVSH],seqB[&&NHX:sequence=MAEIPDATIQQFMALTNVSHNIAVQY--EFGDLNEALNSY # YAYQTDDQKDRREEAHQFMALTNVSH----------]),seqC[&&NHX:sequence=MAEIPDATIQ---ALTNVSHNIA # VQYLSEFGDLNEALNSYYASQTDDQPDRREEAHQFMALTNVSH----------]),seqD[&&NHX:sequence=MAEAPD # ETIQQFMALTNVSHNIAVQYLSEFGDLNEAL--------------REEAHQ----------FMALTNVSH]); # # And yes, you can save this newick text and reload it into a PhyloTree instance. sametree = PhyloTree(t.write(features=["sequence"])) print "Recovered tree with sequence features:" print sametree # # /-seqA # /--------|
SPECIES_NAME_POS = args.species_field SPECIES_NAME_DELIMITER = args.species_delimiter # load a phylomeDB Tree provided as a newick file in the command line t = PhyloTree(newick, sp_naming_function=extract_spname) if args.root: if len(args.root) > 1: outgroup = t.get_common_ancestor(args.root) else: outgroup = t & args.root[0] t.set_outgroup(outgroup) if not args.skip_ortholog_detection: # detect speciation and duplication events using the species overlap # algorithm used in phylomeDB t.get_descendant_evol_events() if args.ascii: print t.get_ascii(attributes=[args.evoltype_attr, "name"], show_internal=True) if args.newick: print t.write(features=[args.evoltype_attr], format_root_node=True) if args.show: t.show() export_as_orthoXML(t, args.database, args.evoltype_attr)
for n in bellow: n.detach() n.name = n.name + "{%s}" %n.rank sp_node.add_child(n) sp_node.add_child(connector) sp_node.add_feature("collapse_subspecies", "1") if args.show_tree: t.show() print "\n\n ===== Newick files saved as 'your_taxa_query.*' ===== " t.write(format=9, outfile="your_ncbi_query.nw") t.write(format=8, outfile="your_ncbi_query.named.nw") t.write(format=9, features=["taxid", "name", "rank", "bgcolor", "sci_name", "collapse_subspecies"], outfile="your_ncbi_query.extended.nw") for i in t.iter_leaves(): i.name = i.taxid t.write(format=9, outfile="your_ncbi_query.taxids.nw") if all_taxids and reftree: translator = get_taxid_translator(all_taxids) for n in reftree.iter_leaves(): n.add_features(taxid=n.name) n.add_features(cool_name = translator.get(int(n.name), n.name)) lineage = get_sp_lineage(n.taxid) named_lineage = '|'.join(translate_to_names(lineage)) n.add_features(ncbi_track=named_lineage) print reftree.write(features=["taxid", "cool_name", "ncbi_track"])