From 7ce3b7d2b16f3c921035bab150c56f4bd493e8fd Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Wed, 7 Sep 2022 11:39:57 +0200 Subject: [PATCH 1/4] Support setting the plot title using the outid Fixes #92. --- wisecondorX/include/plotter.R | 8 +++++--- wisecondorX/main.py | 3 +++ wisecondorX/predict_output.py | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/wisecondorX/include/plotter.R b/wisecondorX/include/plotter.R index dab12ba..ffe5fab 100644 --- a/wisecondorX/include/plotter.R +++ b/wisecondorX/include/plotter.R @@ -7,6 +7,7 @@ options(warn=-1) args <- commandArgs(T) in.file <- paste0(args[which(args == "--infile")+1]) + # ----- # lib # ----- @@ -29,6 +30,7 @@ gender = input$ref_gender beta = as.numeric(input$beta) zcutoff = as.numeric(input$zscore) ylim = input$ylim +plot.title = ifelse(!is.null(input$plot_title), input$plot_title, "") if (input$cairo) options(bitmaptype='cairo') @@ -123,7 +125,7 @@ layout(l.matrix) par(mar=c(2.5,4,1,0), mgp=c(2.4,0.5,0), oma=c(0,0,3,0)) -plot(1, main="", axes=F, # plots nothing -- enables segments function +plot(1, main=plot.title, axes=F, # plots nothing -- enables segments function xlab="", ylab="", xlim=c(chr.ends[1], chr.ends[length(chr.ends)]), cex=0, ylim=c(chr.wide.lower.limit,chr.wide.upper.limit)) @@ -278,7 +280,7 @@ for (c in chrs){ if (any(is.na(whis))){ next } - + png(paste0(out.dir, "/", labels[c],".png"), width=14,height=10,units="in",res=256,pointsize=18) upper.limit <- 0.6 + whis[2] @@ -289,7 +291,7 @@ for (c in chrs){ lower.limit = ylim[1] ; upper.limit = ylim[2] } par(mar=c(2.5,4,1,0), mgp=c(2.4,0.5,0)) - + plot(1, main="", axes=F, # plots nothing -- enables segments function xlab="", ylab="", cex=0, ylim=c(lower.limit,upper.limit), xlim=margins) diff --git a/wisecondorX/main.py b/wisecondorX/main.py index 4c2e99a..d81602d 100755 --- a/wisecondorX/main.py +++ b/wisecondorX/main.py @@ -396,6 +396,9 @@ def main(): parser_test.add_argument('--cairo', action='store_true', help='Uses cairo bitmap type for plotting. Might be necessary for certain setups.') + parser_test.add_argument("--plot-title", + action="store_true", + help="Add the output name as plot title") parser_test.set_defaults(func=tool_test) args = parser.parse_args(sys.argv[1:]) diff --git a/wisecondorX/predict_output.py b/wisecondorX/predict_output.py index 17153de..542d0ed 100644 --- a/wisecondorX/predict_output.py +++ b/wisecondorX/predict_output.py @@ -28,6 +28,12 @@ def exec_write_plots(rem_input, results): 'infile': str('{}.json'.format(json_plot_dir)), 'out_dir': str('{}.plots'.format(rem_input['args'].outid)), } + + if rem_input["args"].plot_title: + # Strip away paths from the outid if need be + json_dict["plot_title"] = str( + os.path.basename(rem_input["args"].outid)) + exec_R(json_dict) From 01a549864f5a4d59034cb1fb82d70fb234488619 Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Wed, 7 Sep 2022 13:42:25 +0200 Subject: [PATCH 2/4] Use a less ambiguous option name --- wisecondorX/predict_output.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wisecondorX/predict_output.py b/wisecondorX/predict_output.py index 542d0ed..4586966 100644 --- a/wisecondorX/predict_output.py +++ b/wisecondorX/predict_output.py @@ -29,7 +29,7 @@ def exec_write_plots(rem_input, results): 'out_dir': str('{}.plots'.format(rem_input['args'].outid)), } - if rem_input["args"].plot_title: + if rem_input["args"].add_plot_title: # Strip away paths from the outid if need be json_dict["plot_title"] = str( os.path.basename(rem_input["args"].outid)) From 6ee29f6ca3b579b944688ce7ce7b10e24ff72d46 Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Wed, 7 Sep 2022 13:43:26 +0200 Subject: [PATCH 3/4] Place the ID text on the right of the rest of the plot --- wisecondorX/include/plotter.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wisecondorX/include/plotter.R b/wisecondorX/include/plotter.R index ffe5fab..f4ac798 100644 --- a/wisecondorX/include/plotter.R +++ b/wisecondorX/include/plotter.R @@ -30,7 +30,7 @@ gender = input$ref_gender beta = as.numeric(input$beta) zcutoff = as.numeric(input$zscore) ylim = input$ylim -plot.title = ifelse(!is.null(input$plot_title), input$plot_title, "") +plot.title = input$plot_title if (input$cairo) options(bitmaptype='cairo') @@ -125,7 +125,7 @@ layout(l.matrix) par(mar=c(2.5,4,1,0), mgp=c(2.4,0.5,0), oma=c(0,0,3,0)) -plot(1, main=plot.title, axes=F, # plots nothing -- enables segments function +plot(1, main="", axes=F, # plots nothing -- enables segments function xlab="", ylab="", xlim=c(chr.ends[1], chr.ends[length(chr.ends)]), cex=0, ylim=c(chr.wide.lower.limit,chr.wide.upper.limit)) @@ -211,6 +211,12 @@ legend(x=0, cex=1.3, bty="n", pch=c(16,16), col=c(color.C, color.B, "white")) par(xpd=F) +if (!is.null(plot.title)) { + par(xpd=NA) + title(plot.title, line=1.3, adj=0.8, col.main=color.A) + par(xpd=F) +} + # plot segmentation for (ab in input$results_c){ From be82584b53949cecca36cd286555795e6c65020a Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Wed, 7 Sep 2022 13:44:17 +0200 Subject: [PATCH 4/4] Add forgotten option change --- wisecondorX/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wisecondorX/main.py b/wisecondorX/main.py index d81602d..63e61d5 100755 --- a/wisecondorX/main.py +++ b/wisecondorX/main.py @@ -396,7 +396,7 @@ def main(): parser_test.add_argument('--cairo', action='store_true', help='Uses cairo bitmap type for plotting. Might be necessary for certain setups.') - parser_test.add_argument("--plot-title", + parser_test.add_argument("--add-plot-title", action="store_true", help="Add the output name as plot title") parser_test.set_defaults(func=tool_test)