PEATDB/Actions.py
def checkModels(self, DB=None, callback=None, selected=None, usemutationcodes=False):
        """Check that we have modelled a structure for everything we can"""
        if DB == None:
            return
        proteins = DB.getRecs()
        refprot = DB.meta.refprotein
        refseq = DB[refprot].aaseq
        refaa = self.AAList2String(refseq)
        refpdb = DB[refprot].Structure
        refpdbfile = os.path.join(os.getcwd(), 'ref.pdb')
        self.writePDB(refpdb, refpdbfile)
        failed = []

        # Check that Protool is loaded
        if not self.MUT:
            self.initProtool()
            
        #Create protool oinstance for ref pdb
        import Protool
        Xref = Protool.structureIO()
        Xref.parsepdb(refpdb)
            
        # Find all potential parents
        records_with_structure=[]
        for protein in proteins:
            rec = DB.get(protein)
            if rec.hasStructure() == 'available':
                records_with_structure.append(protein)
                
        # Loop over selected or all    
        if selected == None:
            selected = list(set(proteins) - set(records_with_structure))
        numrecords=len(selected)
        count=1
                    
        for protein in selected:
            rec = DB.get(protein)
            if rec.hasStructure() == 'available':
                continue                
            print 'Protein:', protein            
            
            #if no sequence try create one from mutation code
            if rec.aaseq == None and rec.Mutations != None:
                #print refaa
                print 'no sequence, using mutation code and ref protein seq'                 
                import PEATSA.Core as Core
                print 'Record has mutation code %s' %rec.Mutations
                mutationSet = Core.Data.MutationSet(rec.Mutations)
                mutseq = mutationSet.applyToSequence(refaa, id='A', pdb=Xref)                 
                rec.aaseq = self.string2AAseq(mutseq)
                     
            parent_with_structure = []
            for parent in records_with_structure:
                parentrec = DB.get(parent)                              
                is_parent, operations = rec.getAncestry(parentrec)
                         
                # We can only model on X-ray structures
                if parentrec.hasStructure() == 'available' and is_parent:                    
                    parent_with_structure.append([parent, len(operations)])

            # Record failure to model
            if parent_with_structure == []:
                continue

            # Find the best parent
            def compare_func(x,y):
                if x[1]>y[1]:
                    return 1
                elif x[1]==y[1]:
                    return 0
                if x[1]<y[1]:
                    return -1
                
            parent_with_structure.sort(cmp=compare_func)
            parent = parent_with_structure[0][0]               
            operations = rec.getAncestry(parentrec)[1]
            print 'Using %s as template with %d operations.' %(parent, len(operations))

            # Start the modelling
            pdblines = parentrec.Structure
            # Load the pdb file
            import Protool
            X=Protool.structureIO()
            X.parsepdb(pdblines)
            self.MUT.new_PDB(X)
            self.MUT.max_tolerated_bump=0.5
            atom_changes=[]
            skip_protein=None
            self.MUT.new_mutation()
            
            for operation in operations:                
                # Is this a deletion?                    
                if operation.find('delete')!=-1:
                    print 'This is a deletion - Jens should write code for modelling this'
                    print 'Deletion ignored for now'
                    continue
                elif operation.find('insert')!=-1:
                    print 'This is an insertion - Jens should write code for modelling insertions'
                    print 'Insertion ignored for now'
                    continue
                
                # This is a normal mutation                    
                # Get the residue number, old residue and new residue               
                import pKa.pKD_tools as pKD_tools
                new_res = pKD_tools.get_newrestyp_from_mut(operation)
                old_res = pKD_tools.get_oldrestyp_from_mut(operation)
                resid = pKD_tools.get_resid_from_mut(operation)
                
                #print operation, resid                
                if not X.residues.has_key(resid):
                    print 'No structural info for mutation %8s. Not modelling this mutation\n' %operation
                    skip_protein=True
                    continue
                
                # Actually make the mutation                
                bump_score=self.MUT.mutate(resid,new_res,orgtype=old_res)
                print 'Mutation: %s, bump_score: %s' %(resid+new_res,str(bump_score))
                if bump_score is None:
                    skip_protein=True
                    break
                else:
                    atom_changes=atom_changes+self.MUT.mutate_operations
                self.MUT.mutate_operations=[]

            # Update progress            
            completion = float(count)/float(numrecords)*100.0
            if callback != None:
                callback(completion)
            else:
                print '%4d of %4d, completion; %5.2f%%' %(count,float(numrecords),completion)
            count=count+1
            
            # Did it work?                
            if skip_protein:         
                print
                print 'Modelling failed for %s' %protein
                failed.append(protein)
                rec.Structure = 'Bumps'
                rec.structuretype = 'failed model'
                continue
            
            # We have all sets of changes in atom_changes           
            rec.Structure = {'Rotamer_operations': atom_changes}
            rec.Structure['parent'] = parent
            rec.structuretype = 'peat model'
            
        print 'Done'
        if len(failed)>0:
            print 'Failed to model the following proteins:'
            for f in failed: print f
        return
Check that we have modelled a structure for everything we can
Check that we have modelled a structure for everything we can
Check that we have modelled a structure for everything we can
def checkModels(self, DB=None, callback=None, selected=None, usemutationcodes=False):
        if DB == None:
            return
        proteins = DB.getRecs()
        refprot = DB.meta.refprotein
        refseq = DB[refprot].aaseq
        refaa = self.AAList2String(refseq)
        refpdb = DB[refprot].Structure
        refpdbfile = os.path.join(os.getcwd(), 'ref.pdb')
        self.writePDB(refpdb, refpdbfile)
        failed = []
        if not self.MUT:
            self.initProtool()
        import Protool
        Xref = Protool.structureIO()
        Xref.parsepdb(refpdb)
        records_with_structure=[]
        for protein in proteins:
            rec = DB.get(protein)
            if rec.hasStructure() == 'available':
                records_with_structure.append(protein)
        if selected == None:
            selected = list(set(proteins) - set(records_with_structure))
        numrecords=len(selected)
        count=1
        for protein in selected:
            rec = DB.get(protein)
            if rec.hasStructure() == 'available':
                continue                
            print 'Protein:', protein            
            if rec.aaseq == None and rec.Mutations != None:
                print 'no sequence, using mutation code and ref protein seq'                 
                import PEATSA.Core as Core
                print 'Record has mutation code %s' %rec.Mutations
                mutationSet = Core.Data.MutationSet(rec.Mutations)
                mutseq = mutationSet.applyToSequence(refaa, id='A', pdb=Xref)                 
                rec.aaseq = self.string2AAseq(mutseq)
            parent_with_structure = []
            for parent in records_with_structure:
                parentrec = DB.get(parent)                              
                is_parent, operations = rec.getAncestry(parentrec)
                if parentrec.hasStructure() == 'available' and is_parent:                    
                    parent_with_structure.append([parent, len(operations)])
            if parent_with_structure == []:
                continue
            def compare_func(x,y):
                if x[1]>y[1]:
                    return 1
                elif x[1]==y[1]:
                    return 0
                if x[1]<y[1]:
                    return -1
            parent_with_structure.sort(cmp=compare_func)
            parent = parent_with_structure[0][0]               
            operations = rec.getAncestry(parentrec)[1]
            print 'Using %s as template with %d operations.' %(parent, len(operations))
            pdblines = parentrec.Structure
            import Protool
            X=Protool.structureIO()
            X.parsepdb(pdblines)
            self.MUT.new_PDB(X)
            self.MUT.max_tolerated_bump=0.5
            atom_changes=[]
            skip_protein=None
            self.MUT.new_mutation()
            for operation in operations:                
                if operation.find('delete')!=-1:
                    print 'This is a deletion - Jens should write code for modelling this'
                    print 'Deletion ignored for now'
                    continue
                elif operation.find('insert')!=-1:
                    print 'This is an insertion - Jens should write code for modelling insertions'
                    print 'Insertion ignored for now'
                    continue
                import pKa.pKD_tools as pKD_tools
                new_res = pKD_tools.get_newrestyp_from_mut(operation)
                old_res = pKD_tools.get_oldrestyp_from_mut(operation)
                resid = pKD_tools.get_resid_from_mut(operation)
                if not X.residues.has_key(resid):
                    print 'No structural info for mutation %8s. Not modelling this mutation\n' %operation
                    skip_protein=True
                    continue
                bump_score=self.MUT.mutate(resid,new_res,orgtype=old_res)
                print 'Mutation: %s, bump_score: %s' %(resid+new_res,str(bump_score))
                if bump_score is None:
                    skip_protein=True
                    break
                else:
                    atom_changes=atom_changes+self.MUT.mutate_operations
                self.MUT.mutate_operations=[]
            completion = float(count)/float(numrecords)*100.0
            if callback != None:
                callback(completion)
            else:
                print '%4d of %4d, completion; %5.2f%%' %(count,float(numrecords),completion)
            count=count+1
            if skip_protein:         
                print
                print 'Modelling failed for %s' %protein
                failed.append(protein)
                rec.Structure = 'Bumps'
                rec.structuretype = 'failed model'
                continue
            rec.Structure = {'Rotamer_operations': atom_changes}
            rec.Structure['parent'] = parent
            rec.structuretype = 'peat model'
        print 'Done'
        if len(failed)>0:
            print 'Failed to model the following proteins:'
            for f in failed: print f
        return
