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 3594
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?
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
reversed() built-in function is added in Python 2.4 to do such.
However, I need to use Python 2.2.x because of a module I'm using.
|
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.
--------------------------------- PROGRAMME
--------------------------------
/* K&R2 section 1.9
exercise 1.19
|
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 should except that
every traversal thru the string I've gotten it to repeat the "list" again.
This is what it looks like:
for char in x:
mylist.append(char)
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |