本文整理汇总了Python中dendropy.Tree.get_from_string方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.get_from_string方法的具体用法?Python Tree.get_from_string怎么用?Python Tree.get_from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dendropy.Tree
的用法示例。
在下文中一共展示了Tree.get_from_string方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: readTreeFromString
# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import get_from_string [as 别名]
def readTreeFromString(self, treeString):
'''
input: string containing newick tree
return Tree object
'''
myTree= Tree()
myTree= Tree.get_from_string( treeString, 'newick', annotations_as_nhx=True, extract_comment_metadata=True , suppress_annotations=False)
return myTree
示例2: WrapFastTreeRooted
# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import get_from_string [as 别名]
def WrapFastTreeRooted(self, sTree):
'''
WrapFastTreeRooted() function is a wrapper over the fasttree tool.
input: inputFile: sequences in seqboot output format (Phylip),
seqType : d (dna); p (protein)
n : Number of datasets,
output: Bifucated and rooted tree in newkick format to file
'''
cmd= self.Where('FastTree')
infile= os.path.join(self.work_dir, self.outFile)
if cmd != None:
print "--> Generating newick trees using fasttree begins..."
try:
fastreeCmdLine = FastTreeCommandline(cmd=cmd, input=infile, n=self.n, boot=100, nosupport=True, nome= True, seed= self.seedNum, quiet= True)
child = subprocess.Popen(str(fastreeCmdLine),stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=(sys.platform!="win32"))
j=1
with open(os.path.join(self.work_dir, str(self.coreId)+'batch.unrooted.ini'), 'w') as bwf:
bwf.write(os.path.abspath(sTree) + '\n')
for i in child.stdout:
outNewickFile= os.path.join(self.work_dir, str(j)+ "_ftree_coreId_" + str(self.coreId) +".newick")
bwf.write(outNewickFile+ '\n')
ftreeOutFile= outNewickFile
with open(ftreeOutFile, 'w') as wf:
tree = Tree.get_from_string(i, 'newick')
tree.resolve_polytomies(update_splits=False)
st=tree.as_string('newick')
#remove the extra strings
st='\"'+str(st)+'\"'
st=st.translate(None,'\'')
st=st.translate(None,'\"')
wf.write(st)
j += 1
except IOError, e:
print ("Class: Wrapper, Function: WrapFastTreeRooted(): %s " % e)
print "--> Tree generation done..."
示例3: group_sequences
# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import get_from_string [as 别名]
def group_sequences(tree_file, cutoff, excluded):
"""Loads a tree to find sequences which can be merged."""
with open(tree_file) as handle:
tree = Tree.get_from_string(handle.read(), schema = 'newick')
groups = []
done = set()
if excluded is not None:
groups.append(set(excluded))
done = set(excluded)
for t in tree.level_order_node_iter():
if t.edge.length >= cutoff:
lens = [x.edge.length >= cutoff for x in t.level_order_iter() if not x.is_leaf()]
if all(lens) or not any(lens) or t.is_leaf():
leafs = set([str(x.taxon) for x in t.leaf_nodes()])
groups.append(leafs-done)
done |= leafs
groups = [x for x in groups if x]
return groups
示例4: read_slr
# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import get_from_string [as 别名]
print f
dirname, basename = path.split(f)
input_name = basename.rpartition('.')[0]
input_core = input_name.rpartition('_')[0]
seqs = read_slr(open(f))
utils.check_dir(path.join(args.outdir, args.clade, basename[:2]))
out_fasta = path.abspath(path.join(args.outdir, args.clade, basename[:2], input_core+'.fa'))
SeqIO.write(seqs, open(out_fasta, 'w'), 'fasta')
with open(path.join(dirname, input_name+'.nwk')) as fl:
_ = fl.readline()
tree_string = fl.readline().rstrip()
tree = Tree.get_from_string(tree_string, 'newick')
#tree = Tree.get_from_path(path.join(dirname, input_name+'.nwk'), 'newick', preserve_underscores=True)
# rewrite the numbered tree back to a tree with ids.
# easy
fasta_file = open(f, 'r')
fasta = fasta_file.readlines()
aln_ids = {}
for index,line in enumerate(fasta,start=1):
if index%2 == 0:
aln_ids[(index)/2] = line.strip("\n")
#print line
#print (index)/2
for node in tree:
if node.is_leaf():
示例5: read_from_string
# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import get_from_string [as 别名]
def read_from_string(tree_str, schema="newick", taxon_set=None):
taxon = taxon_set
if taxon is None:
taxon = TaxonSet()
return PhylogeneticTree(Tree.get_from_string(tree_str, schema=schema, taxon_set=taxon))