PEATDB/DNAtool/mutation.py
def exhaustive_research(DNA_sequence,AA_number,NewAA,Tm_desired,Tm_method,enzyme_list=None,
                        parent=None,primer_max_len=30,find_restriction_site=None):
    """Generate a primer for introducing the required mutation by generating all possible DNA_sequences
    that will produce the amino acid sequence, and then scoring all of them for Tm, number of mismatches and
    restriction sites introduced"""
    #
    # Make the mutation in the DNA
    #
    codons=get_codons(NewAA)
    base_position=(AA_number-1)*3
    mut_DNA=DNA_sequence[:base_position]+'XXX'+DNA_sequence[base_position+3:]
    #
    # Get the Amino acid sequence from 5 aa (15 bases) up and downstream if possible
    #
    DNA_start=base_position-int(0.5*primer_max_len)
    DNA_end=base_position+int(0.5*primer_max_len)
    if DNA_start<0:
        DNA_end=DNA_end+abs(DNA_start)
        DNA_start=0
    if DNA_end>len(DNA_sequence):
        DNA_end=len(DNA_sequence)
    #
    # Find the base count of the mutation
    #
    primer_template=mut_DNA[DNA_start:DNA_end]
    mut_pos=primer_template.find('XXX')
    primer_template=primer_template.replace('XXX',codons[0])
    AA_sequence3,AA_sequence_1=translate(primer_template)
    AA_sequence3=AA_sequence3[0] # We are only interested in the first reading frame
    #
    # Keep a record of the template DNA
    #
    DNA_template=DNA_sequence[DNA_start:DNA_end]
    #
    # Generate all base sequences that will produce this amino acid sequuence
    #
    # We start by introducing as few mutations as possible, and end of with ?
    #
    res_comb = []
    max_permutations=20000
    #for codons_in_play in range(1,11):
    #    pass
    #print 'Mutated AA',AA_sequence3[AA_number]
    #print AA_sequence
    #stop
    for item in AA_sequence3:
        res_comb.append(inverse_genetic_code[item])
    #
    # Call add_next
    #
    primers_comb=add_next(res_comb)
    #
    # Now we search for all the restriction sites on all the primers. Compare them with the ones present in the
    # DNAsequence and creates two different Dictionaries for them.
    #
    characteristics={}
    #
    # Instantiate the scan_primer class
    #
    SCAN=scan_primer(DNA_sequence)
    #
    # Loop over all primers
    #
    print 'Found %d primers in total' %(len(primers_comb))
    count=0
    parent.prog_can.create_text(5,5,text="Diversity generation",anchor='nw')
    box=None
    for comb in primers_comb:
        count=count+1
        #
        # The progress bar
        #
        if parent.cancelled:
            return None,None,None
        parent.update_primer_progress(float(count)/float(len(primers_comb)),1)
        #
        # Find sub-fragments of this primer that have the correct Tm
        #
        primer_length=len(comb)
        min_primer_length=15
        for primer_start in range(0,12,3):
            for primer_end in range(1,13,3):
                primer_seq=comb[primer_start:-primer_end]
                Tm,mismatches,Tm_method_used=get_primer_Tm(DNA_template,primer_seq,primer_start,Tm_method)
                if abs(Tm-Tm_desired)<4.0:
                    #
                    # Scan for other binding sites
                    #
                    characteristics[primer_seq]={'Tm':Tm,'mismatches':mismatches}
                if Tm<Tm_desired-4.0:
                    break
            #
            if primer_end<3 and Tm<Tm_desired-4.0:
                break
    print 'I found %7d combinations with a Tm less than 4K from the desired Tm' %(len(characteristics.keys()))
    print '--------------------------------------'
    #
    # Perform the resitriction site analysis
    #
    # Instantiate the restriction site class and get the restriction sites for the wt sequence
    #
    RS=restriction_digest() # This one calls the __init__ function
    rest_sites_DNATOT=RS.get_restriction_sites (DNA_sequence, enzyme_list)
    #
    # Finds all the restriction enzymes for each primer
    #
    rest_enzymes_primer = {}
    for primer in characteristics.keys():
        rest_enzymes_primer[primer]=RS.get_restriction_sites(primer,enzyme_list)
    #
    # compare the cut positions in the primer and in the DNAsequence
    #
    enzymes_that_already_cut={}
    new_enzymes={}
    #
    # Print the text
    #
    parent.prog_can.create_text(5,45,text="Primer restriction analysis",anchor='nw')
    count=0
    #
    #
    #
    for primer in characteristics.keys():
        #
        # The progress bar
        #
        if parent.cancelled:
            return None,None,None
        count=count+1
        parent.update_primer_progress(float(count)/float(len(characteristics.keys())),2)
        #
        # Find the enzymes that cut
        #
        for key_primer_enzymes in rest_enzymes_primer[primer].keys():
            if rest_sites_DNATOT.has_key(key_primer_enzymes):
                if not enzymes_that_already_cut.has_key (primer):
                    enzymes_that_already_cut [primer] = []
                enzymes_that_already_cut [primer].append (key_primer_enzymes)
            else:
                if not new_enzymes.has_key (primer):
                    new_enzymes [primer] = []
                new_enzymes[primer].append (key_primer_enzymes)
    #
    # Primer characterisation
    #
    primers_results_dict = {}
    counter=0
    #
    # Calculate self complementarity and hairpin-forming propensity
    #
    parent.prog_can.create_text(5,85,text="Primer characterisation",anchor='nw')
    count=0
    for primer in characteristics.keys():
        #
        # Progress bar
        #
        if parent.cancelled:
            return None,None,None
        count=count+1
        parent.update_primer_progress(float(count)/float(len(characteristics.keys())),3)
        #
        # Get the characteristics
        #
        hairpin_dict, maxscorelist = hairpin_propensity (primer)
        complementarity_dict,maxselfscorelist = self_complementarity_propensity (primer)
        if maxselfscorelist < 8:
            maxselfscorelist = 'OK'
        elif maxselfscorelist >= 8:
            maxselfscorelist = 'BAD'
        if maxscorelist < 8:
            maxscorelist = 'OK'
        elif maxscorelist >= 8:
            maxscorelist = 'BAD'
        #
        # Add the characteristics to the dictionary
        #
        characteristics[primer]['hairpin_prop']=maxscorelist
        characteristics[primer]['self-compl']=maxselfscorelist
    return characteristics, new_enzymes, enzymes_that_already_cut
