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

Ensembl site unresponsive when using creat_cellphonedb_file() function #11

Open
pandaqiuqiu opened this issue Jul 12, 2024 · 1 comment

Comments

@pandaqiuqiu
Copy link

pandaqiuqiu commented Jul 12, 2024

When I use the creat_cellphonedb_file() function to generate the input files for CellPhoneDB, I encountered the following error:

creat_cellphonedb_file(sce, Sample)

Ensembl site unresponsive, trying asia mirror
Ensembl site unresponsive, trying asia mirror
Error: biomaRt has encountered an unexpected server error.
Consider trying one of the Ensembl mirrors (for more details look at ?useEnsembl)

Additionally, I am curious why this process needs to call biomaRt. Any response will be appreciated.

@HaojiaWu
Copy link
Owner

Hi @pandaqiuqiu
The earlier version of CellPhoneDB used a ligand-receptor pair database derived from human genes. Therefore, I need to convert mouse genes to their orthologous human genes, which is why I am using biomaRt. I've tested biomaRt on my server, and it works fine with version 2.60.0. You can use the same version to see if it works for you.
I will add an argument to the function later to allow users to specify the species. For a quick fix, you can modify the source code of the function. The source code is very short (see below). If your Seurat object is from a human sample, you can omit the biomaRt lines.

creat_cellphonedb_file <- function(seu_obj, group){
  counts <- as.data.frame(
    as.matrix(
      seu_obj@assays$RNA@data)
  )
  mouse_genes<-rownames(counts)
  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/")
  genesV2 = getLDS(attributes = c("mgi_symbol"), filters = "mgi_symbol", 
                   values = mouse_genes , mart = mouse, attributesL = c("hgnc_symbol",'ensembl_gene_id'), 
                   martL = human, uniqueRows=F)
  genesV2$Gene.stable.ID<-as.character(genesV2$Gene.stable.ID)
  genesV2$MGI.symbol<-as.character(genesV2$MGI.symbol)
  genesV2<-genesV2[!duplicated(genesV2$Gene.stable.ID),]
  genesV2<-genesV2[!duplicated(genesV2$MGI.symbol),]
  counts<-counts[genesV2$MGI.symbol,]
  rownames(counts)<-genesV2$Gene.stable.ID
  metadata <- data.frame(Cell = colnames(counts),
                         cell_type = as.character(seu_obj@active.ident)
  )
  metadata$Cell<-gsub('\\-','\\.',metadata$Cell)
  counts<-na.omit(counts)
  counts$Gene<-rownames(counts)
  counts<-counts[,c(ncol(counts), 1:(ncol(counts)-1))]
  colnames(counts)<-gsub('\\-','\\.',colnames(counts))
  
  write.table(counts,
              file =paste0(group, '_counts.txt'),
              quote = F,
              col.names = T,
              row.names = F,
              sep = '\t')
  
  write.table(metadata,
              file = paste0(group, '_metadata.txt'),
              quote = F,
              col.names = T,
              row.names = F,
              sep = '\t')
  
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants