Skip to content

Commit

Permalink
Allow users to specify an output directory for the plots
Browse files Browse the repository at this point in the history
This is useful when the number of generated plots gets very high
  • Loading branch information
mgalardini committed Jun 2, 2024
1 parent e504cee commit d924264
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions panfeed/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def get_options():
default='png',
help='Output format for plots (default %(default)s)')

parser.add_argument('--output-directory',
default='.',
help='Output directory for the plots (default %(default)s)')

parser.add_argument('--dpi',
type=int,
default=300,
Expand Down Expand Up @@ -337,7 +341,7 @@ def handle_paralogs_text(x):
cax = divider.append_axes("right", size="2.5%", pad=0.05)
coba = plt.colorbar(im, cax=cax)
coba.set_label("-log10 p-value")
plt.savefig(f'significance_{gene}.{args.format}', dpi=args.dpi, bbox_inches="tight")
plt.savefig(f'{args.output_directory}/significance_{gene}.{args.format}', dpi=args.dpi, bbox_inches="tight")
logger.info(f'saved plot significance_{gene}.{args.format}')
plt.close()

Expand All @@ -360,7 +364,7 @@ def handle_paralogs_text(x):
ax.set_title(f"nucleotide sequence {gene}")
ax.set_xlabel("position relative to gene start")
ax.set_ylabel(f"{g.shape[0]} samples")
plt.savefig(f'sequence_{gene}.{args.format}', dpi=args.dpi, bbox_inches="tight")
plt.savefig(f'{args.output_directory}/sequence_{gene}.{args.format}', dpi=args.dpi, bbox_inches="tight")
logger.info(f'saved plot sequence_{gene}.{args.format}')
plt.close()

Expand Down Expand Up @@ -389,7 +393,7 @@ def handle_paralogs_text(x):
ax.set_title(f"significant k-mers {gene}")
ax.set_xlabel("position relative to gene start")
ax.set_ylabel(f"{g.shape[0]} samples")
plt.savefig(f'hybrid_{gene}.{args.format}', dpi=args.dpi, bbox_inches="tight")
plt.savefig(f'{args.output_directory}/hybrid_{gene}.{args.format}', dpi=args.dpi, bbox_inches="tight")
logger.info(f'saved plot hybrid_{gene}.{args.format}')
plt.close()

Expand All @@ -406,7 +410,7 @@ def handle_paralogs_text(x):
xticklabels=False,
square=True)

plt.savefig(f'sequence_legend.{args.format}', dpi=args.dpi, bbox_inches="tight")
plt.savefig(f'{args.output_directory}/sequence_legend.{args.format}', dpi=args.dpi, bbox_inches="tight")
logger.info(f"Saved nucleotide color key at sequence_legend.{args.format}")
plt.close()

Expand Down

0 comments on commit d924264

Please sign in to comment.