From b81d3288aab9b66620c4b9f6cc2b0c140bd56828 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Flor=C3=A9al=20Cabanettes?= <floreal.cabanettes@inra.fr>
Date: Thu, 20 Apr 2017 14:31:20 +0200
Subject: [PATCH] Add colors to boxplots

---
 build_R_figures.py | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/build_R_figures.py b/build_R_figures.py
index a14f937..95ce17c 100755
--- a/build_R_figures.py
+++ b/build_R_figures.py
@@ -38,6 +38,8 @@ with open(rscript_name, "w") as rscript:
             columns = []
             columns_goods = []
             columns_bads = []
+            rscript.write("colors <- colorRampPalette(c(\"#ff0000\", \"#e6e600\", \"#00ff00\"));\n"
+                          "colors <- colors(101);\n")
             for indiv in range(1, args.nb_inds+1):
                 columns.append("gt_qual[,\"{0}__INDIV_{1}\"]".format(tool, indiv))
                 columns_goods.append("gt_qual_goods[,\"{0}__INDIV_{1}\"]".format(tool, indiv))
@@ -54,21 +56,28 @@ with open(rscript_name, "w") as rscript:
                                   "\t}}\n" +
                                   "}}\n").format(tool, indiv))
 
+            colors = ["colors[round(mean(" + x + ", na.rm = T))+1]" for x in columns]
+            colors_goods = ["colors[round(mean(" + x + ", na.rm = T))+1]" for x in columns_goods]
+            colors_bads = ["colors[round(mean(" + x + ", na.rm = T))+1]" for x in columns_bads]
+
             # All
             rscript.write("pdf(\"gt_quality_" + tool + ".pdf\", width=9, height=3);\n")
             rscript.write("par(mfrow=c(1,3));\n")
-            rscript.write("boxplot({0}, main=\"{1}\", xlab=\"individuals\", ylab=\"quality (%)\", ylim=c(0,100));\n".
-                          format(", ".join(columns), tool.title() + " [ALL]"))
+            rscript.write(
+                "boxplot({0}, main=\"{1}\", xlab=\"individuals\", ylab=\"quality (%)\", ylim=c(0,100), border=c({2}));\n".
+                format(", ".join(columns), tool.title() + " [ALL]", ",".join(colors)))
             rscript.write("axis(side=1, seq(1,{0}));\n".format(args.nb_inds))
 
             # Goods
-            rscript.write("boxplot({0}, main=\"{1}\", xlab=\"individuals\", ylab=\"quality (%)\", ylim=c(0,100));\n".
-                          format(", ".join(columns_goods), tool.title() + " [GOODS]"))
+            rscript.write(
+                "boxplot({0}, main=\"{1}\", xlab=\"individuals\", ylab=\"quality (%)\", ylim=c(0,100), border=c({2}));\n".
+                format(", ".join(columns_goods), tool.title() + " [GOODS]", ",".join(colors_goods)))
             rscript.write("axis(side=1, seq(1,{0}));\n".format(args.nb_inds))
 
             # Bads
-            rscript.write("boxplot({0}, main=\"{1}\", xlab=\"individuals\", ylab=\"quality (%)\", ylim=c(0,100));\n".
-                          format(", ".join(columns_bads), tool.title() + " [BADS]"))
+            rscript.write(
+                "boxplot({0}, main=\"{1}\", xlab=\"individuals\", ylab=\"quality (%)\", ylim=c(0,100), border=c({2}));\n".
+                format(", ".join(columns_bads), tool.title() + " [BADS]", ",".join(colors_bads)))
             rscript.write("axis(side=1, seq(1,{0}));\n".format(args.nb_inds))
 
     sv_file_io = open(svs_file, "r")
-- 
GitLab