|
Finding a Motif in DNA
Combing Through the Haystackclick to expand
Problem
Given two strings s and t, t isa substring of s if t iscontained as a contiguous collection of symbols in s (as a result, t mustbe no longer than s).
The position of asymbol in a string is the total number of symbols found to its left, includingitself (e.g., the positions of all occurrences of 'U' in"AUGCUUCAGAAAGGUCUUACG" are 2, 5, 6, 15, 17, and 18). The symbol atposition i of s is denoted by s[i].
A substring of s can berepresented as s[j:k], where j and k represent thestarting and ending positions of the substring in s; for example, if s ="AUGCUUCAGAAAGGUCUUACG", then s[2:5] = "UGCU".
The location of asubstring s[j:k] is its beginning position j; note that t willhave multiple locations in s if it occurs more than once as asubstring of s (see the Sample below).
Given: Two DNA strings s and t (eachof length at most 1 kbp).
Return: Alllocations of t as a substring of s.
Sample Dataset
GATATATGCATATACTT
ATAT
针对以上案例我写了如下代码:
#!/usr/bin/python
s='GATATATGCATATACTT'
t='ATAT'
for i in range(0,len(s)):
if s[i:i+4]==t[0:4]:
print i+1,
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-27 07:06
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社