PEATDB/PEATApp.py
def startDNAtool(self, data=None):
        """Start DNAtool - this function is far too long and should be simplified"""
        self.DNAtool_instance = None
        if self.DB == None:
            return
        DB = self.DB
        D = DB.data
        M = DB.meta  #DNAtool/primers stuff is now stored in DB.meta

        #change this later
        self.DBfiledir = os.getcwd()

        if not self.DNAtool_instance:

            # Do we have data to pass?
            data_passed = {}
            if self.DNAtool_state:
                data_passed = self.DNAtool_state

            # Load the primer dictionary into the dictionary that are being passed
            data_passed['PEAT_DBrecord']='None'
            data_passed['primer_dict']={}
            if M:
                if M.has_key('DNAtool_primers'):
                    data_passed['primer_dict'] = M['DNAtool_primers'].copy()
            else:
                data_passed['PEAT_DBrecord'] = 'No database'

            # Delete any data that we only transfer if a protein is selected
            if data_passed.has_key('DNAseq'):
                del data_passed['DNAseq']
            if data_passed.has_key('ORF_selected'):
                del data_passed['ORF_selected']

            #Get the DNA sequence and ORF info from the currently selected protein
            sel_prot = self.table.get_selectedRecordNames()[0]

            # Now pass the data
            if sel_prot:
                data_passed['PEAT_DBrecord'] = sel_prot
                import types

                if D[sel_prot].has_key('DNAseq') and D[sel_prot].DNAseq != None:
                    data_passed['DNAseq'] = D[sel_prot].DNAseq

                    # ORF info
                    data_passed['ORF_selected']={}
                    keys=['start','aastart_number','frame','stop','length','aaseq','aaseq3']
                    for key in keys:
                        if D[sel_prot]['ORF_selected'].has_key(key):
                            data_passed['ORF_selected'][key] = D[sel_prot]['ORF_selected'][key]

                    # If we didn't find any data, then don't copy anything
                    if len(data_passed['ORF_selected'].keys())==0:
                        del data_passed['ORF_selected']

            # Now start DNAtool
            import DNAtool.DNAtool as DNAtool
            self.DNAtool_instance=DNAtool.MainWindow(self, data_passed)
            self.master.wait_window(self.DNAtool_instance.master) # Wait for DNAtool to finish
            self.DNAtool_instance=None

            # We came back from DNAtool.
            if self.DNAtool_state:
                if self.DNAtool_state['DNAseq_status']=='MODIFY RECORD':
                    # Modify the present record
                    self.DNAtool_state['DNAseq_status']='OK'

                elif self.DNAtool_state['DNAseq_status']=='NEW SEQ':
                    # Added this in as a fix to modify record when no seq previously
                    if sel_prot:
                        DNAdata = self.DNAtool_state
                        ok = DB.addDNAseq(sel_prot, DNAdata['DNAseq'])
                        data = DNAdata['ORF_selected']
                        ok = DB.addProperty(sel_prot, 'ORF_selected', data)

                        if not ok:
                            raise 'Something went wrong when adding ORF info'

                        #Add the protein sequence
                        ok=DB.addProtseq(sel_prot, DNAdata['ORF_selected']['aaseq3'],
                                                    DNAdata['ORF_selected']['aastart_number'])
                        if not ok:
                            raise 'Something went wrong when adding the protein sequence'

                #this deals with changing the record in-place only when ORF is changed
                elif self.DNAtool_state['DNAseq_status']=='MODIFY ORF':
                    DNAdata=self.DNAtool_state
                    #Now do a check to see if frame has been changed
                    if D[sel_prot].has_key('ORF_selected'):
                        currframe=D[sel_prot]['ORF_selected']['frame']
                        newframe=self.DNAtool_state['ORF_selected']['frame']

                        if currframe!=newframe:
                            import tkMessageBox
                            tkMessageBox.showerror(title='Frame Changed',
                                message='Frame has been changed. You cannot save this in the same record!',
                                parent=self.master)
                            pass
                        else:
                            D[sel_prot]['ORF_selected']=DNAdata['ORF_selected']

                elif self.DNAtool_state['DNAseq_status']=='ADD NEW RECORD':

                    # Add a new protein record
                    #print "DNAtool_state['DNAseq_mutations']", self.DNAtool_state['DNAseq_mutations']
                    self.DNAtool_state['DNAseq_status']='OK'
                    initialvalue=self.DB.get_next_freename_newprot()
                    if self.DNAtool_state.has_key('DNAseq_mutations'):
                        mutations=self.DNAtool_state['DNAseq_mutations']
                        import DNAtool.mutation
                        mutant_text=''
                        if sel_prot:
                            mutant_text=sel_prot+'+'
                        for mut in mutations:
                            old=DNAtool.mutation.three_to_one[mut.split(':')[1]]
                            number=mut.split(':')[2]
                            new=DNAtool.mutation.three_to_one[mut.split(':')[-1]]
                            mutant_text=mutant_text+'%s%s%s+' %(old,number,new)
                        initialvalue=mutant_text[:-1]

                    # Get the name for the mutation
                    ok=None
                    while not ok:
                        import tkSimpleDialog
                        record_name=tkSimpleDialog.askstring('Record name',
                                                'Give a name for the new record',
                        initialvalue=initialvalue,parent=self.master)
                        if not record_name:
                            return

                        # Store the data
                        ok=DB.newmolecule(record_name)
                        if not ok:
                            self.warning('Name already in use',
                                         '%s is already in use' %record_name)

                    # Got the name, now just fill in the fields
                    DNAdata=self.DNAtool_state
                    ok=self.DB.addDNAseq(record_name, DNAdata['DNAseq'])
                    data=DNAdata['ORF_selected']
                    ok=self.DB[record_name]['ORF_selected'] = data
                    if not ok:
                        raise 'Something went wrong when adding ORF info'

                    # Add the protein sequence
                    ok=self.DB.addProtseq(record_name, DNAdata['ORF_selected']['aaseq3'],
                                                   DNAdata['ORF_selected']['aastart_number'])
                    if not ok:
                        raise 'Something went wrong when addding the protein sequence'

                    #add a code for the mutation, this can be parsed to create
                    #a PEATSA mutationset later
                    ref = self.DB.meta.refprotein
                    #DBActions.checkMutation(self.DB, record_name, ref)
                    self.updateTable(record_name, 'Mutations')
        return
Start DNAtool - this function is far too long and should be simplified
Start DNAtool - this function is far too long and should be simplified
Start DNAtool - this function is far too long and should be simplified
def startDNAtool(self, data=None):
        self.DNAtool_instance = None
        if self.DB == None:
            return
        DB = self.DB
        D = DB.data
        M = DB.meta  
        self.DBfiledir = os.getcwd()
        if not self.DNAtool_instance:
            data_passed = {}
            if self.DNAtool_state:
                data_passed = self.DNAtool_state
            data_passed['PEAT_DBrecord']='None'
            data_passed['primer_dict']={}
            if M:
                if M.has_key('DNAtool_primers'):
                    data_passed['primer_dict'] = M['DNAtool_primers'].copy()
            else:
                data_passed['PEAT_DBrecord'] = 'No database'
            if data_passed.has_key('DNAseq'):
                del data_passed['DNAseq']
            if data_passed.has_key('ORF_selected'):
                del data_passed['ORF_selected']
            sel_prot = self.table.get_selectedRecordNames()[0]
            if sel_prot:
                data_passed['PEAT_DBrecord'] = sel_prot
                import types
                if D[sel_prot].has_key('DNAseq') and D[sel_prot].DNAseq != None:
                    data_passed['DNAseq'] = D[sel_prot].DNAseq
                    data_passed['ORF_selected']={}
                    keys=['start','aastart_number','frame','stop','length','aaseq','aaseq3']
                    for key in keys:
                        if D[sel_prot]['ORF_selected'].has_key(key):
                            data_passed['ORF_selected'][key] = D[sel_prot]['ORF_selected'][key]
                    if len(data_passed['ORF_selected'].keys())==0:
                        del data_passed['ORF_selected']
            import DNAtool.DNAtool as DNAtool
            self.DNAtool_instance=DNAtool.MainWindow(self, data_passed)
            self.master.wait_window(self.DNAtool_instance.master) 
            self.DNAtool_instance=None
            if self.DNAtool_state:
                if self.DNAtool_state['DNAseq_status']=='MODIFY RECORD':
                    self.DNAtool_state['DNAseq_status']='OK'
                elif self.DNAtool_state['DNAseq_status']=='NEW SEQ':
                    if sel_prot:
                        DNAdata = self.DNAtool_state
                        ok = DB.addDNAseq(sel_prot, DNAdata['DNAseq'])
                        data = DNAdata['ORF_selected']
                        ok = DB.addProperty(sel_prot, 'ORF_selected', data)
                        if not ok:
                            raise 'Something went wrong when adding ORF info'
                        ok=DB.addProtseq(sel_prot, DNAdata['ORF_selected']['aaseq3'],
                                                    DNAdata['ORF_selected']['aastart_number'])
                        if not ok:
                            raise 'Something went wrong when adding the protein sequence'
                elif self.DNAtool_state['DNAseq_status']=='MODIFY ORF':
                    DNAdata=self.DNAtool_state
                    if D[sel_prot].has_key('ORF_selected'):
                        currframe=D[sel_prot]['ORF_selected']['frame']
                        newframe=self.DNAtool_state['ORF_selected']['frame']
                        if currframe!=newframe:
                            import tkMessageBox
                            tkMessageBox.showerror(title='Frame Changed',
                                message='Frame has been changed. You cannot save this in the same record!',
                                parent=self.master)
                            pass
                        else:
                            D[sel_prot]['ORF_selected']=DNAdata['ORF_selected']
                elif self.DNAtool_state['DNAseq_status']=='ADD NEW RECORD':
                    self.DNAtool_state['DNAseq_status']='OK'
                    initialvalue=self.DB.get_next_freename_newprot()
                    if self.DNAtool_state.has_key('DNAseq_mutations'):
                        mutations=self.DNAtool_state['DNAseq_mutations']
                        import DNAtool.mutation
                        mutant_text=''
                        if sel_prot:
                            mutant_text=sel_prot+'+'
                        for mut in mutations:
                            old=DNAtool.mutation.three_to_one[mut.split(':')[1]]
                            number=mut.split(':')[2]
                            new=DNAtool.mutation.three_to_one[mut.split(':')[-1]]
                            mutant_text=mutant_text+'%s%s%s+' %(old,number,new)
                        initialvalue=mutant_text[:-1]
                    ok=None
                    while not ok:
                        import tkSimpleDialog
                        record_name=tkSimpleDialog.askstring('Record name',
                                                'Give a name for the new record',
                        initialvalue=initialvalue,parent=self.master)
                        if not record_name:
                            return
                        ok=DB.newmolecule(record_name)
                        if not ok:
                            self.warning('Name already in use',
                                         '%s is already in use' %record_name)
                    DNAdata=self.DNAtool_state
                    ok=self.DB.addDNAseq(record_name, DNAdata['DNAseq'])
                    data=DNAdata['ORF_selected']
                    ok=self.DB[record_name]['ORF_selected'] = data
                    if not ok:
                        raise 'Something went wrong when adding ORF info'
                    ok=self.DB.addProtseq(record_name, DNAdata['ORF_selected']['aaseq3'],
                                                   DNAdata['ORF_selected']['aastart_number'])
                    if not ok:
                        raise 'Something went wrong when addding the protein sequence'
                    ref = self.DB.meta.refprotein
                    self.updateTable(record_name, 'Mutations')
        return
