annotate reactivity_cal/react_norm_function.py @ 119:7bb98e9296e9 draft default tip

Uploaded
author tyty
date Tue, 14 Apr 2015 14:18:40 -0400
parents 8bcc5cbbdf91
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
1 #!/usr/bin/env python
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
2 # -*- coding: utf-8 -*-
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
3 import sys
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
4 from Bio import SeqIO
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
5 import math
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
6 from parse_dis_react import *
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
7
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
8 def cap(a,value):
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
9 if a>=value:
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
10 return value
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
11 else:
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
12 return a
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
13
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
14 def react_norm(react_file, result_file, capped_value):
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
15 print("Normalizing.....")
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
16 react1 = parse_dist(react_file)
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
17 react = react1[1]
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
18 h = file(result_file, 'w')
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
19
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
20 capped = int(capped_value)
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
21
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
22 all_react = []
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
23
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
24
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
25 for t in react:
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
26 if react[t]!='null':
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
27 for i in range(len(react[t])):
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
28 if react[t][i]!='NA':
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
29 all_react.append(float(react[t][i]))
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
30
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
31
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
32 all_react.sort(reverse = True)
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
33
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
34
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
35 eight = all_react[int(len(all_react)*0.02):int(len(all_react)*0.1)]
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
36 meight = sum(eight)/len(eight)
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
37
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
38 for t in react:
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
39 h.write(t)
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
40 h.write('\n')
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
41 if react[t]!='null':
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
42 for i in range((len(react[t])-1)):
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
43 if react[t][i]!='NA':
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
44 h.write(str(float('%.3f'%cap((float(react[t][i])/meight),capped))))
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
45 else:
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
46 h.write('NA')
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
47 h.write('\t')
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
48 if react[t][i+1]!='NA':
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
49 h.write(str(float('%.3f'%cap((float(react[t][i+1])/meight),capped))))
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
50 else:
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
51 h.write('NA')
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
52 h.write('\n')
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
53
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
54 h.close()
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
55
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
56
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
57
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
58
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
59
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
60
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
61
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
62
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
63
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
64
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
65
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
66
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
67
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
68
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
69
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
70
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
71
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
72
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
73
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
74
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
75
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
76
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
77
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
78
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
79
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
80
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
81
8bcc5cbbdf91 Uploaded
tyty
parents:
diff changeset
82