comparison 0.4.2/bin/create_mqc_data_table.py @ 105:52045ea4679d

"planemo upload"
author kkonganti
date Thu, 27 Jun 2024 14:17:26 -0400
parents
children
comparison
equal deleted inserted replaced
104:17890124001d 105:52045ea4679d
1 #!/usr/bin/env python
2
3 import sys
4 import yaml
5 from textwrap import dedent
6
7 def main() :
8 """
9 Takes a tab-delimited text file with a mandatory header
10 column and generates an HTML table.
11 """
12
13 args = sys.argv
14 if (len(args) < 2 or len(args) > 3):
15 print(f"\nTwo CL arguments are required!\n")
16 exit(1)
17
18 table_sum_on = args[1].lower()
19 workflow_name = args[2].lower()
20
21 with open(f"{table_sum_on}.tblsum.txt", "r") as tbl:
22 header = tbl.readline()
23 header_cols = header.strip().split('\t')
24
25 html = [
26 dedent(
27 f"""<script type="text/javascript">
28 $(document).ready(function () {{
29 $('#cpipes-process-custom-res-{table_sum_on}').DataTable({{
30 scrollX: true,
31 fixedColumns: true, dom: 'Bfrtip',
32 buttons: [
33 'copy',
34 {{
35 extend: 'print',
36 title: 'CPIPES: MultiQC Report: {table_sum_on}'
37 }},
38 {{
39 extend: 'excel',
40 filename: '{table_sum_on}_results',
41 }},
42 {{
43 extend: 'csv',
44 filename: '{table_sum_on}_results',
45 }}
46 ]
47 }});
48 }});
49 </script>
50 <div class="table-responsive">
51 <style>
52 #cpipes-process-custom-res tr:nth-child(even) {{
53 background-color: #f2f2f2;
54 }}
55 </style>
56 <table class="table" style="width:100%" id="cpipes-process-custom-res-{table_sum_on}">
57 <thead>
58 <tr>"""
59 )
60 ]
61
62 for header_col in header_cols:
63 html.append(
64 dedent(
65 f"""
66 <th> {header_col} </th>"""
67 )
68 )
69
70 html.append(
71 dedent(
72 """
73 </tr>
74 </thead>
75 <tbody>"""
76 )
77 )
78
79 for row in tbl:
80 html.append("<tr>\n")
81 data_cols = row.strip().split('\t')
82 if ( len(header_cols) != len(data_cols) ):
83 print(f"\nWARN: Number of header columns ({len(header_cols)}) and data " +
84 f"columns ({len(data_cols)}) are not equal!\nWill append empty columns!\n")
85 if ( len(header_cols) > len(data_cols) ):
86 data_cols += (( len(header_cols) - len(data_cols) ) * ' ' )
87 print(len(data_cols))
88 else:
89 header_cols += (( len(data_cols) - len(header_cols) ) * ' ')
90
91 html.append(
92 dedent(
93 f"""
94 <td><samp>{data_cols[0]}</samp></td>
95 """
96 )
97 )
98
99 for data_col in data_cols[1:]:
100 html.append(
101 dedent(
102 f"""<td>{data_col}</td>
103 """
104 )
105 )
106 html.append("</tr>\n")
107 html.append("</tbody>\n")
108 html.append("</table>\n")
109 html.append("</div>\n")
110
111 mqc_yaml = {
112 "id": f"{table_sum_on.upper()}_collated_table",
113 "section_name": f"{table_sum_on.upper()}",
114 "section_href": f"https://cfsan-git.fda.gov/Kranti.Konganti/{workflow_name}",
115 "plot_type": "html",
116 "description": "The results table shown here is a collection from all samples.",
117 "data": ('').join(html),
118 }
119
120 with open(f"{table_sum_on.lower()}_mqc.yml", "w") as html_mqc:
121 yaml.dump(mqc_yaml, html_mqc, default_flow_style=False)
122
123 if __name__ == "__main__":
124 main()