Skip to content

Commit

Permalink
Issue 109 a:
Browse files Browse the repository at this point in the history
- Created R/accnum.R
- Added up2ncbi
-  Added documentation in roxygen
  • Loading branch information
Klangina committed Oct 23, 2024
1 parent 7613887 commit 4aa79e0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions R/accnum.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@




#' Convert a UniProt ID to an NCBI Entrez Gene ID
#'
#' This function takes a single UniProt ID and returns the corresponding NCBI Entrez Gene ID.
#' It uses the `org.Hs.eg.db` package to perform the mapping.
#'
#' @author Klangina
#' @param uniprot_id A string representing a single UniProt ID.
#' @return A string representing the corresponding NCBI Entrez Gene ID. Returns `NA` if no mapping is found.
#' @examples
#' \dontrun{
#' uniprot_id <- "P04217"
#' entrez_id <- up2ncbi(uniprot_id)
#' print(entrez_id)
#' }
#' @importFrom AnnotationDbi select
#' @import org.Hs.eg.db
#' @export
up2ncbi <- function(uniprot_id) {
# Use the select function to map the UniProt ID to an Entrez Gene ID
result <- AnnotationDbi::select(org.Hs.eg.db,
keys = uniprot_id,
columns = "ENTREZID",
keytype = "UNIPROT")

# Check if the result is not empty and return the first Entrez ID
if (nrow(result) > 0 && !is.na(result$ENTREZID[1])) {
return(as.character(result$ENTREZID[1]))
} else {
return(NA) # Return NA if no mapping is found
}
}

0 comments on commit 4aa79e0

Please sign in to comment.