function for creating random point mutations
0
0
Entering edit mode
4.5 years ago

Greetings, I wanted to present you my code for creating random point mutation. Is it spaghetti code and is while loop used properly ? I am new to bioinformatics so I require advice for my codes. Thanks for your comments. My code is below.

import random
my_seq = "AATTCCGGACTGAAAAAAGGGTCGTCCCCCAGT"
def random_point_mutater(seq):
    coding_dna= list(seq)
    DNA= ["A", "G", "T","C"] # to create an alphabet of DNA
    a= random.randint(0, len(seq))# takes length of the sequence and gererates a random number between 0 and length
    c= random.randint(0,3)
    b= DNA[c] # chooses a random letter from DNA alphabet
    popped= coding_dna.pop(a) #remove that nucleotide from the sequence
    while b== popped:
          b= DNA[c]    # to prevent changing the same nucleotide 
    coding_dna.insert(a, b)# inserts the new nucleotide to the location which is empty now
    back_to_str= "".join(coding_dna)
    print(a) # to see which index did it choose
    print(back_to_str) #to print mutated sequence
    print("instead of" +" "+ popped + " "+ "now you have" + " "+ b )# a clarification of which base left and which base in


random_point_mutater(my_seq)
mutation point mutation artificial mutation • 2.0k views
ADD COMMENT
0
Entering edit mode

I would prefer to a) choose a different position if the mutation and the base are equal, or b) randomly select from the 3 nucleotides that are not the base in the selected position

ADD REPLY

Login before adding your answer.

Traffic: 1910 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6