473,467 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

'Reactivating' a previous while statement

1 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. >>> x = ("CCCGACTGATATCTACCCC") #My long string
  2. >>> y = ("GATA") #One of my short strings
  3. >>> z = ("CTTC") #Another short string
  4.  
  5. >>>running = True #Bool to work with while statement
  6. >>>running_y = True #Bool to work with while statement
  7. >>>running_z = True #Bool to work with while statement
  8.  
  9. >>>while running:  #While statment to remove short strings.
  10.     while running_y:
  11.         n = x.replace(y,'',1) #Finds 'y' and removes from 'x'
  12.         if x != n: #If something was removed
  13.             x = n #x now equals the removed 
  14.         else:
  15.             running_y = False #turns off the while #statement
  16.     while running_z: #similar to while y statement with z
  17.         n = x.replace(z,'',1)
  18.         if x != n:
  19.             x = n
  20.         else:
  21.             running_z = False
  22.             running = False
  23. >>> print x
  24. CCCGATACCCC
  25.  
#Next, I tried to 'reactivate' the while loop to remove the new 'y' string created #by the following code:
Expand|Select|Wrap|Line Numbers
  1. >>>r = x.find(y) 
  2. >>>if r == True:
  3.     running_y = True
  4.     running_z = True
  5.     running = True
  6. >>> print x
  7. CCCGATACCCC
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
May 2 '10 #1
2 1289
woooee
43 New Member
Pass the sequence to a function which returns the updated sequence. You can do this from the while loop and anywhere else in the program you want, providing the function is defined before the code calling it (the norm is to declare all functions first with the body of the code following).
May 2 '10 #2
bvdet
2,851 Recognized Expert Moderator Specialist
nleake,

I am not sure this does what you want, but the short strings are removed to leave "CCCCCCC".
Expand|Select|Wrap|Line Numbers
  1. def remove_ss(ls, *args):
  2.     while True:
  3.         for ss in args:
  4.             if ss in ls:
  5.                 ls = ls.replace(ss, '', 1)
  6.         if True not in [(item in ls) for item in args]:
  7.             return ls
  8.  
  9. x = "CCCGACTGATATCTACCCC"
  10. y = "GATA"
  11. z = "CTTC"
  12.  
  13. print remove_ss(x, y, z)
May 5 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Cowfisher | last post by:
I can write simple MySQL stuff in PHP but I'm having problems putting in WHERE clauses. Everytime I do I get errors like this: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,...
6
by: Ciprian Ilie | last post by:
Hi there, If you look at the code below, you will see that I am using a template in order to display some photos on my website. I also have "previous" and "next" buttons/link which increment the...
81
by: candy | last post by:
hi all, Is there is any way in the C language by which I can get the address of a statement? For eg,consider the following simple program: 1. #include<stdio.h> 2. 3. int main(void){ 4. ...
8
by: Karen Hill | last post by:
I would like to do something like this using VBA in MS Access 2000: Me.num = "SELECT MAX(num) FROM mytable;" How does one do that in MS Access correctly? Aggregates in SQL are SUM, MAX, MIN...
5
by: devi | last post by:
hi, I am creating a simple bug tracker application (in Access db) and i created a hisotry table to log the bug history. The history table contains details like ProblemRecordNo (PRN),...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
0
by: George Wei | last post by:
There are 2 pages Default.aspx and Result.aspx: <!-- Default.aspx --> <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Default.master" CodeFile="Default.aspx.cs"...
4
by: bokke | last post by:
Hi, I have a page that has several stories that run on it from a mysql database. Right now I use this code: <img src="Images/NewsPics/<?php echo $row;?>.jpg" border="1"to display the image. ...
9
by: maas | last post by:
Hello I have a problem when coding the statement stmt.execute("insert into Member values ("+mname+" ,"+mail+","+tel+")"); where mname, mail,tel are variables which the user inputs them and...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.