Last active
June 28, 2016 20:02
-
-
Save ConradStack/1b1a442e4eb8d61651ce531382eb5b2a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| import argparse | |
| import os | |
| import sys | |
| # Deinterlace an interlaced fastq file | |
| # (modified from iamdelf/deinterlace) | |
| # usage: | |
| # cat interlaced_input.fastq | deinterlacer.sh output_R1.fq output_R2.fq | |
| def main(): | |
| parser = argparse.ArgumentParser(description='Splits an interleaved FASTQ (input in STDIN) into first and second read files') | |
| parser.add_argument('first') | |
| parser.add_argument('second') | |
| args = parser.parse_args() | |
| pipeForward = os.open( os.path.join(os.getcwd(),args.first) , os.O_WRONLY|os.O_CREAT|os.O_EXCL) | |
| pipeReverse = os.open( os.path.join(os.getcwd(),args.second) , os.O_WRONLY|os.O_CREAT|os.O_EXCL) | |
| i = 0 | |
| forward = True | |
| for line in sys.stdin: | |
| if forward: | |
| os.write(pipeForward, line.encode()) | |
| else: | |
| os.write(pipeReverse, line.encode()) | |
| i += 1 | |
| if i == 4: | |
| forward = not forward | |
| i = 0 | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment