annotate reactivity_cal/react_norm_function.py @ 5:7a8ddf1819b1 draft

Uploaded
author tyty
date Mon, 15 Sep 2014 14:52:52 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
1 #!/usr/bin/env python
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
2 # -*- coding: utf-8 -*-
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
3 import sys
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
4 from Bio import SeqIO
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
5 import math
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
6 from parse_dis_react import *
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
7
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
8 def cap(a,value):
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
9 if a>=value:
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
10 return value
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
11 else:
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
12 return a
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
13
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
14 def react_norm(react_file, result_file, capped_value):
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
15 print("Normalizing.....")
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
16 react1 = parse_dist(react_file)
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
17 react = react1[1]
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
18 h = file(result_file, 'w')
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
19
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
20 capped = int(capped_value)
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
21
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
22 all_react = []
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
23
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
24
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
25 for t in react:
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
26 if react[t]!='null':
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
27 for i in range(len(react[t])):
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
28 if react[t][i]!='NA':
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
29 all_react.append(float(react[t][i]))
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
30 # except:
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
31 # print(react[t][i])
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
32 # print(t)
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
33 # print(i)
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
34
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
35 all_react.sort(reverse = True)
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
36 #print((all_react))
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
37 #print(all_react[int(len(all_react)*0.02)])
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
38 #print(all_react[int(len(all_react)*0.03)])
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
39 #print(all_react[int(len(all_react)*0.025)])
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
40 #print(all_react[int(len(all_react)*0.04)])
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
41 #print(all_react[int(len(all_react)*0.05)])
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
42 '''
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
43 mean = sum(all_react)/len(all_react)
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
44 print(mean)
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
45 temp = 0
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
46
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
47 for i in range(len(all_react)):
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
48 temp = temp+all_react[i]*all_react[i]
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
49 temp = temp/len(all_react)
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
50 sd = math.sqrt(temp-mean*mean)
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
51 '''
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
52 eight = all_react[int(len(all_react)*0.02):int(len(all_react)*0.1)]
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
53 meight = sum(eight)/len(eight)
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
54
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
55 for t in react:
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
56 h.write(t)
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
57 h.write('\n')
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
58 if react[t]!='null':
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
59 if (t.find('AT1G29930')==-1) and (t.find('At1g29930')==-1):
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
60 for i in range((len(react[t])-1)):
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
61 if react[t][i]!='NA':
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
62 h.write(str(cap((float(react[t][i])/meight),capped)))
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
63 else:
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
64 h.write('NA')
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
65 h.write('\t')
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
66 if react[t][i+1]!='NA':
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
67 h.write(str(cap((float(react[t][i+1])/meight),capped)))
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
68 else:
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
69 h.write('NA')
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
70 h.write('\n')
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
71 else:
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
72 for i in range((len(react[t])-1)):
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
73 if react[t][i]!='NA':
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
74 h.write(str(float(react[t][i])*2.6))
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
75 else:
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
76 h.write('NA')
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
77 h.write('\t')
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
78 if react[t][i+1]!='NA':
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
79 h.write(str(float(react[t][i])*2.6))
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
80 else:
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
81 h.write('NA')
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
82 h.write('\n')
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
83
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
84
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
85
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
86 h.close()
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
87
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
88
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
89
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
90
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
91
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
92
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
93
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
94
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
95
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
96
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
97
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
98
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
99
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
100
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
101
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
102
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
103
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
104
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
105
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
106
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
107
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
108
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
109
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
110
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
111
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
112
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
113
7a8ddf1819b1 Uploaded
tyty
parents:
diff changeset
114