1 """GradationEffect for BLAST expect value distribution, It uses PIL
2 """
3 import Image, ImageDraw
4 import math
5
6 def yuv2rgb(Y,U,V):
7 R = 1.164*(Y - 16) + 1.596*(V - 128)
8 G = 1.164*(Y - 16) - 0.813*(V - 128) - 0.391*(U - 128)
9 B = 1.164*(Y - 16) + 2.018*(U - 128)
10 return tuple(map(int, (R,G,B)))
11
12 def rgb2yuv(R,G,B):
13 Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
14 U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128
15 V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
16 return tuple(map(int, (Y,U,V)))
17
18 def evalue2rgb(evalue):
19 try:
20 n = -math.log(evalue)/math.log(10)
21 except OverflowError:
22 n = 71
23 if n > 70:
24 v = 255
25 elif n < 5:
26 v = 0
27 else:
28 v = int((n-5)*255/65)
29 return yuv2rgb(10,50,v)
30
31 def makeSampleImage():
32 img = Image.new('RGB', (80,140), (255,255,255))
33 draw = ImageDraw.Draw(img)
34 for yline in range(128):
35 color = yuv2rgb(10, 50, 255-yline*2)
36 draw.line((5, yline+5, 35, yline+5), fill=color)
37 draw.text((40, 2), '1e-70', fill='black')
38 draw.text((40, 60), '1e-32', fill='black')
39 draw.text((40, 126), '1e-5', fill='black')
40 img.save('test.png',type='PNG')
41
42 def makeEvalueDistribution():
43 img = Image.new('RGB', (80,140), (255,255,255))
44 draw = ImageDraw.Draw(img)
45 y = 10
46 for evalue in (1e-3, 1e-5, 1e-10, 1e-34, 1e-68, 1e-70, 1e-80):
47 draw.rectangle((50, y, 70, y+10),fill=evalue2rgb(evalue))
48 y+=15
49 img.save('test.png',type='PNG')
50
51 if __name__=='__main__':
52
53 makeEvalueDistribution()