jpayne@1: #!/bin/bash jpayne@1: # Usage: deinterleave_fastq.sh < interleaved.fastq f.fastq r.fastq [compress] jpayne@1: # jpayne@1: # Deinterleaves a FASTQ file of paired reads into two FASTQ jpayne@1: # files specified on the command line. Optionally GZip compresses the output jpayne@1: # FASTQ files using pigz if the 3rd command line argument is the word "compress" jpayne@1: # jpayne@1: # Can deinterleave 100 million paired reads (200 million total jpayne@1: # reads; a 43Gbyte file), in memory (/dev/shm), in 4m15s (255s) jpayne@1: # jpayne@1: # Latest code: https://gist.github.com/3521724 jpayne@1: # Also see my interleaving script: https://gist.github.com/4544979 jpayne@1: # jpayne@1: # Inspired by Torsten Seemann's blog post: jpayne@1: # http://thegenomefactory.blogspot.com.au/2012/05/cool-use-of-unix-paste-with-ngs.html jpayne@1: jpayne@1: # Set up some defaults jpayne@1: GZIP_OUTPUT=0 jpayne@1: PIGZ_COMPRESSION_THREADS=10 jpayne@1: jpayne@1: # If the third argument is the word "compress" then we'll compress the output using pigz jpayne@1: if [[ $3 == "compress" ]]; then jpayne@1: GZIP_OUTPUT=1 jpayne@1: fi jpayne@1: jpayne@1: if [[ ${GZIP_OUTPUT} == 0 ]]; then jpayne@1: paste - - - - - - - - | tee >(cut -f 1-4 | tr "\t" "\n" > $1) | cut -f 5-8 | tr "\t" "\n" > $2 jpayne@1: else jpayne@1: paste - - - - - - - - | tee >(cut -f 1-4 | tr "\t" "\n" | pigz --best --processes ${PIGZ_COMPRESSION_THREADS} > $1) | cut -f 5-8 | tr "\t" "\n" | pigz --best --processes ${PIGZ_COMPRESSION_THREADS} > $2 jpayne@1: fi