This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seqlib.py
106 lines (91 loc) · 2.47 KB
/
seqlib.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
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
94
95
96
97
98
99
100
101
102
103
104
105
import copy
import random
#=========================
def complement(seq):
newseq = copy.copy(seq)
newseq = newseq.replace('A', 'x')
newseq = newseq.replace('T', 'A')
newseq = newseq.replace('x', 'T')
newseq = newseq.replace('G', 'x')
newseq = newseq.replace('C', 'G')
newseq = newseq.replace('x', 'C')
return newseq
#=========================
def flip(seq):
newseq = copy.copy(seq)
return newseq[::-1]
#=========================
def makeSequence(seqlen=10):
endloop = False
half = int(seqlen//2)
while not endloop:
endloop = True
seq = _makeSequence(seqlen)
compl = complement(seq)
# several criteria for bad sequences
if seq == flip(seq):
endloop = False
elif seq == compl:
endloop = False
elif seq == flip(compl):
endloop = False
elif seq[:half] == seq[-half:]:
endloop = False
elif compl[:half] == compl[-half:]:
endloop = False
elif seq[:half] == compl[-half:]:
endloop = False
elif compl[:half] == seq[-half:]:
endloop = False
elif not 'T' in seq:
endloop = False
elif not 'A' in seq:
endloop = False
elif seq[:half] == flip(seq[-half:]):
endloop = False
elif compl[:half] == flip(compl[-half:]):
endloop = False
elif seq[:half] == flip(compl[-half:]):
endloop = False
elif compl[:half] == flip(seq[-half:]):
endloop = False
elif seq[:half] == flip(seq[:half]):
endloop = False
elif compl[:half] == flip(compl[:half]):
endloop = False
elif seq[:half] == flip(compl[:half]):
endloop = False
elif compl[:half] == flip(seq[:half]):
endloop = False
elif seq[-half:] == flip(seq[-half:]):
endloop = False
elif compl[-half:] == flip(compl[-half:]):
endloop = False
elif seq[-half:] == flip(compl[-half:]):
endloop = False
elif compl[-half:] == flip(seq[-half:]):
endloop = False
if endloop is True:
newseq = copy.copy(seq)
newseq = newseq.replace('T', 'A')
if 'AAAA' in newseq:
endloop = False
newseq = newseq.replace('C', 'G')
if 'GGGG' in newseq:
endloop = False
return seq
#========================================
def html_monospace(txt):
return "<span style='font-family: 'andale mono', 'courier new', courier, monospace;'>{0}</span>".format(txt)
#=========================
def _makeSequence(seqlen=10):
seq = ""
for i in range(seqlen):
seq += random.choice('AGCT')
return seq
#=========================
def transcribe(dna):
#assumes dna sequence is the non-template/coding strand
rna = copy.copy(dna)
rna = rna.replace('T', 'U')
return rna