Mercurial > repos > tyty > structurefold
comparison upload/reactivity_cal/react_norm_function.py @ 34:d74ed492efdd draft
Uploaded
| author | tyty |
|---|---|
| date | Mon, 20 Oct 2014 14:55:16 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 33:1a92d934f8d1 | 34:d74ed492efdd |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 # -*- coding: utf-8 -*- | |
| 3 import sys | |
| 4 from Bio import SeqIO | |
| 5 import math | |
| 6 from parse_dis_react import * | |
| 7 | |
| 8 def cap(a,value): | |
| 9 if a>=value: | |
| 10 return value | |
| 11 else: | |
| 12 return a | |
| 13 | |
| 14 def react_norm(react_file, result_file, capped_value): | |
| 15 print("Normalizing.....") | |
| 16 react1 = parse_dist(react_file) | |
| 17 react = react1[1] | |
| 18 h = file(result_file, 'w') | |
| 19 | |
| 20 capped = int(capped_value) | |
| 21 | |
| 22 all_react = [] | |
| 23 | |
| 24 | |
| 25 for t in react: | |
| 26 if react[t]!='null': | |
| 27 for i in range(len(react[t])): | |
| 28 if react[t][i]!='NA': | |
| 29 all_react.append(float(react[t][i])) | |
| 30 | |
| 31 | |
| 32 all_react.sort(reverse = True) | |
| 33 | |
| 34 | |
| 35 eight = all_react[int(len(all_react)*0.02):int(len(all_react)*0.1)] | |
| 36 meight = sum(eight)/len(eight) | |
| 37 | |
| 38 for t in react: | |
| 39 h.write(t) | |
| 40 h.write('\n') | |
| 41 if react[t]!='null': | |
| 42 for i in range((len(react[t])-1)): | |
| 43 if react[t][i]!='NA': | |
| 44 h.write(str(cap((float(react[t][i])/meight),capped))) | |
| 45 else: | |
| 46 h.write('NA') | |
| 47 h.write('\t') | |
| 48 if react[t][i+1]!='NA': | |
| 49 h.write(str(cap((float(react[t][i+1])/meight),capped))) | |
| 50 else: | |
| 51 h.write('NA') | |
| 52 h.write('\n') | |
| 53 | |
| 54 h.close() | |
| 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 |
