当前位置: 首页>>代码示例>>Python>>正文


Python Tree.get_distance方法代码示例

本文整理汇总了Python中ete3.Tree.get_distance方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.get_distance方法的具体用法?Python Tree.get_distance怎么用?Python Tree.get_distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ete3.Tree的用法示例。


在下文中一共展示了Tree.get_distance方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sum

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_distance [as 别名]
    if a == b:
        return 0.0
    try:
        return matrix[(a, b)]
    except KeyError:
        return matrix[(b, a)]

for tip_a, tip_b in itertools.permutations(lineages.keys(), 2):
    d = sum([n.dist for n in lineages[tip_a] ^ lineages[tip_b]])
    matrix[(tip_a, tip_b)] = d
    #if len(matrix) % 10000 == 0:
    #    print >>sys.stderr, len(matrix)

leaves = t.get_leaf_names()
print '\t'.join(['#names'] + leaves)
for tip_a in leaves:
    row = [tip_a]
    for tip_b in leaves:
        row.append(get_dist(tip_a, tip_b))
    print '\t'.join(map(str, row))


# test

import random
s = random.sample(matrix.keys(), 1000)
for a,b in s:
    d0 = get_dist(a, b)
    d1 = t.get_distance(a, b)
    if round(d0, 8) != round(d1, 8):
        print >>sys.stderr, a, b, d0, d1
开发者ID:linsalrob,项目名称:EdwardsLab,代码行数:33,代码来源:dist_matrix.py

示例2: str

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_distance [as 别名]
            ca = tree.get_common_ancestor(eukaryote_seqs)
            print sys.argv[1] + "\tEuks monophyletic\t" + str(len(eukaryote_seqs)) + "\t" + str(ca.support) 
        elif answer[0] == False:
            mono_groups = []
            target_group = ''
            for node in tree.get_monophyletic(values=['Eukaryote'], target_attr="domain"):
                if target_leaf in node:
                    target_group = node
                else:
                    mono_groups.append(node)
            size_target_group = len(target_group)
            #get distance
            shortest_distance = 999999999999999.0
            closest_other_group = ''
            for subtree in mono_groups:
                curr_distance = tree.get_distance(target_group, subtree, topology_only=True)
                if curr_distance < shortest_distance:
                    shortest_distance = curr_distance
                    closest_other_group = subtree
            #attempt to calculate distance on a version of the tree in which branches below some support threshold have been deleted
#            closest_leaves = []
 #           for leaf in closest_other_group:
  #              closest_leaves.append(leaf.name)
   #         target_leaves = []
    #        for leaf in target_group:
     #           target_leaves.append(leaf.name)
      #      collapsed_tree = tree
       #     for node in collapsed_tree:
        #        if node.support < 0.5:
         #           node.delete()
          #  target_ca = collapsed_tree.get_common_ancestor(target_leaves)
开发者ID:Tancata,项目名称:phylo,代码行数:33,代码来源:test_monophyly_microsporidia.py

示例3: distance

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_distance [as 别名]
#         |                             |         |
#         |                    /--------|          \-F
#         |                   |         |
#         |          /--------|          \-G
#         |         |         |
#          \--------|          \-H
#                   |
#                    \-E
#
# Locate some nodes
A = t&"A"
C = t&"C"
# Calculate distance from current node
print "The distance between A and C is",  A.get_distance("C")
# Calculate distance between two descendants of current node
print "The distance between A and C is",  t.get_distance("A","C")
# Calculate the toplogical distance (number of nodes in between)
print "The number of nodes between A and D is ",  \
    t.get_distance("A","D", topology_only=True)
# Calculate the farthest node from E within the whole structure
farthest, dist = (t&"E").get_farthest_node()
print "The farthest node from E is", farthest.name, "with dist=", dist
# Calculate the farthest node from E within the whole structure,
# regarding the number of nodes in between as distance value
# Note that the result is differnt.
farthest, dist = (t&"E").get_farthest_node(topology_only=True)
print "The farthest (topologically) node from E is", \
    farthest.name, "with", dist, "nodes in between"
# Calculate farthest node from an internal node
farthest, dist = t.get_farthest_node()
print "The farthest node from root is", farthest.name, "with dist=", dist
开发者ID:AlishaMechtley,项目名称:ete,代码行数:33,代码来源:get_distances_between_nodes.py

示例4: open

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_distance [as 别名]
		sfs[pop-1] += 1
		nIndsSFS += 1
	fn.write(leaf.name+"\t"+"\t".join(str(x) for x in sfs)+"\n")

f.close()
fn.close()
sys.stdout.write('S')

#======================================================#
# FORCE ULTRAMETRIC in the output tree, defined in reference to the furthest leaf
if maxNumberOfSpecies == -1: maxNumberOfSpecies = nTrueSpecies + 1
if force_ultrametric:
	if nTrueSpecies <= maxNumberOfSpecies:
		tree_dist = t.get_farthest_leaf()[1]
		for l in t:
			dst = t.get_distance(l)
			if dst != tree_dist:
				l.dist += tree_dist - dst
		sys.stdout.write('u')
	else:
		sys.stdout.write('\nERROR. Too many final species: will not force ultrametricity.\n')

