Skip to content

Commit

Permalink
Bug fix: handle cases where no genes found in species
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Murphy committed Oct 27, 2023
1 parent 2b14d25 commit 2e5081f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 43 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Bug fixes

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

# orthogene 1.7.3

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)
})

0 comments on commit 2e5081f

Please sign in to comment.