Created
July 8, 2013 17:48
-
-
Save gregpinero/5950909 to your computer and use it in GitHub Desktop.
Quick functions for reading and writing fastq files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Quick functions for reading and writing FASTQ""" | |
def read_fastq(filehandle): | |
''' Return dictionary with 'seq_id', 'seq', 'qual_id', and 'qual' ''' | |
record_line = 0 | |
read_number = 0 | |
fastq_record = dict() | |
for line in filehandle: | |
record_line += 1 | |
if record_line == 1: | |
fastq_record['seq_id'] = line.strip() | |
elif record_line == 2: | |
fastq_record['seq'] = line.strip() | |
elif record_line == 3: | |
fastq_record['qual_id'] = line.strip() | |
elif record_line == 4: | |
record_line = 0 | |
fastq_record['qual'] = line.strip() | |
read_number += 1 | |
yield fastq_record | |
def fastq_string(record): | |
return "%s\n%s\n%s\n%s\n" % (record['seq_id'], record['seq'], record['qual_id'], record['qual']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment