4

大きなファイル/行列 (Windows Vista 64 ビット、4G RAM) を使用して R (2.15.0) で for ループを実行しようとしています。このループを 1 回繰り返すと、問題なく動作します。しかし、複数のファイルに対してループを実行すると (何百ものファイルを実行したい場合)、メモリが不足します。ループの最後でファイルを削除しようとしましたが、メモリが Windows に返されません (Windows タスク マネージャーで確認できます)。R は、ファイルを削除した後に内部で利用可能なメモリを使用する代わりに、OS からメモリをどんどん取得しようとしているようです。これに対する回避策はありますか? リサーチクエスチョンについてさらに詳細が必要な場合は、適切な解決策を見つけるために残りを共有させていただきます.

もうありがとう!乾杯、ロバート

> library(VariantAnnotation)
> fi<-list.files("E:/1000genomes/chr22",full.names=T)
> for(i in 1:length(fi)) {
+   input=paste("smaller.00", i, ".gz", sep = "")
+   output=paste("geno.", i, ".RData", sep = "")
+   vcf = readVcf(input, "hg19")
+   genotypes=geno(vcf)$GT[,]
+   save(genotypes, file=output)
+   gc()
+   }
Error: scanVcf: Realloc could not re-allocate memory (873600000 bytes)
  path: E:\1000genomes\chr22\smaller.002.gz
In addition: Warning messages:
1: In doTryCatch(return(expr), name, parentenv, handler) :
  Reached total allocation of 3963Mb: see help(memory.size)
2: In doTryCatch(return(expr), name, parentenv, handler) :
  Reached total allocation of 3963Mb: see help(memory.size)
> gc()
           used  (Mb) gc trigger  (Mb)  max used  (Mb)
Ncells  4543758 242.7   12363911 660.4  18010556 961.9
Vcells 19536404 149.1   61090604 466.1 119317584 910.4

そして、スクリプトの最後にあるものを削除すると:

+   save(genotypes, file=output)
+   rm(vcf)
+   rm(genotypes)
+   rm(input)
+   rm(output)
+   rm(getal)
+   rm(i)
+   }
Error: scanVcf: Calloc could not allocate memory (18 of 1 bytes)
  path: E:\1000genomes\chr22\smaller.001.gz
In addition: Warning message:
In doTryCatch(return(expr), name, parentenv, handler) :
  Reached total allocation of 3963Mb: see help(memory.size)
> gc()
          used  (Mb) gc trigger  (Mb)  max used  (Mb)
Ncells 2355472 125.8   10798339 576.7  16872405 901.1
Vcells 1992717  15.3   62280756 475.2 105556441 805.4

そして、コマンド プロンプトからの実行が機能する可能性があることをインターネットで見つけたので、スクリプトを R ルート ディレクトリの "runthis.R" ファイルに入れ、実行しました。 Rscript.exe runthis.R --no-save --no -restore 余分なファイルを 1 つ実行し、同じエラーを報告しました。

4

1 に答える 1