-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstrings_3.py
More file actions
94 lines (61 loc) · 2.28 KB
/
Copy pathstrings_3.py
File metadata and controls
94 lines (61 loc) · 2.28 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
##############################
# Strings - Text analysis
##############################
##############################
# Activity 3 - DNA sequences
##############################
## Question 1 ##
def presence_of_A(sequence):
""" Determine if the there is a nucleotid A
Input: a sequence of A,C,T,G (a string)
Output: true or false """
for nucleotid in sequence:
if nucleotid == 'A':
return True
return False
# Test
sequence = "AGACAGCGAGCATATGCAGGAAG"
answer = presence_of_A(sequence)
print("Is there a 'A' in the sequence",sequence," : ",answer)
## Question 2 ##
def position_of_AT(sequence):
""" Determine the position of the code AT
Input: a sequence of A,C,T,G (a string)
Output: the position of this subsequence (start at 0) """
for i in range(len(sequence)-1):
if sequence[i] == 'A' and sequence[i+1] == 'T':
return i # If found
return None # If nowhere found
# Test
sequence = "GTGGTTTGACCTCCCATGGCCAT"
pos = position_of_AT(sequence)
print("In the sequence",sequence,"the code AT appears in position",pos)
## Question 3 ##
def position(code,sequence):
""" Determine the position of the code in the given sequence
Input: a code and a sequence of A,C,T,G (two strings)
Output: the position of this code (start at 0) """
for i in range(len(sequence)-len(code)):
if code == sequence[i:i+len(code)]:
return i # If found, it's over
return None # If nowhere found
# Test
sequence = "GAAGACCTTCTCCTCCTGC"
code = "CCTC"
pos = position(code,sequence)
print("In the sequence",sequence,"the code',code,'appears in position",pos)
## Question 4 ##
def investigation():
mustard = "CCTGGAGGGTGGCCCCACCGGCCGAGACAGCGAGCATATGCAGGAAGCGGCAGGAATAAGGAAAAGCAGC"
scarlet = "CTCCTGATGCTCCTCGCTTGGTGGTTTGAGTGGACCTCCCAGGCCAGTGCCGGGCCCCTCATAGGAGAGG"
peacock = "AAGCTCGGGAGGTGGCCAGGCGGCAGGAAGGCGCACCCCCCCAGTACTCCGCGCGCCGGGACAGAATGCC"
plum = "CTGCAGGAACTTCTTCTGGAAGTACTTCTCCTCCTGCAAATAAAACCTCACCCATGAATGCTCACGCAAG"
code1 = "CATA"
code2 = "ATGC"
for suspect in [mustard,scarlet,peacock,plum]:
print(position(code1,suspect))
print(position(code2,suspect))
return
# Investigation
print("--- Investigation ---")
investigation()