Project: s41467-024-44709-1 | Function: colocFunction_jp (r)

system: You are an expert R programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow R best practices and maintain consistent code style.
Return **only** the complete R function code.

user: Complete this R function:

**DESCRIPTION:** Performs colocalization analysis between two traits using the coloc package. Matches SNPs between datasets, checks allele consistency, and calculates posterior probabilities for different hypotheses (H0-H4) to determine if the same causal variant underlies both trait associations.

**KEY TERMS:** {
  "tab1": "GWAS dataset 1",
  "tab2": "GWAS/eQTL dataset 2",
  "PP(H4)": "posterior probability of shared causal variant",
  "beta": "effect size",
  "se": "standard error",
  "MAF": "minor allele frequency"
}

**CONTEXT CODE:** #' @param col_N column name for sample size, Default: 'n_samples'
#' @param col_MAF column name for minor allele frequency, Default: 'maf'
#' @return first entry of coloc.abf result: vector giving the number of SNPs analysed, and the posterior probabilities of H0 (no causal variant), H1 (causal variant for trait 1 only), H2 (causal variant for trait 2 only), H3 (two distinct causal variants) and H4 (one common causal variant)
#' @details see [coloc](https://cran.r-project.org/web/packages/coloc/index.html) package for more information:
#' @examples
#' \dontrun{
#' if(interactive()){
#'  #EXAMPLE1
#'  }
#' }
#' @seealso
#'  \code{\link[data.table]{setcolorder}}
#'  \code{\link[coloc]{coloc.abf}}
#' @rdname colocFunction_jp
#' @export
#' @importFrom data.table setcolorder
#' @importFrom coloc coloc.abf
#' @title Function to perform a co-localization test
#' @description This function takes two locus-wide summary statistic sets and matches them by ID as provided. Then, it tests for co-localization using beta, se, sample size, MAF, and ID. If the plotting option is TRUE, then a co-localization plot is generated and the coloc result is included in the sub title. Both data sets need to have the same columns!
#' @param tab1 data set for trait 1
#' @param tab2 data set for trait 2
#' @param trait1 phenotype name for trait 1, Default: 'trait1'
#' @param trait2 phenotype name for trait 2, Default: 'trait2'
#' @param locus cytoband of tested region; will be used to label the X axis of the coloc plot, Default: 'cytoband'
#' @param locus_name gene name of tested region (e.g., if some specific eQTL-coloc is done); will be used in title of the coloc plot, Default: 'gene'
#' @param plotting should a plot be created?, Default: F
#' @param col_SNPID column name for matching, Default: 'markername'
#' @param col_pos column name for base position, Default: 'pos'
#' @param col_beta column name for beta estimate, Default: 'beta'
#' @param col_se column name for standard error, Default: 'se'
#' @param col_P column name for p-value (used for plotting), Default: 'pval'
#' @param col_N column name for sample size, Default: 'n_samples'
#' @param col_MAF column name for minor allele frequency, Default: 'maf'
#' @param col_effect column name for effect allele, Default: 'effect_allele'
#' @param col_other column name for other allele, Default: 'other_allele'
#' @return first entry of coloc.abf result: vector giving the number of SNPs analysed, and the posterior probabilities of H0 (no causal variant), H1 (causal variant for trait 1 only), H2 (causal variant for trait 2 only), H3 (two distinct causal variants), and H4 (one common causal variant)
#' @details see [coloc](https://cran.r-project.org/web/packages/coloc/index.html) package for more information:
#' @examples
#' \dontrun{
#' if(interactive()){
#'  #EXAMPLE1
#'  }
#' }
#' @seealso
#'  \code{\link[data.table]{setcolorder}}
#'  \code{\link[coloc]{coloc.abf}}
#' @rdname colocFunction_jp
#' @export
#' @importFrom data.table setcolorder
#' @importFrom coloc coloc.abf
colocFunction_jp <- function(tab1, tab2, trait1 = "trait1", trait2 = "trait2", locus = "cytoband", locus_name = "gene",
                             plotting = FALSE, col_SNPID = "markername", col_pos = "pos", col_beta = "beta",
                             col_se = "se", col_P = "pval", col_N = "n_samples", col_MAF = "maf", col_effect = "effect_allele",
                             col_other = "other_allele") {
  stop("Function implementation has been masked")
}

# Example usage (uncomment to run)
# if(interactive()){
#    # EXAMPLE1
#    tab1 <- data.table(...)
#    tab2 <- data.table(...)
#    result <- colocFunction_jp(tab1, tab2)
#    print(result)
# }
```

This function performs the specified colocalization analysis and provides the necessary posterior probabilities for different hypotheses. It handles the matching of SNPs, optional allele consistency checks, and plotting if requested.


Complete the function implementation replacing "stop("Not implemented")".