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 else: pluginFolder = os.path.join(os.path.split(os.path.realpath(__file__))[0], '..', '..', pluginFolder) d = {} 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) d[theObject.name] = theObject return d
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 else: pluginFolder = os.path.join( os.path.split(os.path.realpath(__file__))[0], '..', '..', 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))
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 else: pluginFolder = os.path.join(os.path.split(os.path.realpath(__file__))[0], '..', '..', 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))
def appendCategories(self, inputFile, multiCogTreatment, outputFile, preferences): fin = open(getMainDir() + '/stamp/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() + '/stamp/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()
def appendCategories(self, inputFile, multiCogTreatment, outputFile, preferences): fin = open(getMainDir() + '/stamp/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() + '/stamp/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()