haiferry的个人博客分享 http://blog.sciencenet.cn/u/haiferry

博文

python Finding a Motif in DNA

已有 2804 次阅读 2015-11-20 08:51 |系统分类:科研笔记

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,




https://wap.sciencenet.cn/blog-2887147-936811.html

上一篇:python 删除匹配特定字符的行
下一篇:R语言进行T检验
收藏 IP: 159.226.67.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-19 21:09

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部