CAVS CAVS - 1 year ago 111
Python Question

mutating dna in parallel lists python

def mutations (list_a,string1,name,list_b):
""" (list of str, str, list of str, list of str) -> NoneType

for i in range(len(list_b)):


It's suppose to modify the first parameter. So basically im trying to modify list_a and making it change to
however, i get an error saying


ValueError: 'GAATTC' is not in list

Also, is there a way if the sequence does not exist, it doesn't modify the function?

Answer Source

Well if I understand you correctly, you want to check each element in list_a if it contains its corresponding element from list_b. If so, you want to modify the element from list_a by replacing the rest of the string (including the list_b element) with part of a control string that does also contain the element from list_b, right?!

Ideally you would put this in your question!!

A way of doing this would be as follow:

def mut(list_a, control, list_b):
    for i in range(len(list_a)):  # run through list_a (use xrange in python 2.x)
        if list_b[i] in list_a[i]:  # if the element from list_b is in it
            # correct the element
            list_a[i] = list_a[i][:list_a[i].index(list_b[i])] +\
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download