Mercurial > repos > glogobyte > mirviz
comparison viz_graphs.py @ 10:cc071a0d5d43 draft
Uploaded
| author | glogobyte |
|---|---|
| date | Wed, 20 Oct 2021 08:45:05 +0000 |
| parents | f00fce910645 |
| children |
comparison
equal
deleted
inserted
replaced
| 9:f00fce910645 | 10:cc071a0d5d43 |
|---|---|
| 1 # Import FPDF class | 1 # Import FPDF class |
| 2 from fpdf import FPDF | 2 from fpdf import FPDF |
| 3 | 3 |
| 4 # Import glob module to find all the files matching a pattern | 4 # Import glob module to find all the files matching a pattern |
| 5 import glob | 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 | 6 |
| 119 #############################################################################################################################################################3 | 7 #############################################################################################################################################################3 |
| 120 | 8 |
| 121 def pdf_after_DE(analysis,top,font_path,iso_star_fl,non_star_fl): | 9 def pdf_after_DE(analysis,top,font_path,iso_star_fl,non_star_fl): |
| 122 | 10 |
| 182 | 70 |
| 183 pdf.set_font('Arial','B', 12.0) | 71 pdf.set_font('Arial','B', 12.0) |
| 184 if "a2.png" in images: | 72 if "a2.png" in images: |
| 185 if len(images)>=2: pdf.add_page() | 73 if len(images)>=2: pdf.add_page() |
| 186 pdf.ln(0.5) | 74 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') | 75 pdf.cell(pdf.w-0.5, 0.5, 'Top differentially expressed miRNAs and isomiRs grouped by arm',align='C') |
| 188 pdf.ln(0.4) | 76 pdf.ln(0.4) |
| 189 pdf.image(images[images.index("a2.png")],x=0.8, w=7, h=8) | 77 pdf.image(images[images.index("a2.png")],x=0.8, w=7, h=8) |
| 190 pdf.ln(0.3) | 78 pdf.ln(0.3) |
| 191 else: | 79 else: |
| 192 print("WARNING: There aren't non-template miRNAs which fullfiled these criteria" ) | 80 print("WARNING: There aren't non-template miRNAs which fullfiled these criteria" ) |
