我已经编写了一个函数,用于查找长DNA序列中子序列的索引。当我的较长DNA序列长度小于约4000个字符时,它可以正常工作。然而,当我尝试将相同的函数应用于更长的序列时,控制台会给出一个+而不是一个>... 这使我相信问题在于字符串的长度。
例如:当较长的序列为:"GATATATGCATATACTT",而子序列为:"ATAT"时,我得到的索引是"1, 3, 9"(基于0)
例如:当较长的序列为:"GATATATGCATATACTT",而子序列为:"ATAT"时,我得到的索引是"1, 3, 9"(基于0)
dnaMatch <- function(dna, sequence) {
ret <- list()
k <- str_length(sequence)
c <- str_length(dna) - k
for(i in 1:(c+1)) {
ret[i] = str_sub(dna, i, i+k-1)
}
ret <- unlist(ret)
TFret <- lapply (ret, identical, sequence)
TFret <- which(unlist(TFret), arr.ind = TRUE) -1
print(TFret)
}
基本上,我的问题是...在字符串类中有没有绕过字符限制的方法?
)
,"
,'
或}
导致的。你有没有仔细检查过代码中的拼写错误? - nrussellcat(paste0(rep("abcdef",1000),collapse=""))
复制输出并尝试将其分配给对象x <- "[paste copied text]"
,成功复现了这个问题。很可能是由于某种缓冲区限制导致的。 - nrussellx<-paste0(rep("abcdef",1000),collapse="")
。 - bjoseph?gregxpr
或?regexpr
。详见 http://rfunction.com/archives/1719 和 http://stat.ethz.ch/R-manual/R-devel/library/base/html/regex.html。 - bjosephdnaMatch(x,'ATATAT')
和gregexpr('ATATAT',x)
在一个长度为100k的字符串上匹配,分别需要49秒和0.003秒。抱歉,我没有耐心再运行更长时间的循环。 - rawr