Mercurial > repos > devteam > tabular_to_fastq
comparison tabular_to_fastq.py @ 0:9ae652b76979 draft
Imported from capsule None
| author | devteam |
|---|---|
| date | Thu, 23 Jan 2014 12:31:40 -0500 |
| parents | |
| children | 643018aa1435 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:9ae652b76979 |
|---|---|
| 1 #Dan Blankenberg | |
| 2 import sys | |
| 3 | |
| 4 def main(): | |
| 5 input_filename = sys.argv[1] | |
| 6 output_filename = sys.argv[2] | |
| 7 identifier_col = int( sys.argv[3] ) - 1 | |
| 8 sequence_col = int( sys.argv[4] ) - 1 | |
| 9 quality_col = int( sys.argv[5] ) - 1 | |
| 10 | |
| 11 max_col = max( identifier_col, sequence_col, quality_col ) | |
| 12 num_reads = None | |
| 13 fastq_read = None | |
| 14 skipped_lines = 0 | |
| 15 out = open( output_filename, 'wb' ) | |
| 16 for num_reads, line in enumerate( open( input_filename ) ): | |
| 17 fields = line.rstrip( '\n\r' ).split( '\t' ) | |
| 18 if len( fields ) > max_col: | |
| 19 out.write( "@%s\n%s\n+\n%s\n" % ( fields[identifier_col], fields[sequence_col], fields[quality_col] ) ) | |
| 20 else: | |
| 21 skipped_lines += 1 | |
| 22 | |
| 23 out.close() | |
| 24 if num_reads is None: | |
| 25 print "Input was empty." | |
| 26 else: | |
| 27 print "%i tabular lines were written as FASTQ reads. Be sure to use the FASTQ Groomer tool on this output before further analysis." % ( num_reads + 1 - skipped_lines ) | |
| 28 | |
| 29 if __name__ == "__main__": main() |
