From ae8ae387087d5784039860dd93f914af47e7886c Mon Sep 17 00:00:00 2001 From: Clare <chorscroft@users.noreply.github.com> Date: Thu, 12 Mar 2020 11:47:39 +0000 Subject: [PATCH] Include a call to na.omit when checking for biallelic snps --- NAMESPACE | 1 + R/Zalpha_BetaCDF.R | 4 ++-- R/Zalpha_Zscore.R | 4 ++-- R/Zalpha_all.R | 4 ++-- R/Zalpha_log_rsq_over_expected.R | 4 ++-- R/Zalpha_rsq_over_expected.R | 4 ++-- R/Zbeta.R | 4 ++-- R/Zbeta_BetaCDF.R | 4 ++-- R/Zbeta_Zscore.R | 4 ++-- R/Zbeta_log_rsq_over_expected.R | 4 ++-- R/Zbeta_rsq_over_expected.R | 4 ++-- R/zalpha.R | 4 ++-- 12 files changed, 23 insertions(+), 22 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index eefcaa1..bf0d578 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,4 +16,5 @@ export(Zbeta_expected) export(Zbeta_log_rsq_over_expected) export(Zbeta_rsq_over_expected) importFrom(stats,cor) +importFrom(stats,na.omit) importFrom(stats,pbeta) diff --git a/R/Zalpha_BetaCDF.R b/R/Zalpha_BetaCDF.R index 69cf1b7..69442fa 100644 --- a/R/Zalpha_BetaCDF.R +++ b/R/Zalpha_BetaCDF.R @@ -16,7 +16,7 @@ #' profile should consist of evenly sized bins of distances (for example 0.0001 cM per bin), where the value given is the (inclusive) lower #' bound of the bin. #' -#' @importFrom stats cor pbeta +#' @importFrom stats cor pbeta na.omit #' #' @param pos A numeric vector of SNP locations #' @param ws The window size which the \eqn{Z_{\alpha}^{BetaCDF}}{Zalpha} statistic will be calculated over. This should be on the same scale as the \code{pos} vector. @@ -60,7 +60,7 @@ Zalpha_BetaCDF<-function(pos, ws, x, dist, LDprofile_bins, LDprofile_Beta_a, LDp stop("The number of rows in x must equal the number of SNP locations given in pos") } #Check SNPs are all biallelic - if(sum(apply(x,1,function(x){length(unique(x))}) != 2)>0){ + if(sum(apply(x,1,function(x){length(na.omit(unique(x)))}) != 2)>0){ stop("SNPs must all be biallelic") } #Check dist is a numeric vector diff --git a/R/Zalpha_Zscore.R b/R/Zalpha_Zscore.R index f044925..0f57e56 100644 --- a/R/Zalpha_Zscore.R +++ b/R/Zalpha_Zscore.R @@ -15,7 +15,7 @@ #' profile should consist of evenly sized bins of distances (for example 0.0001 cM per bin), where the value given is the (inclusive) lower #' bound of the bin. #' -#' @importFrom stats cor +#' @importFrom stats cor na.omit #' #' @param pos A numeric vector of SNP locations #' @param ws The window size which the \eqn{Z_{\alpha}^{Zscore}}{Zalpha} statistic will be calculated over. This should be on the same scale as the \code{pos} vector. @@ -59,7 +59,7 @@ Zalpha_Zscore<-function(pos, ws, x, dist, LDprofile_bins, LDprofile_rsq, LDprofi stop("The number of rows in x must equal the number of SNP locations given in pos") } #Check SNPs are all biallelic - if(sum(apply(x,1,function(x){length(unique(x))}) != 2)>0){ + if(sum(apply(x,1,function(x){length(na.omit(unique(x)))}) != 2)>0){ stop("SNPs must all be biallelic") } #Check dist is a numeric vector diff --git a/R/Zalpha_all.R b/R/Zalpha_all.R index 30d81a8..b6a40be 100644 --- a/R/Zalpha_all.R +++ b/R/Zalpha_all.R @@ -13,7 +13,7 @@ #' } #' For more information about the statistics, please see Jacobs (2016). #' -#' @importFrom stats cor pbeta +#' @importFrom stats cor pbeta na.omit #' #' @param pos A numeric vector of SNP locations #' @param ws The window size which the statistics will be calculated over. This should be on the same scale as the \code{pos} vector. @@ -65,7 +65,7 @@ Zalpha_all <- function(pos, ws, x=NULL, dist=NULL, LDprofile_bins=NULL, LDprofil stop("The number of rows in x must equal the number of SNP locations given in pos") } #Check SNPs are all biallelic - if(sum(apply(x,1,function(x){length(unique(x))}) != 2)>0){ + if(sum(apply(x,1,function(x){length(na.omit(unique(x)))}) != 2)>0){ stop("SNPs must all be biallelic") } #Change matrix x to numeric if it isn't already diff --git a/R/Zalpha_log_rsq_over_expected.R b/R/Zalpha_log_rsq_over_expected.R index 09e2a6b..18a1141 100644 --- a/R/Zalpha_log_rsq_over_expected.R +++ b/R/Zalpha_log_rsq_over_expected.R @@ -15,7 +15,7 @@ #' profile should consist of evenly sized bins of distances (for example 0.0001 cM per bin), where the value given is the (inclusive) lower #' bound of the bin. #' -#' @importFrom stats cor +#' @importFrom stats cor na.omit #' #' @param pos A numeric vector of SNP locations #' @param ws The window size which the \eqn{Z_{\alpha}^{log_{10}(r^2/E[r^2])}}{Zalpha} statistic will be calculated over. This should be on the same scale as the \code{pos} vector. @@ -58,7 +58,7 @@ Zalpha_log_rsq_over_expected<-function(pos, ws, x, dist, LDprofile_bins, LDprofi stop("The number of rows in x must equal the number of SNP locations given in pos") } #Check SNPs are all biallelic - if(sum(apply(x,1,function(x){length(unique(x))}) != 2)>0){ + if(sum(apply(x,1,function(x){length(na.omit(unique(x)))}) != 2)>0){ stop("SNPs must all be biallelic") } #Check dist is a numeric vector diff --git a/R/Zalpha_rsq_over_expected.R b/R/Zalpha_rsq_over_expected.R index bffcbc7..7e8ef5d 100644 --- a/R/Zalpha_rsq_over_expected.R +++ b/R/Zalpha_rsq_over_expected.R @@ -15,7 +15,7 @@ #' profile should consist of evenly sized bins of distances (for example 0.0001 cM per bin), where the value given is the (inclusive) lower #' bound of the bin. #' -#' @importFrom stats cor +#' @importFrom stats cor na.omit #' #' @param pos A numeric vector of SNP locations #' @param ws The window size which the \eqn{Z_{\alpha}^{r^2/E[r^2]}}{Zalpha} statistic will be calculated over. This should be on the same scale as the \code{pos} vector. @@ -58,7 +58,7 @@ Zalpha_rsq_over_expected<-function(pos, ws, x, dist, LDprofile_bins, LDprofile_r stop("The number of rows in x must equal the number of SNP locations given in pos") } #Check SNPs are all biallelic - if(sum(apply(x,1,function(x){length(unique(x))}) != 2)>0){ + if(sum(apply(x,1,function(x){length(na.omit(unique(x)))}) != 2)>0){ stop("SNPs must all be biallelic") } #Check dist is a numeric vector diff --git a/R/Zbeta.R b/R/Zbeta.R index 3ed2dfe..8b9a5f0 100644 --- a/R/Zbeta.R +++ b/R/Zbeta.R @@ -7,7 +7,7 @@ #' \deqn{Z_{\beta}=\frac{\sum_{i \in L,j \in R}r^2_{i,j}}{|L||R|}} #' where \code{|L|} and \code{|R|} are the number of SNPs to the left and right of the current locus within the given window \code{ws}, and \eqn{r^2}{r^2} is equal to the squared correlation between a pair of SNPs #' -#' @importFrom stats cor +#' @importFrom stats cor na.omit #' #' @param pos A numeric vector of SNP locations #' @param ws The window size which the \eqn{Z_{\beta}}{Zbeta} statistic will be calculated over. This should be on the same scale as the \code{pos} vector. @@ -44,7 +44,7 @@ Zbeta <- function(pos, ws, x, minRandL = 4, minRL = 25, X = NULL) { stop("The number of rows in x must equal the number of SNP locations given in pos") } #Check SNPs are all biallelic - if(sum(apply(x,1,function(x){length(unique(x))}) != 2)>0){ + if(sum(apply(x,1,function(x){length(na.omit(unique(x)))}) != 2)>0){ stop("SNPs must all be biallelic") } #Check windowsize is a number greater than 0 diff --git a/R/Zbeta_BetaCDF.R b/R/Zbeta_BetaCDF.R index a67ae22..1908284 100644 --- a/R/Zbeta_BetaCDF.R +++ b/R/Zbeta_BetaCDF.R @@ -16,7 +16,7 @@ #' profile should consist of evenly sized bins of distances (for example 0.0001 cM per bin), where the value given is the (inclusive) lower #' bound of the bin. #' -#' @importFrom stats cor pbeta +#' @importFrom stats cor pbeta na.omit #' #' @param pos A numeric vector of SNP locations #' @param ws The window size which the \eqn{Z_{\beta}^{BetaCDF}}{Zbeta} statistic will be calculated over. This should be on the same scale as the \code{pos} vector. @@ -60,7 +60,7 @@ Zbeta_BetaCDF<-function(pos, ws, x, dist, LDprofile_bins, LDprofile_Beta_a, LDpr stop("The number of rows in x must equal the number of SNP locations given in pos") } #Check SNPs are all biallelic - if(sum(apply(x,1,function(x){length(unique(x))}) != 2)>0){ + if(sum(apply(x,1,function(x){length(na.omit(unique(x)))}) != 2)>0){ stop("SNPs must all be biallelic") } #Check dist is a numeric vector diff --git a/R/Zbeta_Zscore.R b/R/Zbeta_Zscore.R index 29ba79e..76eda7d 100644 --- a/R/Zbeta_Zscore.R +++ b/R/Zbeta_Zscore.R @@ -15,7 +15,7 @@ #' profile should consist of evenly sized bins of distances (for example 0.0001 cM per bin), where the value given is the (inclusive) lower #' bound of the bin. #' -#' @importFrom stats cor +#' @importFrom stats cor na.omit #' #' @param pos A numeric vector of SNP locations #' @param ws The window size which the \eqn{Z_{\beta}^{Zscore}}{Zbeta} statistic will be calculated over. This should be on the same scale as the \code{pos} vector. @@ -59,7 +59,7 @@ Zbeta_Zscore<-function(pos, ws, x, dist, LDprofile_bins, LDprofile_rsq, LDprofil stop("The number of rows in x must equal the number of SNP locations given in pos") } #Check SNPs are all biallelic - if(sum(apply(x,1,function(x){length(unique(x))}) != 2)>0){ + if(sum(apply(x,1,function(x){length(na.omit(unique(x)))}) != 2)>0){ stop("SNPs must all be biallelic") } #Check dist is a numeric vector diff --git a/R/Zbeta_log_rsq_over_expected.R b/R/Zbeta_log_rsq_over_expected.R index e257c67..7e8bbec 100644 --- a/R/Zbeta_log_rsq_over_expected.R +++ b/R/Zbeta_log_rsq_over_expected.R @@ -15,7 +15,7 @@ #' profile should consist of evenly sized bins of distances (for example 0.0001 cM per bin), where the value given is the (inclusive) lower #' bound of the bin. #' -#' @importFrom stats cor +#' @importFrom stats cor na.omit #' #' @param pos A numeric vector of SNP locations #' @param ws The window size which the \eqn{Z_{\beta}^{log_{10}(r^2/E[r^2])}}{Zbeta} statistic will be calculated over. This should be on the same scale as the \code{pos} vector. @@ -58,7 +58,7 @@ Zbeta_log_rsq_over_expected<-function(pos, ws, x, dist, LDprofile_bins, LDprofil stop("The number of rows in x must equal the number of SNP locations given in pos") } #Check SNPs are all biallelic - if(sum(apply(x,1,function(x){length(unique(x))}) != 2)>0){ + if(sum(apply(x,1,function(x){length(na.omit(unique(x)))}) != 2)>0){ stop("SNPs must all be biallelic") } #Check dist is a numeric vector diff --git a/R/Zbeta_rsq_over_expected.R b/R/Zbeta_rsq_over_expected.R index 30bb6a0..af0262d 100644 --- a/R/Zbeta_rsq_over_expected.R +++ b/R/Zbeta_rsq_over_expected.R @@ -15,7 +15,7 @@ #' profile should consist of evenly sized bins of distances (for example 0.0001 cM per bin), where the value given is the (inclusive) lower #' bound of the bin. #' -#' @importFrom stats cor +#' @importFrom stats cor na.omit #' #' @param pos A numeric vector of SNP locations #' @param ws The window size which the \eqn{Z_{\beta}^{r^2/E[r^2]}}{Zbeta} statistic will be calculated over. This should be on the same scale as the \code{pos} vector. @@ -58,7 +58,7 @@ Zbeta_rsq_over_expected<-function(pos, ws, x, dist, LDprofile_bins, LDprofile_rs stop("The number of rows in x must equal the number of SNP locations given in pos") } #Check SNPs are all biallelic - if(sum(apply(x,1,function(x){length(unique(x))}) != 2)>0){ + if(sum(apply(x,1,function(x){length(na.omit(unique(x)))}) != 2)>0){ stop("SNPs must all be biallelic") } #Check dist is a numeric vector diff --git a/R/zalpha.R b/R/zalpha.R index c7cc51d..c9c1fde 100644 --- a/R/zalpha.R +++ b/R/zalpha.R @@ -7,7 +7,7 @@ #' \deqn{Z_{\alpha}=\frac{{|L| \choose 2}^{-1}\sum_{i,j \in L}r^2_{i,j} + {|R| \choose 2}^{-1}\sum_{i,j \in L}r^2_{i,j}}{2}} #' where \code{|L|} and \code{|R|} are the number of SNPs to the left and right of the current locus within the given window \code{ws}, and \eqn{r^2}{r^2} is equal to the squared correlation between a pair of SNPs #' -#' @importFrom stats cor +#' @importFrom stats cor na.omit #' #' @param pos A numeric vector of SNP locations #' @param ws The window size which the \eqn{Z_{\alpha}}{Zalpha} statistic will be calculated over. This should be on the same scale as the \code{pos} vector. @@ -44,7 +44,7 @@ Zalpha <- function(pos, ws, x, minRandL = 4, minRL = 25, X = NULL) { stop("The number of rows in x must equal the number of SNP locations given in pos") } #Check SNPs are all biallelic - if(sum(apply(x,1,function(x){length(unique(x))}) != 2)>0){ + if(sum(apply(x,1,function(x){length(na.omit(unique(x)))}) != 2)>0){ stop("SNPs must all be biallelic") } #Check windowsize is a number greater than 0 -- GitLab