1 """
2 BIANA: Biologic Interactions and Network Analysis
3 Copyright (C) 2009 Javier Garcia-Garcia, Emre Guney, Baldo Oliva
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 """
19
20
21
22
23
25 value = int(value)
26 if value<0:
27 value = -1*value | pow(2,max_bytes*8-1)
28 temp = [ '\x00' for x in xrange(max_bytes) ]
29 del x
30 pos = max_bytes-1
31 while value>255:
32 temp[pos] = chr(value%255)
33 pos-=1
34 value/=255
35 if value==255: temp[pos] = chr(255)
36 else: temp[pos] = chr(value%255)
37 return "".join(temp)
38
40 value = 0
41 pos = len(ascii)-1
42 for x in xrange(len(ascii)):
43 value += ord(ascii[x])*pow(255,pos)
44 pos-=1
45 if ord(ascii[0])&128:
46 return -1* value ^ pow(2,len(ascii)*8-1)
47 else:
48 return value
49
50
51
52
54
55 value = int(value)
56 temp = [ '\x00' for x in xrange(max_bytes) ]
57 del x
58 pos = max_bytes-1
59 while value>255:
60 temp[pos] = chr(value%255)
61 pos-=1
62 value/=255
63 if value==255: temp[pos] = chr(255)
64 else: temp[pos] = chr(value%255)
65
66 return "".join(temp)
67
68
70
71 value = 0
72
73 pos = len(ascii)-1
74
75 for x in xrange(len(ascii)):
76 value += ord(ascii[x])*pow(255,pos)
77 pos-=1
78
79 return value
80
81
82
83
84
88
92
94
95 return int_to_ascii(bytes,float(value)*pow(10,dec_positions))
96
98
99 return ascii_to_int(ascii)/float(pow(10,dec_positions))
100
101
102
103
104
105
109
113
117
121
122
126
128
129 return [ ascii_to_int(ascii[x:x+bytes]) for x in xrange(0,len(ascii),bytes)]
130
134
136
137 return [ ascii_to_float(dec_bytes,ascii[x:x+bytes]) for x in xrange(0,len(ascii),bytes)]
138