Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit 3042a35

Browse files
committed
Merge pull request #51 from BradnerLab/bamliquidator_v1.3
bamliquidator_batch now compatible with latest bokeh version
2 parents 0467ae9 + 2f0ce6a commit 3042a35

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

bamliquidator_internal/bamliquidatorbatch/bamliquidator_batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from os.path import basename
2121
from os.path import dirname
2222

23-
__version__ = '1.2.0'
23+
__version__ = '1.3.0'
2424

2525
default_black_list = ["chrUn", "_random", "Zv9_", "_hap"]
2626

bamliquidator_internal/bamliquidatorbatch/normalize_plot_and_summarize.py

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,22 @@
3535
import logging
3636

3737
try:
38-
import bokeh.plotting as bp
38+
try:
39+
import bokeh.plotting as bp
40+
except:
41+
bokeh_import_error = ('Bokeh module not found; consider running the following command to install: '
42+
'sudo pip install bokeh')
43+
raise
44+
45+
try:
46+
# bamliquidatorbatch was originally developed for bokeh 0.4.4, but
47+
# around version 0.7 the bokeh API had some breaking changes (like requiring the explicit use of vplot).
48+
# I confirmed things work with version 0.9.3, and I hope future versions maintain compatability.
49+
bp.vplot
50+
except:
51+
bokeh_import_error = ('Bokeh version is incompatible; consider running the following command to upgrade: '
52+
'sudo pip install bokeh --upgrade')
53+
raise
3954
except:
4055
bp = None
4156

@@ -105,12 +120,13 @@ def file_keys(counts, cell_type):
105120
return file_keys_memo[cell_type]
106121

107122
def plot_summaries(output_directory, normalized_counts, chromosomes):
108-
bp.output_file(output_directory + "/summary.html")
109-
123+
bp.output_file(output_directory + "/summary.html", mode="cdn")
124+
plots = []
110125
for chromosome in chromosomes:
111-
plot_summary(normalized_counts, chromosome)
112-
113-
bp.save()
126+
plot = plot_summary(normalized_counts, chromosome)
127+
if plot:
128+
plots.append(plot)
129+
bp.save(bp.vplot(*plots))
114130

115131
def plot_summary(normalized_counts, chromosome):
116132
logging.debug(" - plotting %s summary", chromosome)
@@ -126,14 +142,22 @@ def plot_summary(normalized_counts, chromosome):
126142
logging.info("-- skipping plotting %s because not enough bins (only %d)", chromosome, num_bins)
127143
return
128144

129-
overall = bp.scatter(chromosome_count_by_bin.keys(), chromosome_count_by_bin.values())
130-
overall.title = chromosome + " counts per bin across all bam files"
145+
plot = bp.figure()
146+
plot.title = chromosome + " counts per bin across all bam files"
147+
plot.scatter(chromosome_count_by_bin.keys(), chromosome_count_by_bin.values())
148+
return plot
131149

132150
def plot(output_directory, normalized_counts, chromosome, cell_types):
133-
bp.output_file(output_directory + "/" + chromosome + ".html")
134-
135-
plot_summary(normalized_counts, chromosome)
136-
151+
bp.output_file(output_directory + "/" + chromosome + ".html", mode="cdn")
152+
plots = []
153+
154+
summary = plot_summary(normalized_counts, chromosome)
155+
if summary:
156+
plots.append(summary)
157+
else:
158+
# if summary can't be plotted, then rest probably can't be plotted either,
159+
# so return without even saving the file (the file is never created on disk if not saved)
160+
return
137161
for cell_type in cell_types:
138162
logging.debug(" - plotting %s", cell_type)
139163

@@ -146,10 +170,11 @@ def plot(output_directory, normalized_counts, chromosome, cell_types):
146170
bin_number.append(row["bin_number"])
147171
count.append(row["count"])
148172

149-
cell_type_plot = bp.scatter(bin_number, count)
150-
cell_type_plot.title = "%s counts per bin" % cell_type
151-
152-
bp.save()
173+
plot = bp.figure()
174+
plot.title = "%s counts per bin" % cell_type
175+
plot.scatter(bin_number, count)
176+
plots.append(plot)
177+
bp.save(bp.vplot(*plots))
153178

154179
def populate_normalized_counts(normalized_counts, counts, file_key, bin_size, files):
155180
total_count = length_for_file_key(files, file_key)
@@ -375,10 +400,9 @@ def normalize_plot_and_summarize(counts_file, output_directory, bin_size, skip_p
375400

376401
if not skip_plot:
377402
if bp is None:
378-
logging.error('Skipping plotting because plots require bokeh and it is not installed -- '
379-
'see https://github.com/BradnerLab/pipeline/wiki/bamliquidator#Install . '
380-
'Consider running the following command to install bokeh: '
381-
'sudo pip install bokeh==0.4.4 "openpyxl>=1.6.1,<2.0.0"')
403+
logging.error('Skipping plotting because plots require a compatible version of bokeh -- '
404+
'see https://github.com/BradnerLab/pipeline/wiki/bamliquidator#Install . %s'
405+
% bokeh_import_error)
382406
else:
383407
logging.info("Plotting")
384408
for chromosome in chromosomes:

0 commit comments

Comments
 (0)