diff --git a/README.md b/README.md
index b1d8bdb6cad0d92a3d06238e6535bbce1af5c815..dae643c30c8f58ffb6fffb83b1cdeed00db72f4d 100755
--- a/README.md
+++ b/README.md
@@ -132,11 +132,13 @@ export SINGU_CONF=singularity/3.8.3
 export SINGU_CONF_AFTER=bin/singularity # on maestro
 export GIT_CONF=git/2.25.0
 export GIT_CONF_AFTER=bin/git # on maestro
+export GRAPHVIZ_CONF=graphviz//2.42.3
+export GRAPHVIZ_CONF_AFTER=bin/graphviz # on maestro
 
-MODULES="${CONF_BEFORE}/${JAVA_CONF}/${JAVA_CONF_AFTER},${CONF_BEFORE}/${SINGU_CONF}/${SINGU_CONF_AFTER},${CONF_BEFORE}/${GIT_CONF}/${GIT_CONF_AFTER}"
+MODULES="${CONF_BEFORE}/${JAVA_CONF}/${JAVA_CONF_AFTER},${CONF_BEFORE}/${SINGU_CONF}/${SINGU_CONF_AFTER},${CONF_BEFORE}/${GIT_CONF}/${GIT_CONF_AFTER},${CONF_BEFORE}/${GRAPHVIZ_CONF}/${GRAPHVIZ_CONF_AFTER}"
 # cd ${EXEC_PATH} # not required when using the gitlab repo to run the script
 # chmod 755 ${EXEC_PATH}/bin/*.* # not required when using the gitlab repo to run the script
