Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_quality_control():
report.files = {"sequana/quality_control":
[ { 'fn': sequana_data('summary_qc.json'), 'root': '.'}]
}
quality_control.MultiqcModule()
logwarn = "Depreciation Warning: {} - Please use new style for find_log_files()".format(self.name)
if len(report.files[self.name]) > 0:
logger.warn(logwarn)
else:
logger.debug(logwarn)
elif not isinstance(sp_key, str):
logger.warn("Did not understand find_log_files() search key")
return
for f in report.files[sp_key]:
# Make a note of the filename so that we can report it if something crashes
report.last_found_file = os.path.join(f['root'], f['fn'])
# Filter out files based on exclusion patterns
if path_filters_exclude and len(path_filters_exclude) > 0:
exlusion_hits = (fnmatch.fnmatch(report.last_found_file, pfe) for pfe in path_filters_exclude)
if any(exlusion_hits):
logger.debug("{} - Skipping '{}' as it matched the path_filters_exclude for '{}'".format(sp_key, f['fn'], self.name))
continue
# Filter out files based on inclusion patterns
if path_filters and len(path_filters) > 0:
inclusion_hits = (fnmatch.fnmatch(report.last_found_file, pf) for pf in path_filters)
if not any(inclusion_hits):
logger.debug("{} - Skipping '{}' as it didn't match the path_filters for '{}'".format(sp_key, f['fn'], self.name))
continue
else:
logger.debug("{} - Selecting '{}' as it matched the path_filters for '{}'".format(sp_key, f['fn'], self.name))
# Make a sample name from the filename
f['s_name'] = self.clean_s_name(f['fn'], f['root'])
if filehandles or filecontents:
b64_img = base64.b64encode(img_buffer.getvalue()).decode('utf8')
img_buffer.close()
html += '<div id="{}" class="mqc_mplplot"><img src="data:image/png;base64,{}"></div>'.format(pid, hidediv, b64_img)
# Save to a file and link <img>
else:
plot_relpath = os.path.join(config.plots_dir_name, 'png', '{}.png'.format(pid))
html += '<div id="{}" class="mqc_mplplot"><img src="{}"></div>'.format(pid, hidediv, plot_relpath)
plt.close(fig)
# Close wrapping div
html += ''
report.num_mpl_plots += 1
return html
def matplotlib_linegraph (plotdata, pconfig=None):
"""
Plot a line graph with Matplot lib and return a HTML string. Either embeds a base64
encoded image within HTML or writes the plot and links to it. Should be called by
plot_bargraph, which properly formats the input data.
"""
if pconfig is None:
pconfig = {}
# Plot group ID
if pconfig.get('id') is None:
pconfig['id'] = 'mqc_mplplot_'+''.join(random.sample(letters, 10))
# Sanitise plot ID and check for duplicates
pconfig['id'] = report.save_htmlid(pconfig['id'])
# Individual plot IDs
pids = []
for k in range(len(plotdata)):
try:
name = pconfig['data_labels'][k]['name']
except:
name = k+1
pid = 'mqc_{}_{}'.format(pconfig['id'], name)
pid = report.save_htmlid(pid, skiplint=True)
pids.append(pid)
html = '<p class="text-info"><small><span aria-hidden="true" class="glyphicon glyphicon-picture"></span> ' + \
'Flat image plot. Toolbox functions such as highlighting / hiding samples will not work ' + \
'(see the <a href="http://multiqc.info/docs/#flat--interactive-plots">docs</a>).</small></p>'
html += '<div id="{}" class="mqc_mplplot_plotgroup">'.format(pconfig['id'])</div>
# The plot div
html += '<div class="hc-plot-wrapper"><div class="hc-plot not_rendered hc-heatmap" id="{id}"><small>loading..</small></div></div> \n'.format(id=pconfig['id'])
# Javascript with data dump
html += ''.format(id=pconfig['id'], d=json.dumps(pdata), x=json.dumps(xcats), y=json.dumps(ycats), c=json.dumps(pconfig));
report.num_hc_plots += 1
return html
def highcharts_linegraph (plotdata, pconfig=None):
"""
Build the HTML needed for a HighCharts line graph. Should be
called by linegraph.plot(), which properly formats input data.
"""
if pconfig is None:
pconfig = {}
# Get the plot ID
if pconfig.get('id') is None:
pconfig['id'] = 'mqc_hcplot_'+''.join(random.sample(letters, 10))
# Sanitise plot ID and check for duplicates
pconfig['id'] = report.save_htmlid(pconfig['id'])
# Build the HTML for the page
html = '<div class="mqc_hcplot_plotgroup">'
# Buttons to cycle through different datasets
if len(plotdata) > 1:
html += '<div class="btn-group hc_switch_group">\n'
for k, p in enumerate(plotdata):
active = 'active' if k == 0 else ''
try:
name = pconfig['data_labels'][k]['name']
except:
name = k+1
try:
ylab = 'data-ylab="{}"'.format(pconfig['data_labels'][k]['ylab'])
except:</div></div>
section_id_order[anchor] = section_id_order[ss['after']] + 1
if ss.get('before') in section_id_order.keys():
section_id_order[anchor] = section_id_order[ss['before']] - 1
# Remove module sections
section_id_order = { s:o for s,o in section_id_order.items() if o is not False }
# Sort the module sections
sorted_ids = sorted(section_id_order, key=section_id_order.get)
report.modules_output[midx].sections = [ s for i in sorted_ids for s in mod.sections if s['anchor'] == i ]
plugin_hooks.mqc_trigger('after_modules')
# Remove empty data sections from the General Stats table
empty_keys = [i for i, d in enumerate(report.general_stats_data[:]) if len(d) == 0]
empty_keys.sort(reverse=True)
for i in empty_keys:
del report.general_stats_data[i]
del report.general_stats_headers[i]
# Add general-stats IDs to table row headers
for idx, h in enumerate(report.general_stats_headers):
for k in h.keys():
if 'rid' not in h[k]:
h[k]['rid'] = re.sub(r'\W+', '_', k).strip().strip('_')
ns_html = re.sub(r'\W+', '_', h[k]['namespace']).strip().strip('_').lower()
report.general_stats_headers[idx][k]['rid'] = report.save_htmlid('mqc-generalstats-{}-{}'.format(ns_html, h[k]['rid']))
# Generate the General Statistics HTML & write to file
if len(report.general_stats_data) > 0:
pconfig = {
'id': 'general_stats_table',
'table_title': 'General Statistics',
'save_file': True,
'raw_data_fn':'multiqc_general_stats'
}