Generate a primer for introducing the required mutation by generating all possible DNA_sequences
    that will produce the amino acid sequence, and then scoring all of them for Tm, number of mismatches and
    restriction sites introduced
Generate a primer for introducing the required mutation by generating all possible DNA_sequences
that will produce the amino acid sequence, and then scoring all of them for Tm, number of mismatches and
restriction sites introduced
Generate a primer for introducing the required mutation by generating all possible DNA_sequences that will produce the amino acid sequence and then scoring all of them for Tm number of mismatches and restriction sites introduced
def exhaustive_research(DNA_sequence,AA_number,NewAA,Tm_desired,Tm_method,enzyme_list=None,
                        parent=None,primer_max_len=30,find_restriction_site=None):
     Make the mutation in the DNA
    codons=get_codons(NewAA)
    base_position=(AA_number-1)*3
    mut_DNA=DNA_sequence[:base_position]+'XXX'+DNA_sequence[base_position+3:]
     Get the Amino acid sequence from 5 aa (15 bases) up and downstream if possible
    DNA_start=base_position-int(0.5*primer_max_len)
    DNA_end=base_position+int(0.5*primer_max_len)
    if DNA_start<0:
        DNA_end=DNA_end+abs(DNA_start)
        DNA_start=0
    if DNA_end>len(DNA_sequence):
        DNA_end=len(DNA_sequence)
     Find the base count of the mutation
    primer_template=mut_DNA[DNA_start:DNA_end]
    mut_pos=primer_template.find('XXX')
    primer_template=primer_template.replace('XXX',codons[0])
    AA_sequence3,AA_sequence_1=translate(primer_template)
    AA_sequence3=AA_sequence3[0]  We are only interested in the first reading frame
     Keep a record of the template DNA
    DNA_template=DNA_sequence[DNA_start:DNA_end]
     Generate all base sequences that will produce this amino acid sequuence
     We start by introducing as few mutations as possible, and end of with ?
    res_comb = []
    max_permutations=20000
    for codons_in_play in range(1,11):
        pass
    print 'Mutated AA',AA_sequence3[AA_number]
    print AA_sequence
    stop
    for item in AA_sequence3:
        res_comb.append(inverse_genetic_code[item])
     Call add_next
    primers_comb=add_next(res_comb)
     Now we search for all the restriction sites on all the primers. Compare them with the ones present in the
     DNAsequence and creates two different Dictionaries for them.
    characteristics={}
     Instantiate the scan_primer class
    SCAN=scan_primer(DNA_sequence)
     Loop over all primers
    print 'Found %d primers in total' %(len(primers_comb))
    count=0
    parent.prog_can.create_text(5,5,text="Diversity generation",anchor='nw')
    box=None
    for comb in primers_comb:
        count=count+1
         The progress bar
        if parent.cancelled:
            return None,None,None
        parent.update_primer_progress(float(count)/float(len(primers_comb)),1)
         Find sub-fragments of this primer that have the correct Tm
        primer_length=len(comb)
        min_primer_length=15
        for primer_start in range(0,12,3):
            for primer_end in range(1,13,3):
                primer_seq=comb[primer_start:-primer_end]
                Tm,mismatches,Tm_method_used=get_primer_Tm(DNA_template,primer_seq,primer_start,Tm_method)
                if abs(Tm-Tm_desired)<4.0:
                     Scan for other binding sites
                    characteristics[primer_seq]={'Tm':Tm,'mismatches':mismatches}
                if Tm<Tm_desired-4.0:
                    break
            if primer_end<3 and Tm<Tm_desired-4.0:
                break
    print 'I found %7d combinations with a Tm less than 4K from the desired Tm' %(len(characteristics.keys()))
    print '--------------------------------------'
     Perform the resitriction site analysis
     Instantiate the restriction site class and get the restriction sites for the wt sequence
    RS=restriction_digest()  This one calls the __init__ function
    rest_sites_DNATOT=RS.get_restriction_sites (DNA_sequence, enzyme_list)
     Finds all the restriction enzymes for each primer
    rest_enzymes_primer = {}
    for primer in characteristics.keys():
        rest_enzymes_primer[primer]=RS.get_restriction_sites(primer,enzyme_list)
     compare the cut positions in the primer and in the DNAsequence
    enzymes_that_already_cut={}
    new_enzymes={}
     Print the text
    parent.prog_can.create_text(5,45,text="Primer restriction analysis",anchor='nw')
    count=0
    for primer in characteristics.keys():
         The progress bar
        if parent.cancelled:
            return None,None,None
        count=count+1
        parent.update_primer_progress(float(count)/float(len(characteristics.keys())),2)
         Find the enzymes that cut
        for key_primer_enzymes in rest_enzymes_primer[primer].keys():
            if rest_sites_DNATOT.has_key(key_primer_enzymes):
                if not enzymes_that_already_cut.has_key (primer):
                    enzymes_that_already_cut [primer] = []
                enzymes_that_already_cut [primer].append (key_primer_enzymes)
            else:
                if not new_enzymes.has_key (primer):
                    new_enzymes [primer] = []
                new_enzymes[primer].append (key_primer_enzymes)
     Primer characterisation
    primers_results_dict = {}
    counter=0
     Calculate self complementarity and hairpin-forming propensity
    parent.prog_can.create_text(5,85,text="Primer characterisation",anchor='nw')
    count=0
    for primer in characteristics.keys():
         Progress bar
        if parent.cancelled:
            return None,None,None
        count=count+1
        parent.update_primer_progress(float(count)/float(len(characteristics.keys())),3)
         Get the characteristics
        hairpin_dict, maxscorelist = hairpin_propensity (primer)
        complementarity_dict,maxselfscorelist = self_complementarity_propensity (primer)
        if maxselfscorelist < 8:
            maxselfscorelist = 'OK'
        elif maxselfscorelist >= 8:
            maxselfscorelist = 'BAD'
        if maxscorelist < 8:
            maxscorelist = 'OK'
        elif maxscorelist >= 8:
            maxscorelist = 'BAD'
         Add the characteristics to the dictionary
        characteristics[primer]['hairpin_prop']=maxscorelist
        characteristics[primer]['self-compl']=maxselfscorelist
    return characteristics, new_enzymes, enzymes_that_already_cut
