2016-04-25 28 views
0

私はプログラミングの初心者であり、データ解析にPythonを使用しようとしています。私は、それぞれの読み取り(データ)が解析に必要な相補的な読み取りを持っているペアエンドシーケンシングのfastqファイルをいくつか持っています。私のコードは小さなファイルでうまく動作しますが、大きなファイルではうまくいかないのはなぜですか?

品質スコアが30を超える読み取りを選択するために以下のコードを書いています。これは小さなファイル(1GBまでテストしました)でもうまく動作しますが、実際のサイズのデータ​​に使用しようとすると、 30 GBの場合、結果として空のファイルが表示されます。誰が問題が何であるか教えていただけますか?ありがとう!

P.S.コードで言及されているaverage()関数は完全に機能します。私はスペースのためにここでそれをスキップしました。

#enter name of the forward source file here 
y=open("file1", "r") 
lenght=0 
for line in y: 
    lenght+=1 
y.close() 
import re 
s=0 
p=4 
#enter name of the forward destination file here 
h=open("result1", "w") 
#enter name of the reverse destination file here 
k=open("result1_complementary", "w") 
for turn in range(lenght/4): 
    #enter name of the forward source file here 
    a=open("file1", "r") 
    c=a.readlines()[s:p] 
    #enter name of the reverse source file here 
    d=open("file1_complementary", "r") 
    g=d.readlines()[s:p] 
    for line in c: 
     #enter the begining of the index line here 
     if re.search(r"^@ABC",line): 
      #enter the cutting Phred score here 
      if average(c[c.index(line)+3])<30: 
       del c[0:4] 
       del g[0:4] 
    for line in g: 
     if re.search(r"^@HWI-", line): 
      if average(g[g.index(line)+3])<30: 
       del g[0:4] 
       del c[0:4] 

    for line in c: 
     h.write(line) 
    for line in g: 
     k.write(line) 

    s+=4 
    p+=4 
    a.close() 
    d.close() 
h.close() 
k.close() 
+5

おそらく、ストリーミングせずに30GBのファイルを読み込む必要はありません。 –

+3

c = a.readlines()[s:p]はファイル全体を読み込み、数行しか取らない。行ごとに読み取りと処理を行います。 – iced

+0

私は同時に4行、4行ブロックを読む必要があります。どのように@Iicedを行うことができますか? – Hamed

答えて

0

ご意見ありがとうございます。私はのreadline()の代わりにのreadline()の反復を使用しましたreadlines()[s:p]そしてそれは完全に働いた。

関連する問題