#======================================================#
# EXPORT phylo
t.write(format=5, outfile=ophylo, dist_formatter='%0.20f')
## write the count of resultant species
f = open(ophylo, 'a')
f.write("\n"+str(nTrueSpecies)+"\n")
f.close()

if plot_trees:
开发者ID:sunyatin,项目名称:vanaprabhava,代码行数:33,代码来源:VPB.py

示例5: defaultdict

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_distance [as 别名]
for line in tt:
    target_taxa.append(line.rstrip())
tt.close()

#now read in a collection of trees, calc branch lengths over sample, summarise and print out
branch_lengths = defaultdict(list) #key = taxa, value = list of brlens
treefile = open(sys.argv[3])
for line in treefile:
    curr_tree = Tree(line.rstrip())
    root_node = curr_tree.get_common_ancestor(outgroups)
    if curr_tree != root_node:
        curr_tree.set_outgroup(root_node)
    print curr_tree
    #bundle = curr_tree.check_monophyly(values=outgroups,target_attr='name')
    #print bundle
    #if bundle[0] == False:
    #    continue
    #find common ancestor of the target taxa, and use this as the reference node for calculating branch lengths. This might not always be the measure you want!
    reference_node = curr_tree.get_common_ancestor(target_taxa)
    #if reference_node != curr_tree:
    #    curr_tree.set_outgroup(reference_node)
    #calc distance from root to each branch of interest
    for taxon in target_taxa:
        dist = curr_tree.get_distance(taxon, reference_node) 
        branch_lengths[taxon].append(dist)

#now compute the credible intervals of the branch length for each of the target taxa
for taxon in branch_lengths:
    mean, var, std = stats.bayes_mvs(branch_lengths[taxon], alpha=0.95)
    print taxon + "\t" + str(mean[0]) + "\t" + str(mean[1][0]) + "\t" + str(mean[1][1])
开发者ID:Tancata,项目名称:phylo,代码行数:32,代码来源:bayesian_relative_rates.py

示例6: str

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_distance [as 别名]
	no_n=re.search(r'_N\d+', line)
	if no_n:
		no_n_str= no_n.group()	
		no_n_str=re.sub('_N','',no_n_str)
		no_N_dict[acc_str]=no_n_str
	
log_file.write("The number of clusters are:" + str(cluster_cnt))
log_file.close()
cdhit_file.close()

#print "Tree from FastTree program is being used to calculate root to leaf distances..."
#Passing in the tree generated by FastTree
FastTree=Tree(args.input2)
#Getting the root of the tree
root=FastTree.get_tree_root()
#Loop through each leaf of the tree
for leaf in FastTree:
	#Convert 'leaf' to string to allow manipulation
	leaf_str=str(leaf)
	acc_nu=re.search(r'\w{2}\d+.\d{1}_\d{4}|\w{2}_\d+.\d{1}_\d{4}',leaf_str)
	acc_nu=str(acc_nu.group())
	acc_nu=re.sub('_\d{4}$','',acc_nu)
	rt_lf=FastTree.get_distance(root,leaf)
	#Make a dictionary using acc_nu as key 
	branlength_dict[acc_nu]=rt_lf
	#Using the generated dictionaries to print the relevant information to a tab delimited file
	tsv_file.write(acc_nu + "\t" + year_dict[acc_nu] + "\t" + str(rt_lf) + "\t" + clust_dict[acc_nu] + "\t" + no_N_dict[acc_nu] + "\n")
tsv_file.close


开发者ID:MarcNiebel,项目名称:GenRefSeq,代码行数:30,代码来源:Combo.py

示例7: distance

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_distance [as 别名]
#         |                             |         |
#         |                    /--------|          \-F
#         |                   |         |
#         |          /--------|          \-G
#         |         |         |
#          \--------|          \-H
#                   |
#                    \-E
#
# Locate some nodes
A = t & "A"
C = t & "C"
# Calculate distance from current node
print "The distance between A and C is", A.get_distance("C")
# Calculate distance between two descendants of current node
print "The distance between A and C is", t.get_distance("A", "C")
# Calculate the toplogical distance (number of nodes in between)
print "The number of nodes between A and D is ", t.get_distance("A", "D", topology_only=True)
# Calculate the farthest node from E within the whole structure
farthest, dist = (t & "E").get_farthest_node()
print "The farthest node from E is", farthest.name, "with dist=", dist
# Calculate the farthest node from E within the whole structure,
# regarding the number of nodes in between as distance value
# Note that the result is differnt.
farthest, dist = (t & "E").get_farthest_node(topology_only=True)
print "The farthest (topologically) node from E is", farthest.name, "with", dist, "nodes in between"
# Calculate farthest node from an internal node
farthest, dist = t.get_farthest_node()
print "The farthest node from root is is", farthest.name, "with dist=", dist
#
# The program results in the following information:
开发者ID:abdo3a,项目名称:ete,代码行数:33,代码来源:get_distances_between_nodes.py


注:本文中的ete3.Tree.get_distance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。