Skip to content
Snippets Groups Projects
Commit ae8ae387 authored by Clare's avatar Clare
Browse files

Include a call to na.omit when checking for biallelic snps

parent 5077604e
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment