/tools/fastq/fastq_paired_end_splitter.py

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 33 lines · 27 code · 4 blank · 2 comment · 8 complexity · 64c7e8b5d571e91565b8701af9e9e281 MD5 · raw file

  1. #Dan Blankenberg
  2. import sys, os, shutil
  3. from galaxy_utils.sequence.fastq import fastqReader, fastqWriter, fastqSplitter
  4. def main():
  5. #Read command line arguments
  6. input_filename = sys.argv[1]
  7. input_type = sys.argv[2] or 'sanger'
  8. output1_filename = sys.argv[3]
  9. output2_filename = sys.argv[4]
  10. splitter = fastqSplitter()
  11. out1 = fastqWriter( open( output1_filename, 'wb' ), format = input_type )
  12. out2 = fastqWriter( open( output2_filename, 'wb' ), format = input_type )
  13. i = None
  14. skip_count = 0
  15. for i, fastq_read in enumerate( fastqReader( open( input_filename, 'rb' ), format = input_type ) ):
  16. read1, read2 = splitter.split( fastq_read )
  17. if read1 and read2:
  18. out1.write( read1 )
  19. out2.write( read2 )
  20. else:
  21. skip_count += 1
  22. out1.close()
  23. out2.close()
  24. if i is None:
  25. print "Your file contains no valid FASTQ reads."
  26. else:
  27. print 'Split %s of %s reads (%.2f%%).' % ( i - skip_count + 1, i + 1, float( i - skip_count + 1 ) / float( i + 1 ) * 100.0 )
  28. if __name__ == "__main__":
  29. main()