forked from BT18D011/Seq2Feature
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseq_dna1.py
565 lines (533 loc) · 39.6 KB
/
seq_dna1.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
#!/usr/bin/python2.7
# Import modules for CGI handling
"""
Created on Mon Apr 16 09:38:25 2018
@author: rahul
"""
import re
import pandas as pd
#import sys
import argparse
#import glob
#import string
#import urllib
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--input_file",help = "Input file")
parser.add_argument("--property", help = """Enter 'PHY' for Physicochemical properties,'CON' for Conformational properties, 'NA' for Nucleotide content and 'ALL' to calculate all properties""")
# parser.add_argument("--SUB", help = "Substitution matrices")
# parser.add_argument("--CON", help = "Pairwise properties and contact potential")
# parser.add_argument("--ALL", help = "ALL properties")
args = parser.parse_args()
# Create instance of FieldStorage
#input from form
f1 = open(args.input_file,'r').readlines()[1:]
#seq1 = form.getfirst("input_seq1","0")
#mut1= ''
#mut2= ''
#mut3= ''
#mut4 = ''
#prop1 = form.getElementById('cb1')
df1 = pd.DataFrame()
df2 = pd.DataFrame()
df3 = pd.DataFrame()
df_all = pd.DataFrame()
df11 = pd.DataFrame()
df22 = pd.DataFrame()
df33 = pd.DataFrame()
df_all_1 = pd.DataFrame()
n1 = pd.DataFrame()
n2 = pd.DataFrame()
n3 = pd.DataFrame()
prop = []
if args.property == 'PHY':
prop = ['P']
elif args.property == 'CON':
prop = ['C']
elif args.property == 'NA':
prop = ['L']
elif args.property == 'ALL':
prop = ['P','C','L']
#print(prop)
class letter_based:
def __inti__(self,seq):
self.seq = seq
def gc_content(self):
GC_content = ((float(seq.count('G'))+ float(seq.count('C')))*100/len(seq))
print(GC_content)
def purine_AG(self):
Purine_AG_content = ((float(seq.count('G'))+ float(seq.count('A')))*100/len(seq))
print(Purine_AG_content)
def Keto_GT(self):
Keto_GT_content = ((float(seq.count('G'))+ float(seq.count('T')))*100/len(seq))
print(Keto_GT_content)
def A_content(self):
Adenine_content = float(seq.count('A'))*100/len(seq)
print(Adenine_content)
def Guanine_content(self):
Guanine_content = float(seq.count('G'))*100/len(seq)
print(Guanine_content)
def Cytosine_content(self):
Cytosine_content = float(seq.count('C'))*100/len(seq)
print(Cytosine_content)
def Thymine_content(self):
Thymine_content = float(seq.count('T'))*100/len(seq)
print(Thymine_content)
def all_content(self):
# GC_content = ((float(seq.count('G'))+ float(seq.count('C')))*100/len(seq))
# Purine_AG_content = ((float(seq.count('G'))+ float(seq.count('A')))*100/len(seq))
# Keto_GT_content = ((float(seq.count('G'))+ float(seq.count('T')))*100/len(seq))
# Adenine_content = float(seq.count('A'))*100/len(seq)
# Guanine_content = float(seq.count('G'))*100/len(seq)
# Cytosine_content = float(seq.count('C'))*100/len(seq)
# Thymine_content = float(seq.count('T'))*100/len(seq)
d = {'GC_content':[((float(seq.count('G'))+ float(seq.count('C')))*100/len(seq))],'Purine_AG_content' : [((float(seq.count('G'))+ float(seq.count('A')))*100/len(seq))],'Keto_GT_content' : [((float(seq.count('G'))+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : [float(seq.count('A'))*100/len(seq)],'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
df1 = pd.DataFrame(data = d)
return df1
class seq_windowbased:
# init method or constructor
def __init__(self, seq, position,ref,alt,window):
self.seq = seq
self.position = int(position)
self.ref =ref
self.alt = alt
self.window = int(window)
def win3(self):
var1 = seq[self.position-2:self.position-1] +ref+ seq[self.position:self.position+1]
var2 = seq[self.position-2:self.position-1] +alt+ seq[self.position:self.position+1]
# print var1,var2
# mut1 = var1[0]+var1[1]
# mut2 = var1[1]+var1[2]
# mut3 = var2[0]+var2[1]
# mut4 = var2[1]+var2[2]
# return mut1,mut2,mut3,mut4,var1,var2
return var1,var2
#
def win5(self):
var1 = seq[self.position-3:self.position-1] +ref+ seq[self.position:self.position+2]
var2 = seq[self.position-3:self.position-1] +alt+ seq[self.position:self.position+2]
return var1,var2
def win7(self):
var1 = seq[self.position-4:self.position-1] +ref+ seq[self.position:self.position+3]
var2 = seq[self.position-4:self.position-1] +alt+ seq[self.position:self.position+3]
return var1,var2
def win9(self):
var1 = seq[self.position-5:self.position-1] +ref+ seq[self.position:self.position+4]
var2 = seq[self.position-5:self.position-1] +alt+ seq[self.position:self.position+4]
return var1,var2
def win11(self):
var1 = seq[self.position-6:self.position-1] +ref+ seq[self.position:self.position+5]
var2 = seq[self.position-6:self.position-1] +alt+ seq[self.position:self.position+5]
return var1,var2
class feature_cal:
def __init__(self,mut):
self.mut = mut
# self.mut1 = mut1
# self.mut2 = mut2
# self.mut3 = mut3
# self.mut4 = mut4
#
#conformational properties calculation
def conformational(self):
f1 = pd.read_csv("./data/dna_conformational.csv")
cols= ['Properties','Scaleunit',self.mut]
out = f1[cols]
# outdf = out.to_frame()
return out.transpose()
def physico(self):
f1 = pd.read_csv("./data/dna_physicochemical.csv")
cols= ['Properties','Scaleunit',self.mut]
out = f1[cols]
# df_temp = pd.DataFrame()
# df_temp['value'] = f1[self.mut1]+f1[self.mut2]-f1[self.mut3]-f1[self.mut4]
# print(df_temp.to_html())
# out = pd.concat([f1[cols],df_temp],axis = 1)
# print out
return out.transpose()
# return out
for li in f1:
seq = li.strip().split('\t')[0]
# print(seq)
mutaa1 = ''.join(li.strip().split('\t')[1])
mutaa = mutaa1.split(",")
# ref = muta[0]
# alt = muta[-1]
# position = int(''.join(re.findall('\d+',muta)))
# prop = form.getlist('properties')
# window = form.getvalue('window')
# prop = form.getlist('properties')
window = 3
for muta in mutaa:
# muta = form.getvalue('position')
ref = muta[0].upper()
alt = muta[-1].upper()
position = int(''.join(re.findall('\d+',muta)))
# print(muta)
#parse fasta file
#var = seq1.splitlines()
#flag = False
#for lin in var:
# if(flag):
# se += lin.strip(' \n\t\r')
# if lin.startswith(">"):
# name = lin
# flag = True
#flag = False
######
# if(len(prop)<1):
# print("Kindly select at least one property...!!!</p>")
## elif(len(seq)<1):
# print("<p>Kindly enter or upload valid input sequence...!!!</p>")
if(True):
p = seq_windowbased(seq,position,ref,alt,window)
if(int(window) ==3):
var1,var2 = p.win3()
elif(int(window) ==5):
var1,var2 = p.win5()
elif(int(window)== 7):
var1,var2 = p.win7()
elif(int(window) ==9):
var1,var2 = p.win9()
elif(int(window) ==11):
var1,var2 = p.win11()
else:
print("<p>WRONG WINDOW SIZE</p>")
#print("""<p>var1:%s,var2:%s,window:%s</p>""")%(var1,var2,window)
lis_pair_ref = []
lis_pair_alt = []
for i in range(0,len(var1)-1):
lis_pair_ref.append(var1[i]+var1[i+1])
for i1 in range(0,len(var2)-1):
lis_pair_alt.append(var2[i1]+var2[i1+1])
fA = pd.DataFrame()
fT = pd.DataFrame()
fG = pd.DataFrame()
fC = pd.DataFrame()
fA1 = pd.DataFrame()
fT1 = pd.DataFrame()
fG1 = pd.DataFrame()
fC1 = pd.DataFrame()
#
for item in lis_pair_ref:
for i in prop:
if i=='P':
p1 = feature_cal(item)
d1 = p1.physico()
# df1= df1.append(d1)
# out1 = pd.concat([df1,d1],axis = 1,ignore_index = True)
df1 = df1.append(d1)
if i =='C':
c1 = feature_cal(item)
e1 = c1.conformational()
df2 = df2.append(e1)
if i == 'L':
# lb = letter_based()
if alt =="A" and ref =="T":
d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
fA = pd.DataFrame(data = d)
d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
fT = pd.DataFrame(data = d)
df3 = fT-fA
if alt =="A" and ref =="G":
d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
fA = pd.DataFrame(data = d)
d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
fG = pd.DataFrame(data = d)
df3 = fG-fA
if alt =="A" and ref =="C":
d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
fA = pd.DataFrame(data = d)
d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
fC = pd.DataFrame(data = d)
df3 = fC-fA
if alt =="T"and ref =="A":
d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
fA = pd.DataFrame(data = d)
d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
fT = pd.DataFrame(data = d)
df3 = fA-fT
if alt =="T"and ref =="G":
d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
fG = pd.DataFrame(data = d)
d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
fT = pd.DataFrame(data = d)
df3 = fG-fT
if alt =="T"and ref =="C":
d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
fC = pd.DataFrame(data = d)
d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
fT = pd.DataFrame(data = d)
df3 = fC-fT
if alt =="C" and ref =="A":
d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
fA = pd.DataFrame(data = d)
d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
fC = pd.DataFrame(data = d)
df3 = fA-fC
if alt =="C" and ref =="G":
d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
fG = pd.DataFrame(data = d)
d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
fC = pd.DataFrame(data = d)
df3 = fG-fC
if alt =="C" and ref =="T":
d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
fT = pd.DataFrame(data = d)
d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
fC = pd.DataFrame(data = d)
df3 = fT-fC
if alt =="G" and ref =="A":
d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
fA = pd.DataFrame(data = d)
d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
fG = pd.DataFrame(data = d)
df3 = fA-fG
if alt =="G" and ref =="T":
d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
fT = pd.DataFrame(data = d)
d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
fG = pd.DataFrame(data = d)
df3 = fT-fG
if alt =="G" and ref =="C":
d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
fC = pd.DataFrame(data = d)
d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
fG = pd.DataFrame(data = d)
df3 = fT-fG
# if ref =="A":
# d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
# fA = pd.DataFrame(data = d)
## df3 = df3.append(f1)
# if ref =="T":
# d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
# fT = pd.DataFrame(data = d)
#
# if ref =="C":
# d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
# fC = pd.DataFrame(data = d)
# if alt =="C":
# d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
# fC = pd.DataFrame(data = d)
# if alt =="G":
# d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
# fG = pd.DataFrame(data = d)
# if ref =="G":
# d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
# fG = pd.DataFrame(data = d)
if i == 'A':
p1 = feature_cal(item)
d1 = p1.physico()
df1 = df1.append(d1)
c1 = feature_cal(item)
e1 = c1.conformational()
df2 = df2.append(e1)
lb = letter_based()
f1 = lb.all_content()
df3 = df3.append(f1)
# print"<p>%s</p>"%(df1.to_html())
#
# df1['value']= df1.transpose()[lis_pair_ref].sum()
# print"<p>%s</p>"%(df1.transpose().to_html())
for itm in lis_pair_alt:
for i in prop:
if i=='P':
p1 = feature_cal(itm)
d1 = p1.physico()
# out1 = pd.concat([df1,d1],axis = 1,ignore_index = True)
df11 = df11.append(d1)
if i =='C':
c1 = feature_cal(itm)
e1 = c1.conformational()
df22 = df22.append(e1)
if i == 'L':
lb = letter_based()
if alt =="A" and ref =="T":
d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
fA1 = pd.DataFrame(data = d)
d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
fT1 = pd.DataFrame(data = d)
df33 = fT1-fA1
if alt =="A" and ref =="G":
d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
fA1 = pd.DataFrame(data = d)
d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
fG1 = pd.DataFrame(data = d)
df33 = fG1-fA1
if alt =="A" and ref =="C":
d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
fA1 = pd.DataFrame(data = d)
d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
fC1 = pd.DataFrame(data = d)
df33 = fC1-fA1
if alt =="T"and ref =="A":
d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
fA1 = pd.DataFrame(data = d)
d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
fT1 = pd.DataFrame(data = d)
df33 = fA1-fT1
if alt =="T"and ref =="G":
d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
fG1 = pd.DataFrame(data = d)
d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
fT1 = pd.DataFrame(data = d)
df33 = fG1-fT1
if alt =="T"and ref =="C":
d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
fC1 = pd.DataFrame(data = d)
d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
fT1 = pd.DataFrame(data = d)
df33 = fC1-fT1
if alt =="C" and ref =="A":
d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
fA1 = pd.DataFrame(data = d)
d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
fC1 = pd.DataFrame(data = d)
df33 = fA1-fC1
if alt =="C" and ref =="G":
d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
fG1 = pd.DataFrame(data = d)
d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
fC1 = pd.DataFrame(data = d)
df33 = fG1-fC1
if alt =="C" and ref =="T":
d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
fT1 = pd.DataFrame(data = d)
d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
fC1 = pd.DataFrame(data = d)
df33 = fT1-fC1
if alt =="G" and ref =="A":
d = {'GC_content':0,'Pyrimidine_TC_content':0,'Purine_AG_content':[float(seq.count('A'))*100/len(seq)],'Keto_GT_content':0,'Adenine_content':[float(seq.count('A'))*100/len(seq)],'Guanine_content':0,'Cytosine_content':0,'Thymine_content' : 0}
fA1 = pd.DataFrame(data = d)
d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
fG1 = pd.DataFrame(data = d)
df33 = fA1-fG1
if alt =="G" and ref =="T":
d = {'GC_content':0,'Pyrimidine_TC_content':((float(0)+ float(seq.count('T')))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : [((float(0)+ float(seq.count('T')))*100/len(seq))],'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : 0,'Thymine_content' : [float(seq.count('T'))*100/len(seq)]}
fT1 = pd.DataFrame(data = d)
d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
fG1 = pd.DataFrame(data = d)
df33 = fT1-fG1
if alt =="G" and ref =="C":
d = {'GC_content':[((float(0)+ float(seq.count('C')))*100/len(seq))],'Pyrimidine_TC_content':((float(seq.count('C'))+ float(0))*100/len(seq)),'Purine_AG_content' : 0,'Keto_GT_content' : 0,'Adenine_content' : 0,'Guanine_content' : 0,'Cytosine_content' : [float(seq.count('C'))*100/len(seq)],'Thymine_content' : 0}
fC1 = pd.DataFrame(data = d)
d = {'GC_content':[((float(seq.count('G'))+ 0)*100/len(seq))],'Pyrimidine_TC_content':0,'Purine_AG_content' : [((float(seq.count('G'))))*100/len(seq)],'Keto_GT_content' : [((float(seq.count('G'))+ 0))*100/len(seq)],'Adenine_content' : 0,'Guanine_content' : [float(seq.count('G'))*100/len(seq)],'Cytosine_content' : 0,'Thymine_content' : 0}
fG1 = pd.DataFrame(data = d)
df33 = fT1-fG1
# f1 = lb.all_content()
# df33 = df33.append(f1)
if i == 'A':
p1 = feature_cal(itm)
d1 = p1.physico()
df11 = df11.append(d1)
c1 = feature_cal(itm)
e1 = c1.conformational()
df22 = df22.append(e1)
lb = letter_based()
f1 = lb.all_content()
df33 = df33.append(f1)
for j in prop:
if j == 'P':
print("Physicochemical Properties:")
df_111 = df1.transpose()
# print(df1)
df_111['sum'] = df_111[lis_pair_ref].astype(float).sum(axis = 1)
cols = ['Properties','Scaleunit','sum']
df = df_111.transpose().drop_duplicates().transpose()[cols]
df_222 = df11.transpose()
df_222['sum'] = df_222[lis_pair_alt].astype(float).sum(axis = 1)
cols = ['Properties','Scaleunit','sum']
df_9 = df_222.transpose().drop_duplicates().transpose()[cols]
# print"<p>%s</p>"% (df11.drop_duplicates().to_html(index = False))
df['Value'] = df['sum']-df_9['sum']
cols = ['Properties','Scaleunit','Value']
# print("<p>%s</p>")%(df_111.transpose().drop_duplicates().transpose().to_html())
# df1[cols].T.to_csv("./out_dna/Physicochemical.csv", index = True,header = False)
n1 = n1.append(df[cols].T)
# print"<p>%s</p>"% (df1[cols].drop_duplicates().to_html(index = False))
# print"<p>%s</p>"% ((df1.drop_duplicates(keep = 'first')).transpose().to_html(index = False))
# print("""<input type="button" value="Download Now!" onclick="window.location = '../../SBFE/out_dna/"""+str(number)+"""temp1.csv';">""")
if j == 'C':
print("Conformational Properties:")
df_111 = df2.transpose()
df_111['sum'] = df_111[lis_pair_ref].astype(float).sum(axis = 1)
cols = ['Properties','Scaleunit','sum']
# print"<p>%s</p>"% (df2.to_html())
df = df_111.transpose().drop_duplicates().transpose()[cols]
# print"<p>%s</p>"% (df2.to_html())
df_222 = df22.transpose()
df_222['sum'] = df_222[lis_pair_alt].astype(float).sum(axis = 1)
cols = ['Properties','Scaleunit','sum']
df9 = df_222.transpose().drop_duplicates().transpose()[cols]
df['Value'] = df['sum']-df9['sum']
cols = ['Properties','Scaleunit','Value']
#
# df2[cols].T.to_csv("./out_dna/Conformational.csv", index = True,header = False)
n2 = n2.append(df[cols].T)
# print"<p>%s</p>"% (df2.drop_duplicates(keep = 'first').to_html(index = False))
# print"<p>%s</p>"% (df2[cols].drop_duplicates().to_html(index = False))
# print("""<input type="button" value="Download Now!" onclick="window.location = '../../SBFE/out_dna/"""+ str(number)+"""temp2.csv';">""")
if j =='L':
print("Nucleotide Content:")
df3.drop_duplicates(keep = 'first').to_csv("./out_dna/Nucleotide.csv",index = False)
n3 = n3.append(df3.drop_duplicates(keep = 'first'))
# new = df3.drop_duplicates(keep = 'first').transpose()[1:]
# new.columns = ['Value']
# print"<p>%s</p>"% (new.to_html())
# print("""<input type="button" value="Download Now!" onclick="window.location = '../../SBFE/out_dna/"""+ str(number)+"""temp3.csv';">""")
if j == 'A':
print("Physico-chemical and Conformational properties:")
df_1112 = df2.transpose()
df_1112['sum'] = df_1112[lis_pair_ref].astype(float).sum(axis = 1)
cols = ['Properties','Scaleunit','sum']
df2 = df_1112.transpose().drop_duplicates().transpose()[cols]
df_111 = df1.transpose()
df_111['sum'] = df_111[lis_pair_ref].astype(float).sum(axis = 1)
cols = ['Properties','Scaleunit','sum']
df1 = df_111.transpose().drop_duplicates().transpose()[cols]
df_all = df1.append(df2)
df = df_all.loc[:,~df_all.columns.duplicated()]
df.to_csv("./out_dna/all.csv",index = False)
# print("<p>%s</p>"%(df.to_html(index = False)))
# print("""<input type="button" value="Download Now!" onclick="window.location = '../../SBFE/out_dna/"""+ str(number)+"""temp_all.csv';">""")
#
# print("<p>%s</p>"%(df_all.to_html(index = False)))
# print("<h5>Letter Based properties</h5>")
# print(df3.drop_duplicates(keep = 'first').transpose())
# print"<p>%s</p>"% (df3.drop_duplicates(keep = 'first').transpose().to_html(columns = cols))
# df3.drop_duplicates(keep = 'first').transpose().to_csv("../../html/SBFE/out_dna/"+ str(number)+"temp3.csv", header = False)
# print("""<input type="button" value="Download Now!" onclick="window.location = '../../SBFE/out_dna/"""+ str(number)+"""temp3.csv';">""")
for j in prop:
if j == 'P':
print("Physicochemical Properties:")
n1.drop_duplicates().to_csv("./out_dna/Physicochemical.csv", index = True,header = False)
# n1 = n1.append(df1[cols].T)
# print"<p>%s</p>"% (df1[cols].drop_duplicates().to_html(index = False))
# print"<p>%s</p>"% ((df1.drop_duplicates(keep = 'first')).transpose().to_html(index = False))
# print("""<input type="button" value="Download Now!" onclick="window.location = '../../SBFE/out_dna/"""+str(number)+"""temp1.csv';">""")
if j == 'C':
print("Conformational Properties:")
#
n2.drop_duplicates().to_csv("./out_dna/Conformational.csv", index = True,header = False)
# print"<p>%s</p>"% (df2.drop_duplicates(keep = 'first').to_html(index = False))
# print"<p>%s</p>"% (df2[cols].drop_duplicates().to_html(index = False))
# print("""<input type="button" value="Download Now!" onclick="window.location = '../../SBFE/out_dna/"""+ str(number)+"""temp2.csv';">""")
if j =='L':
print("Nucleotide Content:")
n3.to_csv("./out_dna/Nucleotide.csv",index = False)
# new = df3.drop_duplicates(keep = 'first').transpose()[1:]
# new.columns = ['Value']
# print"<p>%s</p>"% (new.to_html())
# print("""<input type="button" value="Download Now!" onclick="window.location = '../../SBFE/out_dna/"""+ str(number)+"""temp3.csv';">""")
if j == 'A':
print("Physico-chemical and Conformational properties:")
df_1112 = df2.transpose()
df_1112['sum'] = df_1112[lis_pair_ref].astype(float).sum(axis = 1)
cols = ['Properties','Scaleunit','sum']
df2 = df_1112.transpose().drop_duplicates().transpose()[cols]
df_111 = df1.transpose()
df_111['sum'] = df_111[lis_pair_ref].astype(float).sum(axis = 1)
cols = ['Properties','Scaleunit','sum']
df1 = df_111.transpose().drop_duplicates().transpose()[cols]
df_all = df1.append(df2)
df = df_all.loc[:,~df_all.columns.duplicated()]
df.to_csv("./out_dna/all.csv",index = False)