-
Notifications
You must be signed in to change notification settings - Fork 0
/
rosalind_find_motif(subs).py
47 lines (31 loc) · 1.89 KB
/
rosalind_find_motif(subs).py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
# Diane Kaplan
# Rosalind Problem: finding motif (subs)
# http://rosalind.info/problems/subs/
# Aug 14, 2015
# Rules:
#Given: Two DNA strings s and t (each of length at most 1 kbp).
#Return: All locations of t as a substring of s.
#
DEBUG = False
def find_instances(sample, query):
locations= []
substring = query
string = sample
string_length = len(string)
substring_length = len(substring)
cursor = 0
if (DEBUG):
print "substring:", substring
print "string:", string
while cursor < string_length:
current_chunk = string[cursor:(cursor+substring_length)]
if current_chunk == substring:
if (DEBUG):
print "I found: ", current_chunk, " at position: ", cursor+1
locations.append(cursor+1)
cursor += 1
return locations
sample= 'AGGGAGGTCCATAAGTCGTCGTGCGTCGTCGCTGTGACATCAACGTCGTCGGTCGTCGGTTTGAATAGTCGTCGCGTCGTCGGTCGTCGCGTCGTCGGTCGTCGTGTCGTCGACGTCGTCGATGTCGTCGGCCCATAACTCCGTCGTCGGTCGTCGGTCGTCGGGTCGTCGGTCGTCGTATTCGTCGTCGCTTGTCGTCGTGTCGTCGAGCGTCGTCGGTCGTCGTCTAGGTCGTCGGTCGTCGGCTATGTCGTCGGTCGTCGTTTGACGTCGTCGTGTCGTCGGTCGTCGTGTCGTCGCGTCGTCGGTCGTCGGTCGTCGGTCGTCGCAAACGTCGTCGTCCGTCGTCGTGTTGTCGTCGGTCGTCGGTCGTCGGTCGTCGCAGTCGTCGCTGTCGTCGTGTCGTCGATCGTCGTCGGTCGTCGCCGTCGTCGGTCGTCGTCCTCGTCGTCGATGTCGTCGTAAAGTCGTCGTAAAACTTGTCGTCGGTCGTCGGGCGTCGTCGGATAGGTCGTCGGTCGTCGGTCGTCGGTCGTCGGAAGTGTCGTCGAGTTGCGTCGTCGTTCGTCGTCGAGGGTCGTCGGTCGTCGTTGGTCGTCGGATCGTCGTCGTGGTCGTCGACGTCGTCGCGTCGTCGGGTCGTCGAAGTCGTCGCGTCGTCGCCTGTCGTCGGTCGTCGGTCGTCGTGTGTGTCGTCGAGTCGTCGTAGGTCGTCGGTCGTCGGTCGTCGGTCGTCGGCACATTGTCGTCGCACCCTGTCGTCGGGTGACCAGTCGTCGAGTCGTCGGTCGTCGCATGTTCGTCGTCGGTCGTCGTGCCAAGAGGTCGTCGGGTCGTCGGGTCGTCGGTCGTCGTGTCGTCGGTCGTCGCGTCGTCGCATGTCGTCGATTCTTCGATGCCCGTCGTCGTGAACGGAATGGGTCGTCGGTCGTCGTGTCGTCGGTCGTCGATCAAGAGTCGTCGCGTCGTCGTG'
query='GTCGTCGGT'
print find_instances(sample, query)