查询区域内基因
Query genes within regions
我想检索存在于一系列区域内的基因。比如说,我有一个带有查询位置的床文件,例如:
1 2665697 4665777 MIR201
1 10391435 12391516 MIR500
1 15106831 17106911 MIR122
1 23436535 25436616 MIR234
1 23436575 25436656 MIR488
我想获得属于这些区域的基因。
我尝试使用 biomaRt 和 bedtools 相交,但我得到的输出是对应于所有区域,而不是一个一个地查询,因为我想获得的所需输出是每一行中的基因,但在不同的行中,如果我一次查询一个区域。基本上我想知道哪些基因属于每个区域,但仍然能够识别哪些基因属于哪些区域。
我所做的是,从检测到的miRNA区域,向上和向下扩展基因组区域,这样我就可以从这个miRNA中得到邻近的基因。我上下使用了 100 万个碱基 windows。这只适用于一个查询,但是,如何使用 biomaRt 进行多次查询或使用 bedtools 进行多次查询,这样我就有点像:
1 2665697 4665777 MIR201 GENEX, GENEY, GENEZ...
1 10391435 12391516 MIR500 GENEA, GENEB, GENEC...
1 15106831 17106911 MIR122
1 23436535 25436616 MIR234
1 23436575 25436656 MIR488
意味着 GENEX、GENEY 和 GENEZ 落在 1:2665697-4665777 范围内,MIR201 位于中间,因为这个区域是计算减去 100 万 bp 到 sart,并添加 100 万 bp 到结束位置.
我在某种程度上确定了每个 miRNA 的邻近基因,以便在物种内进行比较,但我不知道如何使用 biomaRt 或 单独查询多个区域床具.
有什么帮助吗?
您可以尝试 biomart
& tidyverse
解决方案
library(biomaRt)
library(tidyverse)
# specify the database
ensembl = useMart("ensembl",dataset="hsapiens_gene_ensembl")
# queries per row
res <- d %>%
split(1:nrow(.)) %>%
map(~getBM(attributes=c("external_gene_name", "chromosome_name", "start_position", "end_position"),
filters = c("chromosome_name" , "start", "end"),
values = list(.$V1, .$V2, .$V3),
mart = ensembl))
# plot the results for the first element to check the overlapping genes
plot(data.frame(unlist(d[1, 2:3]), nrow(res$`1`)), type="l", col=2, lwd =3,
ylim = c(0, nrow(res$`1`)),
xlim=unlist(d[1, 2:3])+c(-100000,100000))
res$`1` %>%
gather(k,v,-external_gene_name,-chromosome_name) %>%
arrange(external_gene_name) %>%
mutate(n=rep(1:(n()/2),each=2)) %>%
split(.$n) %>%
map(~with(.,lines(cbind(v, n), type="l", lwd =3)))
# transform the data in your expected data.frame
res %>%
map(~transmute(.,new=paste(external_gene_name, collapse="," )) %>%
slice(1)) %>%
bind_rows() %>%
bind_cols(d,.) %>%
as.tibble()
# A tibble: 5 x 5
V1 V2 V3 V4 new
<int> <int> <int> <fct> <chr>
1 1 2665697 4665777 MIR201 TTC34,AC242022.1,AL592464.2,AL592464.1,AL589702.1,ACTRT2,LINC00982,PRDM16,MIR4251,AL008733.1,AL512383.1,AL590438.~
2 1 10391435 12391516 MIR500 AL139424.2,PGD,AL139424.1,CENPS-CORT,CENPS,CORT,DFFA,AL354956.1,PEX14,RN7SL614P,CASZ1,AL139423.1,HSPE1P24,C1orf12~
3 1 15106831 17106911 MIR122 KAZN,TMEM51-AS1,TMEM51,C1orf195,AL035405.1,AL391094.1,FHAD1,AL031283.2,AL031283.3,AL031283.1,EFHD2,CTRC,CELA2A,CE~
4 1 23436535 25436616 MIR234 ASAP3,E2F2,AL021154.1,ID3,MDS2,AL451000.1,RPL11,ELOA,ELOA-AS1,PITHD1,LYPLA2,GALE,HMGCL,FUCA1,CNR2,BTBD6P1,AL59060~
5 1 23436575 25436656 MIR488 ASAP3,E2F2,AL021154.1,ID3,MDS2,AL451000.1,RPL11,ELOA,ELOA-AS1,PITHD1,LYPLA2,GALE,HMGCL,FUCA1,CNR2,BTBD6P1,AL59060~
如果您需要所有数据,您也可以尝试 purrr
解决方案。优点:biomart 输出存储在一个列表中,不会丢失。
d %>%
nest(-V4) %>%
mutate(biomart=map(data, ~getBM(attributes=c("external_gene_name", "chromosome_name", "start_position", "end_position"),
filters = c("chromosome_name" , "start", "end"),
values = list(.$V1, .$V2, .$V3),
mart = ensembl)),
Genes = map(biomart, ~paste(.$external_gene_name, collapse = ","))) %>%
unnest(Genes, data)
# A tibble: 5 x 6
V4 biomart Genes V1 V2 V3
<fct> <list> <chr> <int> <int> <int>
1 MIR201 <data.frame [43 x 4]> TTC34,AC242022.1,AL592464.2,AL592464.1,AL589702.1,ACTRT2,~ 1 2.67e6 4.67e6
2 MIR500 <data.frame [72 x 4]> AL139424.2,PGD,AL139424.1,CENPS-CORT,CENPS,CORT,DFFA,AL35~ 1 1.04e7 1.24e7
3 MIR122 <data.frame [101 x 4]> KAZN,TMEM51-AS1,TMEM51,C1orf195,AL035405.1,AL391094.1,FHA~ 1 1.51e7 1.71e7
4 MIR234 <data.frame [62 x 4]> ASAP3,E2F2,AL021154.1,ID3,MDS2,AL451000.1,RPL11,ELOA,ELOA~ 1 2.34e7 2.54e7
5 MIR488 <data.frame [62 x 4]> ASAP3,E2F2,AL021154.1,ID3,MDS2,AL451000.1,RPL11,ELOA,ELOA~ 1 2.34e7 2.54e7
与 相同的方法,没有 tidyverse:
library(biomaRt)
# data
d <- read.table(text = "1 2665697 4665777 MIR201
1 10391435 12391516 MIR500
1 15106831 17106911 MIR122
1 23436535 25436616 MIR234
1 23436575 25436656 MIR488")
# specify the database
ensembl = useMart("ensembl", dataset = "hsapiens_gene_ensembl")
# loop through rows, get genes, then paste with collapse,
# and finally bind back with data d.
res <- cbind(
d,
genes = apply(d, 1, function(i){
x <- getBM(attributes=c("external_gene_name"),
filters = c("chromosome_name" , "start", "end"),
values = list(i[1], i[2], i[3]),
mart = ensembl)
# keeping only 3 genes, as output is too long.
# In your case remove below line
x <- head(x, 3)
# return genes, comma separated
paste(x$external_gene_name, collapse = ",")
})
)
res
# V1 V2 V3 V4 genes
# 1 1 2665697 4665777 MIR201 TTC34,AC242022.1,AL592464.2
# 2 1 10391435 12391516 MIR500 AL139424.2,PGD,AL139424.1
# 3 1 15106831 17106911 MIR122 KAZN,TMEM51-AS1,TMEM51
# 4 1 23436535 25436616 MIR234 ASAP3,E2F2,AL021154.1
# 5 1 23436575 25436656 MIR488 ASAP3,E2F2,AL021154.1
我想检索存在于一系列区域内的基因。比如说,我有一个带有查询位置的床文件,例如:
1 2665697 4665777 MIR201
1 10391435 12391516 MIR500
1 15106831 17106911 MIR122
1 23436535 25436616 MIR234
1 23436575 25436656 MIR488
我想获得属于这些区域的基因。
我尝试使用 biomaRt 和 bedtools 相交,但我得到的输出是对应于所有区域,而不是一个一个地查询,因为我想获得的所需输出是每一行中的基因,但在不同的行中,如果我一次查询一个区域。基本上我想知道哪些基因属于每个区域,但仍然能够识别哪些基因属于哪些区域。
我所做的是,从检测到的miRNA区域,向上和向下扩展基因组区域,这样我就可以从这个miRNA中得到邻近的基因。我上下使用了 100 万个碱基 windows。这只适用于一个查询,但是,如何使用 biomaRt 进行多次查询或使用 bedtools 进行多次查询,这样我就有点像:
1 2665697 4665777 MIR201 GENEX, GENEY, GENEZ...
1 10391435 12391516 MIR500 GENEA, GENEB, GENEC...
1 15106831 17106911 MIR122
1 23436535 25436616 MIR234
1 23436575 25436656 MIR488
意味着 GENEX、GENEY 和 GENEZ 落在 1:2665697-4665777 范围内,MIR201 位于中间,因为这个区域是计算减去 100 万 bp 到 sart,并添加 100 万 bp 到结束位置.
我在某种程度上确定了每个 miRNA 的邻近基因,以便在物种内进行比较,但我不知道如何使用 biomaRt 或 单独查询多个区域床具.
有什么帮助吗?
您可以尝试 biomart
& tidyverse
解决方案
library(biomaRt)
library(tidyverse)
# specify the database
ensembl = useMart("ensembl",dataset="hsapiens_gene_ensembl")
# queries per row
res <- d %>%
split(1:nrow(.)) %>%
map(~getBM(attributes=c("external_gene_name", "chromosome_name", "start_position", "end_position"),
filters = c("chromosome_name" , "start", "end"),
values = list(.$V1, .$V2, .$V3),
mart = ensembl))
# plot the results for the first element to check the overlapping genes
plot(data.frame(unlist(d[1, 2:3]), nrow(res$`1`)), type="l", col=2, lwd =3,
ylim = c(0, nrow(res$`1`)),
xlim=unlist(d[1, 2:3])+c(-100000,100000))
res$`1` %>%
gather(k,v,-external_gene_name,-chromosome_name) %>%
arrange(external_gene_name) %>%
mutate(n=rep(1:(n()/2),each=2)) %>%
split(.$n) %>%
map(~with(.,lines(cbind(v, n), type="l", lwd =3)))
# transform the data in your expected data.frame
res %>%
map(~transmute(.,new=paste(external_gene_name, collapse="," )) %>%
slice(1)) %>%
bind_rows() %>%
bind_cols(d,.) %>%
as.tibble()
# A tibble: 5 x 5
V1 V2 V3 V4 new
<int> <int> <int> <fct> <chr>
1 1 2665697 4665777 MIR201 TTC34,AC242022.1,AL592464.2,AL592464.1,AL589702.1,ACTRT2,LINC00982,PRDM16,MIR4251,AL008733.1,AL512383.1,AL590438.~
2 1 10391435 12391516 MIR500 AL139424.2,PGD,AL139424.1,CENPS-CORT,CENPS,CORT,DFFA,AL354956.1,PEX14,RN7SL614P,CASZ1,AL139423.1,HSPE1P24,C1orf12~
3 1 15106831 17106911 MIR122 KAZN,TMEM51-AS1,TMEM51,C1orf195,AL035405.1,AL391094.1,FHAD1,AL031283.2,AL031283.3,AL031283.1,EFHD2,CTRC,CELA2A,CE~
4 1 23436535 25436616 MIR234 ASAP3,E2F2,AL021154.1,ID3,MDS2,AL451000.1,RPL11,ELOA,ELOA-AS1,PITHD1,LYPLA2,GALE,HMGCL,FUCA1,CNR2,BTBD6P1,AL59060~
5 1 23436575 25436656 MIR488 ASAP3,E2F2,AL021154.1,ID3,MDS2,AL451000.1,RPL11,ELOA,ELOA-AS1,PITHD1,LYPLA2,GALE,HMGCL,FUCA1,CNR2,BTBD6P1,AL59060~
如果您需要所有数据,您也可以尝试 purrr
解决方案。优点:biomart 输出存储在一个列表中,不会丢失。
d %>%
nest(-V4) %>%
mutate(biomart=map(data, ~getBM(attributes=c("external_gene_name", "chromosome_name", "start_position", "end_position"),
filters = c("chromosome_name" , "start", "end"),
values = list(.$V1, .$V2, .$V3),
mart = ensembl)),
Genes = map(biomart, ~paste(.$external_gene_name, collapse = ","))) %>%
unnest(Genes, data)
# A tibble: 5 x 6
V4 biomart Genes V1 V2 V3
<fct> <list> <chr> <int> <int> <int>
1 MIR201 <data.frame [43 x 4]> TTC34,AC242022.1,AL592464.2,AL592464.1,AL589702.1,ACTRT2,~ 1 2.67e6 4.67e6
2 MIR500 <data.frame [72 x 4]> AL139424.2,PGD,AL139424.1,CENPS-CORT,CENPS,CORT,DFFA,AL35~ 1 1.04e7 1.24e7
3 MIR122 <data.frame [101 x 4]> KAZN,TMEM51-AS1,TMEM51,C1orf195,AL035405.1,AL391094.1,FHA~ 1 1.51e7 1.71e7
4 MIR234 <data.frame [62 x 4]> ASAP3,E2F2,AL021154.1,ID3,MDS2,AL451000.1,RPL11,ELOA,ELOA~ 1 2.34e7 2.54e7
5 MIR488 <data.frame [62 x 4]> ASAP3,E2F2,AL021154.1,ID3,MDS2,AL451000.1,RPL11,ELOA,ELOA~ 1 2.34e7 2.54e7
与
library(biomaRt)
# data
d <- read.table(text = "1 2665697 4665777 MIR201
1 10391435 12391516 MIR500
1 15106831 17106911 MIR122
1 23436535 25436616 MIR234
1 23436575 25436656 MIR488")
# specify the database
ensembl = useMart("ensembl", dataset = "hsapiens_gene_ensembl")
# loop through rows, get genes, then paste with collapse,
# and finally bind back with data d.
res <- cbind(
d,
genes = apply(d, 1, function(i){
x <- getBM(attributes=c("external_gene_name"),
filters = c("chromosome_name" , "start", "end"),
values = list(i[1], i[2], i[3]),
mart = ensembl)
# keeping only 3 genes, as output is too long.
# In your case remove below line
x <- head(x, 3)
# return genes, comma separated
paste(x$external_gene_name, collapse = ",")
})
)
res
# V1 V2 V3 V4 genes
# 1 1 2665697 4665777 MIR201 TTC34,AC242022.1,AL592464.2
# 2 1 10391435 12391516 MIR500 AL139424.2,PGD,AL139424.1
# 3 1 15106831 17106911 MIR122 KAZN,TMEM51-AS1,TMEM51
# 4 1 23436535 25436616 MIR234 ASAP3,E2F2,AL021154.1
# 5 1 23436575 25436656 MIR488 ASAP3,E2F2,AL021154.1