BioMart:有没有一种方法可以轻松更改我所有代码的种类? [英] BioMart: Is there a way to easily change the species for all of my code?

查看:127
本文介绍了BioMart:有没有一种方法可以轻松更改我所有代码的种类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码的一小部分:

Below is a small fraction of my code:

library(biomaRt)

ensembl_hsapiens <- useMart("ensembl", 
                        dataset = "hsapiens_gene_ensembl")

hsapien_PC_genes <- getBM(attributes = c("ensembl_gene_id", "external_gene_name"), 
                      filters = "biotype", 
                      values = "protein_coding", 
                      mart = ensembl_hsapiens)

paralogues[["hsapiens"]] <- getBM(attributes = c("external_gene_name",
                                                 "hsapiens_paralog_associated_gene_name"), 
                                  filters = "ensembl_gene_id", 
                                  values = c(ensembl_gene_ID) , mart = ensembl_hsapiens)

这部分代码将只允许我提取hsapiens的paralogues,它为我提供了一种方法,可以轻松获取mmusculus(鼠标)和ggallus(鸡)的相同信息,而不必使用诸如此类的代码来重写代码贴上?我的代码比提供的代码段长得多,我所要做的就是将hsapiens替换为mmusulus和ggallus.

This bit of code will only allow me to extract the paralogues for hsapiens, it there a way for me to easily get the same information for mmusculus (mouse) and ggallus (chicken) without having to rewrite the code by using something like Tapply? My code is much longer than the snippet provided, all I would need to do is swap the word hsapiens for mmusulus and ggallus.

推荐答案

简单的方法是将它们全部包装在for循环中:

Easy way is to just wrap it all in a for loop:

library(biomaRt)

species <- c("hsapiens_gene_ensembl", "mmusculus_gene_ensembl", "ggallus_gene_ensembl")

for (s in species) {
tmp <- useMart("ensembl", dataset = paste0(s))
hsapien_PC_genes <- getBM(attributes = c("ensembl_gene_id", "external_gene_name"), 
                          filters = "biotype", 
                          values = "protein_coding", 
                          mart = tmp)
paralogues[[s]] <- getBM(attributes = c("external_gene_name",
                                                 "hsapiens_paralog_associated_gene_name"), 
                                  filters = "ensembl_gene_id", 
                                  values = c(ensembl_gene_ID) , mart = tmp)
}

这应该工作,因为我没有安装那些软件包,所以我没有对其进行测试.我已经更改了一些变量的名称以使其更有意义(例如tmp)

This should work, I haven't tested it because I don't have those packages installed. I've changed the names of some vars to make more sense (eg tmp)

这篇关于BioMart:有没有一种方法可以轻松更改我所有代码的种类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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