Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 109 a: #110

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions R/accnum.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@




#' 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
}
}



#' 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
}
}