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

Error by using mouse_genes_to_human function #147

Open
kongjianyang opened this issue May 30, 2023 · 1 comment
Open

Error by using mouse_genes_to_human function #147

kongjianyang opened this issue May 30, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@kongjianyang
Copy link

If you meet problem by using mouse_genes_to_human like,

mouse_genes_to_human(tpm_data)
# Error in curl::curl_fetch_memory(url, handle = handle) : 
  Timeout was reached: [www.ensembl.org:443] Operation timed out after 10001 milliseconds with 0 bytes received

you can create your own function by modify the original code:

my_mouse_genes_to_human <- function (gene_expression_matrix, mirror = "www") 
{
    gene.names.mouse <- rownames(gene_expression_matrix)
    gene_expression_matrix$gene_name <- gene.names.mouse
    
      # add host to 2021 version, otherwise may have bug
    human <- useMart("ensembl", dataset = "hsapiens_gene_ensembl", 
        host = "https://dec2021.archive.ensembl.org/")
    mouse <- useMart("ensembl", dataset = "mmusculus_gene_ensembl", 
        host = "https://dec2021.archive.ensembl.org/")
    
    
    genes.retrieved <- getLDS(attributes = c("mgi_symbol"), filters = "mgi_symbol", 
        values = gene.names.mouse, mart = mouse, attributesL = c("hgnc_symbol"), 
        martL = human, uniqueRows = T)
    
    
    newGenes.counts <- gene_expression_matrix %>% left_join(., 
        genes.retrieved, by = c(gene_name = "MGI.symbol")) %>% 
        dplyr::select(., -c("gene_name")) %>% dplyr::select(., c("HGNC.symbol", 
        everything())) %>% .[!(is.na(.$HGNC.symbol)), ]
    colnames(newGenes.counts)[1] <- "gene_name"
    newGenes.counts <- newGenes.counts[!(duplicated(newGenes.counts$gene_name)), 
        ] %>% as.data.frame(.)
    rownames(newGenes.counts) <- newGenes.counts$gene_name
    newGenes.counts <- dplyr::select(newGenes.counts, -c("gene_name"))
    fraction <- 100 * (nrow(newGenes.counts)/nrow(gene_expression_matrix)) %>% 
        round(., 1)
    message(paste0("ATTENTION: Only the ", fraction, "% of genes was maintained"))
    return(newGenes.counts)
}

then using

# mouse data, change to human gene ID
expression_matrix_humanGenes <- my_mouse_genes_to_human(gene_expression_matrix, mirror = "www")

This will solve your problem.

@kongjianyang kongjianyang added the bug Something isn't working label May 30, 2023
@Kiliankleemann
Copy link

Error: 'mouse_genes_to_human' is not an exported object from 'namespace:immunedeconv'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants