annotate tools/fastq/fastq_paired_end_splitter.py @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #Dan Blankenberg
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2 import sys, os, shutil
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 from galaxy_utils.sequence.fastq import fastqReader, fastqWriter, fastqSplitter
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 def main():
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 #Read command line arguments
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 input_filename = sys.argv[1]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 input_type = sys.argv[2] or 'sanger'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 output1_filename = sys.argv[3]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 output2_filename = sys.argv[4]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 splitter = fastqSplitter()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 out1 = fastqWriter( open( output1_filename, 'wb' ), format = input_type )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 out2 = fastqWriter( open( output2_filename, 'wb' ), format = input_type )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 i = None
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 skip_count = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 for i, fastq_read in enumerate( fastqReader( open( input_filename, 'rb' ), format = input_type ) ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 read1, read2 = splitter.split( fastq_read )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 if read1 and read2:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 out1.write( read1 )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 out2.write( read2 )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 skip_count += 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 out1.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 out2.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 if i is None:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 print "Your file contains no valid FASTQ reads."
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 print 'Split %s of %s reads (%.2f%%).' % ( i - skip_count + 1, i + 1, float( i - skip_count + 1 ) / float( i + 1 ) * 100.0 )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 if __name__ == "__main__":
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 main()