annotate tools/fastq/fastq_groomer.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
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 from galaxy_utils.sequence.fastq import fastqReader, fastqVerboseErrorReader, fastqAggregator, fastqWriter
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 def main():
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 input_filename = sys.argv[1]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 input_type = sys.argv[2]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 output_filename = sys.argv[3]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 output_type = sys.argv[4]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 force_quality_encoding = sys.argv[5]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 summarize_input = sys.argv[6] == 'summarize_input'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 if force_quality_encoding == 'None':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 force_quality_encoding = None
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 aggregator = fastqAggregator()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 out = fastqWriter( open( output_filename, 'wb' ), format = output_type, force_quality_encoding = force_quality_encoding )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 read_count = None
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 if summarize_input:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 reader = fastqVerboseErrorReader
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 reader = fastqReader
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 for read_count, fastq_read in enumerate( reader( open( input_filename ), format = input_type, apply_galaxy_conventions = True ) ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 if summarize_input:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 aggregator.consume_read( fastq_read )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 out.write( fastq_read )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 out.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 if read_count is not None:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 print "Groomed %i %s reads into %s reads." % ( read_count + 1, input_type, output_type )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 if input_type != output_type and 'solexa' in [ input_type, output_type ]:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 print "Converted between Solexa and PHRED scores."
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 if summarize_input:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 print "Based upon quality and sequence, the input data is valid for: %s" % ( ", ".join( aggregator.get_valid_formats() ) or "None" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 ascii_range = aggregator.get_ascii_range()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 decimal_range = aggregator.get_decimal_range()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 print "Input ASCII range: %s(%i) - %s(%i)" % ( repr( ascii_range[0] ), ord( ascii_range[0] ), repr( ascii_range[1] ), ord( ascii_range[1] ) ) #print using repr, since \x00 (null) causes info truncation in galaxy when printed
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 print "Input decimal range: %i - %i" % ( decimal_range[0], decimal_range[1] )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 print "No valid FASTQ reads were provided."
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 if __name__ == "__main__": main()