rosalind练习题九

给定两个DNA字符串s和t,任务是找出t作为s的子串的所有位置。子串是从字符串中连续提取的符号集合,其位置由它左侧包括自身的符号总数定义。提供的代码示例展示了如何在Python中遍历序列并找到匹配的子串位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# Problem
# Given two strings $s$ and $t$, $t$ is a substring of $s$ if $t$ is contained as a contiguous collection of symbols in $s$ (as a result, $t$ must be no longer than $s$).
# 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 $i$ of $s$ is denoted by $s[i]$.
# A substring of $s$ can be represented as $s[j:k]$, where $j$ and $k$ represent the starting and ending positions of the substring in $s$; for example, if $s$ = "AUGCUUCAGAAAGGUCUUACG", then $s[2:5]$ = "UGCU".
# The location of a substring $s[j:k]$ is its beginning position $j$; note that $t$ will have multiple locations in $s$ if it occurs more than once as a substring of $s$ (see the Sample below).
# Given: Two DNA strings $s$ and $t$ (each of length at most 1 kbp).
# Return: All locations of $t$ as a substring of $s$.
#
# Sample Dataset
# GATATATGCATATACTT
# ATAT
# Sample Output
# 2 4 10

# 找到motif

# 代码:
seq = "GATATATGCATATACTT"
motif = "ATAT"

loc = []
for i in range(len(seq)):
    if seq[i:i+len(motif)] == motif:
        loc.append(str(i+1))
print(" ".join(loc))


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值