Created
May 4, 2013 23:09
-
-
Save yong27/5519095 to your computer and use it in GitHub Desktop.
Extract valid data from broken fastq file.
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refer to 손상된 압축 FASTQ 파일의 손상부분 제거하기 and falsetru's improvement https://gist.github.com/falsetru/5435949