本文整理汇总了Python中dendropy.Tree.nodes方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.nodes方法的具体用法?Python Tree.nodes怎么用?Python Tree.nodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dendropy.Tree
的用法示例。
在下文中一共展示了Tree.nodes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: match_ancestors_across_models
# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import nodes [as 别名]
def match_ancestors_across_models(con):
"""This method fills data in the table AncestorsAcrossModels"""
cur = con.cursor()
modelids = get_phylo_modelids(con)
msaids = get_alignment_method_ids(con)
ancid_childrenids = {} # key = Ancestor ID, value = list of Taxa IDs
"""Pull the map of taxon names to IDs from the database.
We'll access this information a lot, so let's save it in a separate hashtable
rather than repeatedly querying the databse."""
taxonname_id = {}
sql = "select id, shortname from Taxa"
cur.execute(sql)
for ii in cur.fetchall():
id = ii[0]
name = ii[1]
taxonname_id[name] = id
for modelid in modelids:
for msaid in msaids:
sql = "select newick from AncestralCladogram where unsupportedmltreeid in (select id from UnsupportedMlPhylogenies where almethod=" + msaid.__str__(
) + " and phylomodelid=" + modelid.__str__() + ")"
cur.execute(sql)
xx = cur.fetchone()
if xx is None:
write_error(con, "I cannot find the ancestral Newick cladogram for almethod=" +
msaid.__str__() + " and phylomodelid=" + modelid.__str__())
cladonewick = xx[0].__str__()
t = Tree()
t.read_from_string(cladonewick, "newick")
for node in t.nodes():
if node.is_leaf() == False and node.level() > 0:
sql = "select id from Ancestors where name='Node" + node.label + \
"' and almethod=" + msaid.__str__() + " and phylomodel=" + modelid.__str__()
cur.execute(sql)
ancid = cur.fetchone()[0]
ancid_childrenids[ancid] = []
for l in node.leaf_iter():
# print "978:", l
taxonname = l.as_newick_string()
# print "980:", taxonname
taxonname = re.sub("'", "", taxonname)
ancid_childrenids[ancid].append(
taxonname_id[taxonname])
# key = Ancestor ID, value = list of other ancestor IDs with the same
# children.
ancid_matches = {}
for anc1 in ancid_childrenids:
ancid_matches[anc1] = []
mychildren = ancid_childrenids[anc1]
mychildren.sort()
for anc2 in ancid_childrenids:
if anc1 == anc2:
"""Skip the self comparison."""
continue
theirchildren = ancid_childrenids[anc2]
theirchildren.sort()
if mychildren == theirchildren:
ancid_matches[anc1].append(anc2)
sql = "delete from AncestorsAcrossModels"
cur.execute(sql)
con.commit()
for anc1 in ancid_matches:
for anc2 in ancid_matches[anc1]:
sql = "insert into AncestorsAcrossModels (ancid, same_ancid) values(" + anc1.__str__(
) + "," + anc2.__str__() + ")"
cur.execute(sql)
con.commit()