Skip to content

Instantly share code, notes, and snippets.

@wckdouglas
Created October 28, 2016 05:50
Show Gist options
  • Save wckdouglas/c3c794b2e7aadd2395fc6c1afb90151a to your computer and use it in GitHub Desktop.
Save wckdouglas/c3c794b2e7aadd2395fc6c1afb90151a to your computer and use it in GitHub Desktop.
def read_fastq(file_fq):
"""
takes a fastq file as input
yields idSeq, sequence and score
for each fastq entry
learned from:
http://codereview.stackexchange.com/questions/32897/efficient-parsing-of-fastq
"""
line_count = 0
while True:
line = file_fq.readline()
line_count += 1
#break if we hit the end of the file
if not line:
break
if line_count == 1:
idSeq = line.strip().lstrip('@')
elif line_count == 2:
sequence = line.strip()
elif line_count == 4:
score = line.strip()
line_count = 0
yield idSeq,sequence, score
yield idSeq, sequence, score
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment