parsing a fastq file using biopython
1
0
Entering edit mode
7.9 years ago

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 • 5.2k views
ADD COMMENT
0
Entering edit mode
7.9 years ago
iraun 6.2k

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.

ADD COMMENT

Login before adding your answer.

Traffic: 2521 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6