diff --git a/scripts/compare_results/fullTable_heatmap_external_metrics.R b/scripts/compare_results/fullTable_heatmap_external_metrics.R index 3767a8f2e5d2f82a92871e55c9df9fa92f3e656e..65c5e6e491191a936d236cd8e81e1f23e935580b 100644 --- a/scripts/compare_results/fullTable_heatmap_external_metrics.R +++ b/scripts/compare_results/fullTable_heatmap_external_metrics.R @@ -1,142 +1,144 @@ -#!/usr/bin/env Rscript - -suppressMessages(library(dplyr)) -suppressMessages(library(formattable)) - -fullTableOfStats<-read.table(file = snakemake@input[[1]], sep = "", header = TRUE, row.names=NULL, check.names = FALSE) - -fullTableOfStats$Gaps_per_Gb <- ((fullTableOfStats$Gaps / fullTableOfStats$Total_bp) *1000000000) -fullTableOfStats$Gaps_per_Gb <- as.integer(fullTableOfStats$Gaps_per_Gb) - - -customPurple='#c699e8' -customGreen='#8fc773' - -selectionOfStats_colouredHeatmap <- fullTableOfStats %>% - select(c('ASM_ID', - 'Gaps_per_Gb', 'Scaf_N50', - 'Cont_N50','qv', - 'Kmer_Compl', "Comp_Single_BUSCOs_%" = BUSCO_S)) %>% - mutate("Comp_Single_BUSCOs_%" = as.numeric(sub("%", "", as.character(`Comp_Single_BUSCOs_%`)))) - -sink(file = snakemake@output[[1]]) - - -format_table(selectionOfStats_colouredHeatmap, - align =c("l","c","c","c","c", "c", "c", "c", "c"), - list(Gaps_per_Gb = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - `background-color` = ifelse(between(Gaps_per_Gb,1001, 10000), "#FFCC99", - ifelse(between(Gaps_per_Gb,201 , 1000), customGreen, - ifelse(Gaps_per_Gb <= 200, customPurple, "#FF9999"))))), - Scaf_N50 = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - `background-color` = ifelse(between(Scaf_N50,0.1, 9.99999), "#FFCC99", - ifelse(between(Scaf_N50,10, 99.99999), customGreen, - ifelse(Scaf_N50 >= 100, customPurple, "#FF9999"))))), - Scaf_L50 = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - `background-color` = ifelse(between(Scaf_L50,0.1, 9.99999), "#FFCC99", - ifelse(between(Scaf_L50,10, 99.99999), customGreen, - ifelse(Scaf_L50 >= 100, customPurple, "#FF9999"))))), - Cont_N50 = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - `background-color` = ifelse(between(Cont_N50,0.01, 0.99999), "#FFCC99", - ifelse(between(Cont_N50,1, 9.999999), customGreen, - ifelse(Cont_N50 >= 10, customPurple, "#FF9999"))))), - Kmer_Compl = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - `background-color` = ifelse(between(Kmer_Compl,80, 89.9999), "#FFCC99", - ifelse(between(Kmer_Compl,90, 94.99999), customGreen, - ifelse(Kmer_Compl >= 95, customPurple, "#FF9999"))))), - qv = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - `background-color` = ifelse(between(qv,35, 39.9999999999), "#FFCC99", - ifelse(between(qv,40, 49.999999999), customGreen, - ifelse(qv >= 50, customPurple, "#FF9999"))))), - - `Comp_Single_BUSCOs_%` = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - `background-color` = ifelse(between(`Comp_Single_BUSCOs_%`,80, 89.9999), "#FFCC99", - ifelse(between(`Comp_Single_BUSCOs_%`,90, 94.99999), customGreen, - ifelse(`Comp_Single_BUSCOs_%` >= 95, customPurple, "#FF9999"))))))) - -cat('<br>') -cat("\n") -cat('<br>') - -legendTable<-read.table(file = snakemake@params[[1]], sep = "", header = TRUE, row.names=NULL, check.names = FALSE) - -format_table(legendTable, - align =c("c","c","c", "c", "c", "c", "c"), - list(Gaps_per_Gb = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - "font.size" = "12px", - "width" = '150px', - `background-color` = ifelse(Gaps_per_Gb == '> 10000',"#FF9999", - ifelse(Gaps_per_Gb == '1000 - 10000',"#FFCC99", - ifelse(Gaps_per_Gb == '200 - 1000',customGreen, customPurple))))), - Scaf_N50 = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - "font.size" = "12px", - "width" = '150px', - `background-color` = ifelse(Scaf_N50 == '< 0.1Mbp',"#FF9999", - ifelse(Scaf_N50 == '0.1Mbp - 10Mbp',"#FFCC99", - ifelse(Scaf_N50 == '10Mbp - 100Mbp',customGreen, customPurple))))), - Cont_N50 = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - "font.size" = "12px", - "width" = '150px', - `background-color` = ifelse(Cont_N50 == '< 0.01Mbp',"#FF9999", - ifelse(Cont_N50 == '0.01Mbp - 1Mbp',"#FFCC99", - ifelse(Cont_N50 == '1Mbp - 10Mbp',customGreen, customPurple))))), - qv = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - "font.size" = "12px", - "width" = '100px', - `background-color` = ifelse(qv == '< 35',"#FF9999", - ifelse(qv == '35 - 40',"#FFCC99", - ifelse(qv == '40 - 50',customGreen, customPurple))))), - Kmer_Compl = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - "font.size" = "12px", - "width" = '150px', - `background-color` = ifelse(Kmer_Compl == '< 80%',"#FF9999", - ifelse(Kmer_Compl == '80% - 90%',"#FFCC99", - ifelse(Kmer_Compl == '90% - 95%',customGreen, customPurple))))), - `Comp_Single_BUSCOs_%` = formatter("span", - style = ~style(display = "block", - padding = "0 4px", - `border-radius` = "3px", - "font.size" = "12px", - "width" = '220px', - `background-color` = ifelse(`Comp_Single_BUSCOs_%` == '< 80%',"#FF9999", - ifelse(`Comp_Single_BUSCOs_%` == '80% - 90%',"#FFCC99", - ifelse(`Comp_Single_BUSCOs_%` == '90% - 95%',customGreen, customPurple))))))) -sink(file = NULL) - - +#!/usr/bin/env Rscript + +suppressMessages(library(dplyr)) +suppressMessages(library(formattable)) + +fullTableOfStats<-read.table(file = snakemake@input[[1]], sep = "", header = TRUE, row.names=NULL, check.names = FALSE) + +fullTableOfStats$Gaps_per_Gb <- ((fullTableOfStats$Gaps / fullTableOfStats$Total_bp) *1000000000) +fullTableOfStats$Gaps_per_Gb <- as.integer(fullTableOfStats$Gaps_per_Gb) + + +#customPurple='#c699e8' +#customGreen='#8fc773' +customPurple='#99c1f1' +customGreen='#8ff0a4' + +selectionOfStats_colouredHeatmap <- fullTableOfStats %>% + select(c('ASM_ID', + 'Gaps_per_Gb', 'Scaf_N50', + 'Cont_N50','qv', + 'Kmer_Compl', "Comp_Single_BUSCOs_%" = BUSCO_S)) %>% + mutate("Comp_Single_BUSCOs_%" = as.numeric(sub("%", "", as.character(`Comp_Single_BUSCOs_%`)))) + +sink(file = snakemake@output[[1]]) + + +format_table(selectionOfStats_colouredHeatmap, + align =c("l","c","c","c","c", "c", "c", "c", "c"), + list(Gaps_per_Gb = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + `background-color` = ifelse(between(Gaps_per_Gb,1001, 10000), "#F9F06B", + ifelse(between(Gaps_per_Gb,201 , 1000), customGreen, + ifelse(Gaps_per_Gb <= 200, customPurple, "#F66151"))))), + Scaf_N50 = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + `background-color` = ifelse(between(Scaf_N50,0.1, 9.99999), "#F9F06B", + ifelse(between(Scaf_N50,10, 99.99999), customGreen, + ifelse(Scaf_N50 >= 100, customPurple, "#F66151"))))), + Scaf_L50 = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + `background-color` = ifelse(between(Scaf_L50,0.1, 9.99999), "#F9F06B", + ifelse(between(Scaf_L50,10, 99.99999), customGreen, + ifelse(Scaf_L50 >= 100, customPurple, "#F66151"))))), + Cont_N50 = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + `background-color` = ifelse(between(Cont_N50,0.01, 0.99999), "#F9F06B", + ifelse(between(Cont_N50,1, 9.999999), customGreen, + ifelse(Cont_N50 >= 10, customPurple, "#F66151"))))), + Kmer_Compl = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + `background-color` = ifelse(between(Kmer_Compl,80, 89.9999), "#F9F06B", + ifelse(between(Kmer_Compl,90, 94.99999), customGreen, + ifelse(Kmer_Compl >= 95, customPurple, "#F66151"))))), + qv = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + `background-color` = ifelse(between(qv,35, 39.9999999999), "#F9F06B", + ifelse(between(qv,40, 49.999999999), customGreen, + ifelse(qv >= 50, customPurple, "#F66151"))))), + + `Comp_Single_BUSCOs_%` = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + `background-color` = ifelse(between(`Comp_Single_BUSCOs_%`,80, 89.9999), "#F9F06B", + ifelse(between(`Comp_Single_BUSCOs_%`,90, 94.99999), customGreen, + ifelse(`Comp_Single_BUSCOs_%` >= 95, customPurple, "#F66151"))))))) + +cat('<br>') +cat("\n") +cat('<br>') + +legendTable<-read.table(file = snakemake@params[[1]], sep = "", header = TRUE, row.names=NULL, check.names = FALSE) + +format_table(legendTable, + align =c("c","c","c", "c", "c", "c", "c"), + list(Gaps_per_Gb = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + "font.size" = "12px", + "width" = '150px', + `background-color` = ifelse(Gaps_per_Gb == '> 10000',"#F66151", + ifelse(Gaps_per_Gb == '1000 - 10000',"#F9F06B", + ifelse(Gaps_per_Gb == '200 - 1000',customGreen, customPurple))))), + Scaf_N50 = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + "font.size" = "12px", + "width" = '150px', + `background-color` = ifelse(Scaf_N50 == '< 0.1Mbp',"#F66151", + ifelse(Scaf_N50 == '0.1Mbp - 10Mbp',"#F9F06B", + ifelse(Scaf_N50 == '10Mbp - 100Mbp',customGreen, customPurple))))), + Cont_N50 = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + "font.size" = "12px", + "width" = '150px', + `background-color` = ifelse(Cont_N50 == '< 0.01Mbp',"#F66151", + ifelse(Cont_N50 == '0.01Mbp - 1Mbp',"#F9F06B", + ifelse(Cont_N50 == '1Mbp - 10Mbp',customGreen, customPurple))))), + qv = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + "font.size" = "12px", + "width" = '100px', + `background-color` = ifelse(qv == '< 35',"#F66151", + ifelse(qv == '35 - 40',"#F9F06B", + ifelse(qv == '40 - 50',customGreen, customPurple))))), + Kmer_Compl = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + "font.size" = "12px", + "width" = '150px', + `background-color` = ifelse(Kmer_Compl == '< 80%',"#F66151", + ifelse(Kmer_Compl == '80% - 90%',"#F9F06B", + ifelse(Kmer_Compl == '90% - 95%',customGreen, customPurple))))), + `Comp_Single_BUSCOs_%` = formatter("span", + style = ~style(display = "block", + padding = "0 4px", + `border-radius` = "3px", + "font.size" = "12px", + "width" = '220px', + `background-color` = ifelse(`Comp_Single_BUSCOs_%` == '< 80%',"#F66151", + ifelse(`Comp_Single_BUSCOs_%` == '80% - 90%',"#F9F06B", + ifelse(`Comp_Single_BUSCOs_%` == '90% - 95%',customGreen, customPurple))))))) +sink(file = NULL) + +