如何修复R中的“尚不支持长向量”错误

时间:2019-02-15 20:01:15

标签: r

我正在尝试运行一些R代码,由于长矢量错误,它崩溃了。我正在运行R 3.5.1,并收到以下错误:

  

“错误(n:1:k){:长向量不支持:eval.c:6393”

输入的FASTA文件大小为1 GB。运行循环后,错误立即出现。我试图使输入文件更小,但事实并非如此,我想可能与所使用的软件包更多相关。造成麻烦的代码如下:

library(biomaRt) #version 2.36.1
library(biomartr)#version 0.8.0
library(R.utils) #version 2.7.0
library(seqinr)  #version 3.4.5

genmt <- read.fasta("genymt.fa")

gensize1 <- 16900
subsize1 <- 22*2

BinToDec <- function(x) 
sum(2^(which(rev(unlist(strsplit(x, "")) == 1))-1))

DecToBin <- function(x)
{
 b <- intToBin(x)
 while(nchar(b) < subsize1)
   b <- paste("0",b,sep = "")
 b
}

bin1 <- gsub('A','00',genmt)
bin1 <- gsub('T','01',bin1)
bin1 <- gsub('C','10',bin1)
bin1 <- gsub('G','11',bin1)

for (i in 1:((gensize1*2)-subsize1)) {

  print(i)
  beg1 <- i
  end1 <- i+(subsize1-1)

  sub1 <- substr(bin1, beg1, end1)

  dec1 <- BinToDec(sub1)

  if (i == 1) {
    exists1 <- dec1
    rep1 <- 1
  } else {
    flag1 <- any(exists1 == dec1)

    if (flag1) {
      ind1 <- which(exists1 == dec1)
      rep1[ind1] <- rep1[ind1]+1
    } else {
      exists1 <- c(exists1,dec1)
      rep1 <- c(rep1,1)
    }
  }
}

dec_res <- -1
k <- 2^subsize1
for (n in 1:k) {
  print(n)
  flag1 <- any(exists1 == n)

  if (!flag1) {
    dec_res <- n
    break
  } 
}

bin_res <- DecToBin(dec_res)

gen_res <- matrix(,nrow = 0,ncol = subsize1/2)
ind <- 0
for(i in seq(1,subsize1,2)) {
  ind <- ind + 1
  ifelse(substr(bin_res,i,i+1) == "00",gen_res[ind] <- "A",
         ifelse(substr(bin_res,i,i+1) == "01",gen_res[ind] <- "T",
                ifelse(substr(bin_res,i,i+1) == "10",gen_res[ind] <-"C",gen_res[ind] <- "G")))
}

能否请您帮助我了解情况并提供解决方案?

0 个答案:

没有答案