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