-module load ${JAVA_CONF} ${SINGU_CONF} ${GIT_CONF}
+module load ${JAVA_CONF} ${SINGU_CONF} ${GIT_CONF} ${GRAPHVIZ_CONF}
 
 ```
 
@@ -197,6 +199,11 @@ Gitlab developers
 ## WHAT'S NEW IN
 
 
+### v7.0.0
+
+1) Ok up to insertion freq, tested using the test file
+
+
 ### v6.1.0
 
 1) config file debugged
diff --git a/bin/duplicate_removal.sh b/bin/duplicate_removal.sh
index a3be46a9597a95232facaecc381ee1c4bfb49471..78039bc4b2b1283bd7b7021f161f0ecfeac9ccc2 100644
--- a/bin/duplicate_removal.sh
+++ b/bin/duplicate_removal.sh
@@ -70,10 +70,11 @@ samtools index ${output_file} |& tee -a ${exec_log} # create indexes
 # check that no duplicates remains in TAG BX
 echo -e "\n\n################ Check that no duplicates remains in TAG BX\n\n" >> ${exec_log}
 echo -e "Number of lines with unique TAG:" >> ${exec_log}
-awk '!/^@|^$/{print $NF}' ${SAMPLE_NAME}_nodup.sam | sort | uniq -c | cut -d ' ' -f 1 | sort | uniq -c >> ${exec_log} # or rev file | cut -f 1
+awk '!/^@|^$/{print $NF}' ${SAMPLE_NAME}_nodup.sam | sort | uniq -c | cut -d ' ' -f 1 >> ${exec_log} # or rev file | cut -f 1
 # !/^@|^$/ because one empty line after @ headers that I do see using samtools view I do not know why. Using Notepad+, I confirm the presence of the empty line
 echo -e "\n\nTotal number of lines:" >> ${exec_log}
 line_nb_after=$(samtools view ${output_file} | wc -l | cut -f1 -d' ')
+echo "$(printf "%'d" ${line_nb_after})\n" >> ${exec_log}
 
 # printing
 LC_NUMERIC="en_US.UTF-8" # this is to have printf working for comma thousand separator
@@ -84,4 +85,4 @@ echo -e "Ratio: " >> ${log}
 echo -e $(printf '%.2f\n' $(echo " $line_nb_after / $line_nb_before " | bc -l)) >> ${log} # the number in '%.2f\n' is the number of decimals
 echo -e "\n\n" >> ${log}
 
-echo \$line_nb_after > dup_read_nb # because nf cannot output values easily
\ No newline at end of file
+echo $line_nb_after > dup_read_nb # because nf cannot output values easily
\ No newline at end of file
diff --git a/bin/plot_coverage.R b/bin/plot_coverage.R
index 3cf7364140d7222f1a2ac42693a7500c548b751f..a70c7d410ae1c4161fb5531fa6286ae3a9f85592 100644
--- a/bin/plot_coverage.R
+++ b/bin/plot_coverage.R
@@ -76,7 +76,7 @@ if(interactive() == FALSE){ # if(grepl(x = commandArgs(trailingOnly = FALSE), pa
         "ori_coord", 
         "ter_coord", 
         "color_coverage", 
-        "ref_name", 
+        "xlab", 
         "file_name", 
         "cute", 
         "log"
@@ -124,7 +124,7 @@ param.list <- c(
     "ori_coord", 
     "ter_coord", 
     "color_coverage", 
-    "ref_name", 
+    "xlab", 
     "file_name", 
     "cute", 
     "log"
@@ -237,7 +237,7 @@ tempo <- fun_check(data = read_nb, class = "vector", typeof = "character", lengt
 tempo <- fun_check(data = ori_coord, class = "vector", typeof = "character", length = 1) ; eval(ee)
 tempo <- fun_check(data = ter_coord, class = "vector", typeof = "character", length = 1) ; eval(ee)
 tempo <- fun_check(data = color_coverage, class = "vector", typeof = "character", length = 1) ; eval(ee)
-tempo <- fun_check(data = ref_name, class = "vector", typeof = "character", length = 1) ; eval(ee)
+tempo <- fun_check(data = xlab, class = "vector", typeof = "character", length = 1) ; eval(ee)
 tempo <- fun_check(data = file_name, class = "vector", typeof = "character", length = 1) ; eval(ee)
 tempo <- fun_check(data = cute, class = "vector", typeof = "character", length = 1) ; eval(ee)
 tempo <- fun_check(data = log, class = "vector", typeof = "character", length = 1) ; eval(ee)
@@ -255,7 +255,7 @@ tempo.arg <-c(
     "ori_coord", 
     "ter_coord", 
     "color_coverage", 
-    "ref_name", 
+    "xlab", 
     "file_name", 
     "cute", 
     "log"
@@ -346,11 +346,11 @@ if(erase.graphs == TRUE){
 
 
 ################ Data import
-print(cov)
+
 
 df <- read.table(paste0(cov, ".cov"), stringsAsFactors = TRUE) # does not take the header
-ori <- data.frame(x= c(ori_coord[1], ori_coord[1], ori_coord[2], ori_coord[2], ori_coord[1]), y = c(0, Inf, Inf, 0 ,0), stringsAsFactors = TRUE)
-ter <- data.frame(x= c(ter_coord[1], ter_coord[1], ter_coord[2], ter_coord[2], ter_coord[1]), y = c(0, Inf, Inf, 0 ,0), stringsAsFactors = TRUE)
+read_nb <- scan(read_nb, what = double())
+
 
 ################ end Data import
 
@@ -358,7 +358,11 @@ ter <- data.frame(x= c(ter_coord[1], ter_coord[1], ter_coord[2], ter_coord[2], t
 ############ modifications of imported tables
 
 
-
+# ori and ter prep
+tempo <- max(df$V4) + 20
+ori <- data.frame(x= c(ori_coord[1], ori_coord[1], ori_coord[2], ori_coord[2], ori_coord[1]), y = c(-tempo, tempo, tempo, -tempo ,-tempo), ZONE = "Ori", stringsAsFactors = TRUE)
+dif <- data.frame(x= c(ter_coord[1], ter_coord[1], ter_coord[2], ter_coord[2], ter_coord[1]), y = c(-tempo, tempo, tempo, -tempo ,-tempo), ZONE = "Ter", stringsAsFactors = TRUE)
+structure <- rbind(ori, dif, stringsAsFactors = TRUE)
 
 ############ end modifications of imported tables
 
@@ -367,16 +371,17 @@ ter <- data.frame(x= c(ter_coord[1], ter_coord[1], ter_coord[2], ter_coord[2], t
 
 
 # fun_open(width = 12, height = 4, pdf.name = "plot_fivep_filtering_stat") # must be systematically opened for main.nf
-png(filename = paste0(cov, ".png"), width = 5000, height = 1800, units = "px", res = 300)
+png(filename = paste0("plot_", cov, ".png"), width = 5000, height = 1800, units = "px", res = 300)
 
 if(ncol(df) > 0){
-    fun_gg_scatter(data1 = list(ori, ter, df), 
-        x = list("x", "x", "V3"), 
-        y = list("y", "y", "V4"), 
+    fun_gg_scatter(data1 = list(structure, df), 
+        x = list("x", "V3"), 
+        y = list("y", "V4"), 
+        categ = list("ZONE", NULL), 
         geom = "geom_step", 
         alpha = 1, 
-        color = list(fun_gg_palette(n = 1), fun_gg_palette(n = 4)[4], fun_gg_palette(n = 7, "dark")[color_coverage]), 
-        x.lab = ref_name, 
+        color = list(c("black", "brown"), fun_gg_palette(n = 7, "dark")[color_coverage]), 
+        x.lab = xlab, 
         x.tick.nb = 6, 
         x.second.tick.nb = 3, 
         x.left.extra.margin = 0, 
@@ -390,10 +395,10 @@ if(ncol(df) > 0){
         y.bottom.extra.margin = 0, 
         grid = TRUE, 
         article = FALSE, 
-        legend.width = 0, 
-        text.size = 16, 
-        title = paste0(cov, " | NB OF READS: ", format(read_nb, big.mark = ","), " | Ori POSITION IN RED | Ter IN "), 
-        title.text.size = 8
+        legend.width = NULL, 
+        text.size = 20, 
+        title = paste0(cov, " | NB OF READS: ", format(read_nb, big.mark = ",")), 
+        title.text.size = 20
     )
 }else{
     fun_gg_empty_graph(text = "EMPTY .cov FILE: NO PLOT DRAWN")
diff --git a/bin/plot_insertion.R b/bin/plot_insertion.R
new file mode 100644
index 0000000000000000000000000000000000000000..207b26077b72f3f59b466eca79c12b6fb23b8a2f
--- /dev/null
+++ b/bin/plot_insertion.R
@@ -0,0 +1,510 @@
+
+
+#########################################################################
+##                                                                     ##
+##     plot_insertion.R                                                 ##
+##                                                                     ##
+##     Gael A. Millot                                                  ##
+##     Bioinformatics and Biostatistics Hub                            ##
+##     Computational Biology Department                                ##
+##     Institut Pasteur Paris                                          ##
+##                                                                     ##
+#########################################################################
+
+
+
+
+################################ Aim
+
+
+################################ End Aim
+
+
+################################ Introduction
+
+
+################################ End Introduction
+
+
+################################ Acknowlegments
+
+
+################################ End Acknowlegments
+
+
+################################ Initialization
+
+
+# R version checking
+if(version$version.string != "R version 4.0.5 (2021-03-31)"){
+    stop(paste0("\n\n================\n\nERROR IN plot_read_length.R\n", version$version.string, " IS NOT THE 4.0.5 RECOMMANDED\n\n================\n\n"))
+}
+# other initializations
+erase.objects = TRUE # write TRUE to erase all the existing objects in R before starting the algorithm and FALSE otherwise. Beginners should use TRUE
+if(erase.objects == TRUE){
+    rm(list = ls(all.names = TRUE))
+    erase.objects = TRUE
+}
+erase.graphs = TRUE # write TRUE to erase all the graphic windows in R before starting the algorithm and FALSE otherwise
+script <- "plot_insertion"
+
+
+################################ End Initialization
+
+
+################################ Parameters that need to be set by the user
+
+
+################################ End Parameters that need to be set by the user
+
+
+################################ Config import
+
+
+tempo.cat <- "KIND OF RUN (SCRIPT, COPY-PASTE OR SOURCE): "
+if(interactive() == FALSE){ # if(grepl(x = commandArgs(trailingOnly = FALSE), pattern = "R\\.exe$|\\/R$|Rcmd\\.exe$|Rcmd$|Rgui\\.exe$|Rgui$|Rscript\\.exe$|Rscript$|Rterm\\.exe$|Rterm$")){ # detection of script usage
+    run.way <- "SCRIPT"
+    cat(paste0("\n\n", tempo.cat, run.way, "\n"))
+    command <- paste0(commandArgs(trailingOnly = FALSE), collapse = ",") # recover the full command
+    args <- commandArgs(trailingOnly = TRUE) # recover arguments written after the call of the R script
+    if(any(is.na(args))){
+        stop(paste0("\n\n================\n\nERROR IN plot_insertion.R\nTHE args OBJECT HAS NA\n\n================\n\n"), call. = FALSE)
+    }
+    tempo.arg.names <- c(
+        "pos", 
+        "ori_coord", 
+        "ter_coord", 
+        "xlab", 
+        "genome_size", 
+        "file_name", 
+        "cute", 
+        "log"
+    ) # objects names exactly in the same order as in the bash code and recovered in args. Here only one, because only the path of the config file to indicate after the plot_insertion.R script execution
+    if(length(args) != length(tempo.arg.names)){
+        stop(paste0("\n\n================\n\nERROR IN plot_insertion.R\nTHE NUMBER OF ELEMENTS IN args (", length(args),") IS DIFFERENT FROM THE NUMBER OF ELEMENTS IN tempo.arg.names (", length(tempo.arg.names),")\nargs:", paste0(args, collapse = ","), "\ntempo.arg.names:", paste0(tempo.arg.names, collapse = ","), "\n\n================\n\n"), call. = FALSE)
+    }
+    for(i1 in 1:length(tempo.arg.names)){
+        assign(tempo.arg.names[i1], args[i1])
+    }
+    rm(tempo.arg.names, args, i1)
+}else if(sys.nframe() == 0L){ # detection of copy-paste/direct execution (for debugging). With script it is also 0, with source, it is 4
+    run.way <- "COPY-PASTE"
+    cat(paste0("\n\n", tempo.cat, run.way, "\n"))
+}else{
+    run.way <- "SOURCE" # using source(), sys.nframe() is 4
+    cat(paste0("\n\n", tempo.cat, run.way, "\n"))
+}
+rm(tempo.cat)
+
+
+################################ End Config import
+
+################################ Test
+
+# cat("\n\n!!!!!!!!!!!!!!!!!!! WARNING: test values are activated\n\n")
+# stat <- "C:/Users/Gael/Documents/Git_projects/14985_loot/dataset/test.fastq_Nremove_trim_5pAttc_1-51.stat" 
+# attc_seq <- "CAATTCATTCAAGCCGACGCCGCTTCGCGGCGCGGCTTAATTCAAGCG" 
+# cute <- "https://gitlab.pasteur.fr/gmillot/cute_little_R_functions/-/raw/v10.9.0/cute_little_R_functions.R" 
+# log <- "report.txt"
+
+################################ end Test
+
+################################ Recording of the initial parameters
+
+
+param.list <- c(
+    "erase.objects", 
+    "erase.graphs", 
+    "script", 
+    "run.way",
+    if(run.way == "SCRIPT"){"command"}, 
+    "pos", 
+    "ori_coord", 
+    "ter_coord", 
+    "xlab", 
+    "genome_size", 
+    "file_name", 
+    "cute", 
+    "log"
+)
+if(any(duplicated(param.list))){
+    stop(paste0("\n\n================\n\nINTERNAL CODE ERROR 1 IN plot_insertion.R\nTHE param.list OBJECT CONTAINS DUPLICATED ELEMENTS:\n", paste(param.list[duplicated(param.list)], collapse = " "), "\n\n================\n\n"), call. = FALSE) # message for developers
+}
+if(erase.objects == TRUE){
+    created.object.control <- ls()[ ! ls() %in% "param.list"]
+    if( ! (all(created.object.control %in% param.list) & all(param.list %in% created.object.control))){
+        stop(paste0("\n\n================\n\nINTERNAL CODE ERROR 2 IN plot_insertion.R\nINCONSISTENCIES BETWEEN THE ARGUMENTS USED AND THE PARAMETERS REQUIRED IN THE EXECUTABLE CODE FILE\nTHE ARGUMENTS NOT PRESENT IN THE EXECUTABLE FILE (plot_insertion.R) ARE:\n", paste(created.object.control[ ! created.object.control %in% param.list], collapse = " "), "\nTHE PARAMETERS OF THE EXECUTABLE FILE (plot_insertion.R) NOT PRESENT IN THE ARGUMENTS ARE:\n", paste(param.list[ ! param.list %in% created.object.control], collapse = " "), "\n\n================\n\n"), call. = FALSE) # message for developers
+    }
+}
+char.length <- nchar(param.list)
+space.add <- max(char.length) - char.length + 5
+param.ini.settings <- character(length = length(param.list))
+for(i in 1:length(param.list)){
+    param.ini.settings[i] <- paste0("\n", param.list[i], paste0(rep(" ", space.add[i]), collapse = ""), paste0(get(param.list[i]), collapse = ",")) # no env = sys.nframe(), inherit = FALSE in get() because look for function in the classical scope
+}
+
+
+################################ End Recording of the initial parameters
+
+
+################################ Functions
+
+
+# Functions are built such that they should have no direct use of Global objects (going through the R scope), and only use function arguments
+# 1) Cute little function is sourced for the moment into the .GlobalEnv environment, but may be interesting to put it into a new environement just above .GlobalEnv environment. See https://stackoverflow.com/questions/9002544/how-to-add-functions-in-an-existing-environment
+# 2) Argument names of each function must not be a name of Global objects (error message otherwise)
+# 3) Argument name of each function ends with "_fun" in the first function, "_2fun" in the second, etc. This prevent conflicts with the argument partial names when using these functions, notably when they are imbricated
+
+
+################ import functions from cute little functions toolbox
+
+
+if(length(cute) != 1){
+    stop(paste0("\n\n============\n\nERROR IN plot_insertion.R\ncute PARAMETER MUST BE LENGTH 1: ", paste(cute, collapse = " "), "\n\n============\n\n"), call. = FALSE)
+}else if(grepl(x = cute, pattern = "^http")){
+    tempo.try <- try(suppressWarnings(suppressMessages(source(cute, local = .GlobalEnv))), silent = TRUE)
+    if(any(grepl(x = tempo.try, pattern = "^[Ee]rror"))){
+        stop(paste0("\n\n============\n\nERROR IN plot_insertion.R\nHTTP INDICATED IN THE cute PARAMETER DOES NOT EXISTS: ", cute, "\n\n============\n\n"), call. = FALSE)
+    }else{
+        source(cute, local = .GlobalEnv) # source the fun_ functions used below
+    }
+}else if( ! grepl(x = cute, pattern = "^http")){
+    if( ! file.exists(cute)){
+        stop(paste0("\n\n============\n\nERROR IN plot_insertion.R\nFILE INDICATED IN THE cute PARAMETER DOES NOT EXISTS: ", cute, "\n\n============\n\n"), call. = FALSE)
+    }else{
+        source(cute, local = .GlobalEnv) # source the fun_ functions used below
+    }
+}else{
+    tempo.cat <- paste0("\n\n================\n\nINTERNAL CODE ERROR 3 IN plot_insertion.R: CODE HAS TO BE MODIFIED\n\n============\n\n")
+    stop(tempo.cat, call. = FALSE)
+}
+
+
+# required cute function checking
+req.function <- c(
+    "fun_check",
+    "fun_pack", 
+    "fun_df_remod", 
+    "fun_gg_scatter", 
+    "fun_gg_palette", 
+    "fun_open", 
+    "fun_gg_empty_graph", 
+    "fun_report"
+)
+tempo <- NULL
+for(i1 in req.function){
+    if(length(find(i1, mode = "function")) == 0L){
+        tempo <- c(tempo, i1)
+    }
+}
+if( ! is.null(tempo)){
+    tempo.cat <- paste0("ERROR IN plot_insertion.R\nREQUIRED cute FUNCTION", ifelse(length(tempo) > 1, "S ARE", " IS"), " MISSING IN THE R ENVIRONMENT:\n", paste0(tempo, collapse = "()\n"))
+    stop(paste0("\n\n================\n\n", tempo.cat, "\n\n================\n\n"), call. = FALSE) # == in stop() to be able to add several messages between ==
+}
+# end required function checking
+
+
+################ local function: package import
+
+
+# R Packages required
+req.package.list <- c(
+    "lubridate", 
+    "ggplot2", 
+    "lemon"
+)
+for(i in 1:length(req.package.list)){suppressMessages(library(req.package.list[i], character.only = TRUE))}
+# fun_pack(req.package = req.package.list, load = TRUE, lib.path = NULL) # packages are imported even if inside functions are written as package.name::function() in the present code
+
+
+################################ End Functions
+
+
+################################ Pre-ignition checking
+
+
+# reserved words
+# end reserved words
+# argument primary checking
+arg.check <- NULL #
+text.check <- NULL #
+checked.arg.names <- NULL # for function debbuging: used by r_debugging_tools
+ee <- expression(arg.check <- c(arg.check, tempo$problem) , text.check <- c(text.check, tempo$text) , checked.arg.names <- c(checked.arg.names, tempo$object.name))
+tempo <- fun_check(data = pos, class = "vector", typeof = "character", length = 1) ; eval(ee)
+tempo <- fun_check(data = ori_coord, class = "vector", typeof = "character", length = 1) ; eval(ee)
+tempo <- fun_check(data = ter_coord, class = "vector", typeof = "character", length = 1) ; eval(ee)
+tempo <- fun_check(data = xlab, class = "vector", typeof = "character", length = 1) ; eval(ee)
+tempo <- fun_check(data = genome_size, class = "vector", typeof = "character", length = 1) ; eval(ee)
+tempo <- fun_check(data = file_name, class = "vector", typeof = "character", length = 1) ; eval(ee)
+tempo <- fun_check(data = cute, class = "vector", typeof = "character", length = 1) ; eval(ee)
+tempo <- fun_check(data = log, class = "vector", typeof = "character", length = 1) ; eval(ee)
+if(any(arg.check) == TRUE){ # normally no NA
+    stop(paste0("\n\n================\n\n", paste(text.check[arg.check], collapse = "\n"), "\n\n================\n\n"), call. = FALSE) # == in stop() to be able to add several messages between == #
+}
+# end argument primary checking
+# second round of checking and data preparation
+# management of NA arguments
+# end management of NA arguments
+# management of NULL arguments
+tempo.arg <-c(
+    "pos", 
+    "ori_coord", 
+    "ter_coord", 
+    "xlab", 
+    "genome_size", 
+    "file_name", 
+    "cute", 
+    "log"
+)
+tempo.log <- sapply(lapply(tempo.arg, FUN = get, env = sys.nframe(), inherit = FALSE), FUN = is.null)
+if(any(tempo.log) == TRUE){# normally no NA with is.null()
+    tempo.cat <- paste0("ERROR IN plot_insertion.R:\n", ifelse(sum(tempo.log, na.rm = TRUE) > 1, "THESE ARGUMENTS\n", "THIS ARGUMENT\n"), paste0(tempo.arg[tempo.log], collapse = "\n"),"\nCANNOT BE NULL")
+    stop(paste0("\n\n================\n\n", tempo.cat, "\n\n================\n\n"), call. = FALSE) # == in stop() to be able to add several messages between ==
+}
+# end management of NULL arguments
+# code that protects set.seed() in the global environment
+# end code that protects set.seed() in the global environment
+# warning initiation
+ini.warning.length <- options()$warning.length
+options(warning.length = 8170)
+warn <- NULL
+# warn.count <- 0 # not required
+# end warning initiation
+# other checkings
+
+ori_coord <- strsplit(ori_coord, split = " ")[[1]]
+if(length(ori_coord) != 2 & any(grepl(ori_coord, pattern = "\\D"))){# normally no NA with is.null()
+    tempo.cat <- paste0("ERROR IN plot_insertion.R:\nTHE ori_coord PARAMETER MUST BE TWO INTEGERS SEPARATED BY A SINGLE SPACE\nHERE IT IS: \n", paste0(ori_coord, collapse = " "))
+    stop(paste0("\n\n================\n\n", tempo.cat, "\n\n================\n\n"), call. = FALSE) # == in stop() to be able to add several messages between ==
+}else{
+    ori_coord <- as.integer(ori_coord)
+}
+ter_coord <- strsplit(ter_coord, split = " ")[[1]]
+if(length(ter_coord) != 2 & any(grepl(ter_coord, pattern = "\\D"))){# normally no NA with is.null()
+    tempo.cat <- paste0("ERROR IN plot_insertion.R:\nTHE ter_coord PARAMETER MUST BE TWO INTEGERS SEPARATED BY A SINGLE SPACE\nHERE IT IS: \n", paste0(ter_coord, collapse = " "))
+    stop(paste0("\n\n================\n\n", tempo.cat, "\n\n================\n\n"), call. = FALSE) # == in stop() to be able to add several messages between ==
+}else{
+    ter_coord <- as.integer(ter_coord)
+}
+genome_size <- strsplit(genome_size, split = " ")[[1]]
+if(length(genome_size) != 1 & any(grepl(genome_size, pattern = "\\D"))){# normally no NA with is.null()
+    tempo.cat <- paste0("ERROR IN plot_insertion.R:\nTHE genome_size PARAMETER MUST BE TWO INTEGERS SEPARATED BY A SINGLE SPACE\nHERE IT IS: \n", paste0(genome_size, collapse = " "))
+    stop(paste0("\n\n================\n\n", tempo.cat, "\n\n================\n\n"), call. = FALSE) # == in stop() to be able to add several messages between ==
+}else{
+    genome_size <- as.integer(genome_size)
+}
+
+
+# end other checkings
+# reserved word checking
+# end reserved word checking
+# end second round of checking and data preparation
+# package checking
+# end package checking
+
+
+################################ End pre-ignition checking
+
+
+################################ Main code
+
+
+################ Ignition
+
+
+fun_report(data = paste0("\n\n################################################################ plot_insertion PROCESS\n\n"), output = log, path = "./", overwrite = FALSE)
+ini.date <- Sys.time()
+ini.time <- as.numeric(ini.date) # time of process begin, converted into seconds
+fun_report(data = paste0("\n\n################################ RUNNING DATE AND STARTING TIME\n\n"), output = log, path = "./", overwrite = FALSE)
+fun_report(data = paste0(ini.date, "\n\n"), output = log, path = "./", overwrite = FALSE)
+fun_report(data = paste0("\n\n################################ RUNNING\n\n"), output = log, path = "./", overwrite = FALSE)
+
+
+################ End ignition
+
+
+################ Graphical parameter initialization
+
+
+pdf(file = NULL)
+par.ini <- par(no.readonly = TRUE) # to recover the initial graphical parameters if required (reset)
+invisible(dev.off()) # close the new window
+zone.ini <- matrix(1, ncol=1)
+if(erase.graphs == TRUE){
+    graphics.off()
+}else{
+    tempo.warn <- paste0("GRAPHICS HAVE NOT BEEN ERASED. GRAPHICAL PARAMETERS MAY HAVE NOT BEEN REINITIALIZED")
+    fun_report(data = paste0("WARNING\n", tempo.warn), output = log, path = "./", overwrite = FALSE)
+    warn <- paste0(ifelse(is.null(warn), tempo.warn, paste0(warn, "\n\n", tempo.warn)))
+}
+
+
+################ End graphical parameter initialization
+
+
+################ Data import
+
+
+obs <- read.table(pos, stringsAsFactors = FALSE) # does not take the header
+
+
+################ end Data import
+
+
+############ modifications of imported tables
+
+
+names(obs) <- c("orient", "pos")
+obs <- obs[2:1]
+
+# ori and ter prep
+ori_center <- mean(ori_coord, na.rm = TRUE)
+ter_center <- mean(ter_coord, na.rm = TRUE)
+# leading and lagging
+obs <- data.frame(obs, fork = obs$orient, stringsAsFactors = TRUE)
+if(ter_center > ori_center){
+    obs$fork[obs$pos < ori_center | obs$pos > ter_center] <- abs(obs$fork[obs$pos < ori_center | obs$pos > ter_center] - 16) # left of the Ori and right of the dif (dif > ori) is switch 0 -> 16 and 16 -> 0 to have the leading and lagging
+}else{
+    obs$fork[obs$pos <= ori_center & obs$pos >= ter_center] <- abs(obs$fork[obs$pos <= ori_center & obs$pos >= ter_center] - 16) # right of the Ori and left of the dif (dif < ori) is switch 0 -> 16 and 16 -> 0 to have the leading and lagging
+}
+obs$fork<- factor(obs$fork, levels = c(0, 16), labels = c("LEADING", "LAGGING"))
+obs <- data.frame(seq = "obs", pos = obs$pos, names = paste(obs$fork, obs$orient, sep = "_"), fork = obs$fork, orient = obs$orient)
+obs$orient[obs$orient == 0] <- "FORWARD"
+obs$orient[obs$orient == 16] <- "REVERSE"
+fun_report(data = head(obs), output = log, path = "./", overwrite = FALSE)
+fun_report(data = paste0("\nNUMBER OF OBS POSITIONS:\n", format(nrow(obs), big.mark=",")), output = log, path = "./", overwrite = FALSE)
+
+
+# saving position file
+options(scipen = 1000) # to avoid writing of scientific numbers in tables, see https://stackoverflow.com/questions/3978266/number-format-writing-1e-5-instead-of-0-00001
+write.table(obs, file = paste0("./", file_name, "_annot.pos"), row.names = FALSE, col.names = TRUE, append = FALSE, quote = FALSE, sep = "\t")
+options(scipen = 0)
+
+
+# freq file
+res <- aggregate(x = obs$pos, by = list(seq = obs$seq, pos = obs$pos, names = obs$names, fork = obs$fork, orient = obs$orient), FUN = length)
+names(res)[names(res) == "x"] <- "freq"
+options(scipen = 1000) # to avoid writing of scientific numbers in tables, see https://stackoverflow.com/questions/3978266/number-format-writing-1e-5-instead-of-0-00001
+write.table(res, file = paste0("./", file_name, "_annot_insertion.freq"), row.names = FALSE, col.names = TRUE, append = FALSE, quote = FALSE, sep = "\t")
+options(scipen = 0)
+
+
+tempo <- max(res$freq) + 20
+ori <- data.frame(x= c(ori_coord[1], ori_coord[1], ori_coord[2], ori_coord[2], ori_coord[1]), y = c(-tempo, tempo, tempo, -tempo ,-tempo), ZONE = "Ori", stringsAsFactors = TRUE)
+dif <- data.frame(x= c(ter_coord[1], ter_coord[1], ter_coord[2], ter_coord[2], ter_coord[1]), y = c(-tempo, tempo, tempo, -tempo ,-tempo), ZONE = "Ter", stringsAsFactors = TRUE)
+structure <- rbind(ori, dif, stringsAsFactors = TRUE)
+
+
+
+############ end modifications of imported tables
+
+
+############ plotting
+
+
+# fun_open(width = 12, height = 4, pdf.name = "plot_fivep_filtering_stat") # must be systematically opened for main.nf
+png(filename = paste0("plot_", file_name, "_insertion_raw.png"), width = 5000, height = 1800, units = "px", res = 300)
+
+if(ncol(obs) > 0){
+    tempo <- res
+    tempo$freq[tempo$orient == "REVERSE"] <- tempo$freq[tempo$orient == "REVERSE"] * -1
+    fun_gg_scatter(
+        data1 = list(structure, tempo), # res # res[res$KIND == "obs", ]
+        x = list("x", "pos"), 
+        y = list("y", "freq"), 
+        categ = list("ZONE", NULL), 
+        geom = list("geom_step", "geom_stick"), 
+        geom.stick.base = 0, 
+        color = list(c("black", "brown"), fun_gg_palette(n = 2)[1]), # fun_gg_palette(n = 2) # fun_gg_palette(n = 2)[1]
+        legend.width = NULL, 
+        title = "RAW", 
+        x.lim = c(0, genome_size), 
+        x.lab = xlab, 
+        x.left.extra.margin = 0, 
+        x.right.extra.margin = 0, 
+        x.second.tick.nb = 4, 
+        y.lab = "Insertion frequency\n<- reverse    forward ->", 
+        y.second.tick.nb = 4, 
+        text.size = 24, 
+        title.text.size = 16
+    )
+}else{
+    fun_gg_empty_graph(text = "EMPTY .freq FILE: NO PLOT DRAWN")
+}
+
+
+############ end plotting
+
+
+################ Pdf window closing
+
+
+graphics.off()
+
+
+################ end Pdf window closing
+
+
+################ Seeding inactivation
+
+
+set.seed(NULL)
+
+
+################ end Seeding inactivation
+
+
+################ Environment saving
+
+
+save(list = ls(), file = "all_objects.RData")
+fun_report(data = paste0("\n\n################################ RUNNING END"), output = log, path = "./", overwrite = FALSE)
+end.date <- Sys.time()
+end.time <- as.numeric(end.date)
+total.lapse <- round(lubridate::seconds_to_period(end.time - ini.time))
+fun_report(data = paste0("\n\nEND TIME: ", end.date), output = log, path = "./", overwrite = FALSE)
+fun_report(data = paste0("\n\nTOTAL TIME LAPSE: ", total.lapse), output = log, path = "./", overwrite = FALSE)
+fun_report(data = paste0("\n\nALL DATA SAVED IN all_objects.RData"), output = log, path = "./", overwrite = FALSE)
+
+
+################ end Environment saving
+
+
+################ Warning messages
+
+
+fun_report(data = paste0("\n\n################################ RECAPITULATION OF WARNING MESSAGES"), output = log, path = "./", overwrite = FALSE)
+if( ! is.null(warn)){
+    fun_report(data = paste0("\n\n", warn), output = log, path = "./", overwrite = FALSE)
+}else{
+    fun_report(data = paste0("\n\nNO WARNING MESSAGE TO REPORT"), output = log, path = "./", overwrite = FALSE)
+}
+
+
+################ end Warning messages
+
+
+################ Parameter printing
+
+
+fun_report(data = paste0("\n\n################################ INITIAL SETTINGS OF PARAMETERS"), output = log, path = "./", overwrite = FALSE)
+fun_report(data = param.ini.settings, output = log, path = "./", overwrite = FALSE, , vector.cat = TRUE)
+fun_report(data = paste0("\n\n################################ R SYSTEM AND PACKAGES"), output = log, path = "./", overwrite = FALSE)
+tempo <- sessionInfo()
+tempo$otherPkgs <- tempo$otherPkgs[order(names(tempo$otherPkgs))] # sort the packages
+tempo$loadedOnly <- tempo$loadedOnly[order(names(tempo$loadedOnly))] # sort the packages
+fun_report(data = tempo, output = log, path = "./", overwrite = FALSE, , vector.cat = TRUE)
+fun_report(data = paste0("\n\n################################ JOB END\n\nTIME: ", end.date, "\n\nTOTAL TIME LAPSE: ", total.lapse, "\n"), output = log, path = "./", overwrite = FALSE)
+
+
+################ end Parameter printing
+
+
+################################ End Main code
+
+
+
+
+
+
+
diff --git a/dev/test.config b/dev/test.config
index 1acb108f8097a47b48898c9ab2cf6c39c4f97520..95dc50631212d313f6eff1e63f91ccd40904e36d 100755
--- a/dev/test.config
+++ b/dev/test.config
@@ -49,8 +49,8 @@ env {
     ori_coord="2320711 2320942" // [2320711, 2320942] // Ecoli centered coordinates
     ter_coord="4627368 4627400" //[4627368, 4627400] // Ecoli centered coordinates
     color_coverage="5" // three integers for the color of the three coverage plots[1, 2, 5]
-    ref_name="Ecoli Genome (bp)" // name of the reference genome for graphics
-
+    xlab="Ecoli Genome (bp)" // name of the reference genome for graphics
+    genome_size="4641652" // in bp
     cute_path="https://gitlab.pasteur.fr/gmillot/cute_little_R_functions/-/raw/v10.9.0/cute_little_R_functions.R" // single character string indicating the file (and absolute pathway) of the required cute_little_R_functions toolbox. With ethernet connection available, this can also be used: "https://gitlab.pasteur.fr/gmillot/cute_little_R_functions/raw/v5.1.0/cute_little_R_functions.R" or local "C:\\Users\\Gael\\Documents\\Git_projects\\cute_little_R_functions\\cute_little_R_functions.R"
 }
 
@@ -136,13 +136,12 @@ timeline {
     file = "${out_path}/reports/nf_timeline.html"
 }
 
-// .dot picture of the workflow
+// .dot picture of the workflow. Only one file allowed
 dag {
     enabled = true
-    file = "${out_path}/reports/nf_dag.dot"
+    file = "${out_path}/reports/nf_dag.png" // Warning: require graphviz installed in the system, see protocol 136
 }
 
-
 // define singularity parameters
 singularity {
     enabled = true
@@ -167,6 +166,9 @@ process {
         scratch=false
         maxRetries=1
         errorStrategy='retry'
+    }else{
+        maxRetries=0
+        errorStrategy='terminate'
     }
     // all the processes of the main.nf file with the label 'bedtools' will use this directives by default
     withLabel: bash {
@@ -176,7 +178,7 @@ process {
     }
 
     withLabel: alien_trimmer {
-        container='gmillot/alien_trimmer_v0.4.0:gitlab_v5.1' // no most recent at 20210930
+        container='gmillot/alien_trimmer_v0.4.0:gitlab_v8.1' // no most recent at 20210930
         cpus=1 // only used when name = "local" in the executor part above
         memory='3G' // only used when name = "local" in the executor part above
     }
diff --git a/main.nf b/main.nf
index 6c2e7ea2b2f88114138e6975fb8968428c3177ee..b033be457f11d98105a90927d16a0167af1800ef 100755
--- a/main.nf
+++ b/main.nf
@@ -51,12 +51,14 @@ fivep_seq_filtering_ch = Channel.from("${fivep_seq_filtering}")
 fivep_seq_nb_ch = Channel.from("${fivep_seq_nb}")
 added_nb_ch = Channel.from("${added_nb}")
 sum_ch = Channel.from("${fivep_seq_nb}", "${added_nb}").toInteger().sum()
-Channel.from("${cute_path}").into{cute_ch1 ; cute_ch2 ; cute_ch3 ; cute_ch4 ; cute_ch5 ; cute_ch6}
+Channel.from("${cute_path}").into{cute_ch1 ; cute_ch2 ; cute_ch3 ; cute_ch4 ; cute_ch5 ; cute_ch6 ; cute_ch7 ; cute_ch8 ; cute_ch9}
 cutoff_nb_ch = Channel.from("${cutoff_nb}")
 Channel.from("${ori_coord}").into{ori_coord_ch1 ; ori_coord_ch2}
 Channel.from("${ter_coord}").into{ter_coord_ch1 ; ter_coord_ch2}
 Channel.from("${color_coverage}").into{color_coverage_ch1 ; color_coverage_ch2}
+Channel.from("${xlab}").into{xlab_ch1 ; xlab_ch2}
 Channel.from("${ref_name}").into{ref_name_ch1 ; ref_name_ch2}
+Channel.from("${genome_size}").into{genome_size_ch1 ; genome_size_ch2}
 
 //////// end Channels
 
@@ -473,8 +475,8 @@ process Q20 { // section 24.2 of the labbook 20200707
     samtools view -q 20 -b ${bam} > ${file_name}_q20.bam |& tee q20_report.txt
     samtools index ${file_name}_q20.bam
     echo -e "<br /><br />\\n\\n###  Q20 filtering\\n\\n" >> report.rmd
-    read_nb_before=\$(samtools view -h ${bam} | wc -l) # -h to remove the header
-    read_nb_after=\$(samtools view -h ${bam.baseName}_q20.bam | wc -l) # -h to remove the header
+    read_nb_before=\$(samtools view ${bam} | wc -l | cut -f1 -d' ') # -h to add the header
+    read_nb_after=\$(samtools view ${file_name}_q20.bam | wc -l | cut -f1 -d' ') # -h to add the header
     echo -e "\\n\\nNumber of sequences before Q20 filtering: \$(printf "%'d" \${read_nb_before})\\n" >> report.rmd
     echo -e "\\n\\nNumber of sequences after Q20 filtering: \$(printf "%'d" \${read_nb_after})\\n" >> report.rmd
     echo -e "Ratio: " >> report.rmd
@@ -500,8 +502,8 @@ process no_soft_clipping { // section 24.4 of the labbook 20200707
     script:
     """
     echo -e "<br /><br />\\n\\n###  Control that no more soft clipping in reads\\n\\n" >> report.rmd
-    echo -e "nb of reads with soft clipping (S) in CIGAR: \$(printf "%'d" \$(samtools view ${bam} | awk '\$6 ~ /.*[S].*/{print \$0}' | wc -l))" >> report.rmd
-    echo -e "\\n\\ntotal nb of reads: \$(printf "%'d" \$(samtools view ${bam} | wc -l))" >> report.rmd
+    echo -e "nb of reads with soft clipping (S) in CIGAR: \$(printf "%'d" \$(samtools view ${bam} | awk '\$6 ~ /.*[S].*/{print \$0}' | wc -l | cut -f1 -d' '))" >> report.rmd
+    echo -e "\\n\\ntotal nb of reads: \$(printf "%'d" \$(samtools view ${bam} | wc -l | cut -f1 -d' '))" >> report.rmd
     """
 }
 
@@ -519,7 +521,7 @@ process duplicate_removal { // section 24.5 of the labbook 20200707. Warning: US
     file "report.rmd" from log_ch13
 
     output:
-    file "${file_name}_q20_nodup.bam" into dup_ch
+    file "${file_name}_q20_nodup.bam" into dup_ch1, dup_ch2
     file "dup_read_nb" into dup_read_nb_ch
     file "dup_report.txt"
     file "report.rmd" into log_ch14
@@ -547,14 +549,13 @@ process report1 {
     script:
     """
     echo -e '
-<br /><br />\\n\\n###  Read coverage\\n\\n
-<br /><br />Of note: process is parallelized at that stage (three channels).
-<center>
-![Figure 4: After Bowtie2 alignment](./figures/${file_name}_bowtie2_mini.png){width=600}
+<br /><br />\\n\\n###  Read coverage\\n\\nOf note: process is parallelized at that stage (three channels).
+<br /><br /><center>
+![Figure 4: After Bowtie2 alignment](./figures/plot_${file_name}_bowtie2_mini.png){width=600}
 </center><br /><br /><center>
-![Figure 5: After Mapping Quality Q20 (1%) filtering](./figures/${file_name}_q20_mini.png){width=600}
+![Figure 5: After Mapping Quality Q20 (1%) filtering](./figures/plot_${file_name}_q20_mini.png){width=600}
 </center><br /><br /><center>
-![Figure 6: After removal of reads with identical 5\' and 3\' coordinates](./figures/${file_name}_q20_nodup_mini.png){width=600}
+![Figure 6: After removal of reads with identical 5\' and 3\' coordinates](./figures/plot_${file_name}_q20_nodup_mini.png){width=600}
 </center>
     ' >> report.rmd
     """
@@ -568,12 +569,12 @@ process coverage { // section 24.5 of the labbook 20200707. Warning: USING 5' AN
     cache 'true'
 
     input:
-    file bam from bowtie2_ch2.concat(q20_ch3, dup_ch)
+    file bam from bowtie2_ch2.concat(q20_ch3, dup_ch1)
     // file "report.rmd" from log_ch14.first() //
     // file ref from ref_ch3 // not required because bedtools genomecov-g ${ref} not required when inputs are bam files
 
     output:
-    file "*_mini.cov" into cov_ch // warning several files
+    file "*_mini.cov" into cov_ch // warning: several files
     // file "*.cov" // coverage per base if ever required but long process
     // file "report.rmd" into log_ch15.first() // warning several files
     file "cov_report.txt" into cov_report_ch
@@ -593,7 +594,7 @@ cov_report_ch.collectFile(name: "cov_report.txt").subscribe{it -> it.copyTo("${o
 
 
 
-process plot_coverage { // section 8.17 of the labbook 20200520
+process plot_coverage { // section 24.6 of the labbook 20200707
     label 'r_ext' // see the withLabel: bash in the nextflow config file 
     publishDir "${out_path}/figures", mode: 'copy', pattern: "{*.png}", overwrite: false // https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob
     // publishDir "${out_path}/reports", mode: 'copy', pattern: "{plot_coverage_report.txt}", overwrite: false // 
@@ -601,32 +602,117 @@ process plot_coverage { // section 8.17 of the labbook 20200520
 
     input:
     val file_name
-    file cov from cov_ch
-    //file read_nb from bow_read_nb_ch.concat(q20_read_nb_ch, dup_read_nb_ch)
-    val ori_coord from ori_coord_ch1
-    val ter_coord from ter_coord_ch1
-    val color_coverage from color_coverage_ch1
-    val ref_name from ref_name_ch1
-    val cute from cute_ch5
+    file cov from cov_ch // warning: several files
+    file read_nb from bow_read_nb_ch.concat(q20_read_nb_ch, dup_read_nb_ch)
+    val ori_coord from ori_coord_ch1.first()
+    val ter_coord from ter_coord_ch1.first()
+    val color_coverage from color_coverage_ch1.first()
+    val xlab from xlab_ch1.first()
+    val cute from cute_ch5.first()
     // file "report.rmd" from log_ch15
 
     output:
-    file "${cov.baseName}.png" into fig_ch5
+    file "plot_${cov.baseName}.png" into fig_ch5 // warning: several files
     file "plot_coverage_report.txt" into plot_cov_report_ch
 
     script:
     """
-    Rscript $workflow.projectDir/bin/plot_coverage.R "${cov.baseName}" "10000" "${ori_coord}" "${ter_coord}" "${color_coverage}" "${ref_name}" "${file_name}" "${cute}" "plot_coverage_report.txt"
+    Rscript $workflow.projectDir/bin/plot_coverage.R "${cov.baseName}" "${read_nb}" "${ori_coord}" "${ter_coord}" "${color_coverage}" "${xlab}" "${file_name}" "${cute}" "plot_coverage_report.txt"
     """
     // single quotes required because of the !
 }
 
 
-
 plot_cov_report_ch.collectFile(name: "plot_cov_report.txt").subscribe{it -> it.copyTo("${out_path}/reports")} // concatenate all the cov_report.txt files in channel cov_report_ch into a single file published into 
 
 
 
+process insertion { // section 24.7 of the labbook 20200707
+    label 'samtools' // see the withLabel: bash in the nextflow config file 
+    publishDir "${out_path}/reports", mode: 'copy', pattern: "insertion_report.txt", overwrite: false
+    // publishDir "${out_path}/files", mode: 'copy', pattern: "${file_name}_q20_nodup.bam", overwrite: false // 
+    cache 'true'
+
+    input:
+    val file_name
+    file bam from dup_ch2
+    file "report.rmd" from log_ch15
+
+    output:
+    file "${file_name}.pos" into orient_ch1, orient_ch2
+    file "insertion_report.txt"
+    file "report.rmd" into log_ch16
+
+    script:
+    """
+    echo -e "<br /><br />\\n\\n### Insertion positions\\n\\n" >> report.rmd
+    echo -e "\\n\\nOne of the step is to correct insertion site read extremity for the reverse reads. It Consist in the redefinition of POS according to FLAG. See the [insertion_report.txt](./reports/insertion_report.txt) file in the reports folders for details\\n\\n" >> report.rmd
+    # extraction of bam column 2, 4 and 10, i.e., FALG, POS and SEQ
+    samtools view ${bam} | awk 'BEGIN{FS="\\t" ; OFS="" ; ORS=""}{print ">"\$2"\\t"\$4"\\n"\$10"\\n" }' > tempo
+    # Of note, samtools fasta \$DIR/\$SAMPLE_NAME > \${OUTPUT}.fasta # convert bam into fasta
+    echo -e "\\n\\nExtraction of the FLAG (containing the read orientation) the POS and the SEQ of the bams\\nHeader is the 1) sens of insersion (0 or 16) and 2) insertion site position\\n\\n" >> insertion_report.txt
+    cat tempo | head -60 | tail -20 >> insertion_report.txt
+    # redefinition of POS according to FLAG
+    awk 'BEGIN{FS="\t" ; OFS="" ; ORS=""}{lineKind=(NR-1)%2}lineKind==0{orient=(\$1~">16") ; if(orient){var1 = \$1 ; var2 = \$2}else{print \$0"\\n"}}lineKind==1{if(orient){var3 = length(\$0) ; var4 = var2 + var3 - 1 ; print var1"\\t"var4"\\n"\$0"\\n"}else{print \$0"\\n"}}' tempo > ${file_name}_reorient.fasta
+    echo -e "\\n\\nFinal fasta file\\n\\n" >> insertion_report.txt
+    cat ${file_name}_reorient.fasta | head -60 | tail -20 >> insertion_report.txt
+    awk '{lineKind=(NR-1)%2}lineKind==0{gsub(/>/, "", \$1) ; print \$0}' ${file_name}_reorient.fasta > ${file_name}.pos
+    echo -e "\\n\\nFinal pos file\\n\\n" >> insertion_report.txt
+    cat ${file_name}.pos | head -60 | tail -20 >> insertion_report.txt
+
+    read_nb_before=\$(samtools view ${bam} | wc -l | cut -f1 -d' ') # -h to add the header. Thus do not put here
+    read_nb_after=\$(wc -l ${file_name}.pos | cut -f1 -d' ')
+    echo -e "\\n\\nNumber of reads used for insertion computation: \$(printf "%'d" \${read_nb_before})\\n" >> report.rmd
+    echo -e "\\n\\nNumber of insertions: \$(printf "%'d" \${read_nb_after})\\n" >> report.rmd
+    echo -e "Ratio: " >> report.rmd
+    echo -e \$(printf "%.2f\n" \$(echo \$" \$read_nb_after / \$read_nb_before " | bc -l)) >> report.rmd # the number in '%.2f\\n' is the number of decimals
+    echo -e "\\n\\n" >> report.rmd
+    """
+}
+
+
+
+process plot_insertion { // sections 24.7.2, 44.1 and 45.1 of the labbook 20200520
+    label 'r_ext' // see the withLabel: bash in the nextflow config file 
+    publishDir "${out_path}/figures", mode: 'copy', pattern: "{*.png}", overwrite: false // https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob
+    publishDir "${out_path}/files", mode: 'copy', pattern: "{*.pos,*.freq}", overwrite: false // 
+    publishDir "${out_path}/reports", mode: 'copy', pattern: "{plot_insertion_report.txt}", overwrite: false // 
+    cache 'true'
+
+    input:
+    val file_name
+    file pos from orient_ch1
+    file "report.rmd" from log_ch16
+    val ori_coord from ori_coord_ch2
+    val ter_coord from ter_coord_ch2
+    val xlab from xlab_ch2
+    val genome_size from genome_size_ch1
+    val cute from cute_ch7
+
+    output:
+    file "*.png" into fig_ch6
+    file "${file_name}_annot.pos" into annot_pos_ch1
+    file "${file_name}_annot_insertion.freq" into insertion_freq_ch1
+    file "plot_insertion_report.txt"
+    file "report.rmd" into log_ch17
+
+    script:
+    """
+    echo -e "<br /><br />\\n\\n###  Insertion plots\\n\\n" >> report.rmd
+    Rscript $workflow.projectDir/bin/plot_insertion.R "${pos}" "${ori_coord}" "${ter_coord}" "${xlab}" "${genome_size}" "${file_name}" "${cute}" "plot_insertion_report.txt"
+    pos_nb=\$(wc -l ${file_name}.pos | cut -f1 -d' ')
+    echo -e "\\n\\nNumber of different positions: \$(printf "%'d" \${pos_nb})\\n" >> report.rmd
+    echo -e "\\n\\nSee the CL Labbook section 24.7.3 to explain the limitation around 100 bp\\n" >> report.rmd
+    echo -e '
+<br /><br /><center>
+![Figure 3: Frequency of insertion according to chromosome position.](./figures/plot_${file_name}_insertion_raw.png){width=600}
+</center><br /><br />
+    ' >> report.rmd
+    """
+    // single quotes required because of the !
+}
+
+
 
 process backup {
     label 'bash' // see the withLabel: bash in the nextflow config file 
@@ -636,18 +722,18 @@ process backup {
     input:
     file config_file
     file log_file
-    file "report.rmd" from log_ch15
+    file "report.rmd" from log_ch17
 
     output:
     file "${config_file}" // warning message if we use file config_file
     file "${log_file}" // warning message if we use file log_file
-    file "report.rmd" into log_ch16
+    file "report.rmd" into log_ch18
 
     script:
     """
     echo -e "<br /><br />\n\n###  Backup\n\n" >> report.rmd
-    echo -e "See the reports folder for all the details of the analysis, including the parameters used in the .config file" >> report.rmd
-    echo -e "<br /><br />Full .nextflow.log is in: ${launchDir}<br />The one in the result folder is not complete (miss the end)" >> report.rmd
+    echo -e "See the [reports](./reports) folder for all the details of the analysis, including the parameters used in the .config file" >> report.rmd
+    echo -e "<br /><br />Full .nextflow.log is in: ${launchDir}<br />The one in the [reports](./reports) folder is not complete (miss the end)" >> report.rmd
     """
 }
 
@@ -657,10 +743,10 @@ process workflowVersion { // create a file with the workflow version in out_path
     cache 'false'
 
     input:
-    file "report.rmd" from log_ch16
+    file "report.rmd" from log_ch18
 
     output:
-    file "report.rmd" into log_ch17
+    file "report.rmd" into log_ch19
 
     script:
     """
@@ -678,6 +764,7 @@ process workflowVersion { // create a file with the workflow version in out_path
     echo "<br />nextflow version: ${nextflow.version}" >> report.rmd
     echo -e "<br /><br />\\n\\nIMPLICIT VARIABLES:\\n\\nlaunchDir (directory where the workflow is run): ${launchDir}<br />\\nprojectDir (directory where the main.nf script is located): ${projectDir}<br />\\nworkDir (directory where tasks temporary files are created): ${workDir}" >> report.rmd
     echo -e "<br /><br />\\n\\nUSER VARIABLES:<br />\\n\\nout_path: ${out_path}<br />\\nin_path: ${in_path}" >> report.rmd
+    echo -e "<br /><br />\\n\\nWORKFLOW DIAGRAM:<br />\\n\\nSee the [nf_dag.png](./reports/nf_dag.png) file" >> report.rmd
     """
 }
 //${projectDir} nextflow variable
@@ -693,14 +780,16 @@ process print_report { // section 8.8 of the labbook 20200520
     cache 'false'
 
     input:
+    val file_name
     val cute from cute_ch6
-    file "tempo_report" from log_ch17
+    file "tempo_report" from log_ch19
     tuple val ("stat_tempo_name"), file ("stat_tempo") from stat_fastq_5p_filter_ch2
     file "plot_fivep_filtering_stat" from fig_ch1
-    file "plot_read_length_ini" from fig_ch2
+    file "plot_read_length_ini" from fig_ch2.first()
     file "plot_read_length_fivep_filtering" from fig_ch3
     file "plot_read_length_cutoff" from fig_ch4
-    file "plot_coverage" from fig_ch5
+    file png from fig_ch5.collect() // warning: several files
+    file png2 from fig_ch6.collect() // warning: several files
 
     output:
     file "report.html"
@@ -712,11 +801,15 @@ process print_report { // section 8.8 of the labbook 20200520
     cp tempo_report report.rmd # this is to get hard files, not symlinks
     mkdir figures
     mkdir files
+    mkdir reports
     cat ${stat_tempo} > ./files/${stat_tempo_name} # this is to get hard files, not symlinks
     cp ${plot_fivep_filtering_stat} ./figures/plot_fivep_filtering_stat.png # also works: cat ${plot_fivep_filtering_stat} > ./figures/plot_fivep_filtering_stat.png
     cp ${plot_read_length_ini} ./figures/plot_read_length_ini.png
     cp ${plot_read_length_fivep_filtering} ./figures/plot_read_length_fivep_filtering.png
     cp ${plot_read_length_cutoff} ./figures/plot_read_length_cutoff.png
+    cp ${png} ./figures/ # Warning several files are copied using their initial names, i.e., the names they have in each work folders of the plot_coverage process
+    cp ${png2} ./figures/ # Warning several files
+    cp ${plot_read_length_cutoff} ./reports/nf_dag.png # trick to delude the knitting during the print report
     Rscript $workflow.projectDir/bin/print_report.R "${cute}" "report.rmd" "print_report.txt"
     """
 }
diff --git a/nextflow.config b/nextflow.config
index fee7c0833c5463abb43da24aa613281e3cad83c0..76191b264315bac9182cc14c7be3eca03a23d851 100755
--- a/nextflow.config
+++ b/nextflow.config
@@ -22,11 +22,11 @@ env {
     git_path="https://gitlab.pasteur.fr/gmillot/14985_loot/"
     //in_path="/mnt/c/Users/Gael/Documents/Git_projects/14985_loot/dataset"
     //in_path="/mnt/share/14985_loot/dataset/B2699/00_Rawdata"
-    in_path="/pasteur/zeus/projets/p01/BioIT/gmillot/14985_loot/dataset/B4985/4" // where initial fastq file is
-    //in_path="/pasteur/zeus/projets/p01/BioIT/gmillot/14985_loot/dataset/B2699/00_Rawdata" // where initial fastq file is
+    //in_path="/pasteur/zeus/projets/p01/BioIT/gmillot/14985_loot/dataset/B4985/4" // where initial fastq file is
+    in_path="/pasteur/zeus/projets/p01/BioIT/gmillot/14985_loot/dataset/B2699/00_Rawdata" // where initial fastq file is
     //fastq_file="test.fastq.gz" // fastq file name
-    //fastq_file="Pool-B2699_S1_L001_R1_001.fastq.gz"
-    fastq_file="4-4_S1_L001_R1_001.fastq.gz"
+    fastq_file="Pool-B2699_S1_L001_R1_001.fastq.gz"
+    //fastq_file="4-4_S1_L001_R1_001.fastq.gz"
     //primer_fasta="/mnt/c/Users/Gael/Documents/Git_projects/14985_loot/dataset/20200520_adapters_TruSeq_B2699_14985_CL.fasta"
     primer_fasta="/pasteur/zeus/projets/p01/BioIT/gmillot/14985_loot/results/20200520_res_CL14985_newtrim_align/20200520_adapters_TruSeq_B2699_14985_CL.fasta" // list of primers used for the library and used by Alien trimmer to trim the raw reads
     //primer_fasta="/mnt/share/14985_loot/results/20200520_res_CL14985_newtrim_align/20200520_adapters_TruSeq_B2699_14985_CL.fasta"
@@ -52,8 +52,8 @@ env {
     ori_coord="2320711 2320942" // [2320711, 2320942] // Ecoli centered coordinates
     ter_coord="4627368 4627400" //[4627368, 4627400] // Ecoli centered coordinates
     color_coverage="5" // three integers for the color of the three coverage plots[1, 2, 5]
-    ref_name="Ecoli Genome (bp)" // name of the reference genome for graphics
-
+    xlab="Ecoli Genome (bp)" // name of the reference genome for graphics
+    genome_size="4641652" // in bp
     cute_path="https://gitlab.pasteur.fr/gmillot/cute_little_R_functions/-/raw/v10.9.0/cute_little_R_functions.R" // single character string indicating the file (and absolute pathway) of the required cute_little_R_functions toolbox. With ethernet connection available, this can also be used: "https://gitlab.pasteur.fr/gmillot/cute_little_R_functions/raw/v5.1.0/cute_little_R_functions.R" or local "C:\\Users\\Gael\\Documents\\Git_projects\\cute_little_R_functions\\cute_little_R_functions.R"
 }
 
@@ -72,7 +72,7 @@ out_path="/pasteur/zeus/projets/p01/BioIT/gmillot/14985_loot/results" // where t
 //// end must be also exported
 
 //// general variables
-result_folder_name="20220107_res_CL14985_test"
+result_folder_name="20220120_res_CL14985_test"
 //// end general variables
 
 //// slurm variables
@@ -139,10 +139,10 @@ timeline {
     file = "${out_path}/reports/nf_timeline.html"
 }
 
-// .dot picture of the workflow
+// .dot picture of the workflow. Only one file allowed
 dag {
     enabled = true
-    file = "${out_path}/reports/nf_dag.dot"
+    file = "${out_path}/reports/nf_dag.png" // Warning: require graphviz installed in the system, see protocol 136
 }
 
 
@@ -171,6 +171,9 @@ process {
         scratch=false
         maxRetries=1
         errorStrategy='retry'
+    }else{
+        maxRetries=0
+        errorStrategy='terminate'
     }
     // all the processes of the main.nf file with the label 'bedtools' will use this directives by default
     withLabel: bash {
@@ -180,7 +183,7 @@ process {
     }
 
     withLabel: alien_trimmer {
-        container='gmillot/alien_trimmer_v0.4.0:gitlab_v5.1' // no most recent at 20210930
+        container='gmillot/alien_trimmer_v0.4.0:gitlab_v8.1' // no most recent at 20210930
         cpus=1 // only used when name = "local" in the executor part above
         memory='3G' // only used when name = "local" in the executor part above
     }
@@ -222,37 +225,6 @@ process {
         memory='64G'
     }
 
-
-
-
-
-
-
-
-    withLabel: gatk {
-        //scratch=true
-        container='broadinstitute/gatk:4.1.9.0'
-        memory='60G'
-        if(system_exec == 'slurm'){
-            queue = {task.attempt>1 ? "$normalqueue" : "$fastqueue" }
-            clusterOptions = {task.attempt > 1 ? "$normalqos $add_options" : "$fastqos $add_options" }
-        }
-    }
-
-    withLabel: bwa {
-        container="evolbioinfo/bwa:v0.7.17"
-	    cpus=20
-        memory='30G'
-    }
-
-    withLabel: bcftools {
-        container="evolbioinfo/bcftools:f27f849"
-        cpus=1
-        memory='10G'
-    }
-
-
-
 }
 
 //////// end directives
\ No newline at end of file