Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if config.make_data_dir == False:
logger.info("Data : None")
else:
# Make directories for data_dir
logger.info("Data : {}".format(os.path.relpath(config.data_dir)))
if not os.path.exists(config.data_dir):
os.makedirs(config.data_dir)
# Modules have run, so data directory should be complete by now. Move its contents.
for f in os.listdir(config.data_tmp_dir):
fn = os.path.join(config.data_tmp_dir, f)
logger.debug("Moving data file from '{}' to '{}'".format(fn, config.data_dir))
shutil.move(fn, config.data_dir)
# Copy across the static plot images if requested
if config.export_plots:
config.plots_dir = os.path.join(config.output_dir, config.plots_dir_name)
if os.path.exists(config.plots_dir):
if config.force:
logger.warning("Deleting : {} (-f was specified)".format(os.path.relpath(config.plots_dir)))
shutil.rmtree(config.plots_dir)
else:
logger.error("Output directory {} already exists.".format(config.plots_dir))
logger.info("Use -f or --force to overwrite existing reports")
shutil.rmtree(tmp_dir)
sys.exit(1)
os.makedirs(config.plots_dir)
logger.info("Plots : {}".format(os.path.relpath(config.plots_dir)))
# Modules have run, so plots directory should be complete by now. Move its contents.
for f in os.listdir(config.plots_tmp_dir):
fn = os.path.join(config.plots_tmp_dir, f)
logger.debug("Moving plots directory from '{}' to '{}'".format(fn, config.plots_dir))
shutil.move(fn, config.data_dir)
# Copy across the static plot images if requested
if config.export_plots:
config.plots_dir = os.path.join(config.output_dir, config.plots_dir_name)
if os.path.exists(config.plots_dir):
if config.force:
logger.warning("Deleting : {} (-f was specified)".format(os.path.relpath(config.plots_dir)))
shutil.rmtree(config.plots_dir)
else:
logger.error("Output directory {} already exists.".format(config.plots_dir))
logger.info("Use -f or --force to overwrite existing reports")
shutil.rmtree(tmp_dir)
sys.exit(1)
os.makedirs(config.plots_dir)
logger.info("Plots : {}".format(os.path.relpath(config.plots_dir)))
# Modules have run, so plots directory should be complete by now. Move its contents.
for f in os.listdir(config.plots_tmp_dir):
fn = os.path.join(config.plots_tmp_dir, f)
logger.debug("Moving plots directory from '{}' to '{}'".format(fn, config.plots_dir))
shutil.move(fn, config.plots_dir)
plugin_hooks.mqc_trigger('before_template')
# Load in parent template files first if a child theme
try:
parent_template = config.avail_templates[template_mod.template_parent].load()
copy_tree(parent_template.template_dir, tmp_dir)
except AttributeError:
pass # Not a child theme
logger.info("Data : None")
else:
# Make directories for data_dir
logger.info("Data : {}".format(os.path.relpath(config.data_dir)))
if not os.path.exists(config.data_dir):
os.makedirs(config.data_dir)
# Modules have run, so data directory should be complete by now. Move its contents.
for f in os.listdir(config.data_tmp_dir):
fn = os.path.join(config.data_tmp_dir, f)
logger.debug("Moving data file from '{}' to '{}'".format(fn, config.data_dir))
shutil.move(fn, config.data_dir)
# Copy across the static plot images if requested
if config.export_plots:
config.plots_dir = os.path.join(config.output_dir, config.plots_dir_name)
if os.path.exists(config.plots_dir):
if config.force:
logger.warning("Deleting : {} (-f was specified)".format(os.path.relpath(config.plots_dir)))
shutil.rmtree(config.plots_dir)
else:
logger.error("Output directory {} already exists.".format(config.plots_dir))
logger.info("Use -f or --force to overwrite existing reports")
shutil.rmtree(tmp_dir)
sys.exit(1)
os.makedirs(config.plots_dir)
logger.info("Plots : {}".format(os.path.relpath(config.plots_dir)))
# Modules have run, so plots directory should be complete by now. Move its contents.
for f in os.listdir(config.plots_tmp_dir):
fn = os.path.join(config.plots_tmp_dir, f)
logger.debug("Moving plots directory from '{}' to '{}'".format(fn, config.plots_dir))
shutil.move(fn, config.plots_dir)
os.makedirs(config.data_dir)
# Modules have run, so data directory should be complete by now. Move its contents.
for f in os.listdir(config.data_tmp_dir):
fn = os.path.join(config.data_tmp_dir, f)
logger.debug("Moving data file from '{}' to '{}'".format(fn, config.data_dir))
shutil.move(fn, config.data_dir)
# Copy across the static plot images if requested
if config.export_plots:
config.plots_dir = os.path.join(config.output_dir, config.plots_dir_name)
if os.path.exists(config.plots_dir):
if config.force:
logger.warning("Deleting : {} (-f was specified)".format(os.path.relpath(config.plots_dir)))
shutil.rmtree(config.plots_dir)
else:
logger.error("Output directory {} already exists.".format(config.plots_dir))
logger.info("Use -f or --force to overwrite existing reports")
shutil.rmtree(tmp_dir)
sys.exit(1)
os.makedirs(config.plots_dir)
logger.info("Plots : {}".format(os.path.relpath(config.plots_dir)))
# Modules have run, so plots directory should be complete by now. Move its contents.
for f in os.listdir(config.plots_tmp_dir):
fn = os.path.join(config.plots_tmp_dir, f)
logger.debug("Moving plots directory from '{}' to '{}'".format(fn, config.plots_dir))
shutil.move(fn, config.plots_dir)
plugin_hooks.mqc_trigger('before_template')
# Load in parent template files first if a child theme
try:
logger.debug("Moving data file from '{}' to '{}'".format(fn, config.data_dir))
shutil.move(fn, config.data_dir)
# Copy across the static plot images if requested
if config.export_plots:
config.plots_dir = os.path.join(config.output_dir, config.plots_dir_name)
if os.path.exists(config.plots_dir):
if config.force:
logger.warning("Deleting : {} (-f was specified)".format(os.path.relpath(config.plots_dir)))
shutil.rmtree(config.plots_dir)
else:
logger.error("Output directory {} already exists.".format(config.plots_dir))
logger.info("Use -f or --force to overwrite existing reports")
shutil.rmtree(tmp_dir)
sys.exit(1)
os.makedirs(config.plots_dir)
logger.info("Plots : {}".format(os.path.relpath(config.plots_dir)))
# Modules have run, so plots directory should be complete by now. Move its contents.
for f in os.listdir(config.plots_tmp_dir):
fn = os.path.join(config.plots_tmp_dir, f)
logger.debug("Moving plots directory from '{}' to '{}'".format(fn, config.plots_dir))
shutil.move(fn, config.plots_dir)
plugin_hooks.mqc_trigger('before_template')
# Load in parent template files first if a child theme
try:
parent_template = config.avail_templates[template_mod.template_parent].load()
copy_tree(parent_template.template_dir, tmp_dir)
except AttributeError:
pass # Not a child theme
logger.info("Data : {}".format(os.path.relpath(config.data_dir)))
if not os.path.exists(config.data_dir):
os.makedirs(config.data_dir)
# Modules have run, so data directory should be complete by now. Move its contents.
for f in os.listdir(config.data_tmp_dir):
fn = os.path.join(config.data_tmp_dir, f)
logger.debug("Moving data file from '{}' to '{}'".format(fn, config.data_dir))
shutil.move(fn, config.data_dir)
# Copy across the static plot images if requested
if config.export_plots:
config.plots_dir = os.path.join(config.output_dir, config.plots_dir_name)
if os.path.exists(config.plots_dir):
if config.force:
logger.warning("Deleting : {} (-f was specified)".format(os.path.relpath(config.plots_dir)))
shutil.rmtree(config.plots_dir)
else:
logger.error("Output directory {} already exists.".format(config.plots_dir))
logger.info("Use -f or --force to overwrite existing reports")
shutil.rmtree(tmp_dir)
sys.exit(1)
os.makedirs(config.plots_dir)
logger.info("Plots : {}".format(os.path.relpath(config.plots_dir)))
# Modules have run, so plots directory should be complete by now. Move its contents.
for f in os.listdir(config.plots_tmp_dir):
fn = os.path.join(config.plots_tmp_dir, f)
logger.debug("Moving plots directory from '{}' to '{}'".format(fn, config.plots_dir))
shutil.move(fn, config.plots_dir)
plugin_hooks.mqc_trigger('before_template')
if config.force:
logger.warning("Deleting : {} (-f was specified)".format(os.path.relpath(config.plots_dir)))
shutil.rmtree(config.plots_dir)
else:
logger.error("Output directory {} already exists.".format(config.plots_dir))
logger.info("Use -f or --force to overwrite existing reports")
shutil.rmtree(tmp_dir)
sys.exit(1)
os.makedirs(config.plots_dir)
logger.info("Plots : {}".format(os.path.relpath(config.plots_dir)))
# Modules have run, so plots directory should be complete by now. Move its contents.
for f in os.listdir(config.plots_tmp_dir):
fn = os.path.join(config.plots_tmp_dir, f)
logger.debug("Moving plots directory from '{}' to '{}'".format(fn, config.plots_dir))
shutil.move(fn, config.plots_dir)
plugin_hooks.mqc_trigger('before_template')
# Load in parent template files first if a child theme
try:
parent_template = config.avail_templates[template_mod.template_parent].load()
copy_tree(parent_template.template_dir, tmp_dir)
except AttributeError:
pass # Not a child theme
# Copy the template files to the tmp directory (distutils overwrites parent theme files)
copy_tree(template_mod.template_dir, tmp_dir)
# Function to include file contents in Jinja template
def include_file(name, fdir=tmp_dir, b64=False):
try:
run_module_names = [ list(m.keys())[0] for m in run_modules ]
logger.debug("Analysing modules: {}".format(', '.join(run_module_names)))
# Create the temporary working directories
tmp_dir = tempfile.mkdtemp()
logger.debug('Using temporary directory for creating report: {}'.format(tmp_dir))
config.data_tmp_dir = os.path.join(tmp_dir, 'multiqc_data')
if filename != 'stdout' and config.make_data_dir == True:
config.data_dir = config.data_tmp_dir
os.makedirs(config.data_dir)
else:
config.data_dir = None
config.plots_tmp_dir = os.path.join(tmp_dir, 'multiqc_plots')
if filename != 'stdout' and config.export_plots == True:
config.plots_dir = config.plots_tmp_dir
os.makedirs(config.plots_dir)
# Load the template
template_mod = config.avail_templates[config.template].load()
# Add an output subdirectory if specified by template
try:
config.output_dir = os.path.join(config.output_dir, template_mod.output_subdir)
except AttributeError:
pass # No subdirectory variable given
# Add custom content section names
try:
if 'custom_content' in run_module_names:
run_module_names.extend(config.custom_data.keys())
except AttributeError:
if len(pdata) <= 15:
axes.legend(loc='lower center', bbox_to_anchor=(0, -0.22, 1, .102), ncol=5, mode='expand', fontsize=8, frameon=False)
plt.tight_layout(rect=[0,0.08,1,0.92])
else:
plt.tight_layout(rect=[0,0,1,0.92])
# Should this plot be hidden on report load?
hidediv = ''
if pidx > 0:
hidediv = ' style="display:none;"'
# Save the plot to the data directory if export is requests
if config.export_plots:
for fformat in config.export_plot_formats:
# Make the directory if it doesn't already exist
plot_dir = os.path.join(config.plots_dir, fformat)
if not os.path.exists(plot_dir):
os.makedirs(plot_dir)
# Save the plot
plot_fn = os.path.join(plot_dir, '{}.{}'.format(pid, fformat))
fig.savefig(plot_fn, format=fformat, bbox_inches='tight')
# Output the figure to a base64 encoded string
if getattr(get_template_mod(), 'base64_plots', True) is True:
img_buffer = io.BytesIO()
fig.savefig(img_buffer, format='png', bbox_inches='tight')
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:
template_parent = 'default'
base64_plots = False
template_dir = os.path.dirname(__file__)
base_fn = 'base.html'
output_subdir = 'multiqc_report'
copy_files = ['assets']
# This has already been done in the main script, do now if it was false
if not config.export_plots:
tmp_dir = config.data_tmp_dir.rstrip('multiqc_data')
config.plots_tmp_dir = os.path.join(tmp_dir, 'multiqc_plots')
config.plots_dir = config.plots_tmp_dir
if not os.path.exists(config.plots_dir):
os.makedirs(config.plots_dir)
config.export_plots = True