本文整理汇总了Python中cogent.LoadTree.getNodeMatchingName方法的典型用法代码示例。如果您正苦于以下问题:Python LoadTree.getNodeMatchingName方法的具体用法?Python LoadTree.getNodeMatchingName怎么用?Python LoadTree.getNodeMatchingName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cogent.LoadTree
的用法示例。
在下文中一共展示了LoadTree.getNodeMatchingName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_params_merge
# 需要导入模块: from cogent import LoadTree [as 别名]
# 或者: from cogent.LoadTree import getNodeMatchingName [as 别名]
def test_params_merge(self):
t = LoadTree(treestring='((((a,b)ab,c)abc),d)')
for (label, length, beta) in [('a',1, 20),('b',3,2.0),('ab',4,5.0),]:
t.getNodeMatchingName(label).params = {'length':length, 'beta':beta}
t = t.getSubTree(['b', 'c', 'd'])
self.assertEqual(t.getNodeMatchingName('b').params,
{'length':7, 'beta':float(2*3+4*5)/(3+4)})
self.assertRaises(ValueError, t.getSubTree, ['b','c','xxx'])
self.assertEqual(str(t.getSubTree(['b','c','xxx'],ignore_missing=True)),
'(b:7,c)root;')
示例2: MatchNodes
# 需要导入模块: from cogent import LoadTree [as 别名]
# 或者: from cogent.LoadTree import getNodeMatchingName [as 别名]
def MatchNodes(self):
#print "YAY"
self.correctForFastMLNameChanges() #performs the correction on the output string if necessary
#print "NAY"
TerminiStringToNodeName_D = {}
#a termini string is prepared for each internal node, that is, all termini under the internal node sorted an placed into a single string
for NodeKey in self.UpperKey_L:
TerminiStringToNodeName_D['-'.join(sorted(self.Nodes_D[NodeKey]['terminal']))] = NodeKey
#prepares a cogent tree object for the fastML output
FH = getInputTempFile(self.FastMLOutputTreeString)
FastMLCogentTree = LoadTree(FH.name)
self.FastMLToOriginalMatchedNodes_D = {}
#for each cogent node in the FastML cogent tree
for FastMLCogentNodeKey in FastMLCogentTree.getNodeNames():
#a termini string is prepared for the fastML node
FastMLCogentNode = FastMLCogentTree.getNodeMatchingName(FastMLCogentNodeKey)
FastMLTermini_L = [tip.Name for tip in FastMLCogentNode.iterTips()]
#if it has more than 0 termini under the node
if len(FastMLTermini_L) > 0:
#A fastML termini string is prepared, and this termini string will be the same termini string as the equivalent cogent node
FastMLTerminiString = '-'.join(sorted(FastMLTermini_L))
self.FastMLToOriginalMatchedNodes_D[FastMLCogentNodeKey] = TerminiStringToNodeName_D[FastMLTerminiString]
#if it has no termini under it, then the node itself is a terminus and has the same name in FastML and Cogent
else:
self.FastMLToOriginalMatchedNodes_D[FastMLCogentNodeKey] = FastMLCogentNodeKey
示例3: test_getsetParamValue
# 需要导入模块: from cogent import LoadTree [as 别名]
# 或者: from cogent.LoadTree import getNodeMatchingName [as 别名]
def test_getsetParamValue(self):
"""test getting, setting of param values"""
t = LoadTree(treestring='((((a:.2,b:.3)ab:.1,c:.3)abc:.4),d:.6)')
self.assertEqual(t.getParamValue('length', 'ab'), 0.1, 2)
t.setParamValue('zz', 'ab', 4.321)
node = t.getNodeMatchingName('ab')
self.assertEqual(4.321, node.params['zz'], 4)
示例4: Parsed
# 需要导入模块: from cogent import LoadTree [as 别名]
# 或者: from cogent.LoadTree import getNodeMatchingName [as 别名]
#.........这里部分代码省略.........
"Removes internal node names so that FastML adds its own naming convention"
def FixUpFileForFastML(self, CogentTree):
#gets the tree string for the cogent object
TreeString = CogentTree.getNewick(with_distances=True).replace("'","")
i = 0
NotThroughTheString = True
#while loop moves one space along tree string until it gets to the end
while NotThroughTheString:
#when a close bracket is found, it signifies the end of an internal node
if TreeString[i] == ")":
if TreeString[i+1] == ";":
pass
else:
#tree string replaces the name of the internal node with nothing
lengthToColon = len(re.compile("^(.+?)[:;]").search(TreeString[i:]).group(1)) - 1
TreeString = TreeString[:i+1]+ TreeString[i+lengthToColon+1:]
#check to end while loop
if i == len(TreeString) - 1:
NotThroughTheString = False
i += 1
return TreeString
"Prepares simple FastaFile to be given to FastML"
def getTempFASTAFile(self):
retString_L = []
#FastaFile will have the sequence "GREAT" for each terminal sequence
for LeafKey in self.LeafKey_L:
retString_L.append(">"+LeafKey)
retString_L.append("GREAT")
return '\n'.join(retString_L)
"Corrects for instances where FastML anomalously renames terminal nodes"
def correctForFastMLNameChanges(self):
#gets lists of terminal names in the FastML input and output strings (in the same order)
FastMLInputNames = [re.compile("^(.+?):").search(TaxString).group(1) for TaxString in re.findall("[A-Za-z0-9_./]+:[.0-9]+",self.FastMLInputTreeString)]
#print FastMLInputNames
FastMLOutputNames = [re.compile("^(.+?):").search(TaxString).group(1) for TaxString in re.findall("[A-Za-z0-9_./]+:[.0-9]+",self.FastMLOutputTreeString)]
FastMLOutputNames = [Name for Name in FastMLOutputNames if re.compile("^N[0-9]+$").search(Name) == None]
#when equivalent node names are not the same, then the output string node name is renamed according to the input string node name
for i in range(0,len(FastMLInputNames)):
if FastMLInputNames[i] != FastMLOutputNames[i]:
self.FastMLOutputTreeString = re.sub("([,\(\)])%s:" % (FastMLOutputNames[i]) , r"\1%s:" % (FastMLInputNames[i]) , self.FastMLOutputTreeString)
"Matches original (cogent) node names with how the nodes are named in FastML"
def MatchNodes(self):
#print "YAY"
self.correctForFastMLNameChanges() #performs the correction on the output string if necessary
#print "NAY"
TerminiStringToNodeName_D = {}
#a termini string is prepared for each internal node, that is, all termini under the internal node sorted an placed into a single string
for NodeKey in self.UpperKey_L:
TerminiStringToNodeName_D['-'.join(sorted(self.Nodes_D[NodeKey]['terminal']))] = NodeKey
#prepares a cogent tree object for the fastML output
FH = getInputTempFile(self.FastMLOutputTreeString)
FastMLCogentTree = LoadTree(FH.name)
self.FastMLToOriginalMatchedNodes_D = {}
#for each cogent node in the FastML cogent tree
for FastMLCogentNodeKey in FastMLCogentTree.getNodeNames():
#a termini string is prepared for the fastML node
FastMLCogentNode = FastMLCogentTree.getNodeMatchingName(FastMLCogentNodeKey)
FastMLTermini_L = [tip.Name for tip in FastMLCogentNode.iterTips()]
#if it has more than 0 termini under the node
if len(FastMLTermini_L) > 0:
#A fastML termini string is prepared, and this termini string will be the same termini string as the equivalent cogent node
FastMLTerminiString = '-'.join(sorted(FastMLTermini_L))
self.FastMLToOriginalMatchedNodes_D[FastMLCogentNodeKey] = TerminiStringToNodeName_D[FastMLTerminiString]
#if it has no termini under it, then the node itself is a terminus and has the same name in FastML and Cogent
else:
self.FastMLToOriginalMatchedNodes_D[FastMLCogentNodeKey] = FastMLCogentNodeKey
"Sets branch lengths of each node"
def setBranchLengths(self):
self.BranchLength_D = {}
#gets the distance between a node and its immediate ancestor
for NodeNameKey in self.NodeKey_L:
HigherNode = self.CogentTree.getNodeMatchingName(NodeNameKey)
for ImmediateNeighbourNodeNameKey in self.Nodes_D[NodeNameKey]['immediate']:
LowerNode = self.CogentTree.getNodeMatchingName(ImmediateNeighbourNodeNameKey)
self.BranchLength_D[ImmediateNeighbourNodeNameKey] = HigherNode.distance(LowerNode)