forked from freudiandrip/igem-code-2016
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstop_codon_insertion.py
86 lines (75 loc) · 2.33 KB
/
stop_codon_insertion.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
import sys
import re
"""
This programme is intended to be used to control expression of constructs in
yeast cells that are in a [PSI+] prion state.
Input: in-frame nt sequence of genetic construct
Output: the top-scoring bp positions with respect to predicted readthrough
efficiency during a [PSI+] response
"""
# Concatenates the provided bases
def concatBase(string):
if(len(string)==1):
return string
else:
return "["+string+"]"
# Enables processing of sequences with ambiguous nt reads
def iupacToBase(iupac):
transform={
"A":"A",
"C":"C",
"G":"G",
"T":"T",
"R":"AG",
"Y":"CT",
"S":"CG",
"W":"AT",
"K":"GT",
"M":"AC",
"B":"CGT",
"D":"AGT",
"H":"ACT",
"V":"ACG",
"N":"ACGT"}
return "".join([concatBase(transform[i]) for i in iupac])
# Custom definition of Regx searching
def applyRegx(string,dnaseq):
## Find the flag to ignore case
return [i.start() for i in re.finditer(iupacToBase(string),dnaseq)]
# Check if the motif if present between start and end
def within(start,end,motiflocs):
return [i-start for i in motiflocs if i>= start and i< end]
# Returns the locations in the sequence
def findMotifLocs(motif,dnaseq,newlines):
motiflocs=applyRegx(motif,dnaseq) #finds locations
starts = newlines[:-1]
ends = newlines[1:]
motifPerString = [within(i,j,motiflocs) for i,j in zip(starts, ends)]
return motifPerString
def main(dnafile,motifs):
with open(dnafile, 'r') as f:
dnaseq = f.read()
newlines=[i.start() for i in re.finditer("\n",dnaseq)]
found=[] # could initialize
count=[]
which=[]
##
for mot in motifs:
t1=findMotifLocs(mot[0],dnaseq,newlines)
found.append(t1)
t2=sum([len(i) for i in t1])
count.append(t2)
t3=[(n,i) for i,n in zip(t1,range(len(t1))) if len(i)>0]
which.append(t3)
foundMotifs=[(mot,loc) for mot,count,loc in zip(motifs,count,which) if count>0]
for i in foundMotifs:
print i
if __name__ == '__main__':
if len(sys.argv) > 1:
dnafile=sys.argv[1]
print dnafile
else:
dnafile="clean.csv"
## Current Readthrough values by stop codons
motifs=[("CAGCTA",1),("GGGCAA",2),("TTGCCC",2),("CAAGAA",2)]
main(dnafile,motifs)