annotate fastq_paired_end_splitter.py @ 1:d2920111eeee draft

planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
author devteam
date Tue, 13 Oct 2015 12:44:12 -0400
parents 5943afe0f24d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
1 #Dan Blankenberg
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
2 import sys, os, shutil
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
3 from galaxy_utils.sequence.fastq import fastqReader, fastqWriter, fastqSplitter
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
4
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
5 def main():
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
6 #Read command line arguments
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
7 input_filename = sys.argv[1]
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
8 input_type = sys.argv[2] or 'sanger'
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
9 output1_filename = sys.argv[3]
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
10 output2_filename = sys.argv[4]
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
11
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
12 splitter = fastqSplitter()
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
13 out1 = fastqWriter( open( output1_filename, 'wb' ), format = input_type )
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
14 out2 = fastqWriter( open( output2_filename, 'wb' ), format = input_type )
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
15
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
16 i = None
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
17 skip_count = 0
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
18 for i, fastq_read in enumerate( fastqReader( open( input_filename, 'rb' ), format = input_type ) ):
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
19 read1, read2 = splitter.split( fastq_read )
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
20 if read1 and read2:
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
21 out1.write( read1 )
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
22 out2.write( read2 )
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
23 else:
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
24 skip_count += 1
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
25 out1.close()
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
26 out2.close()
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
27 if i is None:
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
28 print "Your file contains no valid FASTQ reads."
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
29 else:
5943afe0f24d Imported from capsule None
devteam
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 )
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
31
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
32 if __name__ == "__main__":
5943afe0f24d Imported from capsule None
devteam
parents:
diff changeset
33 main()