1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
6 class Plf:
7 """
8 means piecewise linear function
9 """
11 def __init__(self,num=None):
12 if num == None:
13 self.len = 0
14 self.limits = []
15 self.penalties = []
16 self.transform = ''
17 self.name = ''
18 self.max_len = 0
19 self.min_len = 0
20 else:
21 self.len = num
22 self.limits = linspace(0,40,num)
23 self.penalties = [0]*num
24 self.transform = ''
25 self.name = ''
26 self.max_len = 0
27 self.min_len = 0
30 def convert2SWIG(self):
33 ps.len = len(self.limits)
38 ps.max_len = self.max_len
39 ps.min_len = self.min_len
40 ps.transform = 0
41 ps.name = self.name
43 return ps
46 def base_coord(b1,b2):
47 b1 = b1.lower()
48 b2 = b2.lower()
49 assert b1 in ['a','c','g','t','n']
50 assert b2 in ['a','c','g','t','n']
51 cb = {'a':0, 'c':1, 'g':2, 't':3, 'n':4}
53 b1 = cb[b1]
54 b2 = cb[b2]
56 return b1*5+b2
58 def linspace(a,b,n):
59 intervalLength = b-a
60 stepSize = 1.0*intervalLength / (n-1)
62 interval = [0]*n
63 interval[0] = a
64 interval[-1] = b
65 for i in range(1,n-1):
66 interval[i] = a+(i*stepSize)
68 return interval
70 def logspace(a,b,n):
71 interval = [0]*n
72 begin = 10.0**a
73 end = 10.0**b
74 intervalSize = 1.0*(b-a)/(n-1)
75 interval[0] = begin
76 interval[-1] = end
78 for i in range(1,n-1):
79 interval[i] = 10**(a+i*intervalSize)
81 return interval
83 def log10(x):
84 return math.log(x)/math.log(10)