Ejemplo n.º 1
0
    def loadPlugins(self, pluginFolder):
        os.chdir(getMainDir())

        pluginModulePath = pluginFolder.replace('/', '.')

        if runningExecutable():
            if platform.system() == 'Windows':
                # windows plugin folder
                pluginFolder = 'library/' + pluginFolder
            else:
                # os x plugin folder
                pluginFolder = './lib/python2.6/site-packages/' + pluginFolder

        dict = {}
        for filename in os.listdir(pluginFolder):
            if os.path.isdir(os.path.join(pluginFolder, filename)):
                continue

            extension = filename[filename.rfind('.') + 1:len(filename)]
            if extension == 'py' and filename != '__init__.py':
                pluginModule = filename[0:filename.rfind('.')]
                theModule = __import__(pluginModulePath + pluginModule,
                                       fromlist='*')
                theClass = getattr(theModule, pluginModule)
                theObject = theClass(self.preferences)
                dict[theObject.name] = theObject

        return dict
Ejemplo n.º 2
0
	def loadPlugins(self, pluginFolder):
		os.chdir(getMainDir())
		
		pluginModulePath = pluginFolder.replace('/', '.')
		
		if runningExecutable():
			if platform.system() == 'Windows':
				# windows plugin folder
				pluginFolder = 'library/' + pluginFolder
			else:
				# os x plugin folder
				pluginFolder = './lib/python2.6/site-packages/' + pluginFolder
		
		dict = {}
		for filename in os.listdir(pluginFolder):
			if os.path.isdir(os.path.join (pluginFolder, filename)):
				continue

			extension = filename[filename.rfind('.')+1:len(filename)]
			if extension == 'py' and filename != '__init__.py':
				pluginModule = filename[0:filename.rfind('.')]
				theModule = __import__(pluginModulePath + pluginModule, fromlist='*')
				theClass = getattr(theModule, pluginModule)
				theObject = theClass(self.preferences)
				dict[theObject.name] = theObject
					 
		return dict
Ejemplo n.º 3
0
	def loadPlots(self, preferences, pluginFolder):
		os.chdir(getMainDir())
		
		pluginModulePath = pluginFolder.replace('/', '.')
		
		if runningExecutable():
			if platform.system() == 'Windows':
				# windows plugin folder
				pluginFolder = 'library/' + pluginFolder
			else:
				# os x plugin folder
				pluginFolder = './lib/python2.6/site-packages/' + pluginFolder
		
		for filename in os.listdir(pluginFolder):
			if os.path.isdir(os.path.join (pluginFolder, filename)):
				continue

			extension = filename[filename.rfind('.')+1:len(filename)]	
			if extension == 'py' and filename != '__init__.py':
				pluginModule = filename[0:filename.rfind('.')]
				theModule = __import__(pluginModulePath + pluginModule, fromlist='*')
				theClass = getattr(theModule, pluginModule)
				plot = theClass(preferences)
				
				self.plotClassDict[plot.name] = theClass
				self.plotDict[plot.name] = plot
			
		exploratoryPlots = []
		statisticalPlots = []
		for key in self.plotDict:
			if self.plotDict[key].type == 'Exploratory':
				exploratoryPlots.append(key)
			else:
				statisticalPlots.append(key)
				
		exploratoryPlots.sort(lambda a,b:cmp(a.upper(), b.upper()))
		statisticalPlots.sort(lambda a,b:cmp(a.upper(), b.upper()))
			
		for plotName in exploratoryPlots:
			self.cboPlots.addItem(plotName)
			
		self.cboPlots.insertSeparator(self.cboPlots.count())
			
		for plotName in statisticalPlots:
			self.cboPlots.addItem(plotName)
				
		self.display(self.defaultPlot, None, None)
		self.cboPlots.setCurrentIndex(self.cboPlots.findText(self.defaultPlot)) 
Ejemplo n.º 4
0
    filename, line, dummy, dummy = traceback.extract_tb(exc_traceback).pop()
    filename = os.path.basename(filename)
    error = "%s: %s" % (exc_type.__name__, exc_value)

    QtGui.QMessageBox.critical(
        mainWindow, "Unknown error...",
        "<center>An error has occured. This is most likely a bug in STAMP. The error is:<br/><br/>"
        + "<b><i>%s</i></b><br/>" % error +
        "It occured at <b>line %d</b> of file <b>%s</b>.<br/>" %
        (line, filename) + "</center>")


if __name__ == "__main__":
    # change the current working directory
    os.chdir(getMainDir())

    # initialize preferences
    preferences = {}
    preferences['Pseudocount'] = 0.5
    preferences['Truncate feature names'] = True
    preferences['Length of truncated feature names'] = 50
    preferences['Sample 1 colour'] = QtGui.QColor(0, 0, 255)
    preferences['Sample 2 colour'] = QtGui.QColor(255, 127, 0)
    preferences['Selected exploratory features'] = []
    preferences['Selected statistical features'] = []
    preferences['Executable directory'] = sys.path[0]

    if len(sys.argv) == 2 and sys.argv[1].startswith("--macapp"):
        del sys.argv[1]
