-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Created R/accnum.R - Added up2ncbi - Added documentation in roxygen
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |