Skip to content

Commit

Permalink
remove guardrails and make reports changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Snicker7 committed Apr 3, 2024
1 parent bed6207 commit 0392855
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 33 deletions.
37 changes: 19 additions & 18 deletions CRISPResso2/CRISPRessoReports/CRISPRessoReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@
from jinja_partials import generate_render_partial, render_partial
from CRISPResso2 import CRISPRessoShared

try:
from CRISPRessoPro import __version__
pro_installed = True
except:
pro_installed = False
if CRISPRessoShared.is_C2Pro_installed():
from CRISPRessoPro import __version__ as CRISPRessoProVersion
C2PRO_INSTALLED = True
else:
C2PRO_INSTALLED = False


def get_jinja_loader(_ROOT):
if CRISPRessoShared.is_C2Pro_installed():
return Environment(loader=ChoiceLoader([FileSystemLoader(os.path.join(_ROOT, 'CRISPRessoReports', 'templates')), PackageLoader('CRISPRessoPro', 'templates')]))
else:
return Environment(loader=FileSystemLoader(os.path.join(_ROOT, 'CRISPRessoReports', 'templates')))


def render_template(template_name, jinja2_env, **data):
Expand Down Expand Up @@ -42,7 +49,7 @@ def custom_partial_render(partial_template_name, **partial_data):
),
is_default_user=False,
is_web=False,
pro_installed=pro_installed,
C2PRO_INSTALLED=C2PRO_INSTALLED,
)
return template.render(**partial_data)
return render_partial(
Expand All @@ -67,7 +74,7 @@ def make_report_from_folder(crispresso_report_file, crispresso_folder, _ROOT):


def add_fig_if_exists(fig, fig_name, fig_root, fig_title, fig_caption, fig_data,
amplicon_fig_names, amplicon_figures, crispresso_folder, d3_nuc_quilt_names=[]):
amplicon_fig_names, amplicon_figures, crispresso_folder, d3_nuc_quilt_names):
"""
Helper function to add figure if the file exists
if fig at filename exists,
Expand All @@ -94,7 +101,7 @@ def add_fig_if_exists(fig, fig_name, fig_root, fig_title, fig_caption, fig_data,
html_string += html.read()
html_string += "</div>"
amplicon_figures['htmls'][fig_name] = html_string
elif os.path.exists(jsonfullpath) and pro_installed:
elif os.path.exists(jsonfullpath) and C2PRO_INSTALLED:
root_name = fig_root.replace('.', '_').replace('-', '_')
d3_nuc_quilt_names.append(f"nuc_quilt_{root_name}")
with open(jsonfullpath) as fig_json_fh:
Expand Down Expand Up @@ -186,18 +193,15 @@ def make_report(run_data, crispresso_report_file, crispresso_folder, _ROOT):
'nuc_quilt_names': data['nuc_quilt_names'],
}

j2_env = Environment(
loader=ChoiceLoader([FileSystemLoader(os.path.join(_ROOT, 'CRISPRessoReports', 'templates')), PackageLoader('CRISPRessoPro', 'templates')]) if pro_installed
else FileSystemLoader(os.path.join(_ROOT, 'CRISPRessoReports', 'templates'))
)
j2_env = get_jinja_loader(_ROOT)

# dest_dir = os.path.dirname(crispresso_report_file)
# shutil.copy2(os.path.join(_ROOT,'templates','CRISPResso_justcup.png'),dest_dir)
# shutil.copy2(os.path.join(_ROOT,'templates','favicon.ico'),dest_dir)

with open(crispresso_report_file, 'w', encoding="utf-8") as outfile:
outfile.write(render_template(
'report.html', j2_env, report_data=report_data, pro_installed=pro_installed,
'report.html', j2_env, report_data=report_data, C2PRO_INSTALLED=C2PRO_INSTALLED,
))


Expand Down Expand Up @@ -521,10 +525,7 @@ def fill_default(dictionary, key, default_type=list):
if key not in dictionary:
dictionary[key] = default_type()

j2_env = Environment(
loader=ChoiceLoader([FileSystemLoader(os.path.join(_ROOT, 'CRISPRessoReports', 'templates')), PackageLoader('CRISPRessoPro', 'templates')]) if pro_installed
else FileSystemLoader(os.path.join(_ROOT, 'CRISPRessoReports', 'templates'))
)
j2_env = get_jinja_loader(_ROOT)

j2_env.filters['dirname'] = dirname
if crispresso_tool == 'batch':
Expand Down Expand Up @@ -609,7 +610,7 @@ def fill_default(dictionary, key, default_type=list):
allele_modification_line_plot_titles=allele_modification_line_plot['titles'],
allele_modification_line_plot_labels=allele_modification_line_plot['labels'],
allele_modification_line_plot_datas=allele_modification_line_plot['datas'],
pro_installed=pro_installed,
C2PRO_INSTALLED=C2PRO_INSTALLED,
))


Expand Down
2 changes: 1 addition & 1 deletion CRISPResso2/CRISPRessoReports/templates/batchReport.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ <h5>{{allele_modification_heatmap_plot_titles[heatmap_plot_name]}}</h5>
{% endblock %}

{% block foot %}
{% if pro_installed %}
{% if C2PRO_INSTALLED %}
<script src="https://unpkg.com/d3@5"></script>
{{ render_partial('partials/batch_d3.html', nucleotide_quilt_slugs=(window_nuc_pct_quilts + nuc_pct_quilts))}}
{% endif %}
Expand Down
7 changes: 3 additions & 4 deletions CRISPResso2/CRISPRessoReports/templates/pooledReport.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
}
</style>

{% if is_pro %}
<script src="https://cdn.plot.ly/plotly-2.11.1.min.js"></script>
{% endif %}

{% endblock %}

{% block content %}
Expand Down Expand Up @@ -101,4 +97,7 @@ <h5 id="modification_summary_title">{{report_data['titles'][plot_name]}}</h5>
{% endblock %}

{% block foot %}
{% if C2PRO_INSTALLED %}
<script src="https://cdn.plot.ly/plotly-2.11.1.min.js"></script>
{% endif %}
{% endblock %}
7 changes: 2 additions & 5 deletions CRISPResso2/CRISPRessoReports/templates/report.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@
}
</style>

{% if pro_installed %}
<script src="https://cdn.plot.ly/plotly-2.11.1.min.js"></script>
{% endif %}

{% endblock %}

{% block content %}
Expand Down Expand Up @@ -726,8 +722,9 @@ <h5>Base editing for {{amplicon_name}}</h5>
</script>


{% if pro_installed %}
{% if C2PRO_INSTALLED %}
<script src="https://unpkg.com/d3@5"></script>
<script src="https://cdn.plot.ly/plotly-2.11.1.min.js"></script>
{{ render_partial('partials/batch_d3.html', nucleotide_quilt_slugs=(report_data['nuc_quilt_names'])) }}
{% endif %}

Expand Down

This file was deleted.

0 comments on commit 0392855

Please sign in to comment.