Ejemplo n.º 5
0
    def appendCategories(self, inputFile, multiCogTreatment, outputFile,
                         preferences):
        fin = open(getMainDir() + '/data/fun.txt', 'U')
        funcData = fin.readlines()
        fin.close()

        # get COG hierarchy information
        funcDict = {}
        for line in funcData:
            line = line.strip()
            if len(line) == 0:
                continue

            if ':' in line:
                code = line[0]
                categoryName = line[2:]
                funcDict[code] = [curClass, categoryName]
            else:
                # new functional classes
                curClass = line

        # get COG category for each COG
        fin = open(getMainDir() + '/data/whog.txt', 'U')
        cogData = fin.readlines()
        fin.close()

        cogDict = {}
        for line in cogData:
            if '[' in line:
                # need to parse a new COG
                code = line[line.find('[') + 1:line.find(']')]
                cogIndex = line.find('COG')
                cogId = line[cogIndex:cogIndex + 7]
                cogDict[cogId] = code

        # modify input file
        fin = open(inputFile, 'U')
        inputData = fin.readlines()
        fin.close()

        fout = open(outputFile, 'w')

        # write out header information
        headers = inputData[0].strip()
        headers = headers.split('\t')
        fout.write('COG classes' + '\t' + 'COG category names' + '\t' +
                   'COG category codes' + '\t' + 'COG annotations' + '\t' +
                   'COG IDs')

        for i in xrange(2, len(headers)):
            fout.write('\t' + headers[i])
        fout.write('\n')

        # write out each row
        for i in xrange(1, len(inputData)):
            line = inputData[i].strip()
            lineSplit = line.split('\t')
            cogId = lineSplit[0]
            cogAnnotation = lineSplit[1]
            cogCode = cogDict[cogId]

            if multiCogTreatment == 'Treat multi-code COGs as features':
                cogClass, cogCategoryName = funcDict.get(
                    cogCode, [cogCode, cogCode])
                fout.write(cogClass + '\t' + cogCategoryName + '\t' + cogCode +
                           '\t' + cogAnnotation + '\t' + cogId)
                for j in xrange(2, len(lineSplit)):
                    fout.write('\t' + lineSplit[j])
                fout.write('\n')
            elif multiCogTreatment == 'Assign sequence to each COG code':
                for ch in cogCode:
                    cogClass, cogCategoryName = funcDict.get(
                        ch, [cogCode, cogCode])
                    fout.write(cogClass + '\t' + cogCategoryName + '\t' + ch +
                               '\t' + cogAnnotation + '\t' + cogId)
                    for j in xrange(2, len(lineSplit)):
                        fout.write('\t' + lineSplit[j])
                    fout.write('\n')

        fout.close()
Ejemplo n.º 6
0
#=======================================================================
Ejemplo n.º 7
0
    def saveSummaryTable(self, filename, statsTestResults):
        tableData, tableHeadings = statsTestResults.tableData(True)

        tableData = SortTableStrCol(tableData, 0)

        fout = open(filename, "w")
        for heading in tableHeadings:
            fout.write(heading + "\t")
        fout.write("\n")

        for row in tableData:
            for entry in row:
                fout.write(str(entry) + "\t")
            fout.write("\n")

        fout.close()


if __name__ == "__main__":
    # change the current working directory
    os.chdir(getMainDir())

    # initialize preferences
    preferences = {}
    preferences["Pseudocount"] = 0.5
    preferences["Executable directory"] = sys.path[0]

    commandLineParser = CommandLineParser(preferences)
    commandLineParser.run()
    sys.exit()
Ejemplo n.º 8
0
  def appendCategories(self, inputFile, multiCogTreatment, outputFile, preferences):
    fin = open(getMainDir() + '/data/fun.txt', 'U')
    funcData = fin.readlines()
    fin.close()
    
    # get COG hierarchy information
    funcDict = {}
    for line in funcData:
      line = line.strip()
      if len(line) == 0:
        continue
      
      if ':' in line:
        code = line[0]
        categoryName = line[2:]
        funcDict[code] = [curClass, categoryName] 
      else:
        # new functional classes
        curClass = line

    # get COG category for each COG
    fin = open(getMainDir() + '/data/whog.txt', 'U')
    cogData = fin.readlines()
    fin.close()
    
    cogDict = {}
    for line in cogData:
      if '[' in line:
        # need to parse a new COG
        code = line[line.find('[')+1:line.find(']')]
        cogIndex = line.find('COG')
        cogId = line[cogIndex:cogIndex+7]    
        cogDict[cogId] = code

    # modify input file
    fin = open(inputFile, 'U')
    inputData = fin.readlines()
    fin.close()
    
    fout = open(outputFile, 'w')
        
    # write out header information
    headers = inputData[0].strip()
    headers = headers.split('\t')
    fout.write('COG classes' + '\t' + 'COG category names' + '\t' + 'COG category codes'
                + '\t' + 'COG annotations' + '\t' + 'COG IDs')
    
    for i in xrange(2,len(headers)):
      fout.write('\t' + headers[i])
    fout.write('\n')
    
    # write out each row
    for i in xrange(1, len(inputData)):
      line = inputData[i].strip()
      lineSplit = line.split('\t')
      cogId = lineSplit[0]
      cogAnnotation = lineSplit[1]
      cogCode = cogDict[cogId]
            
      if multiCogTreatment == 'Treat multi-code COGs as features':
        cogClass, cogCategoryName = funcDict.get(cogCode, [cogCode, cogCode])
        fout.write(cogClass + '\t' + cogCategoryName + '\t' + cogCode + '\t' + cogAnnotation + '\t' + cogId)
        for j in xrange(2, len(lineSplit)):
          fout.write('\t' + lineSplit[j])
        fout.write('\n')
      elif multiCogTreatment == 'Assign sequence to each COG code':
        for ch in cogCode:
          cogClass, cogCategoryName = funcDict.get(ch, [cogCode, cogCode])
          fout.write(cogClass + '\t' + cogCategoryName + '\t' + ch + '\t' + cogAnnotation + '\t' + cogId)
          for j in xrange(2, len(lineSplit)):
            fout.write('\t' + lineSplit[j])
          fout.write('\n')
        
    fout.close()