diff --git a/docs/helper.md b/docs/helper.md index 604534c..bd509ea 100644 --- a/docs/helper.md +++ b/docs/helper.md @@ -35,11 +35,20 @@ derived from the *Sorghum bicolor* case study, in included in the repository. ### plot_network Script that plots the co-expression neighborhood for a specific gene. A PCC cutoff of 0.7 is included by default, -but users can override this setting using the --cutoff parameter. +but users can override this setting using the --cutoff parameter. Matplotlib and networkx are required for this +script. # To draw plot to screen using a PCC cutoff of >= 0.8 python3 plot_network.py --cutoff 0.8 + # Save as png + python3 plot_network.py --cutoff 0.8 --png output.png + + # Set png dpi (for publication) + python3 plot_network.py --cutoff 0.8 --png output.png --dpi 900 + + + ![matrix example](images/plot_network.png "Example of plotted network") ### matrix_heatmap.py diff --git a/docs/images/plot_network.png b/docs/images/plot_network.png new file mode 100644 index 0000000..1d6538f Binary files /dev/null and b/docs/images/plot_network.png differ diff --git a/helper/plot_network.py b/helper/plot_network.py index 1751a81..06f0efa 100644 --- a/helper/plot_network.py +++ b/helper/plot_network.py @@ -8,7 +8,7 @@ DEBUG = True -def plot_network(filename, gene, cutoff=0.7): +def plot_network(filename, gene, cutoff=0.7, png=None, dpi=300): """ Function to load a co-expression network from LSTrAP and plot the neighborhood for one gene. @@ -89,7 +89,11 @@ def plot_network(filename, gene, cutoff=0.7): nx.draw_networkx_labels(graph, pos, {k: k for k in valid_genes}, font_size=16, alpha=0.5) plt.axis('off') - plt.show() + if png is None: + plt.show() + else: + plt.savefig(png, format='png', dpi=dpi) + print("Wrote output to %s" % png) if __name__ == "__main__": @@ -100,10 +104,13 @@ def plot_network(filename, gene, cutoff=0.7): parser.add_argument('--cutoff', help='PCC cutoff to use (default = 0.7)', default=0.7, type=float) + parser.add_argument('--png', help='save output as png file (default: None, don\'t write png to file)', default=None) + parser.add_argument('--dpi', help='dpi for the output (default = 300)', default=300, type=float) + parser.set_defaults(show_labels=True) # Parse arguments and start script args = parser.parse_args() - plot_network(args.filename, args.gene, cutoff=args.cutoff) + plot_network(args.filename, args.gene, cutoff=args.cutoff, png=args.png, dpi=args.dpi)