[2] | 1 | #Dan Blankenberg |
---|
| 2 | import sys, os, shutil |
---|
| 3 | import imp |
---|
| 4 | from galaxy_utils.sequence.fastq import fastqReader, fastqWriter |
---|
| 5 | |
---|
| 6 | def main(): |
---|
| 7 | #Read command line arguments |
---|
| 8 | input_filename = sys.argv[1] |
---|
| 9 | script_filename = sys.argv[2] |
---|
| 10 | output_filename = sys.argv[3] |
---|
| 11 | additional_files_path = sys.argv[4] |
---|
| 12 | input_type = sys.argv[5] or 'sanger' |
---|
| 13 | |
---|
| 14 | #Save script file for debuging/verification info later |
---|
| 15 | os.mkdir( additional_files_path ) |
---|
| 16 | shutil.copy( script_filename, os.path.join( additional_files_path, 'debug.txt' ) ) |
---|
| 17 | |
---|
| 18 | fastq_manipulator = imp.load_module( 'fastq_manipulator', open( script_filename ), script_filename, ( '', 'r', imp.PY_SOURCE ) ) |
---|
| 19 | |
---|
| 20 | out = fastqWriter( open( output_filename, 'wb' ), format = input_type ) |
---|
| 21 | |
---|
| 22 | i = None |
---|
| 23 | reads_manipulated = 0 |
---|
| 24 | for i, fastq_read in enumerate( fastqReader( open( input_filename ), format = input_type ) ): |
---|
| 25 | new_read = fastq_manipulator.match_and_manipulate_read( fastq_read ) |
---|
| 26 | if new_read: |
---|
| 27 | out.write( new_read ) |
---|
| 28 | if new_read != fastq_read: |
---|
| 29 | reads_manipulated += 1 |
---|
| 30 | out.close() |
---|
| 31 | if i is None: |
---|
| 32 | print "Your file contains no valid FASTQ reads." |
---|
| 33 | else: |
---|
| 34 | print 'Manipulated %s of %s reads (%.2f%%).' % ( reads_manipulated, i + 1, float( reads_manipulated ) / float( i + 1 ) * 100.0 ) |
---|
| 35 | |
---|
| 36 | if __name__ == "__main__": |
---|
| 37 | main() |
---|