How to write body function def correct mutationsmutated clea
How to write body function? def correct _mutations(mutated, clean, names, sequences): \" \" \"(list of str, str, list of str, list of str) NoneType The first parameter represents a list of mutated strands of DNA. The second parameter represents a clean strand of DNA. The third and fourth parameters are the same as the second and third parameters for one_cutters. The function modifies the list of mutated strands that share a 1-cutter with the clean strand by replacing all bases starting at the 1-cutter in the mutated strand with all bases starting at the 1-cutter in the clean strand, up to and including the end of the strand. Assume that the clean strand shares at most one 1-cutter with each mutated strand. (It may share a different 1-cutter with different mutated strings, but there will always only be one or zero 1-cutter that can be applied to both the clean strand and any particular mutated strand.) You must apply at most one 1-cutter to each mutated strand. For example, if a mutated strand in the list is \'ACGTGGCCTAGCT\' and a clean strand is \'ACGGCCTT\' and a provided recognition sequence is \'GGCC\', then the position in the list that referred to the mutated strand before the function was called should refer to \'ACGTGGCCTT\' after the function is called. >>>m= [] >>> correct_mutations () >>>m \" \" \"
Solution
def correct_mutations(mutated_list, clean_strand, enzyme_list, seq_list): \"\"\" (list of str, str, list of str, list of str) -> NoneType Modifies a list of mutated strands of DNA using a clean strand of DNA and a list of enzymes and their corresponding recognition sequences. This is done by finding which one-cutters are shared by each mutated strand with the clean strand, and replacing the rest of the mutated strand sequence following the one-cutter with the clean strand\'s corresponding section. Precondition: The clean strand will contain one and only one one-cutter from the list of enzymes and its recognition sequence list. >>> strands = [\'ACGTGGCCTAGCT\', \'CAGCTGATCG\'] >>> clean = \'ACGGCCTT\' >>> names = [\'HaeIII\', \'HgaI\', \'AluI\'] >>> sequences = [\'GGCC\', \'GACGC\', \'AGCT\'] >>> correct_mutations(strands, clean, names, sequences) >>> strands [\'ACGTGGCCTT\', \'CAGCTGATCG\'] >>> strands = [\'ACGTGGAGTACT\', \'AGTACTCCCCCC\'] >>> clean = \'GGGGAATTCCCCGAATTCAAAAGTACTAAA\' >>> names = [\'HaeIII\', \'ScaI\', \'AluI\'] >>> sequences = [\'GGCC\', \'AGTACT\', \'AGCT\'] >>> correct_mutations(strands, clean, names, sequences) >>> strands [\'ACGTGGAGTACTAAA\', \'AGTACTAAA\'] >>> strands = [\'XXXXXX\', \'YYYYYY\'] >>> clean = \'ZZZZZZ\' >>> names = [\'HaeIII\', \'ScaI\', \'AluI\'] >>> sequences = [\'GGCC\', \'AGTACT\', \'AGCT\'] >>> correct_mutations(strands, clean, names, sequences) >>> strands [\'XXXXXX\', \'YYYYYY\'] \"\"\" # we will replace mutated_list with corrected_list corrected_list = [] clean_cutters = one_cutters(clean_strand, enzyme_list, seq_list) # isolate the single one-cutter from the clean strand clean_cutters = [x for x in clean_cutters if x[1] != []] for i in range(len(mutated_list)): strand = mutated_list[i] entry_cut = one_cutters(strand, enzyme_list, seq_list) for i in range(len(entry_cut) - 1): # for each entry in the mutated list, it contains the one-cutter, # perform the mutation correction if entry_cut[i][0] == clean_cutters[0][0] and entry_cut[i][1] != []: entry_index = strand.find(ENZYMES[clean_cutters[0][0]]) clean_index = clean_strand.find(ENZYMES[clean_cutters[0][0]]) strand = strand.replace(strand[entry_index:], clean_strand[clean_index:]) corrected_list.append(strand) mutated_list[:] = corrected_list