Skip to content

Commit

Permalink
Issue-#109-b:
Browse files Browse the repository at this point in the history
- Added ncbi2up to  R/accnum.R
-  Added documentation in roxygen
  • Loading branch information
Klangina committed Oct 23, 2024
1 parent a4c01c1 commit 9bc2ded
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions R/accnum.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,37 @@ up2ncbi <- function(uniprot_id) {
} else {
return(NA) # Return NA if no mapping is found
}
}



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

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

0 comments on commit 9bc2ded

Please sign in to comment.