⇤ ← Revision 1 as of 2005-11-20 17:52:54
Size: 1534
Comment:
|
Size: 1608
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 2: | Line 2: |
"""GradationEffect for BLAST expect value distribution, It uses PIL """ |
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 n = -math.log(evalue)/math.log(10)
20 if n > 70:
21 v = 255
22 elif n < 5:
23 v = 0
24 else:
25 v = int((n-5)*255/65)
26 print evalue, n, v
27 return yuv2rgb(10,50,v)
28
29 def makeSampleImage():
30 img = Image.new('RGB', (80,140), (255,255,255))
31 draw = ImageDraw.Draw(img)
32 for yline in range(128):
33 color = yuv2rgb(10, 50, 255-yline*2)
34 draw.line((5, yline+5, 35, yline+5), fill=color)
35 draw.text((40, 2), '1e-70', fill='black')
36 draw.text((40, 60), '1e-32', fill='black')
37 draw.text((40, 126), '1e-5', fill='black')
38 img.save('test.png',type='PNG')
39
40 def makeEvalueDistribution():
41 img = Image.new('RGB', (80,140), (255,255,255))
42 draw = ImageDraw.Draw(img)
43 y = 10
44 for evalue in (1e-3, 1e-5, 1e-10, 1e-34, 1e-68, 1e-70, 1e-80):
45 draw.rectangle((50, y, 70, y+10),fill=evalue2rgb(evalue))
46 y+=15
47 img.save('test.png',type='PNG')
48
49 if __name__=='__main__':
50 #makeSampleImage()
51 makeEvalueDistribution()