Skip to content

Commit

Permalink
Merge pull request #79 from eastgenomics/v1.5.0-release
Browse files Browse the repository at this point in the history
v1.5.0 release (#79)

Co-Authored-By: Aisha <[email protected]>
Co-Authored-By: Yu-jinKim <[email protected]>
Co-Authored-By: mattgarner <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2022
2 parents 0268549 + bfbd1d9 commit a6371df
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ output/*
/*.html
/*.tsv
report_new.py
*.pyc
75 changes: 65 additions & 10 deletions bin/coverage_report_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def summary_gene_plot(self, cov_summary):
lambda x: f"{x[0]} ({x[1]})", axis=1
)

summary_plot, axs = plt.subplots(figsize=(25, 7.5))
summary_plot, axs = plt.subplots(figsize=(25, 10))

genes100pct = None

Expand Down Expand Up @@ -402,8 +402,8 @@ def summary_gene_plot(self, cov_summary):
red = mpatches.Patch(color='red', label='<90%')

plt.legend(
handles=[green, orange, red], loc='upper center',
bbox_to_anchor=(0.5, -0.32),
handles=[green, orange, red], loc='lower center',
bbox_to_anchor=(0.5, -0.4),
fancybox=True, shadow=True, ncol=12, fontsize=14
)

Expand All @@ -416,7 +416,7 @@ def summary_gene_plot(self, cov_summary):
axs.set_xticks(axs.get_xticks()[::3])
axs.tick_params(axis='both', which='major', labelsize=10)
plt.figtext(
0.5, 0.1,
0.505, 0.01,
"Some gene labels are not shown due to high number of genes",
ha="center", fontsize=12
)
Expand All @@ -425,7 +425,7 @@ def summary_gene_plot(self, cov_summary):
axs.set_xticks(axs.get_xticks()[::2])
axs.tick_params(axis='both', which='major', labelsize=10)
plt.figtext(
0.5, 0.1,
0.505, 0.01,
"Some gene labels are not shown due to high number of genes",
ha="center", fontsize=12
)
Expand Down Expand Up @@ -1096,6 +1096,11 @@ def generate_report(self, cov_stats, cov_summary, snps_low_cov,
)
calculate = calculateValues(self.threshold)

if args.panel_filters:
filter_str = self.panel_filters(filters=args.panel_filters)
else:
filter_str = ''

# apply styling to tables for displaying in report
sub_threshold_stats, low_exon_columns, gene_issues,\
exon_issues = styling.style_sub_threshold()
Expand Down Expand Up @@ -1129,6 +1134,7 @@ def generate_report(self, cov_stats, cov_summary, snps_low_cov,
report_vals["exon_issues"] = str(exon_issues)
report_vals["build"] = build
report_vals["panel"] = panel
report_vals["filter_str"] = filter_str
report_vals["vcfs"] = vcfs
report_vals["version"] = version
report_vals["panel_pct_coverage"] = panel_pct_coverage
Expand All @@ -1152,6 +1158,30 @@ def generate_report(self, cov_stats, cov_summary, snps_low_cov,
self.write_report(html_string, args.output)


def panel_filters(self, filters) -> str:
"""
Generate HTML formatted filters for drop down menu for full
gene plots in the report
Parameters
----------
filters : list
list of filters formatted as ['panel1:gene1,gene2', 'panel2:gene3,gene4']
Returns
-------
str
HTML string of filter options for drop down menu
"""
filters = {x.split(':')[0]: x.split(':')[1] for x in filters}
filter_str = ""

for panel, genes in filters.items():
filter_str += f'<option value="{genes}">{panel}</option>'

return filter_str


def build_report(
self, html_template, total_stats, gene_stats, sub_threshold_stats,
low_exon_columns, snps_low_cov, snps_high_cov, snps_no_cov, fig,
Expand Down Expand Up @@ -1187,6 +1217,18 @@ def build_report(
alt="" style="vertical-align:middle; padding-bottom:3px">'.format(
data_uri)

hide_filter = ""
hide_plots = ""

if all_plots == "":
# no plots to show => hide the div with the plots
hide_plots = 'style="display:none;"'

if report_vals["filter_str"] == "":
# filter str is empty => no panel filters set for plots =>
# hide the drop down filter menu
hide_filter = 'style="display:none;"'

t = Template(html_template)

date = datetime.today().strftime('%Y-%m-%d')
Expand All @@ -1207,6 +1249,9 @@ def build_report(
low_cov_plots=fig,
coverage_per_chromosome_fig=coverage_per_chromosome_fig,
all_plots=all_plots,
panel_filters=report_vals["filter_str"],
hide_filter=hide_filter,
hide_plots=hide_plots,
summary_plot=summary_plot,
gene_stats=gene_stats,
gene_table_headings=report_vals["gene_table_headings"],
Expand Down Expand Up @@ -1251,9 +1296,9 @@ def write_report(self, html_string, output_name):
out_dir = os.path.join(bin_dir, "../output/")
outfile = os.path.join(out_dir, output_name)

file = open(outfile, 'w')
file.write(html_string)
file.close()
with open(outfile, 'w') as fh:
fh.write(html_string)

print(f"Output report written to {outfile}")


Expand Down Expand Up @@ -1389,6 +1434,16 @@ def parse_args():
default=-1,
required=False
)
parser.add_argument(
'--panel_filters', nargs='+',
help=(
'Preset filters of genes / transcripts to set for the full gene '
'plots, these will be presented in a drop down menu for filtering '
'the plots. These should be passed as key:value pairs of panel '
'name to display in the drop down and a comma separated list of '
'gene symbols to filter with (i.e. panel1:gene1,gene2,gene3...)'
)
)
parser.add_argument(
'-m', '--summary',
help="If passed, a short paragraph will be included in the\
Expand Down Expand Up @@ -1504,8 +1559,8 @@ def main():
all_plots = pool.map(plots.all_gene_plots, split_dfs)
all_plots = "".join(all_plots)
else:
all_plots = "<br><b>Full gene plots have been omitted from this report\
due to the high number of genes in the panel.</b></br>"
# not generating plots => set to empty string to hide section in report
all_plots = ""

if len(low_raw_cov.index) > 0:
# some low covered regions, generate plots
Expand Down
8 changes: 5 additions & 3 deletions bin/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,14 @@ def get_panel_name(panel):
# https://github.com/eastgenomics/eggd_generate_bed
panel_name = [x.strip("_") for x in panel_name.split("&&") if x]
panel_name = [
x.strip("_b37").strip("_b38") for x in panel_name if x
x.replace("_b37", "").replace("_b38", "") for x in panel_name if x
]
panel_name = [x.replace("_", " ") for x in panel_name if x]
panel_name = ",&nbsp".join(panel_name)
panel = "<li>Panel(s) / gene(s) included in report: <b>{}</b>\
</li>".format(panel_name)
panel = (
"<li>Panel(s) / gene(s) included in report: "
f"<b>{panel_name}</b></li>"
)
else:
panel = ""

Expand Down
81 changes: 70 additions & 11 deletions data/templates/single_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ <h2> Per gene coverage summary </h2>
<br></br>

<!-- 'Table' for adding full gene plots to -->
<div class="category-filter">
<select id="categoryFilter" class="form-control" $hide_filter>
<option value="">Show All</option>
$panel_filters
</select>
</div>
<table id="fullPlots" class='row-border nowrap noHover pageResize'>
<thead>
<tr>
Expand All @@ -229,7 +235,6 @@ <h2> Per gene coverage summary </h2>
</tr>
</thead>
</table>

</div>

<br></br><hr><br></br>
Expand Down Expand Up @@ -377,13 +382,11 @@ <h2>Coverage per chromosome</h2>
<!-- function to conditionally hide low exon plots div if no plots to display -->
<script>
// $exon_issues is int passed from report script
var cov = $exon_issues
if (exon_check == 0) {
if (exon_issues == 0) {
document.getElementById('low_exon_plots').style.display = "none";
}
</script>


<!-- function to conditionally hide coverage-per-chromosome div if not required -->
<script>
// $coverage_per_chromosome_fig is either int or string passed from report script
Expand Down Expand Up @@ -418,11 +421,14 @@ <h2>Coverage per chromosome</h2>
$(document).ready(function() {
var data = [ $all_plots ];

$('#fullPlots').DataTable( {
var table = $('#fullPlots').DataTable({
data: data,
deferRender: true,
pageResize: true,
info: false,
search: {
regex: true
},
scrollY: "75vh",
scrollCollapse: true,
scroller: true,
Expand All @@ -448,7 +454,39 @@ <h2>Coverage per chromosome</h2>
}
]
});

// Use the built in datatables API to filter rows from dropdown selection
$("#fullPlots_filter.dataTables_filter").append($("#categoryFilter"));

$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
var selectedItem = $('#categoryFilter').val()
var category = data[0]; // hidden column with gene symbol

if ( settings.sInstance != 'fullPlots' ) {
// only applying filters for full gene plots
return true;
}

// split string of genes / transcripts from dropdown to separate items
let split = selectedItem.split(',');

// split gene transcript string in table row to match on either
var [ gene, transcript ] = category.split(' ')

if (selectedItem === "" || split.some((item) => gene == item || transcript == item)) {
return true;
}
return false;
}
);

// Set the change event for the filter dropdown to redraw the datatable each time
// a user selects a new filter.
$("#categoryFilter").change(function (e) {
table.draw();
});
});
</script>


Expand Down Expand Up @@ -528,6 +566,9 @@ <h2>Coverage per chromosome</h2>
'language': {
'processing': 'Loading...'
},
search: {
regex: true
},

"preDrawCallback": function (oSettings) {
// function to create responsive container over dataTable for adding plots to
Expand Down Expand Up @@ -668,6 +709,9 @@ <h2>Coverage per chromosome</h2>
scrollX: true,
scrollCollapse: true,
scroller: true,
search: {
regex: true
},
columns: columnDefs,
columnDefs: [{
targets: thresholdIdx,
Expand All @@ -680,7 +724,7 @@ <h2>Coverage per chromosome</h2>
}],
dom: 'Bfrtip',
buttons: [
'copyHtml5'
'copyHtml5', 'csvHtml5'
]
});
});
Expand All @@ -700,14 +744,17 @@ <h2>Coverage per chromosome</h2>
scroller: {
loadingIndicator: true
},
search: {
regex: true
},
'processing': true,
'language': {
'loadingRecords': '&nbsp;',
'processing': 'Loading...'
},
dom: 'Bfrtip',
buttons: [
'copyHtml5'
'copyHtml5', 'csvHtml5'
]
} );
} );
Expand All @@ -728,14 +775,17 @@ <h2>Coverage per chromosome</h2>
scroller: {
loadingIndicator: true
},
search: {
regex: true
},
'processing': true,
'language': {
'loadingRecords': '&nbsp;',
'processing': 'Loading...'
},
dom: 'Bfrtip',
buttons: [
'copyHtml5'
'copyHtml5', 'csvHtml5'
]
} );
} );
Expand Down Expand Up @@ -764,14 +814,17 @@ <h2>Coverage per chromosome</h2>
scroller: {
loadingIndicator: true
},
search: {
regex: true
},
'processing': true,
'language': {
'loadingRecords': '&nbsp;',
'processing': 'Loading...'
},
dom: 'Bfrtip',
buttons: [
'copyHtml5'
'copyHtml5', 'csvHtml5'
]
} );
} );
Expand Down Expand Up @@ -800,14 +853,17 @@ <h2>Coverage per chromosome</h2>
scroller: {
loadingIndicator: true
},
search: {
regex: true
},
'processing': true,
'language': {
'loadingRecords': '&nbsp;',
'processing': 'Loading...'
},
dom: 'Bfrtip',
buttons: [
'copyHtml5'
'copyHtml5', 'csvHtml5'
]
} );
} );
Expand Down Expand Up @@ -835,14 +891,17 @@ <h2>Coverage per chromosome</h2>
scroller: {
loadingIndicator: true
},
search: {
regex: true
},
'processing': true,
'language': {
'loadingRecords': '&nbsp;',
'processing': 'Loading...'
},
dom: 'Bfrtip',
buttons: [
'copyHtml5'
'copyHtml5', 'csvHtml5'
]
} );
} );
Expand Down

0 comments on commit a6371df

Please sign in to comment.