Skip to content

Commit

Permalink
Merge pull request #38 from Al-Murphy/main
Browse files Browse the repository at this point in the history
Bug fix: handle cases where no genes found in species
  • Loading branch information
bschilder authored Dec 21, 2023
2 parents 4c643d5 + d5eb75c commit 38ab713
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 43 deletions.
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)
})

0 comments on commit 38ab713

Please sign in to comment.