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

Use Agg backend when saving images. Add option for UTC times. #160

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions poretools/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def plot_hist(sizes, args):
"""
sizes = [s for s in sizes if args.min_length < s < args.max_length]

if args.saveas is not None:
plt.switch_backend('Agg') # Use non-interactive backend in case this is
# running on a headless system.

if args.theme_bw:
sns.set_style("whitegrid")
plt.hist(sizes, args.num_bins)
Expand Down
3 changes: 3 additions & 0 deletions poretools/occupancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def plot_performance(parser, args, pore_measure):
"""
Plot the pore performance in terms of reads per pore
"""
if args.saveas is not None:
plt.switch_backend('Agg') # Use non-interactive backend in case this is
# running on a headless system.
flowcell_layout = minion_flowcell_layout()

pore_values = []
Expand Down
5 changes: 5 additions & 0 deletions poretools/poretools_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ def main():
##########
parser_times = subparsers.add_parser('times',
help='Return the start times from a set of FAST5 files in tabular format')
parser_times.add_argument('--utc',
dest='utc',
default=False,
action='store_true',
help="Show timestamps in UTC.")
parser_times.add_argument('files', metavar='FILES', nargs='+',
help='The input FAST5 files.')
parser_times.set_defaults(func=run_subtool)
Expand Down
9 changes: 7 additions & 2 deletions poretools/qual_v_pos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Fast5File
from collections import defaultdict
import pandas
import sys
import matplotlib.pyplot as plt

#logging
Expand Down Expand Up @@ -42,6 +43,10 @@ def run(parser, args):

fast5.close()

if args.saveas is not None:
plt.switch_backend('Agg') # Use non-interactive backend in case this is
# running on a headless system.

logger.info("Processing data...")
data = [qualpos[e] for e in sorted(qualpos.keys())]
logger.info("Constructing box plot...")
Expand All @@ -53,10 +58,10 @@ def run(parser, args):
if args.saveas is not None:
logger.info("Writing plot to file...")
plot_file = args.saveas
if plot_file.endswith(".pdf") or plot_file.endswith(".jpg"):
if plot_file.endswith(".pdf") or plot_file.endswith(".png") or plot_file.endswith(".svg"):
plt.savefig(plot_file)
else:
logger.error("Unrecognized extension for %s! Try .pdf or .jpg" % (plot_file))
logger.error("Unrecognized extension for %s! Try .pdf, .png, or .svg" % (plot_file))
sys.exit()

else:
Expand Down
4 changes: 4 additions & 0 deletions poretools/squiggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def plot_squiggle(args, filename, start_times, mean_signals):
starts = df.groupby('cat')['start']
mins, maxs = list(starts.min()), list(starts.max())

if args.saveas is not None:
plt.switch_backend('Agg') # Use non-interactive backend in case this is
# running on a headless system.

grid = sns.FacetGrid(df, row="cat", sharex=False, size=8)
#plt.gcf().tight_layout()
grid.fig.suptitle('Squiggle plot for read: ' + filename + "\nTotal time (sec): " + str(total_time))
Expand Down
7 changes: 5 additions & 2 deletions poretools/times.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Fast5File
from time import strftime, localtime
from time import strftime, localtime, gmtime
import sys

#logging
Expand Down Expand Up @@ -28,7 +28,10 @@ def run(parser, args):
else:
read_length = 0

lt = localtime(start_time)
if args.utc:
lt = gmtime(start_time)
else:
lt = localtime(start_time)
print "\t".join([str(fast5.get_channel_number()),
fast5.filename,
str(read_length),
Expand Down
4 changes: 4 additions & 0 deletions poretools/yield_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def plot_collectors_curve(args, start_times, read_lengths):
if args.theme_bw:
sns.set_style("whitegrid")

if args.saveas is not None:
plt.switch_backend('Agg') # Use non-interactive backend in case this is
# running on a headless system.

# plot
plt.plot(df['start'], df['cumul'])
plt.xlabel('Time (hours)')
Expand Down