forked from alfredkam/corRna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold_wrapper.py
executable file
·235 lines (230 loc) · 7.05 KB
/
old_wrapper.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env python
import sys
import re
import commands
import shutil
import getopt
import os, glob, sys
import os.path
import random, math
from decimal import Decimal
from time import clock, time
from math import *
import Pearson
DEBUG = True
MUTATION_DEPTH = 2
NSIZE = 10
SEQUENCE = ''
LOOP_SIZE = 10
BUCKETS = []
NODE = ''
Question_Marks = ''
AVG = float(0)
nAVG = float(0)
totalCORRELATION = 0
totalSEQUENCE = 0
totalTIME = 0
SIGNIFICANT = []
def usage():
print "Displaying help:"
print "-s [sequence]"
print "-h display help file"
print "-m [x] mutation depth"
print "-n [x] number of samples"
print "-l [x] loop size"
print "-t [x] correlation threshold"
print "sample usage:\n ./wrapper.py -m 2 -n 10 -l 10 -t 0.4 -s AGCGGGGGAGACAUAUAUCAUAGCCUGUCUCGUGCCCGACCCCGC"
def SCOUT(seq):
#!/bin/bash
if(re.match('AGCGGGGGAGACAUCUAUCACAGCCUGUCUCGUGCCCGACCCCGC', seq)):
print "A68C"
if re.match('AGCGGGGGAGACAUAUACCACAGCCUGUCUCGUGCCCGACCCCGC', seq):
print "U71C"
if re.match('AGCGGGGGAGACAUAUAUCAUAGCCUGUCUCGUGCCCGACCCCGC', seq):
print "C74U"
if re.match('AGCGGGGGAGACAUAUAUCACUCUCUGUCUCGUGCCCGACCCCGC', seq):
print "A75U_G76C_C77U"
if re.match('AGCGGGGGAGACAUAUAUCACAGUCUGUCUCGUGCCCGACCCCGC', seq):
print "C77U"
if re.match('AGCGGGGGAGACAUAUAUCACAGCCUGUCUAGGGCCCGACCCCGC', seq):
print "C84A_U86G"
if re.match('AGCGGGGGAGACAUAUAUCACAGCCUGUCUAGAGCCCGACCCCGC', seq):
print "C84A_U86A"
if re.match('AGCGGGGGAGACAUAUAUCACAGCCUGUCUCGGGCCCGACCCCGC', seq):
print "U86G"
if re.match('AGCGGGGGAGACAUAUAUCACAGCCUGUCUCGUGCCAGGCCCCGC', seq):
print "C90A_A92G"
if re.match('AGCGGGGGAGACAUAUAUCACAGCCUGUCUCGUGCCCGGCCCCGC', seq):
print "C92G"
if re.match('AGCGGGGGAGACAUAUAUCACAGCCUGUCUCGUGCCAGACCCCGC', seq):
print "C90A"
if re.match('AGCGGGGGAGACAUAUAUCACAGCCUGUCUCGUGCCCGUCCCCGC', seq):
print "A92U"
if re.match('AGCGGGGGAGACAUAUAUCACAGCCUGUCUCGUGCCCGCCCCCGC', seq):
print "A92C"
def getAvg():
x = float(0.0)
x += P.getCorr('AGCGGGGGAGACAUCUAUCACAGCCUGUCUCGUGCCCGACCCCGC');
x += P.getCorr('AGCGGGGGAGACAUAUACCACAGCCUGUCUCGUGCCCGACCCCGC');
x += P.getCorr('AGCGGGGGAGACAUAUAUCAUAGCCUGUCUCGUGCCCGACCCCGC');
x += P.getCorr('AGCGGGGGAGACAUAUAUCACUCUCUGUCUCGUGCCCGACCCCGC');
x += P.getCorr('AGCGGGGGAGACAUAUAUCACAGUCUGUCUCGUGCCCGACCCCGC');
x += P.getCorr('AGCGGGGGAGACAUAUAUCACAGCCUGUCUAGGGCCCGACCCCGC');
x += P.getCorr('AGCGGGGGAGACAUAUAUCACAGCCUGUCUAGAGCCCGACCCCGC');
x += P.getCorr('AGCGGGGGAGACAUAUAUCACAGCCUGUCUCGGGCCCGACCCCGC');
x += P.getCorr('AGCGGGGGAGACAUAUAUCACAGCCUGUCUCGUGCCAGGCCCCGC');
x += P.getCorr('AGCGGGGGAGACAUAUAUCACAGCCUGUCUCGUGCCCGGCCCCGC');
x += P.getCorr('AGCGGGGGAGACAUAUAUCACAGCCUGUCUCGUGCCAGACCCCGC');
x += P.getCorr('AGCGGGGGAGACAUAUAUCACAGCCUGUCUCGUGCCCGUCCCCGC');
x += P.getCorr('AGCGGGGGAGACAUAUAUCACAGCCUGUCUCGUGCCCGCCCCCGC');
y = float(x)/float(13)
global AVG
AVG = y
global nAVG
#nAVG = P.getCorr('AGCGGGGGAGACAUAUAUCACAGCCUGUCUAGGGCCCGACCCCGC');
#modified to use threshold from command line
print "<Under Avg> :: under "+str(AVG)+" across the 13 given confirmed sequence"
print "<Under Threshold> :: under "+str(nAVG)+" on A84_U86G or user input threshold"
def initial():
node = ''
getAvg()
global Question_Marks
global NODE
global totalTIME
global totalCORRELATION
global totalSEQUENCE
sequenceCOUNTER = 0
sequenceCORRELATION = 0
for i in range(len(SEQUENCE)):
BUCKETS.append(int(0))
Question_Marks+='?'
node+="o"
#Question_Marks = '?((((((????????????????????????????????))))))'
NODE = node
start = time()
out = commands.getoutput('./RNAmutants -l lib -m '+str(MUTATION_DEPTH)+' -s '+ SEQUENCE +'-n '+str(NSIZE))
end = time() - start
totalTIME+=end
for line in out.splitlines():
if re.match('\w+', line):
if re.match("C|G|c|G|A|a|U|u", line):
sequenceCOUNTER+=1
line = re.sub('\s+.*$',"",line)
x = P.getCorr(line)
sequenceCORRELATION+=x
note = ''
if(AVG > x):
note = " <Under Avg>"
if(nAVG > x):
SIGNIFICANT.append(line)
note+=" <Under Threshold>"
#print line +" "+str(x) + note
print '{0} {1:.4f} {2}'.format(line,x,note)
SCOUT(line)
node = locate(line, node)
totalCORRELATION+=sequenceCORRELATION
totalSEQUENCE+=sequenceCOUNTER
print "avg correlation for this round "+str(sequenceCORRELATION/sequenceCOUNTER)
print 'time took: '+str(end)
loop(node)
def loop(node):
#print LOOP_SIZE
global totalTIME
global totalSEQUENCE
global totalCORRELATION
#lock file name for this session
rant = random.randint(1, 100);
wrapper = str(rant)+'-wrapper.in'
while(os.path.isfile(wrapper)):
rant = random.randint(1, 100);
wrapper = str(rant)+'-wrapper.in'
for i in range(int(LOOP_SIZE)):
sequenceCOUNTER =0
sequenceCORRELATION = 0
f = open(wrapper, 'w')
f.write(SEQUENCE+'\n')
f.write(node+'\n')
f.write(Question_Marks+'\n')
f.close()
print node
node = NODE
start = time()
out = commands.getoutput('./RNAmutants -l lib -m '+str(MUTATION_DEPTH) +' -n '+str(NSIZE) +' -f '+ wrapper +' -C')
end = time() - start
totalTIME+=end
# node = lockS(node)
for line in out.splitlines():
if re.match('\w+', line):
if re.match("C|G|c|G|A|a|U|u", line):
sequenceCOUNTER+=1
line = re.sub('\s+.*$',"",line)
x = P.getCorr(line)
sequenceCORRELATION+=x
note = ''
if(AVG > x):
note = " <Under Avg>"
if(nAVG > x):
SIGNIFICANT.append(line)
note+=" <Under Threshold>"
#print line +" "+str(x) + note
print '{0} {1:.4f} {2}'.format(line,x,note)
SCOUT(line)
node = locate(line, node)
print "avg correlation for this round "+str(sequenceCORRELATION/sequenceCOUNTER)
print 'time took: '+str(end)
out = commands.getoutput('rm '+wrapper)
print "total avg correlation "+str(totalCORRELATION/totalSEQUENCE)
print "total TIME took:: "+str(totalTIME) + " avg time took:: "+str(totalTIME/(LOOP_SIZE+1))
print BUCKETS
print 'No of SIGS Under Threshold threshold {0} = {1}'.format(nAVG,len(SIGNIFICANT))
print "# [sequence] [correlation]"
#print SIGNIFICANT
for i, seq in enumerate(SIGNIFICANT):
print i, seq, "%.4f" % P.getCorr(seq)
def lockS(node):
for i in range(len(BUCKETS)):
if(BUCKETS[i] != 0 and BUCKETS[i] % 10 == 0):
node = node[:i]+"X"+node[i+1:]
BUCKETS[i] = 0
return node
def locate(seq, node):
i=0
for x in seq:
if re.match("c|g|a|u", x):
if not re.match("X", node[i]):
node = node[:i]+"X"+node[i+1:]
BUCKETS[i]+=1;
i+=1;
return node
if __name__ == "__main__":
try:
optlist, args = getopt.getopt(sys.argv[1:], 'n:l:s:m:t:h', ["help"])
except getopt.GetoptError, err:
print str(err)
print usage()
sys.exit(2)
for opt, query in optlist:
if opt == "-s":
SEQUENCE = query
P = Pearson.Correlation(SEQUENCE)
elif opt in ("-h", "--help"):
usage()
sys.exit(2)
elif opt == "-m":
MUTATION_DEPTH = int(query)
elif opt == "-n":
NSIZE = int(query)
elif opt == "-l":
LOOP_SIZE = int(query)
elif opt == "-t":
print 'Setting threshold to {0}'.format(query)
nAVG = float(query)
else:
print "ERROR: incorrect usage"
usage()
sys.exit
if(re.match('\w+',SEQUENCE)):
initial()
else:
print "ERROR: Buggy or Null Sequence"
sys.exit