### Install QTLseqr from GitHub Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/README.md Installs the devtools package and then uses it to install the QTLseqr package from GitHub. Ensure Rtools or Xcode is installed for C++ compilation. ```R install.packages("devtools") # use devtools to install QTLseqr devtools::install_github("bmansfeld/QTLseqr") ``` -------------------------------- ### Install and Load QTLseqr Package Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/vignettes/QTLseqr.Rmd Installs the QTLseqr package from GitHub using devtools and then loads it into the R session. Ensure devtools is installed first. ```R install.packages("devtools") # download the QTLseqr package from GitHub devtools::install_github("bmansfeld/QTLseqr") ``` ```R #load the package library("QTLseqr") ``` ```R #Install step if you have not done so yet: #install.packages("devtools") devtools::install_github("bmansfeld/QTLseqr") library("QTLseqr") ``` -------------------------------- ### runQTLseqAnalysis Usage Example Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/runQTLseqAnalysis.html An example of how to call runQTLseqAnalysis with specific parameters for bulk size and window size. ```R df_filt <- runQTLseqAnalysis( SNPset = df_filt, bulkSize = c(25, 35) windowSize = 1e6, popStruc = "F2", replications = 10000, intervals = c(95, 99) ) ``` -------------------------------- ### Install QTLseqr from GitHub Source: https://rdrr.io/github/bmansfeld/QTLseqR Use the remotes package to install the latest version of QTLseqr directly from the GitHub repository. ```R install.packages("remotes") remotes::install_github("bmansfeld/QTLseqR") ``` -------------------------------- ### Install and Load Yang2013data Package Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/vignettes/QTLseqr.Rmd Downloads and loads the Yang2013data package from GitHub, which contains trial data for use with QTLseqr. ```R #download and load data package (~50Mb) devtools::install_github("bmansfeld/Yang2013data") library("Yang2013data") ``` -------------------------------- ### Specify Custom Data File Path Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/vignettes/QTLseqr.Rmd Provides an example of how to specify a direct file path to a custom BSA data table. ```R rawData <- "C:/PATH/TO/MY/DIR/My_BSA_data.table" ``` -------------------------------- ### Import GATK SNP Data Source: https://rdrr.io/github/bmansfeld/QTLseqR/src/R/Import_Filter.R Example usage of the importFromGATK function to load and process SNP data from a GATK table file. ```R df <- ImportFromGATK(filename = file.table, highBulk = highBulkSampleName, lowBulk = lowBulkSampleName, chromList = c("Chr1","Chr4","Chr7")) ``` -------------------------------- ### Call plotSimulatedThresholds function Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/plotSimulatedThresholds.html Example usage of the plotSimulatedThresholds function with default parameters. ```R plotSimulatedThresholds(SNPset = NULL, popStruc = "F2", bulkSize, depth = NULL, replications = 10000, filter = 0.3, intervals = c(95, 99)) ``` -------------------------------- ### filterSNPs Usage Example Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/FilterSNPs.html An example demonstrating how to apply multiple filtering criteria to a SNP data frame. ```R df_filt <- FilterSNPs( df, refAlleleFreq = 0.3, minTotalDepth = 40, maxTotalDepth = 80, minSampleDepth = 20, minGQ = 99, verbose = TRUE ) ``` -------------------------------- ### Import Yang et al. (2013) Data Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/vignettes/QTLseqr.Rmd Locates and imports the Yang_et_al_2013.table data file from the installed Yang2013data package. ```R #Import the data rawData <- system.file( "extdata", "Yang_et_al_2013.table", package = "Yang2013data", mustWork = TRUE) ``` -------------------------------- ### Simulate Confidence Intervals Source: https://rdrr.io/github/bmansfeld/QTLseqR/src/R/takagi_sim.R Calculates delta SNP-index thresholds for confidence intervals based on population structure and bulk size. Includes an example usage pattern. ```R CI <- simulateConfInt( popStruc = "F2", bulkSize = 50, depth = 1:100, intervals = c(0.05, 0.95, 0.025, 0.975, 0.005, 0.995, 0.0025, 0.9975) ``` ```R simulateConfInt <- function(popStruc = "F2", bulkSize, depth = 1:100, replications = 10000, filter = 0.3, intervals = c(0.05, 0.025)) { if (popStruc == "F2") { message( "Assuming bulks selected from F2 population, with ", paste(bulkSize, collapse = " and "), " individuals per bulk." ) } else { message( "Assuming bulks selected from RIL population, with ", bulkSize, " individuals per bulk." ) } if (length(bulkSize) == 1) { message("The 'bulkSize' argument is of length 1, setting number of individuals in both bulks to: ", bulkSize) bulkSize[2] <- bulkSize[1] } if (length(bulkSize) > 2) { message("The 'bulkSize' argument is larger than 2. Using the first two values as the bulk size.") } if (any(bulkSize < 0)) { stop("Negative bulkSize values") } #makes a vector of possible alt allele frequencies once. this is then sampled for each replicate tmp_freq <- replicate(n = replications * 10, simulateAlleleFreq(n = bulkSize[1], pop = popStruc)) tmp_freq2 <- replicate(n = replications * 10, simulateAlleleFreq(n = bulkSize[2], pop = popStruc)) message( paste0( "Simulating ", replications, " SNPs with reads at each depth: ", min(depth), "-", max(depth) ) ) message(paste0( "Keeping SNPs with >= ", filter, ``` -------------------------------- ### Display R Session Information Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/vignettes/QTLseqr.Rmd Use this command to output the current R session details, including loaded packages and version information. ```R sessionInfo() ``` -------------------------------- ### Run Gprime Analysis and Calculate Q-values Source: https://rdrr.io/github/bmansfeld/QTLseqR/src/R/export_functions.R This function is used to calculate q-values before using getQTLTable with the Gprime method. Ensure the SNPset contains necessary columns for this analysis. ```R getQTLTable <- function(SNPset, method = "Gprime", alpha = 0.05, interval = 99, export = FALSE, fileName = "QTL.csv") { conf <- paste0("CI_", interval) if (!method %in% c("Gprime", "QTLseq")) { stop("method must be either \"Gprime\" or \"QTLseq\"") } if ((method == "Gprime") & !("qvalue" %in% colnames(SNPset))) { stop("Please first use runGprimeAnalysis to calculate q-values") } if ((method == "QTLseq") & !(any(names(SNPset) %in% conf))) { stop( "Cant find the requested confidence interval. Please check that the requested interval exsits or first use runQTLseqAnalysis to calculate confidence intervals" ) } #QTL <- getSigRegions(SNPset = SNPset, method = method, interval = interval, alpha = alpha) fdrT <- getFDRThreshold(SNPset$pvalue, alpha = alpha) GprimeT <- SNPset[which(SNPset$pvalue == fdrT), "Gprime"] #merged_QTL <- dplyr::bind_rows(QTL, .id = "id") SNPset <- SNPset %>% dplyr::group_by(CHROM) if (method == "QTLseq") { qtltable <- SNPset %>% dplyr::mutate(passThresh = abs(tricubeDeltaSNP) > abs(!!as.name(conf))) %>% dplyr::group_by(CHROM, run = { run = rle(passThresh) rep(seq_along(run$lengths), run$lengths) }) %>% dplyr::filter(passThresh == TRUE) %>% dplyr::ungroup() %>% dplyr::group_by(CHROM) %>% dplyr::group_by(CHROM, qtl = { qtl = rep(seq_along(rle(run)$lengths), rle(run)$lengths) }) %>% #dont need run variable anymore dplyr::select(-run) %>% dplyr::summarize( start = min(POS), end = max(POS), length = end - start, nSNPs = length(POS), avgSNPs_Mb = round(length(POS) / (max(POS) - min(POS)) * 1e6), peakDeltaSNP = ifelse( mean(tricubeDeltaSNP) >= 0, max(tricubeDeltaSNP), min(tricubeDeltaSNP) ), posPeakDeltaSNP = POS[which.max(abs(tricubeDeltaSNP))], avgDeltaSNP = mean(tricubeDeltaSNP) ) } else { qtltable <- SNPset %>% dplyr::mutate(passThresh = qvalue <= alpha) %>% dplyr::group_by(CHROM, run = { run = rle(passThresh) rep(seq_along(run$lengths), run$lengths) }) %>% dplyr::filter(passThresh == T) %>% dplyr::ungroup() %>% dplyr::group_by(CHROM) %>% dplyr::group_by(CHROM, qtl = { qtl = rep(seq_along(rle(run)$lengths), rle(run)$lengths) }) %>% #dont need run variable anymore dplyr::select(-run) %>% dplyr::summarize( start = min(POS), end = max(POS), length = end - start, nSNPs = length(POS), avgSNPs_Mb = round(length(POS) / (max(POS) - min(POS)) * 1e6), peakDeltaSNP = ifelse( mean(tricubeDeltaSNP) >= 0, max(tricubeDeltaSNP), min(tricubeDeltaSNP) ), posPeakDeltaSNP = POS[which.max(abs(tricubeDeltaSNP))], avgDeltaSNP = mean(tricubeDeltaSNP), #Gprime stuff maxGprime = max(Gprime), posMaxGprime = POS[which.max(Gprime)], meanGprime = mean(Gprime), sdGprime = sd(Gprime), AUCaT = sum(diff(POS) * (((head(Gprime, -1) + tail(Gprime, -1)) / 2 ) - GprimeT)), ``` -------------------------------- ### Basic NGS-BSA Data Analysis with QTLseqr Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/README.md Demonstrates a basic workflow for importing, filtering, analyzing, and plotting NGS-BSA data using QTLseqr. This includes setting up sample names, defining chromosomes, importing data from GATK format, filtering SNPs, running G' and QTLseq analyses, and plotting results. ```R #load the package library("QTLseqr") #Set sample and file names HighBulk <- "SRR834931" LowBulk <- "SRR834927" file <- "SNPs_from_GATK.table" #Choose which chromosomes will be included in the analysis (i.e. exclude smaller contigs) Chroms <- paste0(rep("Chr", 12), 1:12) #Import SNP data from file df <- importFromGATK( file = file, highBulk = HighBulk, lowBulk = LowBulk, chromList = Chroms ) #Filter SNPs based on some criteria df_filt <- filterSNPs( SNPset = df, refAlleleFreq = 0.20, minTotalDepth = 100, maxTotalDepth = 400, minSampleDepth = 40, minGQ = 99 ) #Run G' analysis df_filt <- runGprimeAnalysis( SNPset = df_filt, windowSize = 1e6, outlierFilter = "deltaSNP") #Run QTLseq analysis df_filt <- runQTLseqAnalysis( SNPset = df_filt, windowSize = 1e6, popStruc = "F2", bulkSize = c(25, 25), replications = 10000, intervals = c(95, 99) ) #Plot plotQTLStats(SNPset = df_filt, var = "Gprime", plotThreshold = TRUE, q = 0.01) plotQTLStats(SNPset = df_filt, var = "deltaSNP", plotIntervals = TRUE) #export summary CSV getQTLTable(SNPset = df_filt, alpha = 0.01, export = TRUE, fileName = "my_BSA_QTL.csv") ``` -------------------------------- ### simulateConfInt Function Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/simulateConfInt.html Simulates delta SNP-index confidence interval thresholds as described in Takagi et al., (2013). Genotypes are randomly assigned for each individual in the bulk, based on the population structure. The total alternative allele frequency in each bulk is calculated at each depth used to simulate delta SNP-indeces, with a user-defined number of bootstrapped replications. The requested confidence intervals are then calculated from the bootstraps. ```APIDOC ## simulateConfInt ### Description Simulates delta SNP-index confidence interval thresholds. ### Method (Implicitly R function call, not a standard HTTP method) ### Endpoint (Not applicable, this is an R function) ### Parameters #### Arguments - **popStruc** (character) - The population structure. Defaults to "F2" and assumes "RIL". - **bulkSize** (integer vector) - Non-negative integer vector. The number of individuals in each simulated bulk. Can be of length 1, then both bulks are set to the same size. Assumes the first value in the vector is the simulated high bulk. - **depth** (integer) - A read depth for which to replicate SNP-index calls. Defaults to 1:100. - **replications** (integer) - The number of bootstrap replications. Defaults to 10000. - **filter** (numeric) - An optional minimum SNP-index filter. Defaults to 0.3. - **intervals** (numeric vector) - Vector of probabilities with values in [0,1] corresponding to the requested confidence intervals. Defaults to c(0.05, 0.025). ### Request Example (This section is not applicable as it's an R function, not a web API endpoint. The example below shows R code usage.) ```R CI <- simulateConfInt( popStruc = "F2", bulkSize = 50, depth = 1:100, intervals = c(0.05, 0.95, 0.025, 0.975, 0.005, 0.995, 0.0025, 0.9975) ) ``` ### Response #### Success Response - **Data Frame** - A data frame of delta SNP-index thresholds corresponding to the requested confidence intervals at the user-set depths. ``` -------------------------------- ### Plot Specific Chromosomes with FDR Threshold Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/plotQTLStats.html This example demonstrates plotting the G' value for specific chromosomes ('Chr3', 'Chr4') and displaying the False Discovery Rate (FDR) threshold at a q-value of 0.01. Ensure your SNPset data is filtered appropriately. ```R p <- plotQTLstats(df_filt_6Mb, var = "Gprime", plotThreshold = TRUE, q = 0.01, subset = c("Chr3","Chr4")) ``` -------------------------------- ### Generate QTL Summary Table Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/vignettes/QTLseqr.Rmd Summarize significant QTL regions using `getQTLTable`. Set `export = TRUE` and `fileName` to save the results as a CSV. The `method` can be 'Gprime' or 'QTLseq'. ```R results <- getQTLTable(SNPset = df_filt, method = "Gprime",alpha = 0.01, export = FALSE) results ``` -------------------------------- ### Plotting and Visualization Source: https://rdrr.io/github/bmansfeld/QTLseqR/man Functions for visualizing G' distribution, QTL statistics, and simulation data. ```APIDOC ## plotGprimeDist / plotQTLStats / plotSimulatedThresholds ### Description Functions to generate various plots for visualizing QTLseqr analysis results and simulation data. - `plotGprimeDist`: Plots the distribution of G' statistics. - `plotQTLStats`: Plots different parameters for QTL identification. - `plotSimulatedThresholds`: Plots simulation data for QTLseq analysis. ### Method Not applicable (R functions) ### Endpoint Not applicable (R functions) ### Parameters **plotGprimeDist**: - **g_stats** (numeric vector) - Description: Vector of G statistics. - **null_distribution** (numeric vector) - Description: Estimated null distribution of G' statistics. **plotQTLStats**: - **results** (data.frame) - Description: Data frame containing QTL analysis results. **plotSimulatedThresholds**: - **sim_data** (data.frame) - Description: Data frame containing simulation results. ### Request Example ```R # Example for plotGprimeDist plotGprimeDist(g_stats = my_g_stats, null_distribution = my_null_dist) # Example for plotQTLStats plotQTLStats(results = my_analysis_results) # Example for plotSimulatedThresholds plotSimulatedThresholds(sim_data = my_simulation_data) ``` ### Response These functions typically generate plots and do not return specific data structures, though they might return plot objects depending on the R environment. ``` -------------------------------- ### Estimate P-values using Log-Normal Distribution Source: https://rdrr.io/github/bmansfeld/QTLseqR/src/R/G_functions.R Estimates p-values using a non-parametric method based on the log-normal distribution of smoothed G' statistics. It filters outlier regions using either deltaSNP or Hampel's rule before estimation. Ensure the 'modeest' package is installed for mode estimation. ```R getPvals <- function(Gprime, deltaSNP = NULL, outlierFilter = c("deltaSNP", "Hampel"), filterThreshold) { if (outlierFilter == "deltaSNP") { if (abs(filterThreshold) >= 0.5) { stop("filterThreshold should be less than 0.5") } message("Using deltaSNP-index to filter outlier regions with a threshold of ", filterThreshold) trimGprime <- Gprime[abs(deltaSNP) < abs(filterThreshold)] } else { message("Using Hampel's rule to filter outlier regions") lnGprime <- log(Gprime) medianLogGprime <- median(lnGprime) MAD <- median(medianLogGprime - lnGprime[lnGprime <= medianLogGprime]) trimGprime <- Gprime[lnGprime - median(lnGprime) <= 5.2 * MAD] } medianTrimGprime <- median(trimGprime) message("Estimating the mode of a trimmed G prime set using the 'modeest' package...") modeTrimGprime <- modeest::mlv(x = trimGprime, bw = 0.5, method = "hsm")[1] muE <- log(medianTrimGprime) varE <- abs(muE - log(modeTrimGprime)) message("Calculating p-values...") pval <- 1 - plnorm(q = Gprime, meanlog = muE, sdlog = sqrt(varE)) return(pval) } ``` -------------------------------- ### Write QTL Table to CSV Source: https://rdrr.io/github/bmansfeld/QTLseqR/src/R/export_functions.R Exports the processed QTL table to a CSV file. Ensure the 'export' argument is set to TRUE and provide a valid 'fileName'. ```R write.csv(file = fileName, x = qtltable, row.names = FALSE) ``` -------------------------------- ### Define importFromGATK Function Source: https://rdrr.io/github/bmansfeld/QTLseqR/src/R/Import_Filter.R Implementation of the importFromGATK function, which reads GATK table files and validates required columns. ```R importFromGATK <- function(file, highBulk = character(), lowBulk = character(), chromList = NULL) { # first read one line to help define col types colheader <- read.delim(file, nrows=1, check.names=FALSE) # identify the sample name specific int and chr columns int_matches <- grep('DP|GQ', names(colheader), value=TRUE) chr_matches <- grep('\\.AD', names(colheader), value=TRUE) # create cols_spec class definitions int_cols <- do.call(readr::cols, setNames( rep(list(readr::col_integer()), length(int_matches)), int_matches))$cols chr_cols <- do.call(readr::cols, setNames( rep(list(readr::col_character()), length(chr_matches)), chr_matches))$cols col_defs <- readr::cols(CHROM = "c", POS = "i") col_defs$cols <- c(readr::cols(CHROM = "c", POS = "i")$cols, int_cols, chr_cols ) SNPset <- readr::read_tsv(file = file, col_names = TRUE, guess_max = 10000, col_types = col_defs) if (!all( c( "CHROM", "POS", paste0(highBulk, ".AD"), paste0(lowBulk, ".AD"), paste0(highBulk, ".DP"), paste0(lowBulk, ".DP") ) %in% names(SNPset))) { stop("One of the required fields is missing. Check your table file.") } ``` -------------------------------- ### QTL Analysis Execution Source: https://rdrr.io/github/bmansfeld/QTLseqR/man Functions to run the main QTLseqr analysis pipelines. ```APIDOC ## runGprimeAnalysis / runQTLseqAnalysis ### Description Functions to execute the core QTLseqr analysis. - `runGprimeAnalysis`: Identifies QTL using a smoothed G statistic. - `runQTLseqAnalysis`: Calculates delta SNP confidence intervals for QTLseq analysis. ### Method Not applicable (R functions) ### Endpoint Not applicable (R functions) ### Parameters **runGprimeAnalysis**: - **snp_data** (data.frame) - Description: Data frame containing SNP information. - **window_size** (integer) - Description: Size of the sliding window. - **min_depth** (integer) - Description: Minimum read depth for filtering. - **max_depth** (integer) - Description: Maximum read depth for filtering. - **min_quality** (numeric) - Description: Minimum SNP quality for filtering. **runQTLseqAnalysis**: - **snp_data** (data.frame) - Description: Data frame containing SNP information. - **ploidy** (integer) - Description: Ploidy level of the organism. - **n_simulations** (integer) - Description: Number of simulations to perform. ### Request Example ```R # Example for runGprimeAnalysis g_analysis_results <- runGprimeAnalysis(snp_data = my_snp_data, window_size = 100, min_depth = 5, max_depth = 50, min_quality = 30) # Example for runQTLseqAnalysis qtlseq_results <- runQTLseqAnalysis(snp_data = my_snp_data, ploidy = 2, n_simulations = 1000) ``` ### Response **runGprimeAnalysis**: - **g_analysis_results** (data.frame) - Description: Data frame containing results from the G' analysis. **runQTLseqAnalysis**: - **qtlseq_results** (data.frame) - Description: Data frame containing results from the QTLseq analysis, including confidence intervals. ``` -------------------------------- ### Inspect Loaded Data Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/vignettes/QTLseqr.Rmd Display the first few rows of the loaded data frame to verify structure. ```R head(df) ``` -------------------------------- ### runGprimeAnalysis Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/runGprimeAnalysis.html A wrapper function that executes the complete G prime analysis pipeline to identify QTL. It calculates genome-wide G statistics, applies tricube smoothing to obtain G' values, estimates p-values using a non-parametric method, and calculates negative log10- and Benjamini-Hochberg adjusted p-values. ```APIDOC ## POST /runGprimeAnalysis ### Description Performs a full G prime analysis to identify QTL by calculating G statistics, applying tricube smoothing, estimating p-values, and adjusting them. ### Method POST ### Endpoint /runGprimeAnalysis ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **SNPset** (data.frame) - Required - A data frame containing the SNP set with previously filtered SNPs. - **windowSize** (numeric) - Optional - The window size in base pairs for calculating statistics. Defaults to 1e+06. - **outlierFilter** (character) - Optional - Method for filtering outlier regions for p-value estimation. Options are "deltaSNP" or "Hampel". Defaults to "deltaSNP". - **filterThreshold** (numeric) - Optional - The absolute delta SNP index to use for filtering putative QTL. Defaults to 0.1. - **...** (any) - Optional - Additional arguments passed to `locfit` and `locfit.raw`. ### Request Example ```json { "SNPset": "your_snp_data_frame", "windowSize": 2000000, "outlierFilter": "deltaSNP", "filterThreshold": 0.1 } ``` ### Response #### Success Response (200) - **G** (numeric) - The G statistic for each SNP. - **Gprime** (numeric) - The tricube smoothed G statistic. - **pvalue** (numeric) - The p-value at each SNP calculated by non-parametric estimation. - **negLog10Pval** (numeric) - The -Log10(pvalue) for plotting. - **qvalue** (numeric) - The Benjamini-Hochberg adjusted p-value. #### Response Example ```json { "G": [ ... ], "Gprime": [ ... ], "pvalue": [ ... ], "negLog10Pval": [ ... ], "qvalue": [ ... ] } ``` ``` -------------------------------- ### importFromGATK Source: https://rdrr.io/github/bmansfeld/QTLseqR/src/R/Import_Filter.R Imports SNP data from GATK VariantsToTable output and calculates delta SNP index and G statistics. ```APIDOC ## importFromGATK ### Description Imports SNP data from the output of the GATK VariantsToTable function. It calculates total reference allele frequency, delta SNP index, and the G statistic. ### Parameters #### Arguments - **file** (string) - Required - The name of the GATK VariablesToTable output .table file. - **highBulk** (string) - Required - The sample name of the High Bulk. - **lowBulk** (string) - Required - The sample name of the Low Bulk. - **chromList** (string vector) - Optional - A list of chromosomes to be used in the analysis. ### Response - **Returns** (data.frame) - A data frame containing columns for Read depth (DP), Reference Allele Depth (AD_REF), Alternative Allele Depth (AD_ALT), Genotype Quality (GQ), SNPindex for each bulk, REF_FRQ, deltaSNPindex, and GStat. ### Request Example importFromGATK(file = "data.table", highBulk = "HighSample", lowBulk = "LowSample", chromList = c("Chr1", "Chr4")) ``` -------------------------------- ### Run G' and QTLseq Analyses Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/vignettes/QTLseqr.Rmd Performs G' analysis using the deltaSNP outlier filter and then runs the QTLseq analysis with specified parameters for population structure, bulk size, replications, and confidence intervals. ```R #Run G' analysis df_filt <- runGprimeAnalysis(SNPset = df_filt, windowSize = 1e6, outlierFilter = "deltaSNP") #Run QTLseq analysis df_filt <- runQTLseqAnalysis( SNPset = df_filt, windowSize = 1e6, popStruc = "F2", bulkSize = c(300, 450), replications = 10000, intervals = c(95, 99) ) ``` -------------------------------- ### simulateSNPindex Function Source: https://rdrr.io/github/bmansfeld/QTLseqR/src/R/takagi_sim.R Simulates SNP-index values for bulk segregant analysis based on provided allele frequencies and read depths. ```APIDOC ## simulateSNPindex ### Description Simulates SNP-index values for bulk segregant analysis. ### Parameters - **depth** (numeric) - Read depth for simulation. - **altFreq1** (numeric) - Alternative allele frequency for the first bulk. - **altFreq2** (numeric) - Alternative allele frequency for the second bulk. - **replicates** (integer) - Number of bootstrap replications. - **filter** (numeric) - Optional minimum SNP-index filter. ### Returns A data frame with simulated SNP-index values and confidence intervals. ``` -------------------------------- ### Import SNP Data using importFromGATK Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/vignettes/QTLseqr.Rmd This R code imports SNP data from a GATK VariantsToTable output file. It requires specifying the input file, high bulk sample name, low bulk sample name, and a list of chromosomes to process. ```r #import data df <- \ importFromGATK( file = rawData, highBulk = HighBulk, lowBulk = LowBulk, chromList = Chroms ) ``` -------------------------------- ### POST /runGprimeAnalysis Source: https://rdrr.io/github/bmansfeld/QTLseqR/src/R/G_functions.R Performs G-prime analysis on a provided SNP set to identify potential QTL regions. ```APIDOC ## POST /runGprimeAnalysis ### Description Calculates G and G' statistics for a given SNP set, estimates p-values using a log-normal distribution, and calculates Benjamini-Hochberg adjusted p-values. ### Method POST ### Parameters #### Request Body - **SNPset** (data.frame) - Required - Data frame containing filtered SNPs. - **windowSize** (numeric) - Optional - Window size in base pairs (default = 1e6). - **outlierFilter** (string) - Optional - Method for filtering outlier regions, either 'deltaSNP' or 'Hampel'. - **filterThreshold** (numeric) - Optional - Absolute delta SNP index threshold for filtering putative QTL (default = 0.1). - **...** (dots) - Optional - Additional arguments passed to locfit. ### Response #### Success Response (200) - **SNPset** (data.frame) - The input SNP set with five additional columns: G, Gprime, pvalue, negLog10Pval, and qvalue. ``` -------------------------------- ### GATK VariantsToTable Command Syntax Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/vignettes/QTLseqr.Rmd This bash command demonstrates the syntax for using GATK's VariantsToTable tool to extract necessary SNP information from a VCF file for downstream analysis. Ensure `${REF}` and `${NAME}` are replaced with your actual file paths. ```bash java -jar GenomeAnalysisTK.jar \ -T VariantsToTable \ -R ${REF} \ -V ${NAME} \ -F CHROM -F POS -F REF -F ALT \ -GF AD -GF DP -GF GQ -GF PL \ -o ${NAME}.table ``` -------------------------------- ### Import Data from GATK Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/ImportFromGATK.html Imports SNP data from GATK's VariantsToTable output, calculates allele frequencies, delta SNP index, and G statistic. ```APIDOC ## POST /api/importFromGATK ### Description Imports SNP data from the output of the VariantsToTable function in GATK. After importing the data, the function then calculates total reference allele frequency for both bulks together, the delta SNP index (i.e. SNP index of the low bulk subtracted from the SNP index of the high bulk), the G statistic and returns a data frame. The required GATK fields (-F) are CHROM (Chromosome) and POS (Position). The required Genotype fields (-GF) are AD (Allele Depth), DP (Depth). Recommended fields are REF (Reference allele) and ALT (Alternative allele) Recommended Genotype feilds are PL (Phred-scaled likelihoods) and GQ (Genotype Quality). ### Method POST ### Endpoint /api/importFromGATK ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **file** (string) - Required - The name of the GATK VariablesToTable output .table file which the data are to be read from. - **highBulk** (string) - Required - The sample name of the High Bulk - **lowBulk** (string) - Required - The sample name of the Low Bulk - **chromList** (array of strings) - Optional - A string vector of the chromosomes to be used in the analysis. Useful for filtering out unwanted contigs etc. ### Request Example ```json { "file": "path/to/your/gatk_output.table", "highBulk": "HighBulkSampleName", "lowBulk": "LowBulkSampleName", "chromList": ["Chr1", "Chr4", "Chr7"] } ``` ### Response #### Success Response (200) - **DP** (integer) - Read depth for the SNP. - **AD_REF** (integer) - Reference allele depth for the SNP. - **AD_ALT** (integer) - Alternative allele depth for the SNP. - **GQ** (integer) - Genotype Quality for the SNP. - **SNPindex.HIGH** (numeric) - SNP index for the high bulk. - **SNPindex.LOW** (numeric) - SNP index for the low bulk. - **REF_FRQ** (numeric) - Total reference allele frequency. - **deltaSNPindex** (numeric) - The delta SNP index (SNPindex.HIGH - SNPindex.LOW). - **GStat** (numeric) - The calculated G statistic for the SNP. #### Response Example ```json { "DP": 150, "AD_REF": 120, "AD_ALT": 30, "GQ": 99, "SNPindex.HIGH": 0.8, "SNPindex.LOW": 0.2, "REF_FRQ": 0.75, "deltaSNPindex": 0.6, "GStat": 15.5 } ``` ### See Also - `getG` for explanation of how G statistic is calculated. - What is a VCF and how should I interpret it? for more information on GATK Fields and Genotype Fields ``` -------------------------------- ### Simulate Allele Frequency - R Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/simulateAlleleFreq.html Use this function to simulate alternate allele frequencies within a bulk for simulating SNP-indeces. Specify the number of individuals and the population structure. ```R simulateAlleleFreq(n, pop = "F2") ``` -------------------------------- ### getQTLTable Source: https://rdrr.io/github/bmansfeld/QTLseqR/src/R/export_functions.R Exports a summarized table of identified QTL regions. ```APIDOC ## getQTLTable ### Description Generates a summarized table of identified QTL regions, optionally exporting to a CSV file. ### Parameters #### Request Body - **SNPset** (Data frame) - Required - SNP set containing previously filtered SNPs. - **method** (string) - Required - Either "Gprime" or "QTLseq". - **alpha** (numeric) - Optional - The required false discovery rate alpha for method = "Gprime". - **interval** (numeric) - Optional - The Takagi based confidence interval for method = "QTLseq". - **export** (logical) - Optional - If TRUE, exports a csv table. - **fileName** (string) - Optional - File path or connection for output. ### Response #### Success Response (200) - **id** (integer) - The QTL identification number. - **chromosome** (string) - The chromosome on which the region was identified. - **start** (integer) - The start position of the region. - **end** (integer) - The end position of the region. - **length** (integer) - The length in basepairs. - **nSNPs** (integer) - The number of SNPs in the region. ``` -------------------------------- ### Import SNP data from GATK VariantsToTable output Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/ImportFromGATK.html Use this function to import SNP data from GATK's VariantsToTable output. It calculates total reference allele frequency, delta SNP index, and the G statistic. Ensure GATK fields CHROM and POS, and Genotype fields AD and DP are present. ```R importFromGATK(file, highBulk = character(), lowBulk = character(), chromList = NULL) ``` ```R df <- ImportFromGATK(filename = file.table, highBulk = highBulkSampleName, lowBulk = lowBulkSampleName, chromList = c("Chr1","Chr4","Chr7")) ``` -------------------------------- ### Export Summarized QTL Table Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/getQTLTable.html Use this function to export a summarized table of QTL. It supports Gprime and QTLseq methods and allows for CSV export or console output. ```R getQTLTable(SNPset, method = "Gprime", alpha = 0.05, interval = 99, export = FALSE, fileName = "QTL.csv") ``` -------------------------------- ### Run QTLseq analysis for F2 population Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/vignettes/QTLseqr.Rmd Executes the QTLseq analysis on filtered data using a specified window size and population structure. The function calculates confidence intervals based on the provided replications and bulk sizes. ```R df_filt <- runQTLseqAnalysis(df_filt, windowSize = 1e6, popStruc = "F2", bulkSize = c(385, 430), replications = 10000, intervals = c(95, 99) ) ``` ```R df_filt <- runQTLseqAnalysis( df_filt, windowSize = 1e6, popStruc = "F2", bulkSize = c(385, 430), replications = 10000, intervals = c(95, 99) ) ``` -------------------------------- ### Import SNP data from a table Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/importFromTable.html Use this function to load SNP data from a delimited file and perform initial calculations. Ensure input columns follow the required naming convention for allele depths. ```R importFromTable(file, highBulk = "HIGH", lowBulk = "LOW", chromList = NULL, sep = ",") ``` -------------------------------- ### Run G' Analysis with QTLseqR Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/runGprimeAnalysis.html This function performs the full G' analysis to identify QTL. It calculates G statistics, applies tricube smoothing, estimates p-values using a non-parametric method, and adjusts them using Benjamini-Hochberg. Use this function with a pre-filtered SNP set. ```R runGprimeAnalysis(SNPset, windowSize = 1e+06, outlierFilter = "deltaSNP", filterThreshold = 0.1, ...) ``` ```R df_filt <- runGprimeAnalysis(df_filt,windowSize = 2e6,outlierFilter = "deltaSNP") ``` -------------------------------- ### Plotting QTL Identification Parameters with plotQTLStats Source: https://rdrr.io/github/bmansfeld/QTLseqR/src/R/plotting_functions.R Use this function to plot genome-wide distributions of parameters like 'nSNPs', 'deltaSNP', 'Gprime', or 'negLog10Pval'. It requires a SNPset data frame and allows subsetting by chromosome, scaling chromosome sizes, and plotting FDR thresholds. ```R plotQTLStats <- function(SNPset, subset = NULL, var = "nSNPs", scaleChroms = TRUE, line = TRUE, plotThreshold = FALSE, plotIntervals = FALSE, q = 0.05, ...) { #get fdr threshold by ordering snps by pval then getting the last pval #with a qval < q if (!all(subset %in% unique(SNPset$CHROM))) { whichnot <- paste(subset[base::which(!subset %in% unique(SNPset$CHROM))], collapse = ', ') stop(paste0("The following are not true chromosome names: ", whichnot)) } if (!var %in% c("nSNPs", "deltaSNP", "Gprime", "negLog10Pval")) stop( "Please choose one of the following variables to plot: \"nSNPs\", \"deltaSNP\", \"Gprime\", \"negLog10Pval\" ) #don't plot threshold lines in deltaSNPprime or number of SNPs as they are not relevant if ((plotThreshold == TRUE & var == "deltaSNP") | (plotThreshold == TRUE & var == "nSNPs")) { message("FDR threshold is not plotted in deltaSNP or nSNPs plots") plotThreshold <- FALSE } #if you need to plot threshold get the FDR, but check if there are any values that pass fdr GprimeT <- 0 logFdrT <- 0 if (plotThreshold == TRUE) { fdrT <- getFDRThreshold(SNPset$pvalue, alpha = q) if (is.na(fdrT)) { warning("The q threshold is too low. No threshold line will be drawn") plotThreshold <- FALSE } else { logFdrT <- -log10(fdrT) GprimeT <- SNPset[which(SNPset$pvalue == fdrT), "Gprime"] } } SNPset <- if (is.null(subset)) { SNPset } else { SNPset[SNPset$CHROM %in% subset,] } p <- ggplot2::ggplot(data = SNPset) + ggplot2::scale_x_continuous(breaks = seq(from = 0,to = max(SNPset$POS), by = 10^(floor(log10(max(SNPset$POS))))), labels = format_genomic(), name = "Genomic Position (Mb)") + ggplot2::theme(plot.margin = ggplot2::margin( b = 10, l = 20, r = 20, unit = "pt" )) if (var == "Gprime") { threshold <- GprimeT p <- p + ggplot2::ylab("G' value") } ``` -------------------------------- ### getQTLTable Function Source: https://rdrr.io/github/bmansfeld/QTLseqR/man/getQTLTable.html Summarizes and optionally exports QTL data based on Gprime or QTLseq methods. ```APIDOC ## getQTLTable ### Description Exports a summarized table of QTL identified from a provided SNP set. ### Parameters #### Arguments - **SNPset** (data frame) - Required - Data frame SNP set containing previously filtered SNPs. - **method** (string) - Optional - Either "Gprime" or "QTLseq". The method for detecting significant regions. Default is "Gprime". - **alpha** (numeric) - Optional - The required false discovery rate alpha for use with method = "Gprime". Default is 0.05. - **interval** (numeric) - Optional - For use with method = "QTLseq". The Takagi based confidence interval requested. Default is 99. - **export** (logical) - Optional - If TRUE will export a csv table. Default is FALSE. - **fileName** (string) - Optional - Either a character string naming a file or a connection open for writing. Default is "QTL.csv". ### Response Returns a summarized table of QTL identified containing the following columns: - **id** (integer) - The QTL identification number - **chromosome** (string) - The chromosome on which the region was identified - **start** (integer) - The start position on that chromosome - **end** (integer) - The end position - **length** (integer) - The length in basepairs from start to end - **nSNPs** (integer) - The number of SNPs in the region - **avgSNPs_Mb** (numeric) - The average number of SNPs/Mb within that region - **peakDeltaSNP** (numeric) - The tricube-smoothed deltaSNP-index value at the peak summit - **posPeakDeltaSNP** (integer) - The position of the absolute maximum tricube-smoothed deltaSNP-index - **maxGprime** (numeric) - The max G' score in the region - **posMaxGprime** (integer) - The genomic position of the maximum G' value - **meanGprime** (numeric) - The average G' score of that region - **sdGprime** (numeric) - The standard deviation of G' within the region - **AUCaT** (numeric) - The Area Under the Curve but above the Threshold line - **meanPval** (numeric) - The average p-value in the region - **meanQval** (numeric) - The average adjusted p-value in the region ``` -------------------------------- ### Define Bulk and Chromosome Names Source: https://rdrr.io/github/bmansfeld/QTLseqR/f/vignettes/QTLseqr.Rmd Sets the sample names for the high and low bulks and defines a vector of chromosome names to be included in the analysis. ```R HighBulk <- "SRR834931" LowBulk <- "SRR834927" Chroms <- paste0(rep("Chr", 12), 1:12) ```