Mercurial > repos > devteam > fastq_paired_end_joiner
diff fastq_paired_end_joiner.py @ 0:2793d1d765b9 draft
Imported from capsule None
author | devteam |
---|---|
date | Mon, 27 Jan 2014 09:25:44 -0500 |
parents | |
children | 270a8ed8a300 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fastq_paired_end_joiner.py Mon Jan 27 09:25:44 2014 -0500 @@ -0,0 +1,38 @@ +#Dan Blankenberg +import sys, os, shutil +from galaxy_utils.sequence.fastq import fastqReader, fastqNamedReader, fastqWriter, fastqJoiner + +def main(): + #Read command line arguments + input1_filename = sys.argv[1] + input1_type = sys.argv[2] or 'sanger' + input2_filename = sys.argv[3] + input2_type = sys.argv[4] or 'sanger' + output_filename = sys.argv[5] + + if input1_type != input2_type: + print "WARNING: You are trying to join files of two different types: %s and %s." % ( input1_type, input2_type ) + + input2 = fastqNamedReader( open( input2_filename, 'rb' ), input2_type ) + joiner = fastqJoiner( input1_type ) + out = fastqWriter( open( output_filename, 'wb' ), format = input1_type ) + + i = None + skip_count = 0 + for i, fastq_read in enumerate( fastqReader( open( input1_filename, 'rb' ), format = input1_type ) ): + identifier = joiner.get_paired_identifier( fastq_read ) + fastq_paired = input2.get( identifier ) + if fastq_paired is None: + skip_count += 1 + else: + out.write( joiner.join( fastq_read, fastq_paired ) ) + out.close() + + if i is None: + print "Your file contains no valid FASTQ reads." + else: + print input2.has_data() + print 'Joined %s of %s read pairs (%.2f%%).' % ( i - skip_count + 1, i + 1, float( i - skip_count + 1 ) / float( i + 1 ) * 100.0 ) + +if __name__ == "__main__": + main()