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


Python Tree.get_from_string方法代码示例

本文整理汇总了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
开发者ID:malagori,项目名称:PhyloGenClust,代码行数:10,代码来源:wrappers.py

示例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..."
开发者ID:malagori,项目名称:PhyloGenClust,代码行数:43,代码来源:wrappers.py

示例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
开发者ID:JudoWill,项目名称:LinkageAnalysis,代码行数:24,代码来源:TreeUtils.py

示例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():
开发者ID:pomeranz,项目名称:tree_stats,代码行数:33,代码来源:prepare_fubar.py

示例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))
开发者ID:czli,项目名称:Canopy,代码行数:8,代码来源:tree.py


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