comparison viz_graphs.py @ 8:fa26ea53c055 draft

Uploaded
author glogobyte
date Wed, 13 Oct 2021 11:20:06 +0000
parents
children f00fce910645
comparison
equal deleted inserted replaced
7:77d835d85a2f 8:fa26ea53c055
1 # Import FPDF class
2 from fpdf import FPDF
3
4 # Import glob module to find all the files matching a pattern
5 import glob
6
7 def pdf_before_DE(analysis):
8
9 # Image extensions
10 if analysis=="2":
11 image_extensions = ("c_hist_red.png","t_hist_red.png","pie_non.png","spider_red.png","spider_non_red.png","c_logo.png","t_logo.png","c_bar.png","t_bar.png")
12 else:
13 image_extensions = ("c_hist_red.png","t_hist_red.png","pie_tem.png","spider_red.png","spider_non_red.png")
14 # This list will hold the images file names
15 images = []
16
17 # Build the image list by merging the glob results (a list of files)
18 # for each extension. We are taking images from current folder.
19 for extension in image_extensions:
20 images.extend(glob.glob(extension))
21
22 # Create instance of FPDF class
23 pdf = FPDF('P', 'in', 'A4')
24 # Add new page. Without this you cannot create the document.
25 pdf.add_page()
26 # Set font to Arial, 'B'old, 16 pts
27 pdf.set_font('Arial', 'B', 20.0)
28
29 # Page header
30 pdf.cell(pdf.w-0.5, 0.5, 'IsomiR Profile Report',align='C')
31 pdf.ln(0.7)
32 pdf.set_font('Arial','', 16.0)
33 pdf.cell(pdf.w-0.5, 0.5, 'sRNA Length Distribution',align='C')
34
35 # Smaller font for image captions
36 pdf.set_font('Arial', '', 11.0)
37
38 # Image caption
39 pdf.ln(0.5)
40
41 yh=FPDF.get_y(pdf)
42 pdf.image(images[0],x=0.3,w=4, h=3)
43 pdf.image(images[1],x=4,y=yh, w=4, h=3)
44 pdf.ln(0.3)
45
46 # Image caption
47 pdf.cell(0.2)
48 pdf.cell(3.0, 0.0, " Mapped and unmapped reads to custom precussor arm reference DB (5p and 3p arms) in Control (left)")
49 pdf.ln(0.2)
50 pdf.cell(0.2)
51 pdf.cell(3.0, 0.0, " and Treated (right) groups")
52
53
54 pdf.ln(0.5)
55 h1=FPDF.get_y(pdf)
56 pdf.image(images[2],x=1, w=6.5, h=5)
57 h2=FPDF.get_y(pdf)
58 FPDF.set_y(pdf,h1+0.2)
59 pdf.set_font('Arial','', 14.0)
60 pdf.cell(pdf.w-0.5, 0.5, 'Template and non-template IsomiRs',align='C')
61 pdf.set_font('Arial', '', 11.0)
62 FPDF.set_y(pdf,h2)
63 FPDF.set_y(pdf,9.5)
64 # Image caption
65 pdf.cell(0.2)
66 if analysis=="2":
67 pdf.cell(3.0, 0.0, " Template, non-template, miRNA reference and unmapped sequences as percentage of total sRNA")
68 else:
69 pdf.cell(3.0, 0.0, " Template, miRNA reference and unmapped sequences as percentage of total sRNA")
70 pdf.ln(0.2)
71 pdf.cell(0.2)
72 pdf.cell(3.0, 0.0, " reads in Control (left) and treated (right) groups")
73
74
75
76 pdf.add_page()
77 pdf.set_font('Arial', 'B', 16.0)
78 pdf.cell(pdf.w-0.5, 0.5, "Reference form and isomiR among total miRNA reads",align='C')
79 pdf.ln(0.7)
80 pdf.set_font('Arial', 'B', 12.0)
81 pdf.cell(pdf.w-0.5, 0.5, "Template isomiR profile (redundant)",align='C')
82 pdf.ln(0.5)
83 pdf.image(images[3],x=1.5, w=5.5, h=4)
84 pdf.ln(0.6)
85 pdf.cell(pdf.w-0.5, 0.0, "Template isomiR profile (non-redundant)",align='C')
86 pdf.set_font('Arial', '', 12.0)
87 pdf.ln(0.2)
88 pdf.image(images[4],x=1.5, w=5.5, h=4)
89 pdf.ln(0.3)
90 pdf.set_font('Arial', '', 11.0)
91 pdf.cell(0.2)
92 pdf.cell(3.0, 0.0, " * IsomiRs potentialy initiated from multiple loci")
93
94
95 if analysis=="2":
96 pdf.add_page('L')
97
98 pdf.set_font('Arial', 'B', 16.0)
99 pdf.cell(pdf.w-0.5, 0.5, "Non-template IsomiRs",align='C')
100 pdf.ln(0.5)
101 pdf.set_font('Arial', 'B', 12.0)
102 pdf.cell(pdf.w-0.5, 0.5, "3' Additions of reference of isomiR sequence",align='C')
103 pdf.ln(0.7)
104
105 yh=FPDF.get_y(pdf)
106 pdf.image(images[5],x=1.5,w=3.65, h=2.65)
107 pdf.image(images[7],x=6.5,y=yh, w=3.65, h=2.65)
108 pdf.ln(0.5)
109 yh=FPDF.get_y(pdf)
110 pdf.image(images[6],x=1.5,w=3.65, h=2.65)
111 pdf.image(images[8],x=6.5,y=yh, w=3.65, h=2.65)
112
113 pdf.close()
114 pdf.output('report1.pdf','F')
115
116
117
118
119 #############################################################################################################################################################3
120
121 def pdf_after_DE(analysis,top,font_path,iso_star_fl,non_star_fl):
122
123 # Image extensions
124 if analysis=="2":
125 image_extensions = ("tem.png","a2.png","non.png")
126 else:
127 image_extensions = ("tem.png","a2.png")
128
129 # This list will hold the images file names
130 images = []
131
132 # Build the image list by merging the glob results (a list of files)
133 # for each extension. We are taking images from current folder.
134 for extension in image_extensions:
135 images.extend(glob.glob(extension))
136
137 # Create instance of FPDF class
138 pdf = FPDF('P', 'in', 'letter')
139 pdf.add_font('uni-arial', '', font_path+"/arial-unicode-ms.ttf", uni=True)
140 # Add new page. Without this you cannot create the document.
141 pdf.add_page()
142 # Set font to Arial, 'B'old, 16 pts
143 pdf.set_font('Arial', 'B', 16.0)
144
145 # Page header
146 pdf.cell(pdf.w-0.5, 0.5, 'Differential expression of miRNAs and isomiRs',align='C')
147 #pdf.ln(0.25)
148
149 pdf.ln(0.7)
150 pdf.set_font('Arial','B', 12.0)
151 if "tem.png" in images:
152 pdf.cell(pdf.w-0.5, 0.5, 'Top '+top+' differentially expressed miRNA and templated isoforms',align='C')
153 # Smaller font for image captions
154 pdf.set_font('Arial', '', 10.0)
155 # Image caption
156 pdf.ln(0.4)
157 pdf.image(images[images.index("tem.png")],x=0.8, w=7, h=8)
158 pdf.ln(0.3)
159 if iso_star_fl==1:
160 pdf.set_font('uni-arial', '', 9.0)
161 pdf.cell(0.2)
162 pdf.cell(3.0, 0.0, " ★ IsomiRs potentially generated from multiple loci")
163 #pdf.set_font('Arial','B', 12.0)
164 else:
165 print("WARNING: There aren't miRNAs which fullfiled these criteria" )
166 pdf.set_font('Arial','B', 12.0)
167 if "non.png" in images and analysis=="2":
168 if "tem.png" in images: pdf.add_page()
169 pdf.ln(0.7)
170 pdf.cell(pdf.w-0.5, 0.5, 'Top '+top+' differentially expressed non-templated isomiRs',align='C')
171 pdf.ln(0.4)
172 pdf.image(images[images.index("non.png")],x=0.8, w=7, h=8)
173 pdf.ln(0.3)
174 if non_star_fl==1:
175 pdf.set_font('uni-arial', '', 9.0)
176 pdf.cell(0.2)
177 pdf.cell(3.0, 0.0, " ★ IsomiRs potentially generated from multiple loci")
178
179 #pdf.image(images[images.index("non.png")],x=0.5, w=7.5, h=6.5)
180 else:
181 print("WARNING: There aren't non-template miRNAs which fullfiled these criteria" )
182
183 pdf.set_font('Arial','B', 12.0)
184 if "a2.png" in images:
185 if len(images)>=2: pdf.add_page()
186 pdf.ln(0.5)
187 pdf.cell(pdf.w-0.5, 0.5, 'Top '+top+' differentially expressed miRNAs and isomiRs grouped by arm',align='C')
188 pdf.ln(0.4)
189 pdf.image(images[images.index("a2.png")],x=0.8, w=7, h=8)
190 pdf.ln(0.3)
191 else:
192 print("WARNING: There aren't non-template miRNAs which fullfiled these criteria" )
193
194
195 pdf.output('report2.pdf', 'F')
196
197
198