Skip to content

Instantly share code, notes, and snippets.

@yong27
Created May 4, 2013 23:09
Show Gist options
  • Save yong27/5519095 to your computer and use it in GitHub Desktop.
Save yong27/5519095 to your computer and use it in GitHub Desktop.
Extract valid data from broken fastq file.
def is_valid_fastq(lines):
start = lines[0].startswith('@')
middle = lines[2].startswith('+')
length = len(lines[1]) == len(lines[3])
return all([start, middle, length])
def FastqIterator(file):
lines = [file.next(), file.next(), file.next()]
for line in file:
lines.append(line)
if is_valid_fastq(lines):
yield ''.join(lines)
lines = lines[1:]
if __name__ == '__main__':
import sys
for record in FastqIterator(sys.stdin):
sys.stdout.write(record)
@yong27
Copy link
Author

yong27 commented May 4, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment