orthogene: Getting Started (original) (raw)
Installation
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
# orthogene is only available on Bioconductor>=3.14
if(BiocManager::version()<"3.14") BiocManager::install(version = "3.14")
BiocManager::install("orthogene")
library(orthogene)
data("exp_mouse")
# Setting to "homologene" for the purposes of quick demonstration.
# We generally recommend using method="gprofiler" (default).
method <- "homologene"
Examples
Convert orthologs
convert_orthologs is very flexible with what users can supply as gene_df
, and can take a data.frame
/data.table
/tibble
, (sparse) matrix
, or list
/vector
containing genes.
Genes, transcripts, proteins, SNPs, or genomic ranges will be recognised in most formats (HGNC, Ensembl, RefSeq, UniProt, etc.) and can even be a mixture of different formats.
All genes will be mapped to gene symbols, unless specified otherwise with the...
arguments (see ?orthogene::convert_orthologs
or here for details).
Note on non-1:1 orthologs
A key feature of convert_orthologs is that it handles the issue of genes with many-to-many mappings across species. This can occur due to evolutionary divergence, and the function of these genes tends to be less conserved and less translatable. Users can address this using different strategies via non121_strategy=
:
"drop_both_species"
: Drop genes that have duplicate mappings in either the input_species or output_species, (DEFAULT)."drop_input_species"
: Only drop genes that have duplicate mappings ininput_species
."drop_output_species"
: Only drop genes that have duplicate mappings in theoutput_species
."keep_both_species"
: Keep all genes regardless of whether they have duplicate mappings in either species."keep_popular"
: Return only the most “popular” interspecies ortholog mappings. This procedure tends to yield a greater number of returned genes but at the cost of many of them not being true biological 1:1 orthologs.
When gene_df
is a matrix. These strategies can be used together with agg_fun
. This feature automatically performs both ortholog aggregation (many:1 mappings) and expansion (1:many mappings) of matrices, depending on the situation. This means that you have the option to keep non-1:1 ortholog genes, and still produce a matrix with only 1 gene per row. Options include: 1. "sum"
2. "mean"
3. "median"
4. "min"
5. "max"
For more information on how orthogene
performs matrix aggregation/expansion, see the documentation for the underlying function: ?orthogene:::many2many_rows
gene_df <- orthogene::convert_orthologs(gene_df = exp_mouse,
gene_input = "rownames",
gene_output = "rownames",
input_species = "mouse",
output_species = "human",
non121_strategy = "drop_both_species",
method = method)
## Preparing gene_df.
## sparseMatrix format detected.
## Extracting genes from rownames.
## 15,259 genes extracted.
## Converting mouse ==> human orthologs using: homologene
## Retrieving all organisms available in homologene.
## Mapping species name: mouse
## Common name mapping found for mouse
## 1 organism identified from search: 10090
## Retrieving all organisms available in homologene.
## Mapping species name: human
## Common name mapping found for human
## 1 organism identified from search: 9606
## Checking for genes without orthologs in human.
## Extracting genes from input_gene.
## 13,416 genes extracted.
## Extracting genes from ortholog_gene.
## 13,416 genes extracted.
## Checking for genes without 1:1 orthologs.
## Dropping 46 genes that have multiple input_gene per ortholog_gene (many:1).
## Dropping 56 genes that have multiple ortholog_gene per input_gene (1:many).
## Filtering gene_df with gene_map
## Setting ortholog_gene to rownames.
##
## =========== REPORT SUMMARY ===========
## Total genes dropped after convert_orthologs :
## 2,016 / 15,259 (13%)
## Total genes remaining after convert_orthologs :
## 13,243 / 15,259 (87%)
knitr::kable(as.matrix(head(gene_df)))
Map species
map_species lets you standardise species names from a wide variety of identifiers (e.g. common name, taxonomy ID, Latin name, partial match).
All exposed orthogene
functions (including convert_orthologs) use map_species
under the hood, so you don’t have to worry about getting species names exactly right.
You can check the full list of available species by simply runningmap_species()
with no arguments, or checking here.
species <- orthogene::map_species(species = c("human",9544,"mus musculus",
"fruit fly","Celegans"),
output_format = "scientific_name")
## Retrieving all organisms available in homologene.
## Mapping species name: human
## Common name mapping found for human
## 1 organism identified from search: Homo sapiens
## Mapping species name: 9544
## 1 organism identified from search: Macaca mulatta
## Mapping species name: mus musculus
## 1 organism identified from search: Mus musculus
## Mapping species name: fruit fly
## Common name mapping found for fruit fly
## 1 organism identified from search: Drosophila melanogaster
## Mapping species name: Celegans
## 1 organism identified from search: Caenorhabditis elegans
print(species)
## human 9544 mus musculus
## "Homo sapiens" "Macaca mulatta" "Mus musculus"
## fruit fly Celegans
## "Drosophila melanogaster" "Caenorhabditis elegans"
Report orthologs
It may be helpful to know the maximum expected number of orthologous gene mappings from one species to another.
ortholog_report generates a report that tells you this information genome-wide.
orth_zeb <- orthogene::report_orthologs(target_species = "zebrafish",
reference_species = "human",
method_all_genes = method,
method_convert_orthologs = method)
## Gathering ortholog reports.
## Retrieving all genes using: homologene.
## Retrieving all organisms available in homologene.
## Mapping species name: human
## Common name mapping found for human
## 1 organism identified from search: 9606
## Gene table with 19,129 rows retrieved.
## Returning all 19,129 genes from human.
## Retrieving all genes using: homologene.
## Retrieving all organisms available in homologene.
## Mapping species name: zebrafish
## Common name mapping found for zebrafish
## 1 organism identified from search: 7955
## Gene table with 20,897 rows retrieved.
## Returning all 20,897 genes from zebrafish.
## --
## --
## Preparing gene_df.
## data.frame format detected.
## Extracting genes from Gene.Symbol.
## 20,897 genes extracted.
## Converting zebrafish ==> human orthologs using: homologene
## Retrieving all organisms available in homologene.
## Mapping species name: zebrafish
## Common name mapping found for zebrafish
## 1 organism identified from search: 7955
## Retrieving all organisms available in homologene.
## Mapping species name: human
## Common name mapping found for human
## 1 organism identified from search: 9606
## Checking for genes without orthologs in human.
## Extracting genes from input_gene.
## 14,768 genes extracted.
## Extracting genes from ortholog_gene.
## 14,768 genes extracted.
## Checking for genes without 1:1 orthologs.
## Dropping 46 genes that have multiple input_gene per ortholog_gene (many:1).
## Dropping 2,707 genes that have multiple ortholog_gene per input_gene (1:many).
## Filtering gene_df with gene_map
## Adding input_gene col to gene_df.
## Adding ortholog_gene col to gene_df.
##
## =========== REPORT SUMMARY ===========
## Total genes dropped after convert_orthologs :
## 10,336 / 20,895 (49%)
## Total genes remaining after convert_orthologs :
## 10,559 / 20,895 (51%)
## --
##
## =========== REPORT SUMMARY ===========
## 10,557 / 20,895 (50.52%) target_species genes remain after ortholog conversion.
## 10,557 / 19,129 (55.19%) reference_species genes remain after ortholog conversion.
knitr::kable(head(orth_zeb$map))
knitr::kable(orth_zeb$report)
Map genes
map_genes finds matching within-species synonyms across a wide variety of gene naming conventions (HGNC, Ensembl, RefSeq, UniProt, etc.) and returns a table with standardised gene symbols (or whatever output format you prefer).
genes <- c("Klf4", "Sox2", "TSPAN12","NM_173007","Q8BKT6",9999,
"ENSMUSG00000012396","ENSMUSG00000074637")
mapped_genes <- orthogene::map_genes(genes = genes,
species = "mouse",
drop_na = FALSE)
## Retrieving all organisms available in gprofiler.
## Using stored `gprofiler_orgs`.
## Mapping species name: mouse
## Common name mapping found for mouse
## 1 organism identified from search: mmusculus
## 7 / 8 (87.5%) genes mapped.
knitr::kable(head(mapped_genes))
Aggregate mapped genes
aggregate_mapped_genes
does the following:
- Uses
map_genes
to identify within-species many-to-one gene mappings (e.g. Ensembl transcript IDs ==> gene symbols). Alternatively, can map across species if output frommap_orthologs
is supplied togene_map
argument (andgene_map_col="ortholog_gene"
). - Drops all non-mappable genes.
- Aggregates the values of matrix
gene_df
using"sum"
,"mean"
,"median"
,"min"
or"max"
.
Note, this only works when the input data (gene_df
) is a sparse or dense matrix, and the genes are row names.
data("exp_mouse_enst")
knitr::kable(tail(as.matrix(exp_mouse_enst)))
exp_agg <- orthogene::aggregate_mapped_genes(gene_df=exp_mouse_enst,
input_species="mouse",
agg_fun = "sum")
## Retrieving all organisms available in gprofiler.
## Using stored `gprofiler_orgs`.
## Mapping species name: mouse
## Common name mapping found for mouse
## 1 organism identified from search: mmusculus
## 473 / 482 (98.13%) genes mapped.
## Aggregating rows using: monocle3
## Converting obj to sparseMatrix.
## Matrix aggregated:
## - Input: 482 x 7
## - Output: 92 x 7
knitr::kable(tail(as.matrix(exp_agg)))
Get all genes
You can also quickly get all known genes from the genome of a given species with all_genes.
genome_mouse <- orthogene::all_genes(species = "mouse",
method = method)
## Retrieving all genes using: homologene.
## Retrieving all organisms available in homologene.
## Mapping species name: mouse
## Common name mapping found for mouse
## 1 organism identified from search: 10090
## Gene table with 21,207 rows retrieved.
## Returning all 21,207 genes from mouse.
knitr::kable(head(genome_mouse))
Session Info
utils::sessionInfo()
## R version 4.5.0 RC (2025-04-04 r88126)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.2 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.21-bioc/R/lib/libRblas.so
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0 LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_GB LC_COLLATE=C
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: America/New_York
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] orthogene_1.14.0 BiocStyle_2.36.0
##
## loaded via a namespace (and not attached):
## [1] gtable_0.3.6 babelgene_22.9
## [3] xfun_0.52 bslib_0.9.0
## [5] ggplot2_3.5.2 htmlwidgets_1.6.4
## [7] rstatix_0.7.2 lattice_0.22-7
## [9] bitops_1.0-9 vctrs_0.6.5
## [11] tools_4.5.0 generics_0.1.3
## [13] yulab.utils_0.2.0 parallel_4.5.0
## [15] tibble_3.2.1 pkgconfig_2.0.3
## [17] Matrix_1.7-3 data.table_1.17.0
## [19] homologene_1.4.68.19.3.27 ggplotify_0.1.2
## [21] lifecycle_1.0.4 compiler_4.5.0
## [23] farver_2.1.2 treeio_1.32.0
## [25] tinytex_0.57 munsell_0.5.1
## [27] carData_3.0-5 ggtree_3.16.0
## [29] ggfun_0.1.8 gprofiler2_0.2.3
## [31] htmltools_0.5.8.1 sass_0.4.10
## [33] RCurl_1.98-1.17 yaml_2.3.10
## [35] lazyeval_0.2.2 Formula_1.2-5
## [37] plotly_4.10.4 pillar_1.10.2
## [39] car_3.1-3 ggpubr_0.6.0
## [41] jquerylib_0.1.4 tidyr_1.3.1
## [43] cachem_1.1.0 grr_0.9.5
## [45] magick_2.8.6 abind_1.4-8
## [47] nlme_3.1-168 tidyselect_1.2.1
## [49] aplot_0.2.5 digest_0.6.37
## [51] dplyr_1.1.4 purrr_1.0.4
## [53] bookdown_0.43 labeling_0.4.3
## [55] fastmap_1.2.0 grid_4.5.0
## [57] colorspace_2.1-1 cli_3.6.4
## [59] magrittr_2.0.3 patchwork_1.3.0
## [61] broom_1.0.8 ape_5.8-1
## [63] withr_3.0.2 scales_1.3.0
## [65] backports_1.5.0 httr_1.4.7
## [67] rmarkdown_2.29 ggsignif_0.6.4
## [69] evaluate_1.0.3 knitr_1.50
## [71] viridisLite_0.4.2 gridGraphics_0.5-1
## [73] rlang_1.1.6 Rcpp_1.0.14
## [75] glue_1.8.0 tidytree_0.4.6
## [77] BiocManager_1.30.25 jsonlite_2.0.0
## [79] R6_2.6.1 fs_1.6.6