I am using biopython package and I would like to save result like tsv file. This output from print to tsv.
for record in SeqIO.parse("/home/fil/Desktop/420_2_03_074.fastq", "fastq"):
print ("%s %s %s" % (record.id,record.seq, record.format("qual")))
Thank you.
My preferred solution is to use the CSV module. It's a standard module, so:
The following code snippet should do the trick for you:
#! /bin/env python3
import csv
with open('records.tsv', 'w') as tsvfile:
writer = csv.writer(tsvfile, delimiter='\t', newline='\n')
for record in SeqIO.parse("/home/fil/Desktop/420_2_03_074.fastq", "fastq"):
writer.writerow([record.id, record.seq, record.format("qual")])
Note that this is for Python 3.x. If you're using 2.x, the open
and writer = ...
will be slightly different.