I intend use string and reverse function to build a simple application in python for DNA (presented by A,G,G, and T) mutation when one of its substring is reversed during the replication process. The reversal happens what are termed inverted pairs. For instance, if the pattern TGAA is later followed byinverted pattern AAGT, the slice of DNA delimited by those patterns could be inverted and reattached. Something's like
TGAA CATTAAGT
will be inversed to
TGAA TTACAAGT
---------------------------------
The program is simple but I don't know how to manipulate the string to make it be reversed in the way I would like to. Here is my incomplete design: -
DNAsequence = raw_input('Please enter a DNA sequence :') #First, people have to enter a DNA sequence (A,C,G,T only).
-
pattern= raw_input('please enter the pattern :') # Second, people have to enter the pattern (also A,C,G,T only) this limited to 4 characters.
-
MutatedDNA ='......' #this is the output I would like to have, a mutated sequence of DNA
-
16 3546
I intend use string and reverse function to build a simple application in python for DNA (presented by A,G,G, and T) mutation when one of its substring is reversed during the replication process. The reversal happens what are termed inverted pairs. For instance, if the pattern TGAA is later followed byinverted pattern AAGT, the slice of DNA delimited by those patterns could be inverted and reattached. Something's like
TGAACATTAAGT
will be inversed to
TGAATTACAAGT
---------------------------------
The program is simple but I don't know how to manipulate the string to make it be reversed in the way I would like to. Here is my incomplete design: -
DNAsequence = raw_input('Please enter a DNA sequence :') #First people have to enter a DNA sequence (A,C,G,T only).
-
pattern= raw_input('please enter the pattern :') # Second people have to enter the pattern (also A,C,G,T only)
-
MutatedDNA ='......' #this is the output I would like to have, a mutated sequence of DNA
-
To reverse: -
>>> s = "CATT"
-
>>> s[::-1]
-
'TTAC'
-
>>>
-
>>> ls = list(s)
-
>>> ls.reverse()
-
>>> "".join(ls)
-
'TTAC'
-
thank you I got the principle, I will try to see how far I can go.
Anyway, what command(s) should I use if there is another letter rather than A,C,G,T used in the first and second input (if there is a error of inputing, there will be a message appear so user can re-input)?
thank you I got the principle, I will try to see how far I can go.
Anyway, what command(s) should I use if there is another letter rather than A,C,G,T used in the first and second input (if there is a error of inputing, there will be a message appear so user can re-input)?
-
import string
-
letts = string.lowercase
-
letts.remove("a")
-
letts.remove("c")
-
letts.remove("g")
-
letts.remove("t")
-
-
bad = 0
-
for let in user_input.lower():
-
if let in letts:
-
bad = 1
-
-
... or ...
-
-
us = user_input.lower()
-
if us.count("a") + us.count("c") + us.count("g") + us.count("t") < len(us):
-
bad = 1
-
else:
-
bad = 0
-
Fished the basic, however, I would like to have something advanced:
- I want to inverse ALL occurrences of the input pattern (if there is more than one) in the DNAsequence. Display the new inversed sequence (other none-inversed in DNA sequence + inversed pattern(s) in proper index as example above, not only the inversed pattern). How can I do so?
Fished the basic, however, I would like to have something advanced:
- I want to inverse ALL occurrences of the input pattern (if there is more than one) in the DNAsequence. Display the new inversed sequence (other none-inversed in DNA sequence + inversed pattern(s) in proper index as example above, not only the inversed pattern). How can I do so?
Like this? -
seq = "TCGA"
-
dna = "TCGAGATCTAGTCATCTAGCTCGATCGAAAGTCTATCGATCGGAT"
-
print dna.replace(seq, seq[::-1])
-
I appreciate your help. Now I'd like to extend the program, instead of inversing the pattern we enter, we inverse the next pattern after the entered pattern. For example
dna = 'TACAAATCGGAC'
pat = 'AATC'
result will be 'TACAAATCACGG'?
I appreciate your help. Now I'd like to extend the program, instead of inversing the pattern we enter, we inverse the next pattern after the entered pattern. For example
dna = 'TACAAATCGGAC'
pat = 'AATC'
result will be 'TACAAATCACGG'?
You mean the last part should be 'CAGG'? -
def indexList(s, item, i = 0): # Thanks to bvdet for code
-
i_list = []
-
while 1:
-
try:
-
i = s.index(item, i)
-
i_list.append(i)
-
i += 1
-
except:
-
break
-
return i_list
-
-
dna = 'TACAAATCGGAC'
-
pat = 'AATC'
-
-
for i in indexList(dna, pat):
-
nex = dna[i + 4:i + 8]
-
dna = dna.replace(nex, nex[::-1])
-
See if that works.
I have just begun learning python in a few days. Your code looked so complicated for me to understand. Can you explain in more details or can you make the code less complicated?
Like the simple code of ilikepython -
>>> s = "CATT"
-
>>> s[::-1]
-
'TTAC'
-
>>> ls = list(s)
-
>>> ls.reverse()
-
>>> "".join(ls)
-
'TTAC'
-
it works well. From this source code, can we extend it to achievement my goal?
I have just begun learning python in a few days. Your code looked so complicated for me to understand. Can you explain in more details or can you make the code less complicated?
Like the simple code of ilikepython -
>>> s = "CATT"
-
>>> s[::-1]
-
'TTAC'
-
>>> ls = list(s)
-
>>> ls.reverse()
-
>>> "".join(ls)
-
'TTAC'
-
it works well. From this source code, can we extend it to achievement my goal?
Well, the code I gave you doesn't quite work right. Sorry. Let's try this: -
-
dna = 'TACAAATCGGAC'
-
pat = 'AATC'
-
-
for i in indexList(dna, pat):
-
nex = dna[i + 4:i + 8] # pattern after; to be reserved
-
here = dna[i:i + 4] # pattern (pat)
-
dna = dna.replace(here + nex, here + nex[::-1]) # replace the combination with the last pattern reversed
-
Don't worry about the code in indexList, just know what it does. It returns a list of the indices of the item in the list s. So: -
ls = [1, 2, 2, 4, 5, 2, 4]
-
indexList(ls, 2) will return [1, 2, 5]
-
indexList(ls, 4) will return [3, 6]
-
indexList(ls, 1) will return [0]
-
indexList(ls, 7) will return []
-
Does that make sense?
I modified a little bit the source you gave me earlier, it worked quite well (only inversed the pattern we enter, not the next pattern after the pattern we entered). The new source code makes more sense. Thank U very much.
The program seems to reverse only the first next pattern but not all in the sequence.
For example
dna = 'AACCTTGGAATTCATTAACCACGGAATTCATT'
pat ='AACC'
will only reversed to
dna = AACCGGTTAATTCATTAACCACGGAATTCATT'
The program seems to reverse only the first next pattern but not all in the sequence.
For example
dna = 'AACCTTGGAATTCATTAACCACGGAATTCATT'
pat ='AACC'
will only reversed to
dna = AACCGGTTAATTCATTAACCACGGAATTCATT'
I'm pretty sure it works: -
def indexList(s, item, i = 0): # Thanks to bvdet for code
-
i_list = []
-
while 1:
-
try:
-
i = s.index(item, i)
-
i_list.append(i)
-
i += 1
-
except:
-
break
-
return i_list
-
-
-
def getNew(dna, pat):
-
for i in indexList(dna, pat):
-
nex = dna[i + 4:i + 8] # pattern after; to be reserved
-
here = dna[i:i + 4] # pattern (pat)
-
dna = dna.replace(here + nex, here + nex[::-1]) # replace the combination with the last pattern reversed
-
return dna
-
-
-
dna = 'AACCTTGGAATTCATTAACCACGGAATTCATT'
-
pat ='AACC'
-
-
print "OLD: %s" % dna
-
dna = getNew(dna, pat)
-
print "NEW: %s" % dna
-
Thank you very mich, I have a problem when running the source code.
For example, -
dna ='AGGTGGTTAGGTGGTT'
-
pa='AGGT'
-
-
#the output is fine
-
result='AGGTTTGGAGGTTTGG
-
however, if it changes the last pattern of the dna -
dna ='AGGTGGTTAGGTTGGT'
-
pa='AGGT'
-
-
#the output is not good
-
result='AGGTTTGGAGGTTGGT
-
I'm also looking for a code without using while. I want something very basic since I'm just a beginner.
bvdet 2,851
Expert Mod 2GB
Thank you very mich, I have a problem when running the source code.
For example, -
dna ='AGGTGGTTAGGTGGTT'
-
pa='AGGT'
-
-
#the output is fine
-
result='AGGTTTGGAGGTTTGG
-
however, if it changes the last pattern of the dna -
dna ='AGGTGGTTAGGTTGGT'
-
pa='AGGT'
-
-
#the output is not good
-
result='AGGTTTGGAGGTTGGT
-
I'm also looking for a code without using while. I want something very basic since I'm just a beginner.
The while and for statements are the two basic loop constructs in Python and are good for a beginner to learn. I made some changes to ilikepython's code: - # Reverse the sequence(s) in 'dna' following the substring defined by 'pat'def getNew(dna, pat):
-
def getNew(dna, pat):
-
for i in indexList(dna, pat):
-
j = len(pat)
-
revstr = dna[i + j:i + j*2]
-
dna = revstr[::-1].join([dna[:i+j], dna[i+j*2:]])
-
return dna
-
You still need function indexList().
How can I print the output out(the mutated DNA)? I got error message.
How can I make the program run without being interrupted (after input the dna and pat, it outputs the result, then it appears the input again,...) when I want it to stop I type 'exit' and 'quit' to make it stop running?
How can I print the output out(the mutated DNA)? I got error message.
How can I make the program run without being interrupted (after input the dna and pat, it outputs the result, then it appears the input again,...) when I want it to stop I type 'exit' and 'quit' to make it stop running?
- # Use lots of comments
-
# to describe your program
-
-
# put imports at the top
-
import sys
-
-
def CheckDNASequence(sequence):
-
# just a stub
-
return True
-
-
-
# "encapsulate" using functions
-
def GetDNASequence(): # use descriptive names
-
while 1: # alway loop
-
seq = raw_input("Enter a sequence ('q' to quit): ")
-
if seq.lower() == "q":
-
return # break out of the loop, returning None
-
if CheckDNASequence(seq): # break out of the loop
-
break
-
return seq # good practice to put the valid return here
-
-
def GetPattern():
-
pat = raw_input("Enter a pattern: ")
-
return pat
-
-
-
def main():
-
while True: # always loop
-
seq = GetDNASequence()
-
if seq is None:
-
sys.exit()
-
print seq
-
pat = GetPattern()
-
print pat
-
-
if __name__ == "__main__":
-
main()
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Aki Niimura |
last post by:
Hello everyone,
I need to reverse an iterator in my program.
There are many posting to related to this. But most of them are
talking about how to expand the language to support such. In fact...
|
by: arnuld |
last post by:
i have created a solutions myself. it compiles without any trouble
and runs but it prints some strange characters. i am not able to find
where is the trouble.
...
|
by: Scott |
last post by:
Yeah I know strings == immutable, but question 1 in section 7.14 of "How to
think like a computer Scientist" has me trying to reverse one.
I've come up with two things, one works almost like it...
|
by: rajkumarbathula |
last post by:
Hi
Could any one help me out in reversing rows/elements of DataTable or String or DataList by using any simple statement?
Thanks
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |