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


Python Model.initialize方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import initialize [as 别名]
class Controller:
    def __init__(self,viewType=None):
        '''
        construct an instance of the controller class
        to use invoke the method initialize
        '''
        ## determine location                                                            
        cwd = os.getcwd()

        if os.path.split(cwd)[1] == 'gdiqt4':
            self.baseDir = cwd
        elif os.path.split(cwd)[1] == 'tests':
            self.baseDir = os.path.join(os.path.split(cwd)[0],'gdiqt4')
        else:
            print "ERROR: cannot determine current working directory"

        ## basic application wide variables 
        self.viewType = viewType
        self.appName = "Gene Data Integrator"
        self.fontName = 'Arial' #'Helvetica'
        self.verbose = True
        self.reset_workspace()

    def reset_workspace(self):
        self.projectID = None
        self.homeDir = None
        self.model = Model()
        self.log = Logger()
        self.subsampleIndices = None
                              
    def save(self):
        self.log.write()

    def initialize_project(self,projectID,loadExisting=False):
        self.projectID = projectID
        self.homeDir = os.path.join(self.baseDir,"projects",self.projectID)
        self.log.initialize(self.projectID,self.homeDir,load=loadExisting) 
        self.model.initialize(self.projectID,self.homeDir)

    ##################################################################################################
    #
    # data dealings -- handling file, project, model and figure data
    #
    ##################################################################################################
           
    def create_new_project(self,view=None,projectID=None):
        #fcsFileName = str(fcsFileName)
        createNew = True
    
        ## create projects dir if necssary
        if os.path.isdir(os.path.join(self.baseDir,'projects')) == False:
            print "INFO: projects dir did not exist. creating..."
            os.mkdir(os.path.join(self.baseDir,'projects'))

        ## get project id
        if projectID != None:
            pass
        elif createNew == True and projectID == None:
            projectID, ok = QtGui.QInputDialog.getText(view, self.appName, 'Enter the name of your new project:')
            projectID = str(projectID)
            
            if ok == False:
                createNew = False
        else:
            createNew = False
            print "ERROR: creating a new project"

        if createNew == True:
            print 'initializing project...'
            self.initialize_project(projectID)
        else:
            print "WARNING: did not initialize project"
            return False

        # remove previous 
        if self.homeDir != None and os.path.exists(self.homeDir) == True and createNew == True:
            print 'overwriting...', self.homeDir
            self.remove_project(self.homeDir)

        if createNew == True and self.homeDir != None:
            os.mkdir(self.homeDir)
            os.mkdir(os.path.join(self.homeDir,"data"))
            os.mkdir(os.path.join(self.homeDir,"figs"))
            os.mkdir(os.path.join(self.homeDir,"models"))
            os.mkdir(os.path.join(self.homeDir,"results"))

        return True

    def remove_project(self,homeDir):        
        for fileOrDir in os.listdir(homeDir):
            if os.path.isfile(os.path.join(homeDir,fileOrDir)) == True:
                os.remove(os.path.join(homeDir,fileOrDir))
            elif os.path.isdir(os.path.join(homeDir,fileOrDir)) == True:
                for fileOrDir2 in os.listdir(os.path.join(homeDir,fileOrDir)):
                    if os.path.isfile(os.path.join(homeDir,fileOrDir,fileOrDir2)) == True:
                        os.remove(os.path.join(homeDir,fileOrDir,fileOrDir2))
                    elif os.path.isdir(os.path.join(homeDir,fileOrDir,fileOrDir2)) == True:
                        for fileOrDir3 in os.listdir(os.path.join(homeDir,fileOrDir,fileOrDir2)):
                            if os.path.isfile(os.path.join(homeDir,fileOrDir,fileOrDir2,fileOrDir3)) == True:
                                os.remove(os.path.join(homeDir,fileOrDir,fileOrDir2,fileOrDir3))
#.........这里部分代码省略.........
开发者ID:ajrichards,项目名称:GenesDI,代码行数:103,代码来源:Controller.py

示例2: __init__

# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import initialize [as 别名]
class Controller:
    def __init__(self,configDict=None,debug=False):
        """
        construct an instance of the controller class
        to use invoke the method initialize
        """

        ## basic application wide variables 
        self.appName = "cytostream"
        self.debug = debug

        if self.debug == True:
            self.verbose = True
            self.defaultDir = os.path.join(self.baseDir,'projects')
        else:
            self.verbose = False
            self.defaultDir = os.getenv("HOME")

        ## application variables
        self.configDict = configDict
        self.reset_workspace()

        # get base directory
        if hasattr(sys,'frozen'):
            self.baseDir = os.path.dirname(sys.executable)
            self.baseDir = re.sub("MacOS","Resources",self.baseDir)
        else:
            self.baseDir = os.path.dirname(__file__)

        if os.path.split(self.baseDir)[-1] != "cytostream":
            self.baseDir = os.path.join(self.baseDir,"cytostream")

        if os.path.isdir(os.path.join(self.baseDir,'cytostream')) == True:
            self.baseDir = os.path.join(self.baseDir,"cytostream")

    def reset_workspace(self):
        self.projectID = None
        self.homeDir = None
        self.model = Model(verbose=self.verbose)
        self.log = None
        self.subsampleIndices = None
        self.fileChannelPath = None
        self.baseDir = self.model.baseDir
        self.currentPlotView = None
        self.compensationFilePath= None
        self.eventsList = []
        self.fileNameList = None
        self.channelDict = None
        self.subsampleDict = {}
        self.uniqueLabels = {}
        self.labelsList = {}
        self.labelsLogList = {}
        self.pythonPath = self.model.pythonPath                           
        
    def save(self):
        self.log.write()

    def initialize_project(self,homeDir,loadExisting=False):
        ## clean
        #if clean == True:

        self.homeDir = os.path.realpath(homeDir)

        if loadExisting == False:
            print '...cleaning home directory'
            self.remove_project(self.homeDir)
            os.mkdir(self.homeDir)

        self.projectID = os.path.split(homeDir)[-1]
        self.homeDir = homeDir
        self.log = Logger(self.homeDir,configDict=self.configDict) 
        self.model.initialize(self.homeDir)
        self.fileNameList = get_fcs_file_names(self.homeDir)
        
        ## this needs to be tested or modified for very large projects
        self.eventsList = [self.model.get_events_from_file(fn) for fn in self.fileNameList]
        
        if len(self.fileNameList) > 0:
            self.fileChannels = self.model.get_file_channel_list(self.fileNameList[0])
        else:
            self.fileChannels = None

        if self.channelDict == None:
            self.channelDict = self.model.load_channel_dict()

    def _labels_load(self,labelsID):
        '''
        load the labels from a given labelsID
        Often the model run id is the labelsID
        '''

        if labelsID == None:
            return

        if self.labelsList.has_key(labelsID) == True:
            return None

        _labelsList = []
        _logsList = []

#.........这里部分代码省略.........
开发者ID:ajrichards,项目名称:cytostream,代码行数:103,代码来源:Controller.py


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