Skip to content

Commit

Permalink
Resize plotly (#75)
Browse files Browse the repository at this point in the history
* Sam/try plots (#71)

* Fix batch mode pandas warning. (#70)

* refactor to call method on DataFrame, rather than Series.
Removes warning.

* Fix pandas future warning in CRISPRessoWGS

---------

Co-authored-by: Cole Lyman <[email protected]>

* Functional

* Cole/fix status file name (#69)

* Update config file logging messages

This removes printing the exception (which is essentially a duplicate),
and adds a condition if no config file was provided. Also changes `json`
to `config` so that it is more clear.

* Fix divide by zero when no amplicons are present in Batch mode

* Don't append file_prefix to status file name

* Place status files in output directories

* Update tests branch for file_prefix addition

* Load D3 and plotly figures with pro with multiple amplicons

* Update batch

* Fix bug in CRISPRessoCompare with pointing to report datas with file_prefix

Before this fix, when using a file_prefix the second run that was compared
would not be displayed as a data in the first figure of the report.

* Import CRISPRessoPro instead of importing the version

When installed via conda, the version is not available

* Remove `get_amplicon_output` unused function from CRISPRessoCompare

Also remove unused argparse import

* Implement `get_matching_allele_files` in CRISPRessoCompare and accompanying unit tests

* Allow for matching of multiple guides in the same amplicon

* Fix pandas FutureWarning

* Change test branch back to master

---------

Co-authored-by: Sam <[email protected]>

* Try catch all futures

* Fix test fail plots

* Point test to try-plots

* Fix d3 not showing and plotly mixing with matplotlib

* Use logger for warnings and debug statements

* Point tests back at master

---------

Co-authored-by: mbowcut2 <[email protected]>
Co-authored-by: Cole Lyman <[email protected]>

* Sam/fix plots (#72)

* Fix batch mode pandas warning. (#70)

* refactor to call method on DataFrame, rather than Series.
Removes warning.

* Fix pandas future warning in CRISPRessoWGS

---------

Co-authored-by: Cole Lyman <[email protected]>

* Functional

* Cole/fix status file name (#69)

* Update config file logging messages

This removes printing the exception (which is essentially a duplicate),
and adds a condition if no config file was provided. Also changes `json`
to `config` so that it is more clear.

* Fix divide by zero when no amplicons are present in Batch mode

* Don't append file_prefix to status file name

* Place status files in output directories

* Update tests branch for file_prefix addition

* Load D3 and plotly figures with pro with multiple amplicons

* Update batch

* Fix bug in CRISPRessoCompare with pointing to report datas with file_prefix

Before this fix, when using a file_prefix the second run that was compared
would not be displayed as a data in the first figure of the report.

* Import CRISPRessoPro instead of importing the version

When installed via conda, the version is not available

* Remove `get_amplicon_output` unused function from CRISPRessoCompare

Also remove unused argparse import

* Implement `get_matching_allele_files` in CRISPRessoCompare and accompanying unit tests

* Allow for matching of multiple guides in the same amplicon

* Fix pandas FutureWarning

* Change test branch back to master

---------

Co-authored-by: Sam <[email protected]>

* Try catch all futures

* Fix test fail plots

* Fix d3 not showing and plotly mixing with matplotlib

---------

Co-authored-by: mbowcut2 <[email protected]>
Co-authored-by: Cole Lyman <[email protected]>

* Remove token from integration tests file

* Pass div id for plotly

* Remove debug

---------

Co-authored-by: mbowcut2 <[email protected]>
Co-authored-by: Cole Lyman <[email protected]>
  • Loading branch information
3 people authored May 11, 2024
1 parent 308fd0f commit 17b880a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CRISPResso2/CRISPRessoAggregateCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,14 @@ def main():
crispresso2_info['results']['general_plots']['allele_modification_heatmap_plot_titles'] = {}
crispresso2_info['results']['general_plots']['allele_modification_heatmap_plot_labels'] = {}
crispresso2_info['results']['general_plots']['allele_modification_heatmap_plot_datas'] = {}
crispresso2_info['results']['general_plots']['allele_modification_heatmap_plot_divs'] = {}

crispresso2_info['results']['general_plots']['allele_modification_line_plot_names'] = []
crispresso2_info['results']['general_plots']['allele_modification_line_plot_paths'] = {}
crispresso2_info['results']['general_plots']['allele_modification_line_plot_titles'] = {}
crispresso2_info['results']['general_plots']['allele_modification_line_plot_labels'] = {}
crispresso2_info['results']['general_plots']['allele_modification_line_plot_datas'] = {}
crispresso2_info['results']['general_plots']['allele_modification_line_plot_divs'] = {}
if guides_all_same:
sgRNA_intervals = [consensus_sgRNA_intervals] * modification_frequency_summary_df.shape[0]
else:
Expand All @@ -645,11 +647,13 @@ def main():
plot_name = 'CRISPRessoAggregate_percentage_of_{0}_across_alleles_{1}_heatmap'.format(modification_type.lower(), amplicon_name)
plot_path = '{0}.html'.format(_jp(plot_name))

heatmap_div_id = '{0}-allele-modification-heatmap-{1}'.format(amplicon_name.lower(), modification_type.lower())
allele_modification_heatmap_input = {
'sample_values': modification_df,
'sample_sgRNA_intervals': sgRNA_intervals,
'plot_path': plot_path,
'title': modification_type,
'div_id': heatmap_div_id,
}
plot(
CRISPRessoPlot.plot_allele_modification_heatmap,
Expand All @@ -671,15 +675,18 @@ def main():
),
),
]
crispresso2_info['results']['general_plots']['allele_modification_heatmap_plot_divs'][plot_name] = heatmap_div_id

plot_name = 'CRISPRessoAggregate_percentage_of_{0}_across_alleles_{1}_line'.format(modification_type.lower(), amplicon_name)
plot_path = '{0}.html'.format(_jp(plot_name))

line_div_id = '{0}-allele-modification-line-{1}'.format(amplicon_name.lower(), modification_type.lower())
allele_modification_line_input = {
'sample_values': modification_df,
'sample_sgRNA_intervals': sgRNA_intervals,
'plot_path': plot_path,
'title': modification_type,
'div_id': line_div_id,
}
plot(
CRISPRessoPlot.plot_allele_modification_line,
Expand All @@ -700,6 +707,7 @@ def main():
),
),
]
crispresso2_info['results']['general_plots']['allele_modification_line_plot_divs'][plot_name] = line_div_id

crispresso2_info['results']['general_plots']['window_nuc_pct_quilt_plot_names'] = window_nuc_pct_quilt_plot_names
crispresso2_info['results']['general_plots']['nuc_pct_quilt_plot_names'] = nuc_pct_quilt_plot_names
Expand Down
10 changes: 8 additions & 2 deletions CRISPResso2/CRISPRessoBatchCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,14 @@ def main():
crispresso2_info['results']['general_plots']['allele_modification_heatmap_plot_titles'] = {}
crispresso2_info['results']['general_plots']['allele_modification_heatmap_plot_labels'] = {}
crispresso2_info['results']['general_plots']['allele_modification_heatmap_plot_datas'] = {}
crispresso2_info['results']['general_plots']['allele_modification_heatmap_plot_divs'] = {}

crispresso2_info['results']['general_plots']['allele_modification_line_plot_names'] = []
crispresso2_info['results']['general_plots']['allele_modification_line_plot_paths'] = {}
crispresso2_info['results']['general_plots']['allele_modification_line_plot_titles'] = {}
crispresso2_info['results']['general_plots']['allele_modification_line_plot_labels'] = {}
crispresso2_info['results']['general_plots']['allele_modification_line_plot_datas'] = {}
crispresso2_info['results']['general_plots']['allele_modification_line_plot_divs'] = {}

percent_complete_start, percent_complete_end = 90, 99
if all_amplicons:
Expand Down Expand Up @@ -798,12 +800,13 @@ def main():
plot_name = 'CRISPRessoBatch_percentage_of_{0}_across_alleles_{1}_heatmap'.format(modification_type.lower(), amplicon_name)
plot_path = '{0}.html'.format(_jp(plot_name))

heatmap_div_id = '{0}-allele-modification-heatmap-{1}'.format(amplicon_name.lower(), modification_type.lower())
allele_modification_heatmap_input = {
'sample_values': modification_df,
'sample_sgRNA_intervals': sgRNA_intervals,
'plot_path': plot_path,
'title': modification_type,
'amplicon_name': amplicon_name,
'div_id': heatmap_div_id,
}
debug('Plotting allele modification heatmap for {0}'.format(amplicon_name))
plot(
Expand All @@ -826,16 +829,18 @@ def main():
),
),
]
crispresso2_info['results']['general_plots']['allele_modification_heatmap_plot_divs'][plot_name] = heatmap_div_id

plot_name = 'CRISPRessoBatch_percentage_of_{0}_across_alleles_{1}_line'.format(modification_type.lower(), amplicon_name)
plot_path = '{0}.html'.format(_jp(plot_name))

line_div_id = '{0}-allele-modification-line-{1}'.format(amplicon_name.lower(), modification_type.lower())
allele_modification_line_input = {
'sample_values': modification_df,
'sample_sgRNA_intervals': sgRNA_intervals,
'plot_path': plot_path,
'title': modification_type,
'amplicon_name': amplicon_name,
'div_id': line_div_id,
}
debug('Plotting allele modification line plot for {0}'.format(amplicon_name))
plot(
Expand All @@ -858,6 +863,7 @@ def main():
),
),
]
crispresso2_info['results']['general_plots']['allele_modification_line_plot_divs'][plot_name] = line_div_id
#end if amp_found_count > 0 (how many folders had information for this amplicon)
#end per-amplicon analysis

