Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在使用biomaRt库的函数上下文中调用变量时出现意外结果_R - Fatal编程技术网

在使用biomaRt库的函数上下文中调用变量时出现意外结果

在使用biomaRt库的函数上下文中调用变量时出现意外结果,r,R,我有一个一般性的问题,我认为可以归结为某种范围问题 下面是使用biomaRt的getSequence()函数的公式片段。用户在自定义函数中输入(1)基因名称,并可选地输入(2)上游要导入的碱基对数 # Load libraries library(biomaRt) # Let's make a custom "getSequence" function getUpstream <- function(x, bp.upstream = 50){ bp.upstream <- b

我有一个一般性的问题,我认为可以归结为某种范围问题

下面是使用biomaRt的getSequence()函数的公式片段。用户在自定义函数中输入(1)基因名称,并可选地输入(2)上游要导入的碱基对数

# Load libraries
library(biomaRt)
# Let's make a custom "getSequence" function
getUpstream <- function(x, bp.upstream = 50){
    bp.upstream <- bp.upstream
    ensembl <- useMart("ensembl", dataset = "hsapiens_gene_ensembl")
    upstream.master <- NULL
    for(i in x){
        upstream.i <- getSequence(id = i,
            type = "hgnc_symbol",
            seqType = "coding_gene_flank",
            upstream = bp.upstream,
            mart = ensembl
        )
        upstream.master <- rbind(upstream.master, upstream.i)
    }
    return(upstream.master)
}
意外的是,如果没有以下行,函数将无法工作:

bp.upstream <- bp.upstream

bp.upstream这里有一个避免范围问题的解决方法

# Load libraries
library(biomaRt)
# Let's make a custom "getSequence" function
 getUpstream <- function(x, bp.upstream = 50){
  ensembl <- useMart("ensembl", dataset = "hsapiens_gene_ensembl")
  upstream.master <- lapply(x, function(i,stream)
                         getSequence(id = i,
                              type = "hgnc_symbol",
                              seqType = "coding_gene_flank",
                              upstream = stream,
                              mart = ensembl),stream=bp.upstream)


  upstream.master
}
#加载库
图书馆(生物艺术)
#让我们创建一个自定义的“getSequence”函数
逆流而上
# Load libraries
library(biomaRt)
# Let's make a custom "getSequence" function
 getUpstream <- function(x, bp.upstream = 50){
  ensembl <- useMart("ensembl", dataset = "hsapiens_gene_ensembl")
  upstream.master <- lapply(x, function(i,stream)
                         getSequence(id = i,
                              type = "hgnc_symbol",
                              seqType = "coding_gene_flank",
                              upstream = stream,
                              mart = ensembl),stream=bp.upstream)


  upstream.master
}