R/shiny_deltaSNPindex.R

Defines functions shiny_deltaSNPindex

Documented in shiny_deltaSNPindex

#Shiny: delta(SNP-index) wrapper function 

#' @title delta(SNP-index) Wrapper Function
#' @description Please note that this function is not to be run manually.
#' Wrapper function for delta(SNP-index) plots specific to the R-shiny application. 
#' Calls all functions involved in plotting delta(SNP-index) values against the mid position of the corresponding window of a specific chromosome.
#'
#' @param vcf.list object containing meta information and vcf data frame
#' @param wtBulk Wild-Type pool
#' @param mBulk Mutant pool 
#' @param variants variants to be considered. Default is "SNP" (allowed: "SNP" or "all")
#' @param min.SNPindex min value allowed for the SNP index (default=0.3)
#' @param max.SNPindex max value allowed for the SNP index (default=0.9)
#' @param min.DP min value allowed for the read depth (default=50)
#' @param max.DP max value allowed for the read depth (default=200)
#' @param min.GQ min value allowed for the genotype quality (default=99)
#' @param chrID chromosome ID of interest
#' @param chr chromosome name printed on the plot
#' @param windowSize window size (default=1000000)
#' @param windowStep window step (default=10000)
#' @param ranges axes ranges (x,y)
#' 
#' @details Wrapper function for generting delta(SNP-index) plots inside the R-Shiny application.
#' The involved functions are the following (in oder): calc_SNPindex(), filter_SNPindex(), extract_chrIDs(), slidingWindow() and shinyPlot_SNPindex().
#' 
#' This function is not intended to be run by the user, as it was specifically created to be used by the BSAvis_shiny() function.
#' @importFrom dplyr %>%
#' @export shiny_deltaSNPindex

shiny_deltaSNPindex <- function(vcf.list, wtBulk, mBulk, variants="SNP",
                                min.SNPindex, max.SNPindex, min.DP, max.DP, min.GQ,
                                chrID, chr, windowSize, windowStep, ranges){
  
  #Calculate SNP-index of each variant in each bulk
  vcf_df_SNPindex <- BSAvis::calc_SNPindex(vcf.list$df, wtBulk, mBulk, variants)
  
  #Filter variants
  vcf_df_SNPindex_filt <- BSAvis::filter_SNPindex(vcf_df_SNPindex, min.SNPindex, max.SNPindex, min.DP, max.DP, min.GQ)
  
  #Create list of chromosome IDs in the way they appear in the VCF file
  chrList <- BSAvis::extract_chrIDs(vcf.list$meta)
  
  #Apply sliding window to calculate mean SNP-index in each window of a specifc size and step for each bulk
  SNPindex_windows <- BSAvis::slidingWindow(vcf.list$meta, chrList, chrID, windowSize, windowStep, vcf_df_SNPindex_filt)
  
  #Calculate delta(SNP-index)
  deltaSNPindex_windows <- BSAvis::calc_deltaSNPindex(SNPindex_windows)
  
  #Plot delta(SNP-index) across the positions of a given chromosome
  BSAvis::shinyPlot_deltaSNPindex(deltaSNPindex_windows, chr, ranges)
}
EG-lisy/BSAvis documentation built on Dec. 17, 2021, 5:38 p.m.