def startDNAtool ( self , data = None ) : self . DNAtool_instance = None if self . DB == None : return DB = self . DB D = DB . data M = DB . meta self . DBfiledir = os . getcwd ( ) if not self . DNAtool_instance : data_passed = { } if self . DNAtool_state : data_passed = self . DNAtool_state data_passed [ 'PEAT_DBrecord' ] = 'None' data_passed [ 'primer_dict' ] = { } if M : if M . has_key ( 'DNAtool_primers' ) : data_passed [ 'primer_dict' ] = M [ 'DNAtool_primers' ] . copy ( ) else : data_passed [ 'PEAT_DBrecord' ] = 'No database' if data_passed . has_key ( 'DNAseq' ) : del data_passed [ 'DNAseq' ] if data_passed . has_key ( 'ORF_selected' ) : del data_passed [ 'ORF_selected' ] sel_prot = self . table . get_selectedRecordNames ( ) [ 0 ] if sel_prot : data_passed [ 'PEAT_DBrecord' ] = sel_prot import types if D [ sel_prot ] . has_key ( 'DNAseq' ) and D [ sel_prot ] . DNAseq != None : data_passed [ 'DNAseq' ] = D [ sel_prot ] . DNAseq data_passed [ 'ORF_selected' ] = { } keys = [ 'start' , 'aastart_number' , 'frame' , 'stop' , 'length' , 'aaseq' , 'aaseq3' ] for key in keys : if D [ sel_prot ] [ 'ORF_selected' ] . has_key ( key ) : data_passed [ 'ORF_selected' ] [ key ] = D [ sel_prot ] [ 'ORF_selected' ] [ key ] if len ( data_passed [ 'ORF_selected' ] . keys ( ) ) == 0 : del data_passed [ 'ORF_selected' ] import DNAtool . DNAtool as DNAtool self . DNAtool_instance = DNAtool . MainWindow ( self , data_passed ) self . master . wait_window ( self . DNAtool_instance . master ) self . DNAtool_instance = None if self . DNAtool_state : if self . DNAtool_state [ 'DNAseq_status' ] == 'MODIFY RECORD' : self . DNAtool_state [ 'DNAseq_status' ] = 'OK' elif self . DNAtool_state [ 'DNAseq_status' ] == 'NEW SEQ' : if sel_prot : DNAdata = self . DNAtool_state ok = DB . addDNAseq ( sel_prot , DNAdata [ 'DNAseq' ] ) data = DNAdata [ 'ORF_selected' ] ok = DB . addProperty ( sel_prot , 'ORF_selected' , data ) if not ok : raise 'Something went wrong when adding ORF info' ok = DB . addProtseq ( sel_prot , DNAdata [ 'ORF_selected' ] [ 'aaseq3' ] , DNAdata [ 'ORF_selected' ] [ 'aastart_number' ] ) if not ok : raise 'Something went wrong when adding the protein sequence' elif self . DNAtool_state [ 'DNAseq_status' ] == 'MODIFY ORF' : DNAdata = self . DNAtool_state if D [ sel_prot ] . has_key ( 'ORF_selected' ) : currframe = D [ sel_prot ] [ 'ORF_selected' ] [ 'frame' ] newframe = self . DNAtool_state [ 'ORF_selected' ] [ 'frame' ] if currframe != newframe : import tkMessageBox tkMessageBox . showerror ( title = 'Frame Changed' , message = 'Frame has been changed. You cannot save this in the same record!' , parent = self . master ) pass else : D [ sel_prot ] [ 'ORF_selected' ] = DNAdata [ 'ORF_selected' ] elif self . DNAtool_state [ 'DNAseq_status' ] == 'ADD NEW RECORD' : self . DNAtool_state [ 'DNAseq_status' ] = 'OK' initialvalue = self . DB . get_next_freename_newprot ( ) if self . DNAtool_state . has_key ( 'DNAseq_mutations' ) : mutations = self . DNAtool_state [ 'DNAseq_mutations' ] import DNAtool . mutation mutant_text = '' if sel_prot : mutant_text = sel_prot + '+' for mut in mutations : old = DNAtool . mutation . three_to_one [ mut . split ( ':' ) [ 1 ] ] number = mut . split ( ':' ) [ 2 ] new = DNAtool . mutation . three_to_one [ mut . split ( ':' ) [ - 1 ] ] mutant_text = mutant_text + '%s%s%s+' % ( old , number , new ) initialvalue = mutant_text [ : - 1 ] ok = None while not ok : import tkSimpleDialog record_name = tkSimpleDialog . askstring ( 'Record name' , 'Give a name for the new record' , initialvalue = initialvalue , parent = self . master ) if not record_name : return ok = DB . newmolecule ( record_name ) if not ok : self . warning ( 'Name already in use' , '%s is already in use' % record_name ) DNAdata = self . DNAtool_state ok = self . DB . addDNAseq ( record_name , DNAdata [ 'DNAseq' ] ) data = DNAdata [ 'ORF_selected' ] ok = self . DB [ record_name ] [ 'ORF_selected' ] = data if not ok : raise 'Something went wrong when adding ORF info' ok = self . DB . addProtseq ( record_name , DNAdata [ 'ORF_selected' ] [ 'aaseq3' ] , DNAdata [ 'ORF_selected' ] [ 'aastart_number' ] ) if not ok : raise 'Something went wrong when addding the protein sequence' ref = self . DB . meta . refprotein self . updateTable ( record_name , 'Mutations' ) return
Start DNAtool - this function is far too long and should be simplified
Start DNAtool - this function is far too long and should be simplified
"""Start DNAtool - this function is far too long and should be simplified""" #DNAtool/primers stuff is now stored in DB.meta #change this later # Do we have data to pass? # Load the primer dictionary into the dictionary that are being passed # Delete any data that we only transfer if a protein is selected #Get the DNA sequence and ORF info from the currently selected protein # Now pass the data # ORF info # If we didn't find any data, then don't copy anything # Now start DNAtool # Wait for DNAtool to finish # We came back from DNAtool. # Modify the present record # Added this in as a fix to modify record when no seq previously #Add the protein sequence #this deals with changing the record in-place only when ORF is changed #Now do a check to see if frame has been changed # Add a new protein record #print "DNAtool_state['DNAseq_mutations']", self.DNAtool_state['DNAseq_mutations'] # Get the name for the mutation # Store the data # Got the name, now just fill in the fields # Add the protein sequence #add a code for the mutation, this can be parsed to create #a PEATSA mutationset later #DBActions.checkMutation(self.DB, record_name, ref)
self
data