def checkModels ( self , DB = None , callback = None , selected = None , usemutationcodes = False ) : if DB == None : return proteins = DB . getRecs ( ) refprot = DB . meta . refprotein refseq = DB [ refprot ] . aaseq refaa = self . AAList2String ( refseq ) refpdb = DB [ refprot ] . Structure refpdbfile = os . path . join ( os . getcwd ( ) , 'ref.pdb' ) self . writePDB ( refpdb , refpdbfile ) failed = [ ] if not self . MUT : self . initProtool ( ) import Protool Xref = Protool . structureIO ( ) Xref . parsepdb ( refpdb ) records_with_structure = [ ] for protein in proteins : rec = DB . get ( protein ) if rec . hasStructure ( ) == 'available' : records_with_structure . append ( protein ) if selected == None : selected = list ( set ( proteins ) - set ( records_with_structure ) ) numrecords = len ( selected ) count = 1 for protein in selected : rec = DB . get ( protein ) if rec . hasStructure ( ) == 'available' : continue print 'Protein:' , protein if rec . aaseq == None and rec . Mutations != None : print 'no sequence, using mutation code and ref protein seq' import PEATSA . Core as Core print 'Record has mutation code %s' % rec . Mutations mutationSet = Core . Data . MutationSet ( rec . Mutations ) mutseq = mutationSet . applyToSequence ( refaa , id = 'A' , pdb = Xref ) rec . aaseq = self . string2AAseq ( mutseq ) parent_with_structure = [ ] for parent in records_with_structure : parentrec = DB . get ( parent ) is_parent , operations = rec . getAncestry ( parentrec ) if parentrec . hasStructure ( ) == 'available' and is_parent : parent_with_structure . append ( [ parent , len ( operations ) ] ) if parent_with_structure == [ ] : continue def compare_func ( x , y ) : if x [ 1 ] > y [ 1 ] : return 1 elif x [ 1 ] == y [ 1 ] : return 0 if x [ 1 ] < y [ 1 ] : return - 1 parent_with_structure . sort ( cmp = compare_func ) parent = parent_with_structure [ 0 ] [ 0 ] operations = rec . getAncestry ( parentrec ) [ 1 ] print 'Using %s as template with %d operations.' % ( parent , len ( operations ) ) pdblines = parentrec . Structure import Protool X = Protool . structureIO ( ) X . parsepdb ( pdblines ) self . MUT . new_PDB ( X ) self . MUT . max_tolerated_bump = 0.5 atom_changes = [ ] skip_protein = None self . MUT . new_mutation ( ) for operation in operations : if operation . find ( 'delete' ) != - 1 : print 'This is a deletion - Jens should write code for modelling this' print 'Deletion ignored for now' continue elif operation . find ( 'insert' ) != - 1 : print 'This is an insertion - Jens should write code for modelling insertions' print 'Insertion ignored for now' continue import pKa . pKD_tools as pKD_tools new_res = pKD_tools . get_newrestyp_from_mut ( operation ) old_res = pKD_tools . get_oldrestyp_from_mut ( operation ) resid = pKD_tools . get_resid_from_mut ( operation ) if not X . residues . has_key ( resid ) : print 'No structural info for mutation %8s. Not modelling this mutation\n' % operation skip_protein = True continue bump_score = self . MUT . mutate ( resid , new_res , orgtype = old_res ) print 'Mutation: %s, bump_score: %s' % ( resid + new_res , str ( bump_score ) ) if bump_score is None : skip_protein = True break else : atom_changes = atom_changes + self . MUT . mutate_operations self . MUT . mutate_operations = [ ] completion = float ( count ) / float ( numrecords ) * 100.0 if callback != None : callback ( completion ) else : print '%4d of %4d, completion; %5.2f%%' % ( count , float ( numrecords ) , completion ) count = count + 1 if skip_protein : print print 'Modelling failed for %s' % protein failed . append ( protein ) rec . Structure = 'Bumps' rec . structuretype = 'failed model' continue rec . Structure = { 'Rotamer_operations' : atom_changes } rec . Structure [ 'parent' ] = parent rec . structuretype = 'peat model' print 'Done' if len ( failed ) > 0 : print 'Failed to model the following proteins:' for f in failed : print f return
Check that we have modelled a structure for everything we can
Check that we have modelled a structure for everything we can
"""Check that we have modelled a structure for everything we can""" # Check that Protool is loaded #Create protool oinstance for ref pdb # Find all potential parents # Loop over selected or all     #if no sequence try create one from mutation code #print refaa # We can only model on X-ray structures # Record failure to model # Find the best parent # Start the modelling # Load the pdb file # Is this a deletion?                     # This is a normal mutation                     # Get the residue number, old residue and new residue                #print operation, resid                 # Actually make the mutation                 # Update progress             # Did it work?                 # We have all sets of changes in atom_changes           
self
DB
callback
selected
usemutationcodes