annotate fastq_filter.py @ 1:b957f55f3955 draft

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/fastq_filter commit a1517c9d22029095120643bbe2c8fa53754dd2b7
author devteam
date Wed, 11 Nov 2015 12:40:42 -0500
parents 30d9ece6c752
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
1 #Dan Blankenberg
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
2 import sys, os, shutil
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
3 from galaxy_utils.sequence.fastq import fastqReader, fastqWriter
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
4
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
5 def main():
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
6 #Read command line arguments
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
7 input_filename = sys.argv[1]
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
8 script_filename = sys.argv[2]
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
9 output_filename = sys.argv[3]
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
10 additional_files_path = sys.argv[4]
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
11 input_type = sys.argv[5] or 'sanger'
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
12
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
13 #Save script file for debuging/verification info later
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
14 os.mkdir( additional_files_path )
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
15 shutil.copy( script_filename, os.path.join( additional_files_path, 'debug.txt' ) )
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
16
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
17 ## Dan, Others: Can we simply drop the "format=input_type" here since it is specified in reader.
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
18 ## This optimization would cut runtime roughly in half (for my test case anyway). -John
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
19 out = fastqWriter( open( output_filename, 'wb' ), format = input_type )
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
20
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
21 i = None
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
22 reads_kept = 0
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
23 execfile(script_filename, globals())
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
24 for i, fastq_read in enumerate( fastqReader( open( input_filename ), format = input_type ) ):
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
25 ret_val = fastq_read_pass_filter( fastq_read ) ## fastq_read_pass_filter defined in script_filename
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
26 if ret_val:
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
27 out.write( fastq_read )
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
28 reads_kept += 1
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
29 out.close()
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
30 if i is None:
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
31 print "Your file contains no valid fastq reads."
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
32 else:
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
33 print 'Kept %s of %s reads (%.2f%%).' % ( reads_kept, i + 1, float( reads_kept ) / float( i + 1 ) * 100.0 )
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
34
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
35 if __name__ == "__main__":
30d9ece6c752 Imported from capsule None
devteam
parents:
diff changeset
36 main()