本文整理汇总了Python中tree.Tree.taxNames方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.taxNames方法的具体用法?Python Tree.taxNames怎么用?Python Tree.taxNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Tree
的用法示例。
在下文中一共展示了Tree.taxNames方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _getMrBayesSampleTree
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import taxNames [as 别名]
def _getMrBayesSampleTree(self, sampNum):
savedDoFastNextTok = var.nexus_doFastNextTok
var.nexus_doFastNextTok = False
tLine = self.tLines[sampNum]
if self.verbose >= 3:
print tLine
f = cStringIO.StringIO(tLine)
t = Tree()
t.parseNexus(f, translationHash=self.translationHash,
doModelComments=self.tree.model.nParts) # doModelComments is nParts
var.nexus_doFastNextTok = savedDoFastNextTok
t.taxNames = self.tree.taxNames
for n in t.iterLeavesNoRoot():
n.seqNum = t.taxNames.index(n.name)
t.model = copy.deepcopy(self.model)
pLine = self.pLines[sampNum]
if self.verbose >= 3:
print pLine
splitPLine = pLine.split()
pGenNum = int(splitPLine[0])
splitTName = t.name.split('.')
tGenNum = int(splitTName[1])
if tGenNum != pGenNum:
raise P4Error(
"something wrong. tGenNum=%i, pGenNum=%i" % (tGenNum, pGenNum))
if self.verbose >= 2:
print "(zero-based) sample %i is gen %i" % (sampNum, tGenNum)
# t.model.dump()
splIndx = 3 # but could be Gen LnL LnPr TL ...
while splIndx < self.nPrams:
pNum = 0
# print "splIndx = %i, pramsHeader = %s" % (splIndx,
# self.pramsHeader[splIndx])
if self.pramsHeader[splIndx].startswith('r(A<->C)'):
if self.tree.model.nParts > 1:
try:
splitPramHeader = self.pramsHeader[
splIndx].split('{')[1][:-1]
pNum = int(splitPramHeader)
pNum -= 1
except:
raise P4Error("could not get the part number")
thisSum = 0.0
for i in range(6):
theFloat = float(splitPLine[splIndx])
t.model.parts[pNum].rMatrices[0].val[i] = theFloat
thisSum += theFloat
splIndx += 1
factor = 1.0 / thisSum # must sum to one
for i in range(6):
t.model.parts[pNum].rMatrices[0].val[i] *= factor
elif self.pramsHeader[splIndx].startswith('pi(A)'):
if self.tree.model.nParts > 1:
try:
splitPramHeader = self.pramsHeader[
splIndx].split('{')[1][:-1]
pNum = int(splitPramHeader)
pNum -= 1
except:
raise P4Error("could not get the part number")
thisSum = 0.0
for i in range(4):
theFloat = float(splitPLine[splIndx])
t.model.parts[pNum].comps[0].val[i] = theFloat
thisSum += theFloat
splIndx += 1
factor = 1.0 / thisSum # must sum to one
for i in range(4):
t.model.parts[pNum].comps[0].val[i] *= factor
elif self.pramsHeader[splIndx].startswith('alpha'):
if self.tree.model.nParts > 1:
try:
splitPramHeader = self.pramsHeader[
splIndx].split('{')[1][:-1]
pNum = int(splitPramHeader)
pNum -= 1
except:
raise P4Error("could not get the part number")
# print "got pNum = %i" % pNum
# print "got splitPLine[%i] = %s" % (splIndx,
# splitPLine[splIndx])
t.model.parts[pNum].gdasrvs[0].val[
0] = float(splitPLine[splIndx])
splIndx += 1
elif self.pramsHeader[splIndx].startswith('pinvar'):
if self.tree.model.nParts > 1:
try:
splitPramHeader = self.pramsHeader[
splIndx].split('{')[1][:-1]
pNum = int(splitPramHeader)
pNum -= 1
except:
raise P4Error("could not get the part number")
t.model.parts[pNum].pInvar.val = float(splitPLine[splIndx])
#.........这里部分代码省略.........
示例2: _getP4SampleTree
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import taxNames [as 别名]
def _getP4SampleTree(self, sampNum):
savedDoFastNextTok = var.nexus_doFastNextTok
var.nexus_doFastNextTok = False
tLine = self.tLines[sampNum]
if self.verbose >= 3:
print tLine
f = cStringIO.StringIO(tLine)
t = Tree()
t.parseNexus(f, translationHash=self.translationHash,
doModelComments=self.tree.model.nParts)
var.nexus_doFastNextTok = savedDoFastNextTok
t.taxNames = self.tree.taxNames
for n in t.iterLeavesNoRoot():
n.seqNum = t.taxNames.index(n.name)
t.model = copy.deepcopy(self.model)
if self.tree.model.nFreePrams:
pLine = self.pLines[sampNum]
if self.verbose >= 3:
print pLine
splitPLine = pLine.split()
pGenNum = int(splitPLine[0])
splitTName = t.name.split('_')
tGenNum = int(splitTName[1])
if tGenNum != pGenNum:
raise P4Error(
"something wrong. tGenNum=%i, pGenNum=%i" % (tGenNum, pGenNum))
if self.verbose >= 2:
print "(zero-based) sample %i is gen %i" % (sampNum, tGenNum)
# t.model.dump()
splIndx = 1
for pNum in range(len(self.pramsProfile)):
compNum = 0
rMatrixNum = 0
gdasrvNum = 0
for desc in self.pramsProfile[pNum]:
if desc[0] == 'relRate':
t.model.parts[pNum].relRate = float(
splitPLine[splIndx])
splIndx += 1
elif desc[0] == 'comp':
vv = []
for i in range(desc[1]):
vv.append(float(splitPLine[splIndx]))
splIndx += 1
for i in range(desc[1]):
if vv[i] < var.PIVEC_MIN:
vv[i] = var.PIVEC_MIN * 1.1
thisSum = sum(vv)
factor = 1.0 / thisSum # must sum to one
for i in range(desc[1]):
t.model.parts[pNum].comps[
compNum].val[i] = vv[i] * factor
compNum += 1
elif desc[0] == 'rMatrix':
vv = []
for i in range(desc[1]):
vv.append(float(splitPLine[splIndx]))
splIndx += 1
if len(vv) == 1:
# its a '2p' model, with a kappa
t.model.parts[pNum].rMatrices[
rMatrixNum].val[0] = vv[0]
else:
# gtr
for i in range(desc[1]):
if vv[i] < var.RATE_MIN:
vv[i] = var.RATE_MIN * 1.1
thisSum = sum(vv)
factor = 1.0 / thisSum # must sum to one
for i in range(desc[1]):
t.model.parts[pNum].rMatrices[
rMatrixNum].val[i] = vv[i] * factor
rMatrixNum += 1
elif desc[0] == 'gdasrv':
t.model.parts[pNum].gdasrvs[gdasrvNum].val[
0] = float(splitPLine[splIndx])
splIndx += 1
gdasrvNum += 1
elif desc[0] == 'pInvar':
t.model.parts[pNum].pInvar.val = float(
splitPLine[splIndx])
splIndx += 1
if splIndx != len(splitPLine):
raise P4Error("Something is wrong. After reading, splIndx=%i, but len split pram line=%i" % (
splIndx, len(splitPLine)))
return t