# File: hw3_4.py # This program introduces single base-pair mutations # (i.e. replacement of A by T/C/G, G by A/T/C, etc...) # into a DNA string at a rate of 1% # (i.e. ~1 mutation every 100 base pairs) import random print 'Enter path to file containing DNA string:' # Ask for path to file containing DNA string # and load DNA string into memory dna = open(raw_input(), 'U').read() print "Enter name of output string:" # Ask under what name to store output string # and create output file output = open(raw_input(), 'w') # Initialize random variable mutation = 1 # Go through the DNA string for letter in dna: # Read every base pair if letter == 'g' or letter == 'G' \ or letter == 'c' or letter == 'C' \ or letter == 'a' or letter == 'A' \ or letter == 't' or letter == 'T': # Generate a random number in [0,1) according to the uniform # distribution in order to determine if a mutation occurs mutation = random.random() # If it does, replace the current base pair by a # different base pair chosen at random (uniformly) if 0.1 < mutation and mutation < 0.11: #output.write('R') mutation = random.randint(1, 3) if letter == 'g' or letter == 'G': if mutation == 1: output.write('c') elif mutation == 2: output.write('a') elif mutation == 3: output.write('t') elif letter == 'c' or letter == 'C': if mutation == 1: output.write('g') elif mutation == 2: output.write('a') elif mutation == 3: output.write('t') elif letter == 'a' or letter == 'A': if mutation == 1: output.write('g') elif mutation == 2: output.write('c') elif mutation == 3: output.write('t') elif letter == 't' or letter == 'T': if mutation == 1: output.write('c') elif mutation == 2: output.write('a') elif mutation == 3: output.write('g') else: output.write(letter) # Maintain layout elif letter == '\n': output.write(letter)