Skip to content

Commit a4c01c1

Browse files
committed
Issue-#109 a:
- Created R/accnum.R - Added up2ncbi - Added documentation in roxygen
1 parent 7613887 commit a4c01c1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

R/accnum.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
3+
4+
5+
#' Convert a UniProt ID to an NCBI Entrez Gene ID
6+
#'
7+
#' This function takes a single UniProt ID and returns the corresponding NCBI Entrez Gene ID.
8+
#' It uses the `org.Hs.eg.db` package to perform the mapping.
9+
#'
10+
#' @author Klangina
11+
#' @param uniprot_id A string representing a single UniProt ID.
12+
#' @return A string representing the corresponding NCBI Entrez Gene ID. Returns `NA` if no mapping is found.
13+
#' @examples
14+
#' \dontrun{
15+
#' uniprot_id <- "P04217"
16+
#' entrez_id <- up2ncbi(uniprot_id)
17+
#' print(entrez_id)
18+
#' }
19+
#' @importFrom AnnotationDbi select
20+
#' @import org.Hs.eg.db
21+
#' @export
22+
up2ncbi <- function(uniprot_id) {
23+
# Use the select function to map the UniProt ID to an Entrez Gene ID
24+
result <- AnnotationDbi::select(org.Hs.eg.db,
25+
keys = uniprot_id,
26+
columns = "ENTREZID",
27+
keytype = "UNIPROT")
28+
29+
# Check if the result is not empty and return the first Entrez ID
30+
if (nrow(result) > 0 && !is.na(result$ENTREZID[1])) {
31+
return(as.character(result$ENTREZID[1]))
32+
} else {
33+
return(NA) # Return NA if no mapping is found
34+
}
35+
}

0 commit comments

Comments
 (0)