def get_current_domain_location(self): if self.currentDomain == -1: print "Load the first domain first before accessing this funciton" if self.isAprofile == 1: profilePath = parms.get('profilesPath') + self.profileName tmpPath = "" #parse the domain's parent structure to get the path curDomain = self.currentDomainNode() hierarchy = [] while curDomain is not None: name = self.filterFoldername(curDomain.description) hierarchy.append(name) if self.profileSunid.find(curDomain.sunid) == 0: curDomain = None else: curDomain = curDomain.parent while len(hierarchy) > 0: foldr = hierarchy.pop() profilePath = profilePath +'\\'+foldr if not path.isfile(profilePath+'\\'+self.currentDomainNode().sid+'.ent'): print "Cannot find File!" return "" return profilePath+'\\'+self.currentDomainNode().sid+'.ent' else: pdb_path = parms.get('scopPDBsLocation') + self.currentDomainNode().sid[2:4] + '\\' + self.currentDomainNode().sid + '.ent' if path.isfile(pdb_path): return pdb_path
def getPDBLocation(self): #check if the path includes the profiles directory path pdb_path="" pos = 0 while pos < len(self.domainsScop[self.currentSelection.id-1]) and self.currentSelection.thisNode.sunid != self.domainsScop[self.currentSelection.id-1][pos].sunid: pos = pos + 1 if self.dirpath.find(parms.get('saveResultsin')) >= 0: #if the domain is to be viewed from a profile pdb_path = parms.get('scopPDBsLocation') + self.domainsScop[self.currentSelection.id-1][pos].sid[2:4] + '\\' + self.domainsScop[self.currentSelection.id-1][pos].sid + '.ent' if path.isfile(pdb_path): return pdb_path print "Selected Domain doesnot exist in the SCOP Database" elif self.dirpath.find(parms.get('profilesPath')) >= 0: #if the domain is to be viewed from the ScopDatabase curItem = self.domainsScop[self.currentSelection.id-1][pos] tmpPath = "" while curItem is not None: name = self.filterFoldername(curItem.description) if len(name) > 20: name = name[:20]+'_'+curItem.sunid tmpPath = name.strip() + '\\' + tmpPath curItem = curItem.parent tmpPath = tmpPath[tmpPath.index('\\')+1:] print "TmpPath: "+tmpPath pdb_path = parms.get('profilesPath')+ self.currentProfileName + '\\' + tmpPath + self.domainsScop[self.currentSelection.id-1][pos].sid + '.ent' print "PDB PATH: "+pdb_path if path.isfile(pdb_path): return pdb_path print "Selected Domain doesnot exist in the profile" return ""
def loadProfile(self): files = listdir(parms.get('profilesPath')) profiles = [] for item in files: direc = parms.get('profilesPath')+item if path.isdir(direc): profiles.append(item) self.neww = Toplevel() dropdown = Pmw.ComboBox(self.neww, label_text = 'Select a Profile:', labelpos = 'nw', selectioncommand=self.loadSelectedProfile, scrolledlist_items = profiles) dropdown.pack(side = LEFT, anchor = N, fill = X, expand = 1, padx = 8, pady = 8)
def get_chain_color_word(self): # returns the word color if parms.get('colorblind'): colormap = parms.get('colorblind_colormap') else: colormap = parms.get('colormap') index = 0 for pchain in self.parent.ProteinList: if self.chain_name == pchain.chain_name: return 'chain%s'%(index%12+1) index = index + 1 for nchain in self.parent.NucleotideChainList: if self.chain_name == nchain.chain_name: return 'chain%s'%(index%12+1) index = index + 1
def __init__(self, obj, id, parent=None, toplevel=None): Frame.__init__(self, parent, bg='white') self.pack() self.toplevel = toplevel self.thisNode = Node() self.thisNode = obj self.isDisplayed = 1 self.isExpanded = 0 self.isALeaf = 0 self.id = id #### EACH SCOP Struct. in the profile is assigned an ID self.gifs_dir = parms.get('gifs_dir') self.pdb_dir = parms.get('pdb_dir') self.createButton() self.createLabel()
def loadSelectedProfile(self, selection): self.neww.destroy() new_window=Toplevel() pw = Pmw.PanedWidget(new_window) pw.add('top', min=10) pw.add('bottom', min = 10) new_window.title("SCOP Profile") new_window.config(bg='white') geometry_string = "%dx%d%+d%+d" %(700,800,50,30) # width,height,x-offset,y-offset new_window.geometry(geometry_string) pw.pane('top').configure(background='white') a = ResultsFrame(parms.get('profilesPath')+selection+'\\', pw, new_window, self.scopViewer).pack(side=TOP) pw.pack(expand=1, fill=BOTH) bottomPane = pw.pane('bottom') bottomPane.system = MolecularSystem.System(self, bottomPane) bottomPane.system.load_pdb("") bottomPane.system.color_ribbon_by_chain() bottomPane.viewer = MolnirMolecularViewer(bottomPane, bottomPane.system) bottomPane.viewer.loadSystem(bottomPane.system) bottomPane.cardframe = CardFrame(bottomPane, bottomPane.system) bottomPane.cardframe.pack(expand=NO, fill=X) self.scopViewer.topMenuSystem.parent.scopViewer_windows.append(new_window) self.topFrame.config(bg='white')
def buildClaList(self): fullFile = file(parms.get('scopClassification'), 'r').readlines() rex = re.compile('\t\d\d\d\d\d\t') for line in fullFile: a = rex.search(line) if a: self.entireClaList[a.group().strip()] = line
def get_chain_color(self): # returns three doubles if parms.get('colorblind'): colormap = parms.get('colorblind_colormap') colormap_count = len(colormap) else: colormap = parms.get('colormap') colormap_count = len(colormap) index = 0 for pchain in self.parent.ProteinList: if self.chain_name == pchain.chain_name: color_name = 'chain%s'%(index%12+1) return colormap[color_name] index = index + 1 for nchain in self.parent.NucleotideChainList: if self.chain_name == nchain.chain_name: color_name = 'chain%s'%(index%12+1) return colormap[color_name] index = index + 1
def loadKeywords(self): if path.isfile(parms.get('keywordsFile')): wordsFile = file(parms.get('keywordsFile'), 'r') strg = wordsFile.readline() while strg.find('#keywords') == -1: strg = wordsFile.readline() strg = wordsFile.readline() while strg.find('#removed keywords') == -1: for words in strg.split(','): if len(words.strip()) > 0: self.keywords.append(words.strip()) strg = wordsFile.readline() strg = wordsFile.readline() while strg: for words in strg.split(','): if len(words.strip()) > 0: self.removedKwds.append(words.strip()) strg = wordsFile.readline()
def loadScop(self, cla_path=None, des_path=None, hie_path=None): if cla_path is None: self.cla_file = file(parms.get('scopClassification'), 'r') self.des_file = file(parms.get('scopDescription'), 'r') self.hie_file = file(parms.get('scopHierarchy'), 'r') elif cla_path is not None and hie_path is not None and des_path is not None: self.cla_file = file(cla_path, 'r') self.des_file = file(des_path, 'r') self.hie_file = file(hie_path, 'r') else: print "Error in arguments" return self.ScopStructure = SCOP.Scop(self.cla_file, self.des_file, self.hie_file) self.ScopDomains = self.ScopStructure.getDomains() cla_file_name = self.cla_file.name if self.isAprofile == 1: self.profileName = cla_file_name[cla_file_name[:cla_file_name.rindex('\\')].rindex('\\')+1:cla_file_name.rindex('\\')] self.profileSunid = cla_file_name[cla_file_name.rindex('\\')+1:cla_file_name.rindex('\\')+6] print "Profile Name: "+self.profileName
def updateKeywords(self): wordsFile = file(parms.get('keywordsFile'), 'w') wordsFile.write('#keywords\n') for word in self.keywords: if self.keywords.index(word) < (len(self.keywords) - 1): wordsFile.write(word+', ') else: wordsFile.write(word) wordsFile.write('\n#removed keywords\n') for word in self.removedKwds: if self.removedKwds.index(word) < (len(self.removedKwds) - 1): wordsFile.write(word+', ') else: wordsFile.write(word)
def copyPDBs(self, savePath): #dirNamesDonotIncludelist = ['(', ')', ':', '-', '.', ',', ';'] for ScopItem in self.nodesScop: indx = self.nodesNames.index(ScopItem.root.description[len(ScopItem.root.description)-5:])+1 if self.removedNames.count(indx) == 0: pos = 0 #parse the scop structure for eachItem in self.domainsScop[indx-1]: hierarchy = [] curItem = eachItem """ This loop creates a list of directories need to save the domain Eg: If the node hierarchy is of the form Globin->Globin_child->Globin_child_child->Globin_child_child_child and 'Globin_child_child_child' is selected then the list hierarchy will contain [Globin, Globin_child, Globin_child_child, Globin_child_child_child] """ while curItem is not None: name = self.filterFoldername(curItem.description) #If the length of the node.description is > 20, the pad the end of it #with its sunid if len(name)>20: name = name[:20]+'_'+curItem.sunid hierarchy.append(name.strip()) curItem = curItem.parent curPath = savePath #From the 'hierarchy' list, from top down, each item is checked to see if the #folder exists by that name. If it doesnot exist, the folder structure is created. #If the folder by that name exists, then the next item in the 'heirarchy' list is checked hierarchy.pop() while len(hierarchy) > 0: foldr = hierarchy.pop() curPath = curPath+'\\'+foldr if not path.isdir(curPath): mkdir(curPath) while len(hierarchy) > 0: curPath = curPath + '\\' + hierarchy.pop() mkdir(curPath) scopPdbsLoc = parms.get('scopPDBsLocation') #Copy the .ent file from the SCOP Database to the current profile location if path.isdir(scopPdbsLoc+eachItem.sid[2:4]) and path.isfile(scopPdbsLoc+eachItem.sid[2:4]+'\\'+eachItem.sid+'.ent'): copy(scopPdbsLoc+eachItem.sid[2:4]+'\\'+eachItem.sid+'.ent', curPath+'\\'+eachItem.sid+'.ent') else: print "Protein Domain: "+eachItem.sid+" doesnot exist!"
def validateName(self, result): if result is None or result == 'Cancel': self.nameProfileDlg.withdraw() elif result == 'OK': self.currentProfileName = self.nameProfileDlg.get() self.nameProfileDlg.withdraw() print self.currentProfileName+' IN get' if path.isdir(parms.get('profilesPath')+self.currentProfileName): dialog = Pmw.MessageDialog(self, title = 'Profile Name Rejected', defaultbutton = 0, buttons = ('OK', ), message_text = 'A Profile with name \''+self.currentProfileName+'\' already exists!') dialog.activate() self.currentProfileName = "" self.saveCurrentProfile() else: self.finishOffSaving()
def getCurrentDomainLineage(self): type = parms.get('classifications_fullname') lineage = [] currentNode = self.currentDomainNode() while currentNode is not None and len(currentNode.type) > 0: lineage.insert(0, type[currentNode.type]+": "+currentNode.description+'\n') currentNode = currentNode.parent if self.isAprofile == 1: self.hie_file.seek(0) line = self.hie_file.readline() while line[0] == '#': lineage.insert(0,line[1:].strip()+'\n') line = self.hie_file.readline() return lineage
def getCurrentDomainLineage(self): type = parms.get('classifications_fullname') lineage = [] currentNode = self.currentDomainNode() while currentNode is not None and len(currentNode.type) > 0: lineage.insert( 0, type[currentNode.type] + ": " + currentNode.description + '\n') currentNode = currentNode.parent if self.isAprofile == 1: self.hie_file.seek(0) line = self.hie_file.readline() while line[0] == '#': lineage.insert(0, line[1:].strip() + '\n') line = self.hie_file.readline() return lineage
def finishOffSaving(self): print 'In save: '+self.currentProfileName if len(self.currentProfileName) > 0: #Create a profile directory, try: mkdir(parms.get('profilesPath')+self.currentProfileName) except OSError: dialog = Pmw.MessageDialog(self, title = 'Unable to Create Directory', defaultbutton = 0, buttons = ('OK', ), message_text = 'Unable to create the directory: '+parms.get('profilesPath')+self.currentProfileName) dialog.activate() dialog = Pmw.MessageDialog(self, title = 'Profile Not Saved', defaultbutton = 0, buttons = ('OK', ), message_text = 'Unable to Save Profile') dialog.activate() return #Copy all the results from the temperory directory to the actual profile directory files = listdir(parms.get('saveResultsin')) for name in self.nodesNames: if self.removedNames.count(self.nodesNames.index(name)+1) == 0 and files.count(name+'_hie.txt') > 0 and files.count(name+'_cla.txt') > 0 and files.count(name+'_des.txt') > 0: copy(parms.get('saveResultsin')+name+'_hie.txt', parms.get('profilesPath')+self.currentProfileName+'\\'+name+'_hie.txt') copy(parms.get('saveResultsin')+name+'_des.txt', parms.get('profilesPath')+self.currentProfileName+'\\'+name+'_des.txt') copy(parms.get('saveResultsin')+name+'_cla.txt', parms.get('profilesPath')+self.currentProfileName+'\\'+name+'_cla.txt') remove(parms.get('saveResultsin')+name+'_hie.txt') remove(parms.get('saveResultsin')+name+'_des.txt') remove(parms.get('saveResultsin')+name+'_cla.txt') else: print "Unable to save: "+name+" under the profile name: "+self.currentProfileName self.copyPDBs(parms.get('profilesPath')+self.currentProfileName) self.isCurrentProfileSaved = 1 self.treeWinText.configure(label_text = 'Current Profile: '+self.currentProfileName)
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from Tkinter import * import urllib import re import parms import Pmw import string import MolecularSystem from GUICards import * import MolecularViewer from os import * #location of image: plusImage, minusImage pdb_dir = parms.get('pdb_dir') gifs_dir = path.abspath('./Tools/DatabaseManager') + path.normpath('/') class DirNode(Frame): """ This class represents each Directory/File item in the treeWinText textbox. Creates a frame with: 1.path to the item (path) 2.actual item (name) 3.Pointer to the actual Node in SCOP Data structure """ def __init__(self, pth, obj, parent=None): Frame.__init__(self, parent, bg='white') self.pack() self.toplevel = parent self.thisNode = obj
def filterFoldername(self, name): dirNamesDonotIncludelist = parms.get('dirNamesDonotIncludelist') for itm in dirNamesDonotIncludelist: name = name.replace(itm, '') return name.strip()
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from Tkinter import * import urllib import re import parms import Pmw import string import MolecularSystem from GUICards import * import MolecularViewer from os import * #location of image: plusImage, minusImage pdb_dir = parms.get('pdb_dir') gifs_dir = path.abspath('./Tools/DatabaseManager') + path.normpath('/') class DirNode(Frame): """ This class represents each Directory/File item in the treeWinText textbox. Creates a frame with: 1.path to the item (path) 2.actual item (name) 3.Pointer to the actual Node in SCOP Data structure """ def __init__(self, pth, obj, parent=None): Frame.__init__(self, parent, bg='white') self.pack() self.toplevel= parent self.thisNode = obj self.thisPath = pth
def copyPDBs(self, savePath): cla = file( self.saveResultsin + str(self.currentSelection.thisNode.sunid) + "_cla.txt", 'r') hie = file( self.saveResultsin + str(self.currentSelection.thisNode.sunid) + "_hie.txt", 'r') des = file( self.saveResultsin + str(self.currentSelection.thisNode.sunid) + "_des.txt", 'r') scopStruct = SCOP.Scop(cla, des, hie) domsStruct = scopStruct.getDomains() for eachItem in domsStruct: hierarchy = [] curItem = eachItem """ This loop creates a list of directories need to save the domain Eg: If the node hierarchy is of the form Globin->Globin_child->Globin_child_child->Globin_child_child_child and 'Globin_child_child_child' is selected then the list hierarchy will contain [Globin, Globin_child, Globin_child_child, Globin_child_child_child] """ while curItem is not None: name = self.filterFoldername(curItem.description) #If the length of the node.description is > 20, the pad the end of it #with its sunid if len(name) > 20: name = name[:20] + '_' + curItem.sunid hierarchy.append(name.strip()) if self.currentSelection.thisNode.sunid.find( curItem.sunid) == 0: curItem = None else: curItem = curItem.parent curPath = savePath #From the 'hierarchy' list, from top down, each item is checked to see if the #folder exists by that name. If it doesnot exist, the folder structure is created. #If the folder by that name exists, then the next item in the 'heirarchy' list is checked while len(hierarchy) > 0: foldr = hierarchy.pop() curPath = curPath + '\\' + foldr if not path.isdir(curPath): mkdir(curPath) while len(hierarchy) > 0: curPath = curPath + '\\' + hierarchy.pop() mkdir(curPath) scopPdbsLoc = parms.get('scopPDBsLocation') #Copy the .ent file from the SCOP Database to the current profile location if path.isdir(scopPdbsLoc + eachItem.sid[2:4]) and path.isfile( scopPdbsLoc + eachItem.sid[2:4] + '\\' + eachItem.sid + '.ent'): copy( scopPdbsLoc + eachItem.sid[2:4] + '\\' + eachItem.sid + '.ent', curPath + '\\' + eachItem.sid + '.ent') else: print "Protein Domain: " + eachItem.sid + " doesnot exist!"
def __init__(self, parent, viewer, menSystem): Frame.__init__(self, parent.pane('top'), bg='white') self.focus() self.nodesList = [ ] #List of all the nodes in the treeWinText textbox. (has ScopNode objects) self.currentNodeClaList = [ ] #Temp. variable used in UpdateCla funciton self.entireClaList = { } #Classification file is parsed and all domains are hashed by their sids #The bottom pane in the viewer represents the Molecular Viewer self.molnir_level = parent.pane('bottom') self.viewer_window = viewer self.topMenuSystem = menSystem self.saveResultsin = "" #directory path set by the user to save the profile self.currentProfileName = "" self.profilesPath = parms.get('profilesPath') self.type = parms.get('classifications_fullname') #Open the SCOP Parseable Text files clasi = file(parms.get('scopClassification'), 'r') descr = file(parms.get('scopDescription'), 'r') heira = file(parms.get('scopHierarchy'), 'r') #Load SCOP Structure and SCOP Domains self.scopDataStruct = SCOP.Scop(clasi, descr, heira) self.domains = self.scopDataStruct.getDomains() self.nameHierarchy = parms.get('nameHierarchy') self.pdbPath = "" self.balloon = Pmw.Balloon(self) self.menuBar = Pmw.MenuBar(self, hull_relief=RAISED, hull_borderwidth=1, balloon=self.balloon) self.menuBar.pack(fill=X, expand=NO, anchor=N) self.menuBar.addmenu('Profiles', 'Search Profiles') self.menuBar.addmenuitem('Profiles', 'command', command=self.loadProfile, label='Load Profile') self.menuBar.addmenuitem('Profiles', 'command', command=self.editProfile, label='Edit Profile(s)') self.menuBar.addmenu('Save', 'Create a local DB Structure') self.menuBar.addmenuitem('Save', 'command', command=self.saveSelectedNode, label='Save selected Node as a Profile') self.menuBar.addmenu('Search', 'Search Entire SCOP Database') self.menuBar.addmenuitem('Search', 'command', command=self.loadSCOPSearch, label='Search SCOP') self.treeWinText = Pmw.ScrolledText(self, labelpos='n', usehullsize=1, label_text='SCOP Domain Viewer', hull_width=100, hull_height=20, text_padx=1, text_pady=1, text_wrap='none', text_cursor='arrow') self.treeWinText.pack(side=LEFT, expand=YES, fill=BOTH) self.pack(expand=YES, fill=BOTH) self.lineageBox = Text(self, relief=FLAT, cursor="arrow") self.lineageBox.pack(side=TOP, anchor=N) self.lineageBox.config(height=12, width=38, state=DISABLED) self.viewButton = Button(self, text="View", state=DISABLED, height=1, command=self.displaySelected, width=5) self.viewButton.pack(side=LEFT, anchor=S, padx=10) self.lines = 1 #Load all the toplevel nodes (all of type 'Class') into the textbox for item in self.scopDataStruct.root.children: self.nodesList.append(ScopNode(item, self)) indx = "%0.1f" % (self.lines) self.treeWinText.window_create( indx, window=self.nodesList[len(self.nodesList) - 1]) indx = "%0.1f" % (self.lines + 0.1) self.treeWinText.insert(indx, '\n') self.lines = self.lines + 1 #self.currentSelection is updated everytime when a user clicks on a Node in the treeWinText text box self.currentSelection = self.nodesList[0] self.treeWinText.pack() self.treeWinText.configure(text_state='disabled') self.pack()
def updateClaList(self, nde, cla): if len(nde.children) == 0: if self.currentNodeClaList.count(nde.sunid) == 0: self.currentNodeClaList.append(nde.sunid) cla.write(self.entireClaList[nde.sunid]) #Builds a hashed list with the sunids as keys from the classification file def buildClaList(self): fullFile = file(parms.get('scopClassification'), 'r').readlines() rex = re.compile('\t\d\d\d\d\d\t') for line in fullFile: a = rex.search(line) if a: self.entireClaList[a.group().strip()] = line #else: # print "Unable to index the line: "+line if __name__ == '__main__': main_window = Tk() clasi = file(parms.get('scopClassification'), 'r') descr = file(parms.get('scopDescription'), 'r') heira = file(parms.get('scopHierarchy'), 'r') scopStruct = SCOP.Scop(clasi, descr, heira) a = SearchFrame(main_window, scopStruct.root) a.mainloop()
def okbutton(self): if len(self.keywords) > 0: self.types_state = [] #Get the state of Check Boxes for var in self.chk_vars: self.types_state.append(var.get()) #Delete the previous search results tempFiles = listdir(self.saveResultsin) if len(tempFiles) > 0: dialog = Pmw.MessageDialog(self, title = 'Temp Results Directory', defaultbutton = 0, buttons = ('OK', ), message_text = 'Deleting Results of previous Search!') dialog.activate() for rfile in tempFiles: os.remove(self.saveResultsin+rfile) #Parse the comments file and build a hash allComms = file(parms.get('scopComments'), 'r').readlines() for line in allComms: self.commsList[line[:5]] = line[8:] #Build lists of regular expressions for item in self.keywords: if item.find('(+)') == 0: self.includeRegex.append(re.compile(item[3:], re.IGNORECASE)) elif item.find('(-)') == 0: self.excludeRegex.append(re.compile(item[3:], re.IGNORECASE)) for kwrd in self.keywords: self.currentNodeClaList = [] self.findKeyword(self.scopStruct.root) self.updateKeywords() print "KEY WORDS ARE:" print self.keywords if len(self.listOfresultsSunid) > 0: #If there are any search results, display them in ResultsFrame self.destroy() self.toplevel.title("SCOP Search Results") self.toplevel.config(bg='white') pw = Pmw.PanedWidget(self.toplevel) pw.add('top', min=10) pw.add('bottom', min = 10) geometry_string = "%dx%d%+d%+d" %(700,800,50,30) # width,height,x-offset,y-offset self.toplevel.geometry(geometry_string) pw.pane('top').configure(background='white') a = ResultsFrame(self.saveResultsin, pw, self.toplevel, self.scopViewer).pack(side=TOP) pw.pack(expand=1, fill=BOTH) bottomPane = pw.pane('bottom') bottomPane.system = MolecularSystem.System(self, bottomPane) bottomPane.system.load_pdb("") bottomPane.system.color_ribbon_by_chain() bottomPane.viewer = MolnirMolecularViewer(bottomPane, bottomPane.system) bottomPane.viewer.loadSystem(bottomPane.system) bottomPane.cardframe = CardFrame(bottomPane, bottomPane.system) bottomPane.cardframe.pack(expand=NO, fill=X) self.scopViewer.topMenuSystem.parent.scopViewer_windows.append(self.toplevel) else: dialog = Pmw.MessageDialog(self, title = 'Search Results', defaultbutton = 0, buttons = ('OK', ), command='self.destroy()', message_text = 'Search returned 0 results!') dialog.activate() else: print "No Keywords Entered"
def __init__(self, parent, viewer): Frame.__init__(self, parent, bg='white') self.pack(expand=YES, fill=BOTH) self.scopViewer = viewer self.scopStruct = viewer.scopDataStruct self.tier1_frame = Frame(self, bg='white') self.currentExpr = re.compile('') self.toplevel = parent geometry_string = "%dx%d%+d%+d" %(700,500,150,150) # width,height,x-offset,y-offset self.toplevel.geometry(geometry_string) self.toplevel.title('SCOP Search') self.keywords=[] self.removedKwds=[] self.includeRegex = [] self.excludeRegex = [] self.entireClaList = {} self.commsList = {} self.buildClaList() #Build a hash table with sunids as kes from the classification.txt file self.currentNodeClaList = [] self.loadKeywords() self.types_state = [] self.listOfresultsSunid = [] self.saveResultsin = parms.get('saveResultsin') ######### self.add_txt_frame = Frame(self.tier1_frame, bg='white') self.enter_txt_label = Label(self.add_txt_frame, bg='white', text='Enter Keyword:', justify=LEFT) self.enter_txt_label.pack(anchor=W, pady=5) self.kwd_entry = Entry(self.add_txt_frame, width=15) self.kwd_entry.pack() self.kwd_entry.focus() self.kwd_entry.bind('<Return>', (lambda event: self.addKeywordToList())) self.add_kwd_button = Button(self.add_txt_frame, text='Add Keyword', command=self.addKeywordToList) self.add_kwd_button.pack(pady=5) self.exclude_txt_label = Label(self.add_txt_frame, bg='white', text='Exclude Keyword:', justify=LEFT) self.exclude_txt_label.pack(anchor=W, pady=5) self.exclude_kwd_entry = Entry(self.add_txt_frame, width=15) self.exclude_kwd_entry.pack() self.exclude_kwd_entry.bind('<Return>', (lambda event: self.addExcludeKeywordToList())) self.exclude_kwd_button = Button(self.add_txt_frame, text='Add Keyword', command=self.addExcludeKeywordToList) self.exclude_kwd_button.pack(pady=5) self.add_txt_frame.pack(side=LEFT, anchor=N, padx = 25, pady=75) ########## self.keyword_lstbox_frame = Frame(self.tier1_frame, bg='white') self.kwd_listbox_label = Label(self.keyword_lstbox_frame, text='Keywords List', bg='white') self.kwd_listbox_label.pack(pady=5) self.kwd_listbox = Pmw.ScrolledListBox(self.keyword_lstbox_frame, listbox_selectmode=SINGLE, items=self.keywords, listbox_height=15, vscrollmode='static', usehullsize=1, hull_width=200, hull_height=250) self.kwd_listbox.config(background='white') self.kwd_listbox.pack(side=LEFT) self.keyword_lstbox_frame.pack(side=LEFT, anchor=N) ########## self.add_remove_frame = Frame(self.tier1_frame, bg='white') self.add_from_remove = Button(self.add_remove_frame, text='<-- Add', width=10, command=self.addFromRemoveList) self.add_from_remove.pack(padx=15, pady=15) self.remove_from_keyword = Button(self.add_remove_frame, text='Remove -->', width=10, command=self.removeFromKeywordList) self.remove_from_keyword.pack(padx=15) self.add_remove_frame.pack(side=LEFT, anchor=N, pady=75) ########## self.remove_lstbox_frame = Frame(self.tier1_frame, bg='white') self.rm_listbox_label = Label(self.remove_lstbox_frame, text='Removed Keywords List', bg='white') self.rm_listbox_label.pack(pady=5) self.rm_listbox = Pmw.ScrolledListBox(self.remove_lstbox_frame, listbox_selectmode=SINGLE, items = self.removedKwds, listbox_height=15, vscrollmode='static', usehullsize=1, hull_width=200, hull_height=250) self.rm_listbox.config(background='white') self.rm_listbox.pack(side=LEFT) self.remove_lstbox_frame.pack(side=LEFT, anchor=N) self.tier1_frame.pack() self.type = parms.get('classifications_fullname') self.indx = parms.get('classifications') self.classi_index = parms.get('nameHierarchy') self.tier2_frame = Frame(self, bg='white') self.toInlcludeSublevels = IntVar(self) self.include_sublevels_checkbox = Checkbutton(self.tier2_frame, text='Search sublevels of Hits', bg='white', variable=self.toInlcludeSublevels) self.include_sublevels_checkbox.pack(side=LEFT) self.searchComments = IntVar(self) self.searchComments_checkbox = Checkbutton(self.tier2_frame, text='Search Comments', bg='white', variable=self.searchComments) self.searchComments_checkbox.pack(side=LEFT) self.tier2_frame.pack() self.tier3_frame = Frame(self, bg='white') self.chkBox_frame_label = Label(self.tier3_frame, text='Refine Search by selecting the TYPES', bg='white', justify=LEFT) self.chkBox_frame_label.pack(side=TOP, anchor=W, fill=X) self.chk_vars=[] for sel in self.indx: var = IntVar(self) chk = Checkbutton(self.tier3_frame, text=self.type[sel], bg='white', variable=var) chk.pack(side=LEFT, anchor=W) if sel == 'cl': #Donot search the Class Level of the hierarchy, because of a BUG while #displaying the corresponding hit in SearchResults chk.forget() else: chk.select() self.chk_vars.append(var) self.tier3_frame.pack(pady=30) self.tier4_frame = Frame(self, bg='white') self.ok_button = Button(self.tier4_frame, text='OK', command=self.okbutton) self.ok_button.pack(side=LEFT, padx=100) self.cancel_button = Button(self.tier4_frame, text='Cancel', command=self.cancelbutton) self.cancel_button.pack(side=LEFT, padx=100) self.tier4_frame.pack()
from Tkinter import * from Bio.SCOP import Node from Bio import SCOP import urllib import MolecularSystem from GUICards import * from BlissMolecularViewer import * from ScopSearch import * from ScopResults import * import parms import Pmw import re #location of plusImage, minusImage gifs_dir = parms.get('gifs_dir') pdb_dir = parms.get('pdb_dir') """ This class represents each SCOP Node item in the treeWinText textbox. Creates a frame with: 1.+/-button, 2.Empty Label for padding, and 3.Pointer to the actual Node in SCOP Data structure """ class ScopNode(Frame): def __init__(self, obj, parent=None): Frame.__init__(self, parent, bg='white') self.pack()
def load_pdb(self, filename): print "Opening pdb file %s\n"%(os.path.split(filename)[1]) """ parse a pdb file and load it as a system object.""" self.filename = filename self.selected = 1 self.ProteinList = [] self.NucleotideChainList = [] self.LigandList = [] self.WaterList = [] self.HeaderLines = [] self.HBonds = [] self.header = '' # open the file if len(filename) == 0: return PDBfile = open(filename, 'r') # separate atoms, HETATMS, and other ATOMlines = [] HETATMlines = [] ANISlines = [] # anisotropy cards are ignored otherlines = [] while 1: line = PDBfile.readline() # should be able to tell from the first 4 characters of each line if line[0:4] == 'ATOM': ATOMlines.append(line) elif line[0:4] == 'HETA': HETATMlines.append(line) elif line[0:4] == 'ANIS': ANISlines.append(line) elif line[0:4] in ['TER ','MAST','CONE','END ']: pass else: self.HeaderLines.append(line) if not line: break for line in self.HeaderLines: if line[0:4] == 'HEAD': self.header = string.strip(line[6:]) if verbose: print "%d atoms" % len(ATOMlines) print "%d hetero atoms" % len(HETATMlines) print "%d header lines" % len(otherlines) # next make a list of lines for the amino acids and nucleotides AATypes = parms.get('AATypes') NUCTypes = parms.get('NUCTypes') WATTypes = parms.get('WATTypes') AAlines = [] NUClines = [] WATlines = [] OTHlines = [] for line in ATOMlines: if line[17:20] in AATypes: AAlines.append(line) elif line[17:20] in NUCTypes: NUClines.append(line) elif line[17:20] in WATTypes: WATlines.append(line) else: OTHlines.append(line) for line in HETATMlines: if line[17:20] in WATTypes: WATlines.append(line) else: OTHlines.append(line) # now separate the chains # first collect the chain names for AAlines if len(AAlines) > 0: proteinchainlist = [] for line in AAlines: if line[21:22] in proteinchainlist: pass else: proteinchainlist.append(line[21:22]) # and create a list for each separatedlists = [] for chainname in proteinchainlist: newlist = [] for line in AAlines: if chainname == line[21:22]: newlist.append(line) separatedlists.append(newlist) # now create all of the Protein objects for slist in separatedlists: newprotein = Protein(slist, self) self.ProteinList.append(newprotein) # next make a list of all nucleotide lines # and create all of the NucleotideChain objects if len(NUClines) > 0: NUCchainlist = [] for line in NUClines: if line[21:22]in NUCchainlist: pass else: NUCchainlist.append(line[21:22]) if verbose: if len(NUCchainlist) == 1: print "1 nucleotide chain loading" else: print "%d nucleotide chains loading" % len(NUCchainlist) # and create a list for each separatedlists = [] for chainname in NUCchainlist: newlist = [] for line in NUClines: if chainname == line[21:22]: newlist.append(line) separatedlists.append(newlist) # now create all of the Nucleotide chain objects for slist in separatedlists: newnucchain = NucleotideChain(slist, self) self.NucleotideChainList.append(newnucchain) # now make a list of all other molecule types # and create all of the ligand Molecule objects # pass through the list, collecting by residue number if len(OTHlines) > 0: last_rez_num = None current_molecule = [] for line in OTHlines: current_rez_num = string.atoi(line[23:26]) if current_rez_num == last_rez_num: current_molecule.append(line) else: if len(current_molecule)>0: new_molecule = Ligand(current_molecule, self) self.LigandList.append(new_molecule) current_molecule = [] current_molecule.append(line) last_rez_num = current_rez_num new_molecule = Ligand(current_molecule, self) self.LigandList.append(new_molecule) mol_names = [] for mol in self.LigandList: mol_names.append(mol.res_type) if verbose: if len(self.LigandList) == 1: print "1 ligand molecule %s" % (mol_names) else: print "%d ligand molecules %s" % (len(self.LigandList), mol_names) # once ligands have been read in, then process the water list # so that they can be numbered sequentially if len(WATlines) > 0: last_rez_num = None current_molecule = [] for line in WATlines: current_rez_num = line[23:26] if current_rez_num == last_rez_num: current_molecule.append(line) else: if len(current_molecule)>0: new_molecule = Water(current_molecule,self) self.WaterList.append(new_molecule) current_molecule = [] current_molecule.append(line) last_rez_num = current_rez_num if len(current_molecule) > 0: new_molecule = Water(current_molecule,self) self.WaterList.append(new_molecule) if verbose: if len(self.WaterList) == 1: print "1 water molecule" else: print "%d water molecules" % (len(self.WaterList)) PDBfile.close() self._supplementary_initialization()
def load_pdb(self, filename): print "Opening pdb file %s\n" % (os.path.split(filename)[1]) """ parse a pdb file and load it as a system object.""" self.filename = filename self.selected = 1 self.ProteinList = [] self.NucleotideChainList = [] self.LigandList = [] self.WaterList = [] self.HeaderLines = [] self.HBonds = [] self.header = '' # open the file if len(filename) == 0: return PDBfile = open(filename, 'r') # separate atoms, HETATMS, and other ATOMlines = [] HETATMlines = [] ANISlines = [] # anisotropy cards are ignored otherlines = [] while 1: line = PDBfile.readline() # should be able to tell from the first 4 characters of each line if line[0:4] == 'ATOM': ATOMlines.append(line) elif line[0:4] == 'HETA': HETATMlines.append(line) elif line[0:4] == 'ANIS': ANISlines.append(line) elif line[0:4] in ['TER ', 'MAST', 'CONE', 'END ']: pass else: self.HeaderLines.append(line) if not line: break for line in self.HeaderLines: if line[0:4] == 'HEAD': self.header = string.strip(line[6:]) if verbose: print "%d atoms" % len(ATOMlines) print "%d hetero atoms" % len(HETATMlines) print "%d header lines" % len(otherlines) # next make a list of lines for the amino acids and nucleotides AATypes = parms.get('AATypes') NUCTypes = parms.get('NUCTypes') WATTypes = parms.get('WATTypes') AAlines = [] NUClines = [] WATlines = [] OTHlines = [] for line in ATOMlines: if line[17:20] in AATypes: AAlines.append(line) elif line[17:20] in NUCTypes: NUClines.append(line) elif line[17:20] in WATTypes: WATlines.append(line) else: OTHlines.append(line) for line in HETATMlines: if line[17:20] in WATTypes: WATlines.append(line) else: OTHlines.append(line) # now separate the chains # first collect the chain names for AAlines if len(AAlines) > 0: proteinchainlist = [] for line in AAlines: if line[21:22] in proteinchainlist: pass else: proteinchainlist.append(line[21:22]) # and create a list for each separatedlists = [] for chainname in proteinchainlist: newlist = [] for line in AAlines: if chainname == line[21:22]: newlist.append(line) separatedlists.append(newlist) # now create all of the Protein objects for slist in separatedlists: newprotein = Protein(slist, self) self.ProteinList.append(newprotein) # next make a list of all nucleotide lines # and create all of the NucleotideChain objects if len(NUClines) > 0: NUCchainlist = [] for line in NUClines: if line[21:22] in NUCchainlist: pass else: NUCchainlist.append(line[21:22]) if verbose: if len(NUCchainlist) == 1: print "1 nucleotide chain loading" else: print "%d nucleotide chains loading" % len(NUCchainlist) # and create a list for each separatedlists = [] for chainname in NUCchainlist: newlist = [] for line in NUClines: if chainname == line[21:22]: newlist.append(line) separatedlists.append(newlist) # now create all of the Nucleotide chain objects for slist in separatedlists: newnucchain = NucleotideChain(slist, self) self.NucleotideChainList.append(newnucchain) # now make a list of all other molecule types # and create all of the ligand Molecule objects # pass through the list, collecting by residue number if len(OTHlines) > 0: last_rez_num = None current_molecule = [] for line in OTHlines: current_rez_num = string.atoi(line[23:26]) if current_rez_num == last_rez_num: current_molecule.append(line) else: if len(current_molecule) > 0: new_molecule = Ligand(current_molecule, self) self.LigandList.append(new_molecule) current_molecule = [] current_molecule.append(line) last_rez_num = current_rez_num new_molecule = Ligand(current_molecule, self) self.LigandList.append(new_molecule) mol_names = [] for mol in self.LigandList: mol_names.append(mol.res_type) if verbose: if len(self.LigandList) == 1: print "1 ligand molecule %s" % (mol_names) else: print "%d ligand molecules %s" % (len( self.LigandList), mol_names) # once ligands have been read in, then process the water list # so that they can be numbered sequentially if len(WATlines) > 0: last_rez_num = None current_molecule = [] for line in WATlines: current_rez_num = line[23:26] if current_rez_num == last_rez_num: current_molecule.append(line) else: if len(current_molecule) > 0: new_molecule = Water(current_molecule, self) self.WaterList.append(new_molecule) current_molecule = [] current_molecule.append(line) last_rez_num = current_rez_num if len(current_molecule) > 0: new_molecule = Water(current_molecule, self) self.WaterList.append(new_molecule) if verbose: if len(self.WaterList) == 1: print "1 water molecule" else: print "%d water molecules" % (len(self.WaterList)) PDBfile.close() self._supplementary_initialization()
def __init__(self, pth, parent=None, toplevel=None, viewer=None): Frame.__init__(self, bg='white') self.focus() self.scopViewer = viewer #The top pane in the viewer represents the SCOP Browser frame self.topFrame = parent.pane('top') #The bottom pane in the viewer represents the Molecular Viewer self.toplevel = parent.pane('bottom') self.viewer_window = toplevel self.dirpath = pth self.isCurrentProfileSaved = 0 self.currentProfileName = "" if self.dirpath.find(parms.get('profilesPath')) == 0 and self.dirpath.find(parms.get('saveResultsin')) != 0: pt = self.dirpath if pt[len(pt)-1] == '\\': self.currentProfileName = self.dirpath[self.dirpath[:-1].rindex('\\')+1:-1] else: self.currentProfileName = self.dirpath[self.dirpath.rindex('\\')+1:] self.isCurrentProfileSaved = 1 print "HERE++++++++++++"+self.currentProfileName+" -- "+self.dirpath self.nodesList = [] self.nodesNames = [] self.removedNames = [] self.nodesLineage = [] self.nodesScop = [] self.domainsScop = [] self.nameHierarchy = parms.get('nameHierarchy') if self.dirpath[len(self.dirpath)-1] != '\\': self.dirpath = self.dirpath + '\\' #Loads the profile/search results from the path given self.getAllNodes() print "Nodes SCOP: "+str(len(self.nodesScop)) self.balloon = Pmw.Balloon(self.topFrame) self.menuBar = Pmw.MenuBar(self.topFrame, hull_relief=RAISED, hull_borderwidth=1, balloon=self.balloon) self.menuBar.pack(fill=X, expand=NO, anchor=N) self.menuBar.addmenu('Profiles', 'Search Profiles') self.menuBar.addmenuitem('Profiles', 'command', command=self.saveCurrentProfile, label='Save Profile') self.menuBar.addmenuitem('Profiles', 'command', command=self.loadProfile, label='Load Profile') self.menuBar.addmenuitem('Profiles', 'command', command=self.editProfile, label='Edit Profile(s)') self.menuBar.addmenu('Edit', 'Edit Results') self.menuBar.addmenuitem('Edit', 'command', command=self.removeSelectedNode, label='Remove Node') self.menuBar.addmenu('SCOP', 'Search Entire SCOP Database') self.menuBar.addmenuitem('SCOP', 'command', label='View Selected Node in SCOP Domain Viewer', command=self.dispInScopDomViewer) self.treeWinText = Pmw.ScrolledText(self.topFrame, labelpos = 'n', usehullsize = 1, label_text='SCOP Search Results', hull_width = 100, hull_height = 20, text_padx = 1, text_pady = 1, text_wrap='none', text_cursor='arrow') self.treeWinText.pack(side=LEFT, expand=YES, fill=BOTH) self.pack(expand=YES, fill=BOTH) self.lineageBox = Text(self.topFrame, relief=FLAT, cursor = "arrow") self.lineageBox.pack(side=TOP, anchor=N) self.lineageBox.config(height=12, width=38, state=DISABLED) self.viewButton = Button(self.topFrame, text="View", state=DISABLED, height=1, command=self.displaySelected, width=5) self.viewButton.pack(side=LEFT, anchor=S, padx=10) self.scopNodeId = 0 self.lines = 1 #Load all the toplevel nodes (all of type 'Class') into the textbox for item in self.nodesScop: self.scopNodeId = self.scopNodeId + 1 self.nodesList.append(ResultsScopNode(item.root, self.scopNodeId, self.topFrame, self)) indx = "%0.1f"%(self.lines) self.treeWinText.window_create(indx, window=self.nodesList[len(self.nodesList)-1]) indx = "%0.1f"%(self.lines+0.1) self.treeWinText.insert(indx, '\n') self.lines = self.lines + 1 #self.currentSelection is updated everytime when a user clicks on a Node in the treeWinText text box self.currentSelection = self.nodesList[0] self.treeWinText.pack() self.treeWinText.configure(text_state='disabled')