This is a test version of Biostars. For the public version, visit https://www.biostars.org.
parsing a fastq file using biopython

I am trying to store reads from a fastq file into a text file (tab delimited). I use the following code which just stores the read_id and sequence from the fastq file. What should I add to store the third and fourth rows of each entry? Thanks

def parsing_readid(input_file):

    f_read = open ('read1.txt','a')
    for record in SeqIO.parse(open(input_file,"rU"),"fastq"):
            f_read.write("%s\t%s\n" %record.id,record.seq))
next-gen

1 answer

Usually I work with FastqGeneralIterator to parse fastq files but... Have you tried record.qual to print out the read quality?

For other hand, the third line in fq format usually is only a "+" or a "+" followed by the read_id, so, you can just print it like this:

f_read.write("@%s\t%s\t+\t%s\n" % record.id,record.seq, record.qual))

Hope it helps.

Log in to answer this question.