python
照方抓药
import time
start = time.time()
import glob
import gzip
length=[]
with gzip.open('H-CK-1-3_clean.fq.gz','rt') as fp:
i = 0
for line in fp:
i += 1
if i % 4 == 2:
if len(line)-1==50:
length.append(i-1)
length.append(i)
length.append(i+1)
length.append(i+2)
f = gzip.open('H-CK-1-3_clean.fq.gz','rt')
length.append('0')
output_fastq = open("temp2.fq",'w')
i = 0
N = 0
for line in f:
N += 1
if N == length[i]:
output_fastq.write(line)
i += 1
output_fastq.close()
end = time.time()
print("used %s s" % str(end - start))
2
import time
start = time.time()
import glob
import gzip
fp = gzip.open('test.fq.gz','rt')
fastq = open("temp5.fq",'w')
i = 0
for line in fp:
i += 1
if i%4 ==1:
line1=line
elif i%4 ==2:
line2=line
elif i%4 ==3:
line3=line
elif i%4 ==0:
line4=line
if len(line4)-1==50:
fastq.write(line1+line2+line3+line4)
fastq.close()
end = time.time()
print("used %s s" % str(end - start))