Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jromanowska/HaplinMethyl
Browse files Browse the repository at this point in the history
  • Loading branch information
jromanowska committed Sep 28, 2021
2 parents 9d556d1 + 4150b9b commit 8ed5766
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions R/findCpGsnearSNP.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
#' Finding CpGs near a SNP
#'
#' This is a basic function for searching for CpGs in the vicinity of a given SNP
#' @description
#' This is a basic function for searching for CpGs in the vicinity of a given
#' SNP.
#'
#' Given a position and chromosome number of a SNP, along with a table of
#' positions of CpGs in this chromosome, the function will return a data.frame
#' with nearby CpGs (within a given limit).
#' @details
#' Given the position and chromosome number of a SNP, along with the positions
#' of CpGs on the same chromosome, the function will return a data.frame with
#' nearby CpGs (within a given number of base pairs).
#'
#' **Please note** that you should ensure that every CpG in `cpgs` and the SNP
#' in `snp` are located on the same chromosome.
#'
#' @param snp A named list with SNP name ("marker"), chromosome no. ("chr")
#' @param snp A named list with the SNP's name ("marker"), chromosome no. ("chr")
#' and coordinate ("coord").
#' @param cpgs A table with all CpGs in a given chromosome, with the columns
#' named: "id", "coord".
#' @param range Number giving the maximum distance from the SNP where the
#' function will look for CpGs; default: 5000 (base pairs).
#' @param verbose Whether to display extra info about each SNP (default: FALSE).
#' @param cpgs A list or data.frame containing all CpGs on the chromosome where
#' the SNP is located. Must contain only two elements/columns: one named "id"
#' (unique CpG locus cluster ID, cg#) and one named "coord" (coordinate of CpG
#' locus).
#' @param range An integer specifying the desired maximum number of base pairs
#' between the given SNP and CpGs. The default is 5000. The search for CpGs is
#' restricted to the interval (snp$coord - range, snp$coord + range).
#' @param verbose Whether to print information about the result when available
#' (default: FALSE).
#'
#' @return A data.frame with CpGs with columns named: "id", "coord".
#'
Expand All @@ -28,8 +38,20 @@ findCpGsnearSNP <- function( snp = stop( "'snp' is required!", call. = FALSE ),
including the marker name ('marker'), chromosome number ('chr'),
and the coordinate ('coord').", call. = FALSE )
}
if( is.recursive( cpgs ) == FALSE ){
stop( "The given argument 'cpgs' is not compatible with the $ operator.
'cpgs' must be a recursive (list-like) object such as a data frame,
list or tibble."
, call. = FALSE )
}
if( !( length(names( cpgs )) == 2) ){
stop( paste( "The given 'cpgs' must be a list or data.frame with exactly 2",
"elements or columns!"),
call. = FALSE )
}
if( !all(names( cpgs ) %in% c( "id", "coord" )) ){
stop( "The given 'cpg' must be a data.frame with the columns named 'id' and 'coord'!",
stop( paste( "The given 'cpgs' must be a list or data.frame with exactly 2",
"elements or columns named 'id' and 'coord'!"),
call. = FALSE )
}

Expand Down

0 comments on commit 8ed5766

Please sign in to comment.