This is a test version of Biostars. For the public version, visit https://www.biostars.org.
function for creating random point mutations

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

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

0 answers

No answers yet.

Log in to answer this question.