Mercurial > repos > devteam > fastq_filter
comparison fastq_filter.py @ 0:0017fa63af6c draft
Imported from capsule None
| author | devteam |
|---|---|
| date | Thu, 23 Jan 2014 12:31:42 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:0017fa63af6c |
|---|---|
| 1 #Dan Blankenberg | |
| 2 import sys, os, shutil | |
| 3 from galaxy_utils.sequence.fastq import fastqReader, fastqWriter | |
| 4 | |
| 5 def main(): | |
| 6 #Read command line arguments | |
| 7 input_filename = sys.argv[1] | |
| 8 script_filename = sys.argv[2] | |
| 9 output_filename = sys.argv[3] | |
| 10 additional_files_path = sys.argv[4] | |
| 11 input_type = sys.argv[5] or 'sanger' | |
| 12 | |
| 13 #Save script file for debuging/verification info later | |
| 14 os.mkdir( additional_files_path ) | |
| 15 shutil.copy( script_filename, os.path.join( additional_files_path, 'debug.txt' ) ) | |
| 16 | |
| 17 ## Dan, Others: Can we simply drop the "format=input_type" here since it is specified in reader. | |
| 18 ## This optimization would cut runtime roughly in half (for my test case anyway). -John | |
| 19 out = fastqWriter( open( output_filename, 'wb' ), format = input_type ) | |
| 20 | |
| 21 i = None | |
| 22 reads_kept = 0 | |
| 23 execfile(script_filename, globals()) | |
| 24 for i, fastq_read in enumerate( fastqReader( open( input_filename ), format = input_type ) ): | |
| 25 ret_val = fastq_read_pass_filter( fastq_read ) ## fastq_read_pass_filter defined in script_filename | |
| 26 if ret_val: | |
| 27 out.write( fastq_read ) | |
| 28 reads_kept += 1 | |
| 29 out.close() | |
| 30 if i is None: | |
| 31 print "Your file contains no valid fastq reads." | |
| 32 else: | |
| 33 print 'Kept %s of %s reads (%.2f%%).' % ( reads_kept, i + 1, float( reads_kept ) / float( i + 1 ) * 100.0 ) | |
| 34 | |
| 35 if __name__ == "__main__": | |
| 36 main() |
