09 Finding a Motif in DNA

Problem

Given two strings ss and tt, tt is a substring of ss if tt is contained as a contiguous collection of symbols in ss (as a result, tt must be no longer than ss).

The position of a symbol in a string is the total number of symbols found to its left, including itself (e.g., the positions of all occurrences of ‘U‘ in "AUGCUUCAGAAAGGUCUUACG" are 2, 5, 6, 15, 17, and 18). The symbol at position ii of ss is denoted by s[i]s[i].

A substring of ss can be represented as s[j:k]s[j:k], where jj and kk represent the starting and ending positions of the substring in ss; for example, if ss = "AUGCUUCAGAAAGGUCUUACG", then s[2:5]s[2:5] = "UGCU".

The location of a substring s[j:k]s[j:k] is its beginning position jj; note that tt will have multiple locations in ss if it occurs more than once as a substring of ss (see the Sample below).

Given: Two DNA strings ss and tt (each of length at most 1 kbp).

Return: All locations of tt as a substring of ss.

Sample Dataset

GATATATGCATATACTT
ATAT

Sample Output

2 4 10
#-*-coding:UTF-8-*-
### 9. Finding a Motif in DNA ###

# Method 1: Use Module regex.finditer
import regex
# 比re更强大的模块

matches = regex.finditer(‘ATAT‘, ‘GATATATGCATATACTT‘, overlapped=True)
# 返回所有匹配项,
for match in matches:
    print (match.start() + 1)

# Method 2: Brute Force Search
seq = ‘GATATATGCATATACTT‘
pattern = ‘ATAT‘

def find_motif(seq, pattern):
    position = []
    for i in range(len(seq) - len(pattern)):
        if seq[i:i + len(pattern)] == pattern:
            position.append(str(i + 1))

    print (‘\t‘.join(position))

find_motif(seq, pattern)

# methond 3
import re
seq=‘GATATATGCATATACTT‘
print [i.start()+1 for i in re.finditer(‘(?=ATAT)‘,seq)]
# ?= 之后字符串内容需要匹配表达式才能成功匹配。

  

				
时间: 2024-11-06 18:47:59

09 Finding a Motif in DNA的相关文章

Hash function

Hash function From Wikipedia, the free encyclopedia A hash function that maps names to integers from 0 to 15. There is a collision between keys "John Smith" and "Sandra Dee". A hash function is any function that maps data of arbitrary

省选前模板复习

PREFACE 也许是OI生涯最后一场正式比赛了,说是省选前模板,其实都是非常基础的东西,穿插了英文介绍和部分代码实现 祝各位参加JXOI2019的都加油吧 也希望今年JX能翻身,在国赛中夺金 数学知识 见数学知识小结 字符串 KMP算法Knuth-Morris-Pratt Algorithm KMP算法,又称模式匹配算法,是用来在一个文本串(text string)s中找到所有模式串(pattern)w出现的位置. 它是通过当失配(mismatch)发生时,模式串本身能提供足够的信息来决定下一

便是徐荒所带的

自己没趣走开了便是赵青衫以及http://weibo.com/2015.09.16/p/1001603887253242939273http://weibo.com/2015.09.16/p/1001603887253247120848http://weibo.com/2015.09.16/p/1001603887253247133649http://weibo.com/2015.09.16/p/1001603887253247133651http://weibo.com/2015.09.16/

百度房间撒谎发喀什经济法老师

http://www.ebay.com/cln/non.shua/cars/167418482013/2015.02.09 http://www.ebay.com/cln/lehu497/cars/167065144019/2015.02.09 http://www.ebay.com/cln/gaza240/cars/167530469015/2015.02.09 http://www.ebay.com/cln/go_qi26/cars/167224324018/2015.02.09 http:

怪我北灵院不给

要不就算平局吧都是显得极为http://weibo.com/2015.09.16/p/1001603887639781581729http://weibo.com/2015.09.16/p/1001603887639785818588http://weibo.com/2015.09.16/p/1001603887639790012974http://weibo.com/2015.09.16/p/1001603887639794164941http://weibo.com/2015.09.16/p

一道人影漫步而

一道全身包裹在不少人心头一跳http://weibo.com/09.16/2015/p/1001603887643111873409http://weibo.com/09.16/2015/p/1001603887643116067799http://weibo.com/09.16/2015/p/1001603887643120285680http://weibo.com/09.16/2015/p/1001603887643128674390http://weibo.com/09.16/2015/

DNA binding motif比对算法

DNA binding motif比对算法 2012-08-31 ~ ADMIN 之前介绍了序列比对的一些算法.本节主要讲述motif(有人翻译成结构模式,但本文一律使用基模)的比对算法. 那么什么是基模么?基模是对DNA结合位点的一种描述.它有几种描述方式,一种是共同序列(consensus sequences)一种是位点倾向距阵(Position Specific Frequency Matrices(PSFM))而对于PSFM,有两种表示方式,一种叫PCM,一种叫PFM,前者是Positi

hdu 1560 DNA sequence(迭代加深搜索)

DNA sequence Time Limit : 15000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 15   Accepted Submission(s) : 7 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description The twenty-first century

HDU 1560 DNA sequence(DNA序列)

p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo