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