使用biomart的lapply问题 [英] Issue with lapply using biomart

查看:185
本文介绍了使用biomart的lapply问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在提取所有人类基因时,我试图用lapply更改物种名称.

I am trying to use lapply to change the species name when extracting all the human genes.

我仍在学习如何使用lapply,我无法弄清自己做错了什么.

I'm still learning how to use lapply, I cant work out what I'm doing wrong.

到目前为止,我有:

library(biomaRt)

我创建了集市:

ensembl_hsapiens <- useMart("ensembl", 
                        dataset = "hsapiens_gene_ensembl")
ensembl_mmusculus <- useMart("ensembl", 
                     dataset = "mmusculus_gene_ensembl")
ensembl_ggallus <- useMart("ensembl",
                       dataset = "ggallus_gene_ensembl")

设置物种:

species <- c("hsapiens", "mmusculus", "ggallus")

然后我尝试使用lapply:

I then try to use lapply:

species_genes <- lapply(species, function(s) getBM(attributes = c("ensembl_gene_id", 
                                                  "external_gene_name"), 
                                   filters = "biotype", 
                                   values = "protein_coding", 
                                   mart = paste0(s, "_ensembl")))))

它给我一条错误消息,说:

It gives me an error message saying:

martCheck(mart)中的错误:您必须提供一个有效的Mart对象.到 使用功能:useMart创建Mart对象.检查?useMart以获取 更多信息.

Error in martCheck(mart) : You must provide a valid Mart object. To create a Mart object use the function: useMart. Check ?useMart for more information.

推荐答案

这应该可以解决问题:

species_genes <- lapply(species, function(s) getBM(attributes = c("ensembl_gene_id", 
                                                                  "external_gene_name"), 
                                                   filters = "biotype", 
                                                   values = "protein_coding", 
                                                   mart = get(paste0("ensembl_", s))))

说明:

getBM函数中的mart参数需要一个Mart类的对象,而不是string

the mart argument in getBM functions expects an object of class Mart and not a string

class(ensembl_ggallus)
#output
[1] "Mart"
attr(,"package")
[1] "biomaRt"

使用

paste0("ensembl_", s)

您将获得一个字符串,例如:

you get a string such as:

"ensembl_hsapiens"

base函数get按名称在环境中搜索对象.

the base function get searches for an object in the environment by name.

get("ensembl_hsapiens") 

identical(get("ensembl_hsapiens"), ensembl_hsapiens)
#output
TRUE

这篇关于使用biomart的lapply问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