annotate fastq_groomer.py @ 0:06c42572d7c0 draft

Imported from capsule None
author devteam
date Thu, 23 Jan 2014 12:31:44 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
1 #Dan Blankenberg
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
2 import sys
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
3 from galaxy_utils.sequence.fastq import fastqReader, fastqVerboseErrorReader, fastqAggregator, fastqWriter
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
4
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
5 def main():
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
6 input_filename = sys.argv[1]
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
7 input_type = sys.argv[2]
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
8 output_filename = sys.argv[3]
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
9 output_type = sys.argv[4]
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
10 force_quality_encoding = sys.argv[5]
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
11 summarize_input = sys.argv[6] == 'summarize_input'
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
12 if force_quality_encoding == 'None':
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
13 force_quality_encoding = None
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
14
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
15 aggregator = fastqAggregator()
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
16 out = fastqWriter( open( output_filename, 'wb' ), format = output_type, force_quality_encoding = force_quality_encoding )
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
17 read_count = None
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
18 if summarize_input:
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
19 reader = fastqVerboseErrorReader
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
20 else:
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
21 reader = fastqReader
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
22 for read_count, fastq_read in enumerate( reader( open( input_filename ), format = input_type, apply_galaxy_conventions = True ) ):
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
23 if summarize_input:
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
24 aggregator.consume_read( fastq_read )
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
25 out.write( fastq_read )
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
26 out.close()
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
27
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
28 if read_count is not None:
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
29 print "Groomed %i %s reads into %s reads." % ( read_count + 1, input_type, output_type )
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
30 if input_type != output_type and 'solexa' in [ input_type, output_type ]:
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
31 print "Converted between Solexa and PHRED scores."
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
32 if summarize_input:
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
33 print "Based upon quality and sequence, the input data is valid for: %s" % ( ", ".join( aggregator.get_valid_formats() ) or "None" )
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
34 ascii_range = aggregator.get_ascii_range()
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
35 decimal_range = aggregator.get_decimal_range()
06c42572d7c0 Imported from capsule None
devteam
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
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
37 print "Input decimal range: %i - %i" % ( decimal_range[0], decimal_range[1] )
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
38 else:
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
39 print "No valid FASTQ reads were provided."
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
40
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
41
06c42572d7c0 Imported from capsule None
devteam
parents:
diff changeset
42 if __name__ == "__main__": main()