annotate viz_graphs.py @ 13:3ba53d80714b draft default tip

Uploaded
author glogobyte
date Fri, 22 Oct 2021 19:37:27 +0000
parents cc071a0d5d43
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
1 # Import FPDF class
9
f00fce910645 Uploaded
glogobyte
parents: 8
diff changeset
2 from fpdf import FPDF
8
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
3
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
4 # Import glob module to find all the files matching a pattern
9
f00fce910645 Uploaded
glogobyte
parents: 8
diff changeset
5 import glob
8
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
6
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
7 #############################################################################################################################################################3
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
8
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
9 def pdf_after_DE(analysis,top,font_path,iso_star_fl,non_star_fl):
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
10
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
11 # Image extensions
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
12 if analysis=="2":
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
13 image_extensions = ("tem.png","a2.png","non.png")
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
14 else:
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
15 image_extensions = ("tem.png","a2.png")
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
16
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
17 # This list will hold the images file names
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
18 images = []
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
19
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
20 # Build the image list by merging the glob results (a list of files)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
21 # for each extension. We are taking images from current folder.
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
22 for extension in image_extensions:
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
23 images.extend(glob.glob(extension))
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
24
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
25 # Create instance of FPDF class
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
26 pdf = FPDF('P', 'in', 'letter')
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
27 pdf.add_font('uni-arial', '', font_path+"/arial-unicode-ms.ttf", uni=True)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
28 # Add new page. Without this you cannot create the document.
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
29 pdf.add_page()
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
30 # Set font to Arial, 'B'old, 16 pts
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
31 pdf.set_font('Arial', 'B', 16.0)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
32
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
33 # Page header
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
34 pdf.cell(pdf.w-0.5, 0.5, 'Differential expression of miRNAs and isomiRs',align='C')
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
35 #pdf.ln(0.25)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
36
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
37 pdf.ln(0.7)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
38 pdf.set_font('Arial','B', 12.0)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
39 if "tem.png" in images:
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
40 pdf.cell(pdf.w-0.5, 0.5, 'Top '+top+' differentially expressed miRNA and templated isoforms',align='C')
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
41 # Smaller font for image captions
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
42 pdf.set_font('Arial', '', 10.0)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
43 # Image caption
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
44 pdf.ln(0.4)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
45 pdf.image(images[images.index("tem.png")],x=0.8, w=7, h=8)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
46 pdf.ln(0.3)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
47 if iso_star_fl==1:
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
48 pdf.set_font('uni-arial', '', 9.0)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
49 pdf.cell(0.2)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
50 pdf.cell(3.0, 0.0, " ★ IsomiRs potentially generated from multiple loci")
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
51 #pdf.set_font('Arial','B', 12.0)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
52 else:
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
53 print("WARNING: There aren't miRNAs which fullfiled these criteria" )
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
54 pdf.set_font('Arial','B', 12.0)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
55 if "non.png" in images and analysis=="2":
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
56 if "tem.png" in images: pdf.add_page()
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
57 pdf.ln(0.7)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
58 pdf.cell(pdf.w-0.5, 0.5, 'Top '+top+' differentially expressed non-templated isomiRs',align='C')
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
59 pdf.ln(0.4)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
60 pdf.image(images[images.index("non.png")],x=0.8, w=7, h=8)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
61 pdf.ln(0.3)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
62 if non_star_fl==1:
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
63 pdf.set_font('uni-arial', '', 9.0)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
64 pdf.cell(0.2)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
65 pdf.cell(3.0, 0.0, " ★ IsomiRs potentially generated from multiple loci")
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
66
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
67 #pdf.image(images[images.index("non.png")],x=0.5, w=7.5, h=6.5)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
68 else:
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
69 print("WARNING: There aren't non-template miRNAs which fullfiled these criteria" )
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
70
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
71 pdf.set_font('Arial','B', 12.0)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
72 if "a2.png" in images:
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
73 if len(images)>=2: pdf.add_page()
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
74 pdf.ln(0.5)
10
cc071a0d5d43 Uploaded
glogobyte
parents: 9
diff changeset
75 pdf.cell(pdf.w-0.5, 0.5, 'Top differentially expressed miRNAs and isomiRs grouped by arm',align='C')
8
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
76 pdf.ln(0.4)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
77 pdf.image(images[images.index("a2.png")],x=0.8, w=7, h=8)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
78 pdf.ln(0.3)
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
79 else:
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
80 print("WARNING: There aren't non-template miRNAs which fullfiled these criteria" )
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
81
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
82
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
83 pdf.output('report2.pdf', 'F')
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
84
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
85
fa26ea53c055 Uploaded
glogobyte
parents:
diff changeset
86