annotate fastq_manipulation.py @ 1:bb07615a5b6a draft

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/fastq_manipulation commit a1517c9d22029095120643bbe2c8fa53754dd2b7
author devteam
date Wed, 11 Nov 2015 12:41:10 -0500
parents 5d1e9e13e8db
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
1 #Dan Blankenberg
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
2 import sys, os, shutil
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
3 import imp
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
4 from galaxy_utils.sequence.fastq import fastqReader, fastqWriter
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
5
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
6 def main():
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
7 #Read command line arguments
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
8 input_filename = sys.argv[1]
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
9 script_filename = sys.argv[2]
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
10 output_filename = sys.argv[3]
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
11 additional_files_path = sys.argv[4]
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
12 input_type = sys.argv[5] or 'sanger'
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
13
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
14 #Save script file for debuging/verification info later
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
15 os.mkdir( additional_files_path )
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
16 shutil.copy( script_filename, os.path.join( additional_files_path, 'debug.txt' ) )
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
17
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
18 fastq_manipulator = imp.load_module( 'fastq_manipulator', open( script_filename ), script_filename, ( '', 'r', imp.PY_SOURCE ) )
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
19
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
20 out = fastqWriter( open( output_filename, 'wb' ), format = input_type )
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
21
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
22 i = None
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
23 reads_manipulated = 0
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
24 for i, fastq_read in enumerate( fastqReader( open( input_filename ), format = input_type ) ):
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
25 new_read = fastq_manipulator.match_and_manipulate_read( fastq_read )
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
26 if new_read:
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
27 out.write( new_read )
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
28 if new_read != fastq_read:
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
29 reads_manipulated += 1
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
30 out.close()
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
31 if i is None:
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
32 print "Your file contains no valid FASTQ reads."
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
33 else:
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
34 print 'Manipulated %s of %s reads (%.2f%%).' % ( reads_manipulated, i + 1, float( reads_manipulated ) / float( i + 1 ) * 100.0 )
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
35
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
36 if __name__ == "__main__":
5d1e9e13e8db Imported from capsule None
devteam
parents:
diff changeset
37 main()