Hey,
I've been trying to use Python to help me with some DNA sequencing work. I've figured out how to use Biopython for the importing work; however, I need some python code to help me remove a smaller regulatory sequence (a short string) from a larger DNA sequence (a longer string) recursively so that when one is removed and the subsequent joining creates a new regulatory sequence (a short string) this new regulatory sequence is removed as well. The following code shows this better.
Before working with the large files, I made some test code to show this is a working program. Code is as follows:
#Next, I tried to 'reactivate' the while loop to remove the new 'y' string created #by the following code:
Unfortunetately , this code doesn't 'reactivate' the while statement because the 'y' string of 'GATA' is still in 'x'. So, how do I make this while statement to be recursive so that newly made 'y' sequences from the rejoining can be found and removed or is there a more logical way to remove newly created elements after the joining?
I apologize for not knowing the lingo since I am still fairly new to Python.
If my question is still confusing and needs further clarification, please let me know. Any advice/help will be greatly appreciated.
Thanks,
Nick
I've been trying to use Python to help me with some DNA sequencing work. I've figured out how to use Biopython for the importing work; however, I need some python code to help me remove a smaller regulatory sequence (a short string) from a larger DNA sequence (a longer string) recursively so that when one is removed and the subsequent joining creates a new regulatory sequence (a short string) this new regulatory sequence is removed as well. The following code shows this better.
Before working with the large files, I made some test code to show this is a working program. Code is as follows:
Code:
>>> x = ("CCCGACTGATATCTACCCC") #My long string >>> y = ("GATA") #One of my short strings >>> z = ("CTTC") #Another short string >>>running = True #Bool to work with while statement >>>running_y = True #Bool to work with while statement >>>running_z = True #Bool to work with while statement >>>while running: #While statment to remove short strings. while running_y: n = x.replace(y,'',1) #Finds 'y' and removes from 'x' if x != n: #If something was removed x = n #x now equals the removed else: running_y = False #turns off the while #statement while running_z: #similar to while y statement with z n = x.replace(z,'',1) if x != n: x = n else: running_z = False running = False >>> print x CCCGATACCCC
Code:
>>>r = x.find(y) >>>if r == True: running_y = True running_z = True running = True >>> print x CCCGATACCCC
I apologize for not knowing the lingo since I am still fairly new to Python.
If my question is still confusing and needs further clarification, please let me know. Any advice/help will be greatly appreciated.
Thanks,
Nick
Comment