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

Bug fix: handle cases where no genes found in species #38

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* Bump version for Bioc 3.19.
* Use GHCR instead of Dockerhub, update vignette accordingly.

## Bug fixes

* Catch case where no genes are found in the species in `map_genes()` & test
case added.

# orthogene 1.7.3

## New features
Expand Down
4 changes: 3 additions & 1 deletion R/map_genes.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ map_genes <- function(genes,
)
}
#### Drop NAs ####
if (isTRUE(drop_na)) {
# !is.null(syn_map) catches where no hit genes are found in the species
# otherwise map_genes() will give an error rather than returning NULL
if (isTRUE(drop_na) && !is.null(syn_map)) {
syn_map <- remove_all_nas(
dat = syn_map,
col_name = "name",
Expand Down
87 changes: 45 additions & 42 deletions R/map_orthologs.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,48 +56,51 @@ map_orthologs <- function(genes,
)
genes <- syn_map$name
}
#### Select mapping method ####
#### User-supplied mapping ####
if(!is.null(gene_map)){
gene_map <- map_orthologs_custom(gene_map = gene_map,
input_species = input_species,
output_species = output_species,
input_col = input_col,
output_col = output_col,
verbose = verbose)
}
# Both methods will return a dataframe with at least the columns
# "input_gene" and "ortholog_gene"
#### gprofiler ####
if (methods_opts(method = method, gprofiler_opts = TRUE)) {
gene_map <- map_orthologs_gprofiler(
genes = genes,
input_species = input_species,
output_species = output_species,
mthreshold = mthreshold,
verbose = verbose,
...
)
}
#### homologene ####
if (methods_opts(method = method, homologene_opts = TRUE)) {
gene_map <- map_orthologs_homologene(
genes = genes,
input_species = input_species,
output_species = output_species,
verbose = verbose,
...
)
}
#### babelgene ####
if (methods_opts(method = method, babelgene_opts = TRUE)) {
gene_map <- map_orthologs_babelgene(
genes = genes,
input_species = input_species,
output_species = output_species,
verbose = verbose,
...
)
#deal with case where no genes found for species
if(!is.null(genes)){
#### Select mapping method ####
#### User-supplied mapping ####
if(!is.null(gene_map)){
gene_map <- map_orthologs_custom(gene_map = gene_map,
input_species = input_species,
output_species = output_species,
input_col = input_col,
output_col = output_col,
verbose = verbose)
}
# Both methods will return a dataframe with at least the columns
# "input_gene" and "ortholog_gene"
#### gprofiler ####
if (methods_opts(method = method, gprofiler_opts = TRUE)) {
gene_map <- map_orthologs_gprofiler(
genes = genes,
input_species = input_species,
output_species = output_species,
mthreshold = mthreshold,
verbose = verbose,
...
)
}
#### homologene ####
if (methods_opts(method = method, homologene_opts = TRUE)) {
gene_map <- map_orthologs_homologene(
genes = genes,
input_species = input_species,
output_species = output_species,
verbose = verbose,
...
)
}
#### babelgene ####
if (methods_opts(method = method, babelgene_opts = TRUE)) {
gene_map <- map_orthologs_babelgene(
genes = genes,
input_species = input_species,
output_species = output_species,
verbose = verbose,
...
)
}
}
#### Check is already in the same species ####
if(isFALSE(standardise_genes) &&
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-map_genes.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ test_that("map_genes works", {
testthat::expect_gte(nrow(mapped_human), 3)
testthat::expect_gte(nrow(mapped_mouse), total_genes)
testthat::expect_gte(nrow(mapped_zebrafish), 3)

#### Test where genes aren't found in species ####
#should return NULL not fail
genes <- c("a",'list','of','fake','genes')
spec_hits <- map_genes(
genes = genes,
species = 'yeast',
drop_na = TRUE,
verbose = FALSE)$name
testthat::expect_null(spec_hits)
})
Loading