diff --git a/NEWS.md b/NEWS.md index f204ea1..3c101a6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/map_genes.R b/R/map_genes.R index 279225b..aa990a0 100644 --- a/R/map_genes.R +++ b/R/map_genes.R @@ -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", diff --git a/R/map_orthologs.R b/R/map_orthologs.R index bb69a8b..bbcd488 100644 --- a/R/map_orthologs.R +++ b/R/map_orthologs.R @@ -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) && diff --git a/tests/testthat/test-map_genes.R b/tests/testthat/test-map_genes.R index 36aae02..edbfa04 100644 --- a/tests/testthat/test-map_genes.R +++ b/tests/testthat/test-map_genes.R @@ -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) })