% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/convertGene.R
\name{convertGene}
\alias{convertGene}
\title{Convert Ensembl or Entrez Gene IDs to KEGG Gene IDs and KO Terms}
\usage{
convertGene(genes, gene_type = c("ensembl", "entrez"), orthology = TRUE)
}
\arguments{
\item{genes}{A character vector of gene IDs. All IDs must be of the same type,
specified by \code{gene_type}.}

\item{gene_type}{Type of gene ID supplied. One of \code{"ensembl"} or
\code{"entrez"}.}

\item{orthology}{Logical; if \code{TRUE} (default), KEGG gene IDs are further
mapped to KO IDs.}
}
\value{
A \code{data.frame} with columns:
\itemize{
\item \code{Input_ID}: original gene ID (Ensembl or Entrez).
\item \code{Entrez_ID}: mapped Entrez ID, or \code{"unmapped"}.
\item \code{KEGG_ID}: mapped KEGG gene ID, or \code{"unmapped"}.
\item \code{KO_ID}: mapped KEGG Orthology ID, or \code{"unmapped"}
(present only when \code{orthology = TRUE}).
}
}
\description{
Converts Ensembl or Entrez gene identifiers to KEGG gene IDs and,
optionally, to KEGG Orthology (KO) IDs using \pkg{mygene} and
\pkg{KEGGREST}. The input gene type must be specified.
}
\details{
This function supports integration of commonly used gene identifier systems
(Ensembl/Entrez) into KO-based and KEGG network workflows.

The returned data frame keeps all input IDs, including those that cannot
be mapped; unmapped entries are labelled as \code{"unmapped"} in the
corresponding columns. This is useful when building KO- or pathway-centric
views of host genes, for example in tryptophan–kynurenine metabolism or
other immune–metabolic axes.

\itemize{
\item Only one gene type can be used per call; mixed Ensembl/Entrez input
must be split beforehand.
\item When \code{gene_type = "ensembl"}, Ensembl IDs are first converted to
Entrez IDs using \pkg{mygene}, then mapped to KEGG gene IDs via
\pkg{KEGGREST}.
\item When \code{gene_type = "entrez"}, input IDs are checked for a numeric
pattern; non-numeric entries are retained and marked as
\code{"unmapped"}.
\item KEGG gene IDs are optionally mapped to KO terms using
\code{\link[KEGGREST]{keggLink}} when \code{orthology = TRUE}.
\item If any step fails (no Entrez, no KEGG gene, or no KO), the
corresponding field is set to \code{"unmapped"}; no rows are dropped.
}
}
\examples{
## Example 1 — Ensembl IDs for human tryptophan–kynurenine genes
trp_kynurenine_ens <- c("ENSG00000151790", "ENSG00000131203")

convertGene(
  genes      = trp_kynurenine_ens,
  gene_type  = "ensembl",
  orthology  = TRUE
)

## Example 2 — Entrez IDs linked to downstream MetaPathNet network use
## Human enzymes TDO2 (6999) and IDO1 (3620), plus tnaA (948221; a typical microbial enzyme),
## are included here to illustrate how converted KO terms can be checked in a human network.
trp_kynurenine_genes <- c("6999", "3620", "948221")

trp_kyn_conversion <- convertGene(
  genes      = trp_kynurenine_genes,
  gene_type  = "entrez",
  orthology  = TRUE
)

}
\seealso{
\code{\link{findKeggIDs}}
}
