-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbase_complement.py
More file actions
58 lines (50 loc) · 1.83 KB
/
base_complement.py
File metadata and controls
58 lines (50 loc) · 1.83 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
#sequence = raw_input("Enter the sequence you'd like the complement of: \n")
#seqtype = raw_input("Is this DNA or RNA? \n")
sequence = ''
seqtype = 'DNA'
def seqcomplement(sequence, seqtype):
complement = ''
for i in range(len(sequence)):
char = sequence[i]
if char == 'A' or char == 'a':
if 'R' in seqtype or 'r' in seqtype:
complement += 'U'
else:
complement += 'T'
elif char == 'T' or char == 't':
if 'R' in seqtype or 'r' in seqtype:
answer = raw_input("Just letting you know, this sequence has T's despite you saying it's RNA. Do you want me to treat it as DNA? [Answer yes/no]\n")
if 'y' in answer or 'Y' in answer:
seqtype = 'DNA'
for j in range(len(complement)):
if complement[j] == 'U':
complementlist = list(complement)
complementlist[j] = 'T'
complement = "".join(complementlist)
complement += 'A'
else:
complement += 'A'
elif char == 'U' or char == 'u':
if 'D' in seqtype or 'd' in seqtype:
answer = raw_input("Just letting you know, this sequence has U's despite you saying it's DNA. Do you want me to treat it as RNA? [Answer yes/no]\n")
if 'y' in answer or 'Y' in answer:
seqtype = 'RNA'
for j in range(len(complement)):
if complement[j]== 'T':
complementlist = list(complement)
complementlist[j] = 'U'
complement = "".join(complementlist)
complement += 'A'
elif char == 'C' or char == 'c':
complement += 'G'
elif char == 'G' or char == 'g':
complement += 'C'
elif char == '\n' or char == ' ':
continue
else:
print "There's some non-A/U/T/C/G base here. Check index", i, "for the problem. There may be more issues later on in the string but this is the first issue I'm detecting."
complement = ""
break
i+=1
return complement
seqcomplement(sequence, seqtype)