Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D3-Enhancements #78

Merged
merged 25 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0226548
Sam/try plots (#71)
Snicker7 May 6, 2024
3513a6c
Sam/fix plots (#72)
Snicker7 May 6, 2024
d880942
Remove token from integration tests file
Colelyman May 7, 2024
82eaf94
Provide sgRNA_sequences to plot_nucleotide_quilt plots
Colelyman Apr 10, 2024
12c529f
Passing sgRNA_sequences to plot
trevormartinj7 May 7, 2024
ed60122
Refactor check for determining when to use CRISPREssoPro or matplotli…
Colelyman May 7, 2024
118b683
Add max-height to Batch report samples
Colelyman May 7, 2024
88a09a3
Change testing branch
Colelyman May 7, 2024
a26f96d
Fix wrong check for large Batch plots
Colelyman May 7, 2024
d33615f
Fix typo and move flexiguide to debug (#77)
Colelyman May 24, 2024
5f19ca5
Adding id tags for d3 script enhancements
trevormartinj7 May 28, 2024
a32dd43
Merging master
trevormartinj7 May 29, 2024
0fb36f9
pointing to test branch
trevormartinj7 May 29, 2024
127b7fd
Add amplicon_name parameter to allele heatmap and line plots
Colelyman May 31, 2024
3daf542
Add function to extract quantification window regions from include_idxs
Colelyman May 31, 2024
fc175a7
Scale the quantification window according to the coordinates of the s…
Colelyman May 31, 2024
0f9fdb5
added c2pro check, added space in args.json
trevormartinj7 May 31, 2024
00fcb6d
Correct the quantification window indexes for multiple guides
Colelyman Jun 4, 2024
2ebd552
Fix name of nucleotide conversion plot when guides are not the same
Colelyman Jun 6, 2024
d04c964
Fix jinja variables that aren't found
Colelyman Jun 6, 2024
693b4ee
Fix multiple guide errors where the wrong sgRNA sequence was associat…
Colelyman Jun 7, 2024
f982488
Remove unneeded variable and extra whitespace
Colelyman Jun 7, 2024
8a0cf93
Merge branch 'master' into d3-enhancements
Colelyman Jun 7, 2024
1470f39
Merge branch 'master' into d3-enhancements
Colelyman Jul 22, 2024
6b7f981
Switch test branch to master
Colelyman Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions CRISPResso2/CRISPRessoBatchCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,8 @@ def main():
if not args.suppress_plots and not args.suppress_batch_summary_plots and should_plot_large_plots(sub_nucleotide_percentage_summary_df.shape[0], C2PRO_INSTALLED, args.use_matplotlib):
# plot for each guide
# show all sgRNA's on the plot
sub_sgRNA_intervals = []
for sgRNA_interval in consensus_sgRNA_intervals:
sub_sgRNA_intervals, sub_consensus_guides = [], []
for sgRNA_index, sgRNA_interval in enumerate(consensus_sgRNA_intervals):
newstart = None
newend = None
for idx, i in enumerate(sgRNA_plot_idxs):
Expand All @@ -633,6 +633,10 @@ def main():
newend = len(include_idxs) - 1
# and add it to the list
sub_sgRNA_intervals.append((newstart, newend))
sub_consensus_guides.append(consensus_guides[sgRNA_index])

# scale the include_idxs to be in terms of the plot centered around the sgRNA
sub_include_idxs = include_idxs - sgRNA_plot_idxs[0]

this_window_nuc_pct_quilt_plot_name = _jp(amplicon_plot_name.replace('.', '') + 'Nucleotide_percentage_quilt_around_sgRNA_'+sgRNA)
nucleotide_quilt_input = {
Expand All @@ -641,8 +645,8 @@ def main():
'fig_filename_root': f'{this_window_nuc_pct_quilt_plot_name}.json' if not args.use_matplotlib and C2PRO_INSTALLED else this_window_nuc_pct_quilt_plot_name,
'save_also_png': save_png,
'sgRNA_intervals': sub_sgRNA_intervals,
'sgRNA_sequences': consensus_guides,
'quantification_window_idxs': include_idxs,
'sgRNA_sequences': sub_consensus_guides,
'quantification_window_idxs': sub_include_idxs,
'custom_colors': custom_config['colors'],
}
debug('Plotting nucleotide percentage quilt for amplicon {0}, sgRNA {1}'.format(amplicon_name, sgRNA))
Expand All @@ -665,7 +669,7 @@ def main():
'conversion_nuc_to': args.conversion_nuc_to,
'save_also_png': save_png,
'sgRNA_intervals': sub_sgRNA_intervals,
'quantification_window_idxs': include_idxs,
'quantification_window_idxs': sub_include_idxs,
'custom_colors': custom_config['colors']
}
debug('Plotting nucleotide conversion map for amplicon {0}, sgRNA {1}'.format(amplicon_name, sgRNA))
Expand Down Expand Up @@ -754,7 +758,7 @@ def main():
crispresso2_info['results']['general_plots']['summary_plot_labels'][plot_name] = 'Composition of each base for the amplicon ' + amplicon_name
crispresso2_info['results']['general_plots']['summary_plot_datas'][plot_name] = [('Nucleotide frequencies', os.path.basename(nucleotide_frequency_summary_filename)), ('Modification frequencies', os.path.basename(modification_frequency_summary_filename))]
if args.base_editor_output and should_plot_large_plots(nucleotide_percentage_summary_df.shape[0], False, args.use_matplotlib):
this_nuc_conv_plot_name = _jp(amplicon_plot_name + 'Nucleotide_percentage_quilt')
this_nuc_conv_plot_name = _jp(amplicon_plot_name + 'Nucleotide_conversion_map')
conversion_map_input = {
'nuc_pct_df': nucleotide_percentage_summary_df,
'fig_filename_root': this_nuc_conv_plot_name,
Expand Down Expand Up @@ -807,6 +811,7 @@ def main():
'plot_path': plot_path,
'title': modification_type,
'div_id': heatmap_div_id,
'amplicon_name': amplicon_name,
}
debug('Plotting allele modification heatmap for {0}'.format(amplicon_name))
plot(
Expand Down Expand Up @@ -841,6 +846,7 @@ def main():
'plot_path': plot_path,
'title': modification_type,
'div_id': line_div_id,
'amplicon_name': amplicon_name,
}
debug('Plotting allele modification line plot for {0}'.format(amplicon_name))
plot(
Expand Down
12 changes: 6 additions & 6 deletions CRISPResso2/CRISPRessoReports/templates/batchReport.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ <h5 id="CRISPResso2_Batch_Output">{{report_name}}</h5>
{% if window_nuc_pct_quilts|length > 0 %}
<div class='card text-center mb-2'>
<div class='card-header'>
<h5>Nucleotide percentages around guides</h5>
<h5 id="nucleotide-header">Nucleotide percentages around guides</h5>
</div>
<div class='card-body'>
{% for plot_name in window_nuc_pct_quilts %}
Expand All @@ -86,11 +86,11 @@ <h5>{{report_data['titles'][plot_name]}}</h5>
{% if nuc_pct_quilts|length > 0 %}
<div class='card text-center mb-2'>
<div class='card-header'>
<h5>Nucleotide percentages in the entire amplicon</h5>
<h5 id="nucleotide-header-full-amplicon">Nucleotide percentages in the entire amplicon</h5>
</div>
<div class='card-body'>
{% for plot_name in nuc_pct_quilts %}
<h5>{{report_data['titles'][plot_name]}}</h5>
<h5>{{report_data['titles'][plot_name] if plot_name in report_data['titles'] else ''}}</h5>
{{ render_partial('shared/partials/fig_summaries.html', report_data=report_data, plot_name=plot_name) }}
{% endfor %}
</div>
Expand All @@ -104,7 +104,7 @@ <h5>Conversion of target bases around guides</h5>
</div>
<div class='card-body'>
{% for plot_name in window_nuc_conv_plots %}
<h5>{{report_data['titles'][plot_name]}}</h5>
<h5>{{report_data['titles'][plot_name] if plot_name in report_data['titles'] else ''}}</h5>
{{ render_partial('shared/partials/fig_summaries.html', report_data=report_data, plot_name=plot_name) }}
{% endfor %}
</div>
Expand All @@ -118,7 +118,7 @@ <h5>Conversion of target bases in the entire amplicon</h5>
</div>
<div class='card-body'>
{% for plot_name in nuc_conv_plots %}
<h5>{{report_data['titles'][plot_name]}}</h5>
<h5>{{report_data['titles'][plot_name] if plot_name in report_data['titles'] else ''}}</h5>
{{ render_partial('shared/partials/fig_summaries.html', report_data=report_data, plot_name=plot_name) }}
{% endfor %}
</div>
Expand All @@ -129,7 +129,7 @@ <h5>{{report_data['titles'][plot_name]}}</h5>
{% for plot_name in report_data['names'] %}
<div class='card text-center mb-2'>
<div class='card-header'>
<h5>{{report_data['titles'][plot_name]}}</h5>
<h5>{{report_data['titles'][plot_name] if plot_name in report_data['titles'] else ''}}</h5>
</div>
<div class='card-body'>
{{ render_partial('shared/partials/fig_summaries.html', report_data=report_data, plot_name=plot_name) }}
Expand Down
8 changes: 5 additions & 3 deletions CRISPResso2/CRISPRessoReports/templates/report.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ <h5>Nucleotide composition for {{amplicon_name}}</h5>
{% for (data_label,data_path) in report_data['figures']['datas'][amplicon_name]['plot_2a'] %}
<p class="m-0"><small>Data: <a href="{{report_data['crispresso_data_path']}}{{data_path}}">{{data_label}}</a></small></p>
{% endfor %}

{% if 'plot_2b' in report_data['figures']['htmls'][amplicon_name] %}
{{ report_data['figures']['htmls'][amplicon_name]['plot_2b']|safe }}
{% elif report_data['figures']['sgRNA_based_names'][amplicon_name] and report_data['figures']['sgRNA_based_names'][amplicon_name]['2b']%}
Expand Down Expand Up @@ -623,9 +623,11 @@ <h5>Base editing for {{amplicon_name}}</h5>

{% block foot %}
<script>
{% if not C2PRO_INSTALLED %}
function updateZoom(e) {
/*prevent any other actions that may occur when moving over the image:*/
// e.preventDefault();

var img = e.target.imgObj
var view = e.target.viewObj
var lens = e.target.lensObj
Expand Down Expand Up @@ -718,8 +720,8 @@ <h5>Base editing for {{amplicon_name}}</h5>

{% endif %}
{% endfor %}
</script>

{% endif %}
</script>

{% if C2PRO_INSTALLED %}
<script src="https://unpkg.com/d3@5"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="fig_summary_{{plot_name}}">
{% if report_data['htmls'] and report_data['htmls'][plot_name]%}
{% if report_data['htmls'] and plot_name in report_data['htmls']%}
{{report_data['htmls'][plot_name]|safe}}
{% else %}
{% if plot_name in ['Nucleotide_conversion_map', 'Nucleotide_percentage_quilt'] %}
Expand Down
32 changes: 32 additions & 0 deletions CRISPResso2/CRISPRessoShared.py
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,38 @@ def get_sgRNA_mismatch_vals(seq1, seq2, start_loc, end_loc, coords_l, coords_r,
return list(set(this_mismatches))


def get_quant_window_ranges_from_include_idxs(include_idxs):
"""Given a list of indexes, return the ranges that those indexes include.

Parameters
----------
include_idxs: list
A list of indexes included in the quantification window, for example
`[20, 21, 22, 35, 36, 37]`.

Returns
-------
list
A list of tuples representing the ranges included in the quantification
window, for example `[(20, 22), (35, 37)]`. If there is a single index, it
will be reported as `[(20, 20)]`.
"""
quant_ranges = []
if include_idxs is None or len(include_idxs) == 0:
return quant_ranges
start_idx = include_idxs[0]
last_idx = include_idxs[0]
for idx in include_idxs[1:]:
if idx == last_idx + 1:
last_idx = idx
else:
quant_ranges.append((start_idx, last_idx))
start_idx = idx
last_idx = idx
quant_ranges.append((start_idx, last_idx))
return quant_ranges


######
# terminal functions
######
Expand Down
2 changes: 1 addition & 1 deletion CRISPResso2/args.json
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@
"skip_failed": {
"keys": ["--skip_failed"],
"help": "Continue with batch analysis even if one sample fails",
"action":"store_true",
"action": "store_true",
"tools": ["Batch", "Pooled", "WGS"]
},
"min_reads_for_inclusion": {
Expand Down
26 changes: 25 additions & 1 deletion tests/unit_tests/test_CRISPRessoShared.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_get_mismatches():
-5,
-3,
)
assert len(mismatch_cords) == 6
assert len(mismatch_cords) == 6

def test_get_relative_coordinates():
s1inds_gap_left, s1inds_gap_right = CRISPRessoShared.get_relative_coordinates('ATCGT', 'TTCGT')
Expand Down Expand Up @@ -74,3 +74,27 @@ def test_get_relative_coordinates_ind_and_dels():
assert s1inds_gap_left == [0, 2, 2, 2, 3]
assert s1inds_gap_right == [0, 2, 3, 3, 3]


def test_get_quant_window_ranges_from_include_idxs():
include_idxs = [0, 1, 2, 10, 11, 12]
assert CRISPRessoShared.get_quant_window_ranges_from_include_idxs(include_idxs) == [(0, 2), (10, 12)]


def test_get_quant_window_ranges_from_include_idxs_empty():
include_idxs = []
assert CRISPRessoShared.get_quant_window_ranges_from_include_idxs(include_idxs) == []


def test_get_quant_window_ranges_from_include_idxs_single():
include_idxs = [50, 51, 52, 53]
assert CRISPRessoShared.get_quant_window_ranges_from_include_idxs(include_idxs) == [(50, 53)]


def test_get_quant_window_ranges_from_include_idxs_single_gap():
include_idxs = [50, 51, 52, 53, 55]
assert CRISPRessoShared.get_quant_window_ranges_from_include_idxs(include_idxs) == [(50, 53), (55, 55)]


def test_get_quant_window_ranges_from_include_idxs_multiple_gaps():
include_idxs = [50, 51, 52, 53, 55, 56, 57, 58, 60]
assert CRISPRessoShared.get_quant_window_ranges_from_include_idxs(include_idxs) == [(50, 53), (55, 58), (60, 60)]
Loading