Expand Down
11 changes: 11 additions & 0 deletions CRISPResso2/CRISPRessoReports/CRISPRessoReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ def make_batch_report_from_folder(crispressoBatch_report_file, crispresso2_info,
allele_modification_heatmap_plot['datas'] = crispresso2_info['results']['general_plots']['allele_modification_heatmap_plot_datas']
else:
allele_modification_heatmap_plot['datas'] = {}
if 'allele_modification_heatmap_plot_divs' in crispresso2_info['results']['general_plots']:
allele_modification_heatmap_plot['divs'] = crispresso2_info['results']['general_plots']['allele_modification_heatmap_plot_divs']
else:
allele_modification_heatmap_plot['divs'] = {}

allele_modification_line_plot = {}
if 'allele_modification_line_plot_names' in crispresso2_info['results']['general_plots']:
Expand All @@ -283,6 +287,10 @@ def make_batch_report_from_folder(crispressoBatch_report_file, crispresso2_info,
allele_modification_line_plot['datas'] = crispresso2_info['results']['general_plots']['allele_modification_line_plot_datas']
else:
allele_modification_line_plot['datas'] = {}
if 'allele_modification_line_plot_divs' in crispresso2_info['results']['general_plots']:
allele_modification_line_plot['divs'] = crispresso2_info['results']['general_plots']['allele_modification_line_plot_divs']
else:
allele_modification_line_plot['divs'] = {}

allele_modification_heatmap_plot['htmls'] = {}
for heatmap_plot_name, heatmap_plot_path in allele_modification_heatmap_plot['paths'].items():
Expand Down Expand Up @@ -572,6 +580,7 @@ def fill_default(dictionary, key, default_type=list):
('titles', list),
('labels', dict),
('datas', dict),
('divs', dict)
]
for dictionary in dictionaries:
for key, default_type in keys_and_default_types:
Expand Down Expand Up @@ -618,11 +627,13 @@ def fill_default(dictionary, key, default_type=list):
allele_modification_heatmap_plot_titles=allele_modification_heatmap_plot['titles'],
allele_modification_heatmap_plot_labels=allele_modification_heatmap_plot['labels'],
allele_modification_heatmap_plot_datas=allele_modification_heatmap_plot['datas'],
allele_modification_heatmap_plot_divs=allele_modification_heatmap_plot['divs'],
allele_modification_line_plot_names=allele_modification_line_plot['names'],
allele_modification_line_plot_htmls=allele_modification_line_plot['htmls'],
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'],
allele_modification_line_plot_divs=allele_modification_line_plot['divs'],
C2PRO_INSTALLED=C2PRO_INSTALLED,
))

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 @@ -147,10 +147,10 @@ <h5>{{report_data['titles'][plot_name]}}</h5>
<h5>{{allele_modification_heatmap_plot_titles[heatmap_plot_name]}}</h5>
<ul class="nav nav-tabs justify-content-center card-header-tabs" id="aln-tab" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link active" data-bs-toggle="tab" id="{{modification_type}}-heatmap-tab" data-bs-target="#{{heatmap_plot_name}}" role="tab" aria-controls="{{heatmap_plot_name}}" aria-selected="true">Heatmap</a>
<a class="nav-link active" data-bs-toggle="tab" id="{{heatmap_plot_name}}-heatmap-tab" data-bs-target="#{{heatmap_plot_name}}" role="tab" aria-controls="{{heatmap_plot_name}}" aria-selected="true">Heatmap</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" data-bs-toggle="tab" id="{{modification_type}}-line-tab" data-bs-target="#{{line_plot_name}}" role="tab" aria-controls="{{line_plot_name}}" aria-selected="false">Line</a>
<a class="nav-link" data-bs-toggle="tab" id="{{line_plot_name}}-line-tab" data-bs-target="#{{line_plot_name}}" role="tab" aria-controls="{{line_plot_name}}" aria-selected="false">Line</a>
</li>
</ul>
</div>
Expand All @@ -175,13 +175,13 @@ <h5>{{allele_modification_heatmap_plot_titles[heatmap_plot_name]}}</h5>
</div>
<script type="application/javascript">
document.addEventListener("DOMContentLoaded", () => {
$("#{{modification_type}}-heatmap-tab").on("shown.bs.tab", (e) => {
let plot = document.getElementById("allele-modification-heatmap-{{modification_type}}");
$("#{{heatmap_plot_name}}-heatmap-tab").on("shown.bs.tab", (e) => {
let plot = document.getElementById("{{ allele_modification_heatmap_plot_divs[heatmap_plot_name] }}" );
Plotly.Plots.resize(plot);
window.dispatchEvent(new Event("resize"));
});
$("#{{modification_type}}-line-tab").on("shown.bs.tab", (e) => {
let plot = document.getElementById("allele-modification-line-{{modification_type}}");
$("#{{line_plot_name}}-line-tab").on("shown.bs.tab", (e) => {
let plot = document.getElementById("{{ allele_modification_line_plot_divs[line_plot_name] }}");
Plotly.Plots.resize(plot);
window.dispatchEvent(new Event("resize"));
});
Expand Down

0 comments on commit 17b880a

Please sign in to comment.