@@ -784,6 +784,78 @@ def insert_table_to_ppt(table_data_file,slide_n,table_name,left_h,top_h,width_h,
784784 return data_nrows
785785
786786
787+ def insert_table_to_ppt_end (table_data_file ,slide_n ,table_name ,left_h ,top_h ,width_h ,left_t ,top_t ,width_t ,height_t ,font_size ,table_header ,output_ppt_file ,if_print_rowNo ,table_column_width ,table_max_rows_per_slide ):
788+ table_file = open (table_data_file )
789+ lines = table_file .readlines ()
790+ if not lines :
791+ return
792+ first_line = lines [0 ]
793+ rows = len (lines )
794+ first_line_cells = first_line .split ('\t ' )
795+ cols = len (table_header )
796+ header_not_exist_in_table = []
797+ for n in range (len (table_header )):
798+ if_exist = False
799+ if (table_header [n ] in first_line_cells ):
800+ if_exist = True
801+ if not if_exist :
802+ header_not_exist_in_table .append (n )
803+ data_rows = []
804+ for line in lines :
805+ if (line != first_line ):
806+ line_cells = line .strip ('\t ' )
807+ if header_not_exist_in_table :
808+ for num in header_not_exist_in_table :
809+ line_cells .insert (num ," " )
810+ row_data = [cell .strip () for cell in line .split ('\t ' )]
811+ data_rows .append (row_data )
812+
813+ ppt = Presentation (output_ppt_file )
814+ if (rows <= table_max_rows_per_slide ):
815+ total_slides_needed = 1
816+ else :
817+ total_slides_needed = rows // table_max_rows_per_slide + 1
818+
819+ total_rows = len (data_rows )
820+ start_idx = 0
821+ while start_idx < total_rows :
822+ end_idx = min (start_idx + table_max_rows_per_slide , total_rows )
823+ slide_data = data_rows [start_idx :end_idx ]
824+ slide = ppt .slides .add_slide (ppt .slide_layouts [6 ])
825+ shapes = slide .shapes
826+ left = Inches (left_t )
827+ top = Inches (top_t )
828+ width = Inches (width_t )
829+ height = Inches (height_t )
830+ table_rows = len (slide_data ) + 1
831+ table = shapes .add_table (table_rows ,cols ,left ,top ,width ,height ).table
832+ for c in range (cols ):
833+ if table_column_width :
834+ table .columns [c ].width = Inches (table_column_width [c ])
835+ table .cell (0 ,c ).text = table_header [c ]
836+ table .cell (0 ,c ).text_frame .paragraphs [0 ].font .size = Pt (font_size )
837+
838+ for row_idx , row_data in enumerate (slide_data , start = 1 ):
839+ for col_idx in range (cols ):
840+ table .cell (row_idx ,col_idx ).text = str (row_data [col_idx ])
841+ table .cell (row_idx ,col_idx ).text_frame .paragraphs [0 ].font .size = Pt (font_size )
842+
843+ start_idx = end_idx
844+
845+ textbox = slide .shapes .add_textbox (Inches (left_h ),Inches (top_h ),Inches (width_h ),Inches (0.25 ))
846+ tf = textbox .text_frame
847+ if (if_print_rowNo == True ):
848+ tf .paragraphs [0 ].text = table_name + " (N=" + str (table_rows - 1 ) + ")"
849+ else :
850+ tf .paragraphs [0 ].text = table_name
851+ tf .paragraphs [0 ].font .size = Pt (8 )
852+ tf .paragraphs [0 ].font .bold = True
853+ tf .paragraphs [0 ].alignment = PP_ALIGN .CENTER
854+
855+ ppt .save (output_ppt_file )
856+ return total_slides_needed
857+
858+
787859def update_ppt_variant_summary_table (data_nrows ,DNA_sampleID ,RNA_sampleID ,TMB_DRUP_nr ,TMB_DRUP_str ,DNA_variant_summary_file ,RNA_variant_summary_file ,output_file_preMTB_AppendixTable ,output_table_file_filterResults_AllReporVariants_CodingRegion ,output_ppt_file ):
788860 DNA_summary_file = open (DNA_variant_summary_file )
789861 global str_TMB_DRUP
@@ -1534,7 +1606,8 @@ def main(argv):
15341606 slide8_table_font_size = 7
15351607 if_print_rowNo = True
15361608 table8_column_width = [0.54 , 0.96 , 0.96 , 0.51 , 0.73 , 1.12 , 2.26 , 0.79 , 0.81 , 0.53 ]
1537- slide8_table_nrows = insert_table_to_ppt (slide8_table_data_file ,slide8_table_ppSlide ,slide8_table_name ,slide8_header_left ,slide8_header_top ,slide8_header_width ,slide8_table_left ,slide8_table_top ,slide8_table_width ,slide8_table_height ,slide8_table_font_size ,slide8_table_header ,output_ppt_file ,if_print_rowNo ,table8_column_width )
1609+ table_max_rows_per_slide = int (cfg .get ("INPUT" , "table_max_rows_per_slide" )) - 1
1610+ slide8_table_slides = insert_table_to_ppt_end (slide8_table_data_file ,slide8_table_ppSlide ,slide8_table_name ,slide8_header_left ,slide8_header_top ,slide8_header_width ,slide8_table_left ,slide8_table_top ,slide8_table_width ,slide8_table_height ,slide8_table_font_size ,slide8_table_header ,output_ppt_file ,if_print_rowNo ,table8_column_width ,table_max_rows_per_slide )
15381611
15391612 # Insert the CNV_overveiw_plots pictures A2, B3 and C1 into report.
15401613 A2_to_extract = [2 ]
@@ -1545,12 +1618,13 @@ def main(argv):
15451618 B3_C1_to_extract = [4 , 5 ]
15461619 pdf_page_image_to_ppt (CNV_overview_plots_pdf ,output_ppt_file ,B3_C1_to_extract ,width_scale = 1 ,height_scale = 0.5 )
15471620
1548- # Change slides order.
1621+ # Change slides order.
15491622 ppt = Presentation (output_ppt_file )
1623+ slide_count = len (ppt .slides )
15501624 slides = ppt .slides ._sldIdLst
15511625 slides_list = list (slides )
15521626 slides .remove (slides_list [7 ])
1553- slides .insert (12 ,slides_list [7 ])
1627+ slides .insert (slide_count + 1 ,slides_list [7 ])
15541628 ppt .save (output_ppt_file )
15551629 print ("Generate report for " + DNA_sampleID )
15561630 ppt_nr += 1
0 commit comments