通常从测序公司拿到的fq文件分为四行,第一行为序列名称,第二行为序列的碱基,第三行为序列名称,通常用+号代替,第四行为碱基质量。
代码如下:
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}'
网友评论