fixed pos_count cals in function by specifying dplyr and changed summarize to summarise

This commit is contained in:
Tanushree Tunstall 2021-09-15 15:46:42 +01:00
parent bf432cd054
commit 449af7acf4
3 changed files with 24 additions and 16 deletions

View file

@ -38,14 +38,6 @@ my_corr_pairs <- function (corr_data_all
}
c_plot <- my_corr_pairs(corrplot_df
, dot_size = 1.6
, ats = 1.5
, corr_lab_size = 1.5
, corr_value_size = 1)
######################################################################
my_pp = function (x, smooth = TRUE, scale = FALSE, density = TRUE, ellipses = TRUE,
digits = 2, method = "pearson", pch = 20, lm = FALSE, cor = TRUE,

View file

@ -42,7 +42,9 @@ site_snp_count_bp <- function (plotdf
, "\nNo. of cols:", ncol(plotdf)
, "\nNow adding column: frequency of mutational positions"))
# adding snpcount for each position
#-------------------------------------------
# adding column: snpcount for each position
#-------------------------------------------
setDT(plotdf)[, pos_count := .N, by = .(eval(parse(text = df_colname)))]
cat("\nCumulative nssnp count\n"
@ -64,15 +66,20 @@ site_snp_count_bp <- function (plotdf
cat(paste0("\nrevised df dimensions:"
, "\nNo. of rows:", nrow(plotdf)
, "\nNo. of cols:", ncol(plotdf)))
#------------------------------------------------------
# creating df: average count of snpcount for each position
# created in earlier step
#-------------------------------------------------------
# use group by on pos_count
snpsBYpos_df <- plotdf %>%
group_by(eval(parse(text = df_colname))) %>%
summarize(snpsBYpos = mean(pos_count))
cat("\nnssnp count\n"
, table(snpsBYpos_df$snpsBYpos))
dplyr::group_by(eval(parse(text = df_colname))) %>%
dplyr::summarise(snpsBYpos = mean(pos_count)) # changed from summarize!
cat("\nnssnp count per position\n"
, table(snpsBYpos_df$snpsBYpos)
, "\n")
# calculating total no. of sites associated with nsSNPs
tot_sites = sum(table(snpsBYpos_df$snpsBYpos))