def exhaustive_research ( DNA_sequence , AA_number , NewAA , Tm_desired , Tm_method , enzyme_list = None , parent = None , primer_max_len = 30 , find_restriction_site = None ) : codons = get_codons ( NewAA ) base_position = ( AA_number - 1 ) * 3 mut_DNA = DNA_sequence [ : base_position ] + 'XXX' + DNA_sequence [ base_position + 3 : ] DNA_start = base_position - int ( 0.5 * primer_max_len ) DNA_end = base_position + int ( 0.5 * primer_max_len ) if DNA_start < 0 : DNA_end = DNA_end + abs ( DNA_start ) DNA_start = 0 if DNA_end > len ( DNA_sequence ) : DNA_end = len ( DNA_sequence ) primer_template = mut_DNA [ DNA_start : DNA_end ] mut_pos = primer_template . find ( 'XXX' ) primer_template = primer_template . replace ( 'XXX' , codons [ 0 ] ) AA_sequence3 , AA_sequence_1 = translate ( primer_template ) AA_sequence3 = AA_sequence3 [ 0 ] DNA_template = DNA_sequence [ DNA_start : DNA_end ] res_comb = [ ] max_permutations = 20000 for item in AA_sequence3 : res_comb . append ( inverse_genetic_code [ item ] ) primers_comb = add_next ( res_comb ) characteristics = { } SCAN = scan_primer ( DNA_sequence ) print 'Found %d primers in total' % ( len ( primers_comb ) ) count = 0 parent . prog_can . create_text ( 5 , 5 , text = "Diversity generation" , anchor = 'nw' ) box = None for comb in primers_comb : count = count + 1 if parent . cancelled : return None , None , None parent . update_primer_progress ( float ( count ) / float ( len ( primers_comb ) ) , 1 ) primer_length = len ( comb ) min_primer_length = 15 for primer_start in range ( 0 , 12 , 3 ) : for primer_end in range ( 1 , 13 , 3 ) : primer_seq = comb [ primer_start : - primer_end ] Tm , mismatches , Tm_method_used = get_primer_Tm ( DNA_template , primer_seq , primer_start , Tm_method ) if abs ( Tm - Tm_desired ) < 4.0 : characteristics [ primer_seq ] = { 'Tm' : Tm , 'mismatches' : mismatches } if Tm < Tm_desired - 4.0 : break if primer_end < 3 and Tm < Tm_desired - 4.0 : break print 'I found %7d combinations with a Tm less than 4K from the desired Tm' % ( len ( characteristics . keys ( ) ) ) print '--------------------------------------' RS = restriction_digest ( ) rest_sites_DNATOT = RS . get_restriction_sites ( DNA_sequence , enzyme_list ) rest_enzymes_primer = { } for primer in characteristics . keys ( ) : rest_enzymes_primer [ primer ] = RS . get_restriction_sites ( primer , enzyme_list ) enzymes_that_already_cut = { } new_enzymes = { } parent . prog_can . create_text ( 5 , 45 , text = "Primer restriction analysis" , anchor = 'nw' ) count = 0 for primer in characteristics . keys ( ) : if parent . cancelled : return None , None , None count = count + 1 parent . update_primer_progress ( float ( count ) / float ( len ( characteristics . keys ( ) ) ) , 2 ) for key_primer_enzymes in rest_enzymes_primer [ primer ] . keys ( ) : if rest_sites_DNATOT . has_key ( key_primer_enzymes ) : if not enzymes_that_already_cut . has_key ( primer ) : enzymes_that_already_cut [ primer ] = [ ] enzymes_that_already_cut [ primer ] . append ( key_primer_enzymes ) else : if not new_enzymes . has_key ( primer ) : new_enzymes [ primer ] = [ ] new_enzymes [ primer ] . append ( key_primer_enzymes ) primers_results_dict = { } counter = 0 parent . prog_can . create_text ( 5 , 85 , text = "Primer characterisation" , anchor = 'nw' ) count = 0 for primer in characteristics . keys ( ) : if parent . cancelled : return None , None , None count = count + 1 parent . update_primer_progress ( float ( count ) / float ( len ( characteristics . keys ( ) ) ) , 3 ) hairpin_dict , maxscorelist = hairpin_propensity ( primer ) complementarity_dict , maxselfscorelist = self_complementarity_propensity ( primer ) if maxselfscorelist < 8 : maxselfscorelist = 'OK' elif maxselfscorelist >= 8 : maxselfscorelist = 'BAD' if maxscorelist < 8 : maxscorelist = 'OK' elif maxscorelist >= 8 : maxscorelist = 'BAD' characteristics [ primer ] [ 'hairpin_prop' ] = maxscorelist characteristics [ primer ] [ 'self-compl' ] = maxselfscorelist return characteristics , new_enzymes , enzymes_that_already_cut
Generate a primer for introducing the required mutation by generating all possible DNA_sequences
that will produce the amino acid sequence, and then scoring all of them for Tm, number of mismatches and
restriction sites introduced
Generate a primer for introducing the required mutation by generating all possible DNA_sequences that will produce the amino acid sequence and then scoring all of them for Tm number of mismatches and restriction sites introduced
"""Generate a primer for introducing the required mutation by generating all possible DNA_sequences
    that will produce the amino acid sequence, and then scoring all of them for Tm, number of mismatches and
    restriction sites introduced""" # # Make the mutation in the DNA # # # Get the Amino acid sequence from 5 aa (15 bases) up and downstream if possible # # # Find the base count of the mutation # # We are only interested in the first reading frame # # Keep a record of the template DNA # # # Generate all base sequences that will produce this amino acid sequuence # # We start by introducing as few mutations as possible, and end of with ? # #for codons_in_play in range(1,11): #    pass #print 'Mutated AA',AA_sequence3[AA_number] #print AA_sequence #stop # # Call add_next # # # Now we search for all the restriction sites on all the primers. Compare them with the ones present in the # DNAsequence and creates two different Dictionaries for them. # # # Instantiate the scan_primer class # # # Loop over all primers # # # The progress bar # # # Find sub-fragments of this primer that have the correct Tm # # # Scan for other binding sites # # # # Perform the resitriction site analysis # # Instantiate the restriction site class and get the restriction sites for the wt sequence # # This one calls the __init__ function # # Finds all the restriction enzymes for each primer # # # compare the cut positions in the primer and in the DNAsequence # # # Print the text # # # # # # The progress bar # # # Find the enzymes that cut # # # Primer characterisation # # # Calculate self complementarity and hairpin-forming propensity # # # Progress bar # # # Get the characteristics # # # Add the characteristics to the dictionary #
DNA_sequence
AA_number
NewAA
Tm_desired
Tm_method
enzyme_list
parent
primer_max_len
find_restriction_site