annotate reactivity_cal/react_norm_function.py @ 92:976dcf4d45b2 draft

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