Question: Question: Using Python: We can model the mutation of genes in Python by changing a randomly selecting a position in a string representing a DNA
Question:
Using Python: We can model the mutation of genes in Python by changing a randomly selecting a position in a string representing a DNA molecule. Using the random.randint() and random.choice()functions from the Python random module, write a function that will mutate a DNA string. Then, use the frequency table functions from Lab 14 to analyze the changes that occur in frequencies if you randomly change 100 positions in a 1000 gene DNA sequence. Your program should randomly generate a DNA string with 1000 bases, display the frequency table of this string, apply 100 mutations to the string, and then print the frequency table for the mutated string.
Lab 14 finished (which was mentioned above):
#!\usr\bin\python import random def generateString(N, alphabet='AGCT'): dna = [random.choice(alphabet) for i in xrange(N)] dna = ''.join(str(x) for x in dna) return dna def frequencyTable(dnaList): n = max([len(dna) for dna in dnaList]) frequency_matrix = { 'A': [0]*n, 'C': [0]*n, 'G': [0]*n, 'T': [0]*n } for dna in dnaList: for index,base in enumerate(dna): frequency_matrix[base][index] += 1 return frequency_matrix def findConsensus(freqMatrix): consensus = '' dnaLength = len(freqMatrix['A']) for i in range(dnaLength): maxFreq = -1 maxFreqBase = None for base in 'ATGC': l = freqMatrix[base] if l[i] > maxFreq: maxFreq = freqMatrix[base][i] maxFreqBase = base elif l[i] == maxFreq: maxFreqBase = '-' consensus += maxFreqBase return consensus def main(): testList = [] for i in range(10): testList.append(generateString(10)) ft = frequencyTable(testList) print testList print "Freq Table: ",ft cs = findConsensus(ft) print "Consensus String:", cs if __name__ == "__main__": main() Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
