removed setDT and replaced with dplyr alt in position_count_bp.R
This commit is contained in:
parent
65d697d3a2
commit
da8f8d90d4
5 changed files with 210 additions and 110 deletions
|
@ -36,6 +36,8 @@ site_snp_count_bp <- function (plotdf
|
|||
, subtitle_size = 20
|
||||
, subtitle_colour = "pink")
|
||||
{
|
||||
|
||||
plotdf = as.data.frame(plotdf)
|
||||
# dim of plotdf
|
||||
cat(paste0("\noriginal df dimensions:"
|
||||
, "\nNo. of rows:", nrow(plotdf)
|
||||
|
@ -45,14 +47,32 @@ site_snp_count_bp <- function (plotdf
|
|||
#-------------------------------------------
|
||||
# adding column: snpcount for each position
|
||||
#-------------------------------------------
|
||||
setDT(plotdf)[, pos_count := .N, by = .(eval(parse(text = df_colname)))]
|
||||
#setDT(plotdf)[, pos_count_check := .N, by = .(eval(parse(text = df_colname)))]
|
||||
|
||||
# from dplyr
|
||||
plotdf = plotdf %>%
|
||||
dplyr::add_count(eval(parse(text = df_colname)))
|
||||
class(plotdf)
|
||||
plotdf = as.data.frame(plotdf)
|
||||
class(plotdf)
|
||||
nc_change = which(colnames(plotdf) == "n")
|
||||
colnames(plotdf)[nc_change] <- "pos_count"
|
||||
class(plotdf)
|
||||
|
||||
# if (all(plotdf$pos_count==plotdf$pos_count_check) ){
|
||||
# cat("\nPASS: pos_count column created")
|
||||
# plotdf = plotdf[, !colnames(plotdf)%in%c("pos_count_check")]
|
||||
# }else{
|
||||
# stop("\nAbort: pos count numbes mismatch from dplyr and data.table")
|
||||
# }
|
||||
|
||||
cat("\nCumulative nssnp count\n"
|
||||
, table(plotdf$pos_count))
|
||||
|
||||
# calculating total no. of mutations
|
||||
tot_muts = sum(table(plotdf$pos_count))
|
||||
|
||||
|
||||
# sanity check
|
||||
if(tot_muts == nrow(plotdf)){
|
||||
cat("\nPASS: total number of mutations match"
|
||||
|
|
|
@ -24,7 +24,7 @@ stability_count_bp <- function(plotdf
|
|||
, geom_ls = 10 # geom_label size
|
||||
, yaxis_title = "Number of nsSNPs"
|
||||
, bp_plot_title = ""
|
||||
, label_categories = c("LEVEL1", "LEVEL2")
|
||||
, label_categories #= c("LEVEL1", "LEVEL2")
|
||||
, title_colour = "chocolate4"
|
||||
, subtitle_text = NULL
|
||||
, sts = 20
|
||||
|
@ -69,7 +69,8 @@ stability_count_bp <- function(plotdf
|
|||
scale_fill_manual(name = ""
|
||||
# name = leg_title
|
||||
, values = bar_fill_values
|
||||
, labels = label_categories)
|
||||
, labels = label_categories # problem with consurf decreasing level
|
||||
)
|
||||
|
||||
|
||||
return(OutPlot_count)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue