通常從測序公司拿到的fq文件分為四行,第一行為序列名稱,第二行為序列的堿基,第三行為序列名稱,通常用+號(hào)代替,第四行為堿基質(zhì)量。
代碼如下:
from collections import Counter
with open('srg1.r1.paired.fq','r') as Fileout, open('srg1.r1.paired.results.txt','w') as Filein:
i = 4
dic, arr = {}, []
while True:
line = Fileout.readline()
i += 1
if i%4 == 2:
arr.append(len(str(line)))
if not line:
break
dic = Counter(arr)
for k,v in dic.iteritems():
Filein.write(k + v)
shell:
cat your.fq | paste ----| awk '{print ">"$1 "\n" $2}'