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


Python Tree.model方法代码示例

本文整理汇总了Python中tree.Tree.model方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.model方法的具体用法?Python Tree.model怎么用?Python Tree.model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tree.Tree的用法示例。


在下文中一共展示了Tree.model方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _getMrBayesSampleTree

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import model [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])
#.........这里部分代码省略.........
开发者ID:pgfoster,项目名称:p4-phylogenetics,代码行数:103,代码来源:posteriorsamples.py

示例2: Foo

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import model [as 别名]

#.........这里部分代码省略.........
		self.shortRadioMode = QtGui.QShortcut(QtGui.QKeySequence(modifier+dictShortcuts['radio_mode']), self, self.toggleRadio)
		self.shortEqualizer = QtGui.QShortcut(QtGui.QKeySequence(modifier+dictShortcuts['equalizer']), self, self.openEqualizer)
		
		thread = QtCore.QThread(self)
		thread.worker = WorkThreadPipe()
		thread.worker.moveToThread(thread);
		thread.started.connect(thread.worker.process)
		thread.worker.hotKey.connect(self.onHotKey)
		thread.worker.finished.connect(thread.quit)
		thread.worker.finished.connect(thread.worker.deleteLater)
		thread.finished.connect(thread.deleteLater)
		thread.start()
			
		self.show()
	
	def keyReleaseEvent(self, event):
		if event.key() == Qt.Key_Alt:
			self.menuBar().setVisible(not self.menuBar().isVisible())
		else:
			QWidget.keyPressEvent(self, event)
		
	# Triggered by player end of stream event
	# or called by hand to stop the stream
	def stop(self, bus=None, msg=None):
		self.player.stop()
		self.scrollSlider.setValue(0)
		self.table.displayPlayToStop()
		self.stopStatusEmission('Ready')

	def previous(self):
		if self.table.playingId > 0:
			self.player.stop()
			self.table.playingId-=1
			self.player.add(self.table.model().item(self.table.playingId,0).data()['file'])
			self.player.play()
			
	def next(self):
		if self.table.model().rowCount()-1 > self.table.playingId:
			self.player.stop()
			self.table.playingId+=1
			self.player.add(self.table.model().item(self.table.playingId,0).data()['file'])
			self.player.play()
	
	def toggleSong(self):			
		state = self.player.playbin.get_state(Gst.State.NULL)
		if state[1] == Gst.State.PLAYING:
			self.table.displayPlayToPause()
			self.player.toggle()
			
			status = self.statusBar().currentMessage().replace('Playing', 'Paused')
			self.stopStatusEmission(status)	
		else:
			self.table.displayPauseToPlay(self.table.playingId)
			self.player.toggle()
			#self.onDurationChanged(0,0)
			status = self.table.getStatus()
			self.setStatusEmission(status)
			
	# Triggered by player when a song starts
	def onDurationChanged(self, bus, msg):
		self.table.displayNext()
		print('Duration changed signal !')
		filename = self.table.model().item(self.table.playingId,0).data()['file'][7:]
		data = wave.getDBData(filename)
		wave.createImg(data)
		self.scrollSlider.setStyleSheet("border-image: url(./wave.png)")
开发者ID:newmonade,项目名称:Foo.cd,代码行数:70,代码来源:main.py

示例3: _getP4SampleTree

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import model [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
开发者ID:pgfoster,项目名称:p4-phylogenetics,代码行数:95,代码来源:posteriorsamples.py


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