本文整理汇总了Python中ete3.Tree.get_ascii方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.get_ascii方法的具体用法?Python Tree.get_ascii怎么用?Python Tree.get_ascii使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete3.Tree
的用法示例。
在下文中一共展示了Tree.get_ascii方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_ascii [as 别名]
def test():
custom_functions = {"length":length}
pattern = """
(
len{@.children} > 2
,
len{set{{@.name|}}.intersection{set{{"hello"|"bye"}}}} > 0
){length{@.name} < 3 or @.name == "pasa"} and @.dist >= 0.5
;
"""
pattern = TreePattern(pattern, format=8)
print pattern
tree = Tree("((hello,(1,2,3)kk)pasa:1, NODE);", format=1)
print tree.get_ascii(attributes=["name", "dist"])
print "Pattern matches tree?:", pattern.find_match(tree, custom_functions)
tree = Tree("((hello,(1,2,3)kk)pasa:0.4, NODE);", format=1)
print tree.get_ascii(attributes=["name", "dist"])
print "Pattern matches tree?:", pattern.find_match(tree, custom_functions)
tree = Tree("(hello,(1,2,3)kk)pasa:1;", format=1)
print tree.get_ascii(attributes=["name", "dist"])
print "Pattern matches tree?:", pattern.find_match(tree, custom_functions)
tree = Tree("((bye,(1,2,3)kk)none:1, NODE);", format=1)
print tree.get_ascii(attributes=["name", "dist"])
print "Pattern matches tree?:", pattern.find_match(tree, custom_functions)
tree = Tree("((bye,(1,2,3)kk)y:1, NODE);", format=1)
print tree.get_ascii(attributes=["name", "dist"])
print "Pattern matches tree?:", pattern.find_match(tree, custom_functions)
示例2: ete_print
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_ascii [as 别名]
def ete_print(self):
""" Pretty print.
TODO Debug and document better for case USE_ETE3 == False
"""
if Cfg.USE_ETE3:
t = EteTree(self.ete_str(), format=1)
print(t.get_ascii(show_internal=True))
else:
return str(self)
示例3: Tree
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_ascii [as 别名]
from ete3 import Tree
t = Tree('((((H,K)D,(F,I)G)B,E)A,((L,(N,Q)O)J,(P,S)M)C)X;', format=1)
print t.get_ascii(show_internal=True)
#print rooted_tree
示例4: len
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_ascii [as 别名]
else: # for child
#### search the parent node by parent_id
node_cur = root.search_nodes(name=str(parent_id))
# there should be only one parent node
if len(node_cur) == 1:
#### set child with its id
node_cur = node_cur[0].add_child(name=str(cell_id))
#### set duration
node_cur.add_feature("dist", time_duration)
# set node style
node_cur.set_style(ns)
# set node name to face
nameFace = TextFace(node_cur.name)
nameFace.fgcolor = "white"
nameFace.fsize = 15
nameFace.background.color = "green"
node_cur.add_face(nameFace, column=1, position="branch-bottom")
else:
raise RuntimeError("the cell id should be unique!")
#node = root.search_nodes(name=str(5))
#node[0].add_feature("dist", 1.5)
print root.get_ascii()
root.show(tree_style=ts)
示例5: outgroup
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_ascii [as 别名]
parser.add_argument(
'--verbose', action='store_true',
help=('Print information about the outgroup (if any) taxa to standard '
'error'))
args = parser.parse_args()
tree = Tree(args.treeFile.read())
if args.outgroupRegex:
from re import compile
regex = compile(args.outgroupRegex)
taxa = [leaf.name for leaf in tree.iter_leaves() if regex.match(leaf.name)]
if taxa:
ca = tree.get_common_ancestor(taxa)
if args.verbose:
print('Taxa for outgroup:', taxa, file=sys.stderr)
print('Common ancestor:', ca.name, file=sys.stderr)
print('Common ancestor is tree:', tree == ca, file=sys.stderr)
if len(taxa) == 1:
tree.set_outgroup(tree & taxa[0])
else:
if ca == tree:
tree.set_outgroup(tree.get_midpoint_outgroup())
else:
tree.set_outgroup(tree.get_common_ancestor(taxa))
print(tree.get_ascii())
示例6: main
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_ascii [as 别名]
def main():
random.seed()
#Open the files
trainingFile = open("data/training.txt","r")
testFile = open("data/test.txt", "r")
trainingExamples = []
testExamples = []
#Read eaxmaples from files
for line in trainingFile:
trainingExamples.append(line.split())
for line in testFile:
testExamples.append(line.split())
#Convert 2 to 0 in examples and make the values integers
for i in xrange(0, len(trainingExamples)):
for j in xrange(0, len(trainingExamples[0])):
if trainingExamples[i][j] == '1':
trainingExamples[i][j] = 1
else:
trainingExamples[i][j] = 0
for i in xrange(0, len(testExamples)):
for j in xrange(0, len(testExamples[0])):
if testExamples[i][j] == '1':
testExamples[i][j] = 1
else:
testExamples[i][j] = 0
#Create the attrbutes 0 to 6
attributes = [x for x in range(0, len(trainingExamples[0])-1)]
#Create deep copy in order for training with random Importance
random_attributes = copy.deepcopy(attributes)
#Close files
trainingFile.close()
testFile.close()
#Train two trees, one with regular Importance and one with random Importance
tree = train(trainingExamples, attributes)
random_tree = train(trainingExamples, random_attributes, True)
#Test the trees
accuracy = test(tree, testExamples)
random_accuracy = test(random_tree, testExamples)
print accuracy
print random_accuracy
#Visualise the trees
s = print_tree(tree)
s = s[:-1]
s += ';'
print s
try:
t = Tree(s, format=1)
print t.get_ascii(show_internal=True)
except NameError as e:
pass
r = print_tree(random_tree)
r = r[:-1]
r += ';'
print r
try:
rt = Tree(r, format=1)
print rt.get_ascii(show_internal=True)
except NameError as e:
pass
示例7: run
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import get_ascii [as 别名]
def run(args):
if args.text_mode:
from ete3 import Tree
for tindex, tfile in enumerate(args.src_tree_iterator):
#print tfile
if args.raxml:
nw = re.sub(":(\d+\.\d+)\[(\d+)\]", ":\\1[&&NHX:support=\\2]", open(tfile).read())
t = Tree(nw)
else:
t = Tree(tfile)
print(t.get_ascii(show_internal=args.show_internal_names,
attributes=args.show_attributes))
return
import random
import re
import colorsys
from collections import defaultdict
from ete3 import (Tree, PhyloTree, TextFace, RectFace, faces, TreeStyle,
add_face_to_node, random_color)
global FACES
if args.face:
FACES = parse_faces(args.face)
else:
FACES = []
# VISUALIZATION
ts = TreeStyle()
ts.mode = args.mode
ts.show_leaf_name = True
ts.tree_width = args.tree_width
for f in FACES:
if f["value"] == "@name":
ts.show_leaf_name = False
break
if args.as_ncbi:
ts.show_leaf_name = False
FACES.extend(parse_faces(
['value:@sci_name, size:10, fstyle:italic',
'value:@taxid, color:grey, size:6, format:" - %s"',
'value:@sci_name, color:steelblue, size:7, pos:b-top, nodetype:internal',
'value:@rank, color:indianred, size:6, pos:b-bottom, nodetype:internal',
]))
if args.alg:
FACES.extend(parse_faces(
['value:@sequence, size:10, pos:aligned, ftype:%s' %args.alg_type]
))
if args.heatmap:
FACES.extend(parse_faces(
['value:@name, size:10, pos:aligned, ftype:heatmap']
))
if args.bubbles:
for bubble in args.bubbles:
FACES.extend(parse_faces(
['value:@%s, pos:float, ftype:bubble, opacity:0.4' %bubble,
]))
ts.branch_vertical_margin = args.branch_separation
if args.show_support:
ts.show_branch_support = True
if args.show_branch_length:
ts.show_branch_length = True
if args.force_topology:
ts.force_topology = True
ts.layout_fn = lambda x: None
for tindex, tfile in enumerate(args.src_tree_iterator):
#print tfile
if args.raxml:
nw = re.sub(":(\d+\.\d+)\[(\d+)\]", ":\\1[&&NHX:support=\\2]", open(tfile).read())
t = PhyloTree(nw)
else:
t = PhyloTree(tfile)
if args.alg:
t.link_to_alignment(args.alg, alg_format=args.alg_format)
if args.heatmap:
DEFAULT_COLOR_SATURATION = 0.3
BASE_LIGHTNESS = 0.7
def gradient_color(value, max_value, saturation=0.5, hue=0.1):
def rgb2hex(rgb):
return '#%02x%02x%02x' % rgb
def hls2hex(h, l, s):
return rgb2hex( tuple([int(x*255) for x in colorsys.hls_to_rgb(h, l, s)]))
lightness = 1 - (value * BASE_LIGHTNESS) / max_value
return hls2hex(hue, lightness, DEFAULT_COLOR_SATURATION)
#.........这里部